@@ -18,135 +18,135 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class CoreDataHandler extends AbstractDataHandler |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * @var array |
|
| 23 | - */ |
|
| 24 | - protected $dataHandler; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Process Content with action "update". |
|
| 28 | - * |
|
| 29 | - * @param Content $content |
|
| 30 | - * @throws \Exception |
|
| 31 | - * @return bool |
|
| 32 | - */ |
|
| 33 | - public function processUpdate(Content $content) |
|
| 34 | - { |
|
| 35 | - $values = []; |
|
| 36 | - |
|
| 37 | - // Check the field to be updated exists |
|
| 38 | - foreach ($content->toArray() as $fieldName => $value) { |
|
| 39 | - if (!Tca::table($content->getDataType())->hasField($fieldName)) { |
|
| 40 | - $message = sprintf('It looks field "%s" does not exist for data type "%s"', $fieldName, $content->getDataType()); |
|
| 41 | - throw new \Exception($message, 1390668497); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - // Flatten value if array given which is required for the DataHandler. |
|
| 45 | - if (is_array($value)) { |
|
| 46 | - $value = implode(',', $value); |
|
| 47 | - } |
|
| 48 | - $values[$fieldName] = $value; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - $data[$content->getDataType()][$content->getUid()] = $values; |
|
| 52 | - |
|
| 53 | - $dataHandler = $this->getDataHandler(); |
|
| 54 | - $dataHandler->start($data, array()); |
|
| 55 | - $dataHandler->process_datamap(); |
|
| 56 | - $this->errorMessages = $dataHandler->errorLog; |
|
| 57 | - |
|
| 58 | - // Returns true is log does not contain errors. |
|
| 59 | - return empty($dataHandler->errorLog); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Process Content with action "remove". |
|
| 64 | - * |
|
| 65 | - * @param Content $content |
|
| 66 | - * @return bool |
|
| 67 | - */ |
|
| 68 | - public function processRemove(Content $content) |
|
| 69 | - { |
|
| 70 | - // Build command |
|
| 71 | - $cmd[$content->getDataType()][$content->getUid()]['delete'] = 1; |
|
| 72 | - |
|
| 73 | - /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 74 | - $dataHandler = $this->getDataHandler(); |
|
| 75 | - $dataHandler->start([], $cmd); |
|
| 76 | - $dataHandler->process_datamap(); |
|
| 77 | - $dataHandler->process_cmdmap(); |
|
| 78 | - $this->errorMessages = $dataHandler->errorLog; |
|
| 79 | - |
|
| 80 | - // Returns true is log does not contain errors. |
|
| 81 | - return empty($dataHandler->errorLog); |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - /** |
|
| 85 | - * Process Content with action "copy". |
|
| 86 | - * |
|
| 87 | - * @param Content $content |
|
| 88 | - * @param string $target |
|
| 89 | - * @return bool |
|
| 90 | - */ |
|
| 91 | - public function processCopy(Content $content, $target) |
|
| 92 | - { |
|
| 93 | - // TODO: Implement processCopy() method. |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Process Content with action "move". |
|
| 98 | - * The $target corresponds to the pid to move the records to. |
|
| 99 | - * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor. |
|
| 100 | - * |
|
| 101 | - * @param Content $content |
|
| 102 | - * @param int $target corresponds |
|
| 103 | - * @return bool |
|
| 104 | - */ |
|
| 105 | - public function processMove(Content $content, $target) |
|
| 106 | - { |
|
| 107 | - // Build command |
|
| 108 | - $cmd[$content->getDataType()][$content->getUid()]['move'] = $target; |
|
| 109 | - |
|
| 110 | - /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 111 | - $dataHandler = $this->getDataHandler(); |
|
| 112 | - $dataHandler->start([], $cmd); |
|
| 113 | - $dataHandler->process_datamap(); |
|
| 114 | - $dataHandler->process_cmdmap(); |
|
| 115 | - $this->errorMessages = $dataHandler->errorLog; |
|
| 116 | - |
|
| 117 | - // Returns true is log does not contain errors. |
|
| 118 | - return empty($dataHandler->errorLog); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - /** |
|
| 122 | - * Process Content with action "localize". |
|
| 123 | - * |
|
| 124 | - * @param Content $content |
|
| 125 | - * @param int $language |
|
| 126 | - * @return bool |
|
| 127 | - */ |
|
| 128 | - public function processLocalize(Content $content, $language) |
|
| 129 | - { |
|
| 130 | - $command[$content->getDataType()][$content->getUid()]['localize'] = $language; |
|
| 131 | - |
|
| 132 | - $dataHandler = $this->getDataHandler(); |
|
| 133 | - $dataHandler->start([], $command); |
|
| 134 | - $dataHandler->process_datamap(); |
|
| 135 | - $dataHandler->process_cmdmap(); |
|
| 136 | - $this->errorMessages = $dataHandler->errorLog; |
|
| 137 | - |
|
| 138 | - // Returns true is log does not contain errors. |
|
| 139 | - return empty($dataHandler->errorLog); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * @return DataHandler |
|
| 144 | - */ |
|
| 145 | - protected function getDataHandler() |
|
| 146 | - { |
|
| 147 | - if (!$this->dataHandler) { |
|
| 148 | - $this->dataHandler = GeneralUtility::makeInstance(DataHandler::class); |
|
| 149 | - } |
|
| 150 | - return $this->dataHandler; |
|
| 151 | - } |
|
| 21 | + /** |
|
| 22 | + * @var array |
|
| 23 | + */ |
|
| 24 | + protected $dataHandler; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Process Content with action "update". |
|
| 28 | + * |
|
| 29 | + * @param Content $content |
|
| 30 | + * @throws \Exception |
|
| 31 | + * @return bool |
|
| 32 | + */ |
|
| 33 | + public function processUpdate(Content $content) |
|
| 34 | + { |
|
| 35 | + $values = []; |
|
| 36 | + |
|
| 37 | + // Check the field to be updated exists |
|
| 38 | + foreach ($content->toArray() as $fieldName => $value) { |
|
| 39 | + if (!Tca::table($content->getDataType())->hasField($fieldName)) { |
|
| 40 | + $message = sprintf('It looks field "%s" does not exist for data type "%s"', $fieldName, $content->getDataType()); |
|
| 41 | + throw new \Exception($message, 1390668497); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + // Flatten value if array given which is required for the DataHandler. |
|
| 45 | + if (is_array($value)) { |
|
| 46 | + $value = implode(',', $value); |
|
| 47 | + } |
|
| 48 | + $values[$fieldName] = $value; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + $data[$content->getDataType()][$content->getUid()] = $values; |
|
| 52 | + |
|
| 53 | + $dataHandler = $this->getDataHandler(); |
|
| 54 | + $dataHandler->start($data, array()); |
|
| 55 | + $dataHandler->process_datamap(); |
|
| 56 | + $this->errorMessages = $dataHandler->errorLog; |
|
| 57 | + |
|
| 58 | + // Returns true is log does not contain errors. |
|
| 59 | + return empty($dataHandler->errorLog); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Process Content with action "remove". |
|
| 64 | + * |
|
| 65 | + * @param Content $content |
|
| 66 | + * @return bool |
|
| 67 | + */ |
|
| 68 | + public function processRemove(Content $content) |
|
| 69 | + { |
|
| 70 | + // Build command |
|
| 71 | + $cmd[$content->getDataType()][$content->getUid()]['delete'] = 1; |
|
| 72 | + |
|
| 73 | + /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 74 | + $dataHandler = $this->getDataHandler(); |
|
| 75 | + $dataHandler->start([], $cmd); |
|
| 76 | + $dataHandler->process_datamap(); |
|
| 77 | + $dataHandler->process_cmdmap(); |
|
| 78 | + $this->errorMessages = $dataHandler->errorLog; |
|
| 79 | + |
|
| 80 | + // Returns true is log does not contain errors. |
|
| 81 | + return empty($dataHandler->errorLog); |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + /** |
|
| 85 | + * Process Content with action "copy". |
|
| 86 | + * |
|
| 87 | + * @param Content $content |
|
| 88 | + * @param string $target |
|
| 89 | + * @return bool |
|
| 90 | + */ |
|
| 91 | + public function processCopy(Content $content, $target) |
|
| 92 | + { |
|
| 93 | + // TODO: Implement processCopy() method. |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Process Content with action "move". |
|
| 98 | + * The $target corresponds to the pid to move the records to. |
|
| 99 | + * It can also be a negative value in case of sorting. The negative value would be the uid of its predecessor. |
|
| 100 | + * |
|
| 101 | + * @param Content $content |
|
| 102 | + * @param int $target corresponds |
|
| 103 | + * @return bool |
|
| 104 | + */ |
|
| 105 | + public function processMove(Content $content, $target) |
|
| 106 | + { |
|
| 107 | + // Build command |
|
| 108 | + $cmd[$content->getDataType()][$content->getUid()]['move'] = $target; |
|
| 109 | + |
|
| 110 | + /** @var $dataHandler \TYPO3\CMS\Core\DataHandling\DataHandler */ |
|
| 111 | + $dataHandler = $this->getDataHandler(); |
|
| 112 | + $dataHandler->start([], $cmd); |
|
| 113 | + $dataHandler->process_datamap(); |
|
| 114 | + $dataHandler->process_cmdmap(); |
|
| 115 | + $this->errorMessages = $dataHandler->errorLog; |
|
| 116 | + |
|
| 117 | + // Returns true is log does not contain errors. |
|
| 118 | + return empty($dataHandler->errorLog); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + /** |
|
| 122 | + * Process Content with action "localize". |
|
| 123 | + * |
|
| 124 | + * @param Content $content |
|
| 125 | + * @param int $language |
|
| 126 | + * @return bool |
|
| 127 | + */ |
|
| 128 | + public function processLocalize(Content $content, $language) |
|
| 129 | + { |
|
| 130 | + $command[$content->getDataType()][$content->getUid()]['localize'] = $language; |
|
| 131 | + |
|
| 132 | + $dataHandler = $this->getDataHandler(); |
|
| 133 | + $dataHandler->start([], $command); |
|
| 134 | + $dataHandler->process_datamap(); |
|
| 135 | + $dataHandler->process_cmdmap(); |
|
| 136 | + $this->errorMessages = $dataHandler->errorLog; |
|
| 137 | + |
|
| 138 | + // Returns true is log does not contain errors. |
|
| 139 | + return empty($dataHandler->errorLog); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * @return DataHandler |
|
| 144 | + */ |
|
| 145 | + protected function getDataHandler() |
|
| 146 | + { |
|
| 147 | + if (!$this->dataHandler) { |
|
| 148 | + $this->dataHandler = GeneralUtility::makeInstance(DataHandler::class); |
|
| 149 | + } |
|
| 150 | + return $this->dataHandler; |
|
| 151 | + } |
|
| 152 | 152 | } |
@@ -16,53 +16,53 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class BackendUserPreferenceService |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Returns a class instance |
|
| 21 | - * |
|
| 22 | - * @return \Fab\Vidi\Service\BackendUserPreferenceService|object |
|
| 23 | - */ |
|
| 24 | - public static function getInstance() |
|
| 25 | - { |
|
| 26 | - return GeneralUtility::makeInstance(\Fab\Vidi\Service\BackendUserPreferenceService::class); |
|
| 27 | - } |
|
| 19 | + /** |
|
| 20 | + * Returns a class instance |
|
| 21 | + * |
|
| 22 | + * @return \Fab\Vidi\Service\BackendUserPreferenceService|object |
|
| 23 | + */ |
|
| 24 | + public static function getInstance() |
|
| 25 | + { |
|
| 26 | + return GeneralUtility::makeInstance(\Fab\Vidi\Service\BackendUserPreferenceService::class); |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Returns a configuration key for the current BE User. |
|
| 31 | - * |
|
| 32 | - * @param string $key |
|
| 33 | - * @return mixed |
|
| 34 | - */ |
|
| 35 | - public function get($key) |
|
| 36 | - { |
|
| 37 | - $result = ''; |
|
| 38 | - if ($this->getBackendUser() && !empty($this->getBackendUser()->uc[$key])) { |
|
| 39 | - $result = $this->getBackendUser()->uc[$key]; |
|
| 40 | - } |
|
| 41 | - return $result; |
|
| 42 | - } |
|
| 29 | + /** |
|
| 30 | + * Returns a configuration key for the current BE User. |
|
| 31 | + * |
|
| 32 | + * @param string $key |
|
| 33 | + * @return mixed |
|
| 34 | + */ |
|
| 35 | + public function get($key) |
|
| 36 | + { |
|
| 37 | + $result = ''; |
|
| 38 | + if ($this->getBackendUser() && !empty($this->getBackendUser()->uc[$key])) { |
|
| 39 | + $result = $this->getBackendUser()->uc[$key]; |
|
| 40 | + } |
|
| 41 | + return $result; |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - /** |
|
| 45 | - * Set a configuration for the current BE User. |
|
| 46 | - * |
|
| 47 | - * @param string $key |
|
| 48 | - * @param mixed $value |
|
| 49 | - * @return void |
|
| 50 | - */ |
|
| 51 | - public function set($key, $value) |
|
| 52 | - { |
|
| 53 | - if ($this->getBackendUser()) { |
|
| 54 | - $this->getBackendUser()->uc[$key] = $value; |
|
| 55 | - $this->getBackendUser()->writeUC(); |
|
| 56 | - } |
|
| 57 | - } |
|
| 44 | + /** |
|
| 45 | + * Set a configuration for the current BE User. |
|
| 46 | + * |
|
| 47 | + * @param string $key |
|
| 48 | + * @param mixed $value |
|
| 49 | + * @return void |
|
| 50 | + */ |
|
| 51 | + public function set($key, $value) |
|
| 52 | + { |
|
| 53 | + if ($this->getBackendUser()) { |
|
| 54 | + $this->getBackendUser()->uc[$key] = $value; |
|
| 55 | + $this->getBackendUser()->writeUC(); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * Returns an instance of the current Backend User. |
|
| 61 | - * |
|
| 62 | - * @return BackendUserAuthentication |
|
| 63 | - */ |
|
| 64 | - protected function getBackendUser() |
|
| 65 | - { |
|
| 66 | - return $GLOBALS['BE_USER']; |
|
| 67 | - } |
|
| 59 | + /** |
|
| 60 | + * Returns an instance of the current Backend User. |
|
| 61 | + * |
|
| 62 | + * @return BackendUserAuthentication |
|
| 63 | + */ |
|
| 64 | + protected function getBackendUser() |
|
| 65 | + { |
|
| 66 | + return $GLOBALS['BE_USER']; |
|
| 67 | + } |
|
| 68 | 68 | } |
@@ -22,82 +22,82 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class FileReferenceService implements SingletonInterface |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @var array |
|
| 27 | - */ |
|
| 28 | - protected static $instances = []; |
|
| 25 | + /** |
|
| 26 | + * @var array |
|
| 27 | + */ |
|
| 28 | + protected static $instances = []; |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Returns a class instance |
|
| 32 | - * |
|
| 33 | - * @return \Fab\Vidi\Service\FileReferenceService|object |
|
| 34 | - */ |
|
| 35 | - public static function getInstance() |
|
| 36 | - { |
|
| 37 | - return GeneralUtility::makeInstance(\Fab\Vidi\Service\FileReferenceService::class); |
|
| 38 | - } |
|
| 30 | + /** |
|
| 31 | + * Returns a class instance |
|
| 32 | + * |
|
| 33 | + * @return \Fab\Vidi\Service\FileReferenceService|object |
|
| 34 | + */ |
|
| 35 | + public static function getInstance() |
|
| 36 | + { |
|
| 37 | + return GeneralUtility::makeInstance(\Fab\Vidi\Service\FileReferenceService::class); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param Content $object |
|
| 42 | - * @param string $propertyName |
|
| 43 | - * @return File[] |
|
| 44 | - */ |
|
| 45 | - public function findReferencedBy($propertyName, Content $object) |
|
| 46 | - { |
|
| 47 | - if (!isset(self::$instances[$object->getUid()][$propertyName])) { |
|
| 48 | - // Initialize instances value |
|
| 49 | - if (!isset(self::$instances[$object->getUid()])) { |
|
| 50 | - self::$instances[$object->getUid()] = []; |
|
| 51 | - } |
|
| 40 | + /** |
|
| 41 | + * @param Content $object |
|
| 42 | + * @param string $propertyName |
|
| 43 | + * @return File[] |
|
| 44 | + */ |
|
| 45 | + public function findReferencedBy($propertyName, Content $object) |
|
| 46 | + { |
|
| 47 | + if (!isset(self::$instances[$object->getUid()][$propertyName])) { |
|
| 48 | + // Initialize instances value |
|
| 49 | + if (!isset(self::$instances[$object->getUid()])) { |
|
| 50 | + self::$instances[$object->getUid()] = []; |
|
| 51 | + } |
|
| 52 | 52 | |
| 53 | - $fieldName = GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName); |
|
| 54 | - $field = Tca::table($object->getDataType())->field($fieldName); |
|
| 55 | - if ($field->getForeignTable() === 'sys_file_reference') { |
|
| 56 | - $files = $this->findByFileReference($propertyName, $object); |
|
| 57 | - self::$instances[$object->getUid()][$propertyName] = $files; |
|
| 58 | - } else { |
|
| 59 | - // @todo the standard way of handling file references is by "sys_file_reference". Let see if there is other use cases... |
|
| 60 | - } |
|
| 61 | - } |
|
| 53 | + $fieldName = GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName); |
|
| 54 | + $field = Tca::table($object->getDataType())->field($fieldName); |
|
| 55 | + if ($field->getForeignTable() === 'sys_file_reference') { |
|
| 56 | + $files = $this->findByFileReference($propertyName, $object); |
|
| 57 | + self::$instances[$object->getUid()][$propertyName] = $files; |
|
| 58 | + } else { |
|
| 59 | + // @todo the standard way of handling file references is by "sys_file_reference". Let see if there is other use cases... |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return self::$instances[$object->getUid()][$propertyName]; |
|
| 64 | - } |
|
| 63 | + return self::$instances[$object->getUid()][$propertyName]; |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Fetch the files given an object assuming |
|
| 68 | - * |
|
| 69 | - * @param $propertyName |
|
| 70 | - * @param Content $object |
|
| 71 | - * @return File[] |
|
| 72 | - */ |
|
| 73 | - protected function findByFileReference($propertyName, Content $object) |
|
| 74 | - { |
|
| 75 | - $fileField = 'uid_local'; |
|
| 76 | - $tableName = 'sys_file_reference'; |
|
| 66 | + /** |
|
| 67 | + * Fetch the files given an object assuming |
|
| 68 | + * |
|
| 69 | + * @param $propertyName |
|
| 70 | + * @param Content $object |
|
| 71 | + * @return File[] |
|
| 72 | + */ |
|
| 73 | + protected function findByFileReference($propertyName, Content $object) |
|
| 74 | + { |
|
| 75 | + $fileField = 'uid_local'; |
|
| 76 | + $tableName = 'sys_file_reference'; |
|
| 77 | 77 | |
| 78 | - $rows = $this->getDataService()->getRecords( |
|
| 79 | - $tableName, |
|
| 80 | - [ |
|
| 81 | - 'tablenames' => $object->getDataType(), |
|
| 82 | - 'fieldname'=> GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName), |
|
| 83 | - 'uid_foreign'=> $object->getUid(), |
|
| 84 | - ] |
|
| 85 | - ); |
|
| 78 | + $rows = $this->getDataService()->getRecords( |
|
| 79 | + $tableName, |
|
| 80 | + [ |
|
| 81 | + 'tablenames' => $object->getDataType(), |
|
| 82 | + 'fieldname'=> GeneralUtility::camelCaseToLowerCaseUnderscored($propertyName), |
|
| 83 | + 'uid_foreign'=> $object->getUid(), |
|
| 84 | + ] |
|
| 85 | + ); |
|
| 86 | 86 | |
| 87 | - // Build array of Files |
|
| 88 | - $files = []; |
|
| 89 | - foreach ($rows as $row) { |
|
| 90 | - $files[] = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($row[$fileField]); |
|
| 91 | - } |
|
| 87 | + // Build array of Files |
|
| 88 | + $files = []; |
|
| 89 | + foreach ($rows as $row) { |
|
| 90 | + $files[] = GeneralUtility::makeInstance(ResourceFactory::class)->getFileObject($row[$fileField]); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return $files; |
|
| 94 | - } |
|
| 93 | + return $files; |
|
| 94 | + } |
|
| 95 | 95 | |
| 96 | - /** |
|
| 97 | - * @return object|DataService |
|
| 98 | - */ |
|
| 99 | - protected function getDataService(): DataService |
|
| 100 | - { |
|
| 101 | - return GeneralUtility::makeInstance(DataService::class); |
|
| 102 | - } |
|
| 96 | + /** |
|
| 97 | + * @return object|DataService |
|
| 98 | + */ |
|
| 99 | + protected function getDataService(): DataService |
|
| 100 | + { |
|
| 101 | + return GeneralUtility::makeInstance(DataService::class); |
|
| 102 | + } |
|
| 103 | 103 | } |
@@ -22,121 +22,121 @@ |
||
| 22 | 22 | */ |
| 23 | 23 | class ContentService |
| 24 | 24 | { |
| 25 | - /** |
|
| 26 | - * @var string |
|
| 27 | - */ |
|
| 28 | - protected $dataType; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * @var Content[] |
|
| 32 | - */ |
|
| 33 | - protected $objects = []; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * @var int |
|
| 37 | - */ |
|
| 38 | - protected $numberOfObjects = 0; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Constructor |
|
| 42 | - * |
|
| 43 | - * @param string $dataType |
|
| 44 | - */ |
|
| 45 | - public function __construct($dataType = '') |
|
| 46 | - { |
|
| 47 | - if (empty($dataType)) { |
|
| 48 | - $dataType = $this->getModuleLoader()->getDataType(); |
|
| 49 | - } |
|
| 50 | - $this->dataType = $dataType; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Fetch the files given an object assuming |
|
| 55 | - * |
|
| 56 | - * @param Matcher $matcher |
|
| 57 | - * @param Order $order The order |
|
| 58 | - * @param int $limit |
|
| 59 | - * @param int $offset |
|
| 60 | - * @return $this |
|
| 61 | - */ |
|
| 62 | - public function findBy(Matcher $matcher, Order $order = null, $limit = null, $offset = null) |
|
| 63 | - { |
|
| 64 | - // Query the repository. |
|
| 65 | - $objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order, $limit, $offset); |
|
| 66 | - $signalResult = $this->emitAfterFindContentObjectsSignal($objects, $matcher, $order, $limit, $offset); |
|
| 67 | - |
|
| 68 | - // Reset objects variable after possible signal / slot processing. |
|
| 69 | - $this->objects = $signalResult->getContentObjects(); |
|
| 70 | - |
|
| 71 | - // Count number of content objects. |
|
| 72 | - if ($signalResult->getHasBeenProcessed()) { |
|
| 73 | - $this->numberOfObjects = $signalResult->getNumberOfObjects(); |
|
| 74 | - } else { |
|
| 75 | - $this->numberOfObjects = ContentRepositoryFactory::getInstance($this->dataType)->countBy($matcher); |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - return $this; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Signal that is called after the content objects have been found. |
|
| 83 | - * |
|
| 84 | - * @param array $contentObjects |
|
| 85 | - * @param Matcher $matcher |
|
| 86 | - * @param Order $order |
|
| 87 | - * @param int $limit |
|
| 88 | - * @param int $offset |
|
| 89 | - * @return AfterFindContentObjectsSignalArguments |
|
| 90 | - */ |
|
| 91 | - protected function emitAfterFindContentObjectsSignal($contentObjects, Matcher $matcher, Order $order = null, $limit = 0, $offset = 0) |
|
| 92 | - { |
|
| 93 | - /** @var AfterFindContentObjectsSignalArguments $signalArguments */ |
|
| 94 | - $signalArguments = GeneralUtility::makeInstance(AfterFindContentObjectsSignalArguments::class); |
|
| 95 | - $signalArguments->setDataType($this->dataType) |
|
| 96 | - ->setContentObjects($contentObjects) |
|
| 97 | - ->setMatcher($matcher) |
|
| 98 | - ->setOrder($order) |
|
| 99 | - ->setLimit($limit) |
|
| 100 | - ->setOffset($offset) |
|
| 101 | - ->setHasBeenProcessed(false); |
|
| 102 | - |
|
| 103 | - $signalResult = $this->getSignalSlotDispatcher()->dispatch(ContentService::class, 'afterFindContentObjects', array($signalArguments)); |
|
| 104 | - return $signalResult[0]; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Get the Vidi Module Loader. |
|
| 109 | - * |
|
| 110 | - * @return ModuleLoader|object |
|
| 111 | - */ |
|
| 112 | - protected function getModuleLoader() |
|
| 113 | - { |
|
| 114 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - /** |
|
| 118 | - * Get the SignalSlot dispatcher. |
|
| 119 | - * |
|
| 120 | - * @return Dispatcher|object |
|
| 121 | - */ |
|
| 122 | - protected function getSignalSlotDispatcher() |
|
| 123 | - { |
|
| 124 | - return GeneralUtility::makeInstance(Dispatcher::class); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * @return Content[] |
|
| 129 | - */ |
|
| 130 | - public function getObjects() |
|
| 131 | - { |
|
| 132 | - return $this->objects; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * @return int |
|
| 137 | - */ |
|
| 138 | - public function getNumberOfObjects() |
|
| 139 | - { |
|
| 140 | - return $this->numberOfObjects; |
|
| 141 | - } |
|
| 25 | + /** |
|
| 26 | + * @var string |
|
| 27 | + */ |
|
| 28 | + protected $dataType; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * @var Content[] |
|
| 32 | + */ |
|
| 33 | + protected $objects = []; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * @var int |
|
| 37 | + */ |
|
| 38 | + protected $numberOfObjects = 0; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Constructor |
|
| 42 | + * |
|
| 43 | + * @param string $dataType |
|
| 44 | + */ |
|
| 45 | + public function __construct($dataType = '') |
|
| 46 | + { |
|
| 47 | + if (empty($dataType)) { |
|
| 48 | + $dataType = $this->getModuleLoader()->getDataType(); |
|
| 49 | + } |
|
| 50 | + $this->dataType = $dataType; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Fetch the files given an object assuming |
|
| 55 | + * |
|
| 56 | + * @param Matcher $matcher |
|
| 57 | + * @param Order $order The order |
|
| 58 | + * @param int $limit |
|
| 59 | + * @param int $offset |
|
| 60 | + * @return $this |
|
| 61 | + */ |
|
| 62 | + public function findBy(Matcher $matcher, Order $order = null, $limit = null, $offset = null) |
|
| 63 | + { |
|
| 64 | + // Query the repository. |
|
| 65 | + $objects = ContentRepositoryFactory::getInstance($this->dataType)->findBy($matcher, $order, $limit, $offset); |
|
| 66 | + $signalResult = $this->emitAfterFindContentObjectsSignal($objects, $matcher, $order, $limit, $offset); |
|
| 67 | + |
|
| 68 | + // Reset objects variable after possible signal / slot processing. |
|
| 69 | + $this->objects = $signalResult->getContentObjects(); |
|
| 70 | + |
|
| 71 | + // Count number of content objects. |
|
| 72 | + if ($signalResult->getHasBeenProcessed()) { |
|
| 73 | + $this->numberOfObjects = $signalResult->getNumberOfObjects(); |
|
| 74 | + } else { |
|
| 75 | + $this->numberOfObjects = ContentRepositoryFactory::getInstance($this->dataType)->countBy($matcher); |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + return $this; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Signal that is called after the content objects have been found. |
|
| 83 | + * |
|
| 84 | + * @param array $contentObjects |
|
| 85 | + * @param Matcher $matcher |
|
| 86 | + * @param Order $order |
|
| 87 | + * @param int $limit |
|
| 88 | + * @param int $offset |
|
| 89 | + * @return AfterFindContentObjectsSignalArguments |
|
| 90 | + */ |
|
| 91 | + protected function emitAfterFindContentObjectsSignal($contentObjects, Matcher $matcher, Order $order = null, $limit = 0, $offset = 0) |
|
| 92 | + { |
|
| 93 | + /** @var AfterFindContentObjectsSignalArguments $signalArguments */ |
|
| 94 | + $signalArguments = GeneralUtility::makeInstance(AfterFindContentObjectsSignalArguments::class); |
|
| 95 | + $signalArguments->setDataType($this->dataType) |
|
| 96 | + ->setContentObjects($contentObjects) |
|
| 97 | + ->setMatcher($matcher) |
|
| 98 | + ->setOrder($order) |
|
| 99 | + ->setLimit($limit) |
|
| 100 | + ->setOffset($offset) |
|
| 101 | + ->setHasBeenProcessed(false); |
|
| 102 | + |
|
| 103 | + $signalResult = $this->getSignalSlotDispatcher()->dispatch(ContentService::class, 'afterFindContentObjects', array($signalArguments)); |
|
| 104 | + return $signalResult[0]; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Get the Vidi Module Loader. |
|
| 109 | + * |
|
| 110 | + * @return ModuleLoader|object |
|
| 111 | + */ |
|
| 112 | + protected function getModuleLoader() |
|
| 113 | + { |
|
| 114 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + /** |
|
| 118 | + * Get the SignalSlot dispatcher. |
|
| 119 | + * |
|
| 120 | + * @return Dispatcher|object |
|
| 121 | + */ |
|
| 122 | + protected function getSignalSlotDispatcher() |
|
| 123 | + { |
|
| 124 | + return GeneralUtility::makeInstance(Dispatcher::class); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * @return Content[] |
|
| 129 | + */ |
|
| 130 | + public function getObjects() |
|
| 131 | + { |
|
| 132 | + return $this->objects; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * @return int |
|
| 137 | + */ |
|
| 138 | + public function getNumberOfObjects() |
|
| 139 | + { |
|
| 140 | + return $this->numberOfObjects; |
|
| 141 | + } |
|
| 142 | 142 | } |
@@ -21,145 +21,145 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | class SpreadSheetService |
| 23 | 23 | { |
| 24 | - public const XmlHeader = "<?xml version=\"1.0\" encoding=\"%s\"?\>\n<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:html=\"http://www.w3.org/TR/REC-html40\">"; |
|
| 25 | - public const XmlFooter = "</Workbook>"; |
|
| 26 | - |
|
| 27 | - /** |
|
| 28 | - * @var string |
|
| 29 | - */ |
|
| 30 | - protected $encoding = 'UTF-8'; // encoding type to specify in file. |
|
| 31 | - // Note that you're on your own for making sure your data is actually encoded to this encoding |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * @var string |
|
| 35 | - */ |
|
| 36 | - protected $title = 'Sheet1'; // title for Worksheet |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * @var string |
|
| 40 | - */ |
|
| 41 | - protected $buffer = ''; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Constructor |
|
| 46 | - */ |
|
| 47 | - public function __construct() |
|
| 48 | - { |
|
| 49 | - $this->addToBuffer($this->generateHeader()); |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @param array $row |
|
| 54 | - */ |
|
| 55 | - public function addRow($row) |
|
| 56 | - { |
|
| 57 | - $this->addToBuffer($this->generateRow($row)); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - /** |
|
| 61 | - * @return mixed |
|
| 62 | - */ |
|
| 63 | - public function toString() |
|
| 64 | - { |
|
| 65 | - $this->addToBuffer($this->generateFooter()); |
|
| 66 | - return $this->buffer; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * @param $data |
|
| 71 | - */ |
|
| 72 | - protected function addToBuffer($data) |
|
| 73 | - { |
|
| 74 | - $this->buffer .= $data; |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - /** |
|
| 78 | - * @return string |
|
| 79 | - */ |
|
| 80 | - protected function generateHeader() |
|
| 81 | - { |
|
| 82 | - // workbook header |
|
| 83 | - $output = stripslashes(sprintf(self::XmlHeader, $this->encoding)) . "\n"; |
|
| 84 | - |
|
| 85 | - // Set up styles |
|
| 86 | - $output .= "<Styles>\n"; |
|
| 87 | - $output .= "<Style ss:ID=\"sDT\"><NumberFormat ss:Format=\"Short Date\"/></Style>\n"; |
|
| 88 | - $output .= "</Styles>\n"; |
|
| 89 | - |
|
| 90 | - // worksheet header |
|
| 91 | - $output .= sprintf("<Worksheet ss:Name=\"%s\">\n <Table>\n", htmlentities($this->title)); |
|
| 92 | - |
|
| 93 | - return $output; |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - protected function generateFooter() |
|
| 97 | - { |
|
| 98 | - $output = ''; |
|
| 99 | - |
|
| 100 | - // worksheet footer |
|
| 101 | - $output .= " </Table>\n</Worksheet>\n"; |
|
| 102 | - |
|
| 103 | - // workbook footer |
|
| 104 | - $output .= self::XmlFooter; |
|
| 105 | - |
|
| 106 | - return $output; |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - /** |
|
| 110 | - * @param $row |
|
| 111 | - * @return string |
|
| 112 | - */ |
|
| 113 | - protected function generateRow($row) |
|
| 114 | - { |
|
| 115 | - $output = ''; |
|
| 116 | - $output .= " <Row>\n"; |
|
| 117 | - foreach ($row as $v) { |
|
| 118 | - $output .= $this->generateCell($v); |
|
| 119 | - } |
|
| 120 | - $output .= " </Row>\n"; |
|
| 121 | - return $output; |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * @param $item |
|
| 126 | - * @return string |
|
| 127 | - */ |
|
| 128 | - protected function generateCell($item) |
|
| 129 | - { |
|
| 130 | - $output = ''; |
|
| 131 | - $style = ''; |
|
| 132 | - |
|
| 133 | - // Tell Excel to treat as a number. Note that Excel only stores roughly 15 digits, so keep |
|
| 134 | - // as text if number is longer than that. |
|
| 135 | - if (preg_match("/^-?\d+(?:[.,]\d+)?$/", $item) && (strlen($item) < 15)) { |
|
| 136 | - $type = 'Number'; |
|
| 137 | - } |
|
| 138 | - // Sniff for valid dates; should look something like 2010-07-14 or 7/14/2010 etc. Can |
|
| 139 | - // also have an optional time after the date. |
|
| 140 | - // |
|
| 141 | - // Note we want to be very strict in what we consider a date. There is the possibility |
|
| 142 | - // of really screwing up the data if we try to reformat a string that was not actually |
|
| 143 | - // intended to represent a date. |
|
| 144 | - elseif (preg_match("/^(\d{1,2}|\d{4})[\/\-]\d{1,2}[\/\-](\d{1,2}|\d{4})([^\d].+)?$/", $item) && |
|
| 145 | - ($timestamp = strtotime($item)) && |
|
| 146 | - ($timestamp > 0) && |
|
| 147 | - ($timestamp < strtotime('+500 years')) |
|
| 148 | - ) { |
|
| 149 | - $type = 'DateTime'; |
|
| 150 | - $item = strftime("%Y-%m-%dT%H:%M:%S", $timestamp); |
|
| 151 | - $style = 'sDT'; // defined in header; tells excel to format date for display |
|
| 152 | - } else { |
|
| 153 | - $type = 'String'; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $item = str_replace(''', ''', htmlspecialchars($item, ENT_QUOTES)); |
|
| 157 | - $item = str_replace("\n", ' ', $item); |
|
| 158 | - $output .= " "; |
|
| 159 | - $output .= $style ? "<Cell ss:StyleID=\"$style\">" : "<Cell>"; |
|
| 160 | - $output .= sprintf("<Data ss:Type=\"%s\">%s</Data>", $type, $item); |
|
| 161 | - $output .= "</Cell>\n"; |
|
| 162 | - |
|
| 163 | - return $output; |
|
| 164 | - } |
|
| 24 | + public const XmlHeader = "<?xml version=\"1.0\" encoding=\"%s\"?\>\n<Workbook xmlns=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:x=\"urn:schemas-microsoft-com:office:excel\" xmlns:ss=\"urn:schemas-microsoft-com:office:spreadsheet\" xmlns:html=\"http://www.w3.org/TR/REC-html40\">"; |
|
| 25 | + public const XmlFooter = "</Workbook>"; |
|
| 26 | + |
|
| 27 | + /** |
|
| 28 | + * @var string |
|
| 29 | + */ |
|
| 30 | + protected $encoding = 'UTF-8'; // encoding type to specify in file. |
|
| 31 | + // Note that you're on your own for making sure your data is actually encoded to this encoding |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * @var string |
|
| 35 | + */ |
|
| 36 | + protected $title = 'Sheet1'; // title for Worksheet |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * @var string |
|
| 40 | + */ |
|
| 41 | + protected $buffer = ''; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Constructor |
|
| 46 | + */ |
|
| 47 | + public function __construct() |
|
| 48 | + { |
|
| 49 | + $this->addToBuffer($this->generateHeader()); |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @param array $row |
|
| 54 | + */ |
|
| 55 | + public function addRow($row) |
|
| 56 | + { |
|
| 57 | + $this->addToBuffer($this->generateRow($row)); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + /** |
|
| 61 | + * @return mixed |
|
| 62 | + */ |
|
| 63 | + public function toString() |
|
| 64 | + { |
|
| 65 | + $this->addToBuffer($this->generateFooter()); |
|
| 66 | + return $this->buffer; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * @param $data |
|
| 71 | + */ |
|
| 72 | + protected function addToBuffer($data) |
|
| 73 | + { |
|
| 74 | + $this->buffer .= $data; |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + /** |
|
| 78 | + * @return string |
|
| 79 | + */ |
|
| 80 | + protected function generateHeader() |
|
| 81 | + { |
|
| 82 | + // workbook header |
|
| 83 | + $output = stripslashes(sprintf(self::XmlHeader, $this->encoding)) . "\n"; |
|
| 84 | + |
|
| 85 | + // Set up styles |
|
| 86 | + $output .= "<Styles>\n"; |
|
| 87 | + $output .= "<Style ss:ID=\"sDT\"><NumberFormat ss:Format=\"Short Date\"/></Style>\n"; |
|
| 88 | + $output .= "</Styles>\n"; |
|
| 89 | + |
|
| 90 | + // worksheet header |
|
| 91 | + $output .= sprintf("<Worksheet ss:Name=\"%s\">\n <Table>\n", htmlentities($this->title)); |
|
| 92 | + |
|
| 93 | + return $output; |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + protected function generateFooter() |
|
| 97 | + { |
|
| 98 | + $output = ''; |
|
| 99 | + |
|
| 100 | + // worksheet footer |
|
| 101 | + $output .= " </Table>\n</Worksheet>\n"; |
|
| 102 | + |
|
| 103 | + // workbook footer |
|
| 104 | + $output .= self::XmlFooter; |
|
| 105 | + |
|
| 106 | + return $output; |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + /** |
|
| 110 | + * @param $row |
|
| 111 | + * @return string |
|
| 112 | + */ |
|
| 113 | + protected function generateRow($row) |
|
| 114 | + { |
|
| 115 | + $output = ''; |
|
| 116 | + $output .= " <Row>\n"; |
|
| 117 | + foreach ($row as $v) { |
|
| 118 | + $output .= $this->generateCell($v); |
|
| 119 | + } |
|
| 120 | + $output .= " </Row>\n"; |
|
| 121 | + return $output; |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * @param $item |
|
| 126 | + * @return string |
|
| 127 | + */ |
|
| 128 | + protected function generateCell($item) |
|
| 129 | + { |
|
| 130 | + $output = ''; |
|
| 131 | + $style = ''; |
|
| 132 | + |
|
| 133 | + // Tell Excel to treat as a number. Note that Excel only stores roughly 15 digits, so keep |
|
| 134 | + // as text if number is longer than that. |
|
| 135 | + if (preg_match("/^-?\d+(?:[.,]\d+)?$/", $item) && (strlen($item) < 15)) { |
|
| 136 | + $type = 'Number'; |
|
| 137 | + } |
|
| 138 | + // Sniff for valid dates; should look something like 2010-07-14 or 7/14/2010 etc. Can |
|
| 139 | + // also have an optional time after the date. |
|
| 140 | + // |
|
| 141 | + // Note we want to be very strict in what we consider a date. There is the possibility |
|
| 142 | + // of really screwing up the data if we try to reformat a string that was not actually |
|
| 143 | + // intended to represent a date. |
|
| 144 | + elseif (preg_match("/^(\d{1,2}|\d{4})[\/\-]\d{1,2}[\/\-](\d{1,2}|\d{4})([^\d].+)?$/", $item) && |
|
| 145 | + ($timestamp = strtotime($item)) && |
|
| 146 | + ($timestamp > 0) && |
|
| 147 | + ($timestamp < strtotime('+500 years')) |
|
| 148 | + ) { |
|
| 149 | + $type = 'DateTime'; |
|
| 150 | + $item = strftime("%Y-%m-%dT%H:%M:%S", $timestamp); |
|
| 151 | + $style = 'sDT'; // defined in header; tells excel to format date for display |
|
| 152 | + } else { |
|
| 153 | + $type = 'String'; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $item = str_replace(''', ''', htmlspecialchars($item, ENT_QUOTES)); |
|
| 157 | + $item = str_replace("\n", ' ', $item); |
|
| 158 | + $output .= " "; |
|
| 159 | + $output .= $style ? "<Cell ss:StyleID=\"$style\">" : "<Cell>"; |
|
| 160 | + $output .= sprintf("<Data ss:Type=\"%s\">%s</Data>", $type, $item); |
|
| 161 | + $output .= "</Cell>\n"; |
|
| 162 | + |
|
| 163 | + return $output; |
|
| 164 | + } |
|
| 165 | 165 | } |
@@ -80,7 +80,7 @@ |
||
| 80 | 80 | protected function generateHeader() |
| 81 | 81 | { |
| 82 | 82 | // workbook header |
| 83 | - $output = stripslashes(sprintf(self::XmlHeader, $this->encoding)) . "\n"; |
|
| 83 | + $output = stripslashes(sprintf(self::XmlHeader, $this->encoding))."\n"; |
|
| 84 | 84 | |
| 85 | 85 | // Set up styles |
| 86 | 86 | $output .= "<Styles>\n"; |
@@ -18,42 +18,42 @@ |
||
| 18 | 18 | */ |
| 19 | 19 | class OrderObjectFactory implements SingletonInterface |
| 20 | 20 | { |
| 21 | - /** |
|
| 22 | - * Gets a singleton instance of this class. |
|
| 23 | - * |
|
| 24 | - * @return \Fab\Vidi\Persistence\OrderObjectFactory|object |
|
| 25 | - */ |
|
| 26 | - public static function getInstance() |
|
| 27 | - { |
|
| 28 | - return GeneralUtility::makeInstance(\Fab\Vidi\Persistence\OrderObjectFactory::class); |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * Returns an order object. |
|
| 33 | - * |
|
| 34 | - * @param string $dataType |
|
| 35 | - * @return Order|object |
|
| 36 | - */ |
|
| 37 | - public function getOrder($dataType = '') |
|
| 38 | - { |
|
| 39 | - // Default ordering |
|
| 40 | - $order = Tca::table($dataType)->getDefaultOrderings(); |
|
| 41 | - |
|
| 42 | - // Retrieve a possible id of the column from the request |
|
| 43 | - $orderings = GeneralUtility::_GP('order'); |
|
| 44 | - |
|
| 45 | - if (is_array($orderings) && isset($orderings[0])) { |
|
| 46 | - $columnPosition = $orderings[0]['column']; |
|
| 47 | - $direction = $orderings[0]['dir']; |
|
| 48 | - |
|
| 49 | - if ($columnPosition > 0) { |
|
| 50 | - $field = Tca::grid()->getFieldNameByPosition($columnPosition); |
|
| 51 | - |
|
| 52 | - $order = array( |
|
| 53 | - $field => strtoupper($direction) |
|
| 54 | - ); |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - return GeneralUtility::makeInstance(Order::class, $order); |
|
| 58 | - } |
|
| 21 | + /** |
|
| 22 | + * Gets a singleton instance of this class. |
|
| 23 | + * |
|
| 24 | + * @return \Fab\Vidi\Persistence\OrderObjectFactory|object |
|
| 25 | + */ |
|
| 26 | + public static function getInstance() |
|
| 27 | + { |
|
| 28 | + return GeneralUtility::makeInstance(\Fab\Vidi\Persistence\OrderObjectFactory::class); |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * Returns an order object. |
|
| 33 | + * |
|
| 34 | + * @param string $dataType |
|
| 35 | + * @return Order|object |
|
| 36 | + */ |
|
| 37 | + public function getOrder($dataType = '') |
|
| 38 | + { |
|
| 39 | + // Default ordering |
|
| 40 | + $order = Tca::table($dataType)->getDefaultOrderings(); |
|
| 41 | + |
|
| 42 | + // Retrieve a possible id of the column from the request |
|
| 43 | + $orderings = GeneralUtility::_GP('order'); |
|
| 44 | + |
|
| 45 | + if (is_array($orderings) && isset($orderings[0])) { |
|
| 46 | + $columnPosition = $orderings[0]['column']; |
|
| 47 | + $direction = $orderings[0]['dir']; |
|
| 48 | + |
|
| 49 | + if ($columnPosition > 0) { |
|
| 50 | + $field = Tca::grid()->getFieldNameByPosition($columnPosition); |
|
| 51 | + |
|
| 52 | + $order = array( |
|
| 53 | + $field => strtoupper($direction) |
|
| 54 | + ); |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + return GeneralUtility::makeInstance(Order::class, $order); |
|
| 58 | + } |
|
| 59 | 59 | } |
@@ -16,168 +16,168 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class Pager |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * Total amount of entries |
|
| 21 | - * |
|
| 22 | - * @var integer |
|
| 23 | - */ |
|
| 24 | - protected $count; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Current offset |
|
| 28 | - * |
|
| 29 | - * @var integer |
|
| 30 | - */ |
|
| 31 | - protected $offset; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Current page index |
|
| 35 | - * |
|
| 36 | - * @var integer |
|
| 37 | - */ |
|
| 38 | - protected $page; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * Number of items per page |
|
| 42 | - * |
|
| 43 | - * @var integer |
|
| 44 | - */ |
|
| 45 | - protected $limit = 10; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Constructs a new Pager |
|
| 49 | - */ |
|
| 50 | - public function __construct() |
|
| 51 | - { |
|
| 52 | - $this->page = 1; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * Returns the total amount of entries |
|
| 57 | - * |
|
| 58 | - * @return int |
|
| 59 | - */ |
|
| 60 | - public function getCount() |
|
| 61 | - { |
|
| 62 | - return $this->count; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Sets the total amount of entries |
|
| 67 | - * |
|
| 68 | - * @param int $count |
|
| 69 | - */ |
|
| 70 | - public function setCount($count) |
|
| 71 | - { |
|
| 72 | - $this->count = $count; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Returns the current page index |
|
| 77 | - * |
|
| 78 | - * @return int |
|
| 79 | - */ |
|
| 80 | - public function getPage() |
|
| 81 | - { |
|
| 82 | - return $this->page; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Sets the current page index |
|
| 87 | - * |
|
| 88 | - * @param int $page |
|
| 89 | - */ |
|
| 90 | - public function setPage($page) |
|
| 91 | - { |
|
| 92 | - $this->page = $page; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * Returns the current limit index |
|
| 97 | - * |
|
| 98 | - * @return int |
|
| 99 | - */ |
|
| 100 | - public function getLimit() |
|
| 101 | - { |
|
| 102 | - return $this->limit; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Sets the current limit index |
|
| 107 | - * |
|
| 108 | - * @param int $limit |
|
| 109 | - */ |
|
| 110 | - public function setLimit($limit) |
|
| 111 | - { |
|
| 112 | - $this->limit = $limit; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - /** |
|
| 116 | - * @return Array Items to display |
|
| 117 | - */ |
|
| 118 | - public function getDisplayItems() |
|
| 119 | - { |
|
| 120 | - $last = $this->getLastPage(); |
|
| 121 | - if ($last == 1) { |
|
| 122 | - return null; |
|
| 123 | - } |
|
| 124 | - $values = array(); |
|
| 125 | - for ($i = 1; $i <= $last; $i++) { |
|
| 126 | - $values[] = array('key' => $i, 'value' => $i); |
|
| 127 | - } |
|
| 128 | - return $values; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * @return int The last page index |
|
| 133 | - */ |
|
| 134 | - public function getLastPage() |
|
| 135 | - { |
|
| 136 | - $last = intval($this->count / $this->limit); |
|
| 137 | - if ($this->count % $this->limit > 0) { |
|
| 138 | - $last++; |
|
| 139 | - } |
|
| 140 | - return $last; |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - /** |
|
| 144 | - * @return int The previous page index. Minimum value is 1 |
|
| 145 | - */ |
|
| 146 | - public function getPreviousPage() |
|
| 147 | - { |
|
| 148 | - $prev = $this->page - 1; |
|
| 149 | - if ($prev < 1) { |
|
| 150 | - $prev = 1; |
|
| 151 | - } |
|
| 152 | - return $prev; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * @return int The next page index. Maximum valus is the last page |
|
| 157 | - */ |
|
| 158 | - public function getNextPage() |
|
| 159 | - { |
|
| 160 | - $next = $this->page + 1; |
|
| 161 | - $last = $this->getLastPage(); |
|
| 162 | - if ($next > $last) { |
|
| 163 | - $next = $last; |
|
| 164 | - } |
|
| 165 | - return $next; |
|
| 166 | - } |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * @return int |
|
| 170 | - */ |
|
| 171 | - public function getOffset() |
|
| 172 | - { |
|
| 173 | - return $this->offset; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * @param int $offset |
|
| 178 | - */ |
|
| 179 | - public function setOffset($offset) |
|
| 180 | - { |
|
| 181 | - $this->offset = $offset; |
|
| 182 | - } |
|
| 19 | + /** |
|
| 20 | + * Total amount of entries |
|
| 21 | + * |
|
| 22 | + * @var integer |
|
| 23 | + */ |
|
| 24 | + protected $count; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Current offset |
|
| 28 | + * |
|
| 29 | + * @var integer |
|
| 30 | + */ |
|
| 31 | + protected $offset; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Current page index |
|
| 35 | + * |
|
| 36 | + * @var integer |
|
| 37 | + */ |
|
| 38 | + protected $page; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * Number of items per page |
|
| 42 | + * |
|
| 43 | + * @var integer |
|
| 44 | + */ |
|
| 45 | + protected $limit = 10; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Constructs a new Pager |
|
| 49 | + */ |
|
| 50 | + public function __construct() |
|
| 51 | + { |
|
| 52 | + $this->page = 1; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * Returns the total amount of entries |
|
| 57 | + * |
|
| 58 | + * @return int |
|
| 59 | + */ |
|
| 60 | + public function getCount() |
|
| 61 | + { |
|
| 62 | + return $this->count; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Sets the total amount of entries |
|
| 67 | + * |
|
| 68 | + * @param int $count |
|
| 69 | + */ |
|
| 70 | + public function setCount($count) |
|
| 71 | + { |
|
| 72 | + $this->count = $count; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Returns the current page index |
|
| 77 | + * |
|
| 78 | + * @return int |
|
| 79 | + */ |
|
| 80 | + public function getPage() |
|
| 81 | + { |
|
| 82 | + return $this->page; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Sets the current page index |
|
| 87 | + * |
|
| 88 | + * @param int $page |
|
| 89 | + */ |
|
| 90 | + public function setPage($page) |
|
| 91 | + { |
|
| 92 | + $this->page = $page; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * Returns the current limit index |
|
| 97 | + * |
|
| 98 | + * @return int |
|
| 99 | + */ |
|
| 100 | + public function getLimit() |
|
| 101 | + { |
|
| 102 | + return $this->limit; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Sets the current limit index |
|
| 107 | + * |
|
| 108 | + * @param int $limit |
|
| 109 | + */ |
|
| 110 | + public function setLimit($limit) |
|
| 111 | + { |
|
| 112 | + $this->limit = $limit; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + /** |
|
| 116 | + * @return Array Items to display |
|
| 117 | + */ |
|
| 118 | + public function getDisplayItems() |
|
| 119 | + { |
|
| 120 | + $last = $this->getLastPage(); |
|
| 121 | + if ($last == 1) { |
|
| 122 | + return null; |
|
| 123 | + } |
|
| 124 | + $values = array(); |
|
| 125 | + for ($i = 1; $i <= $last; $i++) { |
|
| 126 | + $values[] = array('key' => $i, 'value' => $i); |
|
| 127 | + } |
|
| 128 | + return $values; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * @return int The last page index |
|
| 133 | + */ |
|
| 134 | + public function getLastPage() |
|
| 135 | + { |
|
| 136 | + $last = intval($this->count / $this->limit); |
|
| 137 | + if ($this->count % $this->limit > 0) { |
|
| 138 | + $last++; |
|
| 139 | + } |
|
| 140 | + return $last; |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + /** |
|
| 144 | + * @return int The previous page index. Minimum value is 1 |
|
| 145 | + */ |
|
| 146 | + public function getPreviousPage() |
|
| 147 | + { |
|
| 148 | + $prev = $this->page - 1; |
|
| 149 | + if ($prev < 1) { |
|
| 150 | + $prev = 1; |
|
| 151 | + } |
|
| 152 | + return $prev; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * @return int The next page index. Maximum valus is the last page |
|
| 157 | + */ |
|
| 158 | + public function getNextPage() |
|
| 159 | + { |
|
| 160 | + $next = $this->page + 1; |
|
| 161 | + $last = $this->getLastPage(); |
|
| 162 | + if ($next > $last) { |
|
| 163 | + $next = $last; |
|
| 164 | + } |
|
| 165 | + return $next; |
|
| 166 | + } |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * @return int |
|
| 170 | + */ |
|
| 171 | + public function getOffset() |
|
| 172 | + { |
|
| 173 | + return $this->offset; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * @param int $offset |
|
| 178 | + */ |
|
| 179 | + public function setOffset($offset) |
|
| 180 | + { |
|
| 181 | + $this->offset = $offset; |
|
| 182 | + } |
|
| 183 | 183 | } |
@@ -14,45 +14,45 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class Order |
| 16 | 16 | { |
| 17 | - /** |
|
| 18 | - * The orderings |
|
| 19 | - * |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected $orderings = []; |
|
| 17 | + /** |
|
| 18 | + * The orderings |
|
| 19 | + * |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected $orderings = []; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * Constructs a new Order |
|
| 26 | - * |
|
| 27 | - * @para array $orders |
|
| 28 | - * @param array $orders |
|
| 29 | - */ |
|
| 30 | - public function __construct($orders = array()) |
|
| 31 | - { |
|
| 32 | - foreach ($orders as $order => $direction) { |
|
| 33 | - $this->addOrdering($order, $direction); |
|
| 34 | - } |
|
| 35 | - } |
|
| 24 | + /** |
|
| 25 | + * Constructs a new Order |
|
| 26 | + * |
|
| 27 | + * @para array $orders |
|
| 28 | + * @param array $orders |
|
| 29 | + */ |
|
| 30 | + public function __construct($orders = array()) |
|
| 31 | + { |
|
| 32 | + foreach ($orders as $order => $direction) { |
|
| 33 | + $this->addOrdering($order, $direction); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * Add ordering |
|
| 39 | - * |
|
| 40 | - * @param string $order The order |
|
| 41 | - * @param string $direction ASC / DESC |
|
| 42 | - * @return void |
|
| 43 | - */ |
|
| 44 | - public function addOrdering($order, $direction) |
|
| 45 | - { |
|
| 46 | - $this->orderings[$order] = $direction; |
|
| 47 | - } |
|
| 37 | + /** |
|
| 38 | + * Add ordering |
|
| 39 | + * |
|
| 40 | + * @param string $order The order |
|
| 41 | + * @param string $direction ASC / DESC |
|
| 42 | + * @return void |
|
| 43 | + */ |
|
| 44 | + public function addOrdering($order, $direction) |
|
| 45 | + { |
|
| 46 | + $this->orderings[$order] = $direction; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - /** |
|
| 50 | - * Returns the order |
|
| 51 | - * |
|
| 52 | - * @return array The order |
|
| 53 | - */ |
|
| 54 | - public function getOrderings() |
|
| 55 | - { |
|
| 56 | - return $this->orderings; |
|
| 57 | - } |
|
| 49 | + /** |
|
| 50 | + * Returns the order |
|
| 51 | + * |
|
| 52 | + * @return array The order |
|
| 53 | + */ |
|
| 54 | + public function getOrderings() |
|
| 55 | + { |
|
| 56 | + return $this->orderings; |
|
| 57 | + } |
|
| 58 | 58 | } |
@@ -16,31 +16,31 @@ |
||
| 16 | 16 | */ |
| 17 | 17 | class ResultSetStorage implements SingletonInterface |
| 18 | 18 | { |
| 19 | - /** |
|
| 20 | - * @var array |
|
| 21 | - */ |
|
| 22 | - protected $resultSets = []; |
|
| 19 | + /** |
|
| 20 | + * @var array |
|
| 21 | + */ |
|
| 22 | + protected $resultSets = []; |
|
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @param string $querySignature |
|
| 26 | - * @return array |
|
| 27 | - */ |
|
| 28 | - public function get($querySignature) |
|
| 29 | - { |
|
| 30 | - $resultSet = null; |
|
| 31 | - if (isset($this->resultSets[$querySignature])) { |
|
| 32 | - $resultSet = $this->resultSets[$querySignature]; |
|
| 33 | - } |
|
| 34 | - return $resultSet; |
|
| 35 | - } |
|
| 24 | + /** |
|
| 25 | + * @param string $querySignature |
|
| 26 | + * @return array |
|
| 27 | + */ |
|
| 28 | + public function get($querySignature) |
|
| 29 | + { |
|
| 30 | + $resultSet = null; |
|
| 31 | + if (isset($this->resultSets[$querySignature])) { |
|
| 32 | + $resultSet = $this->resultSets[$querySignature]; |
|
| 33 | + } |
|
| 34 | + return $resultSet; |
|
| 35 | + } |
|
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @param $querySignature |
|
| 39 | - * @param array $resultSet |
|
| 40 | - * @internal param array $resultSets |
|
| 41 | - */ |
|
| 42 | - public function set($querySignature, array $resultSet) |
|
| 43 | - { |
|
| 44 | - $this->resultSets[$querySignature] = $resultSet; |
|
| 45 | - } |
|
| 37 | + /** |
|
| 38 | + * @param $querySignature |
|
| 39 | + * @param array $resultSet |
|
| 40 | + * @internal param array $resultSets |
|
| 41 | + */ |
|
| 42 | + public function set($querySignature, array $resultSet) |
|
| 43 | + { |
|
| 44 | + $this->resultSets[$querySignature] = $resultSet; |
|
| 45 | + } |
|
| 46 | 46 | } |