当前位置: 首页>>代码示例>>PHP>>正文


PHP record_adapter::set_metadatas方法代码示例

本文整理汇总了PHP中record_adapter::set_metadatas方法的典型用法代码示例。如果您正苦于以下问题:PHP record_adapter::set_metadatas方法的具体用法?PHP record_adapter::set_metadatas怎么用?PHP record_adapter::set_metadatas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在record_adapter的用法示例。


在下文中一共展示了record_adapter::set_metadatas方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: replaceMetadata

 public function replaceMetadata($metadataCollection, \record_adapter $record)
 {
     $metadatas = [];
     $tagnameToFieldnameMapping = [];
     $arrayStructure = iterator_to_array($record->get_databox()->get_meta_structure());
     array_walk($arrayStructure, function ($databoxField) use(&$tagnameToFieldnameMapping) {
         $tagname = $databoxField->get_tag()->getTagname();
         $tagnameToFieldnameMapping[$tagname][] = $databoxField->get_name();
     });
     array_walk($metadataCollection, function (Metadata $metadata) use(&$metadatas, $tagnameToFieldnameMapping) {
         $tagname = $metadata->getTag()->getTagname();
         if (!isset($tagnameToFieldnameMapping[$tagname])) {
             return;
         }
         foreach ($tagnameToFieldnameMapping[$tagname] as $fieldname) {
             if (!isset($metadatas[$fieldname])) {
                 $metadatas[$fieldname] = [];
             }
             $metadatas[$fieldname] = array_merge($metadatas[$fieldname], $metadata->getValue()->asArray());
         }
     });
     $metas = [];
     array_walk($arrayStructure, function (\databox_field $field) use(&$metas, $metadatas, $record) {
         $fieldname = $field->get_name();
         if (!isset($metadatas[$fieldname])) {
             return;
         }
         $values = $metadatas[$fieldname];
         if ($record->get_caption()->has_field($fieldname)) {
             foreach ($record->get_caption()->get_field($fieldname)->get_values() as $value) {
                 $value->delete();
             }
         }
         if ($field->is_multi()) {
             $tmpValues = [];
             foreach ($values as $value) {
                 $tmpValues = array_merge($tmpValues, \caption_field::get_multi_values($value, $field->get_separator()));
             }
             $values = array_unique($tmpValues);
             foreach ($values as $value) {
                 if (trim($value) === '') {
                     continue;
                 }
                 $metas[] = ['meta_struct_id' => $field->get_id(), 'meta_id' => null, 'value' => $value];
             }
         } else {
             $value = array_pop($values);
             if (trim($value) === '') {
                 return;
             }
             $metas[] = ['meta_struct_id' => $field->get_id(), 'meta_id' => null, 'value' => $value];
         }
     });
     if (count($metas) > 0) {
         $record->set_metadatas($metas, true);
     }
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:57,代码来源:PhraseanetMetadataSetter.php

示例2: injectMetadatas

 protected function injectMetadatas(\record_adapter $record)
 {
     foreach ($record->get_databox()->get_meta_structure()->get_elements() as $field) {
         try {
             $values = $record->get_caption()->get_field($field->get_name())->get_values();
             $value = array_pop($values);
             $meta_id = $value->getId();
         } catch (\Exception $e) {
             $meta_id = null;
         }
         $toupdate[$field->get_id()] = ['meta_id' => $meta_id, 'meta_struct_id' => $field->get_id(), 'value' => 'podom pom pom ' . $field->get_id()];
     }
     $record->set_metadatas($toupdate);
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:14,代码来源:ApiTestCase.php

示例3: editRecord

 protected function editRecord($string2add, \record_adapter &$record, $indexable = true, $business = false)
 {
     $toupdate = [];
     $field = null;
     foreach ($record->get_databox()->get_meta_structure()->get_elements() as $field) {
         if ($indexable !== $field->is_indexable() || $field->isBusiness() !== $business) {
             continue;
         }
         try {
             $values = $record->get_caption()->get_field($field->get_name())->get_values();
             $value = array_pop($values);
             $meta_id = $value->getId();
         } catch (\Exception $e) {
             $meta_id = null;
         }
         $toupdate[$field->get_id()] = ['meta_id' => $meta_id, 'meta_struct_id' => $field->get_id(), 'value' => $string2add];
         break;
     }
     $record->set_metadatas($toupdate);
     return $field;
 }
开发者ID:romainneutron,项目名称:Phraseanet,代码行数:21,代码来源:SearchEngineAbstractTest.php

示例4: updateMetadatas

 /**
  * Update the metadatas of a record
  *
  * @param \record_adapter $record
  * @param string          $xml
  */
 protected function updateMetadatas(\record_adapter $record, $xml)
 {
     $metas = $record->get_databox()->get_meta_structure();
     $datas = $metadatas = [];
     if (false !== ($sxe = simplexml_load_string($xml))) {
         $fields = $sxe->xpath('/record/description');
         if ($fields && is_array($fields)) {
             foreach ($fields[0] as $fieldname => $value) {
                 $fieldname = trim($fieldname);
                 $value = trim($value);
                 if (null === ($databox_field = $metas->get_element_by_name($fieldname))) {
                     continue;
                 }
                 if ($databox_field->is_multi()) {
                     $new_value = \caption_field::get_multi_values($value, $databox_field->get_separator());
                     if (isset($datas[$databox_field->get_id()])) {
                         $value = array_unique(array_merge($datas[$databox_field->get_id()], $new_value));
                     } else {
                         $value = $new_value;
                     }
                 } else {
                     $new_value = $value;
                     if (isset($datas[$databox_field->get_id()])) {
                         $value = $datas[$databox_field->get_id()] . ' ' . $new_value;
                     } else {
                         $value = $new_value;
                     }
                 }
                 $datas[$databox_field->get_id()] = $value;
             }
         }
     }
     foreach ($datas as $meta_struct_id => $values) {
         if (is_array($values)) {
             foreach ($values as $value) {
                 $metadatas[] = ['meta_struct_id' => $meta_struct_id, 'meta_id' => null, 'value' => $value];
             }
         } else {
             $metadatas[] = ['meta_struct_id' => $meta_struct_id, 'meta_id' => null, 'value' => $values];
         }
     }
     $record->set_metadatas($metadatas, true);
 }
开发者ID:luisbrito,项目名称:Phraseanet,代码行数:49,代码来源:Step35.php


注:本文中的record_adapter::set_metadatas方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。