@@ -16,13 +16,13 @@ |
||
16 | 16 | */ |
17 | 17 | class ProcessAction extends Enumeration |
18 | 18 | { |
19 | - public const REMOVE = 'remove'; |
|
19 | + public const REMOVE = 'remove'; |
|
20 | 20 | |
21 | - public const UPDATE = 'update'; |
|
21 | + public const UPDATE = 'update'; |
|
22 | 22 | |
23 | - public const COPY = 'copy'; |
|
23 | + public const COPY = 'copy'; |
|
24 | 24 | |
25 | - public const MOVE = 'move'; |
|
25 | + public const MOVE = 'move'; |
|
26 | 26 | |
27 | - public const LOCALIZE = 'localize'; |
|
27 | + public const LOCALIZE = 'localize'; |
|
28 | 28 | } |
@@ -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"; |
@@ -17,125 +17,125 @@ |
||
17 | 17 | */ |
18 | 18 | class DataService implements SingletonInterface |
19 | 19 | { |
20 | - public function getRecord(string $tableName, array $demand = []): array |
|
21 | - { |
|
22 | - $queryBuilder = $this->getQueryBuilder($tableName); |
|
23 | - $queryBuilder |
|
24 | - ->select('*') |
|
25 | - ->from($tableName); |
|
26 | - |
|
27 | - $this->addDemandConstraints($demand, $queryBuilder); |
|
28 | - $record = $queryBuilder->execute()->fetchAssociative(); |
|
29 | - return is_array($record) |
|
30 | - ? $record |
|
31 | - : []; |
|
32 | - } |
|
33 | - |
|
34 | - public function getRecords(string $tableName, array $demand = [], int $maxResult = 0, int $firstResult = 0): array |
|
35 | - { |
|
36 | - $queryBuilder = $this->getQueryBuilder($tableName); |
|
37 | - $queryBuilder |
|
38 | - ->select('*') |
|
39 | - ->from($tableName); |
|
40 | - |
|
41 | - $this->addDemandConstraints($demand, $queryBuilder); |
|
42 | - |
|
43 | - if ($maxResult) { |
|
44 | - $queryBuilder->setMaxResults($maxResult); |
|
45 | - } |
|
46 | - |
|
47 | - if ($firstResult) { |
|
48 | - $queryBuilder->setFirstResult($firstResult); |
|
49 | - } |
|
50 | - |
|
51 | - return $queryBuilder->execute()->fetchAllAssociative(); |
|
52 | - } |
|
53 | - |
|
54 | - public function count(string $tableName, array $demand = [], int $maxResult = 0, int $firstResult = 0): int |
|
55 | - { |
|
56 | - $queryBuilder = $this->getQueryBuilder($tableName); |
|
57 | - |
|
58 | - // We have to count "manually" if we have a limit or offset. |
|
59 | - if ($maxResult || $firstResult) { |
|
60 | - $records = $this->getRecords($tableName, $demand, $maxResult, $firstResult); |
|
61 | - $count = count($records); |
|
62 | - } else { |
|
63 | - $queryBuilder |
|
64 | - ->count('*') |
|
65 | - ->from($tableName); |
|
66 | - |
|
67 | - $this->addDemandConstraints($demand, $queryBuilder); |
|
68 | - $count = (int)$queryBuilder->execute()->fetchOne(); |
|
69 | - } |
|
70 | - return $count; |
|
71 | - } |
|
72 | - |
|
73 | - public function insert(string $tableName, array $values): int |
|
74 | - { |
|
75 | - $connection = $this->getConnection($tableName); |
|
76 | - $connection->insert( |
|
77 | - $tableName, |
|
78 | - $values |
|
79 | - ); |
|
80 | - return (int)$connection->lastInsertId(); |
|
81 | - } |
|
82 | - |
|
83 | - public function update(string $tableName, array $values, array $identifiers): void |
|
84 | - { |
|
85 | - $connection = $this->getConnection($tableName); |
|
86 | - $connection->update( |
|
87 | - $tableName, |
|
88 | - $values, |
|
89 | - $identifiers |
|
90 | - ); |
|
91 | - } |
|
92 | - |
|
93 | - public function delete(string $tableName, array $identifiers): void |
|
94 | - { |
|
95 | - $connection = $this->getConnection($tableName); |
|
96 | - $connection->delete( |
|
97 | - $tableName, |
|
98 | - $identifiers |
|
99 | - ); |
|
100 | - } |
|
101 | - |
|
102 | - protected function addDemandConstraints(array $demand, $queryBuilder): void |
|
103 | - { |
|
104 | - $expressions = []; |
|
105 | - foreach ($demand as $fieldName => $value) { |
|
106 | - if (is_numeric($value)) { |
|
107 | - $expressions[] = $queryBuilder->expr()->eq( |
|
108 | - $fieldName, |
|
109 | - $value |
|
110 | - ); |
|
111 | - } elseif (is_string($value)) { |
|
112 | - $expressions[] = $queryBuilder->expr()->eq( |
|
113 | - $fieldName, |
|
114 | - $queryBuilder->expr()->literal($value) |
|
115 | - ); |
|
116 | - } elseif (is_array($value)) { |
|
117 | - $expressions[] = $queryBuilder->expr()->in( |
|
118 | - $fieldName, |
|
119 | - $value |
|
120 | - ); |
|
121 | - } |
|
122 | - } |
|
123 | - foreach ($expressions as $expression) { |
|
124 | - $queryBuilder->andWhere($expression); |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - protected function getConnection(string $tableName): Connection |
|
129 | - { |
|
130 | - /** @var ConnectionPool $connectionPool */ |
|
131 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
132 | - return $connectionPool->getConnectionForTable($tableName); |
|
133 | - } |
|
134 | - |
|
135 | - protected function getQueryBuilder(string $tableName): QueryBuilder |
|
136 | - { |
|
137 | - /** @var ConnectionPool $connectionPool */ |
|
138 | - $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
139 | - return $connectionPool->getQueryBuilderForTable($tableName); |
|
140 | - } |
|
20 | + public function getRecord(string $tableName, array $demand = []): array |
|
21 | + { |
|
22 | + $queryBuilder = $this->getQueryBuilder($tableName); |
|
23 | + $queryBuilder |
|
24 | + ->select('*') |
|
25 | + ->from($tableName); |
|
26 | + |
|
27 | + $this->addDemandConstraints($demand, $queryBuilder); |
|
28 | + $record = $queryBuilder->execute()->fetchAssociative(); |
|
29 | + return is_array($record) |
|
30 | + ? $record |
|
31 | + : []; |
|
32 | + } |
|
33 | + |
|
34 | + public function getRecords(string $tableName, array $demand = [], int $maxResult = 0, int $firstResult = 0): array |
|
35 | + { |
|
36 | + $queryBuilder = $this->getQueryBuilder($tableName); |
|
37 | + $queryBuilder |
|
38 | + ->select('*') |
|
39 | + ->from($tableName); |
|
40 | + |
|
41 | + $this->addDemandConstraints($demand, $queryBuilder); |
|
42 | + |
|
43 | + if ($maxResult) { |
|
44 | + $queryBuilder->setMaxResults($maxResult); |
|
45 | + } |
|
46 | + |
|
47 | + if ($firstResult) { |
|
48 | + $queryBuilder->setFirstResult($firstResult); |
|
49 | + } |
|
50 | + |
|
51 | + return $queryBuilder->execute()->fetchAllAssociative(); |
|
52 | + } |
|
53 | + |
|
54 | + public function count(string $tableName, array $demand = [], int $maxResult = 0, int $firstResult = 0): int |
|
55 | + { |
|
56 | + $queryBuilder = $this->getQueryBuilder($tableName); |
|
57 | + |
|
58 | + // We have to count "manually" if we have a limit or offset. |
|
59 | + if ($maxResult || $firstResult) { |
|
60 | + $records = $this->getRecords($tableName, $demand, $maxResult, $firstResult); |
|
61 | + $count = count($records); |
|
62 | + } else { |
|
63 | + $queryBuilder |
|
64 | + ->count('*') |
|
65 | + ->from($tableName); |
|
66 | + |
|
67 | + $this->addDemandConstraints($demand, $queryBuilder); |
|
68 | + $count = (int)$queryBuilder->execute()->fetchOne(); |
|
69 | + } |
|
70 | + return $count; |
|
71 | + } |
|
72 | + |
|
73 | + public function insert(string $tableName, array $values): int |
|
74 | + { |
|
75 | + $connection = $this->getConnection($tableName); |
|
76 | + $connection->insert( |
|
77 | + $tableName, |
|
78 | + $values |
|
79 | + ); |
|
80 | + return (int)$connection->lastInsertId(); |
|
81 | + } |
|
82 | + |
|
83 | + public function update(string $tableName, array $values, array $identifiers): void |
|
84 | + { |
|
85 | + $connection = $this->getConnection($tableName); |
|
86 | + $connection->update( |
|
87 | + $tableName, |
|
88 | + $values, |
|
89 | + $identifiers |
|
90 | + ); |
|
91 | + } |
|
92 | + |
|
93 | + public function delete(string $tableName, array $identifiers): void |
|
94 | + { |
|
95 | + $connection = $this->getConnection($tableName); |
|
96 | + $connection->delete( |
|
97 | + $tableName, |
|
98 | + $identifiers |
|
99 | + ); |
|
100 | + } |
|
101 | + |
|
102 | + protected function addDemandConstraints(array $demand, $queryBuilder): void |
|
103 | + { |
|
104 | + $expressions = []; |
|
105 | + foreach ($demand as $fieldName => $value) { |
|
106 | + if (is_numeric($value)) { |
|
107 | + $expressions[] = $queryBuilder->expr()->eq( |
|
108 | + $fieldName, |
|
109 | + $value |
|
110 | + ); |
|
111 | + } elseif (is_string($value)) { |
|
112 | + $expressions[] = $queryBuilder->expr()->eq( |
|
113 | + $fieldName, |
|
114 | + $queryBuilder->expr()->literal($value) |
|
115 | + ); |
|
116 | + } elseif (is_array($value)) { |
|
117 | + $expressions[] = $queryBuilder->expr()->in( |
|
118 | + $fieldName, |
|
119 | + $value |
|
120 | + ); |
|
121 | + } |
|
122 | + } |
|
123 | + foreach ($expressions as $expression) { |
|
124 | + $queryBuilder->andWhere($expression); |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + protected function getConnection(string $tableName): Connection |
|
129 | + { |
|
130 | + /** @var ConnectionPool $connectionPool */ |
|
131 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
132 | + return $connectionPool->getConnectionForTable($tableName); |
|
133 | + } |
|
134 | + |
|
135 | + protected function getQueryBuilder(string $tableName): QueryBuilder |
|
136 | + { |
|
137 | + /** @var ConnectionPool $connectionPool */ |
|
138 | + $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class); |
|
139 | + return $connectionPool->getQueryBuilderForTable($tableName); |
|
140 | + } |
|
141 | 141 | } |
@@ -19,83 +19,83 @@ |
||
19 | 19 | */ |
20 | 20 | class ClipboardService implements SingletonInterface |
21 | 21 | { |
22 | - /** |
|
23 | - * Get the Matcher object of the clipboard. |
|
24 | - * |
|
25 | - * @return Matcher |
|
26 | - */ |
|
27 | - public function getMatcher() |
|
28 | - { |
|
29 | - $matcher = $this->getBackendUser()->getModuleData($this->getDataKey()); |
|
30 | - if (!$matcher) { |
|
31 | - /** @var $matcher Matcher */ |
|
32 | - $matcher = GeneralUtility::makeInstance(Matcher::class); |
|
33 | - } |
|
34 | - return $matcher; |
|
35 | - } |
|
22 | + /** |
|
23 | + * Get the Matcher object of the clipboard. |
|
24 | + * |
|
25 | + * @return Matcher |
|
26 | + */ |
|
27 | + public function getMatcher() |
|
28 | + { |
|
29 | + $matcher = $this->getBackendUser()->getModuleData($this->getDataKey()); |
|
30 | + if (!$matcher) { |
|
31 | + /** @var $matcher Matcher */ |
|
32 | + $matcher = GeneralUtility::makeInstance(Matcher::class); |
|
33 | + } |
|
34 | + return $matcher; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Tell whether the clipboard has items or not. |
|
39 | - * |
|
40 | - * @return bool |
|
41 | - */ |
|
42 | - public function hasItems() |
|
43 | - { |
|
44 | - $matcher = $this->getMatcher(); |
|
37 | + /** |
|
38 | + * Tell whether the clipboard has items or not. |
|
39 | + * |
|
40 | + * @return bool |
|
41 | + */ |
|
42 | + public function hasItems() |
|
43 | + { |
|
44 | + $matcher = $this->getMatcher(); |
|
45 | 45 | |
46 | - $inCriteria = $matcher->getIn(); |
|
47 | - $likeCriteria = $matcher->getLike(); |
|
48 | - $searchTerm = $matcher->getSearchTerm(); |
|
46 | + $inCriteria = $matcher->getIn(); |
|
47 | + $likeCriteria = $matcher->getLike(); |
|
48 | + $searchTerm = $matcher->getSearchTerm(); |
|
49 | 49 | |
50 | - $hasItems = !empty($inCriteria) || !empty($likeCriteria) || !empty($searchTerm); |
|
51 | - return $hasItems; |
|
52 | - } |
|
50 | + $hasItems = !empty($inCriteria) || !empty($likeCriteria) || !empty($searchTerm); |
|
51 | + return $hasItems; |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Save data into the clipboard. |
|
56 | - * |
|
57 | - * @param Matcher $matches |
|
58 | - */ |
|
59 | - public function save(Matcher $matches) |
|
60 | - { |
|
61 | - $this->getBackendUser()->pushModuleData($this->getDataKey(), $matches); |
|
62 | - } |
|
54 | + /** |
|
55 | + * Save data into the clipboard. |
|
56 | + * |
|
57 | + * @param Matcher $matches |
|
58 | + */ |
|
59 | + public function save(Matcher $matches) |
|
60 | + { |
|
61 | + $this->getBackendUser()->pushModuleData($this->getDataKey(), $matches); |
|
62 | + } |
|
63 | 63 | |
64 | - /** |
|
65 | - * Completely empty the clipboard for a data type. |
|
66 | - * |
|
67 | - * @return void |
|
68 | - */ |
|
69 | - public function flush() |
|
70 | - { |
|
71 | - $this->getBackendUser()->pushModuleData($this->getDataKey(), null); |
|
72 | - } |
|
64 | + /** |
|
65 | + * Completely empty the clipboard for a data type. |
|
66 | + * |
|
67 | + * @return void |
|
68 | + */ |
|
69 | + public function flush() |
|
70 | + { |
|
71 | + $this->getBackendUser()->pushModuleData($this->getDataKey(), null); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * @return string |
|
76 | - */ |
|
77 | - protected function getDataKey() |
|
78 | - { |
|
79 | - return 'vidi_clipboard_' . $this->getModuleLoader()->getDataType(); |
|
80 | - } |
|
74 | + /** |
|
75 | + * @return string |
|
76 | + */ |
|
77 | + protected function getDataKey() |
|
78 | + { |
|
79 | + return 'vidi_clipboard_' . $this->getModuleLoader()->getDataType(); |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * Get the Vidi Module Loader. |
|
84 | - * |
|
85 | - * @return ModuleLoader|object |
|
86 | - */ |
|
87 | - protected function getModuleLoader() |
|
88 | - { |
|
89 | - return GeneralUtility::makeInstance(ModuleLoader::class); |
|
90 | - } |
|
82 | + /** |
|
83 | + * Get the Vidi Module Loader. |
|
84 | + * |
|
85 | + * @return ModuleLoader|object |
|
86 | + */ |
|
87 | + protected function getModuleLoader() |
|
88 | + { |
|
89 | + return GeneralUtility::makeInstance(ModuleLoader::class); |
|
90 | + } |
|
91 | 91 | |
92 | - /** |
|
93 | - * Returns an instance of the current Backend User. |
|
94 | - * |
|
95 | - * @return BackendUserAuthentication |
|
96 | - */ |
|
97 | - protected function getBackendUser() |
|
98 | - { |
|
99 | - return $GLOBALS['BE_USER']; |
|
100 | - } |
|
92 | + /** |
|
93 | + * Returns an instance of the current Backend User. |
|
94 | + * |
|
95 | + * @return BackendUserAuthentication |
|
96 | + */ |
|
97 | + protected function getBackendUser() |
|
98 | + { |
|
99 | + return $GLOBALS['BE_USER']; |
|
100 | + } |
|
101 | 101 | } |
@@ -18,92 +18,92 @@ |
||
18 | 18 | */ |
19 | 19 | class Field implements SingletonInterface |
20 | 20 | { |
21 | - /** |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected static $currentField; |
|
21 | + /** |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected static $currentField; |
|
25 | 25 | |
26 | - /** |
|
27 | - * @var string |
|
28 | - */ |
|
29 | - protected static $currentTable; |
|
26 | + /** |
|
27 | + * @var string |
|
28 | + */ |
|
29 | + protected static $currentTable; |
|
30 | 30 | |
31 | - /** |
|
32 | - * @var array |
|
33 | - */ |
|
34 | - protected $storage = []; |
|
31 | + /** |
|
32 | + * @var array |
|
33 | + */ |
|
34 | + protected $storage = []; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @param string $fieldName |
|
38 | - * @return $this |
|
39 | - * @throws \InvalidArgumentException |
|
40 | - */ |
|
41 | - public static function name($fieldName) |
|
42 | - { |
|
43 | - self::$currentField = $fieldName; |
|
44 | - self::$currentTable = ''; // reset the table name value. |
|
45 | - return GeneralUtility::makeInstance(self::class); |
|
46 | - } |
|
36 | + /** |
|
37 | + * @param string $fieldName |
|
38 | + * @return $this |
|
39 | + * @throws \InvalidArgumentException |
|
40 | + */ |
|
41 | + public static function name($fieldName) |
|
42 | + { |
|
43 | + self::$currentField = $fieldName; |
|
44 | + self::$currentTable = ''; // reset the table name value. |
|
45 | + return GeneralUtility::makeInstance(self::class); |
|
46 | + } |
|
47 | 47 | |
48 | - /** |
|
49 | - * @param string|Content $tableNameOrContentObject |
|
50 | - * @return $this |
|
51 | - */ |
|
52 | - public function of($tableNameOrContentObject) |
|
53 | - { |
|
54 | - // Resolve the table name. |
|
55 | - self::$currentTable = $tableNameOrContentObject instanceof Content ? |
|
56 | - $tableNameOrContentObject->getDataType() : |
|
57 | - $tableNameOrContentObject; |
|
58 | - return $this; |
|
59 | - } |
|
48 | + /** |
|
49 | + * @param string|Content $tableNameOrContentObject |
|
50 | + * @return $this |
|
51 | + */ |
|
52 | + public function of($tableNameOrContentObject) |
|
53 | + { |
|
54 | + // Resolve the table name. |
|
55 | + self::$currentTable = $tableNameOrContentObject instanceof Content ? |
|
56 | + $tableNameOrContentObject->getDataType() : |
|
57 | + $tableNameOrContentObject; |
|
58 | + return $this; |
|
59 | + } |
|
60 | 60 | |
61 | - public function toPropertyName() |
|
62 | - { |
|
63 | - $fieldName = $this->getFieldName(); |
|
64 | - $tableName = $this->getTableName(); |
|
61 | + public function toPropertyName() |
|
62 | + { |
|
63 | + $fieldName = $this->getFieldName(); |
|
64 | + $tableName = $this->getTableName(); |
|
65 | 65 | |
66 | - if (empty($this->storage[$tableName][$fieldName])) { |
|
67 | - if (!array_key_exists($tableName, $this->storage)) { |
|
68 | - $this->storage[$tableName] = []; |
|
69 | - } |
|
66 | + if (empty($this->storage[$tableName][$fieldName])) { |
|
67 | + if (!array_key_exists($tableName, $this->storage)) { |
|
68 | + $this->storage[$tableName] = []; |
|
69 | + } |
|
70 | 70 | |
71 | - // Special case when the field name does not follow the conventions "field_name" => "fieldName". |
|
72 | - // Rely on mapping for those cases. |
|
73 | - if (!empty($GLOBALS['TCA'][$tableName]['vidi']['mappings'][$fieldName])) { |
|
74 | - $propertyName = $GLOBALS['TCA'][$tableName]['vidi']['mappings'][$fieldName]; |
|
75 | - } else { |
|
76 | - $propertyName = GeneralUtility::underscoredToLowerCamelCase($fieldName); |
|
77 | - } |
|
71 | + // Special case when the field name does not follow the conventions "field_name" => "fieldName". |
|
72 | + // Rely on mapping for those cases. |
|
73 | + if (!empty($GLOBALS['TCA'][$tableName]['vidi']['mappings'][$fieldName])) { |
|
74 | + $propertyName = $GLOBALS['TCA'][$tableName]['vidi']['mappings'][$fieldName]; |
|
75 | + } else { |
|
76 | + $propertyName = GeneralUtility::underscoredToLowerCamelCase($fieldName); |
|
77 | + } |
|
78 | 78 | |
79 | - $this->storage[$tableName][$fieldName] = $propertyName; |
|
80 | - } |
|
79 | + $this->storage[$tableName][$fieldName] = $propertyName; |
|
80 | + } |
|
81 | 81 | |
82 | - return $this->storage[$tableName][$fieldName]; |
|
83 | - } |
|
82 | + return $this->storage[$tableName][$fieldName]; |
|
83 | + } |
|
84 | 84 | |
85 | - /** |
|
86 | - * @return string |
|
87 | - * @throws \RuntimeException |
|
88 | - */ |
|
89 | - protected function getFieldName() |
|
90 | - { |
|
91 | - $fieldName = self::$currentField; |
|
92 | - if (empty($fieldName)) { |
|
93 | - throw new \RuntimeException('I could not find a field name value.', 1403203290); |
|
94 | - } |
|
95 | - return $fieldName; |
|
96 | - } |
|
85 | + /** |
|
86 | + * @return string |
|
87 | + * @throws \RuntimeException |
|
88 | + */ |
|
89 | + protected function getFieldName() |
|
90 | + { |
|
91 | + $fieldName = self::$currentField; |
|
92 | + if (empty($fieldName)) { |
|
93 | + throw new \RuntimeException('I could not find a field name value.', 1403203290); |
|
94 | + } |
|
95 | + return $fieldName; |
|
96 | + } |
|
97 | 97 | |
98 | - /** |
|
99 | - * @return string |
|
100 | - */ |
|
101 | - protected function getTableName() |
|
102 | - { |
|
103 | - $tableName = self::$currentTable; |
|
104 | - if (empty($tableName)) { |
|
105 | - throw new \RuntimeException('I could not find a table name value.', 1403203291); |
|
106 | - } |
|
107 | - return $tableName; |
|
108 | - } |
|
98 | + /** |
|
99 | + * @return string |
|
100 | + */ |
|
101 | + protected function getTableName() |
|
102 | + { |
|
103 | + $tableName = self::$currentTable; |
|
104 | + if (empty($tableName)) { |
|
105 | + throw new \RuntimeException('I could not find a table name value.', 1403203291); |
|
106 | + } |
|
107 | + return $tableName; |
|
108 | + } |
|
109 | 109 | } |