PageRenderTime 120ms CodeModel.GetById 26ms RepoModel.GetById 1ms app.codeStats 1ms

/app/models/ca_object_representations.php

https://bitbucket.org/Sinfin/pawtucket
PHP | 1170 lines | 790 code | 155 blank | 225 comment | 145 complexity | 29a39322a99433fd5c1a46dc74116dbe MD5 | raw file
Possible License(s): LGPL-3.0, GPL-3.0
  1. <?php
  2. /** ---------------------------------------------------------------------
  3. * app/models/ca_object_representations.php : table access class for table ca_object_representations
  4. * ----------------------------------------------------------------------
  5. * CollectiveAccess
  6. * Open-source collections management software
  7. * ----------------------------------------------------------------------
  8. *
  9. * Software by Whirl-i-Gig (http://www.whirl-i-gig.com)
  10. * Copyright 2008-2011 Whirl-i-Gig
  11. *
  12. * For more information visit http://www.CollectiveAccess.org
  13. *
  14. * This program is free software; you may redistribute it and/or modify it under
  15. * the terms of the provided license as published by Whirl-i-Gig
  16. *
  17. * CollectiveAccess is distributed in the hope that it will be useful, but
  18. * WITHOUT ANY WARRANTIES whatsoever, including any implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  20. *
  21. * This source code is free and modifiable under the terms of
  22. * GNU General Public License. (http://www.gnu.org/copyleft/gpl.html). See
  23. * the "license.txt" file for details, or visit the CollectiveAccess web site at
  24. * http://www.CollectiveAccess.org
  25. *
  26. * @package CollectiveAccess
  27. * @subpackage models
  28. * @license http://www.gnu.org/copyleft/gpl.html GNU Public License version 3
  29. *
  30. * ----------------------------------------------------------------------
  31. */
  32. /**
  33. *
  34. */
  35. require_once(__CA_LIB_DIR__."/ca/IBundleProvider.php");
  36. require_once(__CA_LIB_DIR__."/ca/BundlableLabelableBaseModelWithAttributes.php");
  37. require_once(__CA_MODELS_DIR__."/ca_object_representation_labels.php");
  38. require_once(__CA_MODELS_DIR__."/ca_representation_annotations.php");
  39. require_once(__CA_MODELS_DIR__."/ca_representation_annotation_labels.php");
  40. require_once(__CA_MODELS_DIR__."/ca_object_representation_multifiles.php");
  41. BaseModel::$s_ca_models_definitions['ca_object_representations'] = array(
  42. 'NAME_SINGULAR' => _t('object representation'),
  43. 'NAME_PLURAL' => _t('object representations'),
  44. 'FIELDS' => array(
  45. 'representation_id' => array(
  46. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_HIDDEN,
  47. 'IDENTITY' => true, 'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
  48. 'IS_NULL' => false,
  49. 'DEFAULT' => '',
  50. 'LABEL' => 'Representation id', 'DESCRIPTION' => 'Identifier for Representation'
  51. ),
  52. 'locale_id' => array(
  53. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_SELECT,
  54. 'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
  55. 'IS_NULL' => true,
  56. 'DEFAULT' => '',
  57. 'DISPLAY_FIELD' => array('ca_locales.name'),
  58. 'LABEL' => _t('Locale'), 'DESCRIPTION' => _t('The locale from which the representation originates.')
  59. ),
  60. 'type_id' => array(
  61. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_SELECT,
  62. 'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
  63. 'DISPLAY_FIELD' => array('ca_list_items.item_value'),
  64. 'DISPLAY_ORDERBY' => array('ca_list_items.item_value'),
  65. 'IS_NULL' => false,
  66. 'LIST_CODE' => 'object_representation_types',
  67. 'DEFAULT' => '',
  68. 'LABEL' => _t('Type'), 'DESCRIPTION' => _t('Indicates the type of the representation. The type can only be set when creating a new representation and cannot be changed once the representation is saved.')
  69. ),
  70. 'idno' => array(
  71. 'FIELD_TYPE' => FT_TEXT, 'DISPLAY_TYPE' => DT_FIELD,
  72. 'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
  73. 'IS_NULL' => false,
  74. 'DEFAULT' => '',
  75. 'LABEL' => _t('Representation identifier'), 'DESCRIPTION' => _t('A unique alphanumeric identifier for this representation.'),
  76. 'BOUNDS_LENGTH' => array(0,255)
  77. ),
  78. 'idno_sort' => array(
  79. 'FIELD_TYPE' => FT_TEXT, 'DISPLAY_TYPE' => DT_OMIT,
  80. 'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
  81. 'IS_NULL' => false,
  82. 'DEFAULT' => '',
  83. 'LABEL' => 'Sortable representation identifier', 'DESCRIPTION' => 'Value used for sorting representations on identifier value.',
  84. 'BOUNDS_LENGTH' => array(0,255)
  85. ),
  86. 'media' => array(
  87. 'FIELD_TYPE' => FT_MEDIA, 'DISPLAY_TYPE' => DT_FIELD,
  88. 'DISPLAY_WIDTH' => 88, 'DISPLAY_HEIGHT' => 15,
  89. 'IS_NULL' => false,
  90. 'DEFAULT' => '',
  91. "MEDIA_PROCESSING_SETTING" => 'ca_object_representations',
  92. 'LABEL' => _t('Media to upload'), 'DESCRIPTION' => _t('Use this control to select media from your computer to upload.')
  93. ),
  94. 'media_metadata' => array(
  95. 'FIELD_TYPE' => FT_TEXT, 'DISPLAY_TYPE' => DT_OMIT,
  96. 'DISPLAY_WIDTH' => 88, 'DISPLAY_HEIGHT' => 15,
  97. 'IS_NULL' => false,
  98. 'DEFAULT' => '',
  99. 'LABEL' => _t('Media metadata'), 'DESCRIPTION' => _t('Media metadata')
  100. ),
  101. 'media_content' => array(
  102. 'FIELD_TYPE' => FT_TEXT, 'DISPLAY_TYPE' => DT_OMIT,
  103. 'DISPLAY_WIDTH' => 88, 'DISPLAY_HEIGHT' => 15,
  104. 'IS_NULL' => false,
  105. 'DEFAULT' => '',
  106. 'LABEL' => _t('Media content'), 'DESCRIPTION' => _t('Media content')
  107. ),
  108. 'md5' => array(
  109. 'FIELD_TYPE' => FT_TEXT, 'DISPLAY_TYPE' => DT_FIELD,
  110. 'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
  111. 'IS_NULL' => false,
  112. 'DEFAULT' => '',
  113. 'LABEL' => _t('MD5 hash'), 'DESCRIPTION' => _t('MD5-generated "fingerprint" for this media.'),
  114. 'BOUNDS_LENGTH' => array(0,32)
  115. ),
  116. 'original_filename' => array(
  117. 'FIELD_TYPE' => FT_TEXT, 'DISPLAY_TYPE' => DT_FIELD,
  118. 'DISPLAY_WIDTH' => 90, 'DISPLAY_HEIGHT' => 1,
  119. 'IS_NULL' => false,
  120. 'DEFAULT' => '',
  121. 'LABEL' => _t('Original filename'), 'DESCRIPTION' => _t('The filename of the media at the time of upload.'),
  122. 'BOUNDS_LENGTH' => array(0,1024)
  123. ),
  124. 'access' => array(
  125. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_SELECT,
  126. 'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
  127. 'IS_NULL' => false,
  128. 'DEFAULT' => 0,
  129. 'BOUNDS_CHOICE_LIST' => array(
  130. _t('Not accessible to public') => 0,
  131. _t('Accessible to public') => 1
  132. ),
  133. 'LIST' => 'access_statuses',
  134. 'LABEL' => _t('Access'), 'DESCRIPTION' => _t('Indicates if representation is accessible to the public or not. ')
  135. ),
  136. 'status' => array(
  137. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_SELECT,
  138. 'DISPLAY_WIDTH' => 40, 'DISPLAY_HEIGHT' => 1,
  139. 'IS_NULL' => false,
  140. 'DEFAULT' => 0,
  141. 'BOUNDS_CHOICE_LIST' => array(
  142. _t('Newly created') => 0,
  143. _t('Editing in progress') => 1,
  144. _t('Editing complete - pending review') => 2,
  145. _t('Review in progress') => 3,
  146. _t('Completed') => 4
  147. ),
  148. 'LIST' => 'workflow_statuses',
  149. 'LABEL' => _t('Status'), 'DESCRIPTION' => _t('Indicates the current state of the representation.')
  150. ),
  151. 'rank' => array(
  152. 'FIELD_TYPE' => FT_NUMBER, 'DISPLAY_TYPE' => DT_FIELD,
  153. 'DISPLAY_WIDTH' => 10, 'DISPLAY_HEIGHT' => 1,
  154. 'IS_NULL' => false,
  155. 'DEFAULT' => '',
  156. 'LABEL' => _t('Sort order'), 'DESCRIPTION' => _t('Sort order'),
  157. )
  158. )
  159. );
  160. class ca_object_representations extends BundlableLabelableBaseModelWithAttributes implements IBundleProvider {
  161. # ---------------------------------
  162. # --- Object attribute properties
  163. # ---------------------------------
  164. # Describe structure of content object's properties - eg. database fields and their
  165. # associated types, what modes are supported, et al.
  166. #
  167. # ------------------------------------------------------
  168. # --- Basic object parameters
  169. # ------------------------------------------------------
  170. # what table does this class represent?
  171. protected $TABLE = 'ca_object_representations';
  172. # what is the primary key of the table?
  173. protected $PRIMARY_KEY = 'representation_id';
  174. # ------------------------------------------------------
  175. # --- Properties used by standard editing scripts
  176. #
  177. # These class properties allow generic scripts to properly display
  178. # records from the table represented by this class
  179. #
  180. # ------------------------------------------------------
  181. # Array of fields to display in a listing of records from this table
  182. protected $LIST_FIELDS = array('media');
  183. # When the list of "list fields" above contains more than one field,
  184. # the LIST_DELIMITER text is displayed between fields as a delimiter.
  185. # This is typically a comma or space, but can be any string you like
  186. protected $LIST_DELIMITER = ' ';
  187. # What you'd call a single record from this table (eg. a "person")
  188. protected $NAME_SINGULAR;
  189. # What you'd call more than one record from this table (eg. "people")
  190. protected $NAME_PLURAL;
  191. # List of fields to sort listing of records by; you can use
  192. # SQL 'ASC' and 'DESC' here if you like.
  193. protected $ORDER_BY = array('media');
  194. # Maximum number of record to display per page in a listing
  195. protected $MAX_RECORDS_PER_PAGE = 20;
  196. # How do you want to page through records in a listing: by number pages ordered
  197. # according to your setting above? Or alphabetically by the letters of the first
  198. # LIST_FIELD?
  199. protected $PAGE_SCHEME = 'alpha'; # alpha [alphabetical] or num [numbered pages; default]
  200. # If you want to order records arbitrarily, add a numeric field to the table and place
  201. # its name here. The generic list scripts can then use it to order table records.
  202. protected $RANK = 'rank';
  203. # ------------------------------------------------------
  204. # Hierarchical table properties
  205. # ------------------------------------------------------
  206. protected $HIERARCHY_TYPE = null;
  207. protected $HIERARCHY_LEFT_INDEX_FLD = null;
  208. protected $HIERARCHY_RIGHT_INDEX_FLD = null;
  209. protected $HIERARCHY_PARENT_ID_FLD = null;
  210. protected $HIERARCHY_DEFINITION_TABLE = null;
  211. protected $HIERARCHY_ID_FLD = null;
  212. protected $HIERARCHY_POLY_TABLE = null;
  213. # ------------------------------------------------------
  214. # Change logging
  215. # ------------------------------------------------------
  216. protected $UNIT_ID_FIELD = null;
  217. protected $LOG_CHANGES_TO_SELF = true;
  218. protected $LOG_CHANGES_USING_AS_SUBJECT = array(
  219. "FOREIGN_KEYS" => array(
  220. ),
  221. "RELATED_TABLES" => array(
  222. )
  223. );
  224. # ------------------------------------------------------
  225. # Labeling
  226. # ------------------------------------------------------
  227. protected $LABEL_TABLE_NAME = 'ca_object_representation_labels';
  228. # ------------------------------------------------------
  229. # Attributes
  230. # ------------------------------------------------------
  231. protected $ATTRIBUTE_TYPE_ID_FLD = 'type_id'; // name of type field for this table - attributes system uses this to determine via ca_metadata_type_restrictions which attributes are applicable to rows of the given type
  232. protected $ATTRIBUTE_TYPE_LIST_CODE = 'object_representation_types'; // list code (ca_lists.list_code) of list defining types for this table
  233. # ------------------------------------------------------
  234. # $FIELDS contains information about each field in the table. The order in which the fields
  235. # are listed here is the order in which they will be returned using getFields()
  236. protected $FIELDS;
  237. # ------------------------------------------------------
  238. # ID numbering
  239. # ------------------------------------------------------
  240. protected $ID_NUMBERING_ID_FIELD = 'idno'; // name of field containing user-defined identifier
  241. protected $ID_NUMBERING_SORT_FIELD = 'idno_sort'; // name of field containing version of identifier for sorting (is normalized with padding to sort numbers properly)
  242. # ------------------------------------------------------
  243. # Search
  244. # ------------------------------------------------------
  245. protected $SEARCH_CLASSNAME = 'ObjectRepresentationSearch';
  246. protected $SEARCH_RESULT_CLASSNAME = 'ObjectRepresentationSearchResult';
  247. # ------------------------------------------------------
  248. # --- Constructor
  249. #
  250. # This is a function called when a new instance of this object is created. This
  251. # standard constructor supports three calling modes:
  252. #
  253. # 1. If called without parameters, simply creates a new, empty objects object
  254. # 2. If called with a single, valid primary key value, creates a new objects object and loads
  255. # the record identified by the primary key value
  256. #
  257. # ------------------------------------------------------
  258. public function __construct($pn_id=null) {
  259. parent::__construct($pn_id); # call superclass constructor
  260. }
  261. # ------------------------------------------------------
  262. protected function initLabelDefinitions() {
  263. parent::initLabelDefinitions();
  264. $this->BUNDLES['ca_objects'] = array('type' => 'related_table', 'repeating' => true, 'label' => _t('Related objects'));
  265. $this->BUNDLES['ca_entities'] = array('type' => 'related_table', 'repeating' => true, 'label' => _t('Related entities'));
  266. $this->BUNDLES['ca_places'] = array('type' => 'related_table', 'repeating' => true, 'label' => _t('Related places'));
  267. $this->BUNDLES['ca_occurrences'] = array('type' => 'related_table', 'repeating' => true, 'label' => _t('Related occurrences'));
  268. $this->BUNDLES['ca_representation_annotations'] = array('type' => 'related_table', 'repeating' => true, 'label' => _t('Related annotations'));
  269. $this->BUNDLES['ca_list_items'] = array('type' => 'related_table', 'repeating' => true, 'label' => _t('Related vocabulary terms'));
  270. $this->BUNDLES['ca_object_representations_media_display'] = array('type' => 'special', 'repeating' => false, 'label' => _t('Media and preview images'));
  271. }
  272. # ------------------------------------------------------
  273. public function insert() {
  274. // reject if media is empty
  275. if ($this->mediaIsEmpty()) {
  276. $this->postError(2710, _t('No media was specified'), 'ca_object_representations->insert()');
  277. return false;
  278. }
  279. // do insert
  280. if ($vn_rc = parent::insert()) {
  281. $va_media_info = $this->getMediaInfo('media', 'original');
  282. $this->set('md5', $va_media_info['MD5']);
  283. $va_media_info = $this->getMediaInfo('media');
  284. $this->set('original_filename', $va_media_info['ORIGINAL_FILENAME']);
  285. $vn_rc = parent::update($pa_options);
  286. }
  287. return $vn_rc;
  288. }
  289. # ------------------------------------------------------
  290. public function update($pa_options=null) {
  291. if ($vn_rc = parent::update($pa_options)) {
  292. $va_media_info = $this->getMediaInfo('media', 'original');
  293. $this->set('md5', $va_media_info['MD5']);
  294. $va_media_info = $this->getMediaInfo('media');
  295. $this->set('original_filename', $va_media_info['ORIGINAL_FILENAME']);
  296. $vn_rc = parent::update($pa_options);
  297. }
  298. return $vn_rc;
  299. }
  300. # ------------------------------------------------------
  301. public function delete($pn_delete_related=false) {
  302. return parent::delete($pn_delete_related);
  303. }
  304. # ------------------------------------------------------
  305. /**
  306. * Returns true if the media field is set to a non-empty file
  307. **/
  308. public function mediaIsEmpty() {
  309. if (!($vs_media_path = $this->getMediaPath('media', 'original'))) {
  310. $vs_media_path = $this->get('media');
  311. }
  312. if ($vs_media_path) {
  313. if (file_exists($vs_media_path) && (filesize($vs_media_path) > 0)) {
  314. return false;
  315. }
  316. }
  317. // is it a URL?
  318. if ($this->_CONFIG->get('allow_fetching_of_media_from_remote_urls')) {
  319. if (isURL($vs_media_path)) {
  320. return false;
  321. }
  322. }
  323. return true;
  324. }
  325. # ------------------------------------------------------
  326. # Annotations
  327. # ------------------------------------------------------
  328. /**
  329. * Returns annotation type code for currently loaded representation
  330. * Type codes are based upon the mimetype of the representation's media as defined in the annotation_types.conf file
  331. *
  332. * If you pass the options $pn_representation_id parameter then the returned type is for the specified representation rather
  333. * than the currently loaded one.
  334. */
  335. public function getAnnotationType($pn_representation_id=null) {
  336. if (!$pn_representation_id) {
  337. $t_rep = $this;
  338. } else {
  339. $t_rep = new ca_object_representations($pn_representation_id);
  340. }
  341. $va_media_info = $t_rep->getMediaInfo('media');
  342. if (!isset($va_media_info['INPUT'])) { return null; }
  343. if (!isset($va_media_info['INPUT']['MIMETYPE'])) { return null; }
  344. $vs_mimetype = $va_media_info['INPUT']['MIMETYPE'];
  345. $o_type_config = Configuration::load($this->getAppConfig()->get('annotation_type_config'));
  346. $va_mappings = $o_type_config->getAssoc('mappings');
  347. return $va_mappings[$vs_mimetype];
  348. }
  349. # ------------------------------------------------------
  350. public function getAnnotationPropertyCoderInstance($ps_type) {
  351. return ca_representation_annotations::getPropertiesCoderInstance($ps_type);
  352. }
  353. # ------------------------------------------------------
  354. /**
  355. * Returns number of annotations attached to current representation
  356. *
  357. * @param array $pa_options Optional array of options. Supported options are:
  358. * checkAccess - array of access codes to filter count by. Only annotations with an access value set to one of the specified values will be counted.
  359. * @return int Number of annotations
  360. */
  361. public function getAnnotationCount($pa_options=null) {
  362. if (!($vn_representation_id = $this->getPrimaryKey())) { return null; }
  363. if (!is_array($pa_options)) { $pa_options = array(); }
  364. if (!($o_coder = $this->getAnnotationPropertyCoderInstance($this->getAnnotationType()))) {
  365. // does not support annotations
  366. return null;
  367. }
  368. $vs_access_sql = '';
  369. if (is_array($pa_options['checkAccess']) && sizeof($pa_options['checkAccess'])) {
  370. $vs_access_sql = ' AND cra.access IN ('.join(',', $pa_options['checkAccess']).')';
  371. }
  372. $o_db = $this->getDb();
  373. $qr_annotations = $o_db->query("
  374. SELECT cra.annotation_id, cra.locale_id, cra.props, cra.representation_id, cra.user_id, cra.type_code, cra.access, cra.status
  375. FROM ca_representation_annotations cra
  376. WHERE
  377. cra.representation_id = ? {$vs_access_sql}
  378. ", (int)$vn_representation_id);
  379. return $qr_annotations->numRows();
  380. }
  381. # ------------------------------------------------------
  382. /**
  383. * Returns data for annotations attached to current representation
  384. *
  385. * @param array $pa_options Optional array of options. Supported options are:
  386. * checkAccess - array of access codes to filter count by. Only annotations with an access value set to one of the specified values will be returned
  387. * @return array List of annotations attached to the current representation, key'ed on annotation_id. Value is an array will all values; annotation labels are returned in the current locale.
  388. */
  389. public function getAnnotations($pa_options=null) {
  390. if (!($vn_representation_id = $this->getPrimaryKey())) { return null; }
  391. if (!is_array($pa_options)) { $pa_options = array(); }
  392. if (!($o_coder = $this->getAnnotationPropertyCoderInstance($this->getAnnotationType()))) {
  393. // does not support annotations
  394. return null;
  395. }
  396. $o_db = $this->getDb();
  397. $vs_access_sql = '';
  398. if (is_array($pa_options['checkAccess']) && sizeof($pa_options['checkAccess'])) {
  399. $vs_access_sql = ' AND cra.access IN ('.join(',', $pa_options['checkAccess']).')';
  400. }
  401. $qr_annotations = $o_db->query("
  402. SELECT cra.annotation_id, cra.locale_id, cra.props, cra.representation_id, cra.user_id, cra.type_code, cra.access, cra.status
  403. FROM ca_representation_annotations cra
  404. WHERE
  405. cra.representation_id = ? {$vs_access_sql}
  406. ", (int)$vn_representation_id);
  407. $vs_sort_by_property = $this->getAnnotationSortProperty();
  408. $va_annotations = array();
  409. while($qr_annotations->nextRow()) {
  410. $va_tmp = $qr_annotations->getRow();
  411. $o_coder->setPropertyValues($qr_annotations->getVars('props'));
  412. foreach($o_coder->getPropertyList() as $vs_property) {
  413. $va_tmp[$vs_property] = $o_coder->getProperty($vs_property);
  414. $va_tmp[$vs_property.'_raw'] = $o_coder->getProperty($vs_property, true);
  415. }
  416. if (!($vs_sort_key = $va_tmp[$vs_sort_by_property])) {
  417. $vs_sort_key = '_default_';
  418. }
  419. $va_annotations[$vs_sort_key][$qr_annotations->get('annotation_id')] = $va_tmp;
  420. }
  421. // get annotation labels
  422. $qr_annotation_labels = $o_db->query("
  423. SELECT cral.annotation_id, cral.locale_id, cral.name, cral.label_id
  424. FROM ca_representation_annotation_labels cral
  425. INNER JOIN ca_representation_annotations AS cra ON cra.annotation_id = cral.annotation_id
  426. WHERE
  427. cra.representation_id = ? AND cral.is_preferred = 1
  428. ", (int)$vn_representation_id);
  429. $va_labels = array();
  430. while($qr_annotation_labels->nextRow()) {
  431. $va_labels[$qr_annotation_labels->get('annotation_id')][$qr_annotation_labels->get('locale_id')] = $qr_annotation_labels->get('name');
  432. }
  433. if (!isset($pa_options['dontExtraValuesByUserLocale']) || !$pa_options['dontExtraValuesByUserLocale']) {
  434. $va_labels = caExtractValuesByUserLocale($va_labels);
  435. }
  436. ksort($va_annotations, SORT_REGULAR);
  437. $va_sorted_annotations = array();
  438. foreach($va_annotations as $vs_key => $va_values) {
  439. foreach($va_values as $va_val) {
  440. $va_val['labels'] = $va_labels[$va_val['annotation_id']] ? $va_labels[$va_val['annotation_id']] : array();
  441. $va_sorted_annotations[$va_val['annotation_id']] = $va_val;
  442. }
  443. }
  444. return $va_sorted_annotations;
  445. }
  446. # ------------------------------------------------------
  447. public function addAnnotation($pn_locale_id, $pn_user_id, $pa_properties, $pn_status, $pn_access) {
  448. if (!($vn_representation_id = $this->getPrimaryKey())) { return null; }
  449. if (!($o_coder = $this->getAnnotationPropertyCoderInstance($this->getAnnotationType()))) {
  450. // does not support annotations
  451. return null;
  452. }
  453. foreach($o_coder->getPropertyList() as $vs_property) {
  454. if (!$o_coder->setProperty($vs_property, $pa_properties[$vs_property])) {
  455. // error setting values
  456. $this->errors = $o_coder->errors;
  457. return false;
  458. }
  459. }
  460. if (!$o_coder->validate()) {
  461. $this->errors = $o_coder->errors;
  462. return false;
  463. }
  464. $t_annotation = new ca_representation_annotations();
  465. $t_annotation->setMode(ACCESS_WRITE);
  466. $t_annotation->set('representation_id', $vn_representation_id);
  467. $t_annotation->set('type_code', $o_coder->getType());
  468. $t_annotation->set('locale_id', $pn_locale_id);
  469. $t_annotation->set('user_id', $pn_user_id);
  470. $t_annotation->set('status', $pn_status);
  471. $t_annotation->set('access', $pn_access);
  472. $t_annotation->insert();
  473. if ($t_annotation->numErrors()) {
  474. $this->errors = $t_annotation->errors;
  475. return false;
  476. }
  477. foreach($o_coder->getPropertyList() as $vs_property) {
  478. $t_annotation->setPropertyValue($vs_property, $o_coder->getProperty($vs_property));
  479. }
  480. $t_annotation->update();
  481. if ($t_annotation->numErrors()) {
  482. $this->errors = $t_annotation->errors;
  483. return false;
  484. }
  485. return $t_annotation->getPrimaryKey();
  486. }
  487. # ------------------------------------------------------
  488. public function editAnnotation($pn_annotation_id, $pn_locale_id, $pa_properties, $pn_status, $pn_access) {
  489. if (!($vn_representation_id = $this->getPrimaryKey())) { return null; }
  490. if (!($o_coder = $this->getAnnotationPropertyCoderInstance($this->getAnnotationType()))) {
  491. // does not support annotations
  492. return null;
  493. }
  494. foreach($o_coder->getPropertyList() as $vs_property) {
  495. if (!$o_coder->setProperty($vs_property, $pa_properties[$vs_property])) {
  496. // error setting values
  497. $this->errors = $o_coder->errors;
  498. return false;
  499. }
  500. }
  501. if (!$o_coder->validate()) {
  502. $this->errors = $o_coder->errors;
  503. return false;
  504. }
  505. $t_annotation = new ca_representation_annotations($pn_annotation_id);
  506. if ($t_annotation->getPrimaryKey() && ($t_annotation->get('representation_id') == $vn_representation_id)) {
  507. foreach($o_coder->getPropertyList() as $vs_property) {
  508. $t_annotation->setPropertyValue($vs_property, $o_coder->getProperty($vs_property));
  509. }
  510. $t_annotation->setMode(ACCESS_WRITE);
  511. $t_annotation->set('type_code', $o_coder->getType());
  512. $t_annotation->set('locale_id', $pn_locale_id);
  513. $t_annotation->set('status', $pn_status);
  514. $t_annotation->set('access', $pn_access);
  515. $t_annotation->update();
  516. if ($t_annotation->numErrors()) {
  517. $this->errors = $t_annotation->errors;
  518. return false;
  519. }
  520. return true;
  521. }
  522. return false;
  523. }
  524. # ------------------------------------------------------
  525. public function removeAnnotation($pn_annotation_id) {
  526. if (!($vn_representation_id = $this->getPrimaryKey())) { return null; }
  527. $t_annotation = new ca_representation_annotations($pn_annotation_id);
  528. if ($t_annotation->get('representation_id') == $vn_representation_id) {
  529. $t_annotation->setMode(ACCESS_WRITE);
  530. $t_annotation->delete(true);
  531. if ($t_annotation->numErrors()) {
  532. $this->errors = $t_annotation->errors;
  533. return false;
  534. }
  535. return true;
  536. }
  537. return false;
  538. }
  539. # ------------------------------------------------------
  540. #
  541. # ------------------------------------------------------
  542. /**
  543. * Return list of representations that are related to the object(s) this representation is related to
  544. */
  545. public function getOtherRepresentationsInRelatedObjects() {
  546. if (!($vn_representation_id = $this->getPrimaryKey())) { return null; }
  547. $o_db = $this->getDb();
  548. $qr_res = $o_db->query("
  549. SELECT *
  550. FROM ca_object_representations cor
  551. INNER JOIN ca_objects_x_object_representations AS coxor ON cor.representation_id = coxor.representation_id
  552. WHERE
  553. coxor.object_id IN (
  554. SELECT object_id
  555. FROM ca_objects_x_object_representations
  556. WHERE
  557. representation_id = ?
  558. )
  559. ", (int)$vn_representation_id);
  560. $va_reps = array();
  561. while($qr_res->nextRow()) {
  562. $va_reps[$qr_res->get('representation_id')] = $qr_res->getRow();
  563. }
  564. return $va_reps;
  565. }
  566. # ------------------------------------------------------
  567. /**
  568. * Bundle generator - called from BundlableLabelableBaseModelWithAttributes::getBundleFormHTML()
  569. */
  570. protected function getRepresentationAnnotationHTMLFormBundle($po_request, $ps_form_name, $ps_placement_code, $pa_bundle_settings=null, $pa_options=null) {
  571. //if (!$this->getAnnotationType()) { return; } // don't show bundle if this representation doesn't support annotations
  572. $o_view = new View($po_request, $po_request->getViewsDirectoryPath().'/bundles/');
  573. $t_item = new ca_representation_annotations();
  574. $t_item_label = new ca_representation_annotation_labels();
  575. $o_view->setVar('id_prefix', $ps_form_name);
  576. $o_view->setVar('placement_code', $ps_placement_code); // pass placement code
  577. $o_view->setVar('t_item', $t_item);
  578. $o_view->setVar('t_item_label', $t_item_label);
  579. $o_view->setVar('t_subject', $this);
  580. $o_view->setVar('settings', $pa_bundle_settings);
  581. $va_inital_values = array();
  582. if (sizeof($va_items = $this->getAnnotations(array('dontExtraValuesByUserLocale' => true)))) {
  583. $t_rel = $this->getAppDatamodel()->getInstanceByTableName('ca_representation_annotations', true);
  584. $vs_rel_pk = $t_rel->primaryKey();
  585. foreach ($va_items as $vn_id => $va_item) {
  586. if (!($vs_label = $va_item['labels'][$va_item['locale_id']])) { $vs_label = ''; }
  587. $va_inital_values[$va_item[$t_item->primaryKey()]] = array_merge($va_item, array('id' => $va_item[$vs_rel_pk], 'item_type_id' => $va_item['item_type_id'], 'relationship_type_id' => $va_item['relationship_type_id'], 'label' => $vs_label));
  588. }
  589. }
  590. $o_view->setVar('initialValues', $va_inital_values);
  591. return $o_view->render('ca_representation_annotations.php');
  592. }
  593. # ------------------------------------------------------
  594. /**
  595. *
  596. */
  597. protected function _processRepresentationAnnotations($po_request, $ps_form_prefix, $ps_placement_code) {
  598. $va_rel_items = $this->getAnnotations(array('dontExtraValuesByUserLocale' => true));
  599. $o_coder = $this->getAnnotationPropertyCoderInstance($this->getAnnotationType());
  600. foreach($va_rel_items as $vn_id => $va_rel_item) {
  601. $this->clearErrors();
  602. if (strlen($vn_status = $po_request->getParameter($ps_placement_code.$ps_form_prefix.'_ca_representation_annotations_status_'.$va_rel_item['annotation_id'], pString))) {
  603. $vn_access = $po_request->getParameter($ps_placement_code.$ps_form_prefix.'_ca_representation_annotations_access_'.$va_rel_item['annotation_id'], pInteger);
  604. $vn_locale_id = $po_request->getParameter($ps_placement_code.$ps_form_prefix.'_ca_representation_annotations_locale_id_'.$va_rel_item['annotation_id'], pInteger);
  605. $va_properties = array();
  606. foreach($o_coder->getPropertyList() as $vs_property) {
  607. $va_properties[$vs_property] = $po_request->getParameter($ps_placement_code.$ps_form_prefix.'_ca_representation_annotations_'.$vs_property.'_'.$va_rel_item['annotation_id'], pString);
  608. }
  609. // edit annotation
  610. $this->editAnnotation($va_rel_item['annotation_id'], $vn_locale_id, $va_properties, $vn_status, $vn_access);
  611. if ($this->numErrors()) {
  612. $po_request->addActionErrors($this->errors(), 'ca_representation_annotations', $va_rel_item['annotation_id']);
  613. } else {
  614. // try to add/edit label
  615. if ($vs_label = $po_request->getParameter($ps_placement_code.$ps_form_prefix.'_ca_representation_annotations_label_'.$va_rel_item['annotation_id'], pString)) {
  616. $t_annotation = new ca_representation_annotations($va_rel_item['annotation_id']);
  617. if ($t_annotation->getPrimaryKey()) {
  618. $t_annotation->setMode(ACCESS_WRITE);
  619. $va_pref_labels = $t_annotation->getPreferredLabels(array($vn_locale_id), false);
  620. if (sizeof($va_pref_labels)) {
  621. // edit existing label
  622. foreach($va_pref_labels as $vn_annotation_dummy_id => $va_labels_by_locale) {
  623. foreach($va_labels_by_locale as $vn_locale_dummy_id => $va_labels) {
  624. $t_annotation->editLabel($va_labels[0]['label_id'], array('name' => $vs_label), $vn_locale_id, null, true);
  625. }
  626. }
  627. } else {
  628. // create new label
  629. $t_annotation->addLabel(array('name' => $vs_label), $vn_locale_id, null, true);
  630. }
  631. if ($t_annotation->numErrors()) {
  632. $po_request->addActionErrors($t_annotation->errors(), 'ca_representation_annotations', 'new_'.$vn_c);
  633. }
  634. }
  635. }
  636. }
  637. } else {
  638. // is it a delete key?
  639. $this->clearErrors();
  640. if (($po_request->getParameter($ps_placement_code.$ps_form_prefix.'_ca_representation_annotations_'.$va_rel_item['annotation_id'].'_delete', pInteger)) > 0) {
  641. // delete!
  642. $this->removeAnnotation($va_rel_item['annotation_id']);
  643. if ($this->numErrors()) {
  644. $po_request->addActionErrors($this->errors(), 'ca_representation_annotations', $va_rel_item['annotation_id']);
  645. }
  646. }
  647. }
  648. }
  649. // check for new annotations to add
  650. foreach($_REQUEST as $vs_key => $vs_value ) {
  651. if (!preg_match('/^'.$ps_placement_code.$ps_form_prefix.'_ca_representation_annotations_status_new_([\d]+)/', $vs_key, $va_matches)) { continue; }
  652. $vn_c = intval($va_matches[1]);
  653. if (strlen($vn_status = $po_request->getParameter($ps_placement_code.$ps_form_prefix.'_ca_representation_annotations_status_new_'.$vn_c, pString)) > 0) {
  654. $vn_access = $po_request->getParameter($ps_placement_code.$ps_form_prefix.'_ca_representation_annotations_access_new_'.$vn_c, pInteger);
  655. $vn_locale_id = $po_request->getParameter($ps_placement_code.$ps_form_prefix.'_ca_representation_annotations_locale_id_new_'.$vn_c, pInteger);
  656. $va_properties = array();
  657. foreach($o_coder->getPropertyList() as $vs_property) {
  658. $va_properties[$vs_property] = $po_request->getParameter($ps_placement_code.$ps_form_prefix.'_ca_representation_annotations_'.$vs_property.'_new_'.$vn_c, pString);
  659. }
  660. // create annotation
  661. $vn_annotation_id = $this->addAnnotation($vn_locale_id, $po_request->getUserID(), $va_properties, $vn_status, $vn_access);
  662. if ($this->numErrors()) {
  663. $po_request->addActionErrors($this->errors(), 'ca_representation_annotations', 'new_'.$vn_c);
  664. } else {
  665. // try to add label
  666. if ($vs_label = $po_request->getParameter($ps_placement_code.$ps_form_prefix.'_ca_representation_annotations_label_new_'.$vn_c, pString)) {
  667. $t_annotation = new ca_representation_annotations($vn_annotation_id);
  668. if ($t_annotation->getPrimaryKey()) {
  669. $t_annotation->setMode(ACCESS_WRITE);
  670. $t_annotation->addLabel(array('name' => $vs_label), $vn_locale_id, null, true);
  671. if ($t_annotation->numErrors()) {
  672. $po_request->addActionErrors($t_annotation->errors(), 'ca_representation_annotations', 'new_'.$vn_c);
  673. }
  674. }
  675. }
  676. }
  677. }
  678. }
  679. return true;
  680. }
  681. # ------------------------------------------------------
  682. public function useBundleBasedAnnotationEditor() {
  683. if (!($o_coder = $this->getAnnotationPropertyCoderInstance($this->getAnnotationType()))) {
  684. // does not support annotations
  685. return false;
  686. }
  687. return $o_coder->useBundleBasedAnnotationEditor();
  688. }
  689. # ------------------------------------------------------
  690. public function getAnnotationSortProperty() {
  691. if (!($o_coder = $this->getAnnotationPropertyCoderInstance($this->getAnnotationType()))) {
  692. // does not support annotations
  693. return false;
  694. }
  695. return $o_coder->getAnnotationSortProperty();
  696. }
  697. # ------------------------------------------------------
  698. # Annotation display
  699. # ------------------------------------------------------
  700. public function getDisplayMediaWithAnnotationsHTMLBundle($po_request, $ps_version, $pa_options=null) {
  701. if (!is_array($pa_options)) { $pa_options = array(); }
  702. $pa_options['poster_frame_url'] = $this->getMediaUrl('media', 'medium');
  703. if (!($vs_tag = $this->getMediaTag('media', $ps_version, $pa_options))) {
  704. return '';
  705. }
  706. $o_view = new View($po_request, $po_request->getViewsDirectoryPath().'/bundles/');
  707. $o_view->setVar('viewer_tag', $vs_tag);
  708. $o_view->setVar('annotations', $this->getAnnotations($pa_options));
  709. return $o_view->render('ca_object_representations_display_with_annotations.php', false);
  710. }
  711. # ------------------------------------------------------
  712. # Multifiles
  713. # ------------------------------------------------------
  714. /**
  715. *
  716. */
  717. public function addFile($ps_filepath, $ps_resource_path='/', $pb_allow_duplicates=true) {
  718. if(!$this->getPrimaryKey()) { return null; }
  719. if (!trim($ps_resource_path)) { $ps_resource_path = '/'; }
  720. $t_multifile = new ca_object_representation_multifiles();
  721. if (!$pb_allow_duplicates) {
  722. if ($t_multifile->load(array('resource_path' => $ps_resource_path, 'representation_id' => $this->getPrimaryKey()))) {
  723. return null;
  724. }
  725. }
  726. $t_multifile->setMode(ACCESS_WRITE);
  727. $t_multifile->set('representation_id', $this->getPrimaryKey());
  728. $t_multifile->set('media', $ps_filepath);
  729. $t_multifile->set('resource_path', $ps_resource_path);
  730. $t_multifile->insert();
  731. if ($t_multifile->numErrors()) {
  732. $this->errors = array_merge($this->errors, $t_multifile->errors);
  733. return false;
  734. }
  735. return $t_multifile;
  736. }
  737. # ------------------------------------------------------
  738. /**
  739. *
  740. */
  741. public function removeFile($pn_multifile_id) {
  742. if(!$this->getPrimaryKey()) { return null; }
  743. $t_multifile = new ca_object_representation_multifiles($pn_multifile_id);
  744. if ($t_multifile->get('representation_id') == $this->getPrimaryKey()) {
  745. $t_multifile->setMode(ACCESS_WRITE);
  746. $t_multifile->delete();
  747. if ($t_multifile->numErrors()) {
  748. $this->errors = array_merge($this->errors, $t_multifile->errors);
  749. return false;
  750. }
  751. } else {
  752. $this->postError(2720, _t('File is not part of this representation'), 'ca_object_representations->removeFile()');
  753. return false;
  754. }
  755. return true;
  756. }
  757. # ------------------------------------------------------
  758. /**
  759. *
  760. */
  761. public function removeAllFiles() {
  762. if(!$this->getPrimaryKey()) { return null; }
  763. $va_file_ids = array_keys($this->getFileList());
  764. foreach($va_file_ids as $vn_id) {
  765. $this->removeFile($vn_id);
  766. if($this->numErrors()) {
  767. return false;
  768. }
  769. }
  770. return true;
  771. }
  772. # ------------------------------------------------------
  773. /**
  774. *
  775. */
  776. public function getFileList($pn_representation_id=null, $pn_start=null, $pn_num_files=null, $pa_versions=null) {
  777. if(!($vn_representation_id = $pn_representation_id)) {
  778. if (!($vn_representation_id = $this->getPrimaryKey())) {
  779. return null;
  780. }
  781. }
  782. if (!is_array($pa_versions)) {
  783. $pa_versions = array('preview');
  784. }
  785. $vs_limit_sql = '';
  786. if (!is_null($pn_start) && !is_null($pn_num_files)) {
  787. if (($pn_start >= 0) && ($pn_num_files >= 1)) {
  788. $vs_limit_sql = "LIMIT {$pn_start}, {$pn_num_files}";
  789. }
  790. }
  791. $o_db= $this->getDb();
  792. $qr_res = $o_db->query("
  793. SELECT *
  794. FROM ca_object_representation_multifiles
  795. WHERE
  796. representation_id = ?
  797. {$vs_limit_sql}
  798. ", (int)$vn_representation_id);
  799. $va_files = array();
  800. while($qr_res->nextRow()) {
  801. $vn_multifile_id = $qr_res->get('multifile_id');
  802. $va_files[$vn_multifile_id] = $qr_res->getRow();
  803. unset($va_files[$vn_multifile_id]['media']);
  804. foreach($pa_versions as $vn_i => $vs_version) {
  805. $va_files[$vn_multifile_id][$vs_version.'_tag'] = $qr_res->getMediaTag('media', $vs_version);
  806. $va_files[$vn_multifile_id][$vs_version.'_url'] = $qr_res->getMediaUrl('media', $vs_version);
  807. $va_info = $qr_res->getMediaInfo('media', $vs_version);
  808. $va_files[$vn_multifile_id][$vs_version.'_width'] = $va_info['WIDTH'];
  809. $va_files[$vn_multifile_id][$vs_version.'_height'] = $va_info['HEIGHT'];
  810. }
  811. }
  812. return $va_files;
  813. }
  814. # ------------------------------------------------------
  815. /**
  816. *
  817. */
  818. public function getFileInstance($pn_multifile_id) {
  819. if(!$this->getPrimaryKey()) { return null; }
  820. $t_multifile = new ca_object_representation_multifiles($pn_multifile_id);
  821. if ($t_multifile->get('representation_id') == $this->getPrimaryKey()) {
  822. return $t_multifile;
  823. }
  824. return null;
  825. }
  826. # ------------------------------------------------------
  827. /**
  828. *
  829. */
  830. public function numFiles($pn_representation_id=null) {
  831. if(!($vn_representation_id = $pn_representation_id)) {
  832. if (!($vn_representation_id = $this->getPrimaryKey())) {
  833. return null;
  834. }
  835. }
  836. $o_db= $this->getDb();
  837. $qr_res = $o_db->query("
  838. SELECT count(*) c
  839. FROM ca_object_representation_multifiles
  840. WHERE
  841. representation_id = ?
  842. ", (int)$vn_representation_id);
  843. if($qr_res->nextRow()) {
  844. return intval($qr_res->get('c'));
  845. }
  846. return 0;
  847. }
  848. # ------------------------------------------------------
  849. /**
  850. * Matching method to ca_objects::getRepresentations(), except this one only returns a single representation - the currently loaded one
  851. */
  852. public function getRepresentations($pa_versions=null, $pa_version_sizes=null, $pa_options=null) {
  853. if (!($vn_object_id = $this->getPrimaryKey())) { return null; }
  854. if (!is_array($pa_options)) { $pa_options = array(); }
  855. if (!is_array($pa_versions)) {
  856. $pa_versions = array('preview170');
  857. }
  858. $o_db = $this->getDb();
  859. $qr_reps = $o_db->query("
  860. SELECT caor.representation_id, caor.media, caor.access, caor.status, l.name, caor.locale_id, caor.media_metadata, caor.type_id
  861. FROM ca_object_representations caor
  862. LEFT JOIN ca_locales AS l ON caor.locale_id = l.locale_id
  863. WHERE
  864. caor.representation_id = ?
  865. {$vs_is_primary_sql}
  866. {$vs_access_sql}
  867. ORDER BY
  868. l.name ASC
  869. ", (int)$this->getPrimaryKey());
  870. $va_reps = array();
  871. while($qr_reps->nextRow()) {
  872. $va_tmp = $qr_reps->getRow();
  873. $va_tmp['tags'] = array();
  874. $va_tmp['urls'] = array();
  875. $va_info = $qr_reps->getMediaInfo('media');
  876. $va_tmp['info'] = array('original_filename' => $va_info['ORIGINAL_FILENAME']);
  877. foreach ($pa_versions as $vs_version) {
  878. if (is_array($pa_version_sizes) && isset($pa_version_sizes[$vs_version])) {
  879. $vn_width = $pa_version_sizes[$vs_version]['width'];
  880. $vn_height = $pa_version_sizes[$vs_version]['height'];
  881. } else {
  882. $vn_width = $vn_height = 0;
  883. }
  884. if ($vn_width && $vn_height) {
  885. $va_tmp['tags'][$vs_version] = $qr_reps->getMediaTag('media', $vs_version, array_merge($pa_options, array('viewer_width' => $vn_width, 'viewer_height' => $vn_height)));
  886. } else {
  887. $va_tmp['tags'][$vs_version] = $qr_reps->getMediaTag('media', $vs_version, $pa_options);
  888. }
  889. $va_tmp['urls'][$vs_version] = $qr_reps->getMediaUrl('media', $vs_version);
  890. $va_tmp['paths'][$vs_version] = $qr_reps->getMediaPath('media', $vs_version);
  891. $va_tmp['info'][$vs_version] = $qr_reps->getMediaInfo('media', $vs_version);
  892. $va_dimensions = array();
  893. if (isset($va_tmp['info'][$vs_version]['WIDTH']) && isset($va_tmp['info'][$vs_version]['HEIGHT'])) {
  894. if (($vn_w = $va_tmp['info'][$vs_version]['WIDTH']) && ($vn_h = $va_tmp['info'][$vs_version]['WIDTH'])) {
  895. $va_dimensions[] = $va_tmp['info'][$vs_version]['WIDTH'].'p x '.$va_tmp['info'][$vs_version]['HEIGHT'].'p';
  896. }
  897. }
  898. if (isset($va_tmp['info'][$vs_version]['PROPERTIES']['bitdepth']) && ($vn_depth = $va_tmp['info'][$vs_version]['PROPERTIES']['bitdepth'])) {
  899. $va_dimensions[] = intval($vn_depth).' bpp';
  900. }
  901. if (isset($va_tmp['info'][$vs_version]['PROPERTIES']['colorspace']) && ($vs_colorspace = $va_tmp['info'][$vs_version]['PROPERTIES']['colorspace'])) {
  902. $va_dimensions[] = $vs_colorspace;
  903. }
  904. if (isset($va_tmp['info'][$vs_version]['PROPERTIES']['resolution']) && is_array($va_resolution = $va_tmp['info'][$vs_version]['PROPERTIES']['resolution'])) {
  905. if (isset($va_resolution['x']) && isset($va_resolution['y']) && $va_resolution['x'] && $va_resolution['y']) {
  906. // TODO: units for resolution? right now assume pixels per inch
  907. if ($va_resolution['x'] == $va_resolution['y']) {
  908. $va_dimensions[] = $va_resolution['x'].'ppi';
  909. } else {
  910. $va_dimensions[] = $va_resolution['x'].'x'.$va_resolution['y'].'ppi';
  911. }
  912. }
  913. }
  914. if (isset($va_tmp['info'][$vs_version]['PROPERTIES']['duration']) && ($vn_duration = $va_tmp['info'][$vs_version]['PROPERTIES']['duration'])) {
  915. $va_dimensions[] = sprintf("%4.1f", $vn_duration).'s';
  916. }
  917. if (isset($va_tmp['info'][$vs_version]['PROPERTIES']['pages']) && ($vn_pages = $va_tmp['info'][$vs_version]['PROPERTIES']['pages'])) {
  918. $va_dimensions[] = $vn_pages.' '.(($vn_pages == 1) ? _t('page') : _t('pages'));
  919. }
  920. if (!isset($va_tmp['info'][$vs_version]['PROPERTIES']['filesize']) || !($vn_filesize = $va_tmp['info'][$vs_version]['PROPERTIES']['filesize'])) {
  921. $vn_filesize = @filesize($qr_reps->getMediaPath('media', $vs_version));
  922. }
  923. if ($vn_filesize) {
  924. $va_dimensions[] = sprintf("%4.1f", $vn_filesize/(1024*1024)).'mb';
  925. }
  926. $va_tmp['dimensions'][$vs_version] = join('; ', $va_dimensions);
  927. }
  928. if (isset($va_info['INPUT']['FETCHED_FROM']) && ($vs_fetched_from_url = $va_info['INPUT']['FETCHED_FROM'])) {
  929. $va_tmp['fetched_from'] = $vs_fetched_from_url;
  930. $va_tmp['fetched_on'] = (int)$va_info['INPUT']['FETCHED_ON'];
  931. }
  932. $va_tmp['num_multifiles'] = $this->numFiles($this->get('representation_id'));
  933. $va_reps[] = $va_tmp;
  934. }
  935. return $va_reps;
  936. }
  937. # ------------------------------------------------------
  938. /**
  939. *
  940. */
  941. public function getRepresentationViewerHTMLBundle($po_request, $pa_options=null) {
  942. $va_access_values = (isset($pa_options['access']) && is_array($pa_options['access'])) ? $pa_options['access'] : array();
  943. $vs_display_type = (isset($pa_options['display']) && $pa_options['display']) ? $pa_options['display'] : 'media_overlay';
  944. $vs_container_dom_id = (isset($pa_options['containerID']) && $pa_options['containerID']) ? $pa_options['containerID'] : null;
  945. $vn_object_id = (isset($pa_options['object_id']) && $pa_options['object_id']) ? $pa_options['object_id'] : null;
  946. $t_object = new ca_objects($vn_object_id);
  947. $o_view = new View($po_request, $po_request->getViewsDirectoryPath().'/bundles/');
  948. $o_view->setVar('containerID', $vs_container_dom_id);
  949. if (($vn_representation_id = $this->getPrimaryKey()) && ((!sizeof($va_access_values) || in_array($this->get('access'), $va_access_values)))) { // check rep access
  950. $va_rep_display_info = caGetMediaDisplayInfo($vs_display_type, $this->getMediaInfo('media', 'INPUT', 'MIMETYPE'));
  951. $va_rep_display_info['poster_frame_url'] = $this->getMediaUrl('media', $va_rep_display_info['poster_frame_version']);
  952. $o_view->setVar('num_multifiles', $this->numFiles());
  953. $o_view->setVar('display_options', $va_rep_display_info);
  954. $o_view->setVar('representation_id', $pn_representation_id);
  955. $o_view->setVar('t_object_representation', $this);
  956. $o_view->setVar('versions', $va_versions = $this->getMediaVersions('media'));
  957. $t_media = new Media();
  958. $o_view->setVar('version_type', $t_media->getMimetypeTypename($this->getMediaInfo('media', 'original', 'MIMETYPE')));
  959. if ($t_object->getPrimaryKey()) {
  960. $o_view->setVar('reps', $va_reps = $t_object->getRepresentations(array('icon')));
  961. $vn_next_rep = $vn_prev_rep = null;
  962. $va_rep_list = array_values($va_reps);
  963. foreach($va_rep_list as $vn_i => $va_rep) {
  964. if ($va_rep['representation_id'] == $vn_representation_id) {
  965. if (isset($va_rep_list[$vn_i - 1])) {
  966. $vn_prev_rep = $va_rep_list[$vn_i - 1]['representation_id'];
  967. }
  968. if (isset($va_rep_list[$vn_i + 1])) {
  969. $vn_next_rep = $va_rep_list[$vn_i + 1]['representation_id'];
  970. }
  971. $o_view->setVar('representation_index', $vn_i + 1);
  972. }
  973. }
  974. $o_view->setVar('previous_representation_id', $vn_prev_rep);
  975. $o_view->setVar('next_representation_id', $vn_next_rep);
  976. }
  977. $ps_version = $po_request->getParameter('version', pString);
  978. if (!in_array($ps_version, $va_versions)) {
  979. if (!($ps_version = $va_rep_display_info['display_version'])) { $ps_version = null; }
  980. }
  981. $o_view->setVar('version', $ps_version);
  982. $o_view->setVar('version_info', $this->getMediaInfo('media', $ps_version));
  983. $o_view->setVar('t_object', $t_object);
  984. }
  985. return $o_view->render('representation_viewer_html.php');
  986. }
  987. # ------------------------------------------------------
  988. /**
  989. * Returns HTML form bundle (for use in a ca_object_representations editor form) for media
  990. *
  991. * @param HTTPRequest $po_request The current request
  992. * @param string $ps_form_name
  993. * @param string $ps_placement_code
  994. * @param array $pa_bundle_settings
  995. * @param array $pa_options Array of options. Supported options are
  996. * noCache = If set to true then label cache is bypassed; default is true
  997. *
  998. * @return string Rendered HTML bundle
  999. */
  1000. public function getMediaDisplayHTMLFormBundle($po_request, $ps_form_name, $ps_placement_code, $pa_bundle_settings=null, $pa_options=null) {
  1001. global $g_ui_locale;
  1002. $o_view = new View($po_request, $po_request->getViewsDirectoryPath().'/bundles/');
  1003. if(!is_array($pa_options)) { $pa_options = array(); }
  1004. $o_view->setVar('id_prefix', $ps_form_name.'_media_display');
  1005. $o_view->setVar('placement_code', $ps_placement_code); // pass placement code
  1006. $o_view->setVar('settings', $pa_bundle_settings);
  1007. $o_view->setVar('t_subject', $this);
  1008. $va_media_info = $this->getMediaInfo('media');
  1009. $o_view->setVar('representation_typename', $va_media_info['original']['PROPERTIES']['typename']);
  1010. $o_view->setVar('representation_num_multifiles', $this->numFiles());
  1011. return $o_view->render('ca_object_representations_media_display.php');
  1012. }
  1013. # ------------------------------------------------------
  1014. }
  1015. ?>