本文整理汇总了PHP中record_adapter::get_caption方法的典型用法代码示例。如果您正苦于以下问题:PHP record_adapter::get_caption方法的具体用法?PHP record_adapter::get_caption怎么用?PHP record_adapter::get_caption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类record_adapter
的用法示例。
在下文中一共展示了record_adapter::get_caption方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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);
}
}
示例2: delete_data_from_cache
/**
* Part of the cache_cacheableInterface
*
* @param string $option
* @return caption_field
*/
public function delete_data_from_cache($option = null)
{
$this->value = $this->VocabularyId = $this->VocabularyType = null;
$this->record->delete_data_from_cache(record_adapter::CACHE_TITLE);
try {
$this->record->get_caption()->get_field($this->databox_field->get_name())->delete_data_from_cache();
} catch (\Exception $e) {
}
unset(self::$localCache[$this->get_cache_key($option)]);
}
示例3: testUpload
/**
* @covers Alchemy\Phrasea\Controller\Prod\Upload::upload
* @covers Alchemy\Phrasea\Controller\Prod\Upload::getJsonResponse
*/
public function testUpload()
{
self::$DI['app']['notification.deliverer'] = $this->getMockBuilder('Alchemy\\Phrasea\\Notification\\Deliverer')->disableOriginalConstructor()->getMock();
$data = DataURI\Data::buildFromFile(__DIR__ . '/../../../../../files/cestlafete.jpg');
$params = ['base_id' => self::$DI['collection']->get_base_id(), 'b64_image' => DataURI\Dumper::dump($data)];
$files = ['files' => [new UploadedFile($this->tmpFile, 'KIKOO.JPG')]];
self::$DI['client']->request('POST', '/prod/upload/', $params, $files, ['HTTP_Accept' => 'application/json']);
$response = self::$DI['client']->getResponse();
$this->checkJsonResponse($response);
$datas = json_decode($response->getContent(), true);
$this->assertTrue($datas['success']);
if ($datas['element'] == 'record') {
$id = explode('_', $datas['id']);
$record = new \record_adapter(self::$DI['app'], $id[0], $id[1]);
$this->assertTrue($record->get_thumbnail()->is_physically_present());
$fields = $record->get_caption()->get_fields(['FileName']);
$field = array_pop($fields);
$this->assertEquals($field->get_serialized_values(), 'KIKOO.JPG');
}
}
示例4: serialize
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];
}
示例5: 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);
}
示例6: getSqlDateFields
private function getSqlDateFields(\record_adapter $record)
{
$configuration = $this->getConfiguration();
$sql_fields = [];
foreach ($configuration['date_fields'] as $field_name) {
try {
$value = $record->get_caption()->get_field($field_name)->get_serialized_values();
} catch (\Exception $e) {
$value = null;
}
if ($value) {
$date = \DateTime::createFromFormat('Y/m/d H:i:s', $this->app['unicode']->parseDate($value));
$value = $date->format('U');
}
$sql_fields[] = $value ?: '-1';
}
return ($sql_fields ? ', ' : '') . implode(',', $sql_fields);
}
示例7: buildResult
/**
* @desc build the result from the specified sql
* @param array $champ all the field from the request displayed in a array
* @param string $sql the request from buildreq
* @return $this->result
*/
protected function buildResult(Application $app, $rs)
{
$i = 0;
$pref = parent::getPreff($app, $this->sbas_id);
foreach ($rs as $row) {
if ($this->enable_limit && $i > $this->nb_record) {
break;
}
foreach ($this->champ as $column) {
$this->formatResult($column, $row[$column], $i);
}
if (array_key_exists('record_id', $row)) {
try {
$record = new \record_adapter($app, $this->sbas_id, $row['record_id']);
} catch (\Exception_Record_AdapterNotFound $e) {
continue;
}
foreach ($pref as $field) {
try {
$this->result[$i][$field] = $record->get_caption()->get_field($field)->get_serialized_values();
} catch (\Exception $e) {
$this->result[$i][$field] = '';
}
}
}
$i++;
}
}
示例8: processRecords
protected function processRecords(\record_adapter $record, $outfile, $caption)
{
if (!file_exists($record->get_subdef('document')->get_pathfile())) {
return false;
}
$this->getService('filesystem')->copy($record->get_subdef('document')->get_pathfile(), $outfile);
$dest_file = new \SplFileInfo($outfile);
touch($dest_file->getPathname(), $record->get_creation_date()->format('U'), $record->get_modification_date()->format('U'));
switch (strtolower($caption)) {
case 'xml':
$pathinfo = pathinfo($dest_file->getPathname());
$xml = $this->container['serializer.caption']->serialize($record->get_caption(), CaptionSerializer::SERIALIZE_XML);
$xml_file = dirname($outfile) . '/' . $pathinfo['filename'] . '.xml';
file_put_contents($xml_file, $xml);
break;
default:
break;
}
return true;
}
示例9: refresh
/**
* @param Application $app
* @param int $sbas_id
*
* @return cache_databox
*/
public static function refresh(Application $app, $sbas_id)
{
if (self::$refreshing) {
return;
}
self::$refreshing = true;
$databox = $app['phraseanet.appbox']->get_databox((int) $sbas_id);
$date = new \DateTime('-3 seconds');
$last_update = null;
try {
$last_update = $app['phraseanet.appbox']->get_data_from_cache('memcached_update_' . $sbas_id);
} catch (\Exception $e) {
}
if ($last_update) {
$last_update = new \DateTime($last_update);
} else {
$last_update = new \DateTime('-10 years');
}
if ($date <= $last_update) {
self::$refreshing = false;
return;
}
$connsbas = $databox->get_connection();
$sql = 'SELECT type, value FROM memcached WHERE site_id = :site_id';
$stmt = $connsbas->prepare($sql);
$stmt->execute([':site_id' => $app['conf']->get('servername')]);
$rs = $stmt->fetchAll(\PDO::FETCH_ASSOC);
$stmt->closeCursor();
foreach ($rs as $row) {
switch ($row['type']) {
case 'record':
$key = 'record_' . $sbas_id . '_' . $row['value'];
$databox->delete_data_from_cache($key);
$key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_SUBDEFS;
$databox->delete_data_from_cache($key);
$key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_GROUPING;
$databox->delete_data_from_cache($key);
$key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_MIME;
$databox->delete_data_from_cache($key);
$key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_ORIGINAL_NAME;
$databox->delete_data_from_cache($key);
$key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_SHA256;
$databox->delete_data_from_cache($key);
$key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_STATUS;
$databox->delete_data_from_cache($key);
$key = 'record_' . $sbas_id . '_' . $row['value'] . '_' . \record_adapter::CACHE_TECHNICAL_DATAS;
$databox->delete_data_from_cache($key);
$sql = 'DELETE FROM memcached
WHERE site_id = :site_id AND type="record" AND value = :value';
$params = [':site_id' => $app['conf']->get('servername'), ':value' => $row['value']];
$stmt = $connsbas->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
$record = new \record_adapter($app, $sbas_id, $row['value']);
$record->get_caption()->delete_data_from_cache();
foreach ($record->get_subdefs() as $subdef) {
$subdef->delete_data_from_cache();
}
break;
case 'structure':
$app['phraseanet.appbox']->delete_data_from_cache(\appbox::CACHE_LIST_BASES);
$app['phraseanet.appbox']->delete_data_from_cache(\appbox::CACHE_SBAS_IDS);
$sql = 'DELETE FROM memcached
WHERE site_id = :site_id AND type="structure" AND value = :value';
$params = [':site_id' => $app['conf']->get('servername'), ':value' => $row['value']];
$stmt = $connsbas->prepare($sql);
$stmt->execute($params);
$stmt->closeCursor();
break;
}
}
$date = new \DateTime();
$now = $date->format(DATE_ISO8601);
$app['phraseanet.appbox']->set_data_to_cache($now, 'memcached_update_' . $sbas_id);
$conn = $app['phraseanet.appbox']->get_connection();
$sql = 'UPDATE sitepreff SET memcached_update = :date';
$stmt = $conn->prepare($sql);
$stmt->execute([':date' => $now]);
$stmt->closeCursor();
self::$refreshing = false;
return;
}
示例10: 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;
}
示例11: list_story
/**
* Retrieve detailled informations about one story
*
* @param \record_adapter $story
*
* @return array
*/
public function list_story(Application $app, Request $request, \record_adapter $story)
{
if (!$story->is_grouping()) {
return Result::createError($request, 404, 'Story not found')->createResponse();
}
$that = $this;
$records = array_map(function (\record_adapter $record) use($that, $app) {
return $that->list_record($app, $record);
}, array_values($story->get_children()->get_elements()));
$caption = $story->get_caption();
$format = function (\caption_record $caption, $dcField) {
$field = $caption->get_dc_field($dcField);
if (!$field) {
return null;
}
return $field->get_serialized_values();
};
return ['@entity@' => self::OBJECT_TYPE_STORY, 'databox_id' => $story->get_sbas_id(), 'story_id' => $story->get_record_id(), 'updated_on' => $story->get_modification_date()->format(DATE_ATOM), 'created_on' => $story->get_creation_date()->format(DATE_ATOM), 'collection_id' => \phrasea::collFromBas($app, $story->get_base_id()), 'thumbnail' => $this->list_embedable_media($app, $story, $story->get_thumbnail()), 'uuid' => $story->get_uuid(), 'metadatas' => ['@entity@' => self::OBJECT_TYPE_STORY_METADATA_BAG, 'dc:contributor' => $format($caption, \databox_Field_DCESAbstract::Contributor), 'dc:coverage' => $format($caption, \databox_Field_DCESAbstract::Coverage), 'dc:creator' => $format($caption, \databox_Field_DCESAbstract::Creator), 'dc:date' => $format($caption, \databox_Field_DCESAbstract::Date), 'dc:description' => $format($caption, \databox_Field_DCESAbstract::Description), 'dc:format' => $format($caption, \databox_Field_DCESAbstract::Format), 'dc:identifier' => $format($caption, \databox_Field_DCESAbstract::Identifier), 'dc:language' => $format($caption, \databox_Field_DCESAbstract::Language), 'dc:publisher' => $format($caption, \databox_Field_DCESAbstract::Publisher), 'dc:relation' => $format($caption, \databox_Field_DCESAbstract::Relation), 'dc:rights' => $format($caption, \databox_Field_DCESAbstract::Rights), 'dc:source' => $format($caption, \databox_Field_DCESAbstract::Source), 'dc:subject' => $format($caption, \databox_Field_DCESAbstract::Subject), 'dc:title' => $format($caption, \databox_Field_DCESAbstract::Title), 'dc:type' => $format($caption, \databox_Field_DCESAbstract::Type)], 'records' => $records];
}
示例12: doExport
protected function doExport(Application $app, Task $task, FtpExport $export)
{
$settings = simplexml_load_string($task->getSettings());
$proxy = (string) $settings->proxy;
$proxyport = (string) $settings->proxyport;
$state = "";
$ftp_server = $export->getAddr();
$ftp_user_name = $export->getLogin();
$ftp_user_pass = $export->getPwd();
$ftpLog = $ftp_user_name . "@" . \p4string::addEndSlash($ftp_server) . $export->getDestfolder();
if ($export->getCrash() == 0) {
$line = $this->translator->trans('task::ftp:Etat d\'envoi FTP vers le serveur "%server%" avec le compte "%username%" et pour destination le dossier : "%directory%"', ['%server%' => $ftp_server, '%username%' => $ftp_user_name, '%directory%' => $export->getDestfolder()]) . PHP_EOL;
$state .= $line;
$this->log('debug', $line);
}
$state .= $line = $this->translator->trans("task::ftp:TENTATIVE no %number%, %date%", ['%number%' => $export->getCrash() + 1, '%date%' => " (" . date('r') . ")"]) . PHP_EOL;
$this->log('debug', $line);
try {
$ssl = $export->isSsl();
$ftp_client = $app['phraseanet.ftp.client']($ftp_server, 21, 300, $ssl, $proxy, $proxyport);
$ftp_client->login($ftp_user_name, $ftp_user_pass);
if ($export->isPassif()) {
try {
$ftp_client->passive(true);
} catch (\Exception $e) {
$this->log('debug', $e->getMessage());
}
}
if (trim($export->getDestfolder()) != '') {
try {
$ftp_client->chdir($export->getDestFolder());
$export->setDestfolder('/' . $export->getDestfolder());
} catch (\Exception $e) {
$this->log('debug', $e->getMessage());
}
} else {
$export->setDestfolder('/');
}
if (trim($export->getFoldertocreate()) != '') {
try {
$ftp_client->mkdir($export->getFoldertocreate());
} catch (\Exception $e) {
$this->log('debug', $e->getMessage());
}
try {
$new_dir = $ftp_client->add_end_slash($export->getDestfolder()) . $export->getFoldertocreate();
$ftp_client->chdir($new_dir);
} catch (\Exception $e) {
$this->log('debug', $e->getMessage());
}
}
$obj = [];
$basefolder = '';
if (!in_array(trim($export->getDestfolder()), ['.', './', ''])) {
$basefolder = \p4string::addEndSlash($export->getDestfolder());
}
$basefolder .= $export->getFoldertocreate();
if (in_array(trim($basefolder), ['.', './', ''])) {
$basefolder = '/';
}
foreach ($export->getElements() as $exportElement) {
if ($exportElement->isDone()) {
continue;
}
$base_id = $exportElement->getBaseId();
$record_id = $exportElement->getRecordId();
$subdef = $exportElement->getSubdef();
$localfile = null;
try {
$sbas_id = \phrasea::sbasFromBas($app, $base_id);
$record = new \record_adapter($app, $sbas_id, $record_id);
$sdcaption = $app['serializer.caption']->serialize($record->get_caption(), CaptionSerializer::SERIALIZE_XML, $exportElement->isBusinessfields());
$remotefile = $exportElement->getFilename();
if ($subdef == 'caption') {
$desc = $app['serializer.caption']->serialize($record->get_caption(), CaptionSerializer::SERIALIZE_XML, $exportElement->isBusinessfields());
$localfile = sys_get_temp_dir() . '/' . md5($desc . time() . mt_rand());
if (file_put_contents($localfile, $desc) === false) {
throw new \Exception('Impossible de creer un fichier temporaire');
}
} elseif ($subdef == 'caption-yaml') {
$desc = $app['serializer.caption']->serialize($record->get_caption(), CaptionSerializer::SERIALIZE_YAML, $exportElement->isBusinessfields());
$localfile = sys_get_temp_dir() . '/' . md5($desc . time() . mt_rand());
if (file_put_contents($localfile, $desc) === false) {
throw new \Exception('Impossible de creer un fichier temporaire');
}
} else {
$sd = $record->get_subdefs();
if (!$sd || !isset($sd[$subdef])) {
continue;
}
$localfile = $sd[$subdef]->get_pathfile();
if (!file_exists($localfile)) {
throw new \Exception('Le fichier local n\'existe pas');
}
}
$current_folder = rtrim(str_replace('//', '/', $basefolder . $exportElement->getFolder()), '/');
if ($ftp_client->pwd() != $current_folder) {
try {
$ftp_client->chdir($current_folder);
} catch (\Exception $e) {
//.........这里部分代码省略.........
示例13: buildResult
/**
* @desc build the result from the specified sql
* @param array $champ all the field from the request displayed in a array
* @param string $sql the request from buildreq
* @return $this->result
*/
protected function buildResult(Application $app, $rs)
{
$i = 0;
$pref = parent::getPreff($app, $this->sbas_id);
//// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, var_export($rs, true)), FILE_APPEND);
foreach ($rs as $row) {
if ($this->enable_limit && $i > $this->nb_record) {
break;
}
foreach ($this->champ as $column) {
$this->formatResult($column, $row[$column], $i);
}
if (array_key_exists('record_id', $row)) {
//// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, $row['record_id']), FILE_APPEND);
try {
$record = new \record_adapter($app, $this->sbas_id, $row['record_id']);
$caption = $record->get_caption();
foreach ($pref as $field) {
//// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s) %s\n\n", __FILE__, __LINE__, $field), FILE_APPEND);
try {
$this->result[$i][$field] = $caption->get_field($field)->get_serialized_values();
} catch (\Exception $e) {
$this->result[$i][$field] = '';
}
}
} catch (\Exception_Record_AdapterNotFound $e) {
foreach ($pref as $field) {
$this->result[$i][$field] = '';
}
}
}
$i++;
//// no_file_put_contents("/tmp/report.txt", sprintf("%s (%s)\n\n", __FILE__, __LINE__), FILE_APPEND);
}
}