Ejemplo n.º 1
0
 /**
  * Create field description.
  */
 public function createFieldDescription()
 {
     if ($this->isActive) {
         if (!($fd = $this->dataDescription->getFieldDescriptionByName('tags'))) {
             $fd = new FieldDescription('tags');
             $this->dataDescription->addFieldDescription($fd);
         }
         $fd->setType(FieldDescription::FIELD_TYPE_TEXTBOX_LIST)->setProperty('url', 'tag-autocomplete')->setProperty('separator', TagManager::TAG_SEPARATOR);
     }
 }
Ejemplo n.º 2
0
 /**
  * Create field.
  * It is used in feeds and their derivatives.
  *
  * @param bool|string $mapFieldName Map field name.
  * @param bool $returnOnlyFirstAttachment Defines whether only the first attachment should be returned.
  * @param bool|array $mapValue Map values.
  */
 public function createField($mapFieldName = false, $returnOnlyFirstAttachment = false, $mapValue = false)
 {
     if ($this->isActive && !$this->data->isEmpty()) {
         if (!$mapFieldName) {
             $mapFieldName = $this->pk->getName();
         }
         if (!$mapValue) {
             if (!($f = $this->data->getFieldByName($mapFieldName))) {
                 return;
             }
             $mapValue = $f->getData();
         }
         $mapTableName = $this->tableName;
         //@todo в принципе имя филда можеть быть вычислено через ColumnInfo
         $f = new Field('attachments');
         $this->data->addField($f);
         if (!is_array($mapValue)) {
             $mapValue = [$mapValue];
         }
         if ($filteredMapValue = array_filter(array_values($mapValue))) {
             $langMapTableName = $this->dbh->getTranslationTablename($mapTableName);
             $columns = $this->dbh->getColumnsInfo($mapTableName);
             $prefix = '';
             foreach ($columns as $cname => $col) {
                 if (isset($col['index']) && $col['index'] == 'PRI') {
                     $prefix = str_replace('_id', '', $cname);
                 }
             }
             if ($langMapTableName) {
                 $lang_columns = $this->dbh->getColumnsInfo($langMapTableName);
                 $lang_pk = false;
                 foreach ($lang_columns as $cname => $col) {
                     if (isset($col['index']) && $col['index'] == 'PRI' && $cname != 'lang_id') {
                         $lang_pk = $cname;
                     }
                 }
             }
             $additional_fields = [];
             foreach ($columns as $cname => $col) {
                 if ($cname != 'session_id' && (empty($col['index']) or $col['index'] != 'PRI' and empty($col['key']['tableName']))) {
                     $new_cname = str_replace($prefix . '_', '', $cname);
                     if ($new_cname != 'order_num') {
                         $additional_fields[$cname] = $new_cname;
                     }
                 }
             }
             if ($langMapTableName) {
                 foreach ($lang_columns as $cname => $col) {
                     if (empty($col['index']) or $col['index'] != 'PRI') {
                         $new_cname = str_replace($prefix . '_', '', $cname);
                         if ($new_cname != 'name') {
                             $additional_fields[$cname] = $new_cname;
                         }
                     }
                 }
             }
             $request = 'SELECT spu.' . $mapFieldName . ',spu.upl_id as id, spu.*, ' . 'upl_path as file, upl_name as name, upl_title as title, upl_width as width, upl_height as height, TIME_FORMAT(upl_duration, "%i:%s") as duration,
                         upl_internal_type as type,upl_mime_type as mime, upl_data as data, ' . 'upl_is_mp4 as is_mp4, upl_is_webm as is_webm, upl_is_flv as is_flv ' . ($langMapTableName && $lang_pk ? ', spt.*' : '') . 'FROM ' . self::ATTACH_TABLENAME . ' su ' . 'LEFT JOIN `' . $mapTableName . '` spu ON spu.upl_id = su.upl_id ' . ($langMapTableName && $lang_pk ? 'LEFT JOIN `' . $langMapTableName . '` spt ON spu.' . $lang_pk . ' = spt.' . $lang_pk . ' AND spt.lang_id = ' . E()->getDocument()->getLang() : '') . ' WHERE ' . $mapFieldName . ' IN (' . implode(',', $filteredMapValue) . ') AND (su.upl_is_ready=1) AND (su.upl_is_active = 1)';
             // получаем имя колонки _order_num и сортируем по этому полю, если оно есть
             if ($columns) {
                 foreach ($columns as $col => $colInfo) {
                     if (strpos($col, '_order_num') !== false) {
                         $request .= ' ORDER BY ' . $col;
                     }
                 }
             }
             $images = $this->dbh->select($request);
             if ($images) {
                 foreach ($images as $row) {
                     $repoPath = E()->FileRepoInfo->getRepositoryRoot($row['file']);
                     $row['secure'] = E()->getConfigValue('repositories.ftp.' . $repoPath . '.secure', 0) ? true : false;
                     // делаем преобразование имен из $additional_fiels (отрезаем prefix)
                     if ($additional_fields) {
                         foreach ($additional_fields as $old_field => $new_field) {
                             if (array_key_exists($old_field, $row)) {
                                 $val = $row[$old_field];
                                 unset($row[$old_field]);
                                 $row[$new_field] = $val;
                             }
                         }
                     }
                     $mapID = $row[$mapFieldName];
                     if ($returnOnlyFirstAttachment && isset($imageData[$mapID])) {
                         continue;
                     }
                     if (!isset($imageData[$mapID])) {
                         $imageData[$mapID] = [];
                     }
                     array_push($imageData[$mapID], $row);
                 }
                 list($uploadsPK) = array_keys($columns);
                 for ($i = 0; $i < sizeof($mapValue); $i++) {
                     if (isset($imageData[$mapValue[$i]])) {
                         if ($this->addOG) {
                             foreach ($imageData[$mapValue[$i]] as $row) {
                                 E()->getOGObject()->addImage($row['file']);
                             }
                             $attachment = $imageData[$mapValue[$i]];
                             if (isset($attachment[0]) && $attachment[0]['type'] === 'video') {
                                 //inspect($attachment);
                                 E()->getOGObject()->setVideo($attachment[0]['file'], $attachment[0]['duration'], $attachment[0]['mime'], $attachment[0]['width'], $attachment[0]['height']);
                             }
                         }
                         $builder = new SimplestBuilder();
                         $localData = new Data();
                         $localData->load($imageData[$mapValue[$i]]);
                         $dataDescription = new DataDescription();
                         $fd = new FieldDescription('id');
                         $dataDescription->addFieldDescription($fd);
                         $fd = new FieldDescription($uploadsPK);
                         $fd->setType(FieldDescription::FIELD_TYPE_INT);
                         $fd->setProperty('key', true);
                         $dataDescription->addFieldDescription($fd);
                         $fd = new FieldDescription('file');
                         $fd->setType(FieldDescription::FIELD_TYPE_STRING);
                         $base = pathinfo($imageData[$mapValue[$i]][0]['file'], PATHINFO_DIRNAME) . '/' . pathinfo($imageData[$mapValue[$i]][0]['file'], PATHINFO_FILENAME);
                         $dataDescription->addFieldDescription($fd);
                         $fd = new FieldDescription('type');
                         $fd->setType(FieldDescription::FIELD_TYPE_STRING);
                         $dataDescription->addFieldDescription($fd);
                         $fd = new FieldDescription('duration');
                         $fd->setType(FieldDescription::FIELD_TYPE_STRING);
                         $dataDescription->addFieldDescription($fd);
                         $fd = new FieldDescription('width');
                         $fd->setType(FieldDescription::FIELD_TYPE_STRING);
                         $dataDescription->addFieldDescription($fd);
                         $fd = new FieldDescription('height');
                         $fd->setType(FieldDescription::FIELD_TYPE_STRING);
                         $dataDescription->addFieldDescription($fd);
                         $fd = new FieldDescription('mime');
                         $fd->setType(FieldDescription::FIELD_TYPE_STRING);
                         $dataDescription->addFieldDescription($fd);
                         $fd = new FieldDescription('data');
                         $fd->setType(FieldDescription::FIELD_TYPE_STRING);
                         $dataDescription->addFieldDescription($fd);
                         $fd = new FieldDescription('title');
                         $fd->setType(FieldDescription::FIELD_TYPE_STRING);
                         $dataDescription->addFieldDescription($fd);
                         $fd_name = new FieldDescription('name');
                         $dataDescription->addFieldDescription($fd_name);
                         $fd = new FieldDescription('secure');
                         $fd->setType(FieldDescription::FIELD_TYPE_HIDDEN);
                         $dataDescription->addFieldDescription($fd);
                         $playlist = [];
                         foreach (['mp4', 'webm', 'flv'] as $fileType) {
                             if ($imageData[$mapValue[$i]][0]['is_' . $fileType] == '1') {
                                 $playlist[] = ['id' => $base . '.' . $fileType, 'type' => $fileType];
                             }
                         }
                         if ($playlist && count($playlist) > 1) {
                             $fd = new FieldDescription('playlist');
                             $fd->setType(FieldDescription::FIELD_TYPE_SELECT);
                             $fd->loadAvailableValues($playlist, 'id', 'id');
                             $dataDescription->addFieldDescription($fd);
                         }
                         // дополнительные поля из основной и языковой таблицы _uploads
                         foreach ($additional_fields as $new_name) {
                             if ($new_name != 'name') {
                                 $fd = new FieldDescription($new_name);
                                 $fd->setType(FieldDescription::FIELD_TYPE_STRING);
                                 $dataDescription->addFieldDescription($fd);
                             }
                         }
                         $builder->setData($localData);
                         $builder->setDataDescription($dataDescription);
                         if ($this->dbh->getTagsTablename($mapTableName)) {
                             $tm = new TagManager($dataDescription, $localData, $mapTableName);
                             $tm->createFieldDescription();
                             $tm->createField();
                         }
                         $builder->build();
                         $f->setRowData($i, $builder->getResult());
                     }
                 }
             }
         }
     }
 }
 /**
  * Validate data contained in the description array
  *
  * @todo Should this be a method on DataDescription?
  */
 protected function validateDataDescription($FunctionName, DataDescription $DataDescription, $DescriptionRequired = TRUE)
 {
     if ($DataDescription->getPosition() == '') {
         $this->Errors[] = "[Warning] " . $FunctionName . " - Y Labels are not set.";
         $DataDescription->setPosition("Name");
     }
     if ($DescriptionRequired) {
         if (!isset($DataDescription->description)) {
             $this->Errors[] = "[Warning] " . $FunctionName . " - Series descriptions are not set.";
             foreach ($DataDescription->values as $key => $Value) {
                 $DataDescription->description[$Value] = $Value;
             }
         }
         if (count($DataDescription->description) < count($DataDescription->values)) {
             $this->Errors[] = "[Warning] " . $FunctionName . " - Some series descriptions are not set.";
             foreach ($DataDescription->values as $key => $Value) {
                 if (!isset($DataDescription->description[$Value])) {
                     $DataDescription->description[$Value] = $Value;
                 }
             }
         }
     }
 }
Ejemplo n.º 4
0
 /**
  * Intersect this data description with other object data description.
  *
  * @param DataDescription $otherDataDescr Other data description.
  * @return DataDescription
  */
 public function intersect(DataDescription $otherDataDescr)
 {
     $result = false;
     if ($this->isEmpty()) {
         $result = $otherDataDescr;
     } else {
         // проходимся по описаниям полей текущего объекта
         foreach ($this->fieldDescriptions as $fieldName => $fieldDescription) {
             // если существует описание из БД - пересекаем с ним
             if ($otherDataDescr->getFieldDescriptionByName($fieldName)) {
                 $this->fieldDescriptions[$fieldName] = FieldDescription::intersect($this->fieldDescriptions[$fieldName], $otherDataDescr->getFieldDescriptionByName($fieldName));
             } else {
                 $this->getFieldDescriptionByName($fieldName)->setProperty('customField', 'customField');
             }
         }
         $result = $this;
     }
     return $result;
 }