Bitrix-D7  20.0.0
main/lib/orm/entity.php
См. документацию.
1 <?php
2 /**
3  * Bitrix Framework
4  * @package bitrix
5  * @subpackage main
6  * @copyright 2001-2016 Bitrix
7  */
8 
9 namespace Bitrix\Main\ORM;
10 
11 use Bitrix\Main;
21 
22 /**
23  * Base entity
24  */
25 class Entity
26 {
27  /** @var DataManager */
28  protected $className;
29 
30  protected
37 
38  protected
42 
43  /** @var Field[] */
44  protected $fields;
45 
46  protected $fieldsMap;
47 
48  /** @var UField[] */
49  protected $u_fields;
50 
51  /** @var string Unique code */
52  protected $code;
53 
54  protected $references;
55 
56  /** @var static[] */
57  protected static $instances;
58 
59  /** @var bool */
60  protected $isClone = false;
61 
62  const DEFAULT_OBJECT_PREFIX = 'EO_';
63 
64  /**
65  * Returns entity object
66  *
67  * @param $entityName
68  *
69  * @return Entity
70  * @throws Main\ArgumentException
71  * @throws Main\SystemException
72  */
73  public static function get($entityName)
74  {
75  return static::getInstance($entityName);
76  }
77 
78  /**
79  * Checks if entity exists
80  *
81  * @param $entityName
82  *
83  * @return bool
84  */
85  public static function has($entityName)
86  {
87  $entityClass = static::normalizeEntityClass($entityName);
88  return class_exists($entityClass);
89  }
90 
91  /**
92  * @static
93  *
94  * @param string $entityName
95  *
96  * @return Entity
97  * @throws Main\ArgumentException
98  * @throws Main\SystemException
99  */
100  public static function getInstance($entityName)
101  {
102  $entityName = static::normalizeEntityClass($entityName);
103 
104  return self::getInstanceDirect($entityName);
105  }
106 
107  /**
108  * @param DataManager|string $className
109  *
110  * @return mixed
111  * @throws Main\ArgumentException
112  * @throws Main\SystemException
113  */
114  protected static function getInstanceDirect($className)
115  {
116  if (empty(self::$instances[$className]))
117  {
118  /** @var Entity $entity */
119  $entity = new static;
120  $entity->initialize($className);
121  $entity->postInitialize();
122 
123  // call user-defined postInitialize
124  $className::postInitialize($entity);
125 
126  self::$instances[$className] = $entity;
127  }
128 
129  return self::$instances[$className];
130  }
131 
132  /**
133  * Fields factory
134  *
135  * @param string $fieldName
136  * @param array|Field $fieldInfo
137  *
138  * @return Field
139  * @throws Main\ArgumentException
140  * @throws Main\SystemException
141  */
142  public function initializeField($fieldName, $fieldInfo)
143  {
144  if ($fieldInfo instanceof Field)
145  {
146  $field = $fieldInfo;
147 
148  // rewrite name
149  if (!empty($fieldName) && !is_numeric($fieldName))
150  {
151  $field->setName($fieldName);
152  }
153  }
154  elseif (is_array($fieldInfo))
155  {
156  if (!empty($fieldInfo['reference']))
157  {
158  if (is_string($fieldInfo['data_type']) && strpos($fieldInfo['data_type'], '\\') === false)
159  {
160  // if reference has no namespace, then it'is in the same namespace
161  $fieldInfo['data_type'] = $this->getNamespace().$fieldInfo['data_type'];
162  }
163 
164  //$refEntity = Base::getInstance($fieldInfo['data_type']."Table");
165  $field = new Reference($fieldName, $fieldInfo['data_type'], $fieldInfo['reference'], $fieldInfo);
166  }
167  elseif (!empty($fieldInfo['expression']))
168  {
169  $expression = array_shift($fieldInfo['expression']);
170  $buildFrom = $fieldInfo['expression'];
171 
172  $field = new ExpressionField($fieldName, $expression, $buildFrom, $fieldInfo);
173  }
174  elseif (!empty($fieldInfo['USER_TYPE_ID']))
175  {
176  $field = new UField($fieldInfo);
177  }
178  else
179  {
180  $fieldClass = StringHelper::snake2camel($fieldInfo['data_type']) . 'Field';
181  $fieldClass = '\\Bitrix\\Main\\Entity\\'.$fieldClass;
182 
183  if (strlen($fieldInfo['data_type']) && class_exists($fieldClass))
184  {
185  $field = new $fieldClass($fieldName, $fieldInfo);
186  }
187  elseif (strlen($fieldInfo['data_type']) && class_exists($fieldInfo['data_type']))
188  {
189  $fieldClass = $fieldInfo['data_type'];
190  $field = new $fieldClass($fieldName, $fieldInfo);
191  }
192  else
193  {
194  throw new Main\ArgumentException(sprintf(
195  'Unknown data type "%s" found for `%s` field in %s Entity.',
196  $fieldInfo['data_type'], $fieldName, $this->getName()
197  ));
198  }
199  }
200  }
201  else
202  {
203  throw new Main\ArgumentException(sprintf('Unknown field type `%s`',
204  is_object($fieldInfo) ? get_class($fieldInfo) : gettype($fieldInfo)
205  ));
206  }
207 
208  $field->setEntity($this);
209  $field->postInitialize();
210 
211  return $field;
212  }
213 
214  public function initialize($className)
215  {
216  /** @var $className DataManager */
217  $this->className = $className;
218 
219  /** @var DataManager $className */
220  $this->connectionName = $className::getConnectionName();
221  $this->dbTableName = $className::getTableName();
222  $this->fieldsMap = $className::getMap();
223  $this->uf_id = $className::getUfId();
224  $this->isUts = $className::isUts();
225  $this->isUtm = $className::isUtm();
226 
227  // object & collection classes
228  // Loader::registerObjectClass($className::getObjectClass(), $className);
229  // Loader::registerCollectionClass($className::getCollectionClass(), $className);
230  }
231 
232  /**
233  * @throws Main\ArgumentException
234  * @throws Main\SystemException
235  */
236  public function postInitialize()
237  {
238  // basic properties
239  $classPath = explode('\\', ltrim($this->className, '\\'));
240  $this->name = substr(end($classPath), 0, -5);
241 
242  // default db table name
243  if (is_null($this->dbTableName))
244  {
245  $_classPath = array_slice($classPath, 0, -1);
246 
247  $this->dbTableName = 'b_';
248 
249  foreach ($_classPath as $i => $_pathElem)
250  {
251  if ($i == 0 && $_pathElem == 'Bitrix')
252  {
253  // skip bitrix namespace
254  continue;
255  }
256 
257  if ($i == 1 && $_pathElem == 'Main')
258  {
259  // also skip Main module
260  continue;
261  }
262 
263  $this->dbTableName .= strtolower($_pathElem).'_';
264  }
265 
266  // add class
267  if ($this->name !== end($_classPath))
268  {
269  $this->dbTableName .= StringHelper::camel2snake($this->name);
270  }
271  else
272  {
273  $this->dbTableName = substr($this->dbTableName, 0, -1);
274  }
275  }
276 
277  $this->primary = array();
278  $this->references = array();
279 
280  // attributes
281  foreach ($this->fieldsMap as $fieldName => &$fieldInfo)
282  {
283  $this->addField($fieldInfo, $fieldName);
284  }
285 
286  if (!empty($this->fieldsMap) && empty($this->primary))
287  {
288  throw new Main\SystemException(sprintf('Primary not found for %s Entity', $this->name));
289  }
290 
291  // attach userfields
292  if (empty($this->uf_id))
293  {
294  // try to find ENTITY_ID by map
295  $userTypeManager = Main\Application::getUserTypeManager();
296  if($userTypeManager)
297  {
298  $entityList = $userTypeManager->getEntityList();
299  $ufId = is_array($entityList) ? array_search($this->className, $entityList) : false;
300  if ($ufId !== false)
301  {
302  $this->uf_id = $ufId;
303  }
304  }
305  }
306 
307  if (!empty($this->uf_id))
308  {
309  Main\UserFieldTable::attachFields($this, $this->uf_id);
310  }
311  }
312 
313  /**
314  * Returns class of Object for current entity.
315  *
316  * @return EntityObject|string
317  */
318  public function getObjectClass()
319  {
320  $dataManagerClass = $this->className;
321  return static::normalizeName($dataManagerClass::getObjectClass());
322  }
323 
324  /**
325  * Returns class name of Object for current entity.
326  *
327  * @return EntityObject|string
328  */
329  public function getObjectClassName()
330  {
331  $dataManagerClass = $this->className;
332  return $dataManagerClass::getObjectClassName();
333  }
334 
335  public static function getDefaultObjectClassName($entityName)
336  {
337  $className = $entityName;
338 
339  if (!strlen($className))
340  {
341  // entity without name
342  $className = 'NNM_Object';
343  }
344 
345  $className = static::DEFAULT_OBJECT_PREFIX.$className;
346 
347  return $className;
348  }
349 
350  /**
351  * @return Collection|string
352  */
353  public function getCollectionClass()
354  {
355  $dataClass = $this->getDataClass();
356  return static::normalizeName($dataClass::getCollectionClass());
357  }
358 
359  /**
360  * @return Collection|string
361  */
362  public function getCollectionClassName()
363  {
364  $dataClass = $this->getDataClass();
365  return $dataClass::getCollectionClassName();
366  }
367 
368  public static function getDefaultCollectionClassName($entityName)
369  {
370  $className = static::DEFAULT_OBJECT_PREFIX.$entityName.'_Collection';
371 
372  return $className;
373  }
374 
375  /**
376  * @param bool $setDefaultValues
377  *
378  * @return null Actual type should be annotated by orm:annotate
379  */
380  public function createObject($setDefaultValues = true)
381  {
382  $objectClass = $this->getObjectClass();
383  return new $objectClass($setDefaultValues);
384  }
385 
386  /**
387  * @return null Actual type should be annotated by orm:annotate
388  */
389  public function createCollection()
390  {
391  $collectionClass = $this->getCollectionClass();
392  return new $collectionClass($this);
393  }
394 
395  /**
396  * @see EntityObject::wakeUp()
397  *
398  * @param $row
399  *
400  * @return null Actual type should be annotated by orm:annotate
401  * @throws Main\ArgumentException
402  * @throws Main\SystemException
403  */
404  public function wakeUpObject($row)
405  {
406  $objectClass = $this->getObjectClass();
407  return $objectClass::wakeUp($row);
408  }
409 
410  /**
411  * @see Collection::wakeUp()
412  *
413  * @param $rows
414  *
415  * @return null Actual type should be annotated by orm:annotate
416  * @throws Main\ArgumentException
417  * @throws Main\SystemException
418  */
419  public function wakeUpCollection($rows)
420  {
421  $collectionClass = $this->getCollectionClass();
422  return $collectionClass::wakeUp($rows);
423  }
424 
425  /**
426  * @param Field $field
427  *
428  * @return bool
429  * @throws Main\ArgumentException
430  * @throws Main\SystemException
431  */
432  protected function appendField(Field $field)
433  {
434  if (isset($this->fields[StringHelper::strtoupper($field->getName())]) && !$this->isClone)
435  {
436  trigger_error(sprintf(
437  'Entity `%s` already has Field with name `%s`.', $this->getFullName(), $field->getName()
438  ), E_USER_WARNING);
439 
440  return false;
441  }
442 
443  if ($field instanceof Reference)
444  {
445  // references cache
446  $this->references[$field->getRefEntityName()][] = $field;
447  }
448 
449  $this->fields[StringHelper::strtoupper($field->getName())] = $field;
450 
451  if ($field instanceof ScalarField && $field->isPrimary())
452  {
453  $this->primary[] = $field->getName();
454 
455  if($field->isAutocomplete())
456  {
457  $this->autoIncrement = $field->getName();
458  }
459  }
460 
461  // add reference field for UField iblock_section
462  if ($field instanceof UField && $field->getTypeId() == 'iblock_section')
463  {
464  $refFieldName = $field->getName().'_BY';
465 
466  if ($field->isMultiple())
467  {
468  $localFieldName = $field->getValueFieldName();
469  }
470  else
471  {
472  $localFieldName = $field->getName();
473  }
474 
475  $newFieldInfo = array(
476  'data_type' => 'Bitrix\Iblock\Section',
477  'reference' => array($localFieldName, 'ID')
478  );
479 
480  $newRefField = new Reference($refFieldName, $newFieldInfo['data_type'], $newFieldInfo['reference'][0], $newFieldInfo['reference'][1]);
481  $newRefField->setEntity($this);
482 
483  $this->fields[StringHelper::strtoupper($refFieldName)] = $newRefField;
484  }
485 
486  return true;
487  }
488 
489  /**
490  * @param array|Field $fieldInfo
491  * @param null|string $fieldName
492  *
493  * @return Field|false
494  * @throws Main\ArgumentException
495  * @throws Main\SystemException
496  */
497  public function addField($fieldInfo, $fieldName = null)
498  {
499  $field = $this->initializeField($fieldName, $fieldInfo);
500 
501  return $this->appendField($field) ? $field : false;
502  }
503 
504  public function getReferencesCountTo($refEntityName)
505  {
506  if (array_key_exists($key = strtolower($refEntityName), $this->references))
507  {
508  return count($this->references[$key]);
509  }
510 
511  return 0;
512  }
513 
514 
515  public function getReferencesTo($refEntityName)
516  {
517  if (array_key_exists($key = strtolower($refEntityName), $this->references))
518  {
519  return $this->references[$key];
520  }
521 
522  return array();
523  }
524 
525  // getters
526  public function getFields()
527  {
528  return $this->fields;
529  }
530 
531  /**
532  * @param $name
533  *
534  * @return Field|ScalarField
535  * @throws Main\ArgumentException
536  */
537  public function getField($name)
538  {
539  if ($this->hasField($name))
540  {
541  return $this->fields[StringHelper::strtoupper($name)];
542  }
543 
544  throw new Main\ArgumentException(sprintf(
545  '%s Entity has no `%s` field.', $this->getName(), $name
546  ));
547  }
548 
549  public function hasField($name)
550  {
551  return isset($this->fields[StringHelper::strtoupper($name)]);
552  }
553 
554  /**
555  * @return ScalarField[]
556  */
557  public function getScalarFields()
558  {
559  $scalarFields = array();
560 
561  foreach ($this->getFields() as $field)
562  {
563  if ($field instanceof ScalarField)
564  {
565  $scalarFields[$field->getName()] = $field;
566  }
567  }
568 
569  return $scalarFields;
570  }
571 
572  /**
573  * @deprecated
574  *
575  * @param $name
576  *
577  * @return UField
578  * @throws Main\ArgumentException
579  * @throws Main\SystemException
580  */
581  public function getUField($name)
582  {
583  if ($this->hasUField($name))
584  {
585  return $this->u_fields[$name];
586  }
587 
588  throw new Main\ArgumentException(sprintf(
589  '%s Entity has no `%s` userfield.', $this->getName(), $name
590  ));
591  }
592 
593  /**
594  * @deprecated
595  *
596  * @param $name
597  *
598  * @return bool
599  * @throws Main\SystemException
600  */
601  public function hasUField($name)
602  {
603  if (is_null($this->u_fields))
604  {
605  $this->u_fields = array();
606 
607  if (strlen($this->uf_id))
608  {
609  /** @var \CUserTypeManager $USER_FIELD_MANAGER */
610  global $USER_FIELD_MANAGER;
611 
612  foreach ($USER_FIELD_MANAGER->getUserFields($this->uf_id) as $info)
613  {
614  $this->u_fields[$info['FIELD_NAME']] = new UField($info);
615  $this->u_fields[$info['FIELD_NAME']]->setEntity($this);
616 
617  // add references for ufield (UF_DEPARTMENT_BY)
618  if ($info['USER_TYPE_ID'] == 'iblock_section')
619  {
620  $info['FIELD_NAME'] .= '_BY';
621  $this->u_fields[$info['FIELD_NAME']] = new UField($info);
622  $this->u_fields[$info['FIELD_NAME']]->setEntity($this);
623  }
624  }
625  }
626  }
627 
628  return isset($this->u_fields[$name]);
629  }
630 
631  public function getName()
632  {
633  return $this->name;
634  }
635 
636  public function getFullName()
637  {
638  return substr($this->className, 0, -5);
639  }
640 
641  public function getNamespace()
642  {
643  return substr($this->className, 0, strrpos($this->className, '\\')+1);
644  }
645 
646  public function getModule()
647  {
648  if($this->module === null)
649  {
650  // \Bitrix\Main\Site -> "main"
651  // \Partner\Module\Thing -> "partner.module"
652  // \Thing -> ""
653  $parts = explode("\\", $this->className);
654  if($parts[1] == "Bitrix")
655  $this->module = strtolower($parts[2]);
656  elseif(!empty($parts[1]) && isset($parts[2]))
657  $this->module = strtolower($parts[1].".".$parts[2]);
658  else
659  $this->module = "";
660  }
661  return $this->module;
662  }
663 
664  /**
665  * @return DataManager
666  */
667  public function getDataClass()
668  {
669  return $this->className;
670  }
671 
672  /**
673  * @return Main\DB\Connection
674  * @throws Main\SystemException
675  */
676  public function getConnection()
677  {
678  /** @var Main\DB\Connection $conn */
679  $conn = Main\Application::getInstance()->getConnectionPool()->getConnection($this->connectionName);
680  return $conn;
681  }
682 
683  public function getDBTableName()
684  {
685  return $this->dbTableName;
686  }
687 
688  public function getPrimary()
689  {
690  return count($this->primary) == 1 ? $this->primary[0] : $this->primary;
691  }
692 
693  public function getPrimaryArray()
694  {
695  return $this->primary;
696  }
697 
698  public function getAutoIncrement()
699  {
700  return $this->autoIncrement;
701  }
702 
703  public function isUts()
704  {
705  return $this->isUts;
706  }
707 
708  public function isUtm()
709  {
710  return $this->isUtm;
711  }
712 
713  public function getUfId()
714  {
715  return $this->uf_id;
716  }
717 
718  /**
719  * @param Query $query
720  *
721  * @return Query
722  */
723  public function setDefaultScope($query)
724  {
725  $dataClass = $this->className;
726  return $dataClass::setDefaultScope($query);
727  }
728 
729  public static function isExists($name)
730  {
731  return class_exists(static::normalizeEntityClass($name));
732  }
733 
734  /**
735  * @param $entityName
736  *
737  * @return string|DataManager
738  */
739  public static function normalizeEntityClass($entityName)
740  {
741  if (strtolower(substr($entityName, -5)) !== 'table')
742  {
743  $entityName .= 'Table';
744  }
745 
746  if (substr($entityName, 0, 1) !== '\\')
747  {
748  $entityName = '\\'.$entityName;
749  }
750 
751  return $entityName;
752  }
753 
754  public static function getEntityClassParts($class)
755  {
756  $class = static::normalizeEntityClass($class);
757  $lastPos = strrpos($class, '\\');
758 
759  if($lastPos === 0)
760  {
761  //global namespace
762  $namespace = "";
763  }
764  else
765  {
766  $namespace = substr($class, 1, $lastPos-1);
767  }
768  $name = substr($class, $lastPos+1, -5);
769 
770  return compact('namespace', 'name');
771  }
772 
773  public function getCode()
774  {
775  if ($this->code === null)
776  {
777  $this->code = '';
778 
779  // get absolute path to class
780  $class_path = explode('\\', strtoupper(ltrim($this->className, '\\')));
781 
782  // cut class name to leave namespace only
783  $class_path = array_slice($class_path, 0, -1);
784 
785  // cut Bitrix namespace
786  if ($class_path[0] === 'BITRIX')
787  {
788  $class_path = array_slice($class_path, 1);
789  }
790 
791  // glue module name
792  if (count($class_path))
793  {
794  $this->code = join('_', $class_path).'_';
795  }
796 
797  // glue entity name
798  $this->code .= strtoupper(StringHelper::camel2snake($this->getName()));
799  }
800 
801  return $this->code;
802  }
803 
804  public function getLangCode()
805  {
806  return $this->getCode().'_ENTITY';
807  }
808 
809  public function getTitle()
810  {
811  $dataClass = $this->getDataClass();
812  $title = $dataClass::getTitle();
813 
814  if ($title === null)
815  {
817  }
818 
819  return $title;
820  }
821 
822  /**
823  * @deprecated Use Bitrix\StringHelper::camel2snake instead
824  *
825  * @param $str
826  *
827  * @return string
828  */
829  public static function camel2snake($str)
830  {
831  return StringHelper::camel2snake($str);
832  }
833 
834  /**
835  * @deprecated Use Bitrix\StringHelper::snake2camel instead
836  *
837  * @param $str
838  *
839  * @return mixed
840  */
841  public static function snake2camel($str)
842  {
843  return StringHelper::snake2camel($str);
844  }
845 
846  public static function normalizeName($entityName)
847  {
848  if (substr($entityName, 0, 1) !== '\\')
849  {
850  $entityName = '\\'.$entityName;
851  }
852 
853  if (strtolower(substr($entityName, -5)) === 'table')
854  {
855  $entityName = substr($entityName, 0, -5);
856  }
857 
858  return $entityName;
859  }
860 
861  public function __clone()
862  {
863  $this->isClone = true;
864  }
865 
866  /**
867  * @param Query $query
868  * @param null $entity_name
869  *
870  * @return Entity
871  * @throws Main\ArgumentException
872  * @throws Main\SystemException
873  */
874  public static function getInstanceByQuery(Query $query, &$entity_name = null)
875  {
876  if ($entity_name === null)
877  {
878  $entity_name = 'Tmp'.randString();
879  }
880  elseif (!preg_match('/^[a-z0-9_]+$/i', $entity_name))
881  {
882  throw new Main\ArgumentException(sprintf(
883  'Invalid entity name `%s`.', $entity_name
884  ));
885  }
886 
887  $query_string = '('.$query->getQuery().')';
888  $query_chains = $query->getChains();
889 
890  $replaced_aliases = array_flip($query->getReplacedAliases());
891 
892  // generate fieldsMap
893  $fieldsMap = array();
894 
895  foreach ($query->getSelect() as $k => $v)
896  {
897  // convert expressions to regular field, clone in case of regular scalar field
898  if (is_array($v))
899  {
900  // expression
901  $fieldsMap[$k] = array('data_type' => $v['data_type']);
902  }
903  else
904  {
905  if ($v instanceof ExpressionField)
906  {
907  $fieldDefinition = $v->getName();
908 
909  // better to initialize fields as objects after entity is created
910  $dataType = Field::getOldDataTypeByField($query_chains[$fieldDefinition]->getLastElement()->getValue());
911  $fieldsMap[$fieldDefinition] = array('data_type' => $dataType);
912  }
913  else
914  {
915  $fieldDefinition = is_numeric($k) ? $v : $k;
916 
917  /** @var Field $field */
918  $field = $query_chains[$fieldDefinition]->getLastElement()->getValue();
919 
920  if ($field instanceof ExpressionField)
921  {
922  $dataType = Field::getOldDataTypeByField($query_chains[$fieldDefinition]->getLastElement()->getValue());
923  $fieldsMap[$fieldDefinition] = array('data_type' => $dataType);
924  }
925  else
926  {
927  /** @var ScalarField[] $fieldsMap */
928  $fieldsMap[$fieldDefinition] = clone $field;
929  $fieldsMap[$fieldDefinition]->setName($fieldDefinition);
930  $fieldsMap[$fieldDefinition]->setColumnName($fieldDefinition);
931  $fieldsMap[$fieldDefinition]->resetEntity();
932  }
933  }
934  }
935 
936  if (isset($replaced_aliases[$k]))
937  {
938  if (is_array($fieldsMap[$k]))
939  {
940  $fieldsMap[$k]['column_name'] = $replaced_aliases[$k];
941  }
942  elseif ($fieldsMap[$k] instanceof ScalarField)
943  {
944  /** @var ScalarField[] $fieldsMap */
945  $fieldsMap[$k]->setColumnName($replaced_aliases[$k]);
946  }
947  }
948  }
949 
950  // generate class content
951  $eval = 'class '.$entity_name.'Table extends '.DataManager::class.' {'.PHP_EOL;
952  $eval .= 'public static function getMap() {'.PHP_EOL;
953  $eval .= 'return '.var_export(array('TMP_ID' => array('data_type' => 'integer', 'primary' => true)), true).';'.PHP_EOL;
954  $eval .= '}';
955  $eval .= 'public static function getTableName() {'.PHP_EOL;
956  $eval .= 'return '.var_export($query_string, true).';'.PHP_EOL;
957  $eval .= '}';
958  $eval .= '}';
959 
960  eval($eval);
961 
962  $entity = self::getInstance($entity_name);
963 
964  foreach ($fieldsMap as $k => $v)
965  {
966  $entity->addField($v, $k);
967  }
968 
969  return $entity;
970  }
971 
972  /**
973  * @param string $entityName
974  * @param null|array[]|Field[] $fields
975  * @param array $parameters [namespace, table_name, uf_id, parent, parent_map, default_scope]
976  *
977  * @return Entity
978  *
979  * @throws Main\ArgumentException
980  * @throws Main\SystemException
981  */
982  public static function compileEntity($entityName, $fields = null, $parameters = array())
983  {
984  $classCode = '';
985  $classCodeEnd = '';
986 
987  if (strtolower(substr($entityName, -5)) !== 'table')
988  {
989  $entityName .= 'Table';
990  }
991 
992  // validation
993  if (!preg_match('/^[a-z0-9_]+$/i', $entityName))
994  {
995  throw new Main\ArgumentException(sprintf(
996  'Invalid entity className `%s`.', $entityName
997  ));
998  }
999 
1000  /** @var DataManager $fullEntityName */
1001  $fullEntityName = $entityName;
1002 
1003  // namespace configuration
1004  if (!empty($parameters['namespace']) && $parameters['namespace'] !== '\\')
1005  {
1006  $namespace = $parameters['namespace'];
1007 
1008  if (!preg_match('/^[a-z0-9\\\\]+$/i', $namespace))
1009  {
1010  throw new Main\ArgumentException(sprintf(
1011  'Invalid namespace name `%s`', $namespace
1012  ));
1013  }
1014 
1015  $classCode = $classCode."namespace {$namespace} "."{";
1016  $classCodeEnd = '}'.$classCodeEnd;
1017 
1018  $fullEntityName = '\\'.$namespace.'\\'.$fullEntityName;
1019  }
1020 
1021  $parentClass = !empty($parameters['parent']) ? $parameters['parent'] : DataManager::class;
1022 
1023  // build entity code
1024  $classCode = $classCode."class {$entityName} extends \\".$parentClass." {";
1025  $classCodeEnd = '}'.$classCodeEnd;
1026 
1027  if (!empty($parameters['table_name']))
1028  {
1029  $classCode .= 'public static function getTableName(){return '.var_export($parameters['table_name'], true).';}';
1030  }
1031 
1032  if (!empty($parameters['uf_id']))
1033  {
1034  $classCode .= 'public static function getUfId(){return '.var_export($parameters['uf_id'], true).';}';
1035  }
1036 
1037  if (!empty($parameters['default_scope']))
1038  {
1039  $classCode .= 'public static function setDefaultScope($query){'.$parameters['default_scope'].'}';
1040  }
1041 
1042  if (isset($parameters['parent_map']) && $parameters['parent_map'] == false)
1043  {
1044  $classCode .= 'public static function getMap(){return [];}';
1045  }
1046 
1047  if(isset($parameters['object_parent']) && is_a($parameters['object_parent'], EntityObject::class, true))
1048  {
1049  $classCode .= 'public static function getObjectParentClass(){return '.var_export($parameters['object_parent'], true).';}';
1050  }
1051 
1052  // create entity
1053  eval($classCode.$classCodeEnd);
1054 
1055  $entity = $fullEntityName::getEntity();
1056 
1057  // add fields
1058  if (!empty($fields))
1059  {
1060  foreach ($fields as $fieldName => $field)
1061  {
1062  $entity->addField($field, $fieldName);
1063  }
1064  }
1065 
1066  return $entity;
1067  }
1068 
1069  /**
1070  * @return string[] Array of SQL queries
1071  * @throws Main\SystemException
1072  */
1074  {
1075  $fields = $this->getScalarFields();
1076 
1077  /** @var Main\DB\MysqlCommonConnection $connection */
1078  $connection = $this->getConnection();
1079 
1080  $autocomplete = [];
1081  $unique = [];
1082 
1083  foreach ($fields as $field)
1084  {
1085  if ($field->isAutocomplete())
1086  {
1087  $autocomplete[] = $field->getName();
1088  }
1089 
1090  if ($field->isUnique())
1091  {
1092  $unique[] = $field->getName();
1093  }
1094  }
1095 
1096  // start collecting queries
1097  $connection->disableQueryExecuting();
1098 
1099  // create table
1100  $connection->createTable($this->getDBTableName(), $fields, $this->getPrimaryArray(), $autocomplete);
1101 
1102  // create indexes
1103  foreach ($unique as $fieldName)
1104  {
1105  $connection->createIndex($this->getDBTableName(), $fieldName, [$fieldName], null,
1106  Main\DB\MysqlCommonConnection::INDEX_UNIQUE);
1107  }
1108 
1109  // stop collecting queries
1110  $connection->enableQueryExecuting();
1111 
1112  return $connection->getDisabledQueryExecutingDump();
1113  }
1114 
1115  /**
1116  * @param $dataClass
1117  *
1118  * @return EntityObject|string
1119  */
1120  public static function compileObjectClass($dataClass)
1121  {
1122  $dataClass = static::normalizeEntityClass($dataClass);
1123  $classParts = static::getEntityClassParts($dataClass);
1124 
1125  if (class_exists($dataClass::getObjectClass(), false)
1126  && is_subclass_of($dataClass::getObjectClass(), EntityObject::class))
1127  {
1128  // class is already defined
1129  return $dataClass::getObjectClass();
1130  }
1131 
1132  $baseObjectClass = '\\'.$dataClass::getObjectParentClass();
1133  $objectClassName = static::getDefaultObjectClassName($classParts['name']);
1134 
1135  $eval = "";
1136  if($classParts['namespace'] <> '')
1137  {
1138  $eval .= "namespace {$classParts['namespace']} {";
1139  }
1140  $eval .= "class {$objectClassName} extends {$baseObjectClass} {";
1141  $eval .= "static public \$dataClass = '{$dataClass}';";
1142  $eval .= "}"; // end class
1143  if($classParts['namespace'] <> '')
1144  {
1145  $eval .= "}"; // end namespace
1146  }
1147 
1148  eval($eval);
1149 
1150  return $dataClass::getObjectClass();
1151  }
1152 
1153  /**
1154  * @param $dataClass
1155  *
1156  * @return Collection|string
1157  */
1158  public static function compileCollectionClass($dataClass)
1159  {
1160  $dataClass = static::normalizeEntityClass($dataClass);
1161  $classParts = static::getEntityClassParts($dataClass);
1162 
1163  if (class_exists($dataClass::getCollectionClass(), false)
1164  && is_subclass_of($dataClass::getCollectionClass(), Collection::class))
1165  {
1166  // class is already defined
1167  return $dataClass::getCollectionClass();
1168  }
1169 
1170  $baseCollectionClass = '\\'.$dataClass::getCollectionParentClass();
1171  $collectionClassName = static::getDefaultCollectionClassName($classParts['name']);
1172 
1173  $eval = "";
1174  if($classParts['namespace'] <> '')
1175  {
1176  $eval .= "namespace {$classParts['namespace']} {";
1177  }
1178  $eval .= "class {$collectionClassName} extends {$baseCollectionClass} {";
1179  $eval .= "static public \$dataClass = '{$dataClass}';";
1180  $eval .= "}"; // end class
1181  if($classParts['namespace'] <> '')
1182  {
1183  $eval .= "}"; // end namespace
1184  }
1185 
1186  eval($eval);
1187 
1188  return $dataClass::getCollectionClass();
1189  }
1190 
1191  /**
1192  * Creates table according to Fields collection
1193  *
1194  * @return void
1195  * @throws Main\SystemException
1196  */
1197  public function createDbTable()
1198  {
1199  foreach ($this->compileDbTableStructureDump() as $sqlQuery)
1200  {
1201  $this->getConnection()->query($sqlQuery);
1202  }
1203  }
1204 
1205  /**
1206  * @param Entity|string $entity
1207  *
1208  * @return bool
1209  */
1210  public static function destroy($entity)
1211  {
1212  if ($entity instanceof Entity)
1213  {
1214  $entityName = $entity->getDataClass();
1215  }
1216  else
1217  {
1218  $entityName = static::normalizeEntityClass($entity);
1219  }
1220 
1221  if (isset(self::$instances[$entityName]))
1222  {
1223  unset(self::$instances[$entityName]);
1224  DataManager::unsetEntity($entityName);
1225 
1226  return true;
1227  }
1228 
1229  return false;
1230  }
1231 
1232  /**
1233  * Reads data from cache.
1234  *
1235  * @param int $ttl TTL.
1236  * @param string $cacheId The cache ID.
1237  * @param bool $countTotal Whether to read total count from the cache.
1238  *
1239  * @return Main\DB\ArrayResult|null
1240  * @throws Main\SystemException
1241  */
1242  public function readFromCache($ttl, $cacheId, $countTotal = false)
1243  {
1244  if($ttl > 0)
1245  {
1246  $cache = Main\Application::getInstance()->getManagedCache();
1247  $cacheDir = $this->getCacheDir();
1248 
1249  $count = null;
1250  if($countTotal && $cache->read($ttl, $cacheId.".total", $cacheDir))
1251  {
1252  $count = $cache->get($cacheId.".total");
1253  }
1254  if($cache->read($ttl, $cacheId, $cacheDir))
1255  {
1256  $result = new Main\DB\ArrayResult($cache->get($cacheId));
1257  if($count !== null)
1258  {
1259  $result->setCount($count);
1260  }
1261  return $result;
1262  }
1263  }
1264  return null;
1265  }
1266 
1267  /**
1268  * @param Main\DB\Result $result A query result to cache.
1269  * @param string $cacheId The cache ID.
1270  * @param bool $countTotal Whether to write total count to the cache.
1271  *
1272  * @return Main\DB\ArrayResult
1273  * @throws Main\ObjectPropertyException
1274  * @throws Main\SystemException
1275  */
1276  public function writeToCache(Main\DB\Result $result, $cacheId, $countTotal = false)
1277  {
1278  $rows = $result->fetchAll();
1279  $arrayResult = new Main\DB\ArrayResult($rows);
1280 
1281  $cache = Main\Application::getInstance()->getManagedCache();
1282  $cache->set($cacheId, $rows);
1283 
1284  if($countTotal)
1285  {
1286  $count = $result->getCount();
1287  $cache->set($cacheId.".total", $count);
1288  $arrayResult->setCount($count);
1289  }
1290  return $arrayResult;
1291  }
1292 
1293  /**
1294  * Returns cache TTL for the entity, possibly limited by the .settings.php:
1295  * 'cache_flags' => array('value'=> array(
1296  * "b_group_max_ttl" => 200,
1297  * "b_group_min_ttl" => 100,
1298  * ))
1299  * Maximum is a higher-priority.
1300  * @param int $ttl Preferable TTL
1301  * @return int Calculated TTL
1302  */
1303  public function getCacheTtl($ttl)
1304  {
1305  $table = $this->getDBTableName();
1306  $cacheFlags = Main\Config\Configuration::getValue("cache_flags");
1307  if(isset($cacheFlags[$table."_min_ttl"]))
1308  {
1309  $ttl = (int)max($ttl, $cacheFlags[$table."_min_ttl"]);
1310  }
1311  if(isset($cacheFlags[$table."_max_ttl"]))
1312  {
1313  $ttl = (int)min($ttl, $cacheFlags[$table."_max_ttl"]);
1314  }
1315  return $ttl;
1316  }
1317 
1318  protected function getCacheDir()
1319  {
1320  return "orm_".$this->getDBTableName();
1321  }
1322 
1323  /**
1324  * Cleans all cache entries for the entity.
1325  *
1326  * @throws Main\SystemException
1327  */
1328  public function cleanCache()
1329  {
1330  $cache = Main\Application::getInstance()->getManagedCache();
1331  $cache->cleanDir($this->getCacheDir());
1332  }
1333 
1334  /**
1335  * Sets a flag indicating full text index support for a field.
1336  *
1337  * @param string $field
1338  * @param bool $mode
1339  *
1340  * @throws Main\ArgumentNullException
1341  * @throws Main\ArgumentOutOfRangeException
1342  */
1343  public function enableFullTextIndex($field, $mode = true)
1344  {
1345  $table = $this->getDBTableName();
1346  $options = array();
1347  $optionString = Main\Config\Option::get("main", "~ft_".$table);
1348  if($optionString <> '')
1349  {
1350  $options = unserialize($optionString);
1351  }
1352  $options[StringHelper::strtoupper($field)] = $mode;
1353  Main\Config\Option::set("main", "~ft_".$table, serialize($options));
1354  }
1355 
1356  /**
1357  * Returns true if full text index is enabled for a field.
1358  *
1359  * @param string $field
1360  *
1361  * @return bool
1362  * @throws Main\ArgumentNullException
1363  * @throws Main\ArgumentOutOfRangeException
1364  */
1365  public function fullTextIndexEnabled($field)
1366  {
1367  $table = $this->getDBTableName();
1368  $optionString = Main\Config\Option::get("main", "~ft_".$table);
1369  if($optionString <> '')
1370  {
1371  $field = StringHelper::strtoupper($field);
1372  $options = unserialize($optionString);
1373  if(isset($options[$field]) && $options[$field] === true)
1374  {
1375  return true;
1376  }
1377  }
1378  return false;
1379  }
1380 }
Bitrix\Main\Localization\Loc\getMessage
static getMessage($code, $replace=null, $language=null)
Returns translation by message code.
Definition: loc.php:29
Bitrix\Main\ORM\Entity\getFullName
getFullName()
Definition: main/lib/orm/entity.php:636
Bitrix\Main\ORM\Entity\getObjectClassName
getObjectClassName()
Returns class name of Object for current entity.
Definition: main/lib/orm/entity.php:329
Bitrix\Main\ORM\Entity\getCollectionClass
getCollectionClass()
Definition: main/lib/orm/entity.php:353
Bitrix\Forum\Internals\getInstance
static getInstance($object)
Definition: forum/lib/internals/entityfabric.php:43
Bitrix\Main\ORM\Entity\getModule
getModule()
Definition: main/lib/orm/entity.php:646
Bitrix\Main\ORM\Entity\destroy
static destroy($entity)
Definition: main/lib/orm/entity.php:1210
Bitrix\Main\ORM\Entity\wakeUpObject
wakeUpObject($row)
Definition: main/lib/orm/entity.php:404
Bitrix\Main\ORM\Data\DataManager
Base entity data manager.
Definition: main/lib/orm/data/datamanager.php:32
Bitrix\Main\Text\StringHelper
Definition: stringhelper.php:16
Bitrix\Main\ORM\Entity\$className
$className
Definition: main/lib/orm/entity.php:28
Bitrix\Main\ORM\Entity\compileCollectionClass
static compileCollectionClass($dataClass)
Definition: main/lib/orm/entity.php:1158
Bitrix\Main\ORM
Bitrix\Main\ORM\Fields\Relations\Reference
Definition: reference.php:25
Bitrix\Main\ORM\Entity\getScalarFields
getScalarFields()
Definition: main/lib/orm/entity.php:557
Bitrix\Main\ORM\Entity\wakeUpCollection
wakeUpCollection($rows)
Definition: main/lib/orm/entity.php:419
Bitrix\Main\ORM\Entity\$module
$module
Definition: main/lib/orm/entity.php:31
Bitrix\Main\ORM\Entity\getConnection
getConnection()
Definition: main/lib/orm/entity.php:676
Bitrix\Main\ORM\Entity\initializeField
initializeField($fieldName, $fieldInfo)
Fields factory.
Definition: main/lib/orm/entity.php:142
Bitrix\Main\ORM\Entity\createCollection
createCollection()
Definition: main/lib/orm/entity.php:389
Bitrix\Main\ORM\Entity\$fields
$fields
Definition: main/lib/orm/entity.php:44
Bitrix\Main\Application\getUserTypeManager
static getUserTypeManager()
Returns UF manager.
Definition: main/lib/application.php:432
Bitrix\Main
Bitrix\Main\ORM\Entity\$primary
$primary
Definition: main/lib/orm/entity.php:35
Bitrix\Main\ORM\Entity\compileDbTableStructureDump
compileDbTableStructureDump()
Definition: main/lib/orm/entity.php:1073
Bitrix\Main\ORM\Entity\hasUField
hasUField($name)
Definition: main/lib/orm/entity.php:601
Bitrix\Main\ORM\Entity\getNamespace
getNamespace()
Definition: main/lib/orm/entity.php:641
Bitrix\Main\ORM\Entity\$fieldsMap
$fieldsMap
Definition: main/lib/orm/entity.php:46
Bitrix\Main\Config\Option\set
static set($moduleId, $name, $value="", $siteId="")
Sets an option value and saves it into a DB.
Definition: main/lib/config/option.php:238
Bitrix\Main\ORM\Entity\getReferencesCountTo
getReferencesCountTo($refEntityName)
Definition: main/lib/orm/entity.php:504
Bitrix\Main\ORM\Objectify\EntityObject
Definition: entityobject.php:47
Bitrix\Main\ORM\Entity\getEntityClassParts
static getEntityClassParts($class)
Definition: main/lib/orm/entity.php:754
Bitrix\Main\ORM\Objectify\Collection
Definition: main/lib/orm/objectify/collection.php:32
Bitrix\Main\Text\StringHelper\camel2snake
static camel2snake($str)
Changes registry from CamelCase to snake_case.
Definition: stringhelper.php:44
Bitrix\Main\ORM\Query\Query\getSelect
getSelect()
Returns an array of fields for SELECT clause.
Definition: main/lib/orm/query/query.php:285
Bitrix\Main\ORM\Entity\getInstance
static getInstance($entityName)
Definition: main/lib/orm/entity.php:100
Bitrix\Main\ORM\Entity\getCacheTtl
getCacheTtl($ttl)
Returns cache TTL for the entity, possibly limited by the .settings.php: 'cache_flags' => array('valu...
Definition: main/lib/orm/entity.php:1303
Bitrix\Main\ORM\Entity\isUtm
isUtm()
Definition: main/lib/orm/entity.php:708
Bitrix\Main\ORM\Fields\ScalarField
Definition: scalarfield.php:18
Bitrix\Main\ORM\Entity\getReferencesTo
getReferencesTo($refEntityName)
Definition: main/lib/orm/entity.php:515
Bitrix\Main\ORM\Entity\getField
getField($name)
Definition: main/lib/orm/entity.php:537
Bitrix\Main\Config\Option\get
static get($moduleId, $name, $default="", $siteId=false)
Returns a value of an option.
Definition: main/lib/config/option.php:29
Bitrix\Main\ORM\Entity\getDefaultCollectionClassName
static getDefaultCollectionClassName($entityName)
Definition: main/lib/orm/entity.php:368
Bitrix\Main\ORM\Entity\$uf_id
$uf_id
Definition: main/lib/orm/entity.php:39
Bitrix\Main\ORM\Fields\ExpressionField
Definition: expressionfield.php:23
Bitrix\Main\ORM\Entity\getLangCode
getLangCode()
Definition: main/lib/orm/entity.php:804
Bitrix\Main\ORM\Entity\$references
$references
Definition: main/lib/orm/entity.php:54
Bitrix\Main\ORM\Entity\DEFAULT_OBJECT_PREFIX
const DEFAULT_OBJECT_PREFIX
Definition: main/lib/orm/entity.php:62
Bitrix\Main\ORM\Entity\getInstanceByQuery
static getInstanceByQuery(Query $query, &$entity_name=null)
Definition: main/lib/orm/entity.php:874
Bitrix\Main\ORM\Entity
Base entity.
Definition: main/lib/orm/entity.php:25
Bitrix\Main\ORM\Entity\getTitle
getTitle()
Definition: main/lib/orm/entity.php:809
Bitrix\Main\ORM\Entity\writeToCache
writeToCache(Main\DB\Result $result, $cacheId, $countTotal=false)
Definition: main/lib/orm/entity.php:1276
Bitrix\Main\ORM\Entity\getName
getName()
Definition: main/lib/orm/entity.php:631
Bitrix\Main\ArgumentException
Exception is thrown when function argument is not valid.
Definition: main/lib/exception.php:33
Bitrix\Main\ORM\Entity\snake2camel
static snake2camel($str)
Definition: main/lib/orm/entity.php:841
Bitrix\Main\ORM\Entity\__clone
__clone()
Definition: main/lib/orm/entity.php:861
Bitrix\Main\ORM\Entity\fullTextIndexEnabled
fullTextIndexEnabled($field)
Returns true if full text index is enabled for a field.
Definition: main/lib/orm/entity.php:1365
Bitrix\Main\ORM\Entity\compileObjectClass
static compileObjectClass($dataClass)
Definition: main/lib/orm/entity.php:1120
Bitrix\Main\ORM\Entity\compileEntity
static compileEntity($entityName, $fields=null, $parameters=array())
Definition: main/lib/orm/entity.php:982
Bitrix\Main\ORM\Entity\isUts
isUts()
Definition: main/lib/orm/entity.php:703
Bitrix\Main\ORM\Query\Query
Definition: main/lib/orm/query/query.php:112
Bitrix\Main\SystemException
Base class for fatal exceptions.
Definition: main/lib/exception.php:7
Bitrix\Main\ORM\Entity\getAutoIncrement
getAutoIncrement()
Definition: main/lib/orm/entity.php:698
Bitrix\Main\ORM\Entity\$instances
static $instances
Definition: main/lib/orm/entity.php:57
Bitrix\Main\Text\StringHelper\strtoupper
static strtoupper($str)
Regular uppercase with result cache.
Definition: stringhelper.php:25
Bitrix\Main\ORM\Entity\normalizeEntityClass
static normalizeEntityClass($entityName)
Definition: main/lib/orm/entity.php:739
Bitrix\Main\ORM\Entity\getObjectClass
getObjectClass()
Returns class of Object for current entity.
Definition: main/lib/orm/entity.php:318
Bitrix\Main\ORM\Fields\Field\getOldDataTypeByField
static getOldDataTypeByField(Field $field)
Definition: main/lib/orm/fields/field.php:591
Bitrix\Main\ORM\Entity\getPrimary
getPrimary()
Definition: main/lib/orm/entity.php:688
Bitrix\Main\UserFieldTable\attachFields
static attachFields(ORM\Entity $entity, $ufId)
Definition: userfield.php:119
Bitrix\Main\ORM\Fields\Field
Definition: main/lib/orm/fields/field.php:24
Bitrix\Main\ORM\Entity\$code
$code
Definition: main/lib/orm/entity.php:52
Bitrix\Main\ORM\Entity\$isUtm
$isUtm
Definition: main/lib/orm/entity.php:41
Bitrix\Main\Application\getInstance
static getInstance()
Returns current instance of the Application.
Definition: main/lib/application.php:86
Bitrix\Main\ORM\Entity\cleanCache
cleanCache()
Cleans all cache entries for the entity.
Definition: main/lib/orm/entity.php:1328
Bitrix\Main\ORM\Entity\getCacheDir
getCacheDir()
Definition: main/lib/orm/entity.php:1318
Bitrix\Main\ORM\Entity\$u_fields
$u_fields
Definition: main/lib/orm/entity.php:49
Bitrix\Main\ORM\Entity\getInstanceDirect
static getInstanceDirect($className)
Definition: main/lib/orm/entity.php:114
Bitrix\Main\DB\ArrayResult
Definition: arrayresult.php:9
Bitrix\Main\ORM\Query\Query\getReplacedAliases
getReplacedAliases()
Definition: main/lib/orm/query/query.php:3530
Bitrix\Main\ORM\Entity\getDataClass
getDataClass()
Definition: main/lib/orm/entity.php:667
Bitrix\Main\ORM\Entity\$isUts
$isUts
Definition: main/lib/orm/entity.php:40
Bitrix\Main\ORM\Entity\appendField
appendField(Field $field)
Definition: main/lib/orm/entity.php:432
Bitrix\Main\ORM\Entity\getPrimaryArray
getPrimaryArray()
Definition: main/lib/orm/entity.php:693
Bitrix\Main\ORM\Fields\Field\getName
getName()
Definition: main/lib/orm/fields/field.php:487
Bitrix\Main\ORM\Query\Query\getChains
getChains()
Definition: main/lib/orm/query/query.php:3359
Bitrix\Main\ORM\Entity\getCode
getCode()
Definition: main/lib/orm/entity.php:773
Bitrix\Main\ORM\Entity\getCollectionClassName
getCollectionClassName()
Definition: main/lib/orm/entity.php:362
Bitrix\Main\ORM\Entity\hasField
hasField($name)
Definition: main/lib/orm/entity.php:549
Bitrix\Main\ORM\Entity\normalizeName
static normalizeName($entityName)
Definition: main/lib/orm/entity.php:846
Bitrix\Main\ORM\Entity\getUfId
getUfId()
Definition: main/lib/orm/entity.php:713
Bitrix\Main\ORM\Entity\camel2snake
static camel2snake($str)
Definition: main/lib/orm/entity.php:829
Bitrix\Main\ORM\Entity\getFields
getFields()
Definition: main/lib/orm/entity.php:526
Bitrix\Main\ORM\Entity\setDefaultScope
setDefaultScope($query)
Definition: main/lib/orm/entity.php:723
Bitrix\Main\ORM\Data\Result
Definition: main/lib/orm/data/result.php:15
Bitrix\Main\ORM\Entity\has
static has($entityName)
Checks if entity exists.
Definition: main/lib/orm/entity.php:85
Bitrix\Main\ORM\Entity\getDBTableName
getDBTableName()
Definition: main/lib/orm/entity.php:683
Bitrix\Main\ORM\Entity\$dbTableName
$dbTableName
Definition: main/lib/orm/entity.php:34
Bitrix\Main\ORM\Entity\$autoIncrement
$autoIncrement
Definition: main/lib/orm/entity.php:36
Bitrix\Sender\Connector\getTitle
getTitle()
Get filter.
Definition: resultview.php:80
Bitrix\Main\ORM\Entity\createObject
createObject($setDefaultValues=true)
Definition: main/lib/orm/entity.php:380
Bitrix\Main\ORM\Entity\createDbTable
createDbTable()
Creates table according to Fields collection.
Definition: main/lib/orm/entity.php:1197
Bitrix\Main\ORM\Data\DataManager\unsetEntity
static unsetEntity($class)
Definition: main/lib/orm/data/datamanager.php:87
Bitrix\Main\ORM\Entity\initialize
initialize($className)
Definition: main/lib/orm/entity.php:214
Bitrix\Main\ORM\Entity\postInitialize
postInitialize()
Definition: main/lib/orm/entity.php:236
Bitrix\Main\ORM\Entity\getDefaultObjectClassName
static getDefaultObjectClassName($entityName)
Definition: main/lib/orm/entity.php:335
Bitrix\Main\ORM\Entity\$connectionName
$connectionName
Definition: main/lib/orm/entity.php:33
Bitrix\Main\ORM\Entity\isExists
static isExists($name)
Definition: main/lib/orm/entity.php:729
Bitrix\Main\ORM\Entity\$name
$name
Definition: main/lib/orm/entity.php:32
Bitrix\Main\ORM\Entity\$isClone
$isClone
Definition: main/lib/orm/entity.php:60
Bitrix\Main\ORM\Entity\enableFullTextIndex
enableFullTextIndex($field, $mode=true)
Sets a flag indicating full text index support for a field.
Definition: main/lib/orm/entity.php:1343
Bitrix\Main\ORM\Entity\getUField
getUField($name)
Definition: main/lib/orm/entity.php:581
Bitrix\Main\ORM\Entity\readFromCache
readFromCache($ttl, $cacheId, $countTotal=false)
Reads data from cache.
Definition: main/lib/orm/entity.php:1242
Bitrix\Main\Text\StringHelper\snake2camel
static snake2camel($str)
Changes registry from snake_case or SNAKE_CASE to CamelCase.
Definition: stringhelper.php:56
Bitrix\Main\ORM\Entity\addField
addField($fieldInfo, $fieldName=null)
Definition: main/lib/orm/entity.php:497