Beispiel #1
0
 protected function appendSaveDataModifier($modifier)
 {
     if (!is_callable($modifier)) {
         throw new SystemException(sprintf('Save modifier of "%s" field of "%s" entity should be a callback', $this->name, $this->entity->getDataClass()));
     }
     $this->saveDataModifiers[] = $modifier;
 }
Beispiel #2
0
 /**
  * Вызов методов \Bitrix\Main\Entity\DataManager
  * @see \Bitrix\Main\Entity\DataManager
  * @param $method
  * @param $arguments
  * @return mixed
  * @throws Exception
  */
 public function __call($method, $arguments)
 {
     $allowedMethods = array('getList', 'add', 'update', 'getRow', 'getById', 'delete');
     $allowedMethods = array_map('ToLower', $allowedMethods);
     if (!in_array(ToLower($method), $allowedMethods)) {
         throw new \Exception("Unsupported method {$method}");
     }
     /** @var $className \Bitrix\Main\Entity\DataManager */
     $className = $this->hblockEntity->getDataClass();
     return call_user_func_array("{$className}::{$method}", $arguments);
 }
Beispiel #3
0
 /**
  * @return callback[]|Validator\Base[]
  * @throws \Exception
  */
 public function getValidators()
 {
     if ($this->validators === null) {
         $validators = array();
         if ($this->validation !== null) {
             $validators = call_user_func($this->validation);
             if (!is_array($validators)) {
                 throw new \Exception(sprintf('Validation for %s field of %s entity should return array of validators', $this->name, $this->entity->getDataClass()));
             }
             foreach ($validators as $k => $validator) {
                 if (!$validator instanceof Validator\Base && !is_callable($validator)) {
                     throw new \Exception(sprintf('Validator "%s" of "%s" field of "%s" entity should be a Validator\\Base or callback', $k, $this->name, $this->entity->getDataClass()));
                 }
             }
         }
         $this->validators = $validators;
     }
     return $this->validators;
 }
Beispiel #4
0
 /**
  * @param Base|string $entity
  *
  * @return bool
  */
 public static function destroy($entity)
 {
     if ($entity instanceof Base) {
         $entityName = $entity->getDataClass();
     } else {
         $entityName = static::normalizeEntityClass($entity);
     }
     if (isset(self::$instances[$entityName])) {
         unset(self::$instances[$entityName]);
         DataManager::unsetEntity($entityName);
         return true;
     }
     return false;
 }
Beispiel #5
0
 protected static function compileUtmEntity(Entity\Base $hlentity, $userfield)
 {
     global $USER_FIELD_MANAGER;
     // build utm entity
     /** @var DataManager $hlDataClass */
     $hlDataClass = $hlentity->getDataClass();
     $hlblock = $hlDataClass::getHighloadBlock();
     $utmClassName = static::getUtmEntityClassName($hlentity, $userfield);
     $utmTableName = static::getMultipleValueTableName($hlblock, $userfield);
     // main fields
     $utmValueField = $USER_FIELD_MANAGER->getEntityField($userfield, 'VALUE');
     $utmEntityFields = array(new Entity\IntegerField('ID'), $utmValueField);
     // references
     $references = $USER_FIELD_MANAGER->getEntityReferences($userfield, $utmValueField);
     foreach ($references as $reference) {
         $utmEntityFields[] = $reference;
     }
     // create entity
     $utmEntity = Entity\Base::compileEntity($utmClassName, $utmEntityFields, array('table_name' => $utmTableName, 'namespace' => $hlentity->getNamespace()));
     // add original entity reference
     $referenceField = new Entity\ReferenceField('OBJECT', $hlentity, array('=this.ID' => 'ref.ID'));
     $utmEntity->addField($referenceField);
     // add short alias for back-reference
     $aliasField = new Entity\ExpressionField($userfield['FIELD_NAME'] . '_SINGLE', '%s', $utmEntity->getFullName() . ':' . 'OBJECT.VALUE', array('data_type' => get_class($utmEntity->getField('VALUE'))));
     $hlentity->addField($aliasField);
     // add aliases to references
     /*foreach ($references as $reference)
     		{
     			// todo after #44924 is resolved
     			// actually no. to make it work expression should support linking to references
     		}*/
     // add seriazed cache-field
     $cacheField = new Entity\TextField($userfield['FIELD_NAME']);
     Main\UserFieldTable::setMultipleFieldSerialization($cacheField, $userfield);
     $hlentity->addField($cacheField);
     return $utmEntity;
 }