Esempio n. 1
0
 protected static function createUtmEntity(Entity\Base $srcEntity, array $utmFields)
 {
     global $USER_FIELD_MANAGER;
     /** @var Entity\DataManager $utmClassFull */
     $utmClassFull = static::getUtmEntityClassNameBySrcEntity($srcEntity);
     $utmClassPath = explode('\\', ltrim($utmClassFull, '\\'));
     $utmNamespace = join('\\', array_slice($utmClassPath, 0, -1));
     $utmClass = end($utmClassPath);
     // get table name
     $utmTable = static::getUtmEntityTableNameBySrcEntity($srcEntity);
     // coolect fields
     $fieldsMap = array('ID' => array('data_type' => 'integer', 'primary' => true, 'autocomplete' => true), 'VALUE_ID' => array('data_type' => 'integer', 'primary' => true), 'PARENT' => array('data_type' => $srcEntity->getDataClass(), 'reference' => array('=this.VALUE_ID' => 'ref.ID')), 'FIELD_ID' => array('data_type' => 'integer'), 'VALUE' => array('data_type' => 'text'), 'VALUE_INT' => array('data_type' => 'integer'), 'VALUE_DOUBLE' => array('data_type' => 'float'), 'VALUE_DATE' => array('data_type' => 'datetime'));
     // initialize entity
     $entity = Entity\Base::compileEntity($utmClass, $fieldsMap, array('namespace' => $utmNamespace, 'table_name' => $utmTable));
     // add utm fields being mapped on real column name
     foreach ($utmFields as $utmField) {
         $field = $USER_FIELD_MANAGER->getEntityField($utmField);
         if ($field instanceof Entity\IntegerField) {
             $columnName = 'VALUE_INT';
         } elseif ($field instanceof Entity\FloatField) {
             $columnName = 'VALUE_DOUBLE';
         } elseif ($field instanceof Entity\DateField || $field instanceof Entity\DatetimeField) {
             $columnName = 'VALUE_DATE';
         } else {
             $columnName = 'VALUE';
         }
         $field->setColumnName($columnName);
         $entity->addField($field);
         foreach ($USER_FIELD_MANAGER->getEntityReferences($utmField, $field) as $reference) {
             $entity->addField($reference);
         }
         // add back-reference
         $refField = new Entity\ReferenceField('PARENT_' . $utmField['FIELD_NAME'], $srcEntity->getDataClass(), array('=this.VALUE_ID' => 'ref.ID', '=this.FIELD_ID' => array('?i', $utmField['ID'])));
         $entity->addField($refField);
     }
     return $entity;
 }
Esempio n. 2
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;
 }