@@ -94,7 +94,7 @@ |
||
| 94 | 94 | * |
| 95 | 95 | * @param Content $content |
| 96 | 96 | * @param string $target |
| 97 | - * @return bool |
|
| 97 | + * @return boolean|null |
|
| 98 | 98 | */ |
| 99 | 99 | public function processCopy(Content $content, $target) |
| 100 | 100 | { |
@@ -24,140 +24,140 @@ |
||
| 24 | 24 | class CoreDataHandler extends AbstractDataHandler |
| 25 | 25 | { |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var array |
|
| 29 | - */ |
|
| 30 | - protected $dataHandler; |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Process Content with action "update". |
|
| 34 | - * |
|
| 35 | - * @param Content $content |
|
| 36 | - * @throws \Exception |
|
| 37 | - * @return bool |
|
| 38 | - */ |
|
| 39 | - public function processUpdate(Content $content) |
|
| 40 | - { |
|
| 41 | - |
|
| 42 | - $values = array(); |
|
| 43 | - |
|
| 44 | - // Check the field to be updated exists |
|
| 45 | - foreach ($content->toArray() as $fieldName => $value) { |
|
| 46 | - if (!Tca::table($content->getDataType())->hasField($fieldName)) { |
|
| 47 | - $message = sprintf('It looks field "%s" does not exist for data type "%s"', $fieldName, $content->getDataType()); |
|
| 48 | - throw new \Exception($message, 1390668497); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - // Flatten value if array given which is required for the DataHandler. |
|
| 52 | - if (is_array($value)) { |
|
| 53 | - $value = implode(',', $value); |
|
| 54 | - } |
|
| 55 | - $values[$fieldName] = $value; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - $data[$content->getDataType()][$content->getUid()] = $values; |
|
| 59 | - |
|
| 60 | - $dataHandler = $this->getDataHandler(); |
|
| 61 | - $dataHandler->start($data, array()); |
|
| 62 | - $dataHandler->process_datamap(); |
|
| 63 | - $this->errorMessages = $dataHandler->errorLog; |
|
| 64 | - |
|
| 65 | - // Returns TRUE is log does not contain errors. |
|
| 66 | - return empty($dataHandler->errorLog); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Process Content with action "remove". |
|
| 71 | - * |
|
| 72 | - * @param Content $content |
|
| 73 | - * @return bool |
|
| 74 | - */ |
|
| 75 | - public function processRemove(Content $content) |
|
| 76 | - { |
|
| 77 | - |
|
| 78 | - // Build command |
|
| 79 | - $cmd[$content->getDataType()][$content->getUid()]['delete'] = 1; |
|
| 80 | - |
|
| 81 | - /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 82 | - $dataHandler = $this->getDataHandler(); |
|
| 83 | - $dataHandler->start(array(), $cmd); |
|
| 84 | - $dataHandler->process_datamap(); |
|
| 85 | - $dataHandler->process_cmdmap(); |
|
| 86 | - $this->errorMessages = $dataHandler->errorLog; |
|
| 87 | - |
|
| 88 | - // Returns TRUE is log does not contain errors. |
|
| 89 | - return empty($dataHandler->errorLog); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * Process Content with action "copy". |
|
| 94 | - * |
|
| 95 | - * @param Content $content |
|
| 96 | - * @param string $target |
|
| 97 | - * @return bool |
|
| 98 | - */ |
|
| 99 | - public function processCopy(Content $content, $target) |
|
| 100 | - { |
|
| 101 | - // TODO: Implement processCopy() method. |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - /** |
|
| 105 | - * Process Content with action "move". |
|
| 106 | - * The $target corresponds to the pid to move the records to. |
|
| 107 | - * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor. |
|
| 108 | - * |
|
| 109 | - * @param Content $content |
|
| 110 | - * @param int $target corresponds |
|
| 111 | - * @return bool |
|
| 112 | - */ |
|
| 113 | - public function processMove(Content $content, $target) |
|
| 114 | - { |
|
| 115 | - |
|
| 116 | - // Build command |
|
| 117 | - $cmd[$content->getDataType()][$content->getUid()]['move'] = $target; |
|
| 118 | - |
|
| 119 | - /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 120 | - $dataHandler = $this->getDataHandler(); |
|
| 121 | - $dataHandler->start(array(), $cmd); |
|
| 122 | - $dataHandler->process_datamap(); |
|
| 123 | - $dataHandler->process_cmdmap(); |
|
| 124 | - $this->errorMessages = $dataHandler->errorLog; |
|
| 125 | - |
|
| 126 | - // Returns TRUE is log does not contain errors. |
|
| 127 | - return empty($dataHandler->errorLog); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Process Content with action "localize". |
|
| 132 | - * |
|
| 133 | - * @param Content $content |
|
| 134 | - * @param int $language |
|
| 135 | - * @return bool |
|
| 136 | - */ |
|
| 137 | - public function processLocalize(Content $content, $language) |
|
| 138 | - { |
|
| 139 | - |
|
| 140 | - $command[$content->getDataType()][$content->getUid()]['localize'] = $language; |
|
| 141 | - |
|
| 142 | - $dataHandler = $this->getDataHandler(); |
|
| 143 | - $dataHandler->start(array(), $command); |
|
| 144 | - $dataHandler->process_datamap(); |
|
| 145 | - $dataHandler->process_cmdmap(); |
|
| 146 | - $this->errorMessages = $dataHandler->errorLog; |
|
| 147 | - |
|
| 148 | - // Returns TRUE is log does not contain errors. |
|
| 149 | - return empty($dataHandler->errorLog); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * @return \TYPO3\CMS\Core\DataHandling\DataHandler |
|
| 154 | - */ |
|
| 155 | - protected function getDataHandler() |
|
| 156 | - { |
|
| 157 | - if (!$this->dataHandler) { |
|
| 158 | - $this->dataHandler = GeneralUtility::makeInstance('TYPO3\CMS\Core\DataHandling\DataHandler'); |
|
| 159 | - } |
|
| 160 | - return $this->dataHandler; |
|
| 161 | - } |
|
| 27 | + /** |
|
| 28 | + * @var array |
|
| 29 | + */ |
|
| 30 | + protected $dataHandler; |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Process Content with action "update". |
|
| 34 | + * |
|
| 35 | + * @param Content $content |
|
| 36 | + * @throws \Exception |
|
| 37 | + * @return bool |
|
| 38 | + */ |
|
| 39 | + public function processUpdate(Content $content) |
|
| 40 | + { |
|
| 41 | + |
|
| 42 | + $values = array(); |
|
| 43 | + |
|
| 44 | + // Check the field to be updated exists |
|
| 45 | + foreach ($content->toArray() as $fieldName => $value) { |
|
| 46 | + if (!Tca::table($content->getDataType())->hasField($fieldName)) { |
|
| 47 | + $message = sprintf('It looks field "%s" does not exist for data type "%s"', $fieldName, $content->getDataType()); |
|
| 48 | + throw new \Exception($message, 1390668497); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + // Flatten value if array given which is required for the DataHandler. |
|
| 52 | + if (is_array($value)) { |
|
| 53 | + $value = implode(',', $value); |
|
| 54 | + } |
|
| 55 | + $values[$fieldName] = $value; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + $data[$content->getDataType()][$content->getUid()] = $values; |
|
| 59 | + |
|
| 60 | + $dataHandler = $this->getDataHandler(); |
|
| 61 | + $dataHandler->start($data, array()); |
|
| 62 | + $dataHandler->process_datamap(); |
|
| 63 | + $this->errorMessages = $dataHandler->errorLog; |
|
| 64 | + |
|
| 65 | + // Returns TRUE is log does not contain errors. |
|
| 66 | + return empty($dataHandler->errorLog); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Process Content with action "remove". |
|
| 71 | + * |
|
| 72 | + * @param Content $content |
|
| 73 | + * @return bool |
|
| 74 | + */ |
|
| 75 | + public function processRemove(Content $content) |
|
| 76 | + { |
|
| 77 | + |
|
| 78 | + // Build command |
|
| 79 | + $cmd[$content->getDataType()][$content->getUid()]['delete'] = 1; |
|
| 80 | + |
|
| 81 | + /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 82 | + $dataHandler = $this->getDataHandler(); |
|
| 83 | + $dataHandler->start(array(), $cmd); |
|
| 84 | + $dataHandler->process_datamap(); |
|
| 85 | + $dataHandler->process_cmdmap(); |
|
| 86 | + $this->errorMessages = $dataHandler->errorLog; |
|
| 87 | + |
|
| 88 | + // Returns TRUE is log does not contain errors. |
|
| 89 | + return empty($dataHandler->errorLog); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * Process Content with action "copy". |
|
| 94 | + * |
|
| 95 | + * @param Content $content |
|
| 96 | + * @param string $target |
|
| 97 | + * @return bool |
|
| 98 | + */ |
|
| 99 | + public function processCopy(Content $content, $target) |
|
| 100 | + { |
|
| 101 | + // TODO: Implement processCopy() method. |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + /** |
|
| 105 | + * Process Content with action "move". |
|
| 106 | + * The $target corresponds to the pid to move the records to. |
|
| 107 | + * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor. |
|
| 108 | + * |
|
| 109 | + * @param Content $content |
|
| 110 | + * @param int $target corresponds |
|
| 111 | + * @return bool |
|
| 112 | + */ |
|
| 113 | + public function processMove(Content $content, $target) |
|
| 114 | + { |
|
| 115 | + |
|
| 116 | + // Build command |
|
| 117 | + $cmd[$content->getDataType()][$content->getUid()]['move'] = $target; |
|
| 118 | + |
|
| 119 | + /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 120 | + $dataHandler = $this->getDataHandler(); |
|
| 121 | + $dataHandler->start(array(), $cmd); |
|
| 122 | + $dataHandler->process_datamap(); |
|
| 123 | + $dataHandler->process_cmdmap(); |
|
| 124 | + $this->errorMessages = $dataHandler->errorLog; |
|
| 125 | + |
|
| 126 | + // Returns TRUE is log does not contain errors. |
|
| 127 | + return empty($dataHandler->errorLog); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Process Content with action "localize". |
|
| 132 | + * |
|
| 133 | + * @param Content $content |
|
| 134 | + * @param int $language |
|
| 135 | + * @return bool |
|
| 136 | + */ |
|
| 137 | + public function processLocalize(Content $content, $language) |
|
| 138 | + { |
|
| 139 | + |
|
| 140 | + $command[$content->getDataType()][$content->getUid()]['localize'] = $language; |
|
| 141 | + |
|
| 142 | + $dataHandler = $this->getDataHandler(); |
|
| 143 | + $dataHandler->start(array(), $command); |
|
| 144 | + $dataHandler->process_datamap(); |
|
| 145 | + $dataHandler->process_cmdmap(); |
|
| 146 | + $this->errorMessages = $dataHandler->errorLog; |
|
| 147 | + |
|
| 148 | + // Returns TRUE is log does not contain errors. |
|
| 149 | + return empty($dataHandler->errorLog); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * @return \TYPO3\CMS\Core\DataHandling\DataHandler |
|
| 154 | + */ |
|
| 155 | + protected function getDataHandler() |
|
| 156 | + { |
|
| 157 | + if (!$this->dataHandler) { |
|
| 158 | + $this->dataHandler = GeneralUtility::makeInstance('TYPO3\CMS\Core\DataHandling\DataHandler'); |
|
| 159 | + } |
|
| 160 | + return $this->dataHandler; |
|
| 161 | + } |
|
| 162 | 162 | |
| 163 | 163 | } |
@@ -385,7 +385,7 @@ |
||
| 385 | 385 | /** |
| 386 | 386 | * Return the properties of this object. |
| 387 | 387 | * |
| 388 | - * @return array |
|
| 388 | + * @return string[] |
|
| 389 | 389 | */ |
| 390 | 390 | public function toFields() |
| 391 | 391 | { |
@@ -29,441 +29,441 @@ |
||
| 29 | 29 | class Content implements \ArrayAccess |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var int |
|
| 34 | - */ |
|
| 35 | - protected $uid; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 40 | - protected $dataType; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Constructor for a Content object. |
|
| 44 | - * |
|
| 45 | - * @param string $dataType will basically correspond to a table name, e.g fe_users, tt_content, ... |
|
| 46 | - * @param array $contentData |
|
| 47 | - * @return \Fab\Vidi\Domain\Model\Content |
|
| 48 | - */ |
|
| 49 | - public function __construct($dataType, array $contentData = array()) |
|
| 50 | - { |
|
| 51 | - |
|
| 52 | - $this->dataType = $dataType; |
|
| 53 | - $this->uid = empty($contentData['uid']) ? NULL : (int)$contentData['uid']; |
|
| 54 | - |
|
| 55 | - /** @var \Fab\Vidi\Tca\TableService $table */ |
|
| 56 | - $table = Tca::table($dataType); |
|
| 57 | - |
|
| 58 | - // Initialize the array containing the allowed fields to be filled-in. |
|
| 59 | - $fields = array('pid'); |
|
| 60 | - |
|
| 61 | - // If a creation time stamp has been defined for this data type. |
|
| 62 | - if ($table->getTimeCreationField()) { |
|
| 63 | - $fields[] = $table->getTimeCreationField(); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // If an update time stamp has been defined for this data type. |
|
| 67 | - if ($table->getTimeModificationField()) { |
|
| 68 | - $fields[] = $table->getTimeModificationField(); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - // Merge the other fields allowed for this data type. |
|
| 72 | - $fields = array_merge($fields, $table->getFields()); |
|
| 73 | - |
|
| 74 | - // Fetch excluded fields from the grid. |
|
| 75 | - if ($this->isBackendMode()) { |
|
| 76 | - $fields = $this->filterForConfiguration($fields); |
|
| 77 | - $fields = $this->filterForBackendUser($fields); |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // Get column to be displayed |
|
| 81 | - foreach ($fields as $fieldName) { |
|
| 82 | - if (array_key_exists($fieldName, $contentData)) { |
|
| 83 | - $propertyName = Field::name($fieldName)->of($dataType)->toPropertyName(); |
|
| 84 | - $this->$propertyName = $contentData[$fieldName]; |
|
| 85 | - } |
|
| 86 | - } |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - /** |
|
| 90 | - * Dispatches magic methods (findBy[Property]()) |
|
| 91 | - * |
|
| 92 | - * @param string $methodName The name of the magic method |
|
| 93 | - * @param string $arguments The arguments of the magic method |
|
| 94 | - * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException |
|
| 95 | - * @return mixed |
|
| 96 | - * @api |
|
| 97 | - */ |
|
| 98 | - public function __call($methodName, $arguments) |
|
| 99 | - { |
|
| 100 | - $value = NULL; |
|
| 101 | - if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) { |
|
| 102 | - $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1); |
|
| 103 | - |
|
| 104 | - $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
| 105 | - $field = Tca::table($this->dataType)->field($fieldName); |
|
| 106 | - |
|
| 107 | - $value = $this->$propertyName; |
|
| 108 | - |
|
| 109 | - // TRUE means it is a relation and it is not yet resolved. |
|
| 110 | - if ($this->hasRelation($propertyName) && is_scalar($this->$propertyName)) { |
|
| 111 | - $value = $this->resolveRelation($propertyName); |
|
| 112 | - } elseif ($field->getType() === FieldType::RADIO || $field->getType() === FieldType::SELECT) { |
|
| 113 | - |
|
| 114 | - // Attempt to convert the value into a label for radio and select fields. |
|
| 115 | - $label = Tca::table($this->getDataType())->field($fieldName)->getLabelForItem($value); |
|
| 116 | - if ($label) { |
|
| 117 | - $value = $label; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - } elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) { |
|
| 122 | - $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1); |
|
| 123 | - $this->$propertyName = $arguments[0]; |
|
| 124 | - } |
|
| 125 | - return $value; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Tell whether the property has a relation. |
|
| 130 | - * |
|
| 131 | - * @param string $propertyName |
|
| 132 | - * @return bool |
|
| 133 | - */ |
|
| 134 | - protected function hasRelation($propertyName) |
|
| 135 | - { |
|
| 136 | - $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
| 137 | - return Tca::table($this->dataType)->field($fieldName)->hasRelation(); |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Try to "resolve" the property whether it has a relation. |
|
| 142 | - * If the property has not relation it simply returns the same value. |
|
| 143 | - * |
|
| 144 | - * @throws \RuntimeException |
|
| 145 | - * @param string $propertyName |
|
| 146 | - * @return mixed |
|
| 147 | - */ |
|
| 148 | - protected function resolveRelation($propertyName) |
|
| 149 | - { |
|
| 150 | - |
|
| 151 | - // Convert property name to field name and get the foreign data type. |
|
| 152 | - $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
| 153 | - $foreignDataType = Tca::table($this->dataType)->field($fieldName)->relationDataType(); |
|
| 154 | - |
|
| 155 | - // Get the foreign repository instance form the factory |
|
| 156 | - /** @var \Fab\Vidi\Domain\Repository\ContentRepository $foreignContentRepository */ |
|
| 157 | - $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType, $fieldName); |
|
| 158 | - |
|
| 159 | - if (Tca::table($this->dataType)->field($fieldName)->hasRelationWithCommaSeparatedValues()) { |
|
| 160 | - |
|
| 161 | - // Fetch values from repository |
|
| 162 | - $values = GeneralUtility::trimExplode(',', $this->$propertyName); |
|
| 163 | - $this->$propertyName = $foreignContentRepository->findIn('uid', $values); |
|
| 164 | - } elseif (Tca::table($this->dataType)->field($fieldName)->hasMany()) { |
|
| 165 | - // Include relation many-to-many and one-to-many |
|
| 166 | - // Tca::table($this->dataType)->field($fieldName)->hasRelationOneToMany() |
|
| 167 | - // Tca::table($this->dataType)->field($fieldName)->hasRelationManyToMany() |
|
| 168 | - |
|
| 169 | - $foreignFieldName = Tca::table($this->dataType)->field($fieldName)->getForeignField(); |
|
| 170 | - if (empty($foreignFieldName)) { |
|
| 171 | - $message = sprintf('Missing "foreign_field" key for field "%s" in table "%s".', |
|
| 172 | - $fieldName, |
|
| 173 | - $this->dataType |
|
| 174 | - ); |
|
| 175 | - throw new \RuntimeException($message, 1376149186); |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Fetch values from repository. |
|
| 179 | - $foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName(); |
|
| 180 | - $findByProperty = 'findBy' . ucfirst($foreignPropertyName); |
|
| 181 | - |
|
| 182 | - // Date picker (type == group) are special fields because property path must contain the table name |
|
| 183 | - // to determine the relation type. Example for sys_category, property path will look like "items.sys_file" |
|
| 184 | - $propertyValue = $this->uid; |
|
| 185 | - if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) { |
|
| 186 | - $propertyValue = $this->dataType . '.' . $this->uid; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue); |
|
| 190 | - |
|
| 191 | - } elseif (Tca::table($this->dataType)->field($fieldName)->hasOne()) { |
|
| 192 | - |
|
| 193 | - $fieldConfiguration = Tca::table($this->dataType)->field($fieldName)->getConfiguration(); |
|
| 194 | - |
|
| 195 | - // First case, we are on the "good side" of the relation, just query the repository |
|
| 196 | - if (empty($fieldConfiguration['foreign_field'])) { |
|
| 197 | - $this->$propertyName = $foreignContentRepository->findByUid($this->$propertyName); |
|
| 198 | - } else { |
|
| 199 | - // Second case, we are the "bad side" of the relation, query the foreign repository |
|
| 200 | - // e.g. in case of one-to-one relation. |
|
| 201 | - |
|
| 202 | - // We must query the opposite side to get the identifier of the foreign object. |
|
| 203 | - $foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable(); |
|
| 204 | - $foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField(); |
|
| 205 | - $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType); |
|
| 206 | - $find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField); |
|
| 207 | - |
|
| 208 | - /** @var Content $foreignObject */ |
|
| 209 | - $this->$propertyName = $foreignContentRepository->$find($this->getUid()); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - } |
|
| 213 | - return $this->$propertyName; |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - /** |
|
| 217 | - * @return int |
|
| 218 | - */ |
|
| 219 | - public function getUid() |
|
| 220 | - { |
|
| 221 | - return $this->uid; |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * @return string |
|
| 226 | - */ |
|
| 227 | - public function getDataType() |
|
| 228 | - { |
|
| 229 | - return $this->dataType; |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Whether a offset exists |
|
| 234 | - * |
|
| 235 | - * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
|
| 236 | - * @param mixed $offset |
|
| 237 | - * @return boolean true on success or false on failure. |
|
| 238 | - */ |
|
| 239 | - public function offsetExists($offset) |
|
| 240 | - { |
|
| 241 | - $offset = Field::name($offset)->of($this)->toPropertyName(); |
|
| 242 | - return isset($this->$offset); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - /** |
|
| 246 | - * Offset to retrieve |
|
| 247 | - * |
|
| 248 | - * @link http://php.net/manual/en/arrayaccess.offsetget.php |
|
| 249 | - * @param mixed $offset |
|
| 250 | - * @return mixed Can return all value types. |
|
| 251 | - */ |
|
| 252 | - public function offsetGet($offset) |
|
| 253 | - { |
|
| 254 | - $offset = Field::name($offset)->of($this)->toPropertyName(); |
|
| 255 | - $getter = 'get' . ucfirst($offset); |
|
| 256 | - return $this->$getter(); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - /** |
|
| 260 | - * Offset to set |
|
| 261 | - * |
|
| 262 | - * @link http://php.net/manual/en/arrayaccess.offsetset.php |
|
| 263 | - * @param mixed $offset |
|
| 264 | - * @param mixed $value |
|
| 265 | - * @return $this |
|
| 266 | - */ |
|
| 267 | - public function offsetSet($offset, $value) |
|
| 268 | - { |
|
| 269 | - $offset = Field::name($offset)->of($this)->toPropertyName(); |
|
| 270 | - $setter = 'set' . ucfirst($offset); |
|
| 271 | - $this->$setter($value); |
|
| 272 | - return $this; |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - /** |
|
| 276 | - * Offset to unset |
|
| 277 | - * |
|
| 278 | - * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
|
| 279 | - * @param mixed $offset |
|
| 280 | - * @throws NotImplementedException |
|
| 281 | - * @return void |
|
| 282 | - */ |
|
| 283 | - public function offsetUnset($offset) |
|
| 284 | - { |
|
| 285 | - $message = 'Un-setting value for Array object is not supported'; |
|
| 286 | - throw new NotImplementedException($message, 1376132306); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - /** |
|
| 290 | - * Convert this to array |
|
| 291 | - * |
|
| 292 | - * @return array |
|
| 293 | - */ |
|
| 294 | - public function toArray() |
|
| 295 | - { |
|
| 296 | - $result['uid'] = $this->uid; |
|
| 297 | - $propertiesAndValues = json_decode(json_encode($this), TRUE); |
|
| 298 | - |
|
| 299 | - foreach ($propertiesAndValues as $propertyName => $value) { |
|
| 300 | - $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
| 301 | - $result[$fieldName] = $value; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return $result; |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - /** |
|
| 308 | - * Convert this object to an array containing the resolved values. |
|
| 309 | - * |
|
| 310 | - * @param bool $resolveRelations |
|
| 311 | - * @return array |
|
| 312 | - * @throws \Exception |
|
| 313 | - */ |
|
| 314 | - public function toValues($resolveRelations = TRUE) |
|
| 315 | - { |
|
| 316 | - $result['uid'] = $this->uid; |
|
| 317 | - $propertiesAndValues = json_decode(json_encode($this), TRUE); |
|
| 318 | - |
|
| 319 | - foreach ($propertiesAndValues as $propertyName => $value) { |
|
| 320 | - $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
| 321 | - |
|
| 322 | - $result[$fieldName] = $value; |
|
| 323 | - if ($resolveRelations) { |
|
| 324 | - $field = Tca::table($this->dataType)->field($fieldName); |
|
| 325 | - |
|
| 326 | - $resolvedValue = ''; |
|
| 327 | - if ($field->getType() === FieldType::FILE) { |
|
| 328 | - |
|
| 329 | - if ($field->hasMany()) { |
|
| 330 | - $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this); |
|
| 331 | - |
|
| 332 | - $resolvedValue = array(); |
|
| 333 | - foreach ($files as $file) { |
|
| 334 | - $resolvedValue[] = $file->getIdentifier(); |
|
| 335 | - } |
|
| 336 | - } else { |
|
| 337 | - $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this); |
|
| 338 | - if (!empty($files)) { |
|
| 339 | - $resolvedValue = current($files)->getIdentifier(); |
|
| 340 | - } |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - // Reset value |
|
| 344 | - $result[$fieldName] = $resolvedValue; |
|
| 345 | - |
|
| 346 | - } elseif (Tca::table($this->dataType)->field($fieldName)->hasRelation()) { |
|
| 347 | - $objects = $this[$fieldName]; |
|
| 348 | - if (is_array($objects)) { |
|
| 349 | - $resolvedValue = array(); |
|
| 350 | - foreach ($objects as $object) { |
|
| 351 | - /** @var $object Content */ |
|
| 352 | - $labelField = Tca::table($object->getDataType())->getLabelField(); |
|
| 353 | - $resolvedValue[] = $object[$labelField]; |
|
| 354 | - } |
|
| 355 | - } elseif ($objects instanceof Content) { |
|
| 356 | - $labelField = Tca::table($objects->getDataType())->getLabelField(); |
|
| 357 | - $resolvedValue = $objects[$labelField]; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - // Reset value |
|
| 361 | - $result[$fieldName] = $resolvedValue; |
|
| 362 | - } |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - return $result; |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - /** |
|
| 370 | - * Return the properties of this object. |
|
| 371 | - * |
|
| 372 | - * @return array |
|
| 373 | - */ |
|
| 374 | - public function toProperties() |
|
| 375 | - { |
|
| 376 | - $result[] = 'uid'; |
|
| 377 | - $propertiesAndValues = json_decode(json_encode($this), TRUE); |
|
| 378 | - |
|
| 379 | - foreach ($propertiesAndValues as $propertyName => $value) { |
|
| 380 | - $result[] = $propertyName; |
|
| 381 | - } |
|
| 382 | - return $result; |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Return the properties of this object. |
|
| 387 | - * |
|
| 388 | - * @return array |
|
| 389 | - */ |
|
| 390 | - public function toFields() |
|
| 391 | - { |
|
| 392 | - $result[] = 'uid'; |
|
| 393 | - $propertiesAndValues = json_decode(json_encode($this), TRUE); |
|
| 394 | - |
|
| 395 | - foreach ($propertiesAndValues as $propertyName => $value) { |
|
| 396 | - $result[] = Property::name($propertyName)->of($this)->toFieldName(); |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - return $result; |
|
| 400 | - } |
|
| 401 | - |
|
| 402 | - /** |
|
| 403 | - * @return string |
|
| 404 | - */ |
|
| 405 | - public function __toString() |
|
| 406 | - { |
|
| 407 | - $labelField = Tca::table($this->dataType)->getLabelField(); |
|
| 408 | - return $this[$labelField]; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - /** |
|
| 412 | - * Remove fields according to BE User permission. |
|
| 413 | - * |
|
| 414 | - * @param $fields |
|
| 415 | - * @return array |
|
| 416 | - * @throws \Exception |
|
| 417 | - */ |
|
| 418 | - protected function filterForBackendUser($fields) |
|
| 419 | - { |
|
| 420 | - if (!$this->getBackendUser()->isAdmin()) { |
|
| 421 | - foreach ($fields as $key => $fieldName) { |
|
| 422 | - if (Tca::table($this->dataType)->hasField($fieldName) && !Tca::table($this->dataType)->field($fieldName)->hasAccess()) { |
|
| 423 | - unset($fields[$key]); |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - } |
|
| 427 | - return $fields; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Remove fields according to Grid configuration. |
|
| 432 | - * |
|
| 433 | - * @param $fields |
|
| 434 | - * @return array |
|
| 435 | - */ |
|
| 436 | - protected function filterForConfiguration($fields) |
|
| 437 | - { |
|
| 438 | - |
|
| 439 | - $excludedFields = Tca::grid($this->dataType)->getExcludedFields(); |
|
| 440 | - foreach ($fields as $key => $field) { |
|
| 441 | - if (in_array($field, $excludedFields)) { |
|
| 442 | - unset($fields[$key]); |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - |
|
| 446 | - return $fields; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - /** |
|
| 450 | - * Returns an instance of the current Backend User. |
|
| 451 | - * |
|
| 452 | - * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 453 | - */ |
|
| 454 | - protected function getBackendUser() |
|
| 455 | - { |
|
| 456 | - return $GLOBALS['BE_USER']; |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - /** |
|
| 460 | - * Returns whether the current mode is Backend |
|
| 461 | - * |
|
| 462 | - * @return bool |
|
| 463 | - */ |
|
| 464 | - protected function isBackendMode() |
|
| 465 | - { |
|
| 466 | - return TYPO3_MODE == 'BE'; |
|
| 467 | - } |
|
| 32 | + /** |
|
| 33 | + * @var int |
|
| 34 | + */ |
|
| 35 | + protected $uid; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | + protected $dataType; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Constructor for a Content object. |
|
| 44 | + * |
|
| 45 | + * @param string $dataType will basically correspond to a table name, e.g fe_users, tt_content, ... |
|
| 46 | + * @param array $contentData |
|
| 47 | + * @return \Fab\Vidi\Domain\Model\Content |
|
| 48 | + */ |
|
| 49 | + public function __construct($dataType, array $contentData = array()) |
|
| 50 | + { |
|
| 51 | + |
|
| 52 | + $this->dataType = $dataType; |
|
| 53 | + $this->uid = empty($contentData['uid']) ? NULL : (int)$contentData['uid']; |
|
| 54 | + |
|
| 55 | + /** @var \Fab\Vidi\Tca\TableService $table */ |
|
| 56 | + $table = Tca::table($dataType); |
|
| 57 | + |
|
| 58 | + // Initialize the array containing the allowed fields to be filled-in. |
|
| 59 | + $fields = array('pid'); |
|
| 60 | + |
|
| 61 | + // If a creation time stamp has been defined for this data type. |
|
| 62 | + if ($table->getTimeCreationField()) { |
|
| 63 | + $fields[] = $table->getTimeCreationField(); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // If an update time stamp has been defined for this data type. |
|
| 67 | + if ($table->getTimeModificationField()) { |
|
| 68 | + $fields[] = $table->getTimeModificationField(); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + // Merge the other fields allowed for this data type. |
|
| 72 | + $fields = array_merge($fields, $table->getFields()); |
|
| 73 | + |
|
| 74 | + // Fetch excluded fields from the grid. |
|
| 75 | + if ($this->isBackendMode()) { |
|
| 76 | + $fields = $this->filterForConfiguration($fields); |
|
| 77 | + $fields = $this->filterForBackendUser($fields); |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // Get column to be displayed |
|
| 81 | + foreach ($fields as $fieldName) { |
|
| 82 | + if (array_key_exists($fieldName, $contentData)) { |
|
| 83 | + $propertyName = Field::name($fieldName)->of($dataType)->toPropertyName(); |
|
| 84 | + $this->$propertyName = $contentData[$fieldName]; |
|
| 85 | + } |
|
| 86 | + } |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + /** |
|
| 90 | + * Dispatches magic methods (findBy[Property]()) |
|
| 91 | + * |
|
| 92 | + * @param string $methodName The name of the magic method |
|
| 93 | + * @param string $arguments The arguments of the magic method |
|
| 94 | + * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnsupportedMethodException |
|
| 95 | + * @return mixed |
|
| 96 | + * @api |
|
| 97 | + */ |
|
| 98 | + public function __call($methodName, $arguments) |
|
| 99 | + { |
|
| 100 | + $value = NULL; |
|
| 101 | + if (substr($methodName, 0, 3) === 'get' && strlen($methodName) > 4) { |
|
| 102 | + $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1); |
|
| 103 | + |
|
| 104 | + $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
| 105 | + $field = Tca::table($this->dataType)->field($fieldName); |
|
| 106 | + |
|
| 107 | + $value = $this->$propertyName; |
|
| 108 | + |
|
| 109 | + // TRUE means it is a relation and it is not yet resolved. |
|
| 110 | + if ($this->hasRelation($propertyName) && is_scalar($this->$propertyName)) { |
|
| 111 | + $value = $this->resolveRelation($propertyName); |
|
| 112 | + } elseif ($field->getType() === FieldType::RADIO || $field->getType() === FieldType::SELECT) { |
|
| 113 | + |
|
| 114 | + // Attempt to convert the value into a label for radio and select fields. |
|
| 115 | + $label = Tca::table($this->getDataType())->field($fieldName)->getLabelForItem($value); |
|
| 116 | + if ($label) { |
|
| 117 | + $value = $label; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + } elseif (substr($methodName, 0, 3) === 'set' && strlen($methodName) > 4 && isset($arguments[0])) { |
|
| 122 | + $propertyName = strtolower(substr(substr($methodName, 3), 0, 1)) . substr(substr($methodName, 3), 1); |
|
| 123 | + $this->$propertyName = $arguments[0]; |
|
| 124 | + } |
|
| 125 | + return $value; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Tell whether the property has a relation. |
|
| 130 | + * |
|
| 131 | + * @param string $propertyName |
|
| 132 | + * @return bool |
|
| 133 | + */ |
|
| 134 | + protected function hasRelation($propertyName) |
|
| 135 | + { |
|
| 136 | + $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
| 137 | + return Tca::table($this->dataType)->field($fieldName)->hasRelation(); |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Try to "resolve" the property whether it has a relation. |
|
| 142 | + * If the property has not relation it simply returns the same value. |
|
| 143 | + * |
|
| 144 | + * @throws \RuntimeException |
|
| 145 | + * @param string $propertyName |
|
| 146 | + * @return mixed |
|
| 147 | + */ |
|
| 148 | + protected function resolveRelation($propertyName) |
|
| 149 | + { |
|
| 150 | + |
|
| 151 | + // Convert property name to field name and get the foreign data type. |
|
| 152 | + $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
| 153 | + $foreignDataType = Tca::table($this->dataType)->field($fieldName)->relationDataType(); |
|
| 154 | + |
|
| 155 | + // Get the foreign repository instance form the factory |
|
| 156 | + /** @var \Fab\Vidi\Domain\Repository\ContentRepository $foreignContentRepository */ |
|
| 157 | + $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType, $fieldName); |
|
| 158 | + |
|
| 159 | + if (Tca::table($this->dataType)->field($fieldName)->hasRelationWithCommaSeparatedValues()) { |
|
| 160 | + |
|
| 161 | + // Fetch values from repository |
|
| 162 | + $values = GeneralUtility::trimExplode(',', $this->$propertyName); |
|
| 163 | + $this->$propertyName = $foreignContentRepository->findIn('uid', $values); |
|
| 164 | + } elseif (Tca::table($this->dataType)->field($fieldName)->hasMany()) { |
|
| 165 | + // Include relation many-to-many and one-to-many |
|
| 166 | + // Tca::table($this->dataType)->field($fieldName)->hasRelationOneToMany() |
|
| 167 | + // Tca::table($this->dataType)->field($fieldName)->hasRelationManyToMany() |
|
| 168 | + |
|
| 169 | + $foreignFieldName = Tca::table($this->dataType)->field($fieldName)->getForeignField(); |
|
| 170 | + if (empty($foreignFieldName)) { |
|
| 171 | + $message = sprintf('Missing "foreign_field" key for field "%s" in table "%s".', |
|
| 172 | + $fieldName, |
|
| 173 | + $this->dataType |
|
| 174 | + ); |
|
| 175 | + throw new \RuntimeException($message, 1376149186); |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Fetch values from repository. |
|
| 179 | + $foreignPropertyName = Field::name($foreignFieldName)->of($this)->toPropertyName(); |
|
| 180 | + $findByProperty = 'findBy' . ucfirst($foreignPropertyName); |
|
| 181 | + |
|
| 182 | + // Date picker (type == group) are special fields because property path must contain the table name |
|
| 183 | + // to determine the relation type. Example for sys_category, property path will look like "items.sys_file" |
|
| 184 | + $propertyValue = $this->uid; |
|
| 185 | + if (Tca::table($foreignDataType)->field($foreignFieldName)->isGroup()) { |
|
| 186 | + $propertyValue = $this->dataType . '.' . $this->uid; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $this->$propertyName = $foreignContentRepository->$findByProperty($propertyValue); |
|
| 190 | + |
|
| 191 | + } elseif (Tca::table($this->dataType)->field($fieldName)->hasOne()) { |
|
| 192 | + |
|
| 193 | + $fieldConfiguration = Tca::table($this->dataType)->field($fieldName)->getConfiguration(); |
|
| 194 | + |
|
| 195 | + // First case, we are on the "good side" of the relation, just query the repository |
|
| 196 | + if (empty($fieldConfiguration['foreign_field'])) { |
|
| 197 | + $this->$propertyName = $foreignContentRepository->findByUid($this->$propertyName); |
|
| 198 | + } else { |
|
| 199 | + // Second case, we are the "bad side" of the relation, query the foreign repository |
|
| 200 | + // e.g. in case of one-to-one relation. |
|
| 201 | + |
|
| 202 | + // We must query the opposite side to get the identifier of the foreign object. |
|
| 203 | + $foreignDataType = Tca::table($this->dataType)->field($fieldName)->getForeignTable(); |
|
| 204 | + $foreignField = Tca::table($this->dataType)->field($fieldName)->getForeignField(); |
|
| 205 | + $foreignContentRepository = ContentRepositoryFactory::getInstance($foreignDataType); |
|
| 206 | + $find = 'findOneBy' . GeneralUtility::underscoredToUpperCamelCase($foreignField); |
|
| 207 | + |
|
| 208 | + /** @var Content $foreignObject */ |
|
| 209 | + $this->$propertyName = $foreignContentRepository->$find($this->getUid()); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + } |
|
| 213 | + return $this->$propertyName; |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + /** |
|
| 217 | + * @return int |
|
| 218 | + */ |
|
| 219 | + public function getUid() |
|
| 220 | + { |
|
| 221 | + return $this->uid; |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * @return string |
|
| 226 | + */ |
|
| 227 | + public function getDataType() |
|
| 228 | + { |
|
| 229 | + return $this->dataType; |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Whether a offset exists |
|
| 234 | + * |
|
| 235 | + * @link http://php.net/manual/en/arrayaccess.offsetexists.php |
|
| 236 | + * @param mixed $offset |
|
| 237 | + * @return boolean true on success or false on failure. |
|
| 238 | + */ |
|
| 239 | + public function offsetExists($offset) |
|
| 240 | + { |
|
| 241 | + $offset = Field::name($offset)->of($this)->toPropertyName(); |
|
| 242 | + return isset($this->$offset); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + /** |
|
| 246 | + * Offset to retrieve |
|
| 247 | + * |
|
| 248 | + * @link http://php.net/manual/en/arrayaccess.offsetget.php |
|
| 249 | + * @param mixed $offset |
|
| 250 | + * @return mixed Can return all value types. |
|
| 251 | + */ |
|
| 252 | + public function offsetGet($offset) |
|
| 253 | + { |
|
| 254 | + $offset = Field::name($offset)->of($this)->toPropertyName(); |
|
| 255 | + $getter = 'get' . ucfirst($offset); |
|
| 256 | + return $this->$getter(); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + /** |
|
| 260 | + * Offset to set |
|
| 261 | + * |
|
| 262 | + * @link http://php.net/manual/en/arrayaccess.offsetset.php |
|
| 263 | + * @param mixed $offset |
|
| 264 | + * @param mixed $value |
|
| 265 | + * @return $this |
|
| 266 | + */ |
|
| 267 | + public function offsetSet($offset, $value) |
|
| 268 | + { |
|
| 269 | + $offset = Field::name($offset)->of($this)->toPropertyName(); |
|
| 270 | + $setter = 'set' . ucfirst($offset); |
|
| 271 | + $this->$setter($value); |
|
| 272 | + return $this; |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + /** |
|
| 276 | + * Offset to unset |
|
| 277 | + * |
|
| 278 | + * @link http://php.net/manual/en/arrayaccess.offsetunset.php |
|
| 279 | + * @param mixed $offset |
|
| 280 | + * @throws NotImplementedException |
|
| 281 | + * @return void |
|
| 282 | + */ |
|
| 283 | + public function offsetUnset($offset) |
|
| 284 | + { |
|
| 285 | + $message = 'Un-setting value for Array object is not supported'; |
|
| 286 | + throw new NotImplementedException($message, 1376132306); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + /** |
|
| 290 | + * Convert this to array |
|
| 291 | + * |
|
| 292 | + * @return array |
|
| 293 | + */ |
|
| 294 | + public function toArray() |
|
| 295 | + { |
|
| 296 | + $result['uid'] = $this->uid; |
|
| 297 | + $propertiesAndValues = json_decode(json_encode($this), TRUE); |
|
| 298 | + |
|
| 299 | + foreach ($propertiesAndValues as $propertyName => $value) { |
|
| 300 | + $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
| 301 | + $result[$fieldName] = $value; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return $result; |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + /** |
|
| 308 | + * Convert this object to an array containing the resolved values. |
|
| 309 | + * |
|
| 310 | + * @param bool $resolveRelations |
|
| 311 | + * @return array |
|
| 312 | + * @throws \Exception |
|
| 313 | + */ |
|
| 314 | + public function toValues($resolveRelations = TRUE) |
|
| 315 | + { |
|
| 316 | + $result['uid'] = $this->uid; |
|
| 317 | + $propertiesAndValues = json_decode(json_encode($this), TRUE); |
|
| 318 | + |
|
| 319 | + foreach ($propertiesAndValues as $propertyName => $value) { |
|
| 320 | + $fieldName = Property::name($propertyName)->of($this)->toFieldName(); |
|
| 321 | + |
|
| 322 | + $result[$fieldName] = $value; |
|
| 323 | + if ($resolveRelations) { |
|
| 324 | + $field = Tca::table($this->dataType)->field($fieldName); |
|
| 325 | + |
|
| 326 | + $resolvedValue = ''; |
|
| 327 | + if ($field->getType() === FieldType::FILE) { |
|
| 328 | + |
|
| 329 | + if ($field->hasMany()) { |
|
| 330 | + $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this); |
|
| 331 | + |
|
| 332 | + $resolvedValue = array(); |
|
| 333 | + foreach ($files as $file) { |
|
| 334 | + $resolvedValue[] = $file->getIdentifier(); |
|
| 335 | + } |
|
| 336 | + } else { |
|
| 337 | + $files = FileReferenceService::getInstance()->findReferencedBy($propertyName, $this); |
|
| 338 | + if (!empty($files)) { |
|
| 339 | + $resolvedValue = current($files)->getIdentifier(); |
|
| 340 | + } |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + // Reset value |
|
| 344 | + $result[$fieldName] = $resolvedValue; |
|
| 345 | + |
|
| 346 | + } elseif (Tca::table($this->dataType)->field($fieldName)->hasRelation()) { |
|
| 347 | + $objects = $this[$fieldName]; |
|
| 348 | + if (is_array($objects)) { |
|
| 349 | + $resolvedValue = array(); |
|
| 350 | + foreach ($objects as $object) { |
|
| 351 | + /** @var $object Content */ |
|
| 352 | + $labelField = Tca::table($object->getDataType())->getLabelField(); |
|
| 353 | + $resolvedValue[] = $object[$labelField]; |
|
| 354 | + } |
|
| 355 | + } elseif ($objects instanceof Content) { |
|
| 356 | + $labelField = Tca::table($objects->getDataType())->getLabelField(); |
|
| 357 | + $resolvedValue = $objects[$labelField]; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + // Reset value |
|
| 361 | + $result[$fieldName] = $resolvedValue; |
|
| 362 | + } |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + return $result; |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + /** |
|
| 370 | + * Return the properties of this object. |
|
| 371 | + * |
|
| 372 | + * @return array |
|
| 373 | + */ |
|
| 374 | + public function toProperties() |
|
| 375 | + { |
|
| 376 | + $result[] = 'uid'; |
|
| 377 | + $propertiesAndValues = json_decode(json_encode($this), TRUE); |
|
| 378 | + |
|
| 379 | + foreach ($propertiesAndValues as $propertyName => $value) { |
|
| 380 | + $result[] = $propertyName; |
|
| 381 | + } |
|
| 382 | + return $result; |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Return the properties of this object. |
|
| 387 | + * |
|
| 388 | + * @return array |
|
| 389 | + */ |
|
| 390 | + public function toFields() |
|
| 391 | + { |
|
| 392 | + $result[] = 'uid'; |
|
| 393 | + $propertiesAndValues = json_decode(json_encode($this), TRUE); |
|
| 394 | + |
|
| 395 | + foreach ($propertiesAndValues as $propertyName => $value) { |
|
| 396 | + $result[] = Property::name($propertyName)->of($this)->toFieldName(); |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + return $result; |
|
| 400 | + } |
|
| 401 | + |
|
| 402 | + /** |
|
| 403 | + * @return string |
|
| 404 | + */ |
|
| 405 | + public function __toString() |
|
| 406 | + { |
|
| 407 | + $labelField = Tca::table($this->dataType)->getLabelField(); |
|
| 408 | + return $this[$labelField]; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + /** |
|
| 412 | + * Remove fields according to BE User permission. |
|
| 413 | + * |
|
| 414 | + * @param $fields |
|
| 415 | + * @return array |
|
| 416 | + * @throws \Exception |
|
| 417 | + */ |
|
| 418 | + protected function filterForBackendUser($fields) |
|
| 419 | + { |
|
| 420 | + if (!$this->getBackendUser()->isAdmin()) { |
|
| 421 | + foreach ($fields as $key => $fieldName) { |
|
| 422 | + if (Tca::table($this->dataType)->hasField($fieldName) && !Tca::table($this->dataType)->field($fieldName)->hasAccess()) { |
|
| 423 | + unset($fields[$key]); |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + } |
|
| 427 | + return $fields; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Remove fields according to Grid configuration. |
|
| 432 | + * |
|
| 433 | + * @param $fields |
|
| 434 | + * @return array |
|
| 435 | + */ |
|
| 436 | + protected function filterForConfiguration($fields) |
|
| 437 | + { |
|
| 438 | + |
|
| 439 | + $excludedFields = Tca::grid($this->dataType)->getExcludedFields(); |
|
| 440 | + foreach ($fields as $key => $field) { |
|
| 441 | + if (in_array($field, $excludedFields)) { |
|
| 442 | + unset($fields[$key]); |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + |
|
| 446 | + return $fields; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + /** |
|
| 450 | + * Returns an instance of the current Backend User. |
|
| 451 | + * |
|
| 452 | + * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 453 | + */ |
|
| 454 | + protected function getBackendUser() |
|
| 455 | + { |
|
| 456 | + return $GLOBALS['BE_USER']; |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + /** |
|
| 460 | + * Returns whether the current mode is Backend |
|
| 461 | + * |
|
| 462 | + * @return bool |
|
| 463 | + */ |
|
| 464 | + protected function isBackendMode() |
|
| 465 | + { |
|
| 466 | + return TYPO3_MODE == 'BE'; |
|
| 467 | + } |
|
| 468 | 468 | |
| 469 | 469 | } |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | * |
| 82 | 82 | * @param string $tableName |
| 83 | 83 | * @param string $fieldName |
| 84 | - * @return array |
|
| 84 | + * @return string[] |
|
| 85 | 85 | */ |
| 86 | 86 | protected function checkRelationManyToMany($tableName, $fieldName) |
| 87 | 87 | { |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | * @param string $tableName |
| 116 | 116 | * @param string $fieldName |
| 117 | 117 | * @param string $relationType |
| 118 | - * @return array |
|
| 118 | + * @return string[] |
|
| 119 | 119 | */ |
| 120 | 120 | protected function checkRelationOf($tableName, $fieldName, $relationType) |
| 121 | 121 | { |
@@ -22,114 +22,114 @@ |
||
| 22 | 22 | class GridAnalyserService |
| 23 | 23 | { |
| 24 | 24 | |
| 25 | - /** |
|
| 26 | - * Check relation for table. |
|
| 27 | - * |
|
| 28 | - * @param $tableName |
|
| 29 | - * @return array |
|
| 30 | - */ |
|
| 31 | - public function checkRelationForTable($tableName) |
|
| 32 | - { |
|
| 25 | + /** |
|
| 26 | + * Check relation for table. |
|
| 27 | + * |
|
| 28 | + * @param $tableName |
|
| 29 | + * @return array |
|
| 30 | + */ |
|
| 31 | + public function checkRelationForTable($tableName) |
|
| 32 | + { |
|
| 33 | 33 | |
| 34 | - $relations = array(); |
|
| 35 | - $table = Tca::table($tableName); |
|
| 34 | + $relations = array(); |
|
| 35 | + $table = Tca::table($tableName); |
|
| 36 | 36 | |
| 37 | - $missingOppositionRelationMessage = <<<EOF |
|
| 37 | + $missingOppositionRelationMessage = <<<EOF |
|
| 38 | 38 | |
| 39 | 39 | WARNING! Could not define relation precisely. This is not necessarily a problem |
| 40 | 40 | if the opposite relation is not required in a Grid. But consider adding the opposite |
| 41 | 41 | TCA configuration if so. |
| 42 | 42 | EOF; |
| 43 | 43 | |
| 44 | - foreach (Tca::grid($tableName)->getFields() as $fieldName => $configuration) { |
|
| 45 | - |
|
| 46 | - if ($table->hasField($fieldName)) { |
|
| 47 | - if ($table->field($fieldName)->hasMany()) { |
|
| 48 | - if ($table->field($fieldName)->hasRelationWithCommaSeparatedValues()) { |
|
| 49 | - $_relations = $this->checkRelationOf($tableName, $fieldName, 'comma separated values'); |
|
| 50 | - $relations = array_merge($relations, $_relations); |
|
| 51 | - } elseif ($table->field($fieldName)->hasRelationManyToMany()) { |
|
| 52 | - $_relations = $this->checkRelationManyToMany($tableName, $fieldName); |
|
| 53 | - $relations = array_merge($relations, $_relations); |
|
| 54 | - |
|
| 55 | - } elseif ($table->field($fieldName)->hasRelationOneToMany()) { |
|
| 56 | - $_relations = $this->checkRelationOf($tableName, $fieldName, 'one-to-many'); |
|
| 57 | - $relations = array_merge($relations, $_relations); |
|
| 58 | - } else { |
|
| 59 | - $relations[] = sprintf('* field: "%s", relation: ?-to-many%s', $fieldName, $missingOppositionRelationMessage); |
|
| 60 | - } |
|
| 61 | - $relations[] = ''; |
|
| 62 | - } elseif ($table->field($fieldName)->hasOne()) { |
|
| 63 | - |
|
| 64 | - if ($table->field($fieldName)->hasRelationOneToOne()) { |
|
| 65 | - $relations[] = sprintf('* one-to-one "%s"', $fieldName); |
|
| 66 | - } elseif ($table->field($fieldName)->hasRelationManyToOne()) { |
|
| 67 | - $_relations = $this->checkRelationOf($tableName, $fieldName, 'many-to-one'); |
|
| 68 | - $relations = array_merge($relations, $_relations); |
|
| 69 | - } else { |
|
| 70 | - $relations[] = sprintf('* field: "%s", relation: ?-to-one%s', $fieldName, $missingOppositionRelationMessage); |
|
| 71 | - } |
|
| 72 | - $relations[] = ''; |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - return $relations; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - /** |
|
| 80 | - * Convenience method for printing out relation many-to-many. |
|
| 81 | - * |
|
| 82 | - * @param string $tableName |
|
| 83 | - * @param string $fieldName |
|
| 84 | - * @return array |
|
| 85 | - */ |
|
| 86 | - protected function checkRelationManyToMany($tableName, $fieldName) |
|
| 87 | - { |
|
| 88 | - |
|
| 89 | - $output = array(); |
|
| 90 | - |
|
| 91 | - $table = Tca::table($tableName); |
|
| 92 | - $output[] = sprintf('* field: "%s", relation: many-to-many', $fieldName); |
|
| 93 | - |
|
| 94 | - $foreignTable = $table->field($fieldName)->getForeignTable(); |
|
| 95 | - $manyToManyTable = $table->field($fieldName)->getManyToManyTable(); |
|
| 96 | - $foreignField = $table->field($fieldName)->getForeignField(); |
|
| 97 | - |
|
| 98 | - if (!$foreignField) { |
|
| 99 | - $output[] = sprintf(' ERROR! Can not found foreign field for "%s". Perhaps missing opposite configuration?', $fieldName); |
|
| 100 | - } elseif (!$foreignTable) { |
|
| 101 | - $output[] = sprintf(' ERROR! Can not found foreign table for "%s". Perhaps missing opposite configuration?', $fieldName); |
|
| 102 | - } elseif (!$manyToManyTable) { |
|
| 103 | - $output[] = sprintf(' ERROR! Can not found relation table (MM) for "%s". Perhaps missing opposite configuration?', $fieldName); |
|
| 104 | - } else { |
|
| 105 | - $output[] = sprintf(' %s.%s <--> %s <--> %s.%s', $tableName, $fieldName, $manyToManyTable, $foreignTable, $foreignField); |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - $output[] = ''; |
|
| 109 | - return $output; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Convenience method for printing out relation. |
|
| 114 | - * |
|
| 115 | - * @param string $tableName |
|
| 116 | - * @param string $fieldName |
|
| 117 | - * @param string $relationType |
|
| 118 | - * @return array |
|
| 119 | - */ |
|
| 120 | - protected function checkRelationOf($tableName, $fieldName, $relationType) |
|
| 121 | - { |
|
| 122 | - |
|
| 123 | - $output = array(); |
|
| 124 | - |
|
| 125 | - $table = Tca::table($tableName); |
|
| 126 | - $output[] = sprintf('* field: "%s", relation: %s', $fieldName, $relationType); |
|
| 127 | - |
|
| 128 | - $foreignTable = $table->field($fieldName)->getForeignTable(); |
|
| 129 | - $foreignField = $table->field($fieldName)->getForeignField(); |
|
| 130 | - $output[] = sprintf(' %s.%s <--> %s.%s', $tableName, $fieldName, $foreignTable, $foreignField); |
|
| 131 | - $output[] = ''; |
|
| 132 | - |
|
| 133 | - return $output; |
|
| 134 | - } |
|
| 44 | + foreach (Tca::grid($tableName)->getFields() as $fieldName => $configuration) { |
|
| 45 | + |
|
| 46 | + if ($table->hasField($fieldName)) { |
|
| 47 | + if ($table->field($fieldName)->hasMany()) { |
|
| 48 | + if ($table->field($fieldName)->hasRelationWithCommaSeparatedValues()) { |
|
| 49 | + $_relations = $this->checkRelationOf($tableName, $fieldName, 'comma separated values'); |
|
| 50 | + $relations = array_merge($relations, $_relations); |
|
| 51 | + } elseif ($table->field($fieldName)->hasRelationManyToMany()) { |
|
| 52 | + $_relations = $this->checkRelationManyToMany($tableName, $fieldName); |
|
| 53 | + $relations = array_merge($relations, $_relations); |
|
| 54 | + |
|
| 55 | + } elseif ($table->field($fieldName)->hasRelationOneToMany()) { |
|
| 56 | + $_relations = $this->checkRelationOf($tableName, $fieldName, 'one-to-many'); |
|
| 57 | + $relations = array_merge($relations, $_relations); |
|
| 58 | + } else { |
|
| 59 | + $relations[] = sprintf('* field: "%s", relation: ?-to-many%s', $fieldName, $missingOppositionRelationMessage); |
|
| 60 | + } |
|
| 61 | + $relations[] = ''; |
|
| 62 | + } elseif ($table->field($fieldName)->hasOne()) { |
|
| 63 | + |
|
| 64 | + if ($table->field($fieldName)->hasRelationOneToOne()) { |
|
| 65 | + $relations[] = sprintf('* one-to-one "%s"', $fieldName); |
|
| 66 | + } elseif ($table->field($fieldName)->hasRelationManyToOne()) { |
|
| 67 | + $_relations = $this->checkRelationOf($tableName, $fieldName, 'many-to-one'); |
|
| 68 | + $relations = array_merge($relations, $_relations); |
|
| 69 | + } else { |
|
| 70 | + $relations[] = sprintf('* field: "%s", relation: ?-to-one%s', $fieldName, $missingOppositionRelationMessage); |
|
| 71 | + } |
|
| 72 | + $relations[] = ''; |
|
| 73 | + } |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + return $relations; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + /** |
|
| 80 | + * Convenience method for printing out relation many-to-many. |
|
| 81 | + * |
|
| 82 | + * @param string $tableName |
|
| 83 | + * @param string $fieldName |
|
| 84 | + * @return array |
|
| 85 | + */ |
|
| 86 | + protected function checkRelationManyToMany($tableName, $fieldName) |
|
| 87 | + { |
|
| 88 | + |
|
| 89 | + $output = array(); |
|
| 90 | + |
|
| 91 | + $table = Tca::table($tableName); |
|
| 92 | + $output[] = sprintf('* field: "%s", relation: many-to-many', $fieldName); |
|
| 93 | + |
|
| 94 | + $foreignTable = $table->field($fieldName)->getForeignTable(); |
|
| 95 | + $manyToManyTable = $table->field($fieldName)->getManyToManyTable(); |
|
| 96 | + $foreignField = $table->field($fieldName)->getForeignField(); |
|
| 97 | + |
|
| 98 | + if (!$foreignField) { |
|
| 99 | + $output[] = sprintf(' ERROR! Can not found foreign field for "%s". Perhaps missing opposite configuration?', $fieldName); |
|
| 100 | + } elseif (!$foreignTable) { |
|
| 101 | + $output[] = sprintf(' ERROR! Can not found foreign table for "%s". Perhaps missing opposite configuration?', $fieldName); |
|
| 102 | + } elseif (!$manyToManyTable) { |
|
| 103 | + $output[] = sprintf(' ERROR! Can not found relation table (MM) for "%s". Perhaps missing opposite configuration?', $fieldName); |
|
| 104 | + } else { |
|
| 105 | + $output[] = sprintf(' %s.%s <--> %s <--> %s.%s', $tableName, $fieldName, $manyToManyTable, $foreignTable, $foreignField); |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + $output[] = ''; |
|
| 109 | + return $output; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Convenience method for printing out relation. |
|
| 114 | + * |
|
| 115 | + * @param string $tableName |
|
| 116 | + * @param string $fieldName |
|
| 117 | + * @param string $relationType |
|
| 118 | + * @return array |
|
| 119 | + */ |
|
| 120 | + protected function checkRelationOf($tableName, $fieldName, $relationType) |
|
| 121 | + { |
|
| 122 | + |
|
| 123 | + $output = array(); |
|
| 124 | + |
|
| 125 | + $table = Tca::table($tableName); |
|
| 126 | + $output[] = sprintf('* field: "%s", relation: %s', $fieldName, $relationType); |
|
| 127 | + |
|
| 128 | + $foreignTable = $table->field($fieldName)->getForeignTable(); |
|
| 129 | + $foreignField = $table->field($fieldName)->getForeignField(); |
|
| 130 | + $output[] = sprintf(' %s.%s <--> %s.%s', $tableName, $fieldName, $foreignTable, $foreignField); |
|
| 131 | + $output[] = ''; |
|
| 132 | + |
|
| 133 | + return $output; |
|
| 134 | + } |
|
| 135 | 135 | } |
@@ -109,7 +109,7 @@ |
||
| 109 | 109 | * |
| 110 | 110 | * @param Content $object |
| 111 | 111 | * @param int $language |
| 112 | - * @return string |
|
| 112 | + * @return boolean |
|
| 113 | 113 | */ |
| 114 | 114 | public function hasLocalization(Content $object, $language) |
| 115 | 115 | { |
@@ -25,178 +25,178 @@ |
||
| 25 | 25 | class LanguageService implements SingletonInterface |
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - /** |
|
| 29 | - * @var array |
|
| 30 | - */ |
|
| 31 | - protected $languages; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var array |
|
| 35 | - */ |
|
| 36 | - protected $defaultIcon; |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Store the localized records to boost up performance. |
|
| 40 | - * |
|
| 41 | - * @var array |
|
| 42 | - */ |
|
| 43 | - protected $localizedRecordStorage; |
|
| 44 | - |
|
| 45 | - /** |
|
| 46 | - * Returns available language records. |
|
| 47 | - * The method stores the records in the property to speed up the process as the method can be often called. |
|
| 48 | - * |
|
| 49 | - * @return array |
|
| 50 | - */ |
|
| 51 | - public function getLanguages() |
|
| 52 | - { |
|
| 53 | - if (is_null($this->languages)) { |
|
| 54 | - |
|
| 55 | - $tableName = 'sys_language'; |
|
| 56 | - |
|
| 57 | - $clause = '1 = 1'; |
|
| 58 | - $clause .= BackendUtility::deleteClause($tableName); |
|
| 59 | - $clause .= BackendUtility::BEenableFields($tableName); |
|
| 60 | - $this->languages = $this->getDatabaseConnection()->exec_SELECTgetRows('*', $tableName, $clause); |
|
| 61 | - } |
|
| 62 | - return $this->languages; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Returns a localized record according to a Content object and a language identifier. |
|
| 67 | - * Notice! This method does not overlay anything but simply returns the raw localized record. |
|
| 68 | - * |
|
| 69 | - * @param Content $object |
|
| 70 | - * @param int $language |
|
| 71 | - * @return Content |
|
| 72 | - */ |
|
| 73 | - public function getLocalizedContent(Content $object, $language) |
|
| 74 | - { |
|
| 75 | - |
|
| 76 | - // We want to cache data per Content object. Retrieve the Object hash. |
|
| 77 | - $objectHash = spl_object_hash($object); |
|
| 78 | - |
|
| 79 | - // Initialize the storage |
|
| 80 | - if (empty($this->localizedRecordStorage[$objectHash])) { |
|
| 81 | - $this->localizedRecordStorage[$objectHash] = array(); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - if (empty($this->localizedRecordStorage[$objectHash][$language])) { |
|
| 85 | - |
|
| 86 | - $clause = sprintf('%s = %s AND %s = %s', |
|
| 87 | - Tca::table($object)->getLanguageParentField(), // e.g. l10n_parent |
|
| 88 | - $object->getUid(), |
|
| 89 | - Tca::table($object)->getLanguageField(), // e.g. sys_language_uid |
|
| 90 | - $language |
|
| 91 | - ); |
|
| 92 | - |
|
| 93 | - $clause .= BackendUtility::deleteClause($object->getDataType()); |
|
| 94 | - $localizedRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', $object->getDataType(), $clause); |
|
| 95 | - |
|
| 96 | - if ($localizedRecord) { |
|
| 97 | - $localizedContent = GeneralUtility::makeInstance('Fab\Vidi\Domain\Model\Content', $object->getDataType(), $localizedRecord); |
|
| 98 | - $this->localizedRecordStorage[$objectHash][$language] = $localizedContent; |
|
| 99 | - } else { |
|
| 100 | - $this->localizedRecordStorage[$objectHash][$language] = array(); // We want an array at least, even if empty. |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return $this->localizedRecordStorage[$objectHash][$language]; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Tell whether the given Content object has a localization. |
|
| 109 | - * |
|
| 110 | - * @param Content $object |
|
| 111 | - * @param int $language |
|
| 112 | - * @return string |
|
| 113 | - */ |
|
| 114 | - public function hasLocalization(Content $object, $language) |
|
| 115 | - { |
|
| 116 | - $localizedRecord = $this->getLocalizedContent($object, $language); |
|
| 117 | - return !empty($localizedRecord); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - /** |
|
| 121 | - * Returns a localized field according to a Content object and a language identifier. |
|
| 122 | - * Notice! If there is not translation, simply returns an empty string. |
|
| 123 | - * |
|
| 124 | - * @param Content $object |
|
| 125 | - * @param int $language |
|
| 126 | - * @param string $fieldName |
|
| 127 | - * @return string |
|
| 128 | - */ |
|
| 129 | - public function getLocalizedFieldName(Content $object, $language, $fieldName) |
|
| 130 | - { |
|
| 131 | - $localizedRecord = $this->getLocalizedContent($object, $language); |
|
| 132 | - return empty($localizedRecord) ? '' : $localizedRecord[$fieldName]; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Returns the default language configured by TSConfig. |
|
| 137 | - * |
|
| 138 | - * @return array |
|
| 139 | - */ |
|
| 140 | - public function getDefaultFlag() |
|
| 141 | - { |
|
| 142 | - |
|
| 143 | - if (is_null($this->defaultIcon)) { |
|
| 144 | - |
|
| 145 | - $defaultFlag = ''; // default value |
|
| 146 | - |
|
| 147 | - $tsConfig = BackendUtility::getModTSconfig(0, 'mod.SHARED'); |
|
| 148 | - |
|
| 149 | - // Fallback non sprite-configuration |
|
| 150 | - if (($pos = strrpos($tsConfig['properties']['defaultLanguageFlag'], '.')) !== FALSE) { |
|
| 151 | - $defaultFlag = substr($tsConfig['properties']['defaultLanguageFlag'], 0, $pos); |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - $this->defaultIcon = $defaultFlag; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - return $this->defaultIcon; |
|
| 158 | - } |
|
| 159 | - |
|
| 160 | - /** |
|
| 161 | - * Returns whether the system includes language records. |
|
| 162 | - * |
|
| 163 | - * @return bool |
|
| 164 | - */ |
|
| 165 | - public function hasLanguages() |
|
| 166 | - { |
|
| 167 | - $languages = $this->getLanguages(); |
|
| 168 | - return !empty($languages); |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - /** |
|
| 172 | - * Tell whether the given language exists. |
|
| 173 | - * |
|
| 174 | - * @param int $language |
|
| 175 | - * @return bool |
|
| 176 | - */ |
|
| 177 | - public function languageExists($language) |
|
| 178 | - { |
|
| 179 | - $languages = $this->getLanguages(); |
|
| 180 | - |
|
| 181 | - $LanguageExists = FALSE; |
|
| 182 | - foreach ($languages as $_language) { |
|
| 183 | - if ((int)$_language['uid'] === (int)$language) { |
|
| 184 | - $LanguageExists = TRUE; |
|
| 185 | - break; |
|
| 186 | - } |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - return $LanguageExists; |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - /** |
|
| 193 | - * Returns a pointer to the database. |
|
| 194 | - * |
|
| 195 | - * @return \TYPO3\CMS\Core\Database\DatabaseConnection |
|
| 196 | - */ |
|
| 197 | - protected function getDatabaseConnection() |
|
| 198 | - { |
|
| 199 | - return $GLOBALS['TYPO3_DB']; |
|
| 200 | - } |
|
| 28 | + /** |
|
| 29 | + * @var array |
|
| 30 | + */ |
|
| 31 | + protected $languages; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var array |
|
| 35 | + */ |
|
| 36 | + protected $defaultIcon; |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Store the localized records to boost up performance. |
|
| 40 | + * |
|
| 41 | + * @var array |
|
| 42 | + */ |
|
| 43 | + protected $localizedRecordStorage; |
|
| 44 | + |
|
| 45 | + /** |
|
| 46 | + * Returns available language records. |
|
| 47 | + * The method stores the records in the property to speed up the process as the method can be often called. |
|
| 48 | + * |
|
| 49 | + * @return array |
|
| 50 | + */ |
|
| 51 | + public function getLanguages() |
|
| 52 | + { |
|
| 53 | + if (is_null($this->languages)) { |
|
| 54 | + |
|
| 55 | + $tableName = 'sys_language'; |
|
| 56 | + |
|
| 57 | + $clause = '1 = 1'; |
|
| 58 | + $clause .= BackendUtility::deleteClause($tableName); |
|
| 59 | + $clause .= BackendUtility::BEenableFields($tableName); |
|
| 60 | + $this->languages = $this->getDatabaseConnection()->exec_SELECTgetRows('*', $tableName, $clause); |
|
| 61 | + } |
|
| 62 | + return $this->languages; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Returns a localized record according to a Content object and a language identifier. |
|
| 67 | + * Notice! This method does not overlay anything but simply returns the raw localized record. |
|
| 68 | + * |
|
| 69 | + * @param Content $object |
|
| 70 | + * @param int $language |
|
| 71 | + * @return Content |
|
| 72 | + */ |
|
| 73 | + public function getLocalizedContent(Content $object, $language) |
|
| 74 | + { |
|
| 75 | + |
|
| 76 | + // We want to cache data per Content object. Retrieve the Object hash. |
|
| 77 | + $objectHash = spl_object_hash($object); |
|
| 78 | + |
|
| 79 | + // Initialize the storage |
|
| 80 | + if (empty($this->localizedRecordStorage[$objectHash])) { |
|
| 81 | + $this->localizedRecordStorage[$objectHash] = array(); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + if (empty($this->localizedRecordStorage[$objectHash][$language])) { |
|
| 85 | + |
|
| 86 | + $clause = sprintf('%s = %s AND %s = %s', |
|
| 87 | + Tca::table($object)->getLanguageParentField(), // e.g. l10n_parent |
|
| 88 | + $object->getUid(), |
|
| 89 | + Tca::table($object)->getLanguageField(), // e.g. sys_language_uid |
|
| 90 | + $language |
|
| 91 | + ); |
|
| 92 | + |
|
| 93 | + $clause .= BackendUtility::deleteClause($object->getDataType()); |
|
| 94 | + $localizedRecord = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('*', $object->getDataType(), $clause); |
|
| 95 | + |
|
| 96 | + if ($localizedRecord) { |
|
| 97 | + $localizedContent = GeneralUtility::makeInstance('Fab\Vidi\Domain\Model\Content', $object->getDataType(), $localizedRecord); |
|
| 98 | + $this->localizedRecordStorage[$objectHash][$language] = $localizedContent; |
|
| 99 | + } else { |
|
| 100 | + $this->localizedRecordStorage[$objectHash][$language] = array(); // We want an array at least, even if empty. |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return $this->localizedRecordStorage[$objectHash][$language]; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Tell whether the given Content object has a localization. |
|
| 109 | + * |
|
| 110 | + * @param Content $object |
|
| 111 | + * @param int $language |
|
| 112 | + * @return string |
|
| 113 | + */ |
|
| 114 | + public function hasLocalization(Content $object, $language) |
|
| 115 | + { |
|
| 116 | + $localizedRecord = $this->getLocalizedContent($object, $language); |
|
| 117 | + return !empty($localizedRecord); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + /** |
|
| 121 | + * Returns a localized field according to a Content object and a language identifier. |
|
| 122 | + * Notice! If there is not translation, simply returns an empty string. |
|
| 123 | + * |
|
| 124 | + * @param Content $object |
|
| 125 | + * @param int $language |
|
| 126 | + * @param string $fieldName |
|
| 127 | + * @return string |
|
| 128 | + */ |
|
| 129 | + public function getLocalizedFieldName(Content $object, $language, $fieldName) |
|
| 130 | + { |
|
| 131 | + $localizedRecord = $this->getLocalizedContent($object, $language); |
|
| 132 | + return empty($localizedRecord) ? '' : $localizedRecord[$fieldName]; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Returns the default language configured by TSConfig. |
|
| 137 | + * |
|
| 138 | + * @return array |
|
| 139 | + */ |
|
| 140 | + public function getDefaultFlag() |
|
| 141 | + { |
|
| 142 | + |
|
| 143 | + if (is_null($this->defaultIcon)) { |
|
| 144 | + |
|
| 145 | + $defaultFlag = ''; // default value |
|
| 146 | + |
|
| 147 | + $tsConfig = BackendUtility::getModTSconfig(0, 'mod.SHARED'); |
|
| 148 | + |
|
| 149 | + // Fallback non sprite-configuration |
|
| 150 | + if (($pos = strrpos($tsConfig['properties']['defaultLanguageFlag'], '.')) !== FALSE) { |
|
| 151 | + $defaultFlag = substr($tsConfig['properties']['defaultLanguageFlag'], 0, $pos); |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + $this->defaultIcon = $defaultFlag; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + return $this->defaultIcon; |
|
| 158 | + } |
|
| 159 | + |
|
| 160 | + /** |
|
| 161 | + * Returns whether the system includes language records. |
|
| 162 | + * |
|
| 163 | + * @return bool |
|
| 164 | + */ |
|
| 165 | + public function hasLanguages() |
|
| 166 | + { |
|
| 167 | + $languages = $this->getLanguages(); |
|
| 168 | + return !empty($languages); |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + /** |
|
| 172 | + * Tell whether the given language exists. |
|
| 173 | + * |
|
| 174 | + * @param int $language |
|
| 175 | + * @return bool |
|
| 176 | + */ |
|
| 177 | + public function languageExists($language) |
|
| 178 | + { |
|
| 179 | + $languages = $this->getLanguages(); |
|
| 180 | + |
|
| 181 | + $LanguageExists = FALSE; |
|
| 182 | + foreach ($languages as $_language) { |
|
| 183 | + if ((int)$_language['uid'] === (int)$language) { |
|
| 184 | + $LanguageExists = TRUE; |
|
| 185 | + break; |
|
| 186 | + } |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + return $LanguageExists; |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + /** |
|
| 193 | + * Returns a pointer to the database. |
|
| 194 | + * |
|
| 195 | + * @return \TYPO3\CMS\Core\Database\DatabaseConnection |
|
| 196 | + */ |
|
| 197 | + protected function getDatabaseConnection() |
|
| 198 | + { |
|
| 199 | + return $GLOBALS['TYPO3_DB']; |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | 202 | } |
@@ -242,7 +242,7 @@ |
||
| 242 | 242 | /** |
| 243 | 243 | * Returns the current pid. |
| 244 | 244 | * |
| 245 | - * @return bool |
|
| 245 | + * @return integer |
|
| 246 | 246 | */ |
| 247 | 247 | public function getCurrentPid() |
| 248 | 248 | { |
@@ -26,900 +26,900 @@ |
||
| 26 | 26 | class ModuleLoader |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Define the default main module |
|
| 31 | - */ |
|
| 32 | - const DEFAULT_MAIN_MODULE = 'content'; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * Define the default pid |
|
| 36 | - */ |
|
| 37 | - const DEFAULT_PID = 0; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * The type of data being listed (which corresponds to a table name in TCA) |
|
| 41 | - * |
|
| 42 | - * @var string |
|
| 43 | - */ |
|
| 44 | - protected $dataType; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * @var string |
|
| 48 | - */ |
|
| 49 | - protected $defaultPid; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @var bool |
|
| 53 | - */ |
|
| 54 | - protected $showPageTree; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * @var bool |
|
| 58 | - */ |
|
| 59 | - protected $isShown = TRUE; |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * @var string |
|
| 63 | - */ |
|
| 64 | - protected $access = Access::USER; |
|
| 65 | - |
|
| 66 | - /** |
|
| 67 | - * @var string |
|
| 68 | - */ |
|
| 69 | - protected $mainModule; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var string |
|
| 73 | - */ |
|
| 74 | - protected $position = ''; |
|
| 75 | - |
|
| 76 | - /** |
|
| 77 | - * @var string |
|
| 78 | - */ |
|
| 79 | - protected $icon = ''; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * @var string |
|
| 83 | - */ |
|
| 84 | - protected $moduleLanguageFile = 'LLL:EXT:vidi/Resources/Private/Language/locallang_module.xlf'; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * The module key such as m1, m2. |
|
| 88 | - * |
|
| 89 | - * @var string |
|
| 90 | - */ |
|
| 91 | - protected $moduleKey = 'm1'; |
|
| 92 | - |
|
| 93 | - /** |
|
| 94 | - * @var string[] |
|
| 95 | - */ |
|
| 96 | - protected $additionalJavaScriptFiles = array(); |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * @var string[] |
|
| 100 | - */ |
|
| 101 | - protected $additionalStyleSheetFiles = array(); |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * @var array |
|
| 105 | - */ |
|
| 106 | - protected $components = array( |
|
| 107 | - ModulePosition::DOC_HEADER => array( |
|
| 108 | - ModulePosition::TOP => array( |
|
| 109 | - ModulePosition::LEFT => array(), |
|
| 110 | - ModulePosition::RIGHT => array( |
|
| 111 | - 'Fab\Vidi\View\Button\ToolButton', |
|
| 112 | - ), |
|
| 113 | - ), |
|
| 114 | - ModulePosition::BOTTOM => array( |
|
| 115 | - ModulePosition::LEFT => array( |
|
| 116 | - 'Fab\Vidi\View\Button\NewButton', |
|
| 117 | - 'Fab\Vidi\ViewHelpers\Link\BackViewHelper', |
|
| 118 | - ), |
|
| 119 | - ModulePosition::RIGHT => array(), |
|
| 120 | - ), |
|
| 121 | - ), |
|
| 122 | - ModulePosition::GRID => array( |
|
| 123 | - ModulePosition::TOP => array( |
|
| 124 | - 'Fab\Vidi\View\Check\PidCheck', |
|
| 125 | - 'Fab\Vidi\View\Check\RelationsCheck', |
|
| 126 | - 'Fab\Vidi\View\Tab\DataTypeTab', |
|
| 127 | - ), |
|
| 128 | - ModulePosition::BUTTONS => array( |
|
| 129 | - 'Fab\Vidi\View\Button\EditButton', |
|
| 130 | - 'Fab\Vidi\View\Button\DeleteButton', |
|
| 131 | - ), |
|
| 132 | - ModulePosition::BOTTOM => array(), |
|
| 133 | - ), |
|
| 134 | - ModulePosition::MENU_MASS_ACTION => array( |
|
| 135 | - 'Fab\Vidi\View\MenuItem\ExportXlsMenuItem', |
|
| 136 | - 'Fab\Vidi\View\MenuItem\ExportXmlMenuItem', |
|
| 137 | - 'Fab\Vidi\View\MenuItem\ExportCsvMenuItem', |
|
| 138 | - 'Fab\Vidi\View\MenuItem\DividerMenuItem', |
|
| 139 | - 'Fab\Vidi\View\MenuItem\MassDeleteMenuItem', |
|
| 140 | - #'Fab\Vidi\View\MenuItem\MassEditMenuItem', |
|
| 141 | - ), |
|
| 142 | - ); |
|
| 143 | - |
|
| 144 | - /** |
|
| 145 | - * @param string $dataType |
|
| 146 | - */ |
|
| 147 | - public function __construct($dataType = null) |
|
| 148 | - { |
|
| 149 | - $this->dataType = $dataType; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Tell whether a module is already registered. |
|
| 154 | - * |
|
| 155 | - * @param string $dataType |
|
| 156 | - * @return bool |
|
| 157 | - */ |
|
| 158 | - public function isRegistered($dataType) |
|
| 159 | - { |
|
| 160 | - $internalModuleSignature = $this->getInternalModuleSignature($dataType); |
|
| 161 | - return !empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]); |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - /** |
|
| 165 | - * Register the module |
|
| 166 | - * |
|
| 167 | - * @return void |
|
| 168 | - */ |
|
| 169 | - public function register() |
|
| 170 | - { |
|
| 171 | - |
|
| 172 | - $this->initializeDefaultValues(); |
|
| 173 | - $internalModuleSignature = $this->getInternalModuleSignature(); |
|
| 174 | - |
|
| 175 | - $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature] = array(); |
|
| 176 | - $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['dataType'] = $this->dataType; |
|
| 177 | - $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['mainModule'] = $this->mainModule; |
|
| 178 | - $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['defaultPid'] = $this->defaultPid; |
|
| 179 | - $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['additionalJavaScriptFiles'] = $this->additionalJavaScriptFiles; |
|
| 180 | - $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['additionalStyleSheetFiles'] = $this->additionalStyleSheetFiles; |
|
| 181 | - $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['components'] = $this->components; |
|
| 182 | - |
|
| 183 | - // Register and displays module in the BE only if told, default is TRUE. |
|
| 184 | - if ($this->isShown) { |
|
| 185 | - $moduleConfiguration = array( |
|
| 186 | - #'routeTarget' => \Fab\Vidi\Controller\ContentController::class . '::mainAction', // what to do here? |
|
| 187 | - 'access' => $this->access, |
|
| 188 | - 'labels' => $this->moduleLanguageFile, |
|
| 189 | - 'inheritNavigationComponentFromMainModule' => TRUE |
|
| 190 | - ); |
|
| 191 | - |
|
| 192 | - if (!empty($this->icon)) { |
|
| 193 | - $moduleConfiguration['icon'] = $this->icon; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (!is_null($this->showPageTree)) { |
|
| 197 | - if ($this->showPageTree) { |
|
| 198 | - $moduleConfiguration['navigationComponentId'] = 'typo3-pagetree'; |
|
| 199 | - } else { |
|
| 200 | - $moduleConfiguration['inheritNavigationComponentFromMainModule'] = FALSE; |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - ExtensionUtility::registerModule( |
|
| 205 | - 'Fab.vidi', |
|
| 206 | - $this->mainModule, |
|
| 207 | - $this->dataType . '_' . $this->moduleKey, |
|
| 208 | - $this->position, |
|
| 209 | - array( |
|
| 210 | - 'Content' => 'index, list, delete, update, edit, copy, move, localize, sort, copyClipboard, moveClipboard', |
|
| 211 | - 'Tool' => 'welcome, work', |
|
| 212 | - 'Facet' => 'autoSuggest, autoSuggests', |
|
| 213 | - 'Selection' => 'edit, update, create, delete, list, show', |
|
| 214 | - 'UserPreferences' => 'save', |
|
| 215 | - 'Clipboard' => 'save, flush, show', |
|
| 216 | - ), |
|
| 217 | - $moduleConfiguration |
|
| 218 | - ); |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - /** |
|
| 223 | - * Return the module code for a BE module. |
|
| 224 | - * |
|
| 225 | - * @return string |
|
| 226 | - */ |
|
| 227 | - public function getSignature() |
|
| 228 | - { |
|
| 229 | - return GeneralUtility::_GP(Parameter::MODULE); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - /** |
|
| 233 | - * Tell whether the current module is the list one. |
|
| 234 | - * |
|
| 235 | - * @return bool |
|
| 236 | - */ |
|
| 237 | - public function copeWithPageTree() |
|
| 238 | - { |
|
| 239 | - return GeneralUtility::_GP(Parameter::MODULE) === 'web_VidiM1'; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Returns the current pid. |
|
| 244 | - * |
|
| 245 | - * @return bool |
|
| 246 | - */ |
|
| 247 | - public function getCurrentPid() |
|
| 248 | - { |
|
| 249 | - return GeneralUtility::_GET(Parameter::PID) > 0 ? (int)GeneralUtility::_GET(Parameter::PID) : 0; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Return the Vidi module code which is stored in TBE_MODULES_EXT |
|
| 254 | - * |
|
| 255 | - * @return string |
|
| 256 | - */ |
|
| 257 | - public function getVidiModuleCode() |
|
| 258 | - { |
|
| 259 | - |
|
| 260 | - if ($this->copeWithPageTree()) { |
|
| 261 | - $userPreferenceKey = sprintf('Vidi_pid_%s', $this->getCurrentPid()); |
|
| 262 | - |
|
| 263 | - if (GeneralUtility::_GP(Parameter::SUBMODULE)) { |
|
| 264 | - $subModuleCode = GeneralUtility::_GP(Parameter::SUBMODULE); |
|
| 265 | - BackendUserPreferenceService::getInstance()->set($userPreferenceKey, $subModuleCode); |
|
| 266 | - } else { |
|
| 267 | - |
|
| 268 | - $defaultModuleCode = BackendUserPreferenceService::getInstance()->get($userPreferenceKey); |
|
| 269 | - if (empty($defaultModuleCode)) { |
|
| 270 | - $defaultModuleCode = 'VidiTtContentM1'; // hard-coded submodule |
|
| 271 | - BackendUserPreferenceService::getInstance()->set($userPreferenceKey, $defaultModuleCode); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - $vidiModules = ModuleService::getInstance()->getModulesForCurrentPid(); |
|
| 275 | - |
|
| 276 | - if (empty($vidiModules)) { |
|
| 277 | - $subModuleCode = $defaultModuleCode; |
|
| 278 | - } elseif (isset($vidiModules[$defaultModuleCode])) { |
|
| 279 | - $subModuleCode = $defaultModuleCode; |
|
| 280 | - } else { |
|
| 281 | - $subModuleCode = ModuleService::getInstance()->getFirstModuleForPid($this->getCurrentPid()); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - } else { |
|
| 285 | - $moduleCode = $this->getSignature(); |
|
| 286 | - |
|
| 287 | - // Remove first part which is separated "_" |
|
| 288 | - $delimiter = strpos($moduleCode, '_') + 1; |
|
| 289 | - $subModuleCode = substr($moduleCode, $delimiter); |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - return $subModuleCode; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - /** |
|
| 296 | - * Return the module URL. |
|
| 297 | - * |
|
| 298 | - * @param array $additionalParameters |
|
| 299 | - * @param bool $absoluteUrl |
|
| 300 | - * @return string |
|
| 301 | - */ |
|
| 302 | - public function getModuleUrl(array $additionalParameters = array(), $absoluteUrl = false) |
|
| 303 | - { |
|
| 304 | - $moduleCode = $this->getSignature(); |
|
| 305 | - |
|
| 306 | - // Add possible submodule if current module has page tree. |
|
| 307 | - if ($this->copeWithPageTree() && !isset($additionalParameters[Parameter::SUBMODULE])) { |
|
| 308 | - $additionalParameters[Parameter::SUBMODULE] = $this->getVidiModuleCode(); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - // And don't forget the pid! |
|
| 312 | - if (GeneralUtility::_GET(Parameter::PID)) { |
|
| 313 | - $additionalParameters[Parameter::PID] = GeneralUtility::_GET(Parameter::PID); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - $moduleUrl = BackendUtility::getModuleUrl($moduleCode, $additionalParameters, false, $absoluteUrl); |
|
| 317 | - return $moduleUrl; |
|
| 318 | - } |
|
| 319 | - |
|
| 320 | - /** |
|
| 321 | - * Return the module absolute URL. |
|
| 322 | - * |
|
| 323 | - * @param array $additionalParameters |
|
| 324 | - * @return string |
|
| 325 | - */ |
|
| 326 | - public function getModuleAbsoluteUrl(array $additionalParameters = array()) |
|
| 327 | - { |
|
| 328 | - return $this->getModuleUrl($additionalParameters, true); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * Return the parameter prefix for a BE module. |
|
| 333 | - * |
|
| 334 | - * @return string |
|
| 335 | - */ |
|
| 336 | - public function getParameterPrefix() |
|
| 337 | - { |
|
| 338 | - return 'tx_vidi_' . strtolower($this->getSignature()); |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Return a configuration key or the entire module configuration array if not key is given. |
|
| 343 | - * |
|
| 344 | - * @param string $key |
|
| 345 | - * @throws InvalidKeyInArrayException |
|
| 346 | - * @return mixed |
|
| 347 | - */ |
|
| 348 | - public function getModuleConfiguration($key = '') |
|
| 349 | - { |
|
| 350 | - |
|
| 351 | - $vidiModuleCode = $this->getVidiModuleCode(); |
|
| 352 | - |
|
| 353 | - // Module code must exist |
|
| 354 | - if (empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode])) { |
|
| 355 | - $message = sprintf('Invalid or not existing module code "%s"', $vidiModuleCode); |
|
| 356 | - throw new InvalidKeyInArrayException($message, 1375092053); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - $result = $GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode]; |
|
| 360 | - |
|
| 361 | - if (!empty($key)) { |
|
| 362 | - if (isset($result[$key])) { |
|
| 363 | - $result = $result[$key]; |
|
| 364 | - } else { |
|
| 365 | - // key must exist |
|
| 366 | - $message = sprintf('Invalid key configuration "%s"', $key); |
|
| 367 | - throw new InvalidKeyInArrayException($message, 1375092054); |
|
| 368 | - } |
|
| 369 | - } |
|
| 370 | - return $result; |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - /** |
|
| 374 | - * @param string $icon |
|
| 375 | - * @return $this |
|
| 376 | - */ |
|
| 377 | - public function setIcon($icon) |
|
| 378 | - { |
|
| 379 | - $this->icon = $icon; |
|
| 380 | - return $this; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * @return string |
|
| 385 | - */ |
|
| 386 | - public function getIcon() |
|
| 387 | - { |
|
| 388 | - return $this->icon; |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - /** |
|
| 392 | - * @param string $mainModule |
|
| 393 | - * @return $this |
|
| 394 | - */ |
|
| 395 | - public function setMainModule($mainModule) |
|
| 396 | - { |
|
| 397 | - $this->mainModule = $mainModule; |
|
| 398 | - return $this; |
|
| 399 | - } |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * @return string |
|
| 403 | - */ |
|
| 404 | - public function getMainModule() |
|
| 405 | - { |
|
| 406 | - if (is_null($this->mainModule)) { |
|
| 407 | - $this->mainModule = $this->getModuleConfiguration('mainModule'); |
|
| 408 | - } |
|
| 409 | - return $this->mainModule; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - /** |
|
| 413 | - * @param string $moduleLanguageFile |
|
| 414 | - * @return $this |
|
| 415 | - */ |
|
| 416 | - public function setModuleLanguageFile($moduleLanguageFile) |
|
| 417 | - { |
|
| 418 | - $this->moduleLanguageFile = $moduleLanguageFile; |
|
| 419 | - return $this; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * @return string |
|
| 424 | - */ |
|
| 425 | - public function getModuleLanguageFile() |
|
| 426 | - { |
|
| 427 | - return $this->moduleLanguageFile; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * @param string $position |
|
| 432 | - * @return $this |
|
| 433 | - */ |
|
| 434 | - public function setPosition($position) |
|
| 435 | - { |
|
| 436 | - $this->position = $position; |
|
| 437 | - return $this; |
|
| 438 | - } |
|
| 439 | - |
|
| 440 | - /** |
|
| 441 | - * @return string |
|
| 442 | - */ |
|
| 443 | - public function getPosition() |
|
| 444 | - { |
|
| 445 | - return $this->position; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * @param array $files |
|
| 450 | - * @return $this |
|
| 451 | - */ |
|
| 452 | - public function addJavaScriptFiles(array $files) |
|
| 453 | - { |
|
| 454 | - foreach ($files as $file) { |
|
| 455 | - $this->additionalJavaScriptFiles[] = $file; |
|
| 456 | - } |
|
| 457 | - return $this; |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - /** |
|
| 461 | - * @param string $fileNameAndPath |
|
| 462 | - * @return $this |
|
| 463 | - */ |
|
| 464 | - public function addJavaScriptFile($fileNameAndPath) |
|
| 465 | - { |
|
| 466 | - $this->additionalJavaScriptFiles[] = $fileNameAndPath; |
|
| 467 | - return $this; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - /** |
|
| 471 | - * @param array $files |
|
| 472 | - * @return $this |
|
| 473 | - */ |
|
| 474 | - public function addStyleSheetFiles(array $files) |
|
| 475 | - { |
|
| 476 | - foreach ($files as $file) { |
|
| 477 | - $this->additionalStyleSheetFiles[] = $file; |
|
| 478 | - } |
|
| 479 | - return $this; |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * @param string $fileNameAndPath |
|
| 484 | - * @return $this |
|
| 485 | - */ |
|
| 486 | - public function addStyleSheetFile($fileNameAndPath) |
|
| 487 | - { |
|
| 488 | - $this->additionalStyleSheetFiles[] = $fileNameAndPath; |
|
| 489 | - return $this; |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * @return string |
|
| 494 | - */ |
|
| 495 | - public function getDataType() |
|
| 496 | - { |
|
| 497 | - if (is_null($this->dataType)) { |
|
| 498 | - $this->dataType = $this->getModuleConfiguration('dataType'); |
|
| 499 | - } |
|
| 500 | - return $this->dataType; |
|
| 501 | - } |
|
| 502 | - |
|
| 503 | - /** |
|
| 504 | - * @return array |
|
| 505 | - */ |
|
| 506 | - public function getDataTypes() |
|
| 507 | - { |
|
| 508 | - $dataTypes = array(); |
|
| 509 | - foreach ($GLOBALS['TBE_MODULES_EXT']['vidi'] as $module) { |
|
| 510 | - $dataTypes[] = $module['dataType']; |
|
| 511 | - } |
|
| 512 | - return $dataTypes; |
|
| 513 | - } |
|
| 514 | - |
|
| 515 | - /** |
|
| 516 | - * @param string $dataType |
|
| 517 | - * @return $this |
|
| 518 | - */ |
|
| 519 | - public function setDataType($dataType) |
|
| 520 | - { |
|
| 521 | - $this->dataType = $dataType; |
|
| 522 | - return $this; |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - /** |
|
| 526 | - * @return string |
|
| 527 | - */ |
|
| 528 | - public function getDefaultPid() |
|
| 529 | - { |
|
| 530 | - if (empty($this->defaultPid)) { |
|
| 531 | - $this->defaultPid = $this->getModuleConfiguration('defaultPid'); |
|
| 532 | - } |
|
| 533 | - return $this->defaultPid; |
|
| 534 | - } |
|
| 535 | - |
|
| 536 | - /** |
|
| 537 | - * @param string $defaultPid |
|
| 538 | - * @return $this |
|
| 539 | - */ |
|
| 540 | - public function setDefaultPid($defaultPid) |
|
| 541 | - { |
|
| 542 | - $this->defaultPid = $defaultPid; |
|
| 543 | - return $this; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * @param bool $isPageTreeShown |
|
| 548 | - * @return $this |
|
| 549 | - */ |
|
| 550 | - public function showPageTree($isPageTreeShown) |
|
| 551 | - { |
|
| 552 | - $this->showPageTree = $isPageTreeShown; |
|
| 553 | - return $this; |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * @param string $isShown |
|
| 558 | - * @return $this |
|
| 559 | - */ |
|
| 560 | - public function isShown($isShown) |
|
| 561 | - { |
|
| 562 | - $this->isShown = $isShown; |
|
| 563 | - return $this; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * @return $array |
|
| 568 | - */ |
|
| 569 | - public function getDocHeaderTopLeftComponents() |
|
| 570 | - { |
|
| 571 | - $configuration = $this->getModuleConfiguration(); |
|
| 572 | - return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT]; |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - /** |
|
| 576 | - * @param array $components |
|
| 577 | - * @return $this |
|
| 578 | - */ |
|
| 579 | - public function setDocHeaderTopLeftComponents(array $components) |
|
| 580 | - { |
|
| 581 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = $components; |
|
| 582 | - return $this; |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * @param string|array $components |
|
| 587 | - * @return $this |
|
| 588 | - */ |
|
| 589 | - public function addDocHeaderTopLeftComponents($components) |
|
| 590 | - { |
|
| 591 | - if (is_string($components)) { |
|
| 592 | - $components = array($components); |
|
| 593 | - } |
|
| 594 | - $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT]; |
|
| 595 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = array_merge($currentComponents, $components); |
|
| 596 | - return $this; |
|
| 597 | - } |
|
| 598 | - |
|
| 599 | - /** |
|
| 600 | - * @return $array |
|
| 601 | - */ |
|
| 602 | - public function getDocHeaderTopRightComponents() |
|
| 603 | - { |
|
| 604 | - $configuration = $this->getModuleConfiguration(); |
|
| 605 | - return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT]; |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - /** |
|
| 609 | - * @param array $components |
|
| 610 | - * @return $this |
|
| 611 | - */ |
|
| 612 | - public function setDocHeaderTopRightComponents(array $components) |
|
| 613 | - { |
|
| 614 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = $components; |
|
| 615 | - return $this; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * @param string|array $components |
|
| 620 | - * @return $this |
|
| 621 | - */ |
|
| 622 | - public function addDocHeaderTopRightComponents($components) |
|
| 623 | - { |
|
| 624 | - if (is_string($components)) { |
|
| 625 | - $components = array($components); |
|
| 626 | - } |
|
| 627 | - $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT]; |
|
| 628 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = array_merge($currentComponents, $components); |
|
| 629 | - return $this; |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - /** |
|
| 633 | - * @return $array |
|
| 634 | - */ |
|
| 635 | - public function getDocHeaderBottomLeftComponents() |
|
| 636 | - { |
|
| 637 | - $configuration = $this->getModuleConfiguration(); |
|
| 638 | - return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT]; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - /** |
|
| 642 | - * @param array $components |
|
| 643 | - * @return $this |
|
| 644 | - */ |
|
| 645 | - public function setDocHeaderBottomLeftComponents(array $components) |
|
| 646 | - { |
|
| 647 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = $components; |
|
| 648 | - return $this; |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - /** |
|
| 652 | - * @param string|array $components |
|
| 653 | - * @return $this |
|
| 654 | - */ |
|
| 655 | - public function addDocHeaderBottomLeftComponents($components) |
|
| 656 | - { |
|
| 657 | - if (is_string($components)) { |
|
| 658 | - $components = array($components); |
|
| 659 | - } |
|
| 660 | - $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT]; |
|
| 661 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = array_merge($currentComponents, $components); |
|
| 662 | - return $this; |
|
| 663 | - } |
|
| 664 | - |
|
| 665 | - /** |
|
| 666 | - * @return $array |
|
| 667 | - */ |
|
| 668 | - public function getDocHeaderBottomRightComponents() |
|
| 669 | - { |
|
| 670 | - $configuration = $this->getModuleConfiguration(); |
|
| 671 | - return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT]; |
|
| 672 | - } |
|
| 673 | - |
|
| 674 | - /** |
|
| 675 | - * @param array $components |
|
| 676 | - * @return $this |
|
| 677 | - */ |
|
| 678 | - public function setDocHeaderBottomRightComponents(array $components) |
|
| 679 | - { |
|
| 680 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = $components; |
|
| 681 | - return $this; |
|
| 682 | - } |
|
| 683 | - |
|
| 684 | - /** |
|
| 685 | - * @param string|array $components |
|
| 686 | - * @return $this |
|
| 687 | - */ |
|
| 688 | - public function addDocHeaderBottomRightComponents($components) |
|
| 689 | - { |
|
| 690 | - if (is_string($components)) { |
|
| 691 | - $components = array($components); |
|
| 692 | - } |
|
| 693 | - $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT]; |
|
| 694 | - $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = array_merge($currentComponents, $components); |
|
| 695 | - return $this; |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - /** |
|
| 699 | - * @return $array |
|
| 700 | - */ |
|
| 701 | - public function getGridTopComponents() |
|
| 702 | - { |
|
| 703 | - $configuration = $this->getModuleConfiguration(); |
|
| 704 | - return $configuration['components'][ModulePosition::GRID][ModulePosition::TOP]; |
|
| 705 | - } |
|
| 706 | - |
|
| 707 | - /** |
|
| 708 | - * @param array $components |
|
| 709 | - * @return $this |
|
| 710 | - */ |
|
| 711 | - public function setGridTopComponents(array $components) |
|
| 712 | - { |
|
| 713 | - $this->components[ModulePosition::GRID][ModulePosition::TOP] = $components; |
|
| 714 | - return $this; |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - /** |
|
| 718 | - * @param string|array $components |
|
| 719 | - * @return $this |
|
| 720 | - */ |
|
| 721 | - public function addGridTopComponents($components) |
|
| 722 | - { |
|
| 723 | - if (is_string($components)) { |
|
| 724 | - $components = array($components); |
|
| 725 | - } |
|
| 726 | - $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::TOP]; |
|
| 727 | - $this->components[ModulePosition::GRID][ModulePosition::TOP] = array_merge($currentComponents, $components); |
|
| 728 | - return $this; |
|
| 729 | - } |
|
| 730 | - |
|
| 731 | - /** |
|
| 732 | - * @return $array |
|
| 733 | - */ |
|
| 734 | - public function getGridBottomComponents() |
|
| 735 | - { |
|
| 736 | - $configuration = $this->getModuleConfiguration(); |
|
| 737 | - return $configuration['components'][ModulePosition::GRID][ModulePosition::BOTTOM]; |
|
| 738 | - } |
|
| 739 | - |
|
| 740 | - /** |
|
| 741 | - * @param array $components |
|
| 742 | - * @return $this |
|
| 743 | - */ |
|
| 744 | - public function setGridBottomComponents(array $components) |
|
| 745 | - { |
|
| 746 | - $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = $components; |
|
| 747 | - return $this; |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - /** |
|
| 751 | - * @param string|array $components |
|
| 752 | - * @return $this |
|
| 753 | - */ |
|
| 754 | - public function addGridBottomComponents($components) |
|
| 755 | - { |
|
| 756 | - if (is_string($components)) { |
|
| 757 | - $components = array($components); |
|
| 758 | - } |
|
| 759 | - $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BOTTOM]; |
|
| 760 | - $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = array_merge($currentComponents, $components); |
|
| 761 | - return $this; |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - /** |
|
| 765 | - * @return $array |
|
| 766 | - */ |
|
| 767 | - public function getGridButtonsComponents() |
|
| 768 | - { |
|
| 769 | - $configuration = $this->getModuleConfiguration(); |
|
| 770 | - return $configuration['components'][ModulePosition::GRID][ModulePosition::BUTTONS]; |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - /** |
|
| 774 | - * @param array $components |
|
| 775 | - * @return $this |
|
| 776 | - */ |
|
| 777 | - public function setGridButtonsComponents(array $components) |
|
| 778 | - { |
|
| 779 | - $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = $components; |
|
| 780 | - return $this; |
|
| 781 | - } |
|
| 782 | - |
|
| 783 | - /** |
|
| 784 | - * @param string|array $components |
|
| 785 | - * @return $this |
|
| 786 | - */ |
|
| 787 | - public function addGridButtonsComponents($components) |
|
| 788 | - { |
|
| 789 | - if (is_string($components)) { |
|
| 790 | - $components = array($components); |
|
| 791 | - } |
|
| 792 | - $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BUTTONS]; |
|
| 793 | - $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = array_merge($currentComponents, $components); |
|
| 794 | - return $this; |
|
| 795 | - } |
|
| 796 | - |
|
| 797 | - /** |
|
| 798 | - * @return $array |
|
| 799 | - */ |
|
| 800 | - public function getMenuMassActionComponents() |
|
| 801 | - { |
|
| 802 | - $configuration = $this->getModuleConfiguration(); |
|
| 803 | - return $configuration['components'][ModulePosition::MENU_MASS_ACTION]; |
|
| 804 | - } |
|
| 805 | - |
|
| 806 | - /** |
|
| 807 | - * @param array $components |
|
| 808 | - * @return $this |
|
| 809 | - */ |
|
| 810 | - public function setMenuMassActionComponents(array $components) |
|
| 811 | - { |
|
| 812 | - $this->components[ModulePosition::MENU_MASS_ACTION] = $components; |
|
| 813 | - return $this; |
|
| 814 | - } |
|
| 815 | - |
|
| 816 | - /** |
|
| 817 | - * @param string|array $components |
|
| 818 | - * @return $this |
|
| 819 | - */ |
|
| 820 | - public function addMenuMassActionComponents($components) |
|
| 821 | - { |
|
| 822 | - if (is_string($components)) { |
|
| 823 | - $components = array($components); |
|
| 824 | - } |
|
| 825 | - $currentComponents = $this->components[ModulePosition::MENU_MASS_ACTION]; |
|
| 826 | - $this->components[ModulePosition::MENU_MASS_ACTION] = array_merge($currentComponents, $components); |
|
| 827 | - return $this; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - /** |
|
| 831 | - * @return string |
|
| 832 | - */ |
|
| 833 | - public function getAccess() |
|
| 834 | - { |
|
| 835 | - return $this->access; |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - /** |
|
| 839 | - * @param string $access |
|
| 840 | - * @return $this |
|
| 841 | - */ |
|
| 842 | - public function setAccess($access) |
|
| 843 | - { |
|
| 844 | - $this->access = $access; |
|
| 845 | - return $this; |
|
| 846 | - } |
|
| 847 | - |
|
| 848 | - /** |
|
| 849 | - * @return \string[] |
|
| 850 | - */ |
|
| 851 | - public function getAdditionalJavaScriptFiles() |
|
| 852 | - { |
|
| 853 | - if (empty($this->additionalJavaScriptFiles)) { |
|
| 854 | - $this->additionalJavaScriptFiles = $this->getModuleConfiguration('additionalJavaScriptFiles'); |
|
| 855 | - } |
|
| 856 | - return $this->additionalJavaScriptFiles; |
|
| 857 | - } |
|
| 858 | - |
|
| 859 | - /** |
|
| 860 | - * @return \string[] |
|
| 861 | - */ |
|
| 862 | - public function getAdditionalStyleSheetFiles() |
|
| 863 | - { |
|
| 864 | - if (empty($this->additionalStyleSheetFiles)) { |
|
| 865 | - $this->additionalStyleSheetFiles = $this->getModuleConfiguration('additionalStyleSheetFiles'); |
|
| 866 | - } |
|
| 867 | - return $this->additionalStyleSheetFiles; |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - /** |
|
| 871 | - * @return array |
|
| 872 | - */ |
|
| 873 | - public function getComponents() |
|
| 874 | - { |
|
| 875 | - return $this->components; |
|
| 876 | - } |
|
| 877 | - |
|
| 878 | - /** |
|
| 879 | - * @param string $pluginName |
|
| 880 | - * @return bool |
|
| 881 | - */ |
|
| 882 | - public function hasPlugin($pluginName = '') |
|
| 883 | - { |
|
| 884 | - $parameterPrefix = $this->getParameterPrefix(); |
|
| 885 | - $parameters = GeneralUtility::_GET($parameterPrefix); |
|
| 886 | - |
|
| 887 | - $hasPlugin = !empty($parameters['plugins']) && is_array($parameters['plugins']); |
|
| 888 | - if ($hasPlugin && $pluginName) { |
|
| 889 | - $hasPlugin = in_array($pluginName, $parameters['plugins']); |
|
| 890 | - } |
|
| 891 | - return $hasPlugin; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - /** |
|
| 895 | - * Compute the internal module code |
|
| 896 | - * |
|
| 897 | - * @param NULL|string $dataType |
|
| 898 | - * @return string |
|
| 899 | - */ |
|
| 900 | - protected function getInternalModuleSignature($dataType = NULL) |
|
| 901 | - { |
|
| 902 | - if (is_null($dataType)) { |
|
| 903 | - $dataType = $this->dataType; |
|
| 904 | - } |
|
| 905 | - $subModuleName = $dataType . '_' . $this->moduleKey; |
|
| 906 | - return 'Vidi' . GeneralUtility::underscoredToUpperCamelCase($subModuleName); |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - /** |
|
| 910 | - * Make sure default values are correctly initialized for the module. |
|
| 911 | - * |
|
| 912 | - * @return void |
|
| 913 | - */ |
|
| 914 | - protected function initializeDefaultValues() |
|
| 915 | - { |
|
| 916 | - if (is_null($this->mainModule)) { |
|
| 917 | - $this->mainModule = self::DEFAULT_MAIN_MODULE; |
|
| 918 | - } |
|
| 919 | - |
|
| 920 | - if (is_null($this->defaultPid)) { |
|
| 921 | - $this->defaultPid = self::DEFAULT_PID; |
|
| 922 | - } |
|
| 923 | - } |
|
| 29 | + /** |
|
| 30 | + * Define the default main module |
|
| 31 | + */ |
|
| 32 | + const DEFAULT_MAIN_MODULE = 'content'; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * Define the default pid |
|
| 36 | + */ |
|
| 37 | + const DEFAULT_PID = 0; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * The type of data being listed (which corresponds to a table name in TCA) |
|
| 41 | + * |
|
| 42 | + * @var string |
|
| 43 | + */ |
|
| 44 | + protected $dataType; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * @var string |
|
| 48 | + */ |
|
| 49 | + protected $defaultPid; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @var bool |
|
| 53 | + */ |
|
| 54 | + protected $showPageTree; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * @var bool |
|
| 58 | + */ |
|
| 59 | + protected $isShown = TRUE; |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * @var string |
|
| 63 | + */ |
|
| 64 | + protected $access = Access::USER; |
|
| 65 | + |
|
| 66 | + /** |
|
| 67 | + * @var string |
|
| 68 | + */ |
|
| 69 | + protected $mainModule; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var string |
|
| 73 | + */ |
|
| 74 | + protected $position = ''; |
|
| 75 | + |
|
| 76 | + /** |
|
| 77 | + * @var string |
|
| 78 | + */ |
|
| 79 | + protected $icon = ''; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * @var string |
|
| 83 | + */ |
|
| 84 | + protected $moduleLanguageFile = 'LLL:EXT:vidi/Resources/Private/Language/locallang_module.xlf'; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * The module key such as m1, m2. |
|
| 88 | + * |
|
| 89 | + * @var string |
|
| 90 | + */ |
|
| 91 | + protected $moduleKey = 'm1'; |
|
| 92 | + |
|
| 93 | + /** |
|
| 94 | + * @var string[] |
|
| 95 | + */ |
|
| 96 | + protected $additionalJavaScriptFiles = array(); |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * @var string[] |
|
| 100 | + */ |
|
| 101 | + protected $additionalStyleSheetFiles = array(); |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * @var array |
|
| 105 | + */ |
|
| 106 | + protected $components = array( |
|
| 107 | + ModulePosition::DOC_HEADER => array( |
|
| 108 | + ModulePosition::TOP => array( |
|
| 109 | + ModulePosition::LEFT => array(), |
|
| 110 | + ModulePosition::RIGHT => array( |
|
| 111 | + 'Fab\Vidi\View\Button\ToolButton', |
|
| 112 | + ), |
|
| 113 | + ), |
|
| 114 | + ModulePosition::BOTTOM => array( |
|
| 115 | + ModulePosition::LEFT => array( |
|
| 116 | + 'Fab\Vidi\View\Button\NewButton', |
|
| 117 | + 'Fab\Vidi\ViewHelpers\Link\BackViewHelper', |
|
| 118 | + ), |
|
| 119 | + ModulePosition::RIGHT => array(), |
|
| 120 | + ), |
|
| 121 | + ), |
|
| 122 | + ModulePosition::GRID => array( |
|
| 123 | + ModulePosition::TOP => array( |
|
| 124 | + 'Fab\Vidi\View\Check\PidCheck', |
|
| 125 | + 'Fab\Vidi\View\Check\RelationsCheck', |
|
| 126 | + 'Fab\Vidi\View\Tab\DataTypeTab', |
|
| 127 | + ), |
|
| 128 | + ModulePosition::BUTTONS => array( |
|
| 129 | + 'Fab\Vidi\View\Button\EditButton', |
|
| 130 | + 'Fab\Vidi\View\Button\DeleteButton', |
|
| 131 | + ), |
|
| 132 | + ModulePosition::BOTTOM => array(), |
|
| 133 | + ), |
|
| 134 | + ModulePosition::MENU_MASS_ACTION => array( |
|
| 135 | + 'Fab\Vidi\View\MenuItem\ExportXlsMenuItem', |
|
| 136 | + 'Fab\Vidi\View\MenuItem\ExportXmlMenuItem', |
|
| 137 | + 'Fab\Vidi\View\MenuItem\ExportCsvMenuItem', |
|
| 138 | + 'Fab\Vidi\View\MenuItem\DividerMenuItem', |
|
| 139 | + 'Fab\Vidi\View\MenuItem\MassDeleteMenuItem', |
|
| 140 | + #'Fab\Vidi\View\MenuItem\MassEditMenuItem', |
|
| 141 | + ), |
|
| 142 | + ); |
|
| 143 | + |
|
| 144 | + /** |
|
| 145 | + * @param string $dataType |
|
| 146 | + */ |
|
| 147 | + public function __construct($dataType = null) |
|
| 148 | + { |
|
| 149 | + $this->dataType = $dataType; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Tell whether a module is already registered. |
|
| 154 | + * |
|
| 155 | + * @param string $dataType |
|
| 156 | + * @return bool |
|
| 157 | + */ |
|
| 158 | + public function isRegistered($dataType) |
|
| 159 | + { |
|
| 160 | + $internalModuleSignature = $this->getInternalModuleSignature($dataType); |
|
| 161 | + return !empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]); |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + /** |
|
| 165 | + * Register the module |
|
| 166 | + * |
|
| 167 | + * @return void |
|
| 168 | + */ |
|
| 169 | + public function register() |
|
| 170 | + { |
|
| 171 | + |
|
| 172 | + $this->initializeDefaultValues(); |
|
| 173 | + $internalModuleSignature = $this->getInternalModuleSignature(); |
|
| 174 | + |
|
| 175 | + $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature] = array(); |
|
| 176 | + $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['dataType'] = $this->dataType; |
|
| 177 | + $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['mainModule'] = $this->mainModule; |
|
| 178 | + $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['defaultPid'] = $this->defaultPid; |
|
| 179 | + $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['additionalJavaScriptFiles'] = $this->additionalJavaScriptFiles; |
|
| 180 | + $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['additionalStyleSheetFiles'] = $this->additionalStyleSheetFiles; |
|
| 181 | + $GLOBALS['TBE_MODULES_EXT']['vidi'][$internalModuleSignature]['components'] = $this->components; |
|
| 182 | + |
|
| 183 | + // Register and displays module in the BE only if told, default is TRUE. |
|
| 184 | + if ($this->isShown) { |
|
| 185 | + $moduleConfiguration = array( |
|
| 186 | + #'routeTarget' => \Fab\Vidi\Controller\ContentController::class . '::mainAction', // what to do here? |
|
| 187 | + 'access' => $this->access, |
|
| 188 | + 'labels' => $this->moduleLanguageFile, |
|
| 189 | + 'inheritNavigationComponentFromMainModule' => TRUE |
|
| 190 | + ); |
|
| 191 | + |
|
| 192 | + if (!empty($this->icon)) { |
|
| 193 | + $moduleConfiguration['icon'] = $this->icon; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (!is_null($this->showPageTree)) { |
|
| 197 | + if ($this->showPageTree) { |
|
| 198 | + $moduleConfiguration['navigationComponentId'] = 'typo3-pagetree'; |
|
| 199 | + } else { |
|
| 200 | + $moduleConfiguration['inheritNavigationComponentFromMainModule'] = FALSE; |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + ExtensionUtility::registerModule( |
|
| 205 | + 'Fab.vidi', |
|
| 206 | + $this->mainModule, |
|
| 207 | + $this->dataType . '_' . $this->moduleKey, |
|
| 208 | + $this->position, |
|
| 209 | + array( |
|
| 210 | + 'Content' => 'index, list, delete, update, edit, copy, move, localize, sort, copyClipboard, moveClipboard', |
|
| 211 | + 'Tool' => 'welcome, work', |
|
| 212 | + 'Facet' => 'autoSuggest, autoSuggests', |
|
| 213 | + 'Selection' => 'edit, update, create, delete, list, show', |
|
| 214 | + 'UserPreferences' => 'save', |
|
| 215 | + 'Clipboard' => 'save, flush, show', |
|
| 216 | + ), |
|
| 217 | + $moduleConfiguration |
|
| 218 | + ); |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + /** |
|
| 223 | + * Return the module code for a BE module. |
|
| 224 | + * |
|
| 225 | + * @return string |
|
| 226 | + */ |
|
| 227 | + public function getSignature() |
|
| 228 | + { |
|
| 229 | + return GeneralUtility::_GP(Parameter::MODULE); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + /** |
|
| 233 | + * Tell whether the current module is the list one. |
|
| 234 | + * |
|
| 235 | + * @return bool |
|
| 236 | + */ |
|
| 237 | + public function copeWithPageTree() |
|
| 238 | + { |
|
| 239 | + return GeneralUtility::_GP(Parameter::MODULE) === 'web_VidiM1'; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Returns the current pid. |
|
| 244 | + * |
|
| 245 | + * @return bool |
|
| 246 | + */ |
|
| 247 | + public function getCurrentPid() |
|
| 248 | + { |
|
| 249 | + return GeneralUtility::_GET(Parameter::PID) > 0 ? (int)GeneralUtility::_GET(Parameter::PID) : 0; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Return the Vidi module code which is stored in TBE_MODULES_EXT |
|
| 254 | + * |
|
| 255 | + * @return string |
|
| 256 | + */ |
|
| 257 | + public function getVidiModuleCode() |
|
| 258 | + { |
|
| 259 | + |
|
| 260 | + if ($this->copeWithPageTree()) { |
|
| 261 | + $userPreferenceKey = sprintf('Vidi_pid_%s', $this->getCurrentPid()); |
|
| 262 | + |
|
| 263 | + if (GeneralUtility::_GP(Parameter::SUBMODULE)) { |
|
| 264 | + $subModuleCode = GeneralUtility::_GP(Parameter::SUBMODULE); |
|
| 265 | + BackendUserPreferenceService::getInstance()->set($userPreferenceKey, $subModuleCode); |
|
| 266 | + } else { |
|
| 267 | + |
|
| 268 | + $defaultModuleCode = BackendUserPreferenceService::getInstance()->get($userPreferenceKey); |
|
| 269 | + if (empty($defaultModuleCode)) { |
|
| 270 | + $defaultModuleCode = 'VidiTtContentM1'; // hard-coded submodule |
|
| 271 | + BackendUserPreferenceService::getInstance()->set($userPreferenceKey, $defaultModuleCode); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + $vidiModules = ModuleService::getInstance()->getModulesForCurrentPid(); |
|
| 275 | + |
|
| 276 | + if (empty($vidiModules)) { |
|
| 277 | + $subModuleCode = $defaultModuleCode; |
|
| 278 | + } elseif (isset($vidiModules[$defaultModuleCode])) { |
|
| 279 | + $subModuleCode = $defaultModuleCode; |
|
| 280 | + } else { |
|
| 281 | + $subModuleCode = ModuleService::getInstance()->getFirstModuleForPid($this->getCurrentPid()); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + } else { |
|
| 285 | + $moduleCode = $this->getSignature(); |
|
| 286 | + |
|
| 287 | + // Remove first part which is separated "_" |
|
| 288 | + $delimiter = strpos($moduleCode, '_') + 1; |
|
| 289 | + $subModuleCode = substr($moduleCode, $delimiter); |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + return $subModuleCode; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + /** |
|
| 296 | + * Return the module URL. |
|
| 297 | + * |
|
| 298 | + * @param array $additionalParameters |
|
| 299 | + * @param bool $absoluteUrl |
|
| 300 | + * @return string |
|
| 301 | + */ |
|
| 302 | + public function getModuleUrl(array $additionalParameters = array(), $absoluteUrl = false) |
|
| 303 | + { |
|
| 304 | + $moduleCode = $this->getSignature(); |
|
| 305 | + |
|
| 306 | + // Add possible submodule if current module has page tree. |
|
| 307 | + if ($this->copeWithPageTree() && !isset($additionalParameters[Parameter::SUBMODULE])) { |
|
| 308 | + $additionalParameters[Parameter::SUBMODULE] = $this->getVidiModuleCode(); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + // And don't forget the pid! |
|
| 312 | + if (GeneralUtility::_GET(Parameter::PID)) { |
|
| 313 | + $additionalParameters[Parameter::PID] = GeneralUtility::_GET(Parameter::PID); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + $moduleUrl = BackendUtility::getModuleUrl($moduleCode, $additionalParameters, false, $absoluteUrl); |
|
| 317 | + return $moduleUrl; |
|
| 318 | + } |
|
| 319 | + |
|
| 320 | + /** |
|
| 321 | + * Return the module absolute URL. |
|
| 322 | + * |
|
| 323 | + * @param array $additionalParameters |
|
| 324 | + * @return string |
|
| 325 | + */ |
|
| 326 | + public function getModuleAbsoluteUrl(array $additionalParameters = array()) |
|
| 327 | + { |
|
| 328 | + return $this->getModuleUrl($additionalParameters, true); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * Return the parameter prefix for a BE module. |
|
| 333 | + * |
|
| 334 | + * @return string |
|
| 335 | + */ |
|
| 336 | + public function getParameterPrefix() |
|
| 337 | + { |
|
| 338 | + return 'tx_vidi_' . strtolower($this->getSignature()); |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Return a configuration key or the entire module configuration array if not key is given. |
|
| 343 | + * |
|
| 344 | + * @param string $key |
|
| 345 | + * @throws InvalidKeyInArrayException |
|
| 346 | + * @return mixed |
|
| 347 | + */ |
|
| 348 | + public function getModuleConfiguration($key = '') |
|
| 349 | + { |
|
| 350 | + |
|
| 351 | + $vidiModuleCode = $this->getVidiModuleCode(); |
|
| 352 | + |
|
| 353 | + // Module code must exist |
|
| 354 | + if (empty($GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode])) { |
|
| 355 | + $message = sprintf('Invalid or not existing module code "%s"', $vidiModuleCode); |
|
| 356 | + throw new InvalidKeyInArrayException($message, 1375092053); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + $result = $GLOBALS['TBE_MODULES_EXT']['vidi'][$vidiModuleCode]; |
|
| 360 | + |
|
| 361 | + if (!empty($key)) { |
|
| 362 | + if (isset($result[$key])) { |
|
| 363 | + $result = $result[$key]; |
|
| 364 | + } else { |
|
| 365 | + // key must exist |
|
| 366 | + $message = sprintf('Invalid key configuration "%s"', $key); |
|
| 367 | + throw new InvalidKeyInArrayException($message, 1375092054); |
|
| 368 | + } |
|
| 369 | + } |
|
| 370 | + return $result; |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + /** |
|
| 374 | + * @param string $icon |
|
| 375 | + * @return $this |
|
| 376 | + */ |
|
| 377 | + public function setIcon($icon) |
|
| 378 | + { |
|
| 379 | + $this->icon = $icon; |
|
| 380 | + return $this; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * @return string |
|
| 385 | + */ |
|
| 386 | + public function getIcon() |
|
| 387 | + { |
|
| 388 | + return $this->icon; |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + /** |
|
| 392 | + * @param string $mainModule |
|
| 393 | + * @return $this |
|
| 394 | + */ |
|
| 395 | + public function setMainModule($mainModule) |
|
| 396 | + { |
|
| 397 | + $this->mainModule = $mainModule; |
|
| 398 | + return $this; |
|
| 399 | + } |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * @return string |
|
| 403 | + */ |
|
| 404 | + public function getMainModule() |
|
| 405 | + { |
|
| 406 | + if (is_null($this->mainModule)) { |
|
| 407 | + $this->mainModule = $this->getModuleConfiguration('mainModule'); |
|
| 408 | + } |
|
| 409 | + return $this->mainModule; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + /** |
|
| 413 | + * @param string $moduleLanguageFile |
|
| 414 | + * @return $this |
|
| 415 | + */ |
|
| 416 | + public function setModuleLanguageFile($moduleLanguageFile) |
|
| 417 | + { |
|
| 418 | + $this->moduleLanguageFile = $moduleLanguageFile; |
|
| 419 | + return $this; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * @return string |
|
| 424 | + */ |
|
| 425 | + public function getModuleLanguageFile() |
|
| 426 | + { |
|
| 427 | + return $this->moduleLanguageFile; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * @param string $position |
|
| 432 | + * @return $this |
|
| 433 | + */ |
|
| 434 | + public function setPosition($position) |
|
| 435 | + { |
|
| 436 | + $this->position = $position; |
|
| 437 | + return $this; |
|
| 438 | + } |
|
| 439 | + |
|
| 440 | + /** |
|
| 441 | + * @return string |
|
| 442 | + */ |
|
| 443 | + public function getPosition() |
|
| 444 | + { |
|
| 445 | + return $this->position; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * @param array $files |
|
| 450 | + * @return $this |
|
| 451 | + */ |
|
| 452 | + public function addJavaScriptFiles(array $files) |
|
| 453 | + { |
|
| 454 | + foreach ($files as $file) { |
|
| 455 | + $this->additionalJavaScriptFiles[] = $file; |
|
| 456 | + } |
|
| 457 | + return $this; |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + /** |
|
| 461 | + * @param string $fileNameAndPath |
|
| 462 | + * @return $this |
|
| 463 | + */ |
|
| 464 | + public function addJavaScriptFile($fileNameAndPath) |
|
| 465 | + { |
|
| 466 | + $this->additionalJavaScriptFiles[] = $fileNameAndPath; |
|
| 467 | + return $this; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + /** |
|
| 471 | + * @param array $files |
|
| 472 | + * @return $this |
|
| 473 | + */ |
|
| 474 | + public function addStyleSheetFiles(array $files) |
|
| 475 | + { |
|
| 476 | + foreach ($files as $file) { |
|
| 477 | + $this->additionalStyleSheetFiles[] = $file; |
|
| 478 | + } |
|
| 479 | + return $this; |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * @param string $fileNameAndPath |
|
| 484 | + * @return $this |
|
| 485 | + */ |
|
| 486 | + public function addStyleSheetFile($fileNameAndPath) |
|
| 487 | + { |
|
| 488 | + $this->additionalStyleSheetFiles[] = $fileNameAndPath; |
|
| 489 | + return $this; |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * @return string |
|
| 494 | + */ |
|
| 495 | + public function getDataType() |
|
| 496 | + { |
|
| 497 | + if (is_null($this->dataType)) { |
|
| 498 | + $this->dataType = $this->getModuleConfiguration('dataType'); |
|
| 499 | + } |
|
| 500 | + return $this->dataType; |
|
| 501 | + } |
|
| 502 | + |
|
| 503 | + /** |
|
| 504 | + * @return array |
|
| 505 | + */ |
|
| 506 | + public function getDataTypes() |
|
| 507 | + { |
|
| 508 | + $dataTypes = array(); |
|
| 509 | + foreach ($GLOBALS['TBE_MODULES_EXT']['vidi'] as $module) { |
|
| 510 | + $dataTypes[] = $module['dataType']; |
|
| 511 | + } |
|
| 512 | + return $dataTypes; |
|
| 513 | + } |
|
| 514 | + |
|
| 515 | + /** |
|
| 516 | + * @param string $dataType |
|
| 517 | + * @return $this |
|
| 518 | + */ |
|
| 519 | + public function setDataType($dataType) |
|
| 520 | + { |
|
| 521 | + $this->dataType = $dataType; |
|
| 522 | + return $this; |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + /** |
|
| 526 | + * @return string |
|
| 527 | + */ |
|
| 528 | + public function getDefaultPid() |
|
| 529 | + { |
|
| 530 | + if (empty($this->defaultPid)) { |
|
| 531 | + $this->defaultPid = $this->getModuleConfiguration('defaultPid'); |
|
| 532 | + } |
|
| 533 | + return $this->defaultPid; |
|
| 534 | + } |
|
| 535 | + |
|
| 536 | + /** |
|
| 537 | + * @param string $defaultPid |
|
| 538 | + * @return $this |
|
| 539 | + */ |
|
| 540 | + public function setDefaultPid($defaultPid) |
|
| 541 | + { |
|
| 542 | + $this->defaultPid = $defaultPid; |
|
| 543 | + return $this; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * @param bool $isPageTreeShown |
|
| 548 | + * @return $this |
|
| 549 | + */ |
|
| 550 | + public function showPageTree($isPageTreeShown) |
|
| 551 | + { |
|
| 552 | + $this->showPageTree = $isPageTreeShown; |
|
| 553 | + return $this; |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * @param string $isShown |
|
| 558 | + * @return $this |
|
| 559 | + */ |
|
| 560 | + public function isShown($isShown) |
|
| 561 | + { |
|
| 562 | + $this->isShown = $isShown; |
|
| 563 | + return $this; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * @return $array |
|
| 568 | + */ |
|
| 569 | + public function getDocHeaderTopLeftComponents() |
|
| 570 | + { |
|
| 571 | + $configuration = $this->getModuleConfiguration(); |
|
| 572 | + return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT]; |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + /** |
|
| 576 | + * @param array $components |
|
| 577 | + * @return $this |
|
| 578 | + */ |
|
| 579 | + public function setDocHeaderTopLeftComponents(array $components) |
|
| 580 | + { |
|
| 581 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = $components; |
|
| 582 | + return $this; |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * @param string|array $components |
|
| 587 | + * @return $this |
|
| 588 | + */ |
|
| 589 | + public function addDocHeaderTopLeftComponents($components) |
|
| 590 | + { |
|
| 591 | + if (is_string($components)) { |
|
| 592 | + $components = array($components); |
|
| 593 | + } |
|
| 594 | + $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT]; |
|
| 595 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::LEFT] = array_merge($currentComponents, $components); |
|
| 596 | + return $this; |
|
| 597 | + } |
|
| 598 | + |
|
| 599 | + /** |
|
| 600 | + * @return $array |
|
| 601 | + */ |
|
| 602 | + public function getDocHeaderTopRightComponents() |
|
| 603 | + { |
|
| 604 | + $configuration = $this->getModuleConfiguration(); |
|
| 605 | + return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT]; |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + /** |
|
| 609 | + * @param array $components |
|
| 610 | + * @return $this |
|
| 611 | + */ |
|
| 612 | + public function setDocHeaderTopRightComponents(array $components) |
|
| 613 | + { |
|
| 614 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = $components; |
|
| 615 | + return $this; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * @param string|array $components |
|
| 620 | + * @return $this |
|
| 621 | + */ |
|
| 622 | + public function addDocHeaderTopRightComponents($components) |
|
| 623 | + { |
|
| 624 | + if (is_string($components)) { |
|
| 625 | + $components = array($components); |
|
| 626 | + } |
|
| 627 | + $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT]; |
|
| 628 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::TOP][ModulePosition::RIGHT] = array_merge($currentComponents, $components); |
|
| 629 | + return $this; |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + /** |
|
| 633 | + * @return $array |
|
| 634 | + */ |
|
| 635 | + public function getDocHeaderBottomLeftComponents() |
|
| 636 | + { |
|
| 637 | + $configuration = $this->getModuleConfiguration(); |
|
| 638 | + return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT]; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + /** |
|
| 642 | + * @param array $components |
|
| 643 | + * @return $this |
|
| 644 | + */ |
|
| 645 | + public function setDocHeaderBottomLeftComponents(array $components) |
|
| 646 | + { |
|
| 647 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = $components; |
|
| 648 | + return $this; |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + /** |
|
| 652 | + * @param string|array $components |
|
| 653 | + * @return $this |
|
| 654 | + */ |
|
| 655 | + public function addDocHeaderBottomLeftComponents($components) |
|
| 656 | + { |
|
| 657 | + if (is_string($components)) { |
|
| 658 | + $components = array($components); |
|
| 659 | + } |
|
| 660 | + $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT]; |
|
| 661 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::LEFT] = array_merge($currentComponents, $components); |
|
| 662 | + return $this; |
|
| 663 | + } |
|
| 664 | + |
|
| 665 | + /** |
|
| 666 | + * @return $array |
|
| 667 | + */ |
|
| 668 | + public function getDocHeaderBottomRightComponents() |
|
| 669 | + { |
|
| 670 | + $configuration = $this->getModuleConfiguration(); |
|
| 671 | + return $configuration['components'][ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT]; |
|
| 672 | + } |
|
| 673 | + |
|
| 674 | + /** |
|
| 675 | + * @param array $components |
|
| 676 | + * @return $this |
|
| 677 | + */ |
|
| 678 | + public function setDocHeaderBottomRightComponents(array $components) |
|
| 679 | + { |
|
| 680 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = $components; |
|
| 681 | + return $this; |
|
| 682 | + } |
|
| 683 | + |
|
| 684 | + /** |
|
| 685 | + * @param string|array $components |
|
| 686 | + * @return $this |
|
| 687 | + */ |
|
| 688 | + public function addDocHeaderBottomRightComponents($components) |
|
| 689 | + { |
|
| 690 | + if (is_string($components)) { |
|
| 691 | + $components = array($components); |
|
| 692 | + } |
|
| 693 | + $currentComponents = $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT]; |
|
| 694 | + $this->components[ModulePosition::DOC_HEADER][ModulePosition::BOTTOM][ModulePosition::RIGHT] = array_merge($currentComponents, $components); |
|
| 695 | + return $this; |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + /** |
|
| 699 | + * @return $array |
|
| 700 | + */ |
|
| 701 | + public function getGridTopComponents() |
|
| 702 | + { |
|
| 703 | + $configuration = $this->getModuleConfiguration(); |
|
| 704 | + return $configuration['components'][ModulePosition::GRID][ModulePosition::TOP]; |
|
| 705 | + } |
|
| 706 | + |
|
| 707 | + /** |
|
| 708 | + * @param array $components |
|
| 709 | + * @return $this |
|
| 710 | + */ |
|
| 711 | + public function setGridTopComponents(array $components) |
|
| 712 | + { |
|
| 713 | + $this->components[ModulePosition::GRID][ModulePosition::TOP] = $components; |
|
| 714 | + return $this; |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + /** |
|
| 718 | + * @param string|array $components |
|
| 719 | + * @return $this |
|
| 720 | + */ |
|
| 721 | + public function addGridTopComponents($components) |
|
| 722 | + { |
|
| 723 | + if (is_string($components)) { |
|
| 724 | + $components = array($components); |
|
| 725 | + } |
|
| 726 | + $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::TOP]; |
|
| 727 | + $this->components[ModulePosition::GRID][ModulePosition::TOP] = array_merge($currentComponents, $components); |
|
| 728 | + return $this; |
|
| 729 | + } |
|
| 730 | + |
|
| 731 | + /** |
|
| 732 | + * @return $array |
|
| 733 | + */ |
|
| 734 | + public function getGridBottomComponents() |
|
| 735 | + { |
|
| 736 | + $configuration = $this->getModuleConfiguration(); |
|
| 737 | + return $configuration['components'][ModulePosition::GRID][ModulePosition::BOTTOM]; |
|
| 738 | + } |
|
| 739 | + |
|
| 740 | + /** |
|
| 741 | + * @param array $components |
|
| 742 | + * @return $this |
|
| 743 | + */ |
|
| 744 | + public function setGridBottomComponents(array $components) |
|
| 745 | + { |
|
| 746 | + $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = $components; |
|
| 747 | + return $this; |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + /** |
|
| 751 | + * @param string|array $components |
|
| 752 | + * @return $this |
|
| 753 | + */ |
|
| 754 | + public function addGridBottomComponents($components) |
|
| 755 | + { |
|
| 756 | + if (is_string($components)) { |
|
| 757 | + $components = array($components); |
|
| 758 | + } |
|
| 759 | + $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BOTTOM]; |
|
| 760 | + $this->components[ModulePosition::GRID][ModulePosition::BOTTOM] = array_merge($currentComponents, $components); |
|
| 761 | + return $this; |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + /** |
|
| 765 | + * @return $array |
|
| 766 | + */ |
|
| 767 | + public function getGridButtonsComponents() |
|
| 768 | + { |
|
| 769 | + $configuration = $this->getModuleConfiguration(); |
|
| 770 | + return $configuration['components'][ModulePosition::GRID][ModulePosition::BUTTONS]; |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + /** |
|
| 774 | + * @param array $components |
|
| 775 | + * @return $this |
|
| 776 | + */ |
|
| 777 | + public function setGridButtonsComponents(array $components) |
|
| 778 | + { |
|
| 779 | + $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = $components; |
|
| 780 | + return $this; |
|
| 781 | + } |
|
| 782 | + |
|
| 783 | + /** |
|
| 784 | + * @param string|array $components |
|
| 785 | + * @return $this |
|
| 786 | + */ |
|
| 787 | + public function addGridButtonsComponents($components) |
|
| 788 | + { |
|
| 789 | + if (is_string($components)) { |
|
| 790 | + $components = array($components); |
|
| 791 | + } |
|
| 792 | + $currentComponents = $this->components[ModulePosition::GRID][ModulePosition::BUTTONS]; |
|
| 793 | + $this->components[ModulePosition::GRID][ModulePosition::BUTTONS] = array_merge($currentComponents, $components); |
|
| 794 | + return $this; |
|
| 795 | + } |
|
| 796 | + |
|
| 797 | + /** |
|
| 798 | + * @return $array |
|
| 799 | + */ |
|
| 800 | + public function getMenuMassActionComponents() |
|
| 801 | + { |
|
| 802 | + $configuration = $this->getModuleConfiguration(); |
|
| 803 | + return $configuration['components'][ModulePosition::MENU_MASS_ACTION]; |
|
| 804 | + } |
|
| 805 | + |
|
| 806 | + /** |
|
| 807 | + * @param array $components |
|
| 808 | + * @return $this |
|
| 809 | + */ |
|
| 810 | + public function setMenuMassActionComponents(array $components) |
|
| 811 | + { |
|
| 812 | + $this->components[ModulePosition::MENU_MASS_ACTION] = $components; |
|
| 813 | + return $this; |
|
| 814 | + } |
|
| 815 | + |
|
| 816 | + /** |
|
| 817 | + * @param string|array $components |
|
| 818 | + * @return $this |
|
| 819 | + */ |
|
| 820 | + public function addMenuMassActionComponents($components) |
|
| 821 | + { |
|
| 822 | + if (is_string($components)) { |
|
| 823 | + $components = array($components); |
|
| 824 | + } |
|
| 825 | + $currentComponents = $this->components[ModulePosition::MENU_MASS_ACTION]; |
|
| 826 | + $this->components[ModulePosition::MENU_MASS_ACTION] = array_merge($currentComponents, $components); |
|
| 827 | + return $this; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + /** |
|
| 831 | + * @return string |
|
| 832 | + */ |
|
| 833 | + public function getAccess() |
|
| 834 | + { |
|
| 835 | + return $this->access; |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + /** |
|
| 839 | + * @param string $access |
|
| 840 | + * @return $this |
|
| 841 | + */ |
|
| 842 | + public function setAccess($access) |
|
| 843 | + { |
|
| 844 | + $this->access = $access; |
|
| 845 | + return $this; |
|
| 846 | + } |
|
| 847 | + |
|
| 848 | + /** |
|
| 849 | + * @return \string[] |
|
| 850 | + */ |
|
| 851 | + public function getAdditionalJavaScriptFiles() |
|
| 852 | + { |
|
| 853 | + if (empty($this->additionalJavaScriptFiles)) { |
|
| 854 | + $this->additionalJavaScriptFiles = $this->getModuleConfiguration('additionalJavaScriptFiles'); |
|
| 855 | + } |
|
| 856 | + return $this->additionalJavaScriptFiles; |
|
| 857 | + } |
|
| 858 | + |
|
| 859 | + /** |
|
| 860 | + * @return \string[] |
|
| 861 | + */ |
|
| 862 | + public function getAdditionalStyleSheetFiles() |
|
| 863 | + { |
|
| 864 | + if (empty($this->additionalStyleSheetFiles)) { |
|
| 865 | + $this->additionalStyleSheetFiles = $this->getModuleConfiguration('additionalStyleSheetFiles'); |
|
| 866 | + } |
|
| 867 | + return $this->additionalStyleSheetFiles; |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + /** |
|
| 871 | + * @return array |
|
| 872 | + */ |
|
| 873 | + public function getComponents() |
|
| 874 | + { |
|
| 875 | + return $this->components; |
|
| 876 | + } |
|
| 877 | + |
|
| 878 | + /** |
|
| 879 | + * @param string $pluginName |
|
| 880 | + * @return bool |
|
| 881 | + */ |
|
| 882 | + public function hasPlugin($pluginName = '') |
|
| 883 | + { |
|
| 884 | + $parameterPrefix = $this->getParameterPrefix(); |
|
| 885 | + $parameters = GeneralUtility::_GET($parameterPrefix); |
|
| 886 | + |
|
| 887 | + $hasPlugin = !empty($parameters['plugins']) && is_array($parameters['plugins']); |
|
| 888 | + if ($hasPlugin && $pluginName) { |
|
| 889 | + $hasPlugin = in_array($pluginName, $parameters['plugins']); |
|
| 890 | + } |
|
| 891 | + return $hasPlugin; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + /** |
|
| 895 | + * Compute the internal module code |
|
| 896 | + * |
|
| 897 | + * @param NULL|string $dataType |
|
| 898 | + * @return string |
|
| 899 | + */ |
|
| 900 | + protected function getInternalModuleSignature($dataType = NULL) |
|
| 901 | + { |
|
| 902 | + if (is_null($dataType)) { |
|
| 903 | + $dataType = $this->dataType; |
|
| 904 | + } |
|
| 905 | + $subModuleName = $dataType . '_' . $this->moduleKey; |
|
| 906 | + return 'Vidi' . GeneralUtility::underscoredToUpperCamelCase($subModuleName); |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + /** |
|
| 910 | + * Make sure default values are correctly initialized for the module. |
|
| 911 | + * |
|
| 912 | + * @return void |
|
| 913 | + */ |
|
| 914 | + protected function initializeDefaultValues() |
|
| 915 | + { |
|
| 916 | + if (is_null($this->mainModule)) { |
|
| 917 | + $this->mainModule = self::DEFAULT_MAIN_MODULE; |
|
| 918 | + } |
|
| 919 | + |
|
| 920 | + if (is_null($this->defaultPid)) { |
|
| 921 | + $this->defaultPid = self::DEFAULT_PID; |
|
| 922 | + } |
|
| 923 | + } |
|
| 924 | 924 | |
| 925 | 925 | } |
@@ -290,7 +290,7 @@ discard block |
||
| 290 | 290 | * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
| 291 | 291 | * ) |
| 292 | 292 | * |
| 293 | - * @return array |
|
| 293 | + * @return integer |
|
| 294 | 294 | * @api |
| 295 | 295 | */ |
| 296 | 296 | public function getOrderings() |
@@ -483,7 +483,7 @@ discard block |
||
| 483 | 483 | * Returns a like criterion used for matching objects against a query |
| 484 | 484 | * |
| 485 | 485 | * @param string $propertyName The name of the property to compare against |
| 486 | - * @param mixed $operand The value to compare with |
|
| 486 | + * @param string $operand The value to compare with |
|
| 487 | 487 | * @param boolean $caseSensitive Whether the matching should be done case-sensitive |
| 488 | 488 | * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
| 489 | 489 | * @api |
@@ -29,649 +29,649 @@ |
||
| 29 | 29 | class Query implements QueryInterface |
| 30 | 30 | { |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * An inner join. |
|
| 34 | - */ |
|
| 35 | - const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * A left-outer join. |
|
| 39 | - */ |
|
| 40 | - const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter'; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * A right-outer join. |
|
| 44 | - */ |
|
| 45 | - const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter'; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Charset of strings in QOM |
|
| 49 | - */ |
|
| 50 | - const CHARSET = 'utf-8'; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @var string |
|
| 54 | - */ |
|
| 55 | - protected $sourceFieldName; |
|
| 56 | - |
|
| 57 | - /** |
|
| 58 | - * @var string |
|
| 59 | - */ |
|
| 60 | - protected $type; |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface |
|
| 64 | - */ |
|
| 65 | - protected $objectManager; |
|
| 66 | - |
|
| 67 | - /** |
|
| 68 | - * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface |
|
| 69 | - */ |
|
| 70 | - protected $persistenceManager; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory |
|
| 74 | - */ |
|
| 75 | - protected $qomFactory; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface |
|
| 79 | - */ |
|
| 80 | - protected $source; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @var ConstraintInterface |
|
| 84 | - */ |
|
| 85 | - protected $constraint; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement |
|
| 89 | - */ |
|
| 90 | - protected $statement; |
|
| 91 | - |
|
| 92 | - /** |
|
| 93 | - * @var int |
|
| 94 | - */ |
|
| 95 | - protected $orderings = array(); |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @var int |
|
| 99 | - */ |
|
| 100 | - protected $limit; |
|
| 101 | - |
|
| 102 | - /** |
|
| 103 | - * @var int |
|
| 104 | - */ |
|
| 105 | - protected $offset; |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Apply DISTINCT upon property. |
|
| 109 | - * |
|
| 110 | - * @var string |
|
| 111 | - */ |
|
| 112 | - protected $distinct; |
|
| 113 | - |
|
| 114 | - /** |
|
| 115 | - * The query settings. |
|
| 116 | - * |
|
| 117 | - * @var \Fab\Vidi\Persistence\QuerySettings |
|
| 118 | - * @inject |
|
| 119 | - */ |
|
| 120 | - protected $querySettings; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Constructs a query object working on the given class name |
|
| 124 | - * |
|
| 125 | - * @param string $type |
|
| 126 | - */ |
|
| 127 | - public function __construct($type) |
|
| 128 | - { |
|
| 129 | - $this->type = $type; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager |
|
| 134 | - * @return void |
|
| 135 | - */ |
|
| 136 | - public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) |
|
| 137 | - { |
|
| 138 | - $this->objectManager = $objectManager; |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * Injects the persistence manager, used to fetch the CR session |
|
| 143 | - * |
|
| 144 | - * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager |
|
| 145 | - * @return void |
|
| 146 | - */ |
|
| 147 | - public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager) |
|
| 148 | - { |
|
| 149 | - $this->persistenceManager = $persistenceManager; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - /** |
|
| 153 | - * Injects the Query Object Model Factory |
|
| 154 | - * |
|
| 155 | - * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory |
|
| 156 | - * @return void |
|
| 157 | - */ |
|
| 158 | - public function injectQomFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory) |
|
| 159 | - { |
|
| 160 | - $this->qomFactory = $qomFactory; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Sets the Query Settings. These Query settings must match the settings expected by |
|
| 165 | - * the specific Storage Backend. |
|
| 166 | - * |
|
| 167 | - * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings |
|
| 168 | - * @return void |
|
| 169 | - * @api This method is not part of FLOW3 API |
|
| 170 | - */ |
|
| 171 | - public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings) |
|
| 172 | - { |
|
| 173 | - $this->querySettings = $querySettings; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Returns the Query Settings. |
|
| 178 | - * |
|
| 179 | - * @throws \Exception |
|
| 180 | - * @return \Fab\Vidi\Persistence\QuerySettings $querySettings The Query Settings |
|
| 181 | - * @api This method is not part of FLOW3 API |
|
| 182 | - */ |
|
| 183 | - public function getQuerySettings() |
|
| 184 | - { |
|
| 185 | - if (!$this->querySettings instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface) { |
|
| 186 | - throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('Tried to get the query settings without setting them before.', 1248689115); |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - // Apply possible settings to the query. |
|
| 190 | - if ($this->isBackendMode()) { |
|
| 191 | - /** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */ |
|
| 192 | - $backendConfigurationManager = $this->objectManager->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager'); |
|
| 193 | - $configuration = $backendConfigurationManager->getTypoScriptSetup(); |
|
| 194 | - $querySettings = array('respectSysLanguage'); |
|
| 195 | - foreach ($querySettings as $setting) { |
|
| 196 | - if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) { |
|
| 197 | - $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting]; |
|
| 198 | - ObjectAccess::setProperty($this->querySettings, $setting, $value); |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - return $this->querySettings; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - /** |
|
| 207 | - * Returns the type this query cares for. |
|
| 208 | - * |
|
| 209 | - * @return string |
|
| 210 | - * @api |
|
| 211 | - */ |
|
| 212 | - public function getType() |
|
| 213 | - { |
|
| 214 | - return $this->type; |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - /** |
|
| 218 | - * Sets the source to fetch the result from |
|
| 219 | - * |
|
| 220 | - * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source |
|
| 221 | - */ |
|
| 222 | - public function setSource(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source) |
|
| 223 | - { |
|
| 224 | - $this->source = $source; |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - /** |
|
| 228 | - * Returns the selectorn name or an empty string, if the source is not a selector |
|
| 229 | - * TODO This has to be checked at another place |
|
| 230 | - * |
|
| 231 | - * @return string The selector name |
|
| 232 | - */ |
|
| 233 | - protected function getSelectorName() |
|
| 234 | - { |
|
| 235 | - if ($this->getSource() instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SelectorInterface) { |
|
| 236 | - return $this->source->getSelectorName(); |
|
| 237 | - } else { |
|
| 238 | - return ''; |
|
| 239 | - } |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * Gets the node-tuple source for this query. |
|
| 244 | - * |
|
| 245 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-null |
|
| 246 | - */ |
|
| 247 | - public function getSource() |
|
| 248 | - { |
|
| 249 | - if ($this->source === NULL) { |
|
| 250 | - $this->source = $this->qomFactory->selector($this->getType()); |
|
| 251 | - } |
|
| 252 | - return $this->source; |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - /** |
|
| 256 | - * Executes the query against the database and returns the result |
|
| 257 | - * |
|
| 258 | - * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is TRUE |
|
| 259 | - * @api |
|
| 260 | - */ |
|
| 261 | - public function execute($returnRawQueryResult = FALSE) |
|
| 262 | - { |
|
| 263 | - /** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */ |
|
| 264 | - $backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this); |
|
| 265 | - return $backend->fetchResult(); |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - /** |
|
| 269 | - * Sets the property names to order the result by. Expected like this: |
|
| 270 | - * array( |
|
| 271 | - * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
| 272 | - * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
| 273 | - * ) |
|
| 274 | - * where 'foo' and 'bar' are property names. |
|
| 275 | - * |
|
| 276 | - * @param array $orderings The property names to order by |
|
| 277 | - * @return QueryInterface |
|
| 278 | - * @api |
|
| 279 | - */ |
|
| 280 | - public function setOrderings(array $orderings) |
|
| 281 | - { |
|
| 282 | - $this->orderings = $orderings; |
|
| 283 | - return $this; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - /** |
|
| 287 | - * Returns the property names to order the result by. Like this: |
|
| 288 | - * array( |
|
| 289 | - * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
| 290 | - * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
| 291 | - * ) |
|
| 292 | - * |
|
| 293 | - * @return array |
|
| 294 | - * @api |
|
| 295 | - */ |
|
| 296 | - public function getOrderings() |
|
| 297 | - { |
|
| 298 | - return $this->orderings; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Sets the maximum size of the result set to limit. Returns $this to allow |
|
| 303 | - * for chaining (fluid interface) |
|
| 304 | - * |
|
| 305 | - * @param integer $limit |
|
| 306 | - * @throws \InvalidArgumentException |
|
| 307 | - * @return QueryInterface |
|
| 308 | - * @api |
|
| 309 | - */ |
|
| 310 | - public function setLimit($limit) |
|
| 311 | - { |
|
| 312 | - if (!is_int($limit) || $limit < 1) { |
|
| 313 | - throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870); |
|
| 314 | - } |
|
| 315 | - $this->limit = $limit; |
|
| 316 | - return $this; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - /** |
|
| 320 | - * Resets a previously set maximum size of the result set. Returns $this to allow |
|
| 321 | - * for chaining (fluid interface) |
|
| 322 | - * |
|
| 323 | - * @return QueryInterface |
|
| 324 | - * @api |
|
| 325 | - */ |
|
| 326 | - public function unsetLimit() |
|
| 327 | - { |
|
| 328 | - unset($this->limit); |
|
| 329 | - return $this; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - /** |
|
| 333 | - * Returns the maximum size of the result set to limit. |
|
| 334 | - * |
|
| 335 | - * @return integer |
|
| 336 | - * @api |
|
| 337 | - */ |
|
| 338 | - public function getLimit() |
|
| 339 | - { |
|
| 340 | - return $this->limit; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - /** |
|
| 344 | - * Sets the start offset of the result set to offset. Returns $this to |
|
| 345 | - * allow for chaining (fluid interface) |
|
| 346 | - * |
|
| 347 | - * @param integer $offset |
|
| 348 | - * @throws \InvalidArgumentException |
|
| 349 | - * @return QueryInterface |
|
| 350 | - * @api |
|
| 351 | - */ |
|
| 352 | - public function setOffset($offset) |
|
| 353 | - { |
|
| 354 | - if (!is_int($offset) || $offset < 0) { |
|
| 355 | - throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872); |
|
| 356 | - } |
|
| 357 | - $this->offset = $offset; |
|
| 358 | - return $this; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - /** |
|
| 362 | - * Returns the start offset of the result set. |
|
| 363 | - * |
|
| 364 | - * @return integer |
|
| 365 | - * @api |
|
| 366 | - */ |
|
| 367 | - public function getOffset() |
|
| 368 | - { |
|
| 369 | - return $this->offset; |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - /** |
|
| 373 | - * The constraint used to limit the result set. Returns $this to allow |
|
| 374 | - * for chaining (fluid interface) |
|
| 375 | - * |
|
| 376 | - * @param ConstraintInterface $constraint |
|
| 377 | - * @return QueryInterface |
|
| 378 | - * @api |
|
| 379 | - */ |
|
| 380 | - public function matching($constraint) |
|
| 381 | - { |
|
| 382 | - $this->constraint = $constraint; |
|
| 383 | - return $this; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - /** |
|
| 387 | - * Gets the constraint for this query. |
|
| 388 | - * |
|
| 389 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Constraint the constraint, or null if none |
|
| 390 | - * @api |
|
| 391 | - */ |
|
| 392 | - public function getConstraint() |
|
| 393 | - { |
|
| 394 | - return $this->constraint; |
|
| 395 | - } |
|
| 396 | - |
|
| 397 | - /** |
|
| 398 | - * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND. |
|
| 399 | - * It also scepts a single array of constraints to be concatenated. |
|
| 400 | - * |
|
| 401 | - * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
| 402 | - * @throws InvalidNumberOfConstraintsException |
|
| 403 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface |
|
| 404 | - * @api |
|
| 405 | - */ |
|
| 406 | - public function logicalAnd($constraint1) |
|
| 407 | - { |
|
| 408 | - if (is_array($constraint1)) { |
|
| 409 | - $resultingConstraint = array_shift($constraint1); |
|
| 410 | - $constraints = $constraint1; |
|
| 411 | - } else { |
|
| 412 | - $constraints = func_get_args(); |
|
| 413 | - $resultingConstraint = array_shift($constraints); |
|
| 414 | - } |
|
| 415 | - if ($resultingConstraint === NULL) { |
|
| 416 | - throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500); |
|
| 417 | - } |
|
| 418 | - foreach ($constraints as $constraint) { |
|
| 419 | - $resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint); |
|
| 420 | - } |
|
| 421 | - return $resultingConstraint; |
|
| 422 | - } |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Performs a logical disjunction of the two given constraints |
|
| 426 | - * |
|
| 427 | - * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
| 428 | - * @throws InvalidNumberOfConstraintsException |
|
| 429 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface |
|
| 430 | - * @api |
|
| 431 | - */ |
|
| 432 | - public function logicalOr($constraint1) |
|
| 433 | - { |
|
| 434 | - if (is_array($constraint1)) { |
|
| 435 | - $resultingConstraint = array_shift($constraint1); |
|
| 436 | - $constraints = $constraint1; |
|
| 437 | - } else { |
|
| 438 | - $constraints = func_get_args(); |
|
| 439 | - $resultingConstraint = array_shift($constraints); |
|
| 440 | - } |
|
| 441 | - if ($resultingConstraint === NULL) { |
|
| 442 | - throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501); |
|
| 443 | - } |
|
| 444 | - foreach ($constraints as $constraint) { |
|
| 445 | - $resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint); |
|
| 446 | - } |
|
| 447 | - return $resultingConstraint; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - /** |
|
| 451 | - * Performs a logical negation of the given constraint |
|
| 452 | - * |
|
| 453 | - * @param ConstraintInterface $constraint Constraint to negate |
|
| 454 | - * @throws \RuntimeException |
|
| 455 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface |
|
| 456 | - * @api |
|
| 457 | - */ |
|
| 458 | - public function logicalNot(ConstraintInterface $constraint) |
|
| 459 | - { |
|
| 460 | - return $this->qomFactory->not($constraint); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - /** |
|
| 464 | - * Returns an equals criterion used for matching objects against a query |
|
| 465 | - * |
|
| 466 | - * @param string $propertyName The name of the property to compare against |
|
| 467 | - * @param mixed $operand The value to compare with |
|
| 468 | - * @param boolean $caseSensitive Whether the equality test should be done case-sensitive |
|
| 469 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 470 | - * @api |
|
| 471 | - */ |
|
| 472 | - public function equals($propertyName, $operand, $caseSensitive = TRUE) |
|
| 473 | - { |
|
| 474 | - if (is_object($operand) || $caseSensitive) { |
|
| 475 | - $comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand); |
|
| 476 | - } else { |
|
| 477 | - $comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), QueryInterface::OPERATOR_EQUAL_TO, \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter')->conv_case(\TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET, $operand, 'toLower')); |
|
| 478 | - } |
|
| 479 | - return $comparison; |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * Returns a like criterion used for matching objects against a query |
|
| 484 | - * |
|
| 485 | - * @param string $propertyName The name of the property to compare against |
|
| 486 | - * @param mixed $operand The value to compare with |
|
| 487 | - * @param boolean $caseSensitive Whether the matching should be done case-sensitive |
|
| 488 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 489 | - * @api |
|
| 490 | - */ |
|
| 491 | - public function like($propertyName, $operand, $caseSensitive = TRUE) |
|
| 492 | - { |
|
| 493 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand); |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - /** |
|
| 497 | - * Returns a "contains" criterion used for matching objects against a query. |
|
| 498 | - * It matches if the multivalued property contains the given operand. |
|
| 499 | - * |
|
| 500 | - * @param string $propertyName The name of the (multivalued) property to compare against |
|
| 501 | - * @param mixed $operand The value to compare with |
|
| 502 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 503 | - * @api |
|
| 504 | - */ |
|
| 505 | - public function contains($propertyName, $operand) |
|
| 506 | - { |
|
| 507 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand); |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - /** |
|
| 511 | - * Returns an "in" criterion used for matching objects against a query. It |
|
| 512 | - * matches if the property's value is contained in the multivalued operand. |
|
| 513 | - * |
|
| 514 | - * @param string $propertyName The name of the property to compare against |
|
| 515 | - * @param mixed $operand The value to compare with, multivalued |
|
| 516 | - * @throws UnexpectedTypeException |
|
| 517 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 518 | - * @api |
|
| 519 | - */ |
|
| 520 | - public function in($propertyName, $operand) |
|
| 521 | - { |
|
| 522 | - if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) { |
|
| 523 | - throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095); |
|
| 524 | - } |
|
| 525 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand); |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - /** |
|
| 529 | - * Returns a less than criterion used for matching objects against a query |
|
| 530 | - * |
|
| 531 | - * @param string $propertyName The name of the property to compare against |
|
| 532 | - * @param mixed $operand The value to compare with |
|
| 533 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 534 | - * @api |
|
| 535 | - */ |
|
| 536 | - public function lessThan($propertyName, $operand) |
|
| 537 | - { |
|
| 538 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand); |
|
| 539 | - } |
|
| 540 | - |
|
| 541 | - /** |
|
| 542 | - * Returns a less or equal than criterion used for matching objects against a query |
|
| 543 | - * |
|
| 544 | - * @param string $propertyName The name of the property to compare against |
|
| 545 | - * @param mixed $operand The value to compare with |
|
| 546 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 547 | - * @api |
|
| 548 | - */ |
|
| 549 | - public function lessThanOrEqual($propertyName, $operand) |
|
| 550 | - { |
|
| 551 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand); |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - /** |
|
| 555 | - * Returns a greater than criterion used for matching objects against a query |
|
| 556 | - * |
|
| 557 | - * @param string $propertyName The name of the property to compare against |
|
| 558 | - * @param mixed $operand The value to compare with |
|
| 559 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 560 | - * @api |
|
| 561 | - */ |
|
| 562 | - public function greaterThan($propertyName, $operand) |
|
| 563 | - { |
|
| 564 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - /** |
|
| 568 | - * Returns a greater than or equal criterion used for matching objects against a query |
|
| 569 | - * |
|
| 570 | - * @param string $propertyName The name of the property to compare against |
|
| 571 | - * @param mixed $operand The value to compare with |
|
| 572 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 573 | - * @api |
|
| 574 | - */ |
|
| 575 | - public function greaterThanOrEqual($propertyName, $operand) |
|
| 576 | - { |
|
| 577 | - return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand); |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Returns the query result count. |
|
| 582 | - * |
|
| 583 | - * @return integer The query result count |
|
| 584 | - * @api |
|
| 585 | - */ |
|
| 586 | - public function count() |
|
| 587 | - { |
|
| 588 | - /** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */ |
|
| 589 | - $backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this); |
|
| 590 | - return $backend->countResult(); |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - /** |
|
| 594 | - * Returns an "isEmpty" criterion used for matching objects against a query. |
|
| 595 | - * It matches if the multivalued property contains no values or is NULL. |
|
| 596 | - * |
|
| 597 | - * @param string $propertyName The name of the multivalued property to compare against |
|
| 598 | - * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException |
|
| 599 | - * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property |
|
| 600 | - * @api |
|
| 601 | - */ |
|
| 602 | - public function isEmpty($propertyName) |
|
| 603 | - { |
|
| 604 | - throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__); |
|
| 605 | - } |
|
| 606 | - |
|
| 607 | - /** |
|
| 608 | - * @return string |
|
| 609 | - */ |
|
| 610 | - public function getDistinct() |
|
| 611 | - { |
|
| 612 | - return $this->distinct; |
|
| 613 | - } |
|
| 614 | - |
|
| 615 | - /** |
|
| 616 | - * @param string $distinct |
|
| 617 | - * @return $this |
|
| 618 | - */ |
|
| 619 | - public function setDistinct($distinct) |
|
| 620 | - { |
|
| 621 | - $this->distinct = $distinct; |
|
| 622 | - return $this; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - /** |
|
| 626 | - * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage |
|
| 627 | - * backend (database). |
|
| 628 | - * |
|
| 629 | - * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement |
|
| 630 | - * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement. |
|
| 631 | - * @return QueryInterface |
|
| 632 | - */ |
|
| 633 | - public function statement($statement, array $parameters = array()) |
|
| 634 | - { |
|
| 635 | - $this->statement = $this->qomFactory->statement($statement, $parameters); |
|
| 636 | - return $this; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - /** |
|
| 640 | - * Returns the statement of this query. |
|
| 641 | - * |
|
| 642 | - * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement |
|
| 643 | - */ |
|
| 644 | - public function getStatement() |
|
| 645 | - { |
|
| 646 | - return $this->statement; |
|
| 647 | - } |
|
| 648 | - |
|
| 649 | - /** |
|
| 650 | - * Returns whether the current mode is Backend. |
|
| 651 | - * |
|
| 652 | - * @return bool |
|
| 653 | - */ |
|
| 654 | - protected function isBackendMode() |
|
| 655 | - { |
|
| 656 | - return TYPO3_MODE == 'BE'; |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - /** |
|
| 660 | - * @return string |
|
| 661 | - */ |
|
| 662 | - public function getSourceFieldName() |
|
| 663 | - { |
|
| 664 | - return $this->sourceFieldName; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - /** |
|
| 668 | - * @param string $sourceFieldName |
|
| 669 | - * @return $this |
|
| 670 | - */ |
|
| 671 | - public function setSourceFieldName($sourceFieldName) |
|
| 672 | - { |
|
| 673 | - $this->sourceFieldName = $sourceFieldName; |
|
| 674 | - return $this; |
|
| 675 | - } |
|
| 32 | + /** |
|
| 33 | + * An inner join. |
|
| 34 | + */ |
|
| 35 | + const JCR_JOIN_TYPE_INNER = '{http://www.jcp.org/jcr/1.0}joinTypeInner'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * A left-outer join. |
|
| 39 | + */ |
|
| 40 | + const JCR_JOIN_TYPE_LEFT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeLeftOuter'; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * A right-outer join. |
|
| 44 | + */ |
|
| 45 | + const JCR_JOIN_TYPE_RIGHT_OUTER = '{http://www.jcp.org/jcr/1.0}joinTypeRightOuter'; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Charset of strings in QOM |
|
| 49 | + */ |
|
| 50 | + const CHARSET = 'utf-8'; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @var string |
|
| 54 | + */ |
|
| 55 | + protected $sourceFieldName; |
|
| 56 | + |
|
| 57 | + /** |
|
| 58 | + * @var string |
|
| 59 | + */ |
|
| 60 | + protected $type; |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * @var \TYPO3\CMS\Extbase\Object\ObjectManagerInterface |
|
| 64 | + */ |
|
| 65 | + protected $objectManager; |
|
| 66 | + |
|
| 67 | + /** |
|
| 68 | + * @var \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface |
|
| 69 | + */ |
|
| 70 | + protected $persistenceManager; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory |
|
| 74 | + */ |
|
| 75 | + protected $qomFactory; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface |
|
| 79 | + */ |
|
| 80 | + protected $source; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @var ConstraintInterface |
|
| 84 | + */ |
|
| 85 | + protected $constraint; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * @var \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement |
|
| 89 | + */ |
|
| 90 | + protected $statement; |
|
| 91 | + |
|
| 92 | + /** |
|
| 93 | + * @var int |
|
| 94 | + */ |
|
| 95 | + protected $orderings = array(); |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @var int |
|
| 99 | + */ |
|
| 100 | + protected $limit; |
|
| 101 | + |
|
| 102 | + /** |
|
| 103 | + * @var int |
|
| 104 | + */ |
|
| 105 | + protected $offset; |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Apply DISTINCT upon property. |
|
| 109 | + * |
|
| 110 | + * @var string |
|
| 111 | + */ |
|
| 112 | + protected $distinct; |
|
| 113 | + |
|
| 114 | + /** |
|
| 115 | + * The query settings. |
|
| 116 | + * |
|
| 117 | + * @var \Fab\Vidi\Persistence\QuerySettings |
|
| 118 | + * @inject |
|
| 119 | + */ |
|
| 120 | + protected $querySettings; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Constructs a query object working on the given class name |
|
| 124 | + * |
|
| 125 | + * @param string $type |
|
| 126 | + */ |
|
| 127 | + public function __construct($type) |
|
| 128 | + { |
|
| 129 | + $this->type = $type; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager |
|
| 134 | + * @return void |
|
| 135 | + */ |
|
| 136 | + public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager) |
|
| 137 | + { |
|
| 138 | + $this->objectManager = $objectManager; |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * Injects the persistence manager, used to fetch the CR session |
|
| 143 | + * |
|
| 144 | + * @param \TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager |
|
| 145 | + * @return void |
|
| 146 | + */ |
|
| 147 | + public function injectPersistenceManager(\TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface $persistenceManager) |
|
| 148 | + { |
|
| 149 | + $this->persistenceManager = $persistenceManager; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + /** |
|
| 153 | + * Injects the Query Object Model Factory |
|
| 154 | + * |
|
| 155 | + * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory |
|
| 156 | + * @return void |
|
| 157 | + */ |
|
| 158 | + public function injectQomFactory(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\QueryObjectModelFactory $qomFactory) |
|
| 159 | + { |
|
| 160 | + $this->qomFactory = $qomFactory; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Sets the Query Settings. These Query settings must match the settings expected by |
|
| 165 | + * the specific Storage Backend. |
|
| 166 | + * |
|
| 167 | + * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The Query Settings |
|
| 168 | + * @return void |
|
| 169 | + * @api This method is not part of FLOW3 API |
|
| 170 | + */ |
|
| 171 | + public function setQuerySettings(\TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings) |
|
| 172 | + { |
|
| 173 | + $this->querySettings = $querySettings; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Returns the Query Settings. |
|
| 178 | + * |
|
| 179 | + * @throws \Exception |
|
| 180 | + * @return \Fab\Vidi\Persistence\QuerySettings $querySettings The Query Settings |
|
| 181 | + * @api This method is not part of FLOW3 API |
|
| 182 | + */ |
|
| 183 | + public function getQuerySettings() |
|
| 184 | + { |
|
| 185 | + if (!$this->querySettings instanceof \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface) { |
|
| 186 | + throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('Tried to get the query settings without setting them before.', 1248689115); |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + // Apply possible settings to the query. |
|
| 190 | + if ($this->isBackendMode()) { |
|
| 191 | + /** @var \TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager $backendConfigurationManager */ |
|
| 192 | + $backendConfigurationManager = $this->objectManager->get('TYPO3\CMS\Extbase\Configuration\BackendConfigurationManager'); |
|
| 193 | + $configuration = $backendConfigurationManager->getTypoScriptSetup(); |
|
| 194 | + $querySettings = array('respectSysLanguage'); |
|
| 195 | + foreach ($querySettings as $setting) { |
|
| 196 | + if (isset($configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting])) { |
|
| 197 | + $value = (bool)$configuration['config.']['tx_vidi.']['persistence.']['backend.'][$this->type . '.'][$setting]; |
|
| 198 | + ObjectAccess::setProperty($this->querySettings, $setting, $value); |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + return $this->querySettings; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + /** |
|
| 207 | + * Returns the type this query cares for. |
|
| 208 | + * |
|
| 209 | + * @return string |
|
| 210 | + * @api |
|
| 211 | + */ |
|
| 212 | + public function getType() |
|
| 213 | + { |
|
| 214 | + return $this->type; |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + /** |
|
| 218 | + * Sets the source to fetch the result from |
|
| 219 | + * |
|
| 220 | + * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source |
|
| 221 | + */ |
|
| 222 | + public function setSource(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source) |
|
| 223 | + { |
|
| 224 | + $this->source = $source; |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + /** |
|
| 228 | + * Returns the selectorn name or an empty string, if the source is not a selector |
|
| 229 | + * TODO This has to be checked at another place |
|
| 230 | + * |
|
| 231 | + * @return string The selector name |
|
| 232 | + */ |
|
| 233 | + protected function getSelectorName() |
|
| 234 | + { |
|
| 235 | + if ($this->getSource() instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SelectorInterface) { |
|
| 236 | + return $this->source->getSelectorName(); |
|
| 237 | + } else { |
|
| 238 | + return ''; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * Gets the node-tuple source for this query. |
|
| 244 | + * |
|
| 245 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface the node-tuple source; non-null |
|
| 246 | + */ |
|
| 247 | + public function getSource() |
|
| 248 | + { |
|
| 249 | + if ($this->source === NULL) { |
|
| 250 | + $this->source = $this->qomFactory->selector($this->getType()); |
|
| 251 | + } |
|
| 252 | + return $this->source; |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + /** |
|
| 256 | + * Executes the query against the database and returns the result |
|
| 257 | + * |
|
| 258 | + * @return \TYPO3\CMS\Extbase\Persistence\QueryResultInterface|array The query result object or an array if $this->getQuerySettings()->getReturnRawQueryResult() is TRUE |
|
| 259 | + * @api |
|
| 260 | + */ |
|
| 261 | + public function execute($returnRawQueryResult = FALSE) |
|
| 262 | + { |
|
| 263 | + /** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */ |
|
| 264 | + $backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this); |
|
| 265 | + return $backend->fetchResult(); |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + /** |
|
| 269 | + * Sets the property names to order the result by. Expected like this: |
|
| 270 | + * array( |
|
| 271 | + * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
| 272 | + * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
| 273 | + * ) |
|
| 274 | + * where 'foo' and 'bar' are property names. |
|
| 275 | + * |
|
| 276 | + * @param array $orderings The property names to order by |
|
| 277 | + * @return QueryInterface |
|
| 278 | + * @api |
|
| 279 | + */ |
|
| 280 | + public function setOrderings(array $orderings) |
|
| 281 | + { |
|
| 282 | + $this->orderings = $orderings; |
|
| 283 | + return $this; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + /** |
|
| 287 | + * Returns the property names to order the result by. Like this: |
|
| 288 | + * array( |
|
| 289 | + * 'foo' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_ASCENDING, |
|
| 290 | + * 'bar' => \TYPO3\CMS\Extbase\Persistence\QueryInterface::ORDER_DESCENDING |
|
| 291 | + * ) |
|
| 292 | + * |
|
| 293 | + * @return array |
|
| 294 | + * @api |
|
| 295 | + */ |
|
| 296 | + public function getOrderings() |
|
| 297 | + { |
|
| 298 | + return $this->orderings; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Sets the maximum size of the result set to limit. Returns $this to allow |
|
| 303 | + * for chaining (fluid interface) |
|
| 304 | + * |
|
| 305 | + * @param integer $limit |
|
| 306 | + * @throws \InvalidArgumentException |
|
| 307 | + * @return QueryInterface |
|
| 308 | + * @api |
|
| 309 | + */ |
|
| 310 | + public function setLimit($limit) |
|
| 311 | + { |
|
| 312 | + if (!is_int($limit) || $limit < 1) { |
|
| 313 | + throw new \InvalidArgumentException('The limit must be an integer >= 1', 1245071870); |
|
| 314 | + } |
|
| 315 | + $this->limit = $limit; |
|
| 316 | + return $this; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + /** |
|
| 320 | + * Resets a previously set maximum size of the result set. Returns $this to allow |
|
| 321 | + * for chaining (fluid interface) |
|
| 322 | + * |
|
| 323 | + * @return QueryInterface |
|
| 324 | + * @api |
|
| 325 | + */ |
|
| 326 | + public function unsetLimit() |
|
| 327 | + { |
|
| 328 | + unset($this->limit); |
|
| 329 | + return $this; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + /** |
|
| 333 | + * Returns the maximum size of the result set to limit. |
|
| 334 | + * |
|
| 335 | + * @return integer |
|
| 336 | + * @api |
|
| 337 | + */ |
|
| 338 | + public function getLimit() |
|
| 339 | + { |
|
| 340 | + return $this->limit; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + /** |
|
| 344 | + * Sets the start offset of the result set to offset. Returns $this to |
|
| 345 | + * allow for chaining (fluid interface) |
|
| 346 | + * |
|
| 347 | + * @param integer $offset |
|
| 348 | + * @throws \InvalidArgumentException |
|
| 349 | + * @return QueryInterface |
|
| 350 | + * @api |
|
| 351 | + */ |
|
| 352 | + public function setOffset($offset) |
|
| 353 | + { |
|
| 354 | + if (!is_int($offset) || $offset < 0) { |
|
| 355 | + throw new \InvalidArgumentException('The offset must be a positive integer', 1245071872); |
|
| 356 | + } |
|
| 357 | + $this->offset = $offset; |
|
| 358 | + return $this; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + /** |
|
| 362 | + * Returns the start offset of the result set. |
|
| 363 | + * |
|
| 364 | + * @return integer |
|
| 365 | + * @api |
|
| 366 | + */ |
|
| 367 | + public function getOffset() |
|
| 368 | + { |
|
| 369 | + return $this->offset; |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + /** |
|
| 373 | + * The constraint used to limit the result set. Returns $this to allow |
|
| 374 | + * for chaining (fluid interface) |
|
| 375 | + * |
|
| 376 | + * @param ConstraintInterface $constraint |
|
| 377 | + * @return QueryInterface |
|
| 378 | + * @api |
|
| 379 | + */ |
|
| 380 | + public function matching($constraint) |
|
| 381 | + { |
|
| 382 | + $this->constraint = $constraint; |
|
| 383 | + return $this; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + /** |
|
| 387 | + * Gets the constraint for this query. |
|
| 388 | + * |
|
| 389 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Constraint the constraint, or null if none |
|
| 390 | + * @api |
|
| 391 | + */ |
|
| 392 | + public function getConstraint() |
|
| 393 | + { |
|
| 394 | + return $this->constraint; |
|
| 395 | + } |
|
| 396 | + |
|
| 397 | + /** |
|
| 398 | + * Performs a logical conjunction of the given constraints. The method takes one or more contraints and concatenates them with a boolean AND. |
|
| 399 | + * It also scepts a single array of constraints to be concatenated. |
|
| 400 | + * |
|
| 401 | + * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
| 402 | + * @throws InvalidNumberOfConstraintsException |
|
| 403 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface |
|
| 404 | + * @api |
|
| 405 | + */ |
|
| 406 | + public function logicalAnd($constraint1) |
|
| 407 | + { |
|
| 408 | + if (is_array($constraint1)) { |
|
| 409 | + $resultingConstraint = array_shift($constraint1); |
|
| 410 | + $constraints = $constraint1; |
|
| 411 | + } else { |
|
| 412 | + $constraints = func_get_args(); |
|
| 413 | + $resultingConstraint = array_shift($constraints); |
|
| 414 | + } |
|
| 415 | + if ($resultingConstraint === NULL) { |
|
| 416 | + throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289500); |
|
| 417 | + } |
|
| 418 | + foreach ($constraints as $constraint) { |
|
| 419 | + $resultingConstraint = $this->qomFactory->_and($resultingConstraint, $constraint); |
|
| 420 | + } |
|
| 421 | + return $resultingConstraint; |
|
| 422 | + } |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Performs a logical disjunction of the two given constraints |
|
| 426 | + * |
|
| 427 | + * @param mixed $constraint1 The first of multiple constraints or an array of constraints. |
|
| 428 | + * @throws InvalidNumberOfConstraintsException |
|
| 429 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface |
|
| 430 | + * @api |
|
| 431 | + */ |
|
| 432 | + public function logicalOr($constraint1) |
|
| 433 | + { |
|
| 434 | + if (is_array($constraint1)) { |
|
| 435 | + $resultingConstraint = array_shift($constraint1); |
|
| 436 | + $constraints = $constraint1; |
|
| 437 | + } else { |
|
| 438 | + $constraints = func_get_args(); |
|
| 439 | + $resultingConstraint = array_shift($constraints); |
|
| 440 | + } |
|
| 441 | + if ($resultingConstraint === NULL) { |
|
| 442 | + throw new InvalidNumberOfConstraintsException('There must be at least one constraint or a non-empty array of constraints given.', 1401289501); |
|
| 443 | + } |
|
| 444 | + foreach ($constraints as $constraint) { |
|
| 445 | + $resultingConstraint = $this->qomFactory->_or($resultingConstraint, $constraint); |
|
| 446 | + } |
|
| 447 | + return $resultingConstraint; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + /** |
|
| 451 | + * Performs a logical negation of the given constraint |
|
| 452 | + * |
|
| 453 | + * @param ConstraintInterface $constraint Constraint to negate |
|
| 454 | + * @throws \RuntimeException |
|
| 455 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface |
|
| 456 | + * @api |
|
| 457 | + */ |
|
| 458 | + public function logicalNot(ConstraintInterface $constraint) |
|
| 459 | + { |
|
| 460 | + return $this->qomFactory->not($constraint); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + /** |
|
| 464 | + * Returns an equals criterion used for matching objects against a query |
|
| 465 | + * |
|
| 466 | + * @param string $propertyName The name of the property to compare against |
|
| 467 | + * @param mixed $operand The value to compare with |
|
| 468 | + * @param boolean $caseSensitive Whether the equality test should be done case-sensitive |
|
| 469 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 470 | + * @api |
|
| 471 | + */ |
|
| 472 | + public function equals($propertyName, $operand, $caseSensitive = TRUE) |
|
| 473 | + { |
|
| 474 | + if (is_object($operand) || $caseSensitive) { |
|
| 475 | + $comparison = $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_EQUAL_TO, $operand); |
|
| 476 | + } else { |
|
| 477 | + $comparison = $this->qomFactory->comparison($this->qomFactory->lowerCase($this->qomFactory->propertyValue($propertyName, $this->getSelectorName())), QueryInterface::OPERATOR_EQUAL_TO, \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Charset\\CharsetConverter')->conv_case(\TYPO3\CMS\Extbase\Persistence\Generic\Query::CHARSET, $operand, 'toLower')); |
|
| 478 | + } |
|
| 479 | + return $comparison; |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * Returns a like criterion used for matching objects against a query |
|
| 484 | + * |
|
| 485 | + * @param string $propertyName The name of the property to compare against |
|
| 486 | + * @param mixed $operand The value to compare with |
|
| 487 | + * @param boolean $caseSensitive Whether the matching should be done case-sensitive |
|
| 488 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 489 | + * @api |
|
| 490 | + */ |
|
| 491 | + public function like($propertyName, $operand, $caseSensitive = TRUE) |
|
| 492 | + { |
|
| 493 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LIKE, $operand); |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + /** |
|
| 497 | + * Returns a "contains" criterion used for matching objects against a query. |
|
| 498 | + * It matches if the multivalued property contains the given operand. |
|
| 499 | + * |
|
| 500 | + * @param string $propertyName The name of the (multivalued) property to compare against |
|
| 501 | + * @param mixed $operand The value to compare with |
|
| 502 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 503 | + * @api |
|
| 504 | + */ |
|
| 505 | + public function contains($propertyName, $operand) |
|
| 506 | + { |
|
| 507 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_CONTAINS, $operand); |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + /** |
|
| 511 | + * Returns an "in" criterion used for matching objects against a query. It |
|
| 512 | + * matches if the property's value is contained in the multivalued operand. |
|
| 513 | + * |
|
| 514 | + * @param string $propertyName The name of the property to compare against |
|
| 515 | + * @param mixed $operand The value to compare with, multivalued |
|
| 516 | + * @throws UnexpectedTypeException |
|
| 517 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 518 | + * @api |
|
| 519 | + */ |
|
| 520 | + public function in($propertyName, $operand) |
|
| 521 | + { |
|
| 522 | + if (!is_array($operand) && !$operand instanceof \ArrayAccess && !$operand instanceof \Traversable) { |
|
| 523 | + throw new UnexpectedTypeException('The "in" operator must be given a mutlivalued operand (array, ArrayAccess, Traversable).', 1264678095); |
|
| 524 | + } |
|
| 525 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_IN, $operand); |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + /** |
|
| 529 | + * Returns a less than criterion used for matching objects against a query |
|
| 530 | + * |
|
| 531 | + * @param string $propertyName The name of the property to compare against |
|
| 532 | + * @param mixed $operand The value to compare with |
|
| 533 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 534 | + * @api |
|
| 535 | + */ |
|
| 536 | + public function lessThan($propertyName, $operand) |
|
| 537 | + { |
|
| 538 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN, $operand); |
|
| 539 | + } |
|
| 540 | + |
|
| 541 | + /** |
|
| 542 | + * Returns a less or equal than criterion used for matching objects against a query |
|
| 543 | + * |
|
| 544 | + * @param string $propertyName The name of the property to compare against |
|
| 545 | + * @param mixed $operand The value to compare with |
|
| 546 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 547 | + * @api |
|
| 548 | + */ |
|
| 549 | + public function lessThanOrEqual($propertyName, $operand) |
|
| 550 | + { |
|
| 551 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO, $operand); |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + /** |
|
| 555 | + * Returns a greater than criterion used for matching objects against a query |
|
| 556 | + * |
|
| 557 | + * @param string $propertyName The name of the property to compare against |
|
| 558 | + * @param mixed $operand The value to compare with |
|
| 559 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 560 | + * @api |
|
| 561 | + */ |
|
| 562 | + public function greaterThan($propertyName, $operand) |
|
| 563 | + { |
|
| 564 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN, $operand); |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + /** |
|
| 568 | + * Returns a greater than or equal criterion used for matching objects against a query |
|
| 569 | + * |
|
| 570 | + * @param string $propertyName The name of the property to compare against |
|
| 571 | + * @param mixed $operand The value to compare with |
|
| 572 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface |
|
| 573 | + * @api |
|
| 574 | + */ |
|
| 575 | + public function greaterThanOrEqual($propertyName, $operand) |
|
| 576 | + { |
|
| 577 | + return $this->qomFactory->comparison($this->qomFactory->propertyValue($propertyName, $this->getSelectorName()), QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO, $operand); |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Returns the query result count. |
|
| 582 | + * |
|
| 583 | + * @return integer The query result count |
|
| 584 | + * @api |
|
| 585 | + */ |
|
| 586 | + public function count() |
|
| 587 | + { |
|
| 588 | + /** @var \Fab\Vidi\Persistence\Storage\VidiDbBackend $backend */ |
|
| 589 | + $backend = $this->objectManager->get('Fab\Vidi\Persistence\Storage\VidiDbBackend', $this); |
|
| 590 | + return $backend->countResult(); |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + /** |
|
| 594 | + * Returns an "isEmpty" criterion used for matching objects against a query. |
|
| 595 | + * It matches if the multivalued property contains no values or is NULL. |
|
| 596 | + * |
|
| 597 | + * @param string $propertyName The name of the multivalued property to compare against |
|
| 598 | + * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException |
|
| 599 | + * @throws \TYPO3\CMS\Extbase\Persistence\Exception\InvalidQueryException if used on a single-valued property |
|
| 600 | + * @api |
|
| 601 | + */ |
|
| 602 | + public function isEmpty($propertyName) |
|
| 603 | + { |
|
| 604 | + throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\NotImplementedException(__METHOD__); |
|
| 605 | + } |
|
| 606 | + |
|
| 607 | + /** |
|
| 608 | + * @return string |
|
| 609 | + */ |
|
| 610 | + public function getDistinct() |
|
| 611 | + { |
|
| 612 | + return $this->distinct; |
|
| 613 | + } |
|
| 614 | + |
|
| 615 | + /** |
|
| 616 | + * @param string $distinct |
|
| 617 | + * @return $this |
|
| 618 | + */ |
|
| 619 | + public function setDistinct($distinct) |
|
| 620 | + { |
|
| 621 | + $this->distinct = $distinct; |
|
| 622 | + return $this; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + /** |
|
| 626 | + * Sets the statement of this query. If you use this, you will lose the abstraction from a concrete storage |
|
| 627 | + * backend (database). |
|
| 628 | + * |
|
| 629 | + * @param string|\TYPO3\CMS\Core\Database\PreparedStatement $statement The statement |
|
| 630 | + * @param array $parameters An array of parameters. These will be bound to placeholders '?' in the $statement. |
|
| 631 | + * @return QueryInterface |
|
| 632 | + */ |
|
| 633 | + public function statement($statement, array $parameters = array()) |
|
| 634 | + { |
|
| 635 | + $this->statement = $this->qomFactory->statement($statement, $parameters); |
|
| 636 | + return $this; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + /** |
|
| 640 | + * Returns the statement of this query. |
|
| 641 | + * |
|
| 642 | + * @return \TYPO3\CMS\Extbase\Persistence\Generic\Qom\Statement |
|
| 643 | + */ |
|
| 644 | + public function getStatement() |
|
| 645 | + { |
|
| 646 | + return $this->statement; |
|
| 647 | + } |
|
| 648 | + |
|
| 649 | + /** |
|
| 650 | + * Returns whether the current mode is Backend. |
|
| 651 | + * |
|
| 652 | + * @return bool |
|
| 653 | + */ |
|
| 654 | + protected function isBackendMode() |
|
| 655 | + { |
|
| 656 | + return TYPO3_MODE == 'BE'; |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + /** |
|
| 660 | + * @return string |
|
| 661 | + */ |
|
| 662 | + public function getSourceFieldName() |
|
| 663 | + { |
|
| 664 | + return $this->sourceFieldName; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + /** |
|
| 668 | + * @param string $sourceFieldName |
|
| 669 | + * @return $this |
|
| 670 | + */ |
|
| 671 | + public function setSourceFieldName($sourceFieldName) |
|
| 672 | + { |
|
| 673 | + $this->sourceFieldName = $sourceFieldName; |
|
| 674 | + return $this; |
|
| 675 | + } |
|
| 676 | 676 | |
| 677 | 677 | } |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | /** |
| 232 | 232 | * Parses the query and returns the SQL statement parts. |
| 233 | 233 | * |
| 234 | - * @param QueryInterface $query The query |
|
| 234 | + * @param \Fab\Vidi\Persistence\Query $query The query |
|
| 235 | 235 | * @param array &$parameters |
| 236 | 236 | * @return array The SQL statement parts |
| 237 | 237 | */ |
@@ -774,6 +774,7 @@ discard block |
||
| 774 | 774 | * @param string &$sqlString The query part with placeholders |
| 775 | 775 | * @param array $parameters The parameters |
| 776 | 776 | * @param string $tableName |
| 777 | + * @param string $sqlString |
|
| 777 | 778 | * |
| 778 | 779 | * @throws Exception |
| 779 | 780 | */ |
@@ -1071,7 +1072,7 @@ discard block |
||
| 1071 | 1072 | * |
| 1072 | 1073 | * @param SourceInterface $source The source (selector od join) |
| 1073 | 1074 | * @param array $row |
| 1074 | - * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
| 1075 | + * @param \Fab\Vidi\Persistence\QuerySettings $querySettings The TYPO3 CMS specific query settings |
|
| 1075 | 1076 | * @return array |
| 1076 | 1077 | */ |
| 1077 | 1078 | protected function doLanguageAndWorkspaceOverlay(SourceInterface $source, array $row, $querySettings) |
@@ -18,7 +18,6 @@ |
||
| 18 | 18 | use TYPO3\CMS\Core\Utility\GeneralUtility; |
| 19 | 19 | use TYPO3\CMS\Core\Versioning\VersionState; |
| 20 | 20 | use TYPO3\CMS\Extbase\Persistence\Generic\Exception; |
| 21 | -use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap; |
|
| 22 | 21 | use TYPO3\CMS\Extbase\Persistence\Generic\Qom\ComparisonInterface; |
| 23 | 22 | use TYPO3\CMS\Extbase\Persistence\Generic\Qom\DynamicOperandInterface; |
| 24 | 23 | use TYPO3\CMS\Extbase\Persistence\Generic\Qom\JoinInterface; |
@@ -38,1210 +38,1210 @@ |
||
| 38 | 38 | class VidiDbBackend |
| 39 | 39 | { |
| 40 | 40 | |
| 41 | - const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull'; |
|
| 42 | - const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull'; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * The TYPO3 database object |
|
| 46 | - * |
|
| 47 | - * @var \TYPO3\CMS\Core\Database\DatabaseConnection |
|
| 48 | - */ |
|
| 49 | - protected $databaseHandle; |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * The TYPO3 page repository. Used for language and workspace overlay |
|
| 53 | - * |
|
| 54 | - * @var PageRepository |
|
| 55 | - */ |
|
| 56 | - protected $pageRepository; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * A first-level TypoScript configuration cache |
|
| 60 | - * |
|
| 61 | - * @var array |
|
| 62 | - */ |
|
| 63 | - protected $pageTSConfigCache = array(); |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface |
|
| 67 | - * @inject |
|
| 68 | - */ |
|
| 69 | - protected $configurationManager; |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * @var \TYPO3\CMS\Extbase\Service\CacheService |
|
| 73 | - * @inject |
|
| 74 | - */ |
|
| 75 | - protected $cacheService; |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @var \TYPO3\CMS\Core\Cache\CacheManager |
|
| 79 | - * @inject |
|
| 80 | - */ |
|
| 81 | - protected $cacheManager; |
|
| 82 | - |
|
| 83 | - /** |
|
| 84 | - * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend |
|
| 85 | - */ |
|
| 86 | - protected $tableColumnCache; |
|
| 87 | - |
|
| 88 | - /** |
|
| 89 | - * @var \TYPO3\CMS\Extbase\Service\EnvironmentService |
|
| 90 | - * @inject |
|
| 91 | - */ |
|
| 92 | - protected $environmentService; |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @var \Fab\Vidi\Persistence\Query |
|
| 96 | - */ |
|
| 97 | - protected $query; |
|
| 98 | - |
|
| 99 | - /** |
|
| 100 | - * Store some info related to table name and its aliases. |
|
| 101 | - * |
|
| 102 | - * @var array |
|
| 103 | - */ |
|
| 104 | - protected $tableNameAliases = array( |
|
| 105 | - 'aliases' => array(), |
|
| 106 | - 'aliasIncrement' => array(), |
|
| 107 | - ); |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * Use to store the current foreign table name alias. |
|
| 111 | - * |
|
| 112 | - * @var string |
|
| 113 | - */ |
|
| 114 | - protected $currentChildTableNameAlias = ''; |
|
| 115 | - |
|
| 116 | - /** |
|
| 117 | - * The default object type being returned. |
|
| 118 | - * |
|
| 119 | - * @var string |
|
| 120 | - */ |
|
| 121 | - protected $objectType = 'Fab\Vidi\Domain\Model\Content'; |
|
| 122 | - |
|
| 123 | - /** |
|
| 124 | - * Constructor. takes the database handle from $GLOBALS['TYPO3_DB'] |
|
| 125 | - */ |
|
| 126 | - public function __construct(QueryInterface $query) |
|
| 127 | - { |
|
| 128 | - $this->query = $query; |
|
| 129 | - $this->databaseHandle = $GLOBALS['TYPO3_DB']; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - /** |
|
| 133 | - * Lifecycle method |
|
| 134 | - * |
|
| 135 | - * @return void |
|
| 136 | - */ |
|
| 137 | - public function initializeObject() |
|
| 138 | - { |
|
| 139 | - $this->tableColumnCache = $this->cacheManager->getCache('extbase_typo3dbbackend_tablecolumns'); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @param array $identifier |
|
| 144 | - * @return string |
|
| 145 | - */ |
|
| 146 | - protected function parseIdentifier(array $identifier) |
|
| 147 | - { |
|
| 148 | - $fieldNames = array_keys($identifier); |
|
| 149 | - $suffixedFieldNames = array(); |
|
| 150 | - foreach ($fieldNames as $fieldName) { |
|
| 151 | - $suffixedFieldNames[] = $fieldName . '=?'; |
|
| 152 | - } |
|
| 153 | - return implode(' AND ', $suffixedFieldNames); |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - /** |
|
| 157 | - * Returns the result of the query |
|
| 158 | - */ |
|
| 159 | - public function fetchResult() |
|
| 160 | - { |
|
| 161 | - |
|
| 162 | - $parameters = array(); |
|
| 163 | - $statementParts = $this->parseQuery($this->query, $parameters); |
|
| 164 | - $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); // Mmm... check if that is the right way of doing that. |
|
| 165 | - |
|
| 166 | - $sql = $this->buildQuery($statementParts); |
|
| 167 | - $tableName = ''; |
|
| 168 | - if (is_array($statementParts) && !empty($statementParts['tables'][0])) { |
|
| 169 | - $tableName = $statementParts['tables'][0]; |
|
| 170 | - } |
|
| 171 | - $this->replacePlaceholders($sql, $parameters, $tableName); |
|
| 172 | - #print $sql; exit(); // @debug |
|
| 173 | - |
|
| 174 | - $result = $this->databaseHandle->sql_query($sql); |
|
| 175 | - $this->checkSqlErrors($sql); |
|
| 176 | - $rows = $this->getRowsFromResult($result); |
|
| 177 | - $this->databaseHandle->sql_free_result($result); |
|
| 178 | - |
|
| 179 | - return $rows; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - /** |
|
| 183 | - * Returns the number of tuples matching the query. |
|
| 184 | - * |
|
| 185 | - * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException |
|
| 186 | - * @return int The number of matching tuples |
|
| 187 | - */ |
|
| 188 | - public function countResult() |
|
| 189 | - { |
|
| 190 | - |
|
| 191 | - $parameters = array(); |
|
| 192 | - $statementParts = $this->parseQuery($this->query, $parameters); |
|
| 193 | - $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); // Mmm... check if that is the right way of doing that. |
|
| 194 | - // Reset $statementParts for valid table return |
|
| 195 | - reset($statementParts); |
|
| 196 | - |
|
| 197 | - // if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints |
|
| 198 | - if (!empty($statementParts['limit'])) { |
|
| 199 | - $statement = $this->buildQuery($statementParts); |
|
| 200 | - $this->replacePlaceholders($statement, $parameters, current($statementParts['tables'])); |
|
| 201 | - #print $statement; exit(); // @debug |
|
| 202 | - $result = $this->databaseHandle->sql_query($statement); |
|
| 203 | - $this->checkSqlErrors($statement); |
|
| 204 | - $count = $this->databaseHandle->sql_num_rows($result); |
|
| 205 | - } else { |
|
| 206 | - $statementParts['fields'] = array('COUNT(*)'); |
|
| 207 | - // having orderings without grouping is not compatible with non-MySQL DBMS |
|
| 208 | - $statementParts['orderings'] = array(); |
|
| 209 | - if (isset($statementParts['keywords']['distinct'])) { |
|
| 210 | - unset($statementParts['keywords']['distinct']); |
|
| 211 | - $distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid'; |
|
| 212 | - $statementParts['fields'] = array('COUNT(DISTINCT ' . reset($statementParts['tables']) . '.' . $distinctField . ')'); |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - $statement = $this->buildQuery($statementParts); |
|
| 216 | - $this->replacePlaceholders($statement, $parameters, current($statementParts['tables'])); |
|
| 217 | - |
|
| 218 | - #print $statement; exit(); // @debug |
|
| 219 | - $result = $this->databaseHandle->sql_query($statement); |
|
| 220 | - $this->checkSqlErrors($statement); |
|
| 221 | - $count = 0; |
|
| 222 | - if ($result) { |
|
| 223 | - $row = $this->databaseHandle->sql_fetch_assoc($result); |
|
| 224 | - $count = current($row); |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - $this->databaseHandle->sql_free_result($result); |
|
| 228 | - return (int)$count; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - /** |
|
| 232 | - * Parses the query and returns the SQL statement parts. |
|
| 233 | - * |
|
| 234 | - * @param QueryInterface $query The query |
|
| 235 | - * @param array &$parameters |
|
| 236 | - * @return array The SQL statement parts |
|
| 237 | - */ |
|
| 238 | - public function parseQuery(QueryInterface $query, array &$parameters) |
|
| 239 | - { |
|
| 240 | - $statementParts = array(); |
|
| 241 | - $statementParts['keywords'] = array(); |
|
| 242 | - $statementParts['tables'] = array(); |
|
| 243 | - $statementParts['unions'] = array(); |
|
| 244 | - $statementParts['fields'] = array(); |
|
| 245 | - $statementParts['where'] = array(); |
|
| 246 | - $statementParts['additionalWhereClause'] = array(); |
|
| 247 | - $statementParts['orderings'] = array(); |
|
| 248 | - $statementParts['limit'] = array(); |
|
| 249 | - $source = $query->getSource(); |
|
| 250 | - $this->parseSource($source, $statementParts); |
|
| 251 | - $this->parseConstraint($query->getConstraint(), $source, $statementParts, $parameters); |
|
| 252 | - $this->parseOrderings($query->getOrderings(), $source, $statementParts); |
|
| 253 | - $this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $statementParts); |
|
| 254 | - $tableNames = array_unique(array_keys($statementParts['tables'] + $statementParts['unions'])); |
|
| 255 | - foreach ($tableNames as $tableNameOrAlias) { |
|
| 256 | - if (is_string($tableNameOrAlias) && strlen($tableNameOrAlias) > 0) { |
|
| 257 | - $this->addAdditionalWhereClause($query->getQuerySettings(), $tableNameOrAlias, $statementParts); |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - return $statementParts; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - /** |
|
| 265 | - * Fiddle with the statement structure to handle recursive MM relations. |
|
| 266 | - * For the recursive MM query to work, we must invert some values. |
|
| 267 | - * Let see if that is the best way of doing that... |
|
| 268 | - * |
|
| 269 | - * @param array $statementParts |
|
| 270 | - * @return array |
|
| 271 | - */ |
|
| 272 | - public function processStatementStructureForRecursiveMMRelation(array $statementParts) |
|
| 273 | - { |
|
| 274 | - |
|
| 275 | - if ($this->hasRecursiveMMRelation()) { |
|
| 276 | - $tableName = $this->query->getType(); |
|
| 277 | - |
|
| 278 | - // In order the MM query to work for a recursive MM query, we must invert some values. |
|
| 279 | - // tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name) |
|
| 280 | - $values = array(); |
|
| 281 | - foreach ($statementParts['fields'] as $key => $value) { |
|
| 282 | - $values[$key] = str_replace($tableName, $tableName . '0', $value); |
|
| 283 | - } |
|
| 284 | - $statementParts['fields'] = $values; |
|
| 285 | - |
|
| 286 | - // Same comment as above. |
|
| 287 | - $values = array(); |
|
| 288 | - foreach ($statementParts['where'] as $key => $value) { |
|
| 289 | - $values[$key] = str_replace($tableName . '0', $tableName, $value); |
|
| 290 | - } |
|
| 291 | - $statementParts['where'] = $values; |
|
| 292 | - |
|
| 293 | - // We must be more restrictive by transforming the "left" union by "inner" |
|
| 294 | - $values = array(); |
|
| 295 | - foreach ($statementParts['unions'] as $key => $value) { |
|
| 296 | - $values[$key] = str_replace('LEFT JOIN', 'INNER JOIN', $value); |
|
| 297 | - } |
|
| 298 | - $statementParts['unions'] = $values; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - return $statementParts; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - /** |
|
| 305 | - * Tell whether there is a recursive MM relation. |
|
| 306 | - * |
|
| 307 | - * @return bool |
|
| 308 | - */ |
|
| 309 | - public function hasRecursiveMMRelation() |
|
| 310 | - { |
|
| 311 | - return isset($this->tableNameAliases['aliasIncrement'][$this->query->getType()]); |
|
| 312 | - |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - /** |
|
| 316 | - * Returns the statement, ready to be executed. |
|
| 317 | - * |
|
| 318 | - * @param array $statementParts The SQL statement parts |
|
| 319 | - * @return string The SQL statement |
|
| 320 | - */ |
|
| 321 | - public function buildQuery(array $statementParts) |
|
| 322 | - { |
|
| 323 | - |
|
| 324 | - // Add more statement to the UNION part. |
|
| 325 | - if (!empty($statementParts['unions'])) { |
|
| 326 | - foreach ($statementParts['unions'] as $tableName => $unionPart) { |
|
| 327 | - if (!empty($statementParts['additionalWhereClause'][$tableName])) { |
|
| 328 | - $statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]); |
|
| 329 | - } |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - |
|
| 333 | - $statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']); |
|
| 334 | - if (!empty($statementParts['where'])) { |
|
| 335 | - $statement .= ' WHERE ' . implode('', $statementParts['where']); |
|
| 336 | - if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) { |
|
| 337 | - $statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
| 338 | - } |
|
| 339 | - } elseif (!empty($statementParts['additionalWhereClause'])) { |
|
| 340 | - $statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
| 341 | - } |
|
| 342 | - if (!empty($statementParts['orderings'])) { |
|
| 343 | - $statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']); |
|
| 344 | - } |
|
| 345 | - if (!empty($statementParts['limit'])) { |
|
| 346 | - $statement .= ' LIMIT ' . $statementParts['limit']; |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - return $statement; |
|
| 350 | - } |
|
| 351 | - |
|
| 352 | - /** |
|
| 353 | - * Transforms a Query Source into SQL and parameter arrays |
|
| 354 | - * |
|
| 355 | - * @param SourceInterface $source The source |
|
| 356 | - * @param array &$sql |
|
| 357 | - * @return void |
|
| 358 | - */ |
|
| 359 | - protected function parseSource(SourceInterface $source, array &$sql) |
|
| 360 | - { |
|
| 361 | - if ($source instanceof SelectorInterface) { |
|
| 362 | - $tableName = $source->getNodeTypeName(); |
|
| 363 | - $sql['fields'][$tableName] = $tableName . '.*'; |
|
| 364 | - $sql['tables'][$tableName] = $tableName; |
|
| 365 | - if ($this->query->getDistinct()) { |
|
| 366 | - $sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct(); |
|
| 367 | - $sql['keywords']['distinct'] = 'DISTINCT'; |
|
| 368 | - } |
|
| 369 | - } elseif ($source instanceof JoinInterface) { |
|
| 370 | - $this->parseJoin($source, $sql); |
|
| 371 | - } |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * Transforms a Join into SQL and parameter arrays |
|
| 376 | - * |
|
| 377 | - * @param JoinInterface $join The join |
|
| 378 | - * @param array &$sql The query parts |
|
| 379 | - * @return void |
|
| 380 | - */ |
|
| 381 | - protected function parseJoin(JoinInterface $join, array &$sql) |
|
| 382 | - { |
|
| 383 | - $leftSource = $join->getLeft(); |
|
| 384 | - $leftTableName = $leftSource->getSelectorName(); |
|
| 385 | - // $sql['fields'][$leftTableName] = $leftTableName . '.*'; |
|
| 386 | - $rightSource = $join->getRight(); |
|
| 387 | - if ($rightSource instanceof JoinInterface) { |
|
| 388 | - $rightTableName = $rightSource->getLeft()->getSelectorName(); |
|
| 389 | - } else { |
|
| 390 | - $rightTableName = $rightSource->getSelectorName(); |
|
| 391 | - $sql['fields'][$leftTableName] = $rightTableName . '.*'; |
|
| 392 | - } |
|
| 393 | - $sql['tables'][$leftTableName] = $leftTableName; |
|
| 394 | - $sql['unions'][$rightTableName] = 'LEFT JOIN ' . $rightTableName; |
|
| 395 | - $joinCondition = $join->getJoinCondition(); |
|
| 396 | - if ($joinCondition instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\EquiJoinCondition) { |
|
| 397 | - $column1Name = $joinCondition->getProperty1Name(); |
|
| 398 | - $column2Name = $joinCondition->getProperty2Name(); |
|
| 399 | - $sql['unions'][$rightTableName] .= ' ON ' . $joinCondition->getSelector1Name() . '.' . $column1Name . ' = ' . $joinCondition->getSelector2Name() . '.' . $column2Name; |
|
| 400 | - } |
|
| 401 | - if ($rightSource instanceof JoinInterface) { |
|
| 402 | - $this->parseJoin($rightSource, $sql); |
|
| 403 | - } |
|
| 404 | - } |
|
| 405 | - |
|
| 406 | - /** |
|
| 407 | - * Transforms a constraint into SQL and parameter arrays |
|
| 408 | - * |
|
| 409 | - * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint The constraint |
|
| 410 | - * @param SourceInterface $source The source |
|
| 411 | - * @param array &$sql The query parts |
|
| 412 | - * @param array &$parameters The parameters that will replace the markers |
|
| 413 | - * @return void |
|
| 414 | - */ |
|
| 415 | - protected function parseConstraint(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint = NULL, SourceInterface $source, array &$sql, array &$parameters) |
|
| 416 | - { |
|
| 417 | - if ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface) { |
|
| 418 | - $sql['where'][] = '('; |
|
| 419 | - $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters); |
|
| 420 | - $sql['where'][] = ' AND '; |
|
| 421 | - $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters); |
|
| 422 | - $sql['where'][] = ')'; |
|
| 423 | - } elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface) { |
|
| 424 | - $sql['where'][] = '('; |
|
| 425 | - $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters); |
|
| 426 | - $sql['where'][] = ' OR '; |
|
| 427 | - $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters); |
|
| 428 | - $sql['where'][] = ')'; |
|
| 429 | - } elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface) { |
|
| 430 | - $sql['where'][] = 'NOT ('; |
|
| 431 | - $this->parseConstraint($constraint->getConstraint(), $source, $sql, $parameters); |
|
| 432 | - $sql['where'][] = ')'; |
|
| 433 | - } elseif ($constraint instanceof ComparisonInterface) { |
|
| 434 | - $this->parseComparison($constraint, $source, $sql, $parameters); |
|
| 435 | - } |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * Parse a Comparison into SQL and parameter arrays. |
|
| 440 | - * |
|
| 441 | - * @param ComparisonInterface $comparison The comparison to parse |
|
| 442 | - * @param SourceInterface $source The source |
|
| 443 | - * @param array &$sql SQL query parts to add to |
|
| 444 | - * @param array &$parameters Parameters to bind to the SQL |
|
| 445 | - * @throws Exception\RepositoryException |
|
| 446 | - * @return void |
|
| 447 | - */ |
|
| 448 | - protected function parseComparison(ComparisonInterface $comparison, SourceInterface $source, array &$sql, array &$parameters) |
|
| 449 | - { |
|
| 450 | - $operand1 = $comparison->getOperand1(); |
|
| 451 | - $operator = $comparison->getOperator(); |
|
| 452 | - $operand2 = $comparison->getOperand2(); |
|
| 453 | - if ($operator === QueryInterface::OPERATOR_IN) { |
|
| 454 | - $items = array(); |
|
| 455 | - $hasValue = FALSE; |
|
| 456 | - foreach ($operand2 as $value) { |
|
| 457 | - $value = $this->getPlainValue($value); |
|
| 458 | - if ($value !== NULL) { |
|
| 459 | - $items[] = $value; |
|
| 460 | - $hasValue = TRUE; |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - if ($hasValue === FALSE) { |
|
| 464 | - $sql['where'][] = '1<>1'; |
|
| 465 | - } else { |
|
| 466 | - $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters, NULL); |
|
| 467 | - $parameters[] = $items; |
|
| 468 | - } |
|
| 469 | - } elseif ($operator === QueryInterface::OPERATOR_CONTAINS) { |
|
| 470 | - if ($operand2 === NULL) { |
|
| 471 | - $sql['where'][] = '1<>1'; |
|
| 472 | - } else { |
|
| 473 | - throw new \Exception('Not implemented! Contact extension author.', 1412931227); |
|
| 474 | - # @todo re-implement me if necessary. |
|
| 475 | - #$tableName = $this->query->getType(); |
|
| 476 | - #$propertyName = $operand1->getPropertyName(); |
|
| 477 | - #while (strpos($propertyName, '.') !== FALSE) { |
|
| 478 | - # $this->addUnionStatement($tableName, $propertyName, $sql); |
|
| 479 | - #} |
|
| 480 | - #$columnName = $propertyName; |
|
| 481 | - #$columnMap = $propertyName; |
|
| 482 | - #$typeOfRelation = $columnMap instanceof ColumnMap ? $columnMap->getTypeOfRelation() : NULL; |
|
| 483 | - #if ($typeOfRelation === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) { |
|
| 484 | - # $relationTableName = $columnMap->getRelationTableName(); |
|
| 485 | - # $sql['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=?)'; |
|
| 486 | - # $parameters[] = intval($this->getPlainValue($operand2)); |
|
| 487 | - #} elseif ($typeOfRelation === ColumnMap::RELATION_HAS_MANY) { |
|
| 488 | - # $parentKeyFieldName = $columnMap->getParentKeyFieldName(); |
|
| 489 | - # if (isset($parentKeyFieldName)) { |
|
| 490 | - # $childTableName = $columnMap->getChildTableName(); |
|
| 491 | - # $sql['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=?)'; |
|
| 492 | - # $parameters[] = intval($this->getPlainValue($operand2)); |
|
| 493 | - # } else { |
|
| 494 | - # $sql['where'][] = 'FIND_IN_SET(?,' . $tableName . '.' . $columnName . ')'; |
|
| 495 | - # $parameters[] = intval($this->getPlainValue($operand2)); |
|
| 496 | - # } |
|
| 497 | - #} else { |
|
| 498 | - # throw new Exception\RepositoryException('Unsupported or non-existing property name "' . $propertyName . '" used in relation matching.', 1327065745); |
|
| 499 | - #} |
|
| 500 | - } |
|
| 501 | - } else { |
|
| 502 | - if ($operand2 === NULL) { |
|
| 503 | - if ($operator === QueryInterface::OPERATOR_EQUAL_TO) { |
|
| 504 | - $operator = self::OPERATOR_EQUAL_TO_NULL; |
|
| 505 | - } elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) { |
|
| 506 | - $operator = self::OPERATOR_NOT_EQUAL_TO_NULL; |
|
| 507 | - } |
|
| 508 | - } |
|
| 509 | - $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters); |
|
| 510 | - $parameters[] = $this->getPlainValue($operand2); |
|
| 511 | - } |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - /** |
|
| 515 | - * Returns a plain value, i.e. objects are flattened out if possible. |
|
| 516 | - * |
|
| 517 | - * @param mixed $input |
|
| 518 | - * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException |
|
| 519 | - * @return mixed |
|
| 520 | - */ |
|
| 521 | - protected function getPlainValue($input) |
|
| 522 | - { |
|
| 523 | - if (is_array($input)) { |
|
| 524 | - throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932); |
|
| 525 | - } |
|
| 526 | - if ($input instanceof \DateTime) { |
|
| 527 | - return $input->format('U'); |
|
| 528 | - } elseif (is_object($input)) { |
|
| 529 | - if ($input instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) { |
|
| 530 | - $realInput = $input->_loadRealInstance(); |
|
| 531 | - } else { |
|
| 532 | - $realInput = $input; |
|
| 533 | - } |
|
| 534 | - if ($realInput instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) { |
|
| 535 | - return $realInput->getUid(); |
|
| 536 | - } else { |
|
| 537 | - throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An object of class "' . get_class($realInput) . '" could not be converted to a plain value.', 1274799934); |
|
| 538 | - } |
|
| 539 | - } elseif (is_bool($input)) { |
|
| 540 | - return $input === TRUE ? 1 : 0; |
|
| 541 | - } else { |
|
| 542 | - return $input; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - /** |
|
| 547 | - * Parse a DynamicOperand into SQL and parameter arrays. |
|
| 548 | - * |
|
| 549 | - * @param DynamicOperandInterface $operand |
|
| 550 | - * @param string $operator One of the JCR_OPERATOR_* constants |
|
| 551 | - * @param SourceInterface $source The source |
|
| 552 | - * @param array &$sql The query parts |
|
| 553 | - * @param array &$parameters The parameters that will replace the markers |
|
| 554 | - * @param string $valueFunction an optional SQL function to apply to the operand value |
|
| 555 | - * @return void |
|
| 556 | - */ |
|
| 557 | - protected function parseDynamicOperand(DynamicOperandInterface $operand, $operator, SourceInterface $source, array &$sql, array &$parameters, $valueFunction = NULL) |
|
| 558 | - { |
|
| 559 | - if ($operand instanceof LowerCaseInterface) { |
|
| 560 | - $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'LOWER'); |
|
| 561 | - } elseif ($operand instanceof UpperCaseInterface) { |
|
| 562 | - $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'UPPER'); |
|
| 563 | - } elseif ($operand instanceof PropertyValueInterface) { |
|
| 564 | - $propertyName = $operand->getPropertyName(); |
|
| 565 | - |
|
| 566 | - // Reset value. |
|
| 567 | - $this->currentChildTableNameAlias = ''; |
|
| 568 | - |
|
| 569 | - if ($source instanceof SelectorInterface) { |
|
| 570 | - $tableName = $this->query->getType(); |
|
| 571 | - while (strpos($propertyName, '.') !== FALSE) { |
|
| 572 | - $this->addUnionStatement($tableName, $propertyName, $sql); |
|
| 573 | - } |
|
| 574 | - } elseif ($source instanceof JoinInterface) { |
|
| 575 | - $tableName = $source->getJoinCondition()->getSelector1Name(); |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - $columnName = $propertyName; |
|
| 579 | - $operator = $this->resolveOperator($operator); |
|
| 580 | - $constraintSQL = ''; |
|
| 581 | - if ($valueFunction === NULL) { |
|
| 582 | - $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $operator . ' ?'; |
|
| 583 | - } else { |
|
| 584 | - $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $operator . ' ?'; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - if (isset($tableName) && !empty($this->currentChildTableNameAlias)) { |
|
| 588 | - $constraintSQL = $this->replaceTableNameByAlias($tableName, $this->currentChildTableNameAlias, $constraintSQL); |
|
| 589 | - } |
|
| 590 | - $sql['where'][] = $constraintSQL; |
|
| 591 | - } |
|
| 592 | - } |
|
| 593 | - |
|
| 594 | - /** |
|
| 595 | - * @param string &$tableName |
|
| 596 | - * @param array &$propertyPath |
|
| 597 | - * @param array &$sql |
|
| 598 | - * @throws Exception |
|
| 599 | - * @throws Exception\InvalidRelationConfigurationException |
|
| 600 | - * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\MissingColumnMapException |
|
| 601 | - */ |
|
| 602 | - protected function addUnionStatement(&$tableName, &$propertyPath, array &$sql) |
|
| 603 | - { |
|
| 604 | - |
|
| 605 | - $table = Tca::table($tableName); |
|
| 606 | - |
|
| 607 | - $explodedPropertyPath = explode('.', $propertyPath, 2); |
|
| 608 | - $fieldName = $explodedPropertyPath[0]; |
|
| 609 | - |
|
| 610 | - // Field of type "group" are special because property path must contain the table name |
|
| 611 | - // to determine the relation type. Example for sys_category, property path will look like "items.sys_file" |
|
| 612 | - if ($table->field($fieldName)->isGroup()) { |
|
| 613 | - $parts = explode('.', $propertyPath, 3); |
|
| 614 | - $explodedPropertyPath[0] = $parts[0] . '.' . $parts[1]; |
|
| 615 | - $explodedPropertyPath[1] = $parts[2]; |
|
| 616 | - $fieldName = $explodedPropertyPath[0]; |
|
| 617 | - } |
|
| 618 | - |
|
| 619 | - $parentKeyFieldName = $table->field($fieldName)->getForeignField(); |
|
| 620 | - $childTableName = $table->field($fieldName)->getForeignTable(); |
|
| 621 | - |
|
| 622 | - if ($childTableName === NULL) { |
|
| 623 | - throw new Exception\InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925); |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one" |
|
| 627 | - // sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons. |
|
| 628 | - // $parentKeyFieldName === NULL does the trick somehow. Before condition was if (isset($parentKeyFieldName)) |
|
| 629 | - if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === NULL) { |
|
| 630 | - $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid'; |
|
| 631 | - } else { |
|
| 632 | - $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName; |
|
| 633 | - } |
|
| 634 | - } elseif ($table->field($fieldName)->hasRelationManyToMany()) { |
|
| 635 | - $relationTableName = $table->field($fieldName)->getManyToManyTable(); |
|
| 636 | - |
|
| 637 | - $parentKeyFieldName = $table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local'; |
|
| 638 | - $childKeyFieldName = !$table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local'; |
|
| 639 | - |
|
| 640 | - // MM table e.g sys_category_record_mm |
|
| 641 | - $relationTableNameAlias = $this->generateAlias($relationTableName); |
|
| 642 | - $join = sprintf( |
|
| 643 | - 'LEFT JOIN %s AS %s ON %s.uid=%s.%s', $relationTableName, |
|
| 644 | - $relationTableNameAlias, |
|
| 645 | - $tableName, |
|
| 646 | - $relationTableNameAlias, |
|
| 647 | - $parentKeyFieldName |
|
| 648 | - ); |
|
| 649 | - $sql['unions'][$relationTableNameAlias] = $join; |
|
| 650 | - |
|
| 651 | - // Foreign table e.g sys_category |
|
| 652 | - $childTableNameAlias = $this->generateAlias($childTableName); |
|
| 653 | - $this->currentChildTableNameAlias = $childTableNameAlias; |
|
| 654 | - $join = sprintf( |
|
| 655 | - 'LEFT JOIN %s AS %s ON %s.%s=%s.uid', |
|
| 656 | - $childTableName, |
|
| 657 | - $childTableNameAlias, |
|
| 658 | - $relationTableNameAlias, |
|
| 659 | - $childKeyFieldName, |
|
| 660 | - $childTableNameAlias |
|
| 661 | - ); |
|
| 662 | - $sql['unions'][$childTableNameAlias] = $join; |
|
| 663 | - |
|
| 664 | - // Find a possible table name for a MM condition. |
|
| 665 | - $tableNameCondition = $table->field($fieldName)->getAdditionalTableNameCondition(); |
|
| 666 | - if ($tableNameCondition) { |
|
| 667 | - |
|
| 668 | - // If we can find a source file name, we can then retrieve more MM conditions from the TCA such as a field name. |
|
| 669 | - $sourceFileName = $this->query->getSourceFieldName(); |
|
| 670 | - if (empty($sourceFileName)) { |
|
| 671 | - $additionalMMConditions = array( |
|
| 672 | - 'tablenames' => $tableNameCondition, |
|
| 673 | - ); |
|
| 674 | - } else { |
|
| 675 | - $additionalMMConditions = Tca::table($tableNameCondition)->field($sourceFileName)->getAdditionalMMCondition(); |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - foreach ($additionalMMConditions as $additionalFieldName => $additionalMMCondition) { |
|
| 679 | - $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition); |
|
| 680 | - $sql['unions'][$relationTableNameAlias] .= $additionalJoin; |
|
| 681 | - |
|
| 682 | - $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition); |
|
| 683 | - $sql['unions'][$childTableNameAlias] .= $additionalJoin; |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - } |
|
| 687 | - |
|
| 688 | - |
|
| 689 | - } elseif ($table->field($fieldName)->hasMany()) { // includes relations "many-to-one" and "csv" relations |
|
| 690 | - $childTableNameAlias = $this->generateAlias($childTableName); |
|
| 691 | - $this->currentChildTableNameAlias = $childTableNameAlias; |
|
| 692 | - |
|
| 693 | - if (isset($parentKeyFieldName)) { |
|
| 694 | - $join = sprintf( |
|
| 695 | - 'LEFT JOIN %s AS %s ON %s.uid=%s.%s', |
|
| 696 | - $childTableName, |
|
| 697 | - $childTableNameAlias, |
|
| 698 | - $tableName, |
|
| 699 | - $childTableNameAlias, |
|
| 700 | - $parentKeyFieldName |
|
| 701 | - ); |
|
| 702 | - $sql['unions'][$childTableNameAlias] = $join; |
|
| 703 | - } else { |
|
| 704 | - $join = sprintf( |
|
| 705 | - 'LEFT JOIN %s AS %s ON (FIND_IN_SET(%s.uid, %s.%s))', |
|
| 706 | - $childTableName, |
|
| 707 | - $childTableNameAlias, |
|
| 708 | - $childTableNameAlias, |
|
| 709 | - $tableName, |
|
| 710 | - $fieldName |
|
| 711 | - ); |
|
| 712 | - $sql['unions'][$childTableNameAlias] = $join; |
|
| 713 | - } |
|
| 714 | - } else { |
|
| 715 | - throw new Exception('Could not determine type of relation.', 1252502725); |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - // TODO check if there is another solution for this |
|
| 719 | - $sql['keywords']['distinct'] = 'DISTINCT'; |
|
| 720 | - $propertyPath = $explodedPropertyPath[1]; |
|
| 721 | - $tableName = $childTableName; |
|
| 722 | - } |
|
| 723 | - |
|
| 724 | - /** |
|
| 725 | - * Returns the SQL operator for the given JCR operator type. |
|
| 726 | - * |
|
| 727 | - * @param string $operator One of the JCR_OPERATOR_* constants |
|
| 728 | - * @throws Exception |
|
| 729 | - * @return string an SQL operator |
|
| 730 | - */ |
|
| 731 | - protected function resolveOperator($operator) |
|
| 732 | - { |
|
| 733 | - switch ($operator) { |
|
| 734 | - case self::OPERATOR_EQUAL_TO_NULL: |
|
| 735 | - $operator = 'IS'; |
|
| 736 | - break; |
|
| 737 | - case self::OPERATOR_NOT_EQUAL_TO_NULL: |
|
| 738 | - $operator = 'IS NOT'; |
|
| 739 | - break; |
|
| 740 | - case QueryInterface::OPERATOR_IN: |
|
| 741 | - $operator = 'IN'; |
|
| 742 | - break; |
|
| 743 | - case QueryInterface::OPERATOR_EQUAL_TO: |
|
| 744 | - $operator = '='; |
|
| 745 | - break; |
|
| 746 | - case QueryInterface::OPERATOR_NOT_EQUAL_TO: |
|
| 747 | - $operator = '!='; |
|
| 748 | - break; |
|
| 749 | - case QueryInterface::OPERATOR_LESS_THAN: |
|
| 750 | - $operator = '<'; |
|
| 751 | - break; |
|
| 752 | - case QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO: |
|
| 753 | - $operator = '<='; |
|
| 754 | - break; |
|
| 755 | - case QueryInterface::OPERATOR_GREATER_THAN: |
|
| 756 | - $operator = '>'; |
|
| 757 | - break; |
|
| 758 | - case QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO: |
|
| 759 | - $operator = '>='; |
|
| 760 | - break; |
|
| 761 | - case QueryInterface::OPERATOR_LIKE: |
|
| 762 | - $operator = 'LIKE'; |
|
| 763 | - break; |
|
| 764 | - default: |
|
| 765 | - throw new Exception('Unsupported operator encountered.', 1242816073); |
|
| 766 | - } |
|
| 767 | - return $operator; |
|
| 768 | - } |
|
| 769 | - |
|
| 770 | - /** |
|
| 771 | - * Replace query placeholders in a query part by the given |
|
| 772 | - * parameters. |
|
| 773 | - * |
|
| 774 | - * @param string &$sqlString The query part with placeholders |
|
| 775 | - * @param array $parameters The parameters |
|
| 776 | - * @param string $tableName |
|
| 777 | - * |
|
| 778 | - * @throws Exception |
|
| 779 | - */ |
|
| 780 | - protected function replacePlaceholders(&$sqlString, array $parameters, $tableName = 'foo') |
|
| 781 | - { |
|
| 782 | - // TODO profile this method again |
|
| 783 | - if (substr_count($sqlString, '?') !== count($parameters)) { |
|
| 784 | - throw new Exception('The number of question marks to replace must be equal to the number of parameters.', 1242816074); |
|
| 785 | - } |
|
| 786 | - $offset = 0; |
|
| 787 | - foreach ($parameters as $parameter) { |
|
| 788 | - $markPosition = strpos($sqlString, '?', $offset); |
|
| 789 | - if ($markPosition !== FALSE) { |
|
| 790 | - if ($parameter === NULL) { |
|
| 791 | - $parameter = 'NULL'; |
|
| 792 | - } elseif (is_array($parameter) || $parameter instanceof \ArrayAccess || $parameter instanceof \Traversable) { |
|
| 793 | - $items = array(); |
|
| 794 | - foreach ($parameter as $item) { |
|
| 795 | - $items[] = $this->databaseHandle->fullQuoteStr($item, $tableName); |
|
| 796 | - } |
|
| 797 | - $parameter = '(' . implode(',', $items) . ')'; |
|
| 798 | - } else { |
|
| 799 | - $parameter = $this->databaseHandle->fullQuoteStr($parameter, $tableName); |
|
| 800 | - } |
|
| 801 | - $sqlString = substr($sqlString, 0, $markPosition) . $parameter . substr($sqlString, ($markPosition + 1)); |
|
| 802 | - } |
|
| 803 | - $offset = $markPosition + strlen($parameter); |
|
| 804 | - } |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - /** |
|
| 808 | - * Adds additional WHERE statements according to the query settings. |
|
| 809 | - * |
|
| 810 | - * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
| 811 | - * @param string $tableNameOrAlias The table name to add the additional where clause for |
|
| 812 | - * @param array &$statementParts |
|
| 813 | - * @return void |
|
| 814 | - */ |
|
| 815 | - protected function addAdditionalWhereClause(QuerySettingsInterface $querySettings, $tableNameOrAlias, &$statementParts) |
|
| 816 | - { |
|
| 817 | - $this->addVisibilityConstraintStatement($querySettings, $tableNameOrAlias, $statementParts); |
|
| 818 | - if ($querySettings->getRespectSysLanguage()) { |
|
| 819 | - $this->addSysLanguageStatement($tableNameOrAlias, $statementParts, $querySettings); |
|
| 820 | - } |
|
| 821 | - if ($querySettings->getRespectStoragePage()) { |
|
| 822 | - $this->addPageIdStatement($tableNameOrAlias, $statementParts, $querySettings->getStoragePageIds()); |
|
| 823 | - } |
|
| 824 | - } |
|
| 825 | - |
|
| 826 | - /** |
|
| 827 | - * Adds enableFields and deletedClause to the query if necessary |
|
| 828 | - * |
|
| 829 | - * @param QuerySettingsInterface $querySettings |
|
| 830 | - * @param string $tableNameOrAlias The database table name |
|
| 831 | - * @param array &$statementParts The query parts |
|
| 832 | - * @return void |
|
| 833 | - */ |
|
| 834 | - protected function addVisibilityConstraintStatement(QuerySettingsInterface $querySettings, $tableNameOrAlias, array &$statementParts) |
|
| 835 | - { |
|
| 836 | - $statement = ''; |
|
| 837 | - $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 838 | - if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { |
|
| 839 | - $ignoreEnableFields = $querySettings->getIgnoreEnableFields(); |
|
| 840 | - $enableFieldsToBeIgnored = $querySettings->getEnableFieldsToBeIgnored(); |
|
| 841 | - $includeDeleted = $querySettings->getIncludeDeleted(); |
|
| 842 | - if ($this->environmentService->isEnvironmentInFrontendMode()) { |
|
| 843 | - $statement .= $this->getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted); |
|
| 844 | - } else { |
|
| 845 | - // TYPO3_MODE === 'BE' |
|
| 846 | - $statement .= $this->getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted); |
|
| 847 | - } |
|
| 848 | - |
|
| 849 | - // Remove the prefixing "AND" if any. |
|
| 850 | - if (!empty($statement)) { |
|
| 851 | - $statement = strtolower(substr($statement, 1, 3)) === 'and' ? substr($statement, 5) : $statement; |
|
| 852 | - $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $statement; |
|
| 853 | - } |
|
| 854 | - } |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - /** |
|
| 858 | - * Returns constraint statement for frontend context |
|
| 859 | - * |
|
| 860 | - * @param string $tableNameOrAlias |
|
| 861 | - * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored |
|
| 862 | - * @param array $enableFieldsToBeIgnored If $ignoreEnableFields is true, this array specifies enable fields to be ignored. If it is NULL or an empty array (default) all enable fields are ignored. |
|
| 863 | - * @param boolean $includeDeleted A flag indicating whether deleted records should be included |
|
| 864 | - * @return string |
|
| 865 | - * @throws Exception\InconsistentQuerySettingsException |
|
| 866 | - */ |
|
| 867 | - protected function getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored = array(), $includeDeleted) |
|
| 868 | - { |
|
| 869 | - $statement = ''; |
|
| 870 | - $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 871 | - if ($ignoreEnableFields && !$includeDeleted) { |
|
| 872 | - if (count($enableFieldsToBeIgnored)) { |
|
| 873 | - // array_combine() is necessary because of the way \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() is implemented |
|
| 874 | - $statement .= $this->getPageRepository()->enableFields($tableName, -1, array_combine($enableFieldsToBeIgnored, $enableFieldsToBeIgnored)); |
|
| 875 | - } else { |
|
| 876 | - $statement .= $this->getPageRepository()->deleteClause($tableName); |
|
| 877 | - } |
|
| 878 | - } elseif (!$ignoreEnableFields && !$includeDeleted) { |
|
| 879 | - $statement .= $this->getPageRepository()->enableFields($tableName); |
|
| 880 | - } elseif (!$ignoreEnableFields && $includeDeleted) { |
|
| 881 | - throw new Exception\InconsistentQuerySettingsException('Query setting "ignoreEnableFields=FALSE" can not be used together with "includeDeleted=TRUE" in frontend context.', 1327678173); |
|
| 882 | - } |
|
| 883 | - return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement); |
|
| 884 | - } |
|
| 885 | - |
|
| 886 | - /** |
|
| 887 | - * Returns constraint statement for backend context |
|
| 888 | - * |
|
| 889 | - * @param string $tableNameOrAlias |
|
| 890 | - * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored |
|
| 891 | - * @param boolean $includeDeleted A flag indicating whether deleted records should be included |
|
| 892 | - * @return string |
|
| 893 | - */ |
|
| 894 | - protected function getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted) |
|
| 895 | - { |
|
| 896 | - $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 897 | - $statement = ''; |
|
| 898 | - if (!$ignoreEnableFields) { |
|
| 899 | - $statement .= BackendUtility::BEenableFields($tableName); |
|
| 900 | - } |
|
| 901 | - |
|
| 902 | - // If the table is found to have "workspace" support, add the corresponding fields in the statement. |
|
| 903 | - if (Tca::table($tableName)->hasWorkspaceSupport()) { |
|
| 904 | - if ($this->getBackendUser()->workspace === 0) { |
|
| 905 | - $statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE); |
|
| 906 | - } else { |
|
| 907 | - // Show only records of live and of the current workspace |
|
| 908 | - // In case we are in a Versioning preview |
|
| 909 | - $statement .= ' AND (' . |
|
| 910 | - $tableName . '.t3ver_wsid=0 OR ' . |
|
| 911 | - $tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace . |
|
| 912 | - ')'; |
|
| 913 | - } |
|
| 914 | - |
|
| 915 | - // Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0 |
|
| 916 | - $statement .= ' AND ' . $tableName . '.pid<>-1'; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - if (!$includeDeleted) { |
|
| 920 | - $statement .= BackendUtility::deleteClause($tableName); |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement); |
|
| 924 | - } |
|
| 925 | - |
|
| 926 | - /** |
|
| 927 | - * Builds the language field statement |
|
| 928 | - * |
|
| 929 | - * @param string $tableNameOrAlias The database table name |
|
| 930 | - * @param array &$statementParts The query parts |
|
| 931 | - * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
| 932 | - * @throws Exception |
|
| 933 | - * @return void |
|
| 934 | - */ |
|
| 935 | - protected function addSysLanguageStatement($tableNameOrAlias, array &$statementParts, $querySettings) |
|
| 936 | - { |
|
| 937 | - |
|
| 938 | - $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 939 | - if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { |
|
| 940 | - if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) { |
|
| 941 | - // Select all entries for the current language |
|
| 942 | - $additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)'; |
|
| 943 | - // If any language is set -> get those entries which are not translated yet |
|
| 944 | - // They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode |
|
| 945 | - if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) |
|
| 946 | - && $querySettings->getLanguageUid() > 0 |
|
| 947 | - ) { |
|
| 948 | - $additionalWhereClause .= ' OR (' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' . |
|
| 949 | - ' AND ' . $tableNameOrAlias . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . |
|
| 950 | - ' FROM ' . $tableName . |
|
| 951 | - ' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' . |
|
| 952 | - ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0'; |
|
| 953 | - |
|
| 954 | - // Add delete clause to ensure all entries are loaded |
|
| 955 | - if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) { |
|
| 956 | - $additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0'; |
|
| 957 | - } |
|
| 958 | - $additionalWhereClause .= '))'; |
|
| 959 | - } |
|
| 960 | - $statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')'; |
|
| 961 | - } |
|
| 962 | - } |
|
| 963 | - } |
|
| 964 | - |
|
| 965 | - /** |
|
| 966 | - * Builds the page ID checking statement |
|
| 967 | - * |
|
| 968 | - * @param string $tableNameOrAlias The database table name |
|
| 969 | - * @param array &$statementParts The query parts |
|
| 970 | - * @param array $storagePageIds list of storage page ids |
|
| 971 | - * @throws Exception\InconsistentQuerySettingsException |
|
| 972 | - * @return void |
|
| 973 | - */ |
|
| 974 | - protected function addPageIdStatement($tableNameOrAlias, array &$statementParts, array $storagePageIds) |
|
| 975 | - { |
|
| 976 | - |
|
| 977 | - $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 978 | - $tableColumns = $this->tableColumnCache->get($tableName); |
|
| 979 | - if ($tableColumns === FALSE) { |
|
| 980 | - $tableColumns = $this->databaseHandle->admin_get_fields($tableName); |
|
| 981 | - $this->tableColumnCache->set($tableName, $tableColumns); |
|
| 982 | - } |
|
| 983 | - if (is_array($GLOBALS['TCA'][$tableName]['ctrl']) && array_key_exists('pid', $tableColumns)) { |
|
| 984 | - $rootLevel = (int)$GLOBALS['TCA'][$tableName]['ctrl']['rootLevel']; |
|
| 985 | - if ($rootLevel) { |
|
| 986 | - if ($rootLevel === 1) { |
|
| 987 | - $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $tableNameOrAlias . '.pid = 0'; |
|
| 988 | - } |
|
| 989 | - } else { |
|
| 990 | - if (empty($storagePageIds)) { |
|
| 991 | - throw new Exception\InconsistentQuerySettingsException('Missing storage page ids.', 1365779762); |
|
| 992 | - } |
|
| 993 | - $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $tableNameOrAlias . '.pid IN (' . implode(', ', $storagePageIds) . ')'; |
|
| 994 | - } |
|
| 995 | - } |
|
| 996 | - } |
|
| 997 | - |
|
| 998 | - /** |
|
| 999 | - * Transforms orderings into SQL. |
|
| 1000 | - * |
|
| 1001 | - * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering) |
|
| 1002 | - * @param SourceInterface $source The source |
|
| 1003 | - * @param array &$sql The query parts |
|
| 1004 | - * @throws Exception\UnsupportedOrderException |
|
| 1005 | - * @return void |
|
| 1006 | - */ |
|
| 1007 | - protected function parseOrderings(array $orderings, SourceInterface $source, array &$sql) |
|
| 1008 | - { |
|
| 1009 | - foreach ($orderings as $fieldNameAndPath => $order) { |
|
| 1010 | - switch ($order) { |
|
| 1011 | - case QueryInterface::ORDER_ASCENDING: |
|
| 1012 | - $order = 'ASC'; |
|
| 1013 | - break; |
|
| 1014 | - case QueryInterface::ORDER_DESCENDING: |
|
| 1015 | - $order = 'DESC'; |
|
| 1016 | - break; |
|
| 1017 | - default: |
|
| 1018 | - throw new Exception\UnsupportedOrderException('Unsupported order encountered.', 1456845126); |
|
| 1019 | - } |
|
| 1020 | - |
|
| 1021 | - $tableName = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->query->getType()); |
|
| 1022 | - $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $tableName); |
|
| 1023 | - $sql['orderings'][] = sprintf('%s.%s %s', $tableName, $fieldName, $order); |
|
| 1024 | - } |
|
| 1025 | - } |
|
| 1026 | - |
|
| 1027 | - /** |
|
| 1028 | - * Transforms limit and offset into SQL |
|
| 1029 | - * |
|
| 1030 | - * @param int $limit |
|
| 1031 | - * @param int $offset |
|
| 1032 | - * @param array &$sql |
|
| 1033 | - * @return void |
|
| 1034 | - */ |
|
| 1035 | - protected function parseLimitAndOffset($limit, $offset, array &$sql) |
|
| 1036 | - { |
|
| 1037 | - if ($limit !== NULL && $offset !== NULL) { |
|
| 1038 | - $sql['limit'] = intval($offset) . ', ' . intval($limit); |
|
| 1039 | - } elseif ($limit !== NULL) { |
|
| 1040 | - $sql['limit'] = intval($limit); |
|
| 1041 | - } |
|
| 1042 | - } |
|
| 1043 | - |
|
| 1044 | - /** |
|
| 1045 | - * Transforms a Resource from a database query to an array of rows. |
|
| 1046 | - * |
|
| 1047 | - * @param resource $result The result |
|
| 1048 | - * @return array The result as an array of rows (tuples) |
|
| 1049 | - */ |
|
| 1050 | - protected function getRowsFromResult($result) |
|
| 1051 | - { |
|
| 1052 | - $rows = array(); |
|
| 1053 | - while ($row = $this->databaseHandle->sql_fetch_assoc($result)) { |
|
| 1054 | - if (is_array($row)) { |
|
| 1055 | - |
|
| 1056 | - // Get language uid from querySettings. |
|
| 1057 | - // Ensure the backend handling is not broken (fallback to Get parameter 'L' if needed) |
|
| 1058 | - $overlaidRow = $this->doLanguageAndWorkspaceOverlay($this->query->getSource(), $row, $this->query->getQuerySettings()); |
|
| 1059 | - $contentObject = GeneralUtility::makeInstance($this->objectType, $this->query->getType(), $overlaidRow); |
|
| 1060 | - $rows[] = $contentObject; |
|
| 1061 | - } |
|
| 1062 | - } |
|
| 1063 | - |
|
| 1064 | - return $rows; |
|
| 1065 | - } |
|
| 1066 | - |
|
| 1067 | - /** |
|
| 1068 | - * Performs workspace and language overlay on the given row array. The language and workspace id is automatically |
|
| 1069 | - * detected (depending on FE or BE context). You can also explicitly set the language/workspace id. |
|
| 1070 | - * |
|
| 1071 | - * @param SourceInterface $source The source (selector od join) |
|
| 1072 | - * @param array $row |
|
| 1073 | - * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
| 1074 | - * @return array |
|
| 1075 | - */ |
|
| 1076 | - protected function doLanguageAndWorkspaceOverlay(SourceInterface $source, array $row, $querySettings) |
|
| 1077 | - { |
|
| 1078 | - |
|
| 1079 | - /** @var SelectorInterface $source */ |
|
| 1080 | - $tableName = $source->getSelectorName(); |
|
| 1081 | - |
|
| 1082 | - $pageRepository = $this->getPageRepository(); |
|
| 1083 | - if (is_object($GLOBALS['TSFE'])) { |
|
| 1084 | - $languageMode = $GLOBALS['TSFE']->sys_language_mode; |
|
| 1085 | - if ($this->isBackendUserLogged() && $this->getBackendUser()->workspace !== 0) { |
|
| 1086 | - $pageRepository->versioningWorkspaceId = $this->getBackendUser()->workspace; |
|
| 1087 | - } |
|
| 1088 | - } else { |
|
| 1089 | - $languageMode = ''; |
|
| 1090 | - $workspaceUid = $this->getBackendUser()->workspace; |
|
| 1091 | - $pageRepository->versioningWorkspaceId = $workspaceUid; |
|
| 1092 | - if ($this->getBackendUser()->workspace !== 0) { |
|
| 1093 | - $pageRepository->versioningPreview = 1; |
|
| 1094 | - } |
|
| 1095 | - } |
|
| 1096 | - |
|
| 1097 | - // If current row is a translation select its parent |
|
| 1098 | - if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) |
|
| 1099 | - && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) |
|
| 1100 | - ) { |
|
| 1101 | - if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']]) |
|
| 1102 | - && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0 |
|
| 1103 | - ) { |
|
| 1104 | - $row = $this->databaseHandle->exec_SELECTgetSingleRow( |
|
| 1105 | - $tableName . '.*', |
|
| 1106 | - $tableName, |
|
| 1107 | - $tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] . |
|
| 1108 | - ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' |
|
| 1109 | - ); |
|
| 1110 | - } |
|
| 1111 | - } |
|
| 1112 | - |
|
| 1113 | - // Retrieve the original uid |
|
| 1114 | - // @todo It looks for me this code will never be used! "_ORIG_uid" is something from extbase. Adjust me or remove me in 0.4 + 2 version! |
|
| 1115 | - $pageRepository->versionOL($tableName, $row, TRUE); |
|
| 1116 | - if ($pageRepository->versioningPreview && isset($row['_ORIG_uid'])) { |
|
| 1117 | - $row['uid'] = $row['_ORIG_uid']; |
|
| 1118 | - } |
|
| 1119 | - |
|
| 1120 | - // Special case for table "pages" |
|
| 1121 | - if ($tableName == 'pages') { |
|
| 1122 | - $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid()); |
|
| 1123 | - } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) |
|
| 1124 | - && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '' |
|
| 1125 | - ) { |
|
| 1126 | - if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) { |
|
| 1127 | - $overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : ''; |
|
| 1128 | - $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode); |
|
| 1129 | - } |
|
| 1130 | - } |
|
| 1131 | - |
|
| 1132 | - return $row; |
|
| 1133 | - } |
|
| 1134 | - |
|
| 1135 | - /** |
|
| 1136 | - * Return a resolved table name given a possible table name alias. |
|
| 1137 | - * |
|
| 1138 | - * @param string $tableNameOrAlias |
|
| 1139 | - * @return string |
|
| 1140 | - */ |
|
| 1141 | - protected function resolveTableNameAlias($tableNameOrAlias) |
|
| 1142 | - { |
|
| 1143 | - $resolvedTableName = $tableNameOrAlias; |
|
| 1144 | - if (!empty($this->tableNameAliases['aliases'][$tableNameOrAlias])) { |
|
| 1145 | - $resolvedTableName = $this->tableNameAliases['aliases'][$tableNameOrAlias]; |
|
| 1146 | - } |
|
| 1147 | - return $resolvedTableName; |
|
| 1148 | - } |
|
| 1149 | - |
|
| 1150 | - /** |
|
| 1151 | - * Generate a unique table name alias for the given table name. |
|
| 1152 | - * |
|
| 1153 | - * @param string $tableName |
|
| 1154 | - * @return string |
|
| 1155 | - */ |
|
| 1156 | - protected function generateAlias($tableName) |
|
| 1157 | - { |
|
| 1158 | - |
|
| 1159 | - if (!isset($this->tableNameAliases['aliasIncrement'][$tableName])) { |
|
| 1160 | - $this->tableNameAliases['aliasIncrement'][$tableName] = 0; |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - $numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName]; |
|
| 1164 | - $tableNameAlias = $tableName . $numberOfAliases; |
|
| 1165 | - |
|
| 1166 | - $this->tableNameAliases['aliasIncrement'][$tableName]++; |
|
| 1167 | - $this->tableNameAliases['aliases'][$tableNameAlias] = $tableName; |
|
| 1168 | - |
|
| 1169 | - return $tableNameAlias; |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - /** |
|
| 1173 | - * Replace the table names by its table name alias within the given statement. |
|
| 1174 | - * |
|
| 1175 | - * @param string $tableName |
|
| 1176 | - * @param string $tableNameAlias |
|
| 1177 | - * @param string $statement |
|
| 1178 | - * @return string |
|
| 1179 | - */ |
|
| 1180 | - protected function replaceTableNameByAlias($tableName, $tableNameAlias, $statement) |
|
| 1181 | - { |
|
| 1182 | - if ($statement && $tableName !== $tableNameAlias) { |
|
| 1183 | - $statement = str_replace($tableName, $tableNameAlias, $statement); |
|
| 1184 | - } |
|
| 1185 | - return $statement; |
|
| 1186 | - } |
|
| 1187 | - |
|
| 1188 | - /** |
|
| 1189 | - * Returns an instance of the current Backend User. |
|
| 1190 | - * |
|
| 1191 | - * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 1192 | - */ |
|
| 1193 | - protected function getBackendUser() |
|
| 1194 | - { |
|
| 1195 | - return $GLOBALS['BE_USER']; |
|
| 1196 | - } |
|
| 1197 | - |
|
| 1198 | - /** |
|
| 1199 | - * Tell whether a Backend User is logged in. |
|
| 1200 | - * |
|
| 1201 | - * @return bool |
|
| 1202 | - */ |
|
| 1203 | - protected function isBackendUserLogged() |
|
| 1204 | - { |
|
| 1205 | - return is_object($GLOBALS['BE_USER']); |
|
| 1206 | - } |
|
| 1207 | - |
|
| 1208 | - /** |
|
| 1209 | - * @return PageRepository |
|
| 1210 | - */ |
|
| 1211 | - protected function getPageRepository() |
|
| 1212 | - { |
|
| 1213 | - if (!$this->pageRepository instanceof PageRepository) { |
|
| 1214 | - if ($this->environmentService->isEnvironmentInFrontendMode() && is_object($GLOBALS['TSFE'])) { |
|
| 1215 | - $this->pageRepository = $GLOBALS['TSFE']->sys_page; |
|
| 1216 | - } else { |
|
| 1217 | - $this->pageRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository'); |
|
| 1218 | - } |
|
| 1219 | - } |
|
| 1220 | - |
|
| 1221 | - return $this->pageRepository; |
|
| 1222 | - } |
|
| 1223 | - |
|
| 1224 | - /** |
|
| 1225 | - * @return \Fab\Vidi\Resolver\FieldPathResolver |
|
| 1226 | - */ |
|
| 1227 | - protected function getFieldPathResolver() |
|
| 1228 | - { |
|
| 1229 | - return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver'); |
|
| 1230 | - } |
|
| 1231 | - |
|
| 1232 | - /** |
|
| 1233 | - * Checks if there are SQL errors in the last query, and if yes, throw an exception. |
|
| 1234 | - * |
|
| 1235 | - * @return void |
|
| 1236 | - * @param string $sql The SQL statement |
|
| 1237 | - * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException |
|
| 1238 | - */ |
|
| 1239 | - protected function checkSqlErrors($sql = '') |
|
| 1240 | - { |
|
| 1241 | - $error = $this->databaseHandle->sql_error(); |
|
| 1242 | - if ($error !== '') { |
|
| 1243 | - $error .= $sql ? ': ' . $sql : ''; |
|
| 1244 | - throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException($error, 1247602160); |
|
| 1245 | - } |
|
| 1246 | - } |
|
| 41 | + const OPERATOR_EQUAL_TO_NULL = 'operatorEqualToNull'; |
|
| 42 | + const OPERATOR_NOT_EQUAL_TO_NULL = 'operatorNotEqualToNull'; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * The TYPO3 database object |
|
| 46 | + * |
|
| 47 | + * @var \TYPO3\CMS\Core\Database\DatabaseConnection |
|
| 48 | + */ |
|
| 49 | + protected $databaseHandle; |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * The TYPO3 page repository. Used for language and workspace overlay |
|
| 53 | + * |
|
| 54 | + * @var PageRepository |
|
| 55 | + */ |
|
| 56 | + protected $pageRepository; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * A first-level TypoScript configuration cache |
|
| 60 | + * |
|
| 61 | + * @var array |
|
| 62 | + */ |
|
| 63 | + protected $pageTSConfigCache = array(); |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface |
|
| 67 | + * @inject |
|
| 68 | + */ |
|
| 69 | + protected $configurationManager; |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * @var \TYPO3\CMS\Extbase\Service\CacheService |
|
| 73 | + * @inject |
|
| 74 | + */ |
|
| 75 | + protected $cacheService; |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @var \TYPO3\CMS\Core\Cache\CacheManager |
|
| 79 | + * @inject |
|
| 80 | + */ |
|
| 81 | + protected $cacheManager; |
|
| 82 | + |
|
| 83 | + /** |
|
| 84 | + * @var \TYPO3\CMS\Core\Cache\Frontend\VariableFrontend |
|
| 85 | + */ |
|
| 86 | + protected $tableColumnCache; |
|
| 87 | + |
|
| 88 | + /** |
|
| 89 | + * @var \TYPO3\CMS\Extbase\Service\EnvironmentService |
|
| 90 | + * @inject |
|
| 91 | + */ |
|
| 92 | + protected $environmentService; |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @var \Fab\Vidi\Persistence\Query |
|
| 96 | + */ |
|
| 97 | + protected $query; |
|
| 98 | + |
|
| 99 | + /** |
|
| 100 | + * Store some info related to table name and its aliases. |
|
| 101 | + * |
|
| 102 | + * @var array |
|
| 103 | + */ |
|
| 104 | + protected $tableNameAliases = array( |
|
| 105 | + 'aliases' => array(), |
|
| 106 | + 'aliasIncrement' => array(), |
|
| 107 | + ); |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * Use to store the current foreign table name alias. |
|
| 111 | + * |
|
| 112 | + * @var string |
|
| 113 | + */ |
|
| 114 | + protected $currentChildTableNameAlias = ''; |
|
| 115 | + |
|
| 116 | + /** |
|
| 117 | + * The default object type being returned. |
|
| 118 | + * |
|
| 119 | + * @var string |
|
| 120 | + */ |
|
| 121 | + protected $objectType = 'Fab\Vidi\Domain\Model\Content'; |
|
| 122 | + |
|
| 123 | + /** |
|
| 124 | + * Constructor. takes the database handle from $GLOBALS['TYPO3_DB'] |
|
| 125 | + */ |
|
| 126 | + public function __construct(QueryInterface $query) |
|
| 127 | + { |
|
| 128 | + $this->query = $query; |
|
| 129 | + $this->databaseHandle = $GLOBALS['TYPO3_DB']; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + /** |
|
| 133 | + * Lifecycle method |
|
| 134 | + * |
|
| 135 | + * @return void |
|
| 136 | + */ |
|
| 137 | + public function initializeObject() |
|
| 138 | + { |
|
| 139 | + $this->tableColumnCache = $this->cacheManager->getCache('extbase_typo3dbbackend_tablecolumns'); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @param array $identifier |
|
| 144 | + * @return string |
|
| 145 | + */ |
|
| 146 | + protected function parseIdentifier(array $identifier) |
|
| 147 | + { |
|
| 148 | + $fieldNames = array_keys($identifier); |
|
| 149 | + $suffixedFieldNames = array(); |
|
| 150 | + foreach ($fieldNames as $fieldName) { |
|
| 151 | + $suffixedFieldNames[] = $fieldName . '=?'; |
|
| 152 | + } |
|
| 153 | + return implode(' AND ', $suffixedFieldNames); |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + /** |
|
| 157 | + * Returns the result of the query |
|
| 158 | + */ |
|
| 159 | + public function fetchResult() |
|
| 160 | + { |
|
| 161 | + |
|
| 162 | + $parameters = array(); |
|
| 163 | + $statementParts = $this->parseQuery($this->query, $parameters); |
|
| 164 | + $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); // Mmm... check if that is the right way of doing that. |
|
| 165 | + |
|
| 166 | + $sql = $this->buildQuery($statementParts); |
|
| 167 | + $tableName = ''; |
|
| 168 | + if (is_array($statementParts) && !empty($statementParts['tables'][0])) { |
|
| 169 | + $tableName = $statementParts['tables'][0]; |
|
| 170 | + } |
|
| 171 | + $this->replacePlaceholders($sql, $parameters, $tableName); |
|
| 172 | + #print $sql; exit(); // @debug |
|
| 173 | + |
|
| 174 | + $result = $this->databaseHandle->sql_query($sql); |
|
| 175 | + $this->checkSqlErrors($sql); |
|
| 176 | + $rows = $this->getRowsFromResult($result); |
|
| 177 | + $this->databaseHandle->sql_free_result($result); |
|
| 178 | + |
|
| 179 | + return $rows; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + /** |
|
| 183 | + * Returns the number of tuples matching the query. |
|
| 184 | + * |
|
| 185 | + * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException |
|
| 186 | + * @return int The number of matching tuples |
|
| 187 | + */ |
|
| 188 | + public function countResult() |
|
| 189 | + { |
|
| 190 | + |
|
| 191 | + $parameters = array(); |
|
| 192 | + $statementParts = $this->parseQuery($this->query, $parameters); |
|
| 193 | + $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); // Mmm... check if that is the right way of doing that. |
|
| 194 | + // Reset $statementParts for valid table return |
|
| 195 | + reset($statementParts); |
|
| 196 | + |
|
| 197 | + // if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints |
|
| 198 | + if (!empty($statementParts['limit'])) { |
|
| 199 | + $statement = $this->buildQuery($statementParts); |
|
| 200 | + $this->replacePlaceholders($statement, $parameters, current($statementParts['tables'])); |
|
| 201 | + #print $statement; exit(); // @debug |
|
| 202 | + $result = $this->databaseHandle->sql_query($statement); |
|
| 203 | + $this->checkSqlErrors($statement); |
|
| 204 | + $count = $this->databaseHandle->sql_num_rows($result); |
|
| 205 | + } else { |
|
| 206 | + $statementParts['fields'] = array('COUNT(*)'); |
|
| 207 | + // having orderings without grouping is not compatible with non-MySQL DBMS |
|
| 208 | + $statementParts['orderings'] = array(); |
|
| 209 | + if (isset($statementParts['keywords']['distinct'])) { |
|
| 210 | + unset($statementParts['keywords']['distinct']); |
|
| 211 | + $distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid'; |
|
| 212 | + $statementParts['fields'] = array('COUNT(DISTINCT ' . reset($statementParts['tables']) . '.' . $distinctField . ')'); |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + $statement = $this->buildQuery($statementParts); |
|
| 216 | + $this->replacePlaceholders($statement, $parameters, current($statementParts['tables'])); |
|
| 217 | + |
|
| 218 | + #print $statement; exit(); // @debug |
|
| 219 | + $result = $this->databaseHandle->sql_query($statement); |
|
| 220 | + $this->checkSqlErrors($statement); |
|
| 221 | + $count = 0; |
|
| 222 | + if ($result) { |
|
| 223 | + $row = $this->databaseHandle->sql_fetch_assoc($result); |
|
| 224 | + $count = current($row); |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + $this->databaseHandle->sql_free_result($result); |
|
| 228 | + return (int)$count; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + /** |
|
| 232 | + * Parses the query and returns the SQL statement parts. |
|
| 233 | + * |
|
| 234 | + * @param QueryInterface $query The query |
|
| 235 | + * @param array &$parameters |
|
| 236 | + * @return array The SQL statement parts |
|
| 237 | + */ |
|
| 238 | + public function parseQuery(QueryInterface $query, array &$parameters) |
|
| 239 | + { |
|
| 240 | + $statementParts = array(); |
|
| 241 | + $statementParts['keywords'] = array(); |
|
| 242 | + $statementParts['tables'] = array(); |
|
| 243 | + $statementParts['unions'] = array(); |
|
| 244 | + $statementParts['fields'] = array(); |
|
| 245 | + $statementParts['where'] = array(); |
|
| 246 | + $statementParts['additionalWhereClause'] = array(); |
|
| 247 | + $statementParts['orderings'] = array(); |
|
| 248 | + $statementParts['limit'] = array(); |
|
| 249 | + $source = $query->getSource(); |
|
| 250 | + $this->parseSource($source, $statementParts); |
|
| 251 | + $this->parseConstraint($query->getConstraint(), $source, $statementParts, $parameters); |
|
| 252 | + $this->parseOrderings($query->getOrderings(), $source, $statementParts); |
|
| 253 | + $this->parseLimitAndOffset($query->getLimit(), $query->getOffset(), $statementParts); |
|
| 254 | + $tableNames = array_unique(array_keys($statementParts['tables'] + $statementParts['unions'])); |
|
| 255 | + foreach ($tableNames as $tableNameOrAlias) { |
|
| 256 | + if (is_string($tableNameOrAlias) && strlen($tableNameOrAlias) > 0) { |
|
| 257 | + $this->addAdditionalWhereClause($query->getQuerySettings(), $tableNameOrAlias, $statementParts); |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + return $statementParts; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + /** |
|
| 265 | + * Fiddle with the statement structure to handle recursive MM relations. |
|
| 266 | + * For the recursive MM query to work, we must invert some values. |
|
| 267 | + * Let see if that is the best way of doing that... |
|
| 268 | + * |
|
| 269 | + * @param array $statementParts |
|
| 270 | + * @return array |
|
| 271 | + */ |
|
| 272 | + public function processStatementStructureForRecursiveMMRelation(array $statementParts) |
|
| 273 | + { |
|
| 274 | + |
|
| 275 | + if ($this->hasRecursiveMMRelation()) { |
|
| 276 | + $tableName = $this->query->getType(); |
|
| 277 | + |
|
| 278 | + // In order the MM query to work for a recursive MM query, we must invert some values. |
|
| 279 | + // tx_domain_model_foo0 (the alias) <--> tx_domain_model_foo (the origin table name) |
|
| 280 | + $values = array(); |
|
| 281 | + foreach ($statementParts['fields'] as $key => $value) { |
|
| 282 | + $values[$key] = str_replace($tableName, $tableName . '0', $value); |
|
| 283 | + } |
|
| 284 | + $statementParts['fields'] = $values; |
|
| 285 | + |
|
| 286 | + // Same comment as above. |
|
| 287 | + $values = array(); |
|
| 288 | + foreach ($statementParts['where'] as $key => $value) { |
|
| 289 | + $values[$key] = str_replace($tableName . '0', $tableName, $value); |
|
| 290 | + } |
|
| 291 | + $statementParts['where'] = $values; |
|
| 292 | + |
|
| 293 | + // We must be more restrictive by transforming the "left" union by "inner" |
|
| 294 | + $values = array(); |
|
| 295 | + foreach ($statementParts['unions'] as $key => $value) { |
|
| 296 | + $values[$key] = str_replace('LEFT JOIN', 'INNER JOIN', $value); |
|
| 297 | + } |
|
| 298 | + $statementParts['unions'] = $values; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + return $statementParts; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + /** |
|
| 305 | + * Tell whether there is a recursive MM relation. |
|
| 306 | + * |
|
| 307 | + * @return bool |
|
| 308 | + */ |
|
| 309 | + public function hasRecursiveMMRelation() |
|
| 310 | + { |
|
| 311 | + return isset($this->tableNameAliases['aliasIncrement'][$this->query->getType()]); |
|
| 312 | + |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + /** |
|
| 316 | + * Returns the statement, ready to be executed. |
|
| 317 | + * |
|
| 318 | + * @param array $statementParts The SQL statement parts |
|
| 319 | + * @return string The SQL statement |
|
| 320 | + */ |
|
| 321 | + public function buildQuery(array $statementParts) |
|
| 322 | + { |
|
| 323 | + |
|
| 324 | + // Add more statement to the UNION part. |
|
| 325 | + if (!empty($statementParts['unions'])) { |
|
| 326 | + foreach ($statementParts['unions'] as $tableName => $unionPart) { |
|
| 327 | + if (!empty($statementParts['additionalWhereClause'][$tableName])) { |
|
| 328 | + $statementParts['unions'][$tableName] .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$tableName]); |
|
| 329 | + } |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + |
|
| 333 | + $statement = 'SELECT ' . implode(' ', $statementParts['keywords']) . ' ' . implode(',', $statementParts['fields']) . ' FROM ' . implode(' ', $statementParts['tables']) . ' ' . implode(' ', $statementParts['unions']); |
|
| 334 | + if (!empty($statementParts['where'])) { |
|
| 335 | + $statement .= ' WHERE ' . implode('', $statementParts['where']); |
|
| 336 | + if (!empty($statementParts['additionalWhereClause'][$this->query->getType()])) { |
|
| 337 | + $statement .= ' AND ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
| 338 | + } |
|
| 339 | + } elseif (!empty($statementParts['additionalWhereClause'])) { |
|
| 340 | + $statement .= ' WHERE ' . implode(' AND ', $statementParts['additionalWhereClause'][$this->query->getType()]); |
|
| 341 | + } |
|
| 342 | + if (!empty($statementParts['orderings'])) { |
|
| 343 | + $statement .= ' ORDER BY ' . implode(', ', $statementParts['orderings']); |
|
| 344 | + } |
|
| 345 | + if (!empty($statementParts['limit'])) { |
|
| 346 | + $statement .= ' LIMIT ' . $statementParts['limit']; |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + return $statement; |
|
| 350 | + } |
|
| 351 | + |
|
| 352 | + /** |
|
| 353 | + * Transforms a Query Source into SQL and parameter arrays |
|
| 354 | + * |
|
| 355 | + * @param SourceInterface $source The source |
|
| 356 | + * @param array &$sql |
|
| 357 | + * @return void |
|
| 358 | + */ |
|
| 359 | + protected function parseSource(SourceInterface $source, array &$sql) |
|
| 360 | + { |
|
| 361 | + if ($source instanceof SelectorInterface) { |
|
| 362 | + $tableName = $source->getNodeTypeName(); |
|
| 363 | + $sql['fields'][$tableName] = $tableName . '.*'; |
|
| 364 | + $sql['tables'][$tableName] = $tableName; |
|
| 365 | + if ($this->query->getDistinct()) { |
|
| 366 | + $sql['fields'][$tableName] = $tableName . '.' . $this->query->getDistinct(); |
|
| 367 | + $sql['keywords']['distinct'] = 'DISTINCT'; |
|
| 368 | + } |
|
| 369 | + } elseif ($source instanceof JoinInterface) { |
|
| 370 | + $this->parseJoin($source, $sql); |
|
| 371 | + } |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * Transforms a Join into SQL and parameter arrays |
|
| 376 | + * |
|
| 377 | + * @param JoinInterface $join The join |
|
| 378 | + * @param array &$sql The query parts |
|
| 379 | + * @return void |
|
| 380 | + */ |
|
| 381 | + protected function parseJoin(JoinInterface $join, array &$sql) |
|
| 382 | + { |
|
| 383 | + $leftSource = $join->getLeft(); |
|
| 384 | + $leftTableName = $leftSource->getSelectorName(); |
|
| 385 | + // $sql['fields'][$leftTableName] = $leftTableName . '.*'; |
|
| 386 | + $rightSource = $join->getRight(); |
|
| 387 | + if ($rightSource instanceof JoinInterface) { |
|
| 388 | + $rightTableName = $rightSource->getLeft()->getSelectorName(); |
|
| 389 | + } else { |
|
| 390 | + $rightTableName = $rightSource->getSelectorName(); |
|
| 391 | + $sql['fields'][$leftTableName] = $rightTableName . '.*'; |
|
| 392 | + } |
|
| 393 | + $sql['tables'][$leftTableName] = $leftTableName; |
|
| 394 | + $sql['unions'][$rightTableName] = 'LEFT JOIN ' . $rightTableName; |
|
| 395 | + $joinCondition = $join->getJoinCondition(); |
|
| 396 | + if ($joinCondition instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\EquiJoinCondition) { |
|
| 397 | + $column1Name = $joinCondition->getProperty1Name(); |
|
| 398 | + $column2Name = $joinCondition->getProperty2Name(); |
|
| 399 | + $sql['unions'][$rightTableName] .= ' ON ' . $joinCondition->getSelector1Name() . '.' . $column1Name . ' = ' . $joinCondition->getSelector2Name() . '.' . $column2Name; |
|
| 400 | + } |
|
| 401 | + if ($rightSource instanceof JoinInterface) { |
|
| 402 | + $this->parseJoin($rightSource, $sql); |
|
| 403 | + } |
|
| 404 | + } |
|
| 405 | + |
|
| 406 | + /** |
|
| 407 | + * Transforms a constraint into SQL and parameter arrays |
|
| 408 | + * |
|
| 409 | + * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint The constraint |
|
| 410 | + * @param SourceInterface $source The source |
|
| 411 | + * @param array &$sql The query parts |
|
| 412 | + * @param array &$parameters The parameters that will replace the markers |
|
| 413 | + * @return void |
|
| 414 | + */ |
|
| 415 | + protected function parseConstraint(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface $constraint = NULL, SourceInterface $source, array &$sql, array &$parameters) |
|
| 416 | + { |
|
| 417 | + if ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\AndInterface) { |
|
| 418 | + $sql['where'][] = '('; |
|
| 419 | + $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters); |
|
| 420 | + $sql['where'][] = ' AND '; |
|
| 421 | + $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters); |
|
| 422 | + $sql['where'][] = ')'; |
|
| 423 | + } elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\OrInterface) { |
|
| 424 | + $sql['where'][] = '('; |
|
| 425 | + $this->parseConstraint($constraint->getConstraint1(), $source, $sql, $parameters); |
|
| 426 | + $sql['where'][] = ' OR '; |
|
| 427 | + $this->parseConstraint($constraint->getConstraint2(), $source, $sql, $parameters); |
|
| 428 | + $sql['where'][] = ')'; |
|
| 429 | + } elseif ($constraint instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\NotInterface) { |
|
| 430 | + $sql['where'][] = 'NOT ('; |
|
| 431 | + $this->parseConstraint($constraint->getConstraint(), $source, $sql, $parameters); |
|
| 432 | + $sql['where'][] = ')'; |
|
| 433 | + } elseif ($constraint instanceof ComparisonInterface) { |
|
| 434 | + $this->parseComparison($constraint, $source, $sql, $parameters); |
|
| 435 | + } |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * Parse a Comparison into SQL and parameter arrays. |
|
| 440 | + * |
|
| 441 | + * @param ComparisonInterface $comparison The comparison to parse |
|
| 442 | + * @param SourceInterface $source The source |
|
| 443 | + * @param array &$sql SQL query parts to add to |
|
| 444 | + * @param array &$parameters Parameters to bind to the SQL |
|
| 445 | + * @throws Exception\RepositoryException |
|
| 446 | + * @return void |
|
| 447 | + */ |
|
| 448 | + protected function parseComparison(ComparisonInterface $comparison, SourceInterface $source, array &$sql, array &$parameters) |
|
| 449 | + { |
|
| 450 | + $operand1 = $comparison->getOperand1(); |
|
| 451 | + $operator = $comparison->getOperator(); |
|
| 452 | + $operand2 = $comparison->getOperand2(); |
|
| 453 | + if ($operator === QueryInterface::OPERATOR_IN) { |
|
| 454 | + $items = array(); |
|
| 455 | + $hasValue = FALSE; |
|
| 456 | + foreach ($operand2 as $value) { |
|
| 457 | + $value = $this->getPlainValue($value); |
|
| 458 | + if ($value !== NULL) { |
|
| 459 | + $items[] = $value; |
|
| 460 | + $hasValue = TRUE; |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + if ($hasValue === FALSE) { |
|
| 464 | + $sql['where'][] = '1<>1'; |
|
| 465 | + } else { |
|
| 466 | + $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters, NULL); |
|
| 467 | + $parameters[] = $items; |
|
| 468 | + } |
|
| 469 | + } elseif ($operator === QueryInterface::OPERATOR_CONTAINS) { |
|
| 470 | + if ($operand2 === NULL) { |
|
| 471 | + $sql['where'][] = '1<>1'; |
|
| 472 | + } else { |
|
| 473 | + throw new \Exception('Not implemented! Contact extension author.', 1412931227); |
|
| 474 | + # @todo re-implement me if necessary. |
|
| 475 | + #$tableName = $this->query->getType(); |
|
| 476 | + #$propertyName = $operand1->getPropertyName(); |
|
| 477 | + #while (strpos($propertyName, '.') !== FALSE) { |
|
| 478 | + # $this->addUnionStatement($tableName, $propertyName, $sql); |
|
| 479 | + #} |
|
| 480 | + #$columnName = $propertyName; |
|
| 481 | + #$columnMap = $propertyName; |
|
| 482 | + #$typeOfRelation = $columnMap instanceof ColumnMap ? $columnMap->getTypeOfRelation() : NULL; |
|
| 483 | + #if ($typeOfRelation === ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) { |
|
| 484 | + # $relationTableName = $columnMap->getRelationTableName(); |
|
| 485 | + # $sql['where'][] = $tableName . '.uid IN (SELECT ' . $columnMap->getParentKeyFieldName() . ' FROM ' . $relationTableName . ' WHERE ' . $columnMap->getChildKeyFieldName() . '=?)'; |
|
| 486 | + # $parameters[] = intval($this->getPlainValue($operand2)); |
|
| 487 | + #} elseif ($typeOfRelation === ColumnMap::RELATION_HAS_MANY) { |
|
| 488 | + # $parentKeyFieldName = $columnMap->getParentKeyFieldName(); |
|
| 489 | + # if (isset($parentKeyFieldName)) { |
|
| 490 | + # $childTableName = $columnMap->getChildTableName(); |
|
| 491 | + # $sql['where'][] = $tableName . '.uid=(SELECT ' . $childTableName . '.' . $parentKeyFieldName . ' FROM ' . $childTableName . ' WHERE ' . $childTableName . '.uid=?)'; |
|
| 492 | + # $parameters[] = intval($this->getPlainValue($operand2)); |
|
| 493 | + # } else { |
|
| 494 | + # $sql['where'][] = 'FIND_IN_SET(?,' . $tableName . '.' . $columnName . ')'; |
|
| 495 | + # $parameters[] = intval($this->getPlainValue($operand2)); |
|
| 496 | + # } |
|
| 497 | + #} else { |
|
| 498 | + # throw new Exception\RepositoryException('Unsupported or non-existing property name "' . $propertyName . '" used in relation matching.', 1327065745); |
|
| 499 | + #} |
|
| 500 | + } |
|
| 501 | + } else { |
|
| 502 | + if ($operand2 === NULL) { |
|
| 503 | + if ($operator === QueryInterface::OPERATOR_EQUAL_TO) { |
|
| 504 | + $operator = self::OPERATOR_EQUAL_TO_NULL; |
|
| 505 | + } elseif ($operator === QueryInterface::OPERATOR_NOT_EQUAL_TO) { |
|
| 506 | + $operator = self::OPERATOR_NOT_EQUAL_TO_NULL; |
|
| 507 | + } |
|
| 508 | + } |
|
| 509 | + $this->parseDynamicOperand($operand1, $operator, $source, $sql, $parameters); |
|
| 510 | + $parameters[] = $this->getPlainValue($operand2); |
|
| 511 | + } |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + /** |
|
| 515 | + * Returns a plain value, i.e. objects are flattened out if possible. |
|
| 516 | + * |
|
| 517 | + * @param mixed $input |
|
| 518 | + * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException |
|
| 519 | + * @return mixed |
|
| 520 | + */ |
|
| 521 | + protected function getPlainValue($input) |
|
| 522 | + { |
|
| 523 | + if (is_array($input)) { |
|
| 524 | + throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An array could not be converted to a plain value.', 1274799932); |
|
| 525 | + } |
|
| 526 | + if ($input instanceof \DateTime) { |
|
| 527 | + return $input->format('U'); |
|
| 528 | + } elseif (is_object($input)) { |
|
| 529 | + if ($input instanceof \TYPO3\CMS\Extbase\Persistence\Generic\LazyLoadingProxy) { |
|
| 530 | + $realInput = $input->_loadRealInstance(); |
|
| 531 | + } else { |
|
| 532 | + $realInput = $input; |
|
| 533 | + } |
|
| 534 | + if ($realInput instanceof \TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface) { |
|
| 535 | + return $realInput->getUid(); |
|
| 536 | + } else { |
|
| 537 | + throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException('An object of class "' . get_class($realInput) . '" could not be converted to a plain value.', 1274799934); |
|
| 538 | + } |
|
| 539 | + } elseif (is_bool($input)) { |
|
| 540 | + return $input === TRUE ? 1 : 0; |
|
| 541 | + } else { |
|
| 542 | + return $input; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + /** |
|
| 547 | + * Parse a DynamicOperand into SQL and parameter arrays. |
|
| 548 | + * |
|
| 549 | + * @param DynamicOperandInterface $operand |
|
| 550 | + * @param string $operator One of the JCR_OPERATOR_* constants |
|
| 551 | + * @param SourceInterface $source The source |
|
| 552 | + * @param array &$sql The query parts |
|
| 553 | + * @param array &$parameters The parameters that will replace the markers |
|
| 554 | + * @param string $valueFunction an optional SQL function to apply to the operand value |
|
| 555 | + * @return void |
|
| 556 | + */ |
|
| 557 | + protected function parseDynamicOperand(DynamicOperandInterface $operand, $operator, SourceInterface $source, array &$sql, array &$parameters, $valueFunction = NULL) |
|
| 558 | + { |
|
| 559 | + if ($operand instanceof LowerCaseInterface) { |
|
| 560 | + $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'LOWER'); |
|
| 561 | + } elseif ($operand instanceof UpperCaseInterface) { |
|
| 562 | + $this->parseDynamicOperand($operand->getOperand(), $operator, $source, $sql, $parameters, 'UPPER'); |
|
| 563 | + } elseif ($operand instanceof PropertyValueInterface) { |
|
| 564 | + $propertyName = $operand->getPropertyName(); |
|
| 565 | + |
|
| 566 | + // Reset value. |
|
| 567 | + $this->currentChildTableNameAlias = ''; |
|
| 568 | + |
|
| 569 | + if ($source instanceof SelectorInterface) { |
|
| 570 | + $tableName = $this->query->getType(); |
|
| 571 | + while (strpos($propertyName, '.') !== FALSE) { |
|
| 572 | + $this->addUnionStatement($tableName, $propertyName, $sql); |
|
| 573 | + } |
|
| 574 | + } elseif ($source instanceof JoinInterface) { |
|
| 575 | + $tableName = $source->getJoinCondition()->getSelector1Name(); |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + $columnName = $propertyName; |
|
| 579 | + $operator = $this->resolveOperator($operator); |
|
| 580 | + $constraintSQL = ''; |
|
| 581 | + if ($valueFunction === NULL) { |
|
| 582 | + $constraintSQL .= (!empty($tableName) ? $tableName . '.' : '') . $columnName . ' ' . $operator . ' ?'; |
|
| 583 | + } else { |
|
| 584 | + $constraintSQL .= $valueFunction . '(' . (!empty($tableName) ? $tableName . '.' : '') . $columnName . ') ' . $operator . ' ?'; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + if (isset($tableName) && !empty($this->currentChildTableNameAlias)) { |
|
| 588 | + $constraintSQL = $this->replaceTableNameByAlias($tableName, $this->currentChildTableNameAlias, $constraintSQL); |
|
| 589 | + } |
|
| 590 | + $sql['where'][] = $constraintSQL; |
|
| 591 | + } |
|
| 592 | + } |
|
| 593 | + |
|
| 594 | + /** |
|
| 595 | + * @param string &$tableName |
|
| 596 | + * @param array &$propertyPath |
|
| 597 | + * @param array &$sql |
|
| 598 | + * @throws Exception |
|
| 599 | + * @throws Exception\InvalidRelationConfigurationException |
|
| 600 | + * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception\MissingColumnMapException |
|
| 601 | + */ |
|
| 602 | + protected function addUnionStatement(&$tableName, &$propertyPath, array &$sql) |
|
| 603 | + { |
|
| 604 | + |
|
| 605 | + $table = Tca::table($tableName); |
|
| 606 | + |
|
| 607 | + $explodedPropertyPath = explode('.', $propertyPath, 2); |
|
| 608 | + $fieldName = $explodedPropertyPath[0]; |
|
| 609 | + |
|
| 610 | + // Field of type "group" are special because property path must contain the table name |
|
| 611 | + // to determine the relation type. Example for sys_category, property path will look like "items.sys_file" |
|
| 612 | + if ($table->field($fieldName)->isGroup()) { |
|
| 613 | + $parts = explode('.', $propertyPath, 3); |
|
| 614 | + $explodedPropertyPath[0] = $parts[0] . '.' . $parts[1]; |
|
| 615 | + $explodedPropertyPath[1] = $parts[2]; |
|
| 616 | + $fieldName = $explodedPropertyPath[0]; |
|
| 617 | + } |
|
| 618 | + |
|
| 619 | + $parentKeyFieldName = $table->field($fieldName)->getForeignField(); |
|
| 620 | + $childTableName = $table->field($fieldName)->getForeignTable(); |
|
| 621 | + |
|
| 622 | + if ($childTableName === NULL) { |
|
| 623 | + throw new Exception\InvalidRelationConfigurationException('The relation information for property "' . $fieldName . '" of class "' . $tableName . '" is missing.', 1353170925); |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + if ($table->field($fieldName)->hasOne()) { // includes relation "one-to-one" and "many-to-one" |
|
| 627 | + // sometimes the opposite relation is not defined. We don't want to force this config for backward compatibility reasons. |
|
| 628 | + // $parentKeyFieldName === NULL does the trick somehow. Before condition was if (isset($parentKeyFieldName)) |
|
| 629 | + if ($table->field($fieldName)->hasRelationManyToOne() || $parentKeyFieldName === NULL) { |
|
| 630 | + $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.' . $fieldName . '=' . $childTableName . '.uid'; |
|
| 631 | + } else { |
|
| 632 | + $sql['unions'][$childTableName] = 'LEFT JOIN ' . $childTableName . ' ON ' . $tableName . '.uid=' . $childTableName . '.' . $parentKeyFieldName; |
|
| 633 | + } |
|
| 634 | + } elseif ($table->field($fieldName)->hasRelationManyToMany()) { |
|
| 635 | + $relationTableName = $table->field($fieldName)->getManyToManyTable(); |
|
| 636 | + |
|
| 637 | + $parentKeyFieldName = $table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local'; |
|
| 638 | + $childKeyFieldName = !$table->field($fieldName)->isOppositeRelation() ? 'uid_foreign' : 'uid_local'; |
|
| 639 | + |
|
| 640 | + // MM table e.g sys_category_record_mm |
|
| 641 | + $relationTableNameAlias = $this->generateAlias($relationTableName); |
|
| 642 | + $join = sprintf( |
|
| 643 | + 'LEFT JOIN %s AS %s ON %s.uid=%s.%s', $relationTableName, |
|
| 644 | + $relationTableNameAlias, |
|
| 645 | + $tableName, |
|
| 646 | + $relationTableNameAlias, |
|
| 647 | + $parentKeyFieldName |
|
| 648 | + ); |
|
| 649 | + $sql['unions'][$relationTableNameAlias] = $join; |
|
| 650 | + |
|
| 651 | + // Foreign table e.g sys_category |
|
| 652 | + $childTableNameAlias = $this->generateAlias($childTableName); |
|
| 653 | + $this->currentChildTableNameAlias = $childTableNameAlias; |
|
| 654 | + $join = sprintf( |
|
| 655 | + 'LEFT JOIN %s AS %s ON %s.%s=%s.uid', |
|
| 656 | + $childTableName, |
|
| 657 | + $childTableNameAlias, |
|
| 658 | + $relationTableNameAlias, |
|
| 659 | + $childKeyFieldName, |
|
| 660 | + $childTableNameAlias |
|
| 661 | + ); |
|
| 662 | + $sql['unions'][$childTableNameAlias] = $join; |
|
| 663 | + |
|
| 664 | + // Find a possible table name for a MM condition. |
|
| 665 | + $tableNameCondition = $table->field($fieldName)->getAdditionalTableNameCondition(); |
|
| 666 | + if ($tableNameCondition) { |
|
| 667 | + |
|
| 668 | + // If we can find a source file name, we can then retrieve more MM conditions from the TCA such as a field name. |
|
| 669 | + $sourceFileName = $this->query->getSourceFieldName(); |
|
| 670 | + if (empty($sourceFileName)) { |
|
| 671 | + $additionalMMConditions = array( |
|
| 672 | + 'tablenames' => $tableNameCondition, |
|
| 673 | + ); |
|
| 674 | + } else { |
|
| 675 | + $additionalMMConditions = Tca::table($tableNameCondition)->field($sourceFileName)->getAdditionalMMCondition(); |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + foreach ($additionalMMConditions as $additionalFieldName => $additionalMMCondition) { |
|
| 679 | + $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition); |
|
| 680 | + $sql['unions'][$relationTableNameAlias] .= $additionalJoin; |
|
| 681 | + |
|
| 682 | + $additionalJoin = sprintf(' AND %s.%s = "%s"', $relationTableNameAlias, $additionalFieldName, $additionalMMCondition); |
|
| 683 | + $sql['unions'][$childTableNameAlias] .= $additionalJoin; |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + } |
|
| 687 | + |
|
| 688 | + |
|
| 689 | + } elseif ($table->field($fieldName)->hasMany()) { // includes relations "many-to-one" and "csv" relations |
|
| 690 | + $childTableNameAlias = $this->generateAlias($childTableName); |
|
| 691 | + $this->currentChildTableNameAlias = $childTableNameAlias; |
|
| 692 | + |
|
| 693 | + if (isset($parentKeyFieldName)) { |
|
| 694 | + $join = sprintf( |
|
| 695 | + 'LEFT JOIN %s AS %s ON %s.uid=%s.%s', |
|
| 696 | + $childTableName, |
|
| 697 | + $childTableNameAlias, |
|
| 698 | + $tableName, |
|
| 699 | + $childTableNameAlias, |
|
| 700 | + $parentKeyFieldName |
|
| 701 | + ); |
|
| 702 | + $sql['unions'][$childTableNameAlias] = $join; |
|
| 703 | + } else { |
|
| 704 | + $join = sprintf( |
|
| 705 | + 'LEFT JOIN %s AS %s ON (FIND_IN_SET(%s.uid, %s.%s))', |
|
| 706 | + $childTableName, |
|
| 707 | + $childTableNameAlias, |
|
| 708 | + $childTableNameAlias, |
|
| 709 | + $tableName, |
|
| 710 | + $fieldName |
|
| 711 | + ); |
|
| 712 | + $sql['unions'][$childTableNameAlias] = $join; |
|
| 713 | + } |
|
| 714 | + } else { |
|
| 715 | + throw new Exception('Could not determine type of relation.', 1252502725); |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + // TODO check if there is another solution for this |
|
| 719 | + $sql['keywords']['distinct'] = 'DISTINCT'; |
|
| 720 | + $propertyPath = $explodedPropertyPath[1]; |
|
| 721 | + $tableName = $childTableName; |
|
| 722 | + } |
|
| 723 | + |
|
| 724 | + /** |
|
| 725 | + * Returns the SQL operator for the given JCR operator type. |
|
| 726 | + * |
|
| 727 | + * @param string $operator One of the JCR_OPERATOR_* constants |
|
| 728 | + * @throws Exception |
|
| 729 | + * @return string an SQL operator |
|
| 730 | + */ |
|
| 731 | + protected function resolveOperator($operator) |
|
| 732 | + { |
|
| 733 | + switch ($operator) { |
|
| 734 | + case self::OPERATOR_EQUAL_TO_NULL: |
|
| 735 | + $operator = 'IS'; |
|
| 736 | + break; |
|
| 737 | + case self::OPERATOR_NOT_EQUAL_TO_NULL: |
|
| 738 | + $operator = 'IS NOT'; |
|
| 739 | + break; |
|
| 740 | + case QueryInterface::OPERATOR_IN: |
|
| 741 | + $operator = 'IN'; |
|
| 742 | + break; |
|
| 743 | + case QueryInterface::OPERATOR_EQUAL_TO: |
|
| 744 | + $operator = '='; |
|
| 745 | + break; |
|
| 746 | + case QueryInterface::OPERATOR_NOT_EQUAL_TO: |
|
| 747 | + $operator = '!='; |
|
| 748 | + break; |
|
| 749 | + case QueryInterface::OPERATOR_LESS_THAN: |
|
| 750 | + $operator = '<'; |
|
| 751 | + break; |
|
| 752 | + case QueryInterface::OPERATOR_LESS_THAN_OR_EQUAL_TO: |
|
| 753 | + $operator = '<='; |
|
| 754 | + break; |
|
| 755 | + case QueryInterface::OPERATOR_GREATER_THAN: |
|
| 756 | + $operator = '>'; |
|
| 757 | + break; |
|
| 758 | + case QueryInterface::OPERATOR_GREATER_THAN_OR_EQUAL_TO: |
|
| 759 | + $operator = '>='; |
|
| 760 | + break; |
|
| 761 | + case QueryInterface::OPERATOR_LIKE: |
|
| 762 | + $operator = 'LIKE'; |
|
| 763 | + break; |
|
| 764 | + default: |
|
| 765 | + throw new Exception('Unsupported operator encountered.', 1242816073); |
|
| 766 | + } |
|
| 767 | + return $operator; |
|
| 768 | + } |
|
| 769 | + |
|
| 770 | + /** |
|
| 771 | + * Replace query placeholders in a query part by the given |
|
| 772 | + * parameters. |
|
| 773 | + * |
|
| 774 | + * @param string &$sqlString The query part with placeholders |
|
| 775 | + * @param array $parameters The parameters |
|
| 776 | + * @param string $tableName |
|
| 777 | + * |
|
| 778 | + * @throws Exception |
|
| 779 | + */ |
|
| 780 | + protected function replacePlaceholders(&$sqlString, array $parameters, $tableName = 'foo') |
|
| 781 | + { |
|
| 782 | + // TODO profile this method again |
|
| 783 | + if (substr_count($sqlString, '?') !== count($parameters)) { |
|
| 784 | + throw new Exception('The number of question marks to replace must be equal to the number of parameters.', 1242816074); |
|
| 785 | + } |
|
| 786 | + $offset = 0; |
|
| 787 | + foreach ($parameters as $parameter) { |
|
| 788 | + $markPosition = strpos($sqlString, '?', $offset); |
|
| 789 | + if ($markPosition !== FALSE) { |
|
| 790 | + if ($parameter === NULL) { |
|
| 791 | + $parameter = 'NULL'; |
|
| 792 | + } elseif (is_array($parameter) || $parameter instanceof \ArrayAccess || $parameter instanceof \Traversable) { |
|
| 793 | + $items = array(); |
|
| 794 | + foreach ($parameter as $item) { |
|
| 795 | + $items[] = $this->databaseHandle->fullQuoteStr($item, $tableName); |
|
| 796 | + } |
|
| 797 | + $parameter = '(' . implode(',', $items) . ')'; |
|
| 798 | + } else { |
|
| 799 | + $parameter = $this->databaseHandle->fullQuoteStr($parameter, $tableName); |
|
| 800 | + } |
|
| 801 | + $sqlString = substr($sqlString, 0, $markPosition) . $parameter . substr($sqlString, ($markPosition + 1)); |
|
| 802 | + } |
|
| 803 | + $offset = $markPosition + strlen($parameter); |
|
| 804 | + } |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + /** |
|
| 808 | + * Adds additional WHERE statements according to the query settings. |
|
| 809 | + * |
|
| 810 | + * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
| 811 | + * @param string $tableNameOrAlias The table name to add the additional where clause for |
|
| 812 | + * @param array &$statementParts |
|
| 813 | + * @return void |
|
| 814 | + */ |
|
| 815 | + protected function addAdditionalWhereClause(QuerySettingsInterface $querySettings, $tableNameOrAlias, &$statementParts) |
|
| 816 | + { |
|
| 817 | + $this->addVisibilityConstraintStatement($querySettings, $tableNameOrAlias, $statementParts); |
|
| 818 | + if ($querySettings->getRespectSysLanguage()) { |
|
| 819 | + $this->addSysLanguageStatement($tableNameOrAlias, $statementParts, $querySettings); |
|
| 820 | + } |
|
| 821 | + if ($querySettings->getRespectStoragePage()) { |
|
| 822 | + $this->addPageIdStatement($tableNameOrAlias, $statementParts, $querySettings->getStoragePageIds()); |
|
| 823 | + } |
|
| 824 | + } |
|
| 825 | + |
|
| 826 | + /** |
|
| 827 | + * Adds enableFields and deletedClause to the query if necessary |
|
| 828 | + * |
|
| 829 | + * @param QuerySettingsInterface $querySettings |
|
| 830 | + * @param string $tableNameOrAlias The database table name |
|
| 831 | + * @param array &$statementParts The query parts |
|
| 832 | + * @return void |
|
| 833 | + */ |
|
| 834 | + protected function addVisibilityConstraintStatement(QuerySettingsInterface $querySettings, $tableNameOrAlias, array &$statementParts) |
|
| 835 | + { |
|
| 836 | + $statement = ''; |
|
| 837 | + $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 838 | + if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { |
|
| 839 | + $ignoreEnableFields = $querySettings->getIgnoreEnableFields(); |
|
| 840 | + $enableFieldsToBeIgnored = $querySettings->getEnableFieldsToBeIgnored(); |
|
| 841 | + $includeDeleted = $querySettings->getIncludeDeleted(); |
|
| 842 | + if ($this->environmentService->isEnvironmentInFrontendMode()) { |
|
| 843 | + $statement .= $this->getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored, $includeDeleted); |
|
| 844 | + } else { |
|
| 845 | + // TYPO3_MODE === 'BE' |
|
| 846 | + $statement .= $this->getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted); |
|
| 847 | + } |
|
| 848 | + |
|
| 849 | + // Remove the prefixing "AND" if any. |
|
| 850 | + if (!empty($statement)) { |
|
| 851 | + $statement = strtolower(substr($statement, 1, 3)) === 'and' ? substr($statement, 5) : $statement; |
|
| 852 | + $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $statement; |
|
| 853 | + } |
|
| 854 | + } |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + /** |
|
| 858 | + * Returns constraint statement for frontend context |
|
| 859 | + * |
|
| 860 | + * @param string $tableNameOrAlias |
|
| 861 | + * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored |
|
| 862 | + * @param array $enableFieldsToBeIgnored If $ignoreEnableFields is true, this array specifies enable fields to be ignored. If it is NULL or an empty array (default) all enable fields are ignored. |
|
| 863 | + * @param boolean $includeDeleted A flag indicating whether deleted records should be included |
|
| 864 | + * @return string |
|
| 865 | + * @throws Exception\InconsistentQuerySettingsException |
|
| 866 | + */ |
|
| 867 | + protected function getFrontendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $enableFieldsToBeIgnored = array(), $includeDeleted) |
|
| 868 | + { |
|
| 869 | + $statement = ''; |
|
| 870 | + $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 871 | + if ($ignoreEnableFields && !$includeDeleted) { |
|
| 872 | + if (count($enableFieldsToBeIgnored)) { |
|
| 873 | + // array_combine() is necessary because of the way \TYPO3\CMS\Frontend\Page\PageRepository::enableFields() is implemented |
|
| 874 | + $statement .= $this->getPageRepository()->enableFields($tableName, -1, array_combine($enableFieldsToBeIgnored, $enableFieldsToBeIgnored)); |
|
| 875 | + } else { |
|
| 876 | + $statement .= $this->getPageRepository()->deleteClause($tableName); |
|
| 877 | + } |
|
| 878 | + } elseif (!$ignoreEnableFields && !$includeDeleted) { |
|
| 879 | + $statement .= $this->getPageRepository()->enableFields($tableName); |
|
| 880 | + } elseif (!$ignoreEnableFields && $includeDeleted) { |
|
| 881 | + throw new Exception\InconsistentQuerySettingsException('Query setting "ignoreEnableFields=FALSE" can not be used together with "includeDeleted=TRUE" in frontend context.', 1327678173); |
|
| 882 | + } |
|
| 883 | + return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement); |
|
| 884 | + } |
|
| 885 | + |
|
| 886 | + /** |
|
| 887 | + * Returns constraint statement for backend context |
|
| 888 | + * |
|
| 889 | + * @param string $tableNameOrAlias |
|
| 890 | + * @param boolean $ignoreEnableFields A flag indicating whether the enable fields should be ignored |
|
| 891 | + * @param boolean $includeDeleted A flag indicating whether deleted records should be included |
|
| 892 | + * @return string |
|
| 893 | + */ |
|
| 894 | + protected function getBackendConstraintStatement($tableNameOrAlias, $ignoreEnableFields, $includeDeleted) |
|
| 895 | + { |
|
| 896 | + $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 897 | + $statement = ''; |
|
| 898 | + if (!$ignoreEnableFields) { |
|
| 899 | + $statement .= BackendUtility::BEenableFields($tableName); |
|
| 900 | + } |
|
| 901 | + |
|
| 902 | + // If the table is found to have "workspace" support, add the corresponding fields in the statement. |
|
| 903 | + if (Tca::table($tableName)->hasWorkspaceSupport()) { |
|
| 904 | + if ($this->getBackendUser()->workspace === 0) { |
|
| 905 | + $statement .= ' AND ' . $tableName . '.t3ver_state<=' . new VersionState(VersionState::DEFAULT_STATE); |
|
| 906 | + } else { |
|
| 907 | + // Show only records of live and of the current workspace |
|
| 908 | + // In case we are in a Versioning preview |
|
| 909 | + $statement .= ' AND (' . |
|
| 910 | + $tableName . '.t3ver_wsid=0 OR ' . |
|
| 911 | + $tableName . '.t3ver_wsid=' . (int)$this->getBackendUser()->workspace . |
|
| 912 | + ')'; |
|
| 913 | + } |
|
| 914 | + |
|
| 915 | + // Check if this segment make sense here or whether it should be in the "if" part when we have workspace = 0 |
|
| 916 | + $statement .= ' AND ' . $tableName . '.pid<>-1'; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + if (!$includeDeleted) { |
|
| 920 | + $statement .= BackendUtility::deleteClause($tableName); |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + return $this->replaceTableNameByAlias($tableName, $tableNameOrAlias, $statement); |
|
| 924 | + } |
|
| 925 | + |
|
| 926 | + /** |
|
| 927 | + * Builds the language field statement |
|
| 928 | + * |
|
| 929 | + * @param string $tableNameOrAlias The database table name |
|
| 930 | + * @param array &$statementParts The query parts |
|
| 931 | + * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
| 932 | + * @throws Exception |
|
| 933 | + * @return void |
|
| 934 | + */ |
|
| 935 | + protected function addSysLanguageStatement($tableNameOrAlias, array &$statementParts, $querySettings) |
|
| 936 | + { |
|
| 937 | + |
|
| 938 | + $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 939 | + if (is_array($GLOBALS['TCA'][$tableName]['ctrl'])) { |
|
| 940 | + if (!empty($GLOBALS['TCA'][$tableName]['ctrl']['languageField'])) { |
|
| 941 | + // Select all entries for the current language |
|
| 942 | + $additionalWhereClause = $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . ' IN (' . intval($querySettings->getLanguageUid()) . ',-1)'; |
|
| 943 | + // If any language is set -> get those entries which are not translated yet |
|
| 944 | + // They will be removed by t3lib_page::getRecordOverlay if not matching overlay mode |
|
| 945 | + if (isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) |
|
| 946 | + && $querySettings->getLanguageUid() > 0 |
|
| 947 | + ) { |
|
| 948 | + $additionalWhereClause .= ' OR (' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' . |
|
| 949 | + ' AND ' . $tableNameOrAlias . '.uid NOT IN (SELECT ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . |
|
| 950 | + ' FROM ' . $tableName . |
|
| 951 | + ' WHERE ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'] . '>0' . |
|
| 952 | + ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '>0'; |
|
| 953 | + |
|
| 954 | + // Add delete clause to ensure all entries are loaded |
|
| 955 | + if (isset($GLOBALS['TCA'][$tableName]['ctrl']['delete'])) { |
|
| 956 | + $additionalWhereClause .= ' AND ' . $tableNameOrAlias . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['delete'] . '=0'; |
|
| 957 | + } |
|
| 958 | + $additionalWhereClause .= '))'; |
|
| 959 | + } |
|
| 960 | + $statementParts['additionalWhereClause'][$tableNameOrAlias][] = '(' . $additionalWhereClause . ')'; |
|
| 961 | + } |
|
| 962 | + } |
|
| 963 | + } |
|
| 964 | + |
|
| 965 | + /** |
|
| 966 | + * Builds the page ID checking statement |
|
| 967 | + * |
|
| 968 | + * @param string $tableNameOrAlias The database table name |
|
| 969 | + * @param array &$statementParts The query parts |
|
| 970 | + * @param array $storagePageIds list of storage page ids |
|
| 971 | + * @throws Exception\InconsistentQuerySettingsException |
|
| 972 | + * @return void |
|
| 973 | + */ |
|
| 974 | + protected function addPageIdStatement($tableNameOrAlias, array &$statementParts, array $storagePageIds) |
|
| 975 | + { |
|
| 976 | + |
|
| 977 | + $tableName = $this->resolveTableNameAlias($tableNameOrAlias); |
|
| 978 | + $tableColumns = $this->tableColumnCache->get($tableName); |
|
| 979 | + if ($tableColumns === FALSE) { |
|
| 980 | + $tableColumns = $this->databaseHandle->admin_get_fields($tableName); |
|
| 981 | + $this->tableColumnCache->set($tableName, $tableColumns); |
|
| 982 | + } |
|
| 983 | + if (is_array($GLOBALS['TCA'][$tableName]['ctrl']) && array_key_exists('pid', $tableColumns)) { |
|
| 984 | + $rootLevel = (int)$GLOBALS['TCA'][$tableName]['ctrl']['rootLevel']; |
|
| 985 | + if ($rootLevel) { |
|
| 986 | + if ($rootLevel === 1) { |
|
| 987 | + $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $tableNameOrAlias . '.pid = 0'; |
|
| 988 | + } |
|
| 989 | + } else { |
|
| 990 | + if (empty($storagePageIds)) { |
|
| 991 | + throw new Exception\InconsistentQuerySettingsException('Missing storage page ids.', 1365779762); |
|
| 992 | + } |
|
| 993 | + $statementParts['additionalWhereClause'][$tableNameOrAlias][] = $tableNameOrAlias . '.pid IN (' . implode(', ', $storagePageIds) . ')'; |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | + } |
|
| 997 | + |
|
| 998 | + /** |
|
| 999 | + * Transforms orderings into SQL. |
|
| 1000 | + * |
|
| 1001 | + * @param array $orderings An array of orderings (Tx_Extbase_Persistence_QOM_Ordering) |
|
| 1002 | + * @param SourceInterface $source The source |
|
| 1003 | + * @param array &$sql The query parts |
|
| 1004 | + * @throws Exception\UnsupportedOrderException |
|
| 1005 | + * @return void |
|
| 1006 | + */ |
|
| 1007 | + protected function parseOrderings(array $orderings, SourceInterface $source, array &$sql) |
|
| 1008 | + { |
|
| 1009 | + foreach ($orderings as $fieldNameAndPath => $order) { |
|
| 1010 | + switch ($order) { |
|
| 1011 | + case QueryInterface::ORDER_ASCENDING: |
|
| 1012 | + $order = 'ASC'; |
|
| 1013 | + break; |
|
| 1014 | + case QueryInterface::ORDER_DESCENDING: |
|
| 1015 | + $order = 'DESC'; |
|
| 1016 | + break; |
|
| 1017 | + default: |
|
| 1018 | + throw new Exception\UnsupportedOrderException('Unsupported order encountered.', 1456845126); |
|
| 1019 | + } |
|
| 1020 | + |
|
| 1021 | + $tableName = $this->getFieldPathResolver()->getDataType($fieldNameAndPath, $this->query->getType()); |
|
| 1022 | + $fieldName = $this->getFieldPathResolver()->stripFieldPath($fieldNameAndPath, $tableName); |
|
| 1023 | + $sql['orderings'][] = sprintf('%s.%s %s', $tableName, $fieldName, $order); |
|
| 1024 | + } |
|
| 1025 | + } |
|
| 1026 | + |
|
| 1027 | + /** |
|
| 1028 | + * Transforms limit and offset into SQL |
|
| 1029 | + * |
|
| 1030 | + * @param int $limit |
|
| 1031 | + * @param int $offset |
|
| 1032 | + * @param array &$sql |
|
| 1033 | + * @return void |
|
| 1034 | + */ |
|
| 1035 | + protected function parseLimitAndOffset($limit, $offset, array &$sql) |
|
| 1036 | + { |
|
| 1037 | + if ($limit !== NULL && $offset !== NULL) { |
|
| 1038 | + $sql['limit'] = intval($offset) . ', ' . intval($limit); |
|
| 1039 | + } elseif ($limit !== NULL) { |
|
| 1040 | + $sql['limit'] = intval($limit); |
|
| 1041 | + } |
|
| 1042 | + } |
|
| 1043 | + |
|
| 1044 | + /** |
|
| 1045 | + * Transforms a Resource from a database query to an array of rows. |
|
| 1046 | + * |
|
| 1047 | + * @param resource $result The result |
|
| 1048 | + * @return array The result as an array of rows (tuples) |
|
| 1049 | + */ |
|
| 1050 | + protected function getRowsFromResult($result) |
|
| 1051 | + { |
|
| 1052 | + $rows = array(); |
|
| 1053 | + while ($row = $this->databaseHandle->sql_fetch_assoc($result)) { |
|
| 1054 | + if (is_array($row)) { |
|
| 1055 | + |
|
| 1056 | + // Get language uid from querySettings. |
|
| 1057 | + // Ensure the backend handling is not broken (fallback to Get parameter 'L' if needed) |
|
| 1058 | + $overlaidRow = $this->doLanguageAndWorkspaceOverlay($this->query->getSource(), $row, $this->query->getQuerySettings()); |
|
| 1059 | + $contentObject = GeneralUtility::makeInstance($this->objectType, $this->query->getType(), $overlaidRow); |
|
| 1060 | + $rows[] = $contentObject; |
|
| 1061 | + } |
|
| 1062 | + } |
|
| 1063 | + |
|
| 1064 | + return $rows; |
|
| 1065 | + } |
|
| 1066 | + |
|
| 1067 | + /** |
|
| 1068 | + * Performs workspace and language overlay on the given row array. The language and workspace id is automatically |
|
| 1069 | + * detected (depending on FE or BE context). You can also explicitly set the language/workspace id. |
|
| 1070 | + * |
|
| 1071 | + * @param SourceInterface $source The source (selector od join) |
|
| 1072 | + * @param array $row |
|
| 1073 | + * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings |
|
| 1074 | + * @return array |
|
| 1075 | + */ |
|
| 1076 | + protected function doLanguageAndWorkspaceOverlay(SourceInterface $source, array $row, $querySettings) |
|
| 1077 | + { |
|
| 1078 | + |
|
| 1079 | + /** @var SelectorInterface $source */ |
|
| 1080 | + $tableName = $source->getSelectorName(); |
|
| 1081 | + |
|
| 1082 | + $pageRepository = $this->getPageRepository(); |
|
| 1083 | + if (is_object($GLOBALS['TSFE'])) { |
|
| 1084 | + $languageMode = $GLOBALS['TSFE']->sys_language_mode; |
|
| 1085 | + if ($this->isBackendUserLogged() && $this->getBackendUser()->workspace !== 0) { |
|
| 1086 | + $pageRepository->versioningWorkspaceId = $this->getBackendUser()->workspace; |
|
| 1087 | + } |
|
| 1088 | + } else { |
|
| 1089 | + $languageMode = ''; |
|
| 1090 | + $workspaceUid = $this->getBackendUser()->workspace; |
|
| 1091 | + $pageRepository->versioningWorkspaceId = $workspaceUid; |
|
| 1092 | + if ($this->getBackendUser()->workspace !== 0) { |
|
| 1093 | + $pageRepository->versioningPreview = 1; |
|
| 1094 | + } |
|
| 1095 | + } |
|
| 1096 | + |
|
| 1097 | + // If current row is a translation select its parent |
|
| 1098 | + if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) |
|
| 1099 | + && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) |
|
| 1100 | + ) { |
|
| 1101 | + if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']]) |
|
| 1102 | + && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0 |
|
| 1103 | + ) { |
|
| 1104 | + $row = $this->databaseHandle->exec_SELECTgetSingleRow( |
|
| 1105 | + $tableName . '.*', |
|
| 1106 | + $tableName, |
|
| 1107 | + $tableName . '.uid=' . (int)$row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] . |
|
| 1108 | + ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0' |
|
| 1109 | + ); |
|
| 1110 | + } |
|
| 1111 | + } |
|
| 1112 | + |
|
| 1113 | + // Retrieve the original uid |
|
| 1114 | + // @todo It looks for me this code will never be used! "_ORIG_uid" is something from extbase. Adjust me or remove me in 0.4 + 2 version! |
|
| 1115 | + $pageRepository->versionOL($tableName, $row, TRUE); |
|
| 1116 | + if ($pageRepository->versioningPreview && isset($row['_ORIG_uid'])) { |
|
| 1117 | + $row['uid'] = $row['_ORIG_uid']; |
|
| 1118 | + } |
|
| 1119 | + |
|
| 1120 | + // Special case for table "pages" |
|
| 1121 | + if ($tableName == 'pages') { |
|
| 1122 | + $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid()); |
|
| 1123 | + } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) |
|
| 1124 | + && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '' |
|
| 1125 | + ) { |
|
| 1126 | + if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) { |
|
| 1127 | + $overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : ''; |
|
| 1128 | + $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode); |
|
| 1129 | + } |
|
| 1130 | + } |
|
| 1131 | + |
|
| 1132 | + return $row; |
|
| 1133 | + } |
|
| 1134 | + |
|
| 1135 | + /** |
|
| 1136 | + * Return a resolved table name given a possible table name alias. |
|
| 1137 | + * |
|
| 1138 | + * @param string $tableNameOrAlias |
|
| 1139 | + * @return string |
|
| 1140 | + */ |
|
| 1141 | + protected function resolveTableNameAlias($tableNameOrAlias) |
|
| 1142 | + { |
|
| 1143 | + $resolvedTableName = $tableNameOrAlias; |
|
| 1144 | + if (!empty($this->tableNameAliases['aliases'][$tableNameOrAlias])) { |
|
| 1145 | + $resolvedTableName = $this->tableNameAliases['aliases'][$tableNameOrAlias]; |
|
| 1146 | + } |
|
| 1147 | + return $resolvedTableName; |
|
| 1148 | + } |
|
| 1149 | + |
|
| 1150 | + /** |
|
| 1151 | + * Generate a unique table name alias for the given table name. |
|
| 1152 | + * |
|
| 1153 | + * @param string $tableName |
|
| 1154 | + * @return string |
|
| 1155 | + */ |
|
| 1156 | + protected function generateAlias($tableName) |
|
| 1157 | + { |
|
| 1158 | + |
|
| 1159 | + if (!isset($this->tableNameAliases['aliasIncrement'][$tableName])) { |
|
| 1160 | + $this->tableNameAliases['aliasIncrement'][$tableName] = 0; |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + $numberOfAliases = $this->tableNameAliases['aliasIncrement'][$tableName]; |
|
| 1164 | + $tableNameAlias = $tableName . $numberOfAliases; |
|
| 1165 | + |
|
| 1166 | + $this->tableNameAliases['aliasIncrement'][$tableName]++; |
|
| 1167 | + $this->tableNameAliases['aliases'][$tableNameAlias] = $tableName; |
|
| 1168 | + |
|
| 1169 | + return $tableNameAlias; |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + /** |
|
| 1173 | + * Replace the table names by its table name alias within the given statement. |
|
| 1174 | + * |
|
| 1175 | + * @param string $tableName |
|
| 1176 | + * @param string $tableNameAlias |
|
| 1177 | + * @param string $statement |
|
| 1178 | + * @return string |
|
| 1179 | + */ |
|
| 1180 | + protected function replaceTableNameByAlias($tableName, $tableNameAlias, $statement) |
|
| 1181 | + { |
|
| 1182 | + if ($statement && $tableName !== $tableNameAlias) { |
|
| 1183 | + $statement = str_replace($tableName, $tableNameAlias, $statement); |
|
| 1184 | + } |
|
| 1185 | + return $statement; |
|
| 1186 | + } |
|
| 1187 | + |
|
| 1188 | + /** |
|
| 1189 | + * Returns an instance of the current Backend User. |
|
| 1190 | + * |
|
| 1191 | + * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication |
|
| 1192 | + */ |
|
| 1193 | + protected function getBackendUser() |
|
| 1194 | + { |
|
| 1195 | + return $GLOBALS['BE_USER']; |
|
| 1196 | + } |
|
| 1197 | + |
|
| 1198 | + /** |
|
| 1199 | + * Tell whether a Backend User is logged in. |
|
| 1200 | + * |
|
| 1201 | + * @return bool |
|
| 1202 | + */ |
|
| 1203 | + protected function isBackendUserLogged() |
|
| 1204 | + { |
|
| 1205 | + return is_object($GLOBALS['BE_USER']); |
|
| 1206 | + } |
|
| 1207 | + |
|
| 1208 | + /** |
|
| 1209 | + * @return PageRepository |
|
| 1210 | + */ |
|
| 1211 | + protected function getPageRepository() |
|
| 1212 | + { |
|
| 1213 | + if (!$this->pageRepository instanceof PageRepository) { |
|
| 1214 | + if ($this->environmentService->isEnvironmentInFrontendMode() && is_object($GLOBALS['TSFE'])) { |
|
| 1215 | + $this->pageRepository = $GLOBALS['TSFE']->sys_page; |
|
| 1216 | + } else { |
|
| 1217 | + $this->pageRepository = GeneralUtility::makeInstance('TYPO3\\CMS\\Frontend\\Page\\PageRepository'); |
|
| 1218 | + } |
|
| 1219 | + } |
|
| 1220 | + |
|
| 1221 | + return $this->pageRepository; |
|
| 1222 | + } |
|
| 1223 | + |
|
| 1224 | + /** |
|
| 1225 | + * @return \Fab\Vidi\Resolver\FieldPathResolver |
|
| 1226 | + */ |
|
| 1227 | + protected function getFieldPathResolver() |
|
| 1228 | + { |
|
| 1229 | + return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver'); |
|
| 1230 | + } |
|
| 1231 | + |
|
| 1232 | + /** |
|
| 1233 | + * Checks if there are SQL errors in the last query, and if yes, throw an exception. |
|
| 1234 | + * |
|
| 1235 | + * @return void |
|
| 1236 | + * @param string $sql The SQL statement |
|
| 1237 | + * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException |
|
| 1238 | + */ |
|
| 1239 | + protected function checkSqlErrors($sql = '') |
|
| 1240 | + { |
|
| 1241 | + $error = $this->databaseHandle->sql_error(); |
|
| 1242 | + if ($error !== '') { |
|
| 1243 | + $error .= $sql ? ': ' . $sql : ''; |
|
| 1244 | + throw new \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\SqlErrorException($error, 1247602160); |
|
| 1245 | + } |
|
| 1246 | + } |
|
| 1247 | 1247 | } |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | /** |
| 32 | 32 | * @param ProcessContentDataSignalArguments $signalArguments |
| 33 | - * @return array |
|
| 33 | + * @return ProcessContentDataSignalArguments[] |
|
| 34 | 34 | */ |
| 35 | 35 | public function processRelations(ProcessContentDataSignalArguments $signalArguments) |
| 36 | 36 | { |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | /** |
| 52 | 52 | * @param \Fab\Vidi\Domain\Model\Content $object |
| 53 | - * @param $fieldNameAndPath |
|
| 53 | + * @param string $fieldNameAndPath |
|
| 54 | 54 | * @param array $contentData |
| 55 | 55 | * @param string $savingBehavior |
| 56 | 56 | * @return array |
@@ -28,121 +28,121 @@ |
||
| 28 | 28 | class ContentObjectProcessor implements SingletonInterface |
| 29 | 29 | { |
| 30 | 30 | |
| 31 | - /** |
|
| 32 | - * @param ProcessContentDataSignalArguments $signalArguments |
|
| 33 | - * @return array |
|
| 34 | - */ |
|
| 35 | - public function processRelations(ProcessContentDataSignalArguments $signalArguments) |
|
| 36 | - { |
|
| 37 | - |
|
| 38 | - $contentObject = $signalArguments->getContentObject(); |
|
| 39 | - $fieldNameAndPath = $signalArguments->getFieldNameAndPath(); |
|
| 40 | - $contentData = $signalArguments->getContentData(); |
|
| 41 | - $savingBehavior = $signalArguments->getSavingBehavior(); |
|
| 42 | - |
|
| 43 | - if ($savingBehavior !== SavingBehavior::REPLACE) { |
|
| 44 | - $contentData = $this->appendOrRemoveRelations($contentObject, $fieldNameAndPath, $contentData, $savingBehavior); |
|
| 45 | - $signalArguments->setContentData($contentData); |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - return array($signalArguments); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * @param \Fab\Vidi\Domain\Model\Content $object |
|
| 53 | - * @param $fieldNameAndPath |
|
| 54 | - * @param array $contentData |
|
| 55 | - * @param string $savingBehavior |
|
| 56 | - * @return array |
|
| 57 | - */ |
|
| 58 | - protected function appendOrRemoveRelations(Content $object, $fieldNameAndPath, array $contentData, $savingBehavior) |
|
| 59 | - { |
|
| 60 | - |
|
| 61 | - foreach ($contentData as $fieldName => $values) { |
|
| 62 | - |
|
| 63 | - $resolvedObject = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath); |
|
| 64 | - |
|
| 65 | - if (Tca::table($resolvedObject)->field($fieldName)->hasMany()) { |
|
| 66 | - |
|
| 67 | - // TRUE means CSV values must be converted to array. |
|
| 68 | - if (!is_array($values)) { |
|
| 69 | - $values = GeneralUtility::trimExplode(',', $values); |
|
| 70 | - } |
|
| 71 | - $relatedValues = $this->getRelatedValues($object, $fieldNameAndPath, $fieldName); |
|
| 72 | - |
|
| 73 | - foreach ($values as $value) { |
|
| 74 | - $appendOrRemove = $savingBehavior . 'Relations'; |
|
| 75 | - $relatedValues = $this->$appendOrRemove($value, $relatedValues); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - $contentData[$fieldName] = $relatedValues; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - return $contentData; |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * @param $value |
|
| 86 | - * @param array $relatedValues |
|
| 87 | - * @return array |
|
| 88 | - */ |
|
| 89 | - protected function appendRelations($value, array $relatedValues) |
|
| 90 | - { |
|
| 91 | - if (!in_array($value, $relatedValues)) { |
|
| 92 | - $relatedValues[] = $value; |
|
| 93 | - } |
|
| 94 | - return $relatedValues; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - /** |
|
| 98 | - * @param $value |
|
| 99 | - * @param array $relatedValues |
|
| 100 | - * @return array |
|
| 101 | - */ |
|
| 102 | - protected function removeRelations($value, array $relatedValues) |
|
| 103 | - { |
|
| 104 | - if (in_array($value, $relatedValues)) { |
|
| 105 | - $key = array_search($value, $relatedValues); |
|
| 106 | - unset($relatedValues[$key]); |
|
| 107 | - } |
|
| 108 | - return $relatedValues; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * @param \Fab\Vidi\Domain\Model\Content $object |
|
| 113 | - * @param string $fieldNameAndPath |
|
| 114 | - * @param string $fieldName |
|
| 115 | - * @return array |
|
| 116 | - */ |
|
| 117 | - protected function getRelatedValues(Content $object, $fieldNameAndPath, $fieldName) |
|
| 118 | - { |
|
| 119 | - |
|
| 120 | - $values = array(); |
|
| 121 | - $relatedContentObjects = $this->getContentObjectResolver()->getValue($object, $fieldNameAndPath, $fieldName); |
|
| 122 | - |
|
| 123 | - if (is_array($relatedContentObjects)) { |
|
| 124 | - /** @var Content $relatedContentObject */ |
|
| 125 | - foreach ($relatedContentObjects as $relatedContentObject) { |
|
| 126 | - $values[] = $relatedContentObject->getUid(); |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - return $values; |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * @return \Fab\Vidi\Resolver\ContentObjectResolver |
|
| 135 | - */ |
|
| 136 | - protected function getContentObjectResolver() |
|
| 137 | - { |
|
| 138 | - return GeneralUtility::makeInstance('Fab\Vidi\Resolver\ContentObjectResolver'); |
|
| 139 | - } |
|
| 140 | - |
|
| 141 | - /** |
|
| 142 | - * @return \Fab\Vidi\Resolver\FieldPathResolver |
|
| 143 | - */ |
|
| 144 | - protected function getFieldPathResolver() |
|
| 145 | - { |
|
| 146 | - return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver'); |
|
| 147 | - } |
|
| 31 | + /** |
|
| 32 | + * @param ProcessContentDataSignalArguments $signalArguments |
|
| 33 | + * @return array |
|
| 34 | + */ |
|
| 35 | + public function processRelations(ProcessContentDataSignalArguments $signalArguments) |
|
| 36 | + { |
|
| 37 | + |
|
| 38 | + $contentObject = $signalArguments->getContentObject(); |
|
| 39 | + $fieldNameAndPath = $signalArguments->getFieldNameAndPath(); |
|
| 40 | + $contentData = $signalArguments->getContentData(); |
|
| 41 | + $savingBehavior = $signalArguments->getSavingBehavior(); |
|
| 42 | + |
|
| 43 | + if ($savingBehavior !== SavingBehavior::REPLACE) { |
|
| 44 | + $contentData = $this->appendOrRemoveRelations($contentObject, $fieldNameAndPath, $contentData, $savingBehavior); |
|
| 45 | + $signalArguments->setContentData($contentData); |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + return array($signalArguments); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * @param \Fab\Vidi\Domain\Model\Content $object |
|
| 53 | + * @param $fieldNameAndPath |
|
| 54 | + * @param array $contentData |
|
| 55 | + * @param string $savingBehavior |
|
| 56 | + * @return array |
|
| 57 | + */ |
|
| 58 | + protected function appendOrRemoveRelations(Content $object, $fieldNameAndPath, array $contentData, $savingBehavior) |
|
| 59 | + { |
|
| 60 | + |
|
| 61 | + foreach ($contentData as $fieldName => $values) { |
|
| 62 | + |
|
| 63 | + $resolvedObject = $this->getContentObjectResolver()->getObject($object, $fieldNameAndPath); |
|
| 64 | + |
|
| 65 | + if (Tca::table($resolvedObject)->field($fieldName)->hasMany()) { |
|
| 66 | + |
|
| 67 | + // TRUE means CSV values must be converted to array. |
|
| 68 | + if (!is_array($values)) { |
|
| 69 | + $values = GeneralUtility::trimExplode(',', $values); |
|
| 70 | + } |
|
| 71 | + $relatedValues = $this->getRelatedValues($object, $fieldNameAndPath, $fieldName); |
|
| 72 | + |
|
| 73 | + foreach ($values as $value) { |
|
| 74 | + $appendOrRemove = $savingBehavior . 'Relations'; |
|
| 75 | + $relatedValues = $this->$appendOrRemove($value, $relatedValues); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + $contentData[$fieldName] = $relatedValues; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + return $contentData; |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * @param $value |
|
| 86 | + * @param array $relatedValues |
|
| 87 | + * @return array |
|
| 88 | + */ |
|
| 89 | + protected function appendRelations($value, array $relatedValues) |
|
| 90 | + { |
|
| 91 | + if (!in_array($value, $relatedValues)) { |
|
| 92 | + $relatedValues[] = $value; |
|
| 93 | + } |
|
| 94 | + return $relatedValues; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + /** |
|
| 98 | + * @param $value |
|
| 99 | + * @param array $relatedValues |
|
| 100 | + * @return array |
|
| 101 | + */ |
|
| 102 | + protected function removeRelations($value, array $relatedValues) |
|
| 103 | + { |
|
| 104 | + if (in_array($value, $relatedValues)) { |
|
| 105 | + $key = array_search($value, $relatedValues); |
|
| 106 | + unset($relatedValues[$key]); |
|
| 107 | + } |
|
| 108 | + return $relatedValues; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * @param \Fab\Vidi\Domain\Model\Content $object |
|
| 113 | + * @param string $fieldNameAndPath |
|
| 114 | + * @param string $fieldName |
|
| 115 | + * @return array |
|
| 116 | + */ |
|
| 117 | + protected function getRelatedValues(Content $object, $fieldNameAndPath, $fieldName) |
|
| 118 | + { |
|
| 119 | + |
|
| 120 | + $values = array(); |
|
| 121 | + $relatedContentObjects = $this->getContentObjectResolver()->getValue($object, $fieldNameAndPath, $fieldName); |
|
| 122 | + |
|
| 123 | + if (is_array($relatedContentObjects)) { |
|
| 124 | + /** @var Content $relatedContentObject */ |
|
| 125 | + foreach ($relatedContentObjects as $relatedContentObject) { |
|
| 126 | + $values[] = $relatedContentObject->getUid(); |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + return $values; |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * @return \Fab\Vidi\Resolver\ContentObjectResolver |
|
| 135 | + */ |
|
| 136 | + protected function getContentObjectResolver() |
|
| 137 | + { |
|
| 138 | + return GeneralUtility::makeInstance('Fab\Vidi\Resolver\ContentObjectResolver'); |
|
| 139 | + } |
|
| 140 | + |
|
| 141 | + /** |
|
| 142 | + * @return \Fab\Vidi\Resolver\FieldPathResolver |
|
| 143 | + */ |
|
| 144 | + protected function getFieldPathResolver() |
|
| 145 | + { |
|
| 146 | + return GeneralUtility::makeInstance('Fab\Vidi\Resolver\FieldPathResolver'); |
|
| 147 | + } |
|
| 148 | 148 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | |
| 38 | 38 | /** |
| 39 | 39 | * @param ProcessContentDataSignalArguments $signalArguments |
| 40 | - * @return array |
|
| 40 | + * @return ProcessContentDataSignalArguments[] |
|
| 41 | 41 | */ |
| 42 | 42 | public function processMarkers(ProcessContentDataSignalArguments $signalArguments) |
| 43 | 43 | { |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | * @param string $updateValue |
| 73 | 73 | * @param string $currentValue |
| 74 | 74 | * @param int $counter |
| 75 | - * @param $creationTime |
|
| 75 | + * @param integer $creationTime |
|
| 76 | 76 | * @return string |
| 77 | 77 | */ |
| 78 | 78 | protected function replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime) |
@@ -26,114 +26,114 @@ |
||
| 26 | 26 | class MarkerProcessor implements SingletonInterface |
| 27 | 27 | { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * @var array |
|
| 31 | - */ |
|
| 32 | - protected $wellKnownMarkers = array( |
|
| 33 | - '{*}', |
|
| 34 | - '{counter}', |
|
| 35 | - '{date}', |
|
| 36 | - '{creation_date}' |
|
| 37 | - ); |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @param ProcessContentDataSignalArguments $signalArguments |
|
| 41 | - * @return array |
|
| 42 | - */ |
|
| 43 | - public function processMarkers(ProcessContentDataSignalArguments $signalArguments) |
|
| 44 | - { |
|
| 45 | - |
|
| 46 | - $contentData = $signalArguments->getContentData(); |
|
| 47 | - $creationTime = $this->getCreationTime($signalArguments); |
|
| 48 | - |
|
| 49 | - // Process markers |
|
| 50 | - foreach ($signalArguments->getContentData() as $fieldName => $updateValue) { |
|
| 51 | - if (is_scalar($updateValue)) { |
|
| 52 | - |
|
| 53 | - $currentValue = $this->getContentObjectResolver()->getValue( |
|
| 54 | - $signalArguments->getContentObject(), |
|
| 55 | - $signalArguments->getFieldNameAndPath(), |
|
| 56 | - $fieldName, |
|
| 57 | - $signalArguments->getLanguage() |
|
| 58 | - ); |
|
| 59 | - $counter = $signalArguments->getCounter(); |
|
| 60 | - |
|
| 61 | - $updateValue = $this->searchAndReplace($updateValue, $currentValue); |
|
| 62 | - $updateValue = $this->replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime); |
|
| 63 | - |
|
| 64 | - $contentData[$fieldName] = $updateValue; |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - $signalArguments->setContentData($contentData); |
|
| 69 | - return array($signalArguments); |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * @param string $updateValue |
|
| 74 | - * @param string $currentValue |
|
| 75 | - * @param int $counter |
|
| 76 | - * @param $creationTime |
|
| 77 | - * @return string |
|
| 78 | - */ |
|
| 79 | - protected function replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime) |
|
| 80 | - { |
|
| 81 | - |
|
| 82 | - // Replaces values. |
|
| 83 | - $replaces = array( |
|
| 84 | - $currentValue, |
|
| 85 | - $counter, |
|
| 86 | - date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']), |
|
| 87 | - date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $creationTime), |
|
| 88 | - ); |
|
| 89 | - |
|
| 90 | - // Replace me! |
|
| 91 | - return str_replace($this->wellKnownMarkers, $replaces, $updateValue); |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - /** |
|
| 95 | - * @param string $updateValue |
|
| 96 | - * @param string $currentValue |
|
| 97 | - * @return string |
|
| 98 | - */ |
|
| 99 | - protected function searchAndReplace($updateValue, $currentValue) |
|
| 100 | - { |
|
| 101 | - |
|
| 102 | - if (strpos($updateValue, 's/') !== FALSE) { |
|
| 103 | - $structure = explode('/', $updateValue); |
|
| 104 | - $search = $structure[1]; |
|
| 105 | - $replace = $structure[2]; |
|
| 106 | - |
|
| 107 | - // Perhaps needs to be improved here if $search contains "/" precisely. |
|
| 108 | - $updateValue = preg_replace('/' . $search . '/isU', $replace, $currentValue); |
|
| 109 | - } |
|
| 110 | - return $updateValue; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * @param ProcessContentDataSignalArguments $signalArguments |
|
| 115 | - * @return int |
|
| 116 | - */ |
|
| 117 | - protected function getCreationTime(ProcessContentDataSignalArguments $signalArguments) |
|
| 118 | - { |
|
| 119 | - $creationTime = 0; |
|
| 120 | - $creationTimeField = Tca::table($signalArguments->getContentObject()->getDataType())->getTimeCreationField(); |
|
| 121 | - if ($creationTimeField) { |
|
| 122 | - $creationTime = $this->getContentObjectResolver()->getValue( |
|
| 123 | - $signalArguments->getContentObject(), |
|
| 124 | - $signalArguments->getFieldNameAndPath(), |
|
| 125 | - $creationTimeField |
|
| 126 | - ); |
|
| 127 | - } |
|
| 128 | - return $creationTime; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @return ContentObjectResolver |
|
| 133 | - */ |
|
| 134 | - protected function getContentObjectResolver() |
|
| 135 | - { |
|
| 136 | - return GeneralUtility::makeInstance(ContentObjectResolver::class); |
|
| 137 | - } |
|
| 29 | + /** |
|
| 30 | + * @var array |
|
| 31 | + */ |
|
| 32 | + protected $wellKnownMarkers = array( |
|
| 33 | + '{*}', |
|
| 34 | + '{counter}', |
|
| 35 | + '{date}', |
|
| 36 | + '{creation_date}' |
|
| 37 | + ); |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @param ProcessContentDataSignalArguments $signalArguments |
|
| 41 | + * @return array |
|
| 42 | + */ |
|
| 43 | + public function processMarkers(ProcessContentDataSignalArguments $signalArguments) |
|
| 44 | + { |
|
| 45 | + |
|
| 46 | + $contentData = $signalArguments->getContentData(); |
|
| 47 | + $creationTime = $this->getCreationTime($signalArguments); |
|
| 48 | + |
|
| 49 | + // Process markers |
|
| 50 | + foreach ($signalArguments->getContentData() as $fieldName => $updateValue) { |
|
| 51 | + if (is_scalar($updateValue)) { |
|
| 52 | + |
|
| 53 | + $currentValue = $this->getContentObjectResolver()->getValue( |
|
| 54 | + $signalArguments->getContentObject(), |
|
| 55 | + $signalArguments->getFieldNameAndPath(), |
|
| 56 | + $fieldName, |
|
| 57 | + $signalArguments->getLanguage() |
|
| 58 | + ); |
|
| 59 | + $counter = $signalArguments->getCounter(); |
|
| 60 | + |
|
| 61 | + $updateValue = $this->searchAndReplace($updateValue, $currentValue); |
|
| 62 | + $updateValue = $this->replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime); |
|
| 63 | + |
|
| 64 | + $contentData[$fieldName] = $updateValue; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + $signalArguments->setContentData($contentData); |
|
| 69 | + return array($signalArguments); |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * @param string $updateValue |
|
| 74 | + * @param string $currentValue |
|
| 75 | + * @param int $counter |
|
| 76 | + * @param $creationTime |
|
| 77 | + * @return string |
|
| 78 | + */ |
|
| 79 | + protected function replaceWellKnownMarkers($updateValue, $currentValue, $counter, $creationTime) |
|
| 80 | + { |
|
| 81 | + |
|
| 82 | + // Replaces values. |
|
| 83 | + $replaces = array( |
|
| 84 | + $currentValue, |
|
| 85 | + $counter, |
|
| 86 | + date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy']), |
|
| 87 | + date($GLOBALS['TYPO3_CONF_VARS']['SYS']['ddmmyy'], $creationTime), |
|
| 88 | + ); |
|
| 89 | + |
|
| 90 | + // Replace me! |
|
| 91 | + return str_replace($this->wellKnownMarkers, $replaces, $updateValue); |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + /** |
|
| 95 | + * @param string $updateValue |
|
| 96 | + * @param string $currentValue |
|
| 97 | + * @return string |
|
| 98 | + */ |
|
| 99 | + protected function searchAndReplace($updateValue, $currentValue) |
|
| 100 | + { |
|
| 101 | + |
|
| 102 | + if (strpos($updateValue, 's/') !== FALSE) { |
|
| 103 | + $structure = explode('/', $updateValue); |
|
| 104 | + $search = $structure[1]; |
|
| 105 | + $replace = $structure[2]; |
|
| 106 | + |
|
| 107 | + // Perhaps needs to be improved here if $search contains "/" precisely. |
|
| 108 | + $updateValue = preg_replace('/' . $search . '/isU', $replace, $currentValue); |
|
| 109 | + } |
|
| 110 | + return $updateValue; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * @param ProcessContentDataSignalArguments $signalArguments |
|
| 115 | + * @return int |
|
| 116 | + */ |
|
| 117 | + protected function getCreationTime(ProcessContentDataSignalArguments $signalArguments) |
|
| 118 | + { |
|
| 119 | + $creationTime = 0; |
|
| 120 | + $creationTimeField = Tca::table($signalArguments->getContentObject()->getDataType())->getTimeCreationField(); |
|
| 121 | + if ($creationTimeField) { |
|
| 122 | + $creationTime = $this->getContentObjectResolver()->getValue( |
|
| 123 | + $signalArguments->getContentObject(), |
|
| 124 | + $signalArguments->getFieldNameAndPath(), |
|
| 125 | + $creationTimeField |
|
| 126 | + ); |
|
| 127 | + } |
|
| 128 | + return $creationTime; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @return ContentObjectResolver |
|
| 133 | + */ |
|
| 134 | + protected function getContentObjectResolver() |
|
| 135 | + { |
|
| 136 | + return GeneralUtility::makeInstance(ContentObjectResolver::class); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | 139 | } |