/models/DataObject/Listing/Concrete.php

https://github.com/pimcore/pimcore · PHP · 366 lines · 146 code · 56 blank · 164 comment · 5 complexity · 455ef70c8b1c690395d49820af63a1d2 MD5 · raw file

  1. <?php
  2. /**
  3. * Pimcore
  4. *
  5. * This source file is available under two different licenses:
  6. * - GNU General Public License version 3 (GPLv3)
  7. * - Pimcore Commercial License (PCL)
  8. * Full copyright and license information is available in
  9. * LICENSE.md which is distributed with this source code.
  10. *
  11. * @copyright Copyright (c) Pimcore GmbH (http://www.pimcore.org)
  12. * @license http://www.pimcore.org/license GPLv3 and PCL
  13. */
  14. namespace Pimcore\Model\DataObject\Listing;
  15. use Pimcore\Model;
  16. use Pimcore\Model\DataObject;
  17. /**
  18. * @method DataObject\Listing\Concrete\Dao getDao()
  19. * @method DataObject\Concrete[] load()
  20. * @method DataObject\Concrete|false current()
  21. */
  22. abstract class Concrete extends Model\DataObject\Listing
  23. {
  24. /**
  25. * @var string
  26. */
  27. protected $classId;
  28. /**
  29. * @var string
  30. */
  31. protected $className;
  32. /**
  33. * @var string
  34. */
  35. protected $locale;
  36. /**
  37. * do not use the localized views for this list (in the case the class contains localized fields),
  38. * conditions on localized fields are not possible
  39. *
  40. * @var bool
  41. */
  42. protected $ignoreLocalizedFields = false;
  43. /**
  44. * @throws \Exception
  45. */
  46. public function __construct()
  47. {
  48. $this->initDao(__CLASS__);
  49. }
  50. /**
  51. * @return string
  52. */
  53. public function getClassId()
  54. {
  55. return $this->classId;
  56. }
  57. /**
  58. * @return string
  59. */
  60. public function getClassName()
  61. {
  62. return $this->className;
  63. }
  64. /**
  65. * @param string $classId
  66. *
  67. * @return $this
  68. */
  69. public function setClassId($classId)
  70. {
  71. $this->setData(null);
  72. $this->classId = $classId;
  73. return $this;
  74. }
  75. /**
  76. * @param string $className
  77. *
  78. * @return $this
  79. */
  80. public function setClassName($className)
  81. {
  82. $this->setData(null);
  83. $this->className = $className;
  84. return $this;
  85. }
  86. /**
  87. * @return DataObject\ClassDefinition
  88. */
  89. public function getClass()
  90. {
  91. $class = DataObject\ClassDefinition::getById($this->getClassId());
  92. return $class;
  93. }
  94. /**
  95. * @param string $locale
  96. *
  97. * @return $this
  98. */
  99. public function setLocale($locale)
  100. {
  101. $this->setData(null);
  102. $this->locale = $locale;
  103. return $this;
  104. }
  105. /**
  106. * @return string
  107. */
  108. public function getLocale()
  109. {
  110. return $this->locale;
  111. }
  112. /**
  113. * @param bool $ignoreLocalizedFields
  114. *
  115. * @return $this
  116. */
  117. public function setIgnoreLocalizedFields($ignoreLocalizedFields)
  118. {
  119. $this->setData(null);
  120. $this->ignoreLocalizedFields = $ignoreLocalizedFields;
  121. return $this;
  122. }
  123. /**
  124. * @return bool
  125. */
  126. public function getIgnoreLocalizedFields()
  127. {
  128. return $this->ignoreLocalizedFields;
  129. }
  130. /**
  131. * field collection queries
  132. *
  133. * @var array
  134. */
  135. private $fieldCollectionConfigs = [];
  136. /**
  137. * @param string $type
  138. * @param string|null $fieldname
  139. *
  140. * @throws \Exception
  141. */
  142. public function addFieldCollection($type, $fieldname = null)
  143. {
  144. $this->setData(null);
  145. if (empty($type)) {
  146. throw new \Exception('No fieldcollectiontype given');
  147. }
  148. DataObject\Fieldcollection\Definition::getByKey($type);
  149. $this->fieldCollectionConfigs[] = ['type' => $type, 'fieldname' => $fieldname];
  150. }
  151. /**
  152. * @param array $fieldCollections
  153. *
  154. * @return $this
  155. *
  156. * @throws \Exception
  157. */
  158. public function setFieldCollections($fieldCollections)
  159. {
  160. $this->setData(null);
  161. foreach ($fieldCollections as $fc) {
  162. $this->addFieldCollection($fc['type'], $fc['fieldname']);
  163. }
  164. return $this;
  165. }
  166. /**
  167. * @return array
  168. */
  169. public function getFieldCollections()
  170. {
  171. return $this->fieldCollectionConfigs;
  172. }
  173. /**
  174. * object brick queries
  175. *
  176. * @var array
  177. */
  178. private $objectBrickConfigs = [];
  179. /**
  180. * @param string $type
  181. *
  182. * @throws \Exception
  183. */
  184. public function addObjectbrick($type)
  185. {
  186. $this->setData(null);
  187. if (empty($type)) {
  188. throw new \Exception('No objectbrick given');
  189. }
  190. DataObject\Objectbrick\Definition::getByKey($type);
  191. if (!in_array($type, $this->objectBrickConfigs)) {
  192. $this->objectBrickConfigs[] = $type;
  193. }
  194. }
  195. /**
  196. * @param array $objectbricks
  197. *
  198. * @return $this
  199. *
  200. * @throws \Exception
  201. */
  202. public function setObjectbricks($objectbricks)
  203. {
  204. $this->setData(null);
  205. foreach ($objectbricks as $ob) {
  206. if (!in_array($ob, $this->objectBrickConfigs)) {
  207. $this->addObjectbrick($ob);
  208. }
  209. }
  210. return $this;
  211. }
  212. /**
  213. * @return array
  214. */
  215. public function getObjectbricks()
  216. {
  217. return $this->objectBrickConfigs;
  218. }
  219. /**
  220. * @internal
  221. *
  222. * @return bool
  223. */
  224. public function addDistinct()
  225. {
  226. $fieldCollections = $this->getFieldCollections();
  227. if (!empty($fieldCollections)) {
  228. return true;
  229. }
  230. return false;
  231. }
  232. /**
  233. * Filter by path (system field)
  234. *
  235. * @param string|int|float|array $data comparison data, can be scalar or array (if operator is e.g. "IN (?)")
  236. * @param string $operator SQL comparison operator, e.g. =, <, >= etc. You can use "?" as placeholder, e.g. "IN (?)"
  237. *
  238. * @return static
  239. */
  240. public function filterByPath($data, $operator = '=')
  241. {
  242. $this->addFilterByField('o_path', $operator, $data);
  243. return $this;
  244. }
  245. /**
  246. * Filter by key (system field)
  247. *
  248. * @param string|int|float|array $data comparison data, can be scalar or array (if operator is e.g. "IN (?)")
  249. * @param string $operator SQL comparison operator, e.g. =, <, >= etc. You can use "?" as placeholder, e.g. "IN (?)"
  250. *
  251. * @return static
  252. */
  253. public function filterByKey($data, $operator = '=')
  254. {
  255. $this->addFilterByField('o_key', $operator, $data);
  256. return $this;
  257. }
  258. /**
  259. * Filter by id (system field)
  260. *
  261. * @param string|int|float|array $data comparison data, can be scalar or array (if operator is e.g. "IN (?)")
  262. * @param string $operator SQL comparison operator, e.g. =, <, >= etc. You can use "?" as placeholder, e.g. "IN (?)"
  263. *
  264. * @return static
  265. */
  266. public function filterById($data, $operator = '=')
  267. {
  268. $this->addFilterByField('o_id', $operator, $data);
  269. return $this;
  270. }
  271. /**
  272. * Filter by published (system field)
  273. *
  274. * @param string|int|float|array $data comparison data, can be scalar or array (if operator is e.g. "IN (?)")
  275. * @param string $operator SQL comparison operator, e.g. =, <, >= etc. You can use "?" as placeholder, e.g. "IN (?)"
  276. *
  277. * @return static
  278. */
  279. public function filterByPublished($data, $operator = '=')
  280. {
  281. $this->addFilterByField('o_published', $operator, $data);
  282. return $this;
  283. }
  284. /**
  285. * Filter by creationDate (system field)
  286. *
  287. * @param string|int|float|array $data comparison data, can be scalar or array (if operator is e.g. "IN (?)")
  288. * @param string $operator SQL comparison operator, e.g. =, <, >= etc. You can use "?" as placeholder, e.g. "IN (?)"
  289. *
  290. * @return static
  291. */
  292. public function filterByCreationDate($data, $operator = '=')
  293. {
  294. $this->addFilterByField('o_creationDate', $operator, $data);
  295. return $this;
  296. }
  297. /**
  298. * Filter by modificationDate (system field)
  299. *
  300. * @param string|int|float|array $data comparison data, can be scalar or array (if operator is e.g. "IN (?)")
  301. * @param string $operator SQL comparison operator, e.g. =, <, >= etc. You can use "?" as placeholder, e.g. "IN (?)"
  302. *
  303. * @return static
  304. */
  305. public function filterByModificationDate($data, $operator = '=')
  306. {
  307. $this->addFilterByField('o_modificationDate', $operator, $data);
  308. return $this;
  309. }
  310. }