@@ -18,35 +18,35 @@ |
||
| 18 | 18 | class EditUri extends AbstractComponentView |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * Renders a "edit" button to be placed in the grid. |
|
| 23 | - * |
|
| 24 | - * @param Content $object |
|
| 25 | - * @return string |
|
| 26 | - */ |
|
| 27 | - public function render(Content $object = null) |
|
| 28 | - { |
|
| 29 | - $uri = BackendUtility::getModuleUrl( |
|
| 30 | - 'record_edit', |
|
| 31 | - array( |
|
| 32 | - $this->getEditParameterName($object) => 'edit', |
|
| 33 | - 'returnUrl' => $this->getModuleLoader()->getModuleUrl() |
|
| 34 | - ) |
|
| 35 | - ); |
|
| 36 | - return $uri; |
|
| 37 | - } |
|
| 21 | + /** |
|
| 22 | + * Renders a "edit" button to be placed in the grid. |
|
| 23 | + * |
|
| 24 | + * @param Content $object |
|
| 25 | + * @return string |
|
| 26 | + */ |
|
| 27 | + public function render(Content $object = null) |
|
| 28 | + { |
|
| 29 | + $uri = BackendUtility::getModuleUrl( |
|
| 30 | + 'record_edit', |
|
| 31 | + array( |
|
| 32 | + $this->getEditParameterName($object) => 'edit', |
|
| 33 | + 'returnUrl' => $this->getModuleLoader()->getModuleUrl() |
|
| 34 | + ) |
|
| 35 | + ); |
|
| 36 | + return $uri; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param Content $object |
|
| 41 | - * @return string |
|
| 42 | - */ |
|
| 43 | - protected function getEditParameterName(Content $object) |
|
| 44 | - { |
|
| 45 | - return sprintf( |
|
| 46 | - 'edit[%s][%s]', |
|
| 47 | - $object->getDataType(), |
|
| 48 | - $object->getUid() |
|
| 49 | - ); |
|
| 50 | - } |
|
| 39 | + /** |
|
| 40 | + * @param Content $object |
|
| 41 | + * @return string |
|
| 42 | + */ |
|
| 43 | + protected function getEditParameterName(Content $object) |
|
| 44 | + { |
|
| 45 | + return sprintf( |
|
| 46 | + 'edit[%s][%s]', |
|
| 47 | + $object->getDataType(), |
|
| 48 | + $object->getUid() |
|
| 49 | + ); |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | 52 | } |
@@ -17,102 +17,102 @@ |
||
| 17 | 17 | class Property |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @var string |
|
| 22 | - */ |
|
| 23 | - static protected $currentProperty; |
|
| 24 | - |
|
| 25 | - /** |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - static protected $currentTable; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var array |
|
| 32 | - */ |
|
| 33 | - protected $storage = []; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @param string $propertyName |
|
| 37 | - * @return $this |
|
| 38 | - * @throws \InvalidArgumentException |
|
| 39 | - */ |
|
| 40 | - static public function name($propertyName) |
|
| 41 | - { |
|
| 42 | - self::$currentProperty = $propertyName; |
|
| 43 | - self::$currentTable = ''; // reset the table name value. |
|
| 44 | - return GeneralUtility::makeInstance(self::class); |
|
| 45 | - } |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * @param string|Content $tableNameOrContentObject |
|
| 49 | - * @return $this |
|
| 50 | - */ |
|
| 51 | - public function of($tableNameOrContentObject) |
|
| 52 | - { |
|
| 53 | - // Resolve the table name. |
|
| 54 | - self::$currentTable = $tableNameOrContentObject instanceof Content ? |
|
| 55 | - $tableNameOrContentObject->getDataType() : |
|
| 56 | - $tableNameOrContentObject; |
|
| 57 | - return $this; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @return string |
|
| 62 | - */ |
|
| 63 | - public function toFieldName() |
|
| 64 | - { |
|
| 65 | - |
|
| 66 | - $propertyName = $this->getPropertyName(); |
|
| 67 | - $tableName = $this->getTableName(); |
|
| 68 | - |
|
| 69 | - if (empty($this->storage[$tableName][$propertyName])) { |
|
| 70 | - if ($this->storage[$tableName]) { |
|
| 71 | - $this->storage[$tableName] = []; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // Default case |
|
| 75 | - $fieldName = GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName); |
|
| 76 | - |
|
| 77 | - // Special case in case the field name does not follow the conventions "field_name" => "fieldName" |
|
| 78 | - // There is the chance to make some mapping |
|
| 79 | - if (!empty($GLOBALS['TCA'][$tableName]['vidi']['mappings'])) { |
|
| 80 | - $key = array_search($propertyName, $GLOBALS['TCA'][$tableName]['vidi']['mappings']); |
|
| 81 | - if ($key !== false) { |
|
| 82 | - $fieldName = $key; |
|
| 83 | - } |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - $this->storage[$tableName][$propertyName] = $fieldName; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - return $this->storage[$tableName][$propertyName]; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @return string |
|
| 94 | - * @throws \RuntimeException |
|
| 95 | - */ |
|
| 96 | - protected function getPropertyName() |
|
| 97 | - { |
|
| 98 | - $propertyName = self::$currentProperty; |
|
| 99 | - if (empty($propertyName)) { |
|
| 100 | - throw new \RuntimeException('I could not find a field name value.', 1403203290); |
|
| 101 | - } |
|
| 102 | - return $propertyName; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * @return string |
|
| 107 | - * @throws \RuntimeException |
|
| 108 | - */ |
|
| 109 | - protected function getTableName() |
|
| 110 | - { |
|
| 111 | - $tableName = self::$currentTable; |
|
| 112 | - if (empty($tableName)) { |
|
| 113 | - throw new \RuntimeException('I could not find a table name value.', 1403203291); |
|
| 114 | - } |
|
| 115 | - return $tableName; |
|
| 116 | - } |
|
| 20 | + /** |
|
| 21 | + * @var string |
|
| 22 | + */ |
|
| 23 | + static protected $currentProperty; |
|
| 24 | + |
|
| 25 | + /** |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + static protected $currentTable; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var array |
|
| 32 | + */ |
|
| 33 | + protected $storage = []; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @param string $propertyName |
|
| 37 | + * @return $this |
|
| 38 | + * @throws \InvalidArgumentException |
|
| 39 | + */ |
|
| 40 | + static public function name($propertyName) |
|
| 41 | + { |
|
| 42 | + self::$currentProperty = $propertyName; |
|
| 43 | + self::$currentTable = ''; // reset the table name value. |
|
| 44 | + return GeneralUtility::makeInstance(self::class); |
|
| 45 | + } |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * @param string|Content $tableNameOrContentObject |
|
| 49 | + * @return $this |
|
| 50 | + */ |
|
| 51 | + public function of($tableNameOrContentObject) |
|
| 52 | + { |
|
| 53 | + // Resolve the table name. |
|
| 54 | + self::$currentTable = $tableNameOrContentObject instanceof Content ? |
|
| 55 | + $tableNameOrContentObject->getDataType() : |
|
| 56 | + $tableNameOrContentObject; |
|
| 57 | + return $this; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @return string |
|
| 62 | + */ |
|
| 63 | + public function toFieldName() |
|
| 64 | + { |
|
| 65 | + |
|
| 66 | + $propertyName = $this->getPropertyName(); |
|
| 67 | + $tableName = $this->getTableName(); |
|
| 68 | + |
|
| 69 | + if (empty($this->storage[$tableName][$propertyName])) { |
|
| 70 | + if ($this->storage[$tableName]) { |
|
| 71 | + $this->storage[$tableName] = []; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // Default case |
|
| 75 | + $fieldName = GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName); |
|
| 76 | + |
|
| 77 | + // Special case in case the field name does not follow the conventions "field_name" => "fieldName" |
|
| 78 | + // There is the chance to make some mapping |
|
| 79 | + if (!empty($GLOBALS['TCA'][$tableName]['vidi']['mappings'])) { |
|
| 80 | + $key = array_search($propertyName, $GLOBALS['TCA'][$tableName]['vidi']['mappings']); |
|
| 81 | + if ($key !== false) { |
|
| 82 | + $fieldName = $key; |
|
| 83 | + } |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + $this->storage[$tableName][$propertyName] = $fieldName; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + return $this->storage[$tableName][$propertyName]; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @return string |
|
| 94 | + * @throws \RuntimeException |
|
| 95 | + */ |
|
| 96 | + protected function getPropertyName() |
|
| 97 | + { |
|
| 98 | + $propertyName = self::$currentProperty; |
|
| 99 | + if (empty($propertyName)) { |
|
| 100 | + throw new \RuntimeException('I could not find a field name value.', 1403203290); |
|
| 101 | + } |
|
| 102 | + return $propertyName; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * @return string |
|
| 107 | + * @throws \RuntimeException |
|
| 108 | + */ |
|
| 109 | + protected function getTableName() |
|
| 110 | + { |
|
| 111 | + $tableName = self::$currentTable; |
|
| 112 | + if (empty($tableName)) { |
|
| 113 | + throw new \RuntimeException('I could not find a table name value.', 1403203291); |
|
| 114 | + } |
|
| 115 | + return $tableName; |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | } |
@@ -18,98 +18,98 @@ |
||
| 18 | 18 | class Field implements SingletonInterface |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var string |
|
| 23 | - */ |
|
| 24 | - static protected $currentField; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - static protected $currentTable; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var array |
|
| 33 | - */ |
|
| 34 | - protected $storage = []; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @param string $fieldName |
|
| 38 | - * @return $this |
|
| 39 | - * @throws \InvalidArgumentException |
|
| 40 | - */ |
|
| 41 | - static public function name($fieldName) |
|
| 42 | - { |
|
| 43 | - self::$currentField = $fieldName; |
|
| 44 | - self::$currentTable = ''; // reset the table name value. |
|
| 45 | - return GeneralUtility::makeInstance(self::class); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - /** |
|
| 49 | - * @param string|Content $tableNameOrContentObject |
|
| 50 | - * @return $this |
|
| 51 | - */ |
|
| 52 | - public function of($tableNameOrContentObject) |
|
| 53 | - { |
|
| 54 | - // Resolve the table name. |
|
| 55 | - self::$currentTable = $tableNameOrContentObject instanceof Content ? |
|
| 56 | - $tableNameOrContentObject->getDataType() : |
|
| 57 | - $tableNameOrContentObject; |
|
| 58 | - return $this; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @return string |
|
| 63 | - * @throws \RuntimeException |
|
| 64 | - */ |
|
| 65 | - public function toPropertyName() |
|
| 66 | - { |
|
| 67 | - |
|
| 68 | - $fieldName = $this->getFieldName(); |
|
| 69 | - $tableName = $this->getTableName(); |
|
| 70 | - |
|
| 71 | - if (empty($this->storage[$tableName][$fieldName])) { |
|
| 72 | - if ($this->storage[$tableName]) { |
|
| 73 | - $this->storage[$tableName] = []; |
|
| 74 | - } |
|
| 75 | - |
|
| 76 | - // Special case when the field name does not follow the conventions "field_name" => "fieldName". |
|
| 77 | - // Rely on mapping for those cases. |
|
| 78 | - if (!empty($GLOBALS['TCA'][$tableName]['vidi']['mappings'][$fieldName])) { |
|
| 79 | - $propertyName = $GLOBALS['TCA'][$tableName]['vidi']['mappings'][$fieldName]; |
|
| 80 | - } else { |
|
| 81 | - $propertyName = GeneralUtility::underscoredToLowerCamelCase($fieldName); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - $this->storage[$tableName][$fieldName] = $propertyName; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - return $this->storage[$tableName][$fieldName]; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * @return string |
|
| 92 | - * @throws \RuntimeException |
|
| 93 | - */ |
|
| 94 | - protected function getFieldName() |
|
| 95 | - { |
|
| 96 | - $fieldName = self::$currentField; |
|
| 97 | - if (empty($fieldName)) { |
|
| 98 | - throw new \RuntimeException('I could not find a field name value.', 1403203290); |
|
| 99 | - } |
|
| 100 | - return $fieldName; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @return string |
|
| 105 | - */ |
|
| 106 | - protected function getTableName() |
|
| 107 | - { |
|
| 108 | - $tableName = self::$currentTable; |
|
| 109 | - if (empty($tableName)) { |
|
| 110 | - throw new \RuntimeException('I could not find a table name value.', 1403203291); |
|
| 111 | - } |
|
| 112 | - return $tableName; |
|
| 113 | - } |
|
| 21 | + /** |
|
| 22 | + * @var string |
|
| 23 | + */ |
|
| 24 | + static protected $currentField; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + static protected $currentTable; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var array |
|
| 33 | + */ |
|
| 34 | + protected $storage = []; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @param string $fieldName |
|
| 38 | + * @return $this |
|
| 39 | + * @throws \InvalidArgumentException |
|
| 40 | + */ |
|
| 41 | + static public function name($fieldName) |
|
| 42 | + { |
|
| 43 | + self::$currentField = $fieldName; |
|
| 44 | + self::$currentTable = ''; // reset the table name value. |
|
| 45 | + return GeneralUtility::makeInstance(self::class); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + /** |
|
| 49 | + * @param string|Content $tableNameOrContentObject |
|
| 50 | + * @return $this |
|
| 51 | + */ |
|
| 52 | + public function of($tableNameOrContentObject) |
|
| 53 | + { |
|
| 54 | + // Resolve the table name. |
|
| 55 | + self::$currentTable = $tableNameOrContentObject instanceof Content ? |
|
| 56 | + $tableNameOrContentObject->getDataType() : |
|
| 57 | + $tableNameOrContentObject; |
|
| 58 | + return $this; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @return string |
|
| 63 | + * @throws \RuntimeException |
|
| 64 | + */ |
|
| 65 | + public function toPropertyName() |
|
| 66 | + { |
|
| 67 | + |
|
| 68 | + $fieldName = $this->getFieldName(); |
|
| 69 | + $tableName = $this->getTableName(); |
|
| 70 | + |
|
| 71 | + if (empty($this->storage[$tableName][$fieldName])) { |
|
| 72 | + if ($this->storage[$tableName]) { |
|
| 73 | + $this->storage[$tableName] = []; |
|
| 74 | + } |
|
| 75 | + |
|
| 76 | + // Special case when the field name does not follow the conventions "field_name" => "fieldName". |
|
| 77 | + // Rely on mapping for those cases. |
|
| 78 | + if (!empty($GLOBALS['TCA'][$tableName]['vidi']['mappings'][$fieldName])) { |
|
| 79 | + $propertyName = $GLOBALS['TCA'][$tableName]['vidi']['mappings'][$fieldName]; |
|
| 80 | + } else { |
|
| 81 | + $propertyName = GeneralUtility::underscoredToLowerCamelCase($fieldName); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + $this->storage[$tableName][$fieldName] = $propertyName; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + return $this->storage[$tableName][$fieldName]; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * @return string |
|
| 92 | + * @throws \RuntimeException |
|
| 93 | + */ |
|
| 94 | + protected function getFieldName() |
|
| 95 | + { |
|
| 96 | + $fieldName = self::$currentField; |
|
| 97 | + if (empty($fieldName)) { |
|
| 98 | + throw new \RuntimeException('I could not find a field name value.', 1403203290); |
|
| 99 | + } |
|
| 100 | + return $fieldName; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @return string |
|
| 105 | + */ |
|
| 106 | + protected function getTableName() |
|
| 107 | + { |
|
| 108 | + $tableName = self::$currentTable; |
|
| 109 | + if (empty($tableName)) { |
|
| 110 | + throw new \RuntimeException('I could not find a table name value.', 1403203291); |
|
| 111 | + } |
|
| 112 | + return $tableName; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | 115 | } |
@@ -20,114 +20,114 @@ |
||
| 20 | 20 | class MarkerProcessor implements SingletonInterface |
| 21 | 21 | { |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @var array |
|
| 25 | - */ |
|
| 26 | - protected $wellKnownMarkers = array( |
|
| 27 | - '{*}', |
|
| 28 | - '{counter}', |
|
| 29 | - '{date}', |
|
| 30 | - '{creation_date}' |
|
| 31 | - ); |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @param ProcessContentDataSignalArguments $signalArguments |
|
| 35 | - * @return array |
|
| 36 | - */ |
|
| 37 | - public function processMarkers(ProcessContentDataSignalArguments $signalArguments) |
|
| 38 | - { |
|
| 39 | - |
|
| 40 | - $contentData = $signalArguments->getContentData(); |
|
| 41 | - $creationTime = $this->getCreationTime($signalArguments); |
|
| 42 | - |
|
| 43 | - // Process markers |
|
| 44 | - foreach ($signalArguments->getContentData() as $fieldName => $updateValue) { |
|
| 45 | - if (is_scalar($updateValue)) { |
|
| 46 | - |
|
| 47 | - $currentValue = $this->getContentObjectResolver()->getValue( |
|
| 48 | - $signalArguments->getContentObject(), |
|
| 49 | - $signalArguments->getFieldNameAndPath(), |
|
| 50 | - $fieldName, |
|
| 51 | - $signalArguments->getLanguage() |
|
| 52 | - ); |
|
| 53 | - $counter = $signalArguments->getCounter(); |
|
| 54 | - |
|
| 55 | - $updateValue = $this->searchAndReplace($updateValue, $currentValue); |
|
| 56 | - $updateValue = $this->replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime); |
|
| 57 | - |
|
| 58 | - $contentData[$fieldName] = $updateValue; |
|
| 59 | - } |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - $signalArguments->setContentData($contentData); |
|
| 63 | - return array($signalArguments); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @param string $updateValue |
|
| 68 | - * @param string $currentValue |
|
| 69 | - * @param int $counter |
|
| 70 | - * @param $creationTime |
|
| 71 | - * @return string |
|
| 72 | - */ |
|
| 73 | - protected function replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime) |
|
| 74 | - { |
|
| 75 | - |
|
| 76 | - // Replaces values. |
|
| 77 | - $replaces = array( |
|
| 78 | - $currentValue, |
|
| 79 | - $counter, |
|
| 80 | - date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']), |
|
| 81 | - date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $creationTime), |
|
| 82 | - ); |
|
| 83 | - |
|
| 84 | - // Replace me! |
|
| 85 | - return str_replace($this->wellKnownMarkers, $replaces, $updateValue); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @param string $updateValue |
|
| 90 | - * @param string $currentValue |
|
| 91 | - * @return string |
|
| 92 | - */ |
|
| 93 | - protected function searchAndReplace($updateValue, $currentValue) |
|
| 94 | - { |
|
| 95 | - |
|
| 96 | - if (strpos($updateValue, 's/') !== false) { |
|
| 97 | - $structure = explode('/', $updateValue); |
|
| 98 | - $search = $structure[1]; |
|
| 99 | - $replace = $structure[2]; |
|
| 100 | - |
|
| 101 | - // Perhaps needs to be improved here if $search contains "/" precisely. |
|
| 102 | - $updateValue = preg_replace('/' . $search . '/isU', $replace, $currentValue); |
|
| 103 | - } |
|
| 104 | - return $updateValue; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * @param ProcessContentDataSignalArguments $signalArguments |
|
| 109 | - * @return int |
|
| 110 | - */ |
|
| 111 | - protected function getCreationTime(ProcessContentDataSignalArguments $signalArguments) |
|
| 112 | - { |
|
| 113 | - $creationTime = 0; |
|
| 114 | - $creationTimeField = Tca::table($signalArguments->getContentObject()->getDataType())->getTimeCreationField(); |
|
| 115 | - if ($creationTimeField) { |
|
| 116 | - $creationTime = $this->getContentObjectResolver()->getValue( |
|
| 117 | - $signalArguments->getContentObject(), |
|
| 118 | - $signalArguments->getFieldNameAndPath(), |
|
| 119 | - $creationTimeField |
|
| 120 | - ); |
|
| 121 | - } |
|
| 122 | - return $creationTime; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * @return ContentObjectResolver |
|
| 127 | - */ |
|
| 128 | - protected function getContentObjectResolver() |
|
| 129 | - { |
|
| 130 | - return GeneralUtility::makeInstance(ContentObjectResolver::class); |
|
| 131 | - } |
|
| 23 | + /** |
|
| 24 | + * @var array |
|
| 25 | + */ |
|
| 26 | + protected $wellKnownMarkers = array( |
|
| 27 | + '{*}', |
|
| 28 | + '{counter}', |
|
| 29 | + '{date}', |
|
| 30 | + '{creation_date}' |
|
| 31 | + ); |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @param ProcessContentDataSignalArguments $signalArguments |
|
| 35 | + * @return array |
|
| 36 | + */ |
|
| 37 | + public function processMarkers(ProcessContentDataSignalArguments $signalArguments) |
|
| 38 | + { |
|
| 39 | + |
|
| 40 | + $contentData = $signalArguments->getContentData(); |
|
| 41 | + $creationTime = $this->getCreationTime($signalArguments); |
|
| 42 | + |
|
| 43 | + // Process markers |
|
| 44 | + foreach ($signalArguments->getContentData() as $fieldName => $updateValue) { |
|
| 45 | + if (is_scalar($updateValue)) { |
|
| 46 | + |
|
| 47 | + $currentValue = $this->getContentObjectResolver()->getValue( |
|
| 48 | + $signalArguments->getContentObject(), |
|
| 49 | + $signalArguments->getFieldNameAndPath(), |
|
| 50 | + $fieldName, |
|
| 51 | + $signalArguments->getLanguage() |
|
| 52 | + ); |
|
| 53 | + $counter = $signalArguments->getCounter(); |
|
| 54 | + |
|
| 55 | + $updateValue = $this->searchAndReplace($updateValue, $currentValue); |
|
| 56 | + $updateValue = $this->replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime); |
|
| 57 | + |
|
| 58 | + $contentData[$fieldName] = $updateValue; |
|
| 59 | + } |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + $signalArguments->setContentData($contentData); |
|
| 63 | + return array($signalArguments); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @param string $updateValue |
|
| 68 | + * @param string $currentValue |
|
| 69 | + * @param int $counter |
|
| 70 | + * @param $creationTime |
|
| 71 | + * @return string |
|
| 72 | + */ |
|
| 73 | + protected function replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime) |
|
| 74 | + { |
|
| 75 | + |
|
| 76 | + // Replaces values. |
|
| 77 | + $replaces = array( |
|
| 78 | + $currentValue, |
|
| 79 | + $counter, |
|
| 80 | + date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']), |
|
| 81 | + date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $creationTime), |
|
| 82 | + ); |
|
| 83 | + |
|
| 84 | + // Replace me! |
|
| 85 | + return str_replace($this->wellKnownMarkers, $replaces, $updateValue); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @param string $updateValue |
|
| 90 | + * @param string $currentValue |
|
| 91 | + * @return string |
|
| 92 | + */ |
|
| 93 | + protected function searchAndReplace($updateValue, $currentValue) |
|
| 94 | + { |
|
| 95 | + |
|
| 96 | + if (strpos($updateValue, 's/') !== false) { |
|
| 97 | + $structure = explode('/', $updateValue); |
|
| 98 | + $search = $structure[1]; |
|
| 99 | + $replace = $structure[2]; |
|
| 100 | + |
|
| 101 | + // Perhaps needs to be improved here if $search contains "/" precisely. |
|
| 102 | + $updateValue = preg_replace('/' . $search . '/isU', $replace, $currentValue); |
|
| 103 | + } |
|
| 104 | + return $updateValue; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * @param ProcessContentDataSignalArguments $signalArguments |
|
| 109 | + * @return int |
|
| 110 | + */ |
|
| 111 | + protected function getCreationTime(ProcessContentDataSignalArguments $signalArguments) |
|
| 112 | + { |
|
| 113 | + $creationTime = 0; |
|
| 114 | + $creationTimeField = Tca::table($signalArguments->getContentObject()->getDataType())->getTimeCreationField(); |
|
| 115 | + if ($creationTimeField) { |
|
| 116 | + $creationTime = $this->getContentObjectResolver()->getValue( |
|
| 117 | + $signalArguments->getContentObject(), |
|
| 118 | + $signalArguments->getFieldNameAndPath(), |
|
| 119 | + $creationTimeField |
|
| 120 | + ); |
|
| 121 | + } |
|
| 122 | + return $creationTime; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * @return ContentObjectResolver |
|
| 127 | + */ |
|
| 128 | + protected function getContentObjectResolver() |
|
| 129 | + { |
|
| 130 | + return GeneralUtility::makeInstance(ContentObjectResolver::class); |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | 133 | } |
@@ -16,32 +16,32 @@ |
||
| 16 | 16 | class ResultSetStorage implements SingletonInterface |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected $resultSets = []; |
|
| 19 | + /** |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected $resultSets = []; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param string $querySignature |
|
| 26 | - * @return array |
|
| 27 | - */ |
|
| 28 | - public function get($querySignature) |
|
| 29 | - { |
|
| 30 | - $resultSet = null; |
|
| 31 | - if (isset($this->resultSets[$querySignature])) { |
|
| 32 | - $resultSet = $this->resultSets[$querySignature]; |
|
| 33 | - } |
|
| 34 | - return $resultSet; |
|
| 35 | - } |
|
| 24 | + /** |
|
| 25 | + * @param string $querySignature |
|
| 26 | + * @return array |
|
| 27 | + */ |
|
| 28 | + public function get($querySignature) |
|
| 29 | + { |
|
| 30 | + $resultSet = null; |
|
| 31 | + if (isset($this->resultSets[$querySignature])) { |
|
| 32 | + $resultSet = $this->resultSets[$querySignature]; |
|
| 33 | + } |
|
| 34 | + return $resultSet; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param $querySignature |
|
| 39 | - * @param array $resultSet |
|
| 40 | - * @internal param array $resultSets |
|
| 41 | - */ |
|
| 42 | - public function set($querySignature, array $resultSet) |
|
| 43 | - { |
|
| 44 | - $this->resultSets[$querySignature] = $resultSet; |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * @param $querySignature |
|
| 39 | + * @param array $resultSet |
|
| 40 | + * @internal param array $resultSets |
|
| 41 | + */ |
|
| 42 | + public function set($querySignature, array $resultSet) |
|
| 43 | + { |
|
| 44 | + $this->resultSets[$querySignature] = $resultSet; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | 47 | } |
@@ -14,45 +14,45 @@ |
||
| 14 | 14 | class Order |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * The orderings |
|
| 19 | - * |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected $orderings = []; |
|
| 17 | + /** |
|
| 18 | + * The orderings |
|
| 19 | + * |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected $orderings = []; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Constructs a new Order |
|
| 26 | - * |
|
| 27 | - * @para array $orders |
|
| 28 | - * @param array $orders |
|
| 29 | - */ |
|
| 30 | - public function __construct($orders = array()) |
|
| 31 | - { |
|
| 32 | - foreach ($orders as $order => $direction) { |
|
| 33 | - $this->addOrdering($order, $direction); |
|
| 34 | - } |
|
| 35 | - } |
|
| 24 | + /** |
|
| 25 | + * Constructs a new Order |
|
| 26 | + * |
|
| 27 | + * @para array $orders |
|
| 28 | + * @param array $orders |
|
| 29 | + */ |
|
| 30 | + public function __construct($orders = array()) |
|
| 31 | + { |
|
| 32 | + foreach ($orders as $order => $direction) { |
|
| 33 | + $this->addOrdering($order, $direction); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Add ordering |
|
| 39 | - * |
|
| 40 | - * @param string $order The order |
|
| 41 | - * @param string $direction ASC / DESC |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function addOrdering($order, $direction) |
|
| 45 | - { |
|
| 46 | - $this->orderings[$order] = $direction; |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * Add ordering |
|
| 39 | + * |
|
| 40 | + * @param string $order The order |
|
| 41 | + * @param string $direction ASC / DESC |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function addOrdering($order, $direction) |
|
| 45 | + { |
|
| 46 | + $this->orderings[$order] = $direction; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Returns the order |
|
| 51 | - * |
|
| 52 | - * @return array The order |
|
| 53 | - */ |
|
| 54 | - public function getOrderings() |
|
| 55 | - { |
|
| 56 | - return $this->orderings; |
|
| 57 | - } |
|
| 49 | + /** |
|
| 50 | + * Returns the order |
|
| 51 | + * |
|
| 52 | + * @return array The order |
|
| 53 | + */ |
|
| 54 | + public function getOrderings() |
|
| 55 | + { |
|
| 56 | + return $this->orderings; |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -14,121 +14,121 @@ |
||
| 14 | 14 | class JsonResult |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var int |
|
| 19 | - */ |
|
| 20 | - protected $numberOfObjects = 0; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * @var int |
|
| 24 | - */ |
|
| 25 | - protected $numberOfProcessedObjects = 0; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected $errorMessages = []; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * @var array |
|
| 34 | - */ |
|
| 35 | - protected $processedObject = []; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var array |
|
| 39 | - */ |
|
| 40 | - protected $row = null; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * @return $this |
|
| 44 | - */ |
|
| 45 | - public function incrementNumberOfProcessedObjects() |
|
| 46 | - { |
|
| 47 | - $this->numberOfProcessedObjects++; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - /** |
|
| 51 | - * @param string $errorMessages |
|
| 52 | - * @return $this |
|
| 53 | - */ |
|
| 54 | - public function addErrorMessages($errorMessages) |
|
| 55 | - { |
|
| 56 | - if (!empty($errorMessages)) { |
|
| 57 | - $this->errorMessages[] = $errorMessages; |
|
| 58 | - } else { |
|
| 59 | - $this->incrementNumberOfProcessedObjects(); |
|
| 60 | - } |
|
| 61 | - return $this; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * @param array $errorMessages |
|
| 66 | - * @return $this |
|
| 67 | - */ |
|
| 68 | - public function setErrorMessages($errorMessages) |
|
| 69 | - { |
|
| 70 | - $this->errorMessages = $errorMessages; |
|
| 71 | - return $this; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - /** |
|
| 75 | - * @param array $processedObject |
|
| 76 | - * @return $this |
|
| 77 | - */ |
|
| 78 | - public function setProcessedObject($processedObject) |
|
| 79 | - { |
|
| 80 | - $this->processedObject = $processedObject; |
|
| 81 | - return $this; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @return $this |
|
| 86 | - */ |
|
| 87 | - public function hasErrors() |
|
| 88 | - { |
|
| 89 | - return !empty($this->errorMessages); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @param mixed $numberOfObjects |
|
| 94 | - * @return $this |
|
| 95 | - */ |
|
| 96 | - public function setNumberOfObjects($numberOfObjects) |
|
| 97 | - { |
|
| 98 | - $this->numberOfObjects = $numberOfObjects; |
|
| 99 | - return $this; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @param mixed $row |
|
| 104 | - * @return $this |
|
| 105 | - */ |
|
| 106 | - public function setRow(array $row) |
|
| 107 | - { |
|
| 108 | - $this->row = $row; |
|
| 109 | - return $this; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Convert $this to array |
|
| 114 | - * |
|
| 115 | - * @return array |
|
| 116 | - */ |
|
| 117 | - public function toArray() |
|
| 118 | - { |
|
| 119 | - $arrayValues = array( |
|
| 120 | - 'numberOfObjects' => $this->numberOfObjects, |
|
| 121 | - 'numberOfProcessedObjects' => $this->numberOfProcessedObjects, |
|
| 122 | - 'hasErrors' => $this->hasErrors(), |
|
| 123 | - 'errorMessages' => $this->errorMessages, |
|
| 124 | - 'row' => $this->row, |
|
| 125 | - ); |
|
| 126 | - |
|
| 127 | - // Only feed key processedObject if it has values. |
|
| 128 | - if (!empty($this->processedObject)) { |
|
| 129 | - $arrayValues['processedObject'] = $this->processedObject; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return $arrayValues; |
|
| 133 | - } |
|
| 17 | + /** |
|
| 18 | + * @var int |
|
| 19 | + */ |
|
| 20 | + protected $numberOfObjects = 0; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * @var int |
|
| 24 | + */ |
|
| 25 | + protected $numberOfProcessedObjects = 0; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected $errorMessages = []; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * @var array |
|
| 34 | + */ |
|
| 35 | + protected $processedObject = []; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var array |
|
| 39 | + */ |
|
| 40 | + protected $row = null; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * @return $this |
|
| 44 | + */ |
|
| 45 | + public function incrementNumberOfProcessedObjects() |
|
| 46 | + { |
|
| 47 | + $this->numberOfProcessedObjects++; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + /** |
|
| 51 | + * @param string $errorMessages |
|
| 52 | + * @return $this |
|
| 53 | + */ |
|
| 54 | + public function addErrorMessages($errorMessages) |
|
| 55 | + { |
|
| 56 | + if (!empty($errorMessages)) { |
|
| 57 | + $this->errorMessages[] = $errorMessages; |
|
| 58 | + } else { |
|
| 59 | + $this->incrementNumberOfProcessedObjects(); |
|
| 60 | + } |
|
| 61 | + return $this; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * @param array $errorMessages |
|
| 66 | + * @return $this |
|
| 67 | + */ |
|
| 68 | + public function setErrorMessages($errorMessages) |
|
| 69 | + { |
|
| 70 | + $this->errorMessages = $errorMessages; |
|
| 71 | + return $this; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + /** |
|
| 75 | + * @param array $processedObject |
|
| 76 | + * @return $this |
|
| 77 | + */ |
|
| 78 | + public function setProcessedObject($processedObject) |
|
| 79 | + { |
|
| 80 | + $this->processedObject = $processedObject; |
|
| 81 | + return $this; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @return $this |
|
| 86 | + */ |
|
| 87 | + public function hasErrors() |
|
| 88 | + { |
|
| 89 | + return !empty($this->errorMessages); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @param mixed $numberOfObjects |
|
| 94 | + * @return $this |
|
| 95 | + */ |
|
| 96 | + public function setNumberOfObjects($numberOfObjects) |
|
| 97 | + { |
|
| 98 | + $this->numberOfObjects = $numberOfObjects; |
|
| 99 | + return $this; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @param mixed $row |
|
| 104 | + * @return $this |
|
| 105 | + */ |
|
| 106 | + public function setRow(array $row) |
|
| 107 | + { |
|
| 108 | + $this->row = $row; |
|
| 109 | + return $this; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Convert $this to array |
|
| 114 | + * |
|
| 115 | + * @return array |
|
| 116 | + */ |
|
| 117 | + public function toArray() |
|
| 118 | + { |
|
| 119 | + $arrayValues = array( |
|
| 120 | + 'numberOfObjects' => $this->numberOfObjects, |
|
| 121 | + 'numberOfProcessedObjects' => $this->numberOfProcessedObjects, |
|
| 122 | + 'hasErrors' => $this->hasErrors(), |
|
| 123 | + 'errorMessages' => $this->errorMessages, |
|
| 124 | + 'row' => $this->row, |
|
| 125 | + ); |
|
| 126 | + |
|
| 127 | + // Only feed key processedObject if it has values. |
|
| 128 | + if (!empty($this->processedObject)) { |
|
| 129 | + $arrayValues['processedObject'] = $this->processedObject; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return $arrayValues; |
|
| 133 | + } |
|
| 134 | 134 | } |
| 135 | 135 | \ No newline at end of file |
@@ -18,36 +18,36 @@ |
||
| 18 | 18 | class CsvToArrayConverter extends AbstractTypeConverter |
| 19 | 19 | { |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @var array<string> |
|
| 23 | - */ |
|
| 24 | - protected $sourceTypes = array('string'); |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @var string |
|
| 28 | - */ |
|
| 29 | - protected $targetType = 'array'; |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @var integer |
|
| 33 | - */ |
|
| 34 | - protected $priority = 1; |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * Actually convert from $source to $targetType |
|
| 38 | - * |
|
| 39 | - * @param string $source |
|
| 40 | - * @param string $targetType |
|
| 41 | - * @param array $convertedChildProperties |
|
| 42 | - * @param PropertyMappingConfigurationInterface $configuration |
|
| 43 | - * @return array |
|
| 44 | - * @throws \Exception |
|
| 45 | - * @throws \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException |
|
| 46 | - * @api |
|
| 47 | - */ |
|
| 48 | - public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) |
|
| 49 | - { |
|
| 50 | - return GeneralUtility::trimExplode(',', $source, true); |
|
| 51 | - } |
|
| 21 | + /** |
|
| 22 | + * @var array<string> |
|
| 23 | + */ |
|
| 24 | + protected $sourceTypes = array('string'); |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @var string |
|
| 28 | + */ |
|
| 29 | + protected $targetType = 'array'; |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @var integer |
|
| 33 | + */ |
|
| 34 | + protected $priority = 1; |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * Actually convert from $source to $targetType |
|
| 38 | + * |
|
| 39 | + * @param string $source |
|
| 40 | + * @param string $targetType |
|
| 41 | + * @param array $convertedChildProperties |
|
| 42 | + * @param PropertyMappingConfigurationInterface $configuration |
|
| 43 | + * @return array |
|
| 44 | + * @throws \Exception |
|
| 45 | + * @throws \TYPO3\CMS\Core\Resource\Exception\FileDoesNotExistException |
|
| 46 | + * @api |
|
| 47 | + */ |
|
| 48 | + public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null) |
|
| 49 | + { |
|
| 50 | + return GeneralUtility::trimExplode(',', $source, true); |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | 53 | } |
| 54 | 54 | \ No newline at end of file |
@@ -16,114 +16,114 @@ |
||
| 16 | 16 | class GridAnalyserService |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * Check relation for table. |
|
| 21 | - * |
|
| 22 | - * @param $tableName |
|
| 23 | - * @return array |
|
| 24 | - */ |
|
| 25 | - public function checkRelationForTable($tableName) |
|
| 26 | - { |
|
| 19 | + /** |
|
| 20 | + * Check relation for table. |
|
| 21 | + * |
|
| 22 | + * @param $tableName |
|
| 23 | + * @return array |
|
| 24 | + */ |
|
| 25 | + public function checkRelationForTable($tableName) |
|
| 26 | + { |
|
| 27 | 27 | |
| 28 | - $relations = []; |
|
| 29 | - $table = Tca::table($tableName); |
|
| 28 | + $relations = []; |
|
| 29 | + $table = Tca::table($tableName); |
|
| 30 | 30 | |
| 31 | - $missingOppositionRelationMessage = <<<EOF |
|
| 31 | + $missingOppositionRelationMessage = <<<EOF |
|
| 32 | 32 | |
| 33 | 33 | WARNING! Could not define relation precisely. This is not necessarily a problem |
| 34 | 34 | if the opposite relation is not required in a Grid. But consider adding the opposite |
| 35 | 35 | TCA configuration if so. |
| 36 | 36 | EOF; |
| 37 | 37 | |
| 38 | - foreach (Tca::grid($tableName)->getFields() as $fieldName => $configuration) { |
|
| 39 | - |
|
| 40 | - if ($table->hasField($fieldName)) { |
|
| 41 | - if ($table->field($fieldName)->hasMany()) { |
|
| 42 | - if ($table->field($fieldName)->hasRelationWithCommaSeparatedValues()) { |
|
| 43 | - $_relations = $this->checkRelationOf($tableName, $fieldName, 'comma separated values'); |
|
| 44 | - $relations = array_merge($relations, $_relations); |
|
| 45 | - } elseif ($table->field($fieldName)->hasRelationManyToMany()) { |
|
| 46 | - $_relations = $this->checkRelationManyToMany($tableName, $fieldName); |
|
| 47 | - $relations = array_merge($relations, $_relations); |
|
| 48 | - |
|
| 49 | - } elseif ($table->field($fieldName)->hasRelationOneToMany()) { |
|
| 50 | - $_relations = $this->checkRelationOf($tableName, $fieldName, 'one-to-many'); |
|
| 51 | - $relations = array_merge($relations, $_relations); |
|
| 52 | - } else { |
|
| 53 | - $relations[] = sprintf('* field: "%s", relation: ?-to-many%s', $fieldName, $missingOppositionRelationMessage); |
|
| 54 | - } |
|
| 55 | - $relations[] = ''; |
|
| 56 | - } elseif ($table->field($fieldName)->hasOne()) { |
|
| 57 | - |
|
| 58 | - if ($table->field($fieldName)->hasRelationOneToOne()) { |
|
| 59 | - $relations[] = sprintf('* one-to-one "%s"', $fieldName); |
|
| 60 | - } elseif ($table->field($fieldName)->hasRelationManyToOne()) { |
|
| 61 | - $_relations = $this->checkRelationOf($tableName, $fieldName, 'many-to-one'); |
|
| 62 | - $relations = array_merge($relations, $_relations); |
|
| 63 | - } else { |
|
| 64 | - $relations[] = sprintf('* field: "%s", relation: ?-to-one%s', $fieldName, $missingOppositionRelationMessage); |
|
| 65 | - } |
|
| 66 | - $relations[] = ''; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - return $relations; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Convenience method for printing out relation many-to-many. |
|
| 75 | - * |
|
| 76 | - * @param string $tableName |
|
| 77 | - * @param string $fieldName |
|
| 78 | - * @return array |
|
| 79 | - */ |
|
| 80 | - protected function checkRelationManyToMany($tableName, $fieldName) |
|
| 81 | - { |
|
| 82 | - |
|
| 83 | - $output = []; |
|
| 84 | - |
|
| 85 | - $table = Tca::table($tableName); |
|
| 86 | - $output[] = sprintf('* field: "%s", relation: many-to-many', $fieldName); |
|
| 87 | - |
|
| 88 | - $foreignTable = $table->field($fieldName)->getForeignTable(); |
|
| 89 | - $manyToManyTable = $table->field($fieldName)->getManyToManyTable(); |
|
| 90 | - $foreignField = $table->field($fieldName)->getForeignField(); |
|
| 91 | - |
|
| 92 | - if (!$foreignField) { |
|
| 93 | - $output[] = sprintf(' ERROR! Can not found foreign field for "%s". Perhaps missing opposite configuration?', $fieldName); |
|
| 94 | - } elseif (!$foreignTable) { |
|
| 95 | - $output[] = sprintf(' ERROR! Can not found foreign table for "%s". Perhaps missing opposite configuration?', $fieldName); |
|
| 96 | - } elseif (!$manyToManyTable) { |
|
| 97 | - $output[] = sprintf(' ERROR! Can not found relation table (MM) for "%s". Perhaps missing opposite configuration?', $fieldName); |
|
| 98 | - } else { |
|
| 99 | - $output[] = sprintf(' %s.%s <--> %s <--> %s.%s', $tableName, $fieldName, $manyToManyTable, $foreignTable, $foreignField); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $output[] = ''; |
|
| 103 | - return $output; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - /** |
|
| 107 | - * Convenience method for printing out relation. |
|
| 108 | - * |
|
| 109 | - * @param string $tableName |
|
| 110 | - * @param string $fieldName |
|
| 111 | - * @param string $relationType |
|
| 112 | - * @return array |
|
| 113 | - */ |
|
| 114 | - protected function checkRelationOf($tableName, $fieldName, $relationType) |
|
| 115 | - { |
|
| 116 | - |
|
| 117 | - $output = []; |
|
| 118 | - |
|
| 119 | - $table = Tca::table($tableName); |
|
| 120 | - $output[] = sprintf('* field: "%s", relation: %s', $fieldName, $relationType); |
|
| 121 | - |
|
| 122 | - $foreignTable = $table->field($fieldName)->getForeignTable(); |
|
| 123 | - $foreignField = $table->field($fieldName)->getForeignField(); |
|
| 124 | - $output[] = sprintf(' %s.%s <--> %s.%s', $tableName, $fieldName, $foreignTable, $foreignField); |
|
| 125 | - $output[] = ''; |
|
| 126 | - |
|
| 127 | - return $output; |
|
| 128 | - } |
|
| 38 | + foreach (Tca::grid($tableName)->getFields() as $fieldName => $configuration) { |
|
| 39 | + |
|
| 40 | + if ($table->hasField($fieldName)) { |
|
| 41 | + if ($table->field($fieldName)->hasMany()) { |
|
| 42 | + if ($table->field($fieldName)->hasRelationWithCommaSeparatedValues()) { |
|
| 43 | + $_relations = $this->checkRelationOf($tableName, $fieldName, 'comma separated values'); |
|
| 44 | + $relations = array_merge($relations, $_relations); |
|
| 45 | + } elseif ($table->field($fieldName)->hasRelationManyToMany()) { |
|
| 46 | + $_relations = $this->checkRelationManyToMany($tableName, $fieldName); |
|
| 47 | + $relations = array_merge($relations, $_relations); |
|
| 48 | + |
|
| 49 | + } elseif ($table->field($fieldName)->hasRelationOneToMany()) { |
|
| 50 | + $_relations = $this->checkRelationOf($tableName, $fieldName, 'one-to-many'); |
|
| 51 | + $relations = array_merge($relations, $_relations); |
|
| 52 | + } else { |
|
| 53 | + $relations[] = sprintf('* field: "%s", relation: ?-to-many%s', $fieldName, $missingOppositionRelationMessage); |
|
| 54 | + } |
|
| 55 | + $relations[] = ''; |
|
| 56 | + } elseif ($table->field($fieldName)->hasOne()) { |
|
| 57 | + |
|
| 58 | + if ($table->field($fieldName)->hasRelationOneToOne()) { |
|
| 59 | + $relations[] = sprintf('* one-to-one "%s"', $fieldName); |
|
| 60 | + } elseif ($table->field($fieldName)->hasRelationManyToOne()) { |
|
| 61 | + $_relations = $this->checkRelationOf($tableName, $fieldName, 'many-to-one'); |
|
| 62 | + $relations = array_merge($relations, $_relations); |
|
| 63 | + } else { |
|
| 64 | + $relations[] = sprintf('* field: "%s", relation: ?-to-one%s', $fieldName, $missingOppositionRelationMessage); |
|
| 65 | + } |
|
| 66 | + $relations[] = ''; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + return $relations; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Convenience method for printing out relation many-to-many. |
|
| 75 | + * |
|
| 76 | + * @param string $tableName |
|
| 77 | + * @param string $fieldName |
|
| 78 | + * @return array |
|
| 79 | + */ |
|
| 80 | + protected function checkRelationManyToMany($tableName, $fieldName) |
|
| 81 | + { |
|
| 82 | + |
|
| 83 | + $output = []; |
|
| 84 | + |
|
| 85 | + $table = Tca::table($tableName); |
|
| 86 | + $output[] = sprintf('* field: "%s", relation: many-to-many', $fieldName); |
|
| 87 | + |
|
| 88 | + $foreignTable = $table->field($fieldName)->getForeignTable(); |
|
| 89 | + $manyToManyTable = $table->field($fieldName)->getManyToManyTable(); |
|
| 90 | + $foreignField = $table->field($fieldName)->getForeignField(); |
|
| 91 | + |
|
| 92 | + if (!$foreignField) { |
|
| 93 | + $output[] = sprintf(' ERROR! Can not found foreign field for "%s". Perhaps missing opposite configuration?', $fieldName); |
|
| 94 | + } elseif (!$foreignTable) { |
|
| 95 | + $output[] = sprintf(' ERROR! Can not found foreign table for "%s". Perhaps missing opposite configuration?', $fieldName); |
|
| 96 | + } elseif (!$manyToManyTable) { |
|
| 97 | + $output[] = sprintf(' ERROR! Can not found relation table (MM) for "%s". Perhaps missing opposite configuration?', $fieldName); |
|
| 98 | + } else { |
|
| 99 | + $output[] = sprintf(' %s.%s <--> %s <--> %s.%s', $tableName, $fieldName, $manyToManyTable, $foreignTable, $foreignField); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $output[] = ''; |
|
| 103 | + return $output; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + /** |
|
| 107 | + * Convenience method for printing out relation. |
|
| 108 | + * |
|
| 109 | + * @param string $tableName |
|
| 110 | + * @param string $fieldName |
|
| 111 | + * @param string $relationType |
|
| 112 | + * @return array |
|
| 113 | + */ |
|
| 114 | + protected function checkRelationOf($tableName, $fieldName, $relationType) |
|
| 115 | + { |
|
| 116 | + |
|
| 117 | + $output = []; |
|
| 118 | + |
|
| 119 | + $table = Tca::table($tableName); |
|
| 120 | + $output[] = sprintf('* field: "%s", relation: %s', $fieldName, $relationType); |
|
| 121 | + |
|
| 122 | + $foreignTable = $table->field($fieldName)->getForeignTable(); |
|
| 123 | + $foreignField = $table->field($fieldName)->getForeignField(); |
|
| 124 | + $output[] = sprintf(' %s.%s <--> %s.%s', $tableName, $fieldName, $foreignTable, $foreignField); |
|
| 125 | + $output[] = ''; |
|
| 126 | + |
|
| 127 | + return $output; |
|
| 128 | + } |
|
| 129 | 129 | } |