Esempio n. 1
0
 public function serialize(\record_adapter $record)
 {
     $technicalInformation = $caption = $business = $status = [];
     foreach ($record->get_technical_infos() as $name => $value) {
         $technicalInformation[$name] = $value;
     }
     foreach ($record->get_caption()->get_fields(null, true) as $field) {
         $isDate = $field->get_databox_field()->get_type() === \databox_field::TYPE_DATE;
         $isBusiness = $field->get_databox_field()->isBusiness();
         $vi = $field->get_values();
         if ($field->is_multi()) {
             $values = [];
             foreach ($vi as $value) {
                 $values[] = $this->sanitizeSerializedValue($value->getValue());
             }
             $value = implode(' ' . $field->get_databox_field()->get_separator(false) . ' ', $values);
         } else {
             $value = $this->sanitizeSerializedValue(array_pop($vi)->getValue());
         }
         if ($isDate) {
             try {
                 $date = new \DateTime($value);
                 $value = $date->format(DATE_ATOM);
             } catch (\Exception $e) {
                 continue;
             }
         }
         if ($isBusiness) {
             $business[$field->get_databox_field()->get_name()] = $value;
         }
         $caption[$field->get_databox_field()->get_name()] = $value;
     }
     $i = 0;
     foreach (preg_split('//', strrev($record->get_status()), -1, PREG_SPLIT_NO_EMPTY) as $val) {
         $status['status-' . $i] = (int) $val;
         $i++;
     }
     return ['databox_id' => $record->get_sbas_id(), 'record_id' => $record->get_record_id(), 'collection_id' => $record->get_collection()->get_coll_id(), 'base_id' => $record->get_base_id(), 'mime_type' => $record->get_mime(), 'title' => $record->get_title(), 'original_name' => $record->get_original_name(), 'updated_on' => $record->get_modification_date()->format(DATE_ATOM), 'created_on' => $record->get_creation_date()->format(DATE_ATOM), 'sha256' => $record->get_sha256(), 'technical_informations' => $technicalInformation, 'phrasea_type' => $record->get_type(), 'type' => $record->is_grouping() ? 'story' : 'record', 'uuid' => $record->get_uuid(), 'caption' => $caption, 'status' => $status, 'caption-business' => $business];
 }
Esempio n. 2
0
 /**
  *
  * @param  record_adapter $record
  * @return array
  */
 private function check_record_constraints(record_adapter $record)
 {
     $errors = [];
     if (!$record->get_hd_file() instanceof \SplFileInfo) {
         $errors["file_size"] = $this->translator->trans("Le record n'a pas de fichier physique");
     }
     //Record must rely on real file
     if ($record->get_duration() > self::AUTH_VIDEO_DURATION) {
         $errors["duration"] = $this->translator->trans("La taille maximale d'une video est de %duration% minutes.", ['%duration%' => self::AUTH_VIDEO_DURATION / 60]);
     }
     if ($record->get_technical_infos('size') > self::AUTH_VIDEO_SIZE) {
         $errors["size"] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]);
     }
     return $errors;
 }
Esempio n. 3
0
 /**
  * Retrieve detailed information about one record
  *
  * @param Request          $request
  * @param \record_adapter $record
  * @return array
  */
 public function listRecord(Request $request, \record_adapter $record)
 {
     $technicalInformation = [];
     foreach ($record->get_technical_infos()->getValues() as $name => $value) {
         $technicalInformation[] = ['name' => $name, 'value' => $value];
     }
     $data = ['databox_id' => $record->getDataboxId(), 'record_id' => $record->getRecordId(), 'mime_type' => $record->getMimeType(), 'title' => $record->get_title(), 'original_name' => $record->get_original_name(), 'updated_on' => $record->getUpdated()->format(DATE_ATOM), 'created_on' => $record->getCreated()->format(DATE_ATOM), 'collection_id' => $record->getCollectionId(), 'base_id' => $record->getBaseId(), 'sha256' => $record->getSha256(), 'thumbnail' => $this->listEmbeddableMedia($request, $record, $record->get_thumbnail()), 'technical_informations' => $technicalInformation, 'phrasea_type' => $record->getType(), 'uuid' => $record->getUuid()];
     if ($request->attributes->get('_extended', false)) {
         $subdefs = $caption = [];
         foreach ($record->get_embedable_medias([], []) as $name => $media) {
             if (null !== ($subdef = $this->listEmbeddableMedia($request, $record, $media))) {
                 $subdefs[] = $subdef;
             }
         }
         foreach ($record->get_caption()->get_fields() as $field) {
             $caption[] = ['meta_structure_id' => $field->get_meta_struct_id(), 'name' => $field->get_name(), 'value' => $field->get_serialized_values(';')];
         }
         $extendedData = ['subdefs' => $subdefs, 'metadata' => $this->listRecordCaption($record->get_caption()), 'status' => $this->listRecordStatus($record), 'caption' => $caption];
         $data = array_merge($data, $extendedData);
     }
     return $data;
 }
Esempio n. 4
0
 /**
  * Retrieve detailled informations about one record
  *
  * @param  \record_adapter $record
  *
  * @return array
  */
 public function list_record(Application $app, \record_adapter $record)
 {
     $technicalInformation = [];
     foreach ($record->get_technical_infos() as $name => $value) {
         $technicalInformation[] = ['name' => $name, 'value' => $value];
     }
     return ['databox_id' => $record->get_sbas_id(), 'record_id' => $record->get_record_id(), 'mime_type' => $record->get_mime(), 'title' => $record->get_title(), 'original_name' => $record->get_original_name(), 'updated_on' => $record->get_modification_date()->format(DATE_ATOM), 'created_on' => $record->get_creation_date()->format(DATE_ATOM), 'collection_id' => \phrasea::collFromBas($app, $record->get_base_id()), 'sha256' => $record->get_sha256(), 'thumbnail' => $this->list_embedable_media($app, $record, $record->get_thumbnail()), 'technical_informations' => $technicalInformation, 'phrasea_type' => $record->get_type(), 'uuid' => $record->get_uuid()];
 }
Esempio n. 5
0
 /**
  *
  * @param  record_adapter $record
  * @return array
  */
 private function check_record_constraints(record_adapter $record)
 {
     $errors = [];
     //Record must rely on real file
     if (!$record->get_hd_file() instanceof \SplFileInfo) {
         $errors["file_size"] = $this->translator->trans("Le record n'a pas de fichier physique");
     }
     $size = $record->get_technical_infos('size');
     $size = $size ? $size->getValue() : PHP_INT_MAX;
     if ($size > self::AUTH_PHOTO_SIZE) {
         $errors["size"] = $this->translator->trans("Le poids maximum d'un fichier est de %size%", ['%size%' => p4string::format_octets(self::AUTH_VIDEO_SIZE)]);
     }
     return $errors;
 }