35 return ElementEntity::class;
45 return $query->where(
"IBLOCK_ID", static::getEntity()->getIblock()->getId());
67 $class = static::getEntityClass()::normalizeEntityClass(get_called_class());
69 if (!isset(static::$entity[$class]))
72 $parentClass = get_parent_class(get_called_class());
76 [ElementV1Table::class, ElementV2Table::class]
79 static::$entity[$class] = clone $parentClass::getEntity();
80 static::$entity[$class]->reinitialize($class);
84 static::$entity[$class] = parent::getEntity();
88 return static::$entity[$class];
99 public static function addMulti($rows, $ignoreEvents =
false)
103 foreach ($rows as $row)
105 if (!empty($row[
'__object']))
107 $result = $row[
'__object']->save();
111 $result = static::add($row);
121 $fields = static::getEntity()->getFields();
125 foreach ($fields as $field)
128 $hasEmptyRequiredValue =
false;
132 $property = $field->getIblockElementProperty();
134 if ($property->getIsRequired())
137 $valueContainer = $object->get($field->getName());
139 if (empty($valueContainer))
141 $hasEmptyRequiredValue =
true;
145 if ($valueContainer instanceof ValueStorage)
147 $userType = CIBlockProperty::GetUserType($property->getUserType());
149 if(array_key_exists(
"GetLength", $userType))
151 $length = call_user_func_array(
152 $userType[
"GetLength"],
154 $property->collectValues(),
155 [
"VALUE" => $valueContainer->getValue()]
161 $length = mb_strlen($valueContainer->getValue());
164 $hasEmptyRequiredValue = ($length <= 0);
168 if ($hasEmptyRequiredValue)
170 $result->addError(
new FieldError(
173 "MAIN_ENTITY_FIELD_REQUIRED",
174 [
"#FIELD#" => $property->getName()]
176 FieldError::EMPTY_REQUIRED
189 $iblockId = static::getEntity()->getIblock()->getId();
192 CIBlock::clearIblockTagCache($iblockId);
201 $iblockId = static::getEntity()->getIblock()->getId();
204 CIBlock::clearIblockTagCache($iblockId);
212 parent::onAfterDelete($event);
215 $iblockId = static::getEntity()->getIblock()->getId();
216 $connection = static::getEntity()->getConnection();
219 $tables = [static::getEntity()->getSingleValueTableName(), static::getEntity()->getMultiValueTableName()];
221 foreach (array_unique($tables) as $table)
223 $connection->query(
"DELETE FROM {$table} WHERE IBLOCK_ELEMENT_ID = {$elementId}");
227 CIBlock::clearIblockTagCache($iblockId);
static getMessage($code, $replace=null, $language=null)
static onBeforeAdd(Event $event)