/** 
  * Add media represention to currently loaded item
  *
  * @param $ps_media_path - the path to the media you want to add
  * @param $pn_type_id - the item_id of the representation type, in the ca_list with list_code 'object_represention_types'
  * @param $pn_locale_id - the locale_id of the locale of the representation
  * @param $pn_status - the status code for the representation (as defined in item_value fields of items in the 'workflow_statuses' ca_list)
  * @param $pn_access - the access code for the representation (as defined in item_value fields of items in the 'access_statuses' ca_list)
  * @param $pb_is_primary - if set to true, representation is designated "primary." Primary representation are used in cases where only one representation is required (such as search results). If a primary representation is already attached to this item, then it will be changed to non-primary as only one representation can be primary at any given time. If no primary representations exist, then the new representation will always be marked primary no matter what the setting of this parameter (there must always be a primary representation, if representations are defined).
  * @param $pa_values - array of attributes to attach to new representation
  * @param $pa_options - an array of options passed through to BaseModel::set() when creating the new representation. Currently supported options:
  *		original_filename - the name of the file being uploaded; will be recorded in the database and used as the filename when the file is subsequently downloaded
  *		rank - a numeric rank used to order the representations when listed
  *		returnRepresentation = if set the newly created ca_object_representations instance is returned rather than the link_id of the newly created relationship record
  *
  * @return mixed Returns primary key (link_id) of the relatipnship row linking the newly created representation to the item; if the 'returnRepresentation' is set then an instance for the newly created ca_object_representations is returned instead; boolean false is returned on error
  */
 public function addRepresentation($ps_media_path, $pn_type_id, $pn_locale_id, $pn_status, $pn_access, $pb_is_primary, $pa_values = null, $pa_options = null)
 {
     if (!($vn_id = $this->getPrimaryKey())) {
         return null;
     }
     if (!$pn_locale_id) {
         $pn_locale_id = ca_locales::getDefaultCataloguingLocaleID();
     }
     $t_rep = new ca_object_representations();
     if ($this->inTransaction()) {
         $o_trans = $this->getTransaction();
         $t_rep->setTransaction($o_trans);
     }
     $t_rep->setMode(ACCESS_WRITE);
     $t_rep->set('type_id', $pn_type_id);
     $t_rep->set('locale_id', $pn_locale_id);
     $t_rep->set('status', $pn_status);
     $t_rep->set('access', $pn_access);
     $t_rep->set('media', $ps_media_path, $pa_options);
     if (is_array($pa_values)) {
         if (isset($pa_values['idno'])) {
             $t_rep->set('idno', $pa_values['idno']);
         }
         foreach ($pa_values as $vs_element => $va_value) {
             if (is_array($va_value)) {
                 // array of values (complex multi-valued attribute)
                 $t_rep->addAttribute(array_merge($va_value, array('locale_id' => $pn_locale_id)), $vs_element);
             } else {
                 // scalar value (simple single value attribute)
                 if ($va_value) {
                     $t_rep->addAttribute(array('locale_id' => $pn_locale_id, $vs_element => $va_value), $vs_element);
                 }
             }
         }
     }
     $t_rep->insert();
     if ($t_rep->numErrors()) {
         $this->errors = array_merge($this->errors, $t_rep->errors());
         return false;
     }
     if ($t_rep->getPreferredLabelCount() == 0) {
         $vs_label = isset($pa_values['name']) && $pa_values['name'] ? $pa_values['name'] : '[' . _t('BLANK') . ']';
         $t_rep->addLabel(array('name' => $vs_label), $pn_locale_id, null, true);
         if ($t_rep->numErrors()) {
             $this->errors = array_merge($this->errors, $t_rep->errors());
             return false;
         }
     }
     if (!($t_oxor = $this->_getRepresentationRelationshipTableInstance())) {
         return null;
     }
     $vs_pk = $this->primaryKey();
     if ($this->inTransaction()) {
         $o_trans = $this->getTransaction();
         $t_oxor->setTransaction($o_trans);
     }
     $t_oxor->setMode(ACCESS_WRITE);
     $t_oxor->set($vs_pk, $vn_id);
     $t_oxor->set('representation_id', $t_rep->getPrimaryKey());
     $t_oxor->set('is_primary', $pb_is_primary ? 1 : 0);
     $t_oxor->set('rank', isset($pa_options['rank']) ? (int) $pa_options['rank'] : null);
     if ($t_oxor->hasField('type_id')) {
         $t_oxor->set('type_id', isset($pa_options['type_id']) ? (int) $pa_options['type_id'] : null);
     }
     $t_oxor->insert();
     if ($t_oxor->numErrors()) {
         $this->errors = array_merge($this->errors, $t_oxor->errors());
         $t_rep->delete();
         if ($t_rep->numErrors()) {
             $this->errors = array_merge($this->errors, $t_rep->errors());
         }
         return false;
     }
     //
     // Perform mapping of embedded metadata for newly uploaded representation with respect
     // to ca_objects and ca_object_representation records
     //
     $va_metadata = $t_rep->get('media_metadata', array('binary' => true));
     if (caExtractEmbeddedMetadata($this, $va_metadata, $pn_locale_id)) {
         $this->update();
     }
     if (isset($pa_options['returnRepresentation']) && (bool) $pa_options['returnRepresentation']) {
         return $t_rep;
     }
     return $t_oxor->getPrimaryKey();
 }
     }
 }
 # --- related objects
 $va_related_objects_links = $t_occurrence->get("ca_objects_x_occurrences.relation_id", array("returnAsArray" => true));
 if (sizeof($va_related_objects_links)) {
     $t_objects_x_occurrences = new ca_objects_x_occurrences();
     $t_object = new ca_objects();
     foreach ($va_related_objects_links as $vn_relation_id) {
         $t_objects_x_occurrences->load($vn_relation_id);
         $va_reps = $t_objects_x_occurrences->get("ca_objects_x_occurrences.representation_list", array("returnAsArray" => true, 'idsOnly' => true));
         if (is_array($va_reps)) {
             foreach ($va_reps as $vn_i => $va_attr) {
                 $t_rep = new ca_object_representations($va_attr['representation_list']);
                 print "<div class='unit'>";
                 if ($ps_mode == "print") {
                     print "<input type='checkbox' checked name='print_fields[]' value='rep" . $t_rep->get("representation_id") . "'> ";
                 }
                 # --- open in media viewer
                 print "<a href='#' onclick='caMediaPanel.showPanel(\"" . caNavUrl($this->request, 'Detail', 'Object', 'GetRepresentationInfo', array('object_id' => $t_objects_x_occurrences->get("ca_objects.object_id"), 'representation_id' => $t_rep->getPrimaryKey())) . "\"); return false;' >" . $t_rep->getMediaTag('media', 'medium') . "</a>";
                 #print $t_rep->getMediaTag('media', 'medium');
                 print "</div><!-- end unit -->";
             }
         }
         print "<div class='unit' style='font-size:11px; font-style:italic;'>" . caNavLink($this->request, $t_objects_x_occurrences->get("ca_objects.preferred_labels.name"), '', 'Detail', 'Object', 'Show', array('object_id' => $t_objects_x_occurrences->get("ca_objects.object_id")));
         if ($va_dates = $t_objects_x_occurrences->get("ca_objects.date", array("returnAsArray" => true))) {
             foreach ($va_dates as $va_date_info) {
                 if ($va_date_info["dc_dates_types"] == $vn_original_date) {
                     print ", " . $va_date_info["dates_value"];
                 }
             }
         }
 /**
  * Returns content for overlay containing detail + editor for object representations only (not media attributes)
  *
  * Expects the following request parameters: 
  *		representation_id = the id of the ca_object_representations record to display; the representation must belong to the specified object
  *		reload = return content for reload of existing editor. [Default=false]
  *
  *	Optional request parameters:
  *		version = The version of the representation to display. If omitted the display version configured in media_display.conf is used
  *
  */
 public function GetRepresentationEditor()
 {
     list($vn_subject_id, $t_subject) = $this->_initView();
     $pn_representation_id = $this->request->getParameter('representation_id', pInteger);
     $pb_reload = (bool) $this->request->getParameter('reload', pInteger);
     $t_rep = new ca_object_representations($pn_representation_id);
     if (!$vn_subject_id) {
         if (is_array($va_subject_ids = $t_rep->get($t_subject->tableName() . '.' . $t_subject->primaryKey(), array('returnAsArray' => true))) && sizeof($va_subject_ids)) {
             $vn_subject_id = array_shift($va_subject_ids);
         } else {
             $this->postError(1100, _t('Invalid object/representation'), 'ObjectEditorController->GetRepresentationEditor');
             return;
         }
     }
     $va_opts = array('display' => 'media_editor', 't_subject' => $t_subject, 't_representation' => $t_rep, 'containerID' => 'caMediaPanelContentArea', 'mediaEditor' => true, 'noControls' => $pb_reload);
     if (strlen($vs_use_book_viewer = $this->request->getParameter('use_book_viewer', pInteger))) {
         $va_opts['use_book_viewer'] = (bool) $vs_use_book_viewer;
     }
     $this->response->addContent(caGetMediaViewerHTMLBundle($this->request, $va_opts));
 }
Example #4
0
 /**
  *
  */
 public static function check_media_fixity($po_opts = null)
 {
     require_once __CA_LIB_DIR__ . "/core/Db.php";
     require_once __CA_MODELS_DIR__ . "/ca_object_representations.php";
     $ps_file_path = strtolower((string) $po_opts->getOption('file'));
     $ps_format = strtolower((string) $po_opts->getOption('format'));
     if (!in_array($ps_format, array('text', 'tab', 'csv'))) {
         $ps_format = 'text';
     }
     $o_db = new Db();
     $o_dm = Datamodel::load();
     $t_rep = new ca_object_representations();
     $vs_report_output = join($ps_format == 'tab' ? "\t" : ",", array(_t('Type'), _t('Error'), _t('Name'), _t('ID'), _t('Version'), _t('File path'), _t('Expected MD5'), _t('Actual MD5'))) . "\n";
     // Verify object representations
     $qr_reps = $o_db->query("SELECT representation_id, idno, media FROM ca_object_representations WHERE deleted = 0");
     print CLIProgressBar::start($vn_rep_count = $qr_reps->numRows(), _t('Checking object representations')) . "\n";
     $vn_errors = 0;
     while ($qr_reps->nextRow()) {
         $vn_representation_id = $qr_reps->get('representation_id');
         print CLIProgressBar::next(1, _t("Checking representation media %1", $vn_representation_id));
         $va_media_versions = $qr_reps->getMediaVersions('media');
         foreach ($va_media_versions as $vs_version) {
             $vs_path = $qr_reps->getMediaPath('media', $vs_version);
             $vs_database_md5 = $qr_reps->getMediaInfo('media', $vs_version, 'MD5');
             $vs_file_md5 = md5_file($vs_path);
             if ($vs_database_md5 !== $vs_file_md5) {
                 $t_rep->load($vn_representation_id);
                 $vs_message = _t("[Object representation][MD5 mismatch] %1; version %2 [%3]", $t_rep->get("ca_objects.preferred_labels.name") . " (" . $t_rep->get("ca_objects.idno") . "); representation_id={$vn_representation_id}", $vs_version, $vs_path);
                 switch ($ps_format) {
                     case 'text':
                     default:
                         $vs_report_output .= "{$vs_message}\n";
                         break;
                     case 'tab':
                     case 'csv':
                         $va_log = array(_t('Object representation'), "MD5 mismatch", caEscapeForDelimitedOutput($t_rep->get("ca_objects.preferred_labels.name") . " (" . $t_rep->get("ca_objects.idno") . ")"), $vn_representation_id, $vs_version, $vs_path, $vs_database_md5, $vs_file_md5);
                         $vs_report_output .= join($ps_format == 'tab' ? "\t" : ",", $va_log) . "\n";
                         break;
                 }
                 CLIUtils::addError($vs_message);
                 $vn_errors++;
             }
         }
     }
     print CLIProgressBar::finish();
     CLIUtils::addMessage(_t('%1 errors for %2 representations', $vn_errors, $vn_rep_count));
     // get all Media elements
     $va_elements = ca_metadata_elements::getElementsAsList(false, null, null, true, false, true, array(16));
     // 16=media
     if (is_array($va_elements) && sizeof($va_elements)) {
         if (is_array($va_element_ids = caExtractValuesFromArrayList($va_elements, 'element_id', array('preserveKeys' => false))) && sizeof($va_element_ids)) {
             $qr_c = $o_db->query("\n\t\t\t\t\t\tSELECT count(*) c\n\t\t\t\t\t\tFROM ca_attribute_values\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\telement_id in (?)\n\t\t\t\t\t", array($va_element_ids));
             if ($qr_c->nextRow()) {
                 $vn_count = $qr_c->get('c');
             } else {
                 $vn_count = 0;
             }
             print CLIProgressBar::start($vn_count, _t('Checking attribute media'));
             $vn_errors = 0;
             foreach ($va_elements as $vs_element_code => $va_element_info) {
                 $qr_vals = $o_db->query("SELECT value_id FROM ca_attribute_values WHERE element_id = ?", (int) $va_element_info['element_id']);
                 $va_vals = $qr_vals->getAllFieldValues('value_id');
                 foreach ($va_vals as $vn_value_id) {
                     $t_attr_val = new ca_attribute_values($vn_value_id);
                     if ($t_attr_val->getPrimaryKey()) {
                         $t_attr_val->setMode(ACCESS_WRITE);
                         $t_attr_val->useBlobAsMediaField(true);
                         print CLIProgressBar::next(1, _t("Checking attribute media %1", $vn_value_id));
                         $va_media_versions = $t_attr_val->getMediaVersions('value_blob');
                         foreach ($va_media_versions as $vs_version) {
                             $vs_path = $t_attr_val->getMediaPath('value_blob', $vs_version);
                             $vs_database_md5 = $t_attr_val->getMediaInfo('value_blob', $vs_version, 'MD5');
                             $vs_file_md5 = md5_file($vs_path);
                             if ($vs_database_md5 !== $vs_file_md5) {
                                 $t_attr = new ca_attributes($vn_attribute_id = $t_attr_val->get('attribute_id'));
                                 $vs_label = "attribute_id={$vn_attribute_id}; value_id={$vn_value_id}";
                                 if ($t_instance = $o_dm->getInstanceByTableNum($t_attr->get('table_num'), true)) {
                                     if ($t_instance->load($t_attr->get('row_id'))) {
                                         $vs_label = $t_instance->get($t_instance->tableName() . '.preferred_labels');
                                         if ($vs_idno = $t_instance->get($t_instance->getProperty('ID_NUMBERING_ID_FIELD'))) {
                                             $vs_label .= " ({$vs_label})";
                                         }
                                     }
                                 }
                                 $vs_message = _t("[Media attribute][MD5 mismatch] %1; value_id=%2; version %3 [%4]", $vs_label, $vn_value_id, $vs_version, $vs_path);
                                 switch ($ps_format) {
                                     case 'text':
                                     default:
                                         $vs_report_output .= "{$vs_message}\n";
                                         break;
                                     case 'tab':
                                     case 'csv':
                                         $va_log = array(_t('Media attribute'), _t("MD5 mismatch"), caEscapeForDelimitedOutput($vs_label), $vn_value_id, $vs_version, $vs_path, $vs_database_md5, $vs_file_md5);
                                         $vs_report_output .= join($ps_format == 'tab' ? "\t" : ",", $va_log);
                                         break;
                                 }
                                 CLIUtils::addError($vs_message);
                                 $vn_errors++;
                             }
                         }
                     }
                 }
             }
             print CLIProgressBar::finish();
             CLIUtils::addMessage(_t('%1 errors for %2 attributes', $vn_errors, $vn_rep_count));
         }
     }
     // get all File elements
     $va_elements = ca_metadata_elements::getElementsAsList(false, null, null, true, false, true, array(15));
     // 15=file
     if (is_array($va_elements) && sizeof($va_elements)) {
         if (is_array($va_element_ids = caExtractValuesFromArrayList($va_elements, 'element_id', array('preserveKeys' => false))) && sizeof($va_element_ids)) {
             $qr_c = $o_db->query("\n\t\t\t\t\t\tSELECT count(*) c\n\t\t\t\t\t\tFROM ca_attribute_values\n\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\telement_id in (?)\n\t\t\t\t\t", array($va_element_ids));
             if ($qr_c->nextRow()) {
                 $vn_count = $qr_c->get('c');
             } else {
                 $vn_count = 0;
             }
             print CLIProgressBar::start($vn_count, _t('Checking attribute files'));
             $vn_errors = 0;
             foreach ($va_elements as $vs_element_code => $va_element_info) {
                 $qr_vals = $o_db->query("SELECT value_id FROM ca_attribute_values WHERE element_id = ?", (int) $va_element_info['element_id']);
                 $va_vals = $qr_vals->getAllFieldValues('value_id');
                 foreach ($va_vals as $vn_value_id) {
                     $t_attr_val = new ca_attribute_values($vn_value_id);
                     if ($t_attr_val->getPrimaryKey()) {
                         $t_attr_val->setMode(ACCESS_WRITE);
                         $t_attr_val->useBlobAsFileField(true);
                         print CLIProgressBar::next(1, _t("Checking attribute file %1", $vn_value_id));
                         $vs_path = $t_attr_val->getFilePath('value_blob');
                         $vs_database_md5 = $t_attr_val->getFileInfo('value_blob', 'MD5');
                         $vs_file_md5 = md5_file($vs_path);
                         if ($vs_database_md5 !== $vs_file_md5) {
                             $t_attr = new ca_attributes($vn_attribute_id = $t_attr_val->get('attribute_id'));
                             $vs_label = "attribute_id={$vn_attribute_id}; value_id={$vn_value_id}";
                             if ($t_instance = $o_dm->getInstanceByTableNum($t_attr->get('table_num'), true)) {
                                 if ($t_instance->load($t_attr->get('row_id'))) {
                                     $vs_label = $t_instance->get($t_instance->tableName() . '.preferred_labels');
                                     if ($vs_idno = $t_instance->get($t_instance->getProperty('ID_NUMBERING_ID_FIELD'))) {
                                         $vs_label .= " ({$vs_label})";
                                     }
                                 }
                             }
                             $vs_message = _t("[File attribute][MD5 mismatch] %1; value_id=%2; version %3 [%4]", $vs_label, $vn_value_id, $vs_version, $vs_path);
                             switch ($ps_format) {
                                 case 'text':
                                 default:
                                     $vs_report_output .= "{$vs_message}\n";
                                     break;
                                 case 'tab':
                                 case 'csv':
                                     $va_log = array(_t('File attribute'), _t("MD5 mismatch"), caEscapeForDelimitedOutput($vs_label), $vn_value_id, $vs_version, $vs_path, $vs_database_md5, $vs_file_md5);
                                     $vs_report_output .= join($ps_format == 'tab' ? "\t" : ",", $va_log);
                                     break;
                             }
                             CLIUtils::addError($vs_message);
                             $vn_errors++;
                         }
                     }
                 }
             }
             print CLIProgressBar::finish();
             CLIUtils::addMessage(_t('%1 errors for %2 attributes', $vn_errors, $vn_rep_count));
         }
     }
     if ($ps_file_path) {
         file_put_contents($ps_file_path, $vs_report_output);
     }
     return true;
 }
 /**
  * Convenience method to edit a representation instance. Allows to you edit a linked representation from an instance.
  * 
  * @param int representation_id
  * @param string $ps_media_path
  * @param int $pn_locale_id
  * @param int $pn_status
  * @param int $pn_access
  * @param bool $pb_is_primary Sets 'primaryness' of representation. If you wish to leave the primary setting to its current value set this null or omit the parameter.
  * @param array $pa_values
  * @param array $pa_options
  *		centerX = Horizontal position of image center used when cropping as a percentage expressed as a decimal between 0 and 1. If omitted existing value is maintained. Note that both centerX and centerY must be specified for the center to be changed.
  *		centerY = Vertical position of image center used when cropping as a percentage expressed as a decimal between 0 and 1. If omitted existing value is maintained. Note that both centerX and centerY must be specified for the center to be changed.
  *
  * @return bool True on success, false on failure, null if no row has been loaded into the object model 
  */
 public function editRepresentation($pn_representation_id, $ps_media_path, $pn_locale_id, $pn_status, $pn_access, $pb_is_primary = null, $pa_values = null, $pa_options = null)
 {
     if (!($vn_id = $this->getPrimaryKey())) {
         return null;
     }
     $va_old_replication_keys = array();
     $t_rep = new ca_object_representations();
     if ($this->inTransaction()) {
         $t_rep->setTransaction($this->getTransaction());
     }
     if (!$t_rep->load(array('representation_id' => $pn_representation_id))) {
         $this->postError(750, _t("Representation id=%1 does not exist", $pn_representation_id), "RepresentableBaseModel->editRepresentation()");
         return false;
     } else {
         $t_rep->setMode(ACCESS_WRITE);
         $t_rep->set('locale_id', $pn_locale_id);
         $t_rep->set('status', $pn_status);
         $t_rep->set('access', $pn_access);
         if ($ps_media_path) {
             if (is_array($va_replication_targets = $t_rep->getUsedMediaReplicationTargets('media'))) {
                 foreach ($va_replication_targets as $vs_target => $va_target_info) {
                     $va_old_replication_keys[$vs_target] = $t_rep->getMediaReplicationKey('media', $vs_target);
                 }
             }
             $t_rep->set('media', $ps_media_path, $pa_options);
         }
         if (is_array($pa_values)) {
             if (isset($pa_values['idno'])) {
                 $t_rep->set('idno', $pa_values['idno']);
             }
             foreach ($pa_values as $vs_element => $va_value) {
                 if (is_array($va_value)) {
                     // array of values (complex multi-valued attribute)
                     $t_rep->replaceAttribute(array_merge($va_value, array('locale_id' => $pn_locale_id)), $vs_element);
                 } else {
                     // scalar value (simple single value attribute)
                     if ($va_value) {
                         $t_rep->replaceAttribute(array('locale_id' => $pn_locale_id, $vs_element => $va_value), $vs_element);
                     }
                 }
             }
         }
         $t_rep->update();
         if ($t_rep->numErrors()) {
             $this->errors = array_merge($this->errors, $t_rep->errors());
             return false;
         }
         // Set image center if specified
         $vn_center_x = caGetOption('centerX', $pa_options, null);
         $vn_center_y = caGetOption('centerY', $pa_options, null);
         if (strlen($vn_center_x) && strlen($vn_center_y) && $vn_center_x >= 0 && $vn_center_y >= 0 && $vn_center_x <= 1 && $vn_center_y <= 1) {
             $t_rep->setMediaCenter('media', (double) $vn_center_x, (double) $vn_center_y);
         }
         if ($ps_media_path) {
             // remove any replicated media
             foreach ($va_old_replication_keys as $vs_target => $vs_old_replication_key) {
                 $t_rep->removeMediaReplication('media', $vs_target, $vs_old_replication_key, array('force' => true));
             }
             // Trigger automatic replication
             $va_auto_targets = $t_rep->getAvailableMediaReplicationTargets('media', 'original', array('trigger' => 'auto', 'access' => $t_rep->get('access')));
             if (is_array($va_auto_targets)) {
                 foreach ($va_auto_targets as $vs_target => $va_target_info) {
                     $t_rep->replicateMedia('media', $vs_target);
                 }
             }
         }
         if (!($t_oxor = $this->_getRepresentationRelationshipTableInstance())) {
             return null;
         }
         $vs_pk = $this->primaryKey();
         if ($this->inTransaction()) {
             $t_oxor->setTransaction($this->getTransaction());
         }
         if (!$t_oxor->load(array($vs_pk => $vn_id, 'representation_id' => $pn_representation_id))) {
             $this->postError(750, _t("Representation id=%1 is not related to %3 id=%2", $pn_representation_id, $vn_id, $this->getProperty('NAME_SINGULAR')), "RepresentableBaseModel->editRepresentation()");
             return false;
         } else {
             $t_oxor->setMode(ACCESS_WRITE);
             if (!is_null($pb_is_primary)) {
                 $t_oxor->set('is_primary', (bool) $pb_is_primary ? 1 : 0);
             }
             if (isset($pa_options['rank']) && ($vn_rank = (int) $pa_options['rank'])) {
                 $t_oxor->set('rank', $vn_rank);
             }
             $t_oxor->update();
             if ($t_oxor->numErrors()) {
                 $this->errors = array_merge($this->errors, $t_oxor->errors());
                 return false;
             }
         }
         return true;
     }
     return false;
 }
Example #6
0
 /**
  * Returns content for overlay containing details for media attribute
  *
  * Expects the following request parameters: 
  *		value_id = the id of the attribute value (ca_attribute_values) record to display
  *
  *	Optional request parameters:
  *		version = The version of the representation to display. If omitted the display version configured in media_display.conf is used
  *
  */
 public function GetMediaInfo()
 {
     $pn_representation_id = $this->request->getParameter('representation_id', pInteger);
     $pn_value_id = $this->request->getParameter('value_id', pInteger);
     if ($pn_value_id) {
         $t_rep = new ca_object_representations();
         $t_attr_val = new ca_attribute_values($pn_value_id);
         $t_attr = new ca_attributes($t_attr_val->get('attribute_id'));
         $t_subject = $this->opo_datamodel->getInstanceByTableNum($t_attr->get('table_num'), true);
         $t_subject->load($t_attr->get('row_id'));
         $va_rep_display_info = caGetMediaDisplayInfo('media_overlay', $t_attr_val->getMediaInfo('value_blob', 'INPUT', 'MIMETYPE'));
         // check subject_id here
         $va_opts = array('t_attribute_value' => $t_attr_val, 'display' => 'media_overlay', 't_subject' => $t_subject, 'containerID' => 'caMediaPanelContentArea');
         if (strlen($vs_use_book_viewer = $this->request->getParameter('use_book_viewer', pInteger))) {
             $va_opts['use_book_viewer'] = (bool) $vs_use_book_viewer;
         }
         $this->response->addContent(caGetMediaViewerHTMLBundle($this->request, $va_opts));
     } elseif ($pn_representation_id) {
         $t_rep = new ca_object_representations($pn_representation_id);
         $t_subject = new ca_objects($vn_subject_id = $this->request->getParameter('object_id', pInteger));
         if (!$vn_subject_id) {
             if (is_array($va_subject_ids = $t_rep->get($t_subject->tableName() . '.' . $t_subject->primaryKey(), array('returnAsArray' => true))) && sizeof($va_subject_ids)) {
                 $vn_subject_id = array_shift($va_subject_ids);
             } else {
                 $this->postError(1100, _t('Invalid object/representation'), 'ObjectEditorController->GetRepresentationInfo');
                 return;
             }
         }
         $va_opts = array('display' => 'media_overlay', 't_subject' => $t_subject, 't_representation' => $t_rep, 'containerID' => 'caMediaPanelContentArea');
         if (strlen($vs_use_book_viewer = $this->request->getParameter('use_book_viewer', pInteger))) {
             $va_opts['use_book_viewer'] = (bool) $vs_use_book_viewer;
         }
         $this->response->addContent(caGetMediaViewerHTMLBundle($this->request, $va_opts));
     } else {
         //
     }
     //$pn_value_id 	= $this->request->getParameter('value_id', pInteger);
     //$this->response->addContent(caGetMediaViewerHTMLBundle($this->request, array('display' => 'media_overlay', 't_attribute_value' => $pn_value_id, 'containerID' => 'caMediaPanelContentArea')));
 }
 /**
  * 
  */
 public function media()
 {
     if (!is_object($t_entity = $this->_checkEntity())) {
         return $t_entity;
     }
     $vn_id = $t_entity->getPrimaryKey();
     $t_list = new ca_lists();
     $vn_exhibition_audio_type_id = $t_list->getItemIDFromList('object_types', 'MemEx_Audio');
     $vs_filter = $this->opo_request->getParameter('filter', pString);
     if (!in_array($vs_filter, array('video', 'audio', 'image', 'pdf'))) {
         $vs_filter = null;
     }
     $t_object = new ca_objects();
     $va_data = array('id' => $vn_id);
     $from = $this->opo_request->getParameter('from', pString);
     $until = $this->opo_request->getParameter('until', pString);
     if (!$until) {
         $until = date('c');
     }
     $vs_range = $from && $until ? self::utcToDb($from) . ' to ' . self::utcToDb($until) : null;
     $o_tep = new TimeExpressionParser();
     $vb_parsed_date = false;
     if ($vs_range) {
         if ($vb_parsed_date = $o_tep->parse($vs_range)) {
             $va_range = $o_tep->getUnixTimestamps();
         }
     }
     $t_rep = new ca_object_representations();
     $t_list = new ca_lists();
     $va_pub_target_values = $t_list->getItemsForList('object_publication_targets', array('extractValuesByUserLocale' => true));
     $va_audio_target_values = $t_list->getItemsForList('audio_publication_targets', array('extractValuesByUserLocale' => true));
     $vn_memorial_exhibition_audio_type_id = $t_list->getItemIDFromList('object_types', 'MemEx_Audio');
     $vn_publish_annotation_id = $t_list->getItemIDFromList('annotation_publication_targets', 'interactive_tables');
     $vn_publish_rep = $t_list->getItemIDFromList("memex_status", "publish");
     $va_objects = $t_entity->getRelatedItems('ca_objects');
     foreach ($va_objects as $vn_relation_id => $va_object_info) {
         $va_timestamp = $t_object->getLastChangeTimestamp($va_object_info['object_id']);
         if ($vb_parsed_date && ($va_timestamp['timestamp'] <= $va_range['start'] || $va_timestamp['timestamp'] >= $va_range['end'])) {
             continue;
         }
         if ($t_object->load($va_object_info['object_id'])) {
             $va_reps = $t_object->getRepresentations(array("preview", "preview170", "icon", "small", "medium", "large", "large_png", "original", "h264_hi", "mp3"));
             if (!is_array($va_reps) || !sizeof($va_reps)) {
                 continue;
             }
             $va_filtered_reps = array();
             foreach ($va_reps as $vn_i => $va_rep) {
                 $va_tmp = explode('/', $vs_mimetype = $va_rep['info']['original']['MIMETYPE']);
                 if ($vs_filter && ($va_tmp[0] != $vs_filter && $va_tmp[1] != $vs_filter)) {
                     continue;
                 }
                 $vb_is_audio = false;
                 if ($t_object->get('type_id') == $vn_memorial_exhibition_audio_type_id) {
                     $va_pub_targets = $t_object->get('ca_objects.audio_publication_targets', array('returnAsArray' => true, 'convertCodesToDisplayText' => false));
                     $vb_is_audio = true;
                 } else {
                     $va_pub_targets = $t_object->get('ca_objects.object_publication_targets', array('returnAsArray' => true, 'convertCodesToDisplayText' => false));
                 }
                 if (!sizeof($va_pub_targets)) {
                     continue;
                 }
                 if (!$t_rep->load($va_rep['representation_id'])) {
                     continue;
                 }
                 if ($t_rep->get("ca_object_representations.memex_status", array('convertCodesToDisplayText' => false)) != $vn_publish_rep) {
                     continue;
                 }
                 // reset filesize property to reflect size of version, not size of original
                 foreach ($va_reps[$vn_i]['paths'] as $vs_version => $vs_path) {
                     $va_reps[$vn_i]['info'][$vs_version]['PROPERTIES']['filesize'] = @filesize($va_reps[$vn_i]['paths'][$vs_version]);
                 }
                 unset($va_reps[$vn_i]['paths']);
                 unset($va_reps[$vn_i]['tags']);
                 unset($va_reps[$vn_i]['media']);
                 unset($va_reps[$vn_i]['media_metadata']);
                 unset($va_reps[$vn_i]['is_primary']);
                 unset($va_reps[$vn_i]['name']);
                 unset($va_reps[$vn_i]['status']);
                 unset($va_reps[$vn_i]['locale_id']);
                 unset($va_reps[$vn_i]['type_id']);
                 $va_reps[$vn_i]['lastupdate_timestamp'] = date('o-m-N', $va_timestamp['timestamp']) . "T" . date('H:i:s', $va_timestamp['timestamp']) . "Z";
                 //date('c', $va_timestamp['timestamp']);
                 $va_reps[$vn_i]['type_id'] = $vn_type_id = $t_object->get('ca_objects.type_id');
                 $va_reps[$vn_i]['typename'] = $t_object->getTypeName();
                 $va_reps[$vn_i]['typecode'] = $t_object->getTypeCode();
                 $va_targets = array();
                 foreach ($va_pub_targets as $vn_attr_id => $va_value) {
                     $va_targets[] = $va_pub_target_values[$va_value['object_publication_targets']]['idno'] ? $va_pub_target_values[$va_value['object_publication_targets']]['idno'] : $va_audio_target_values[$va_value['audio_publication_targets']]['idno'];
                 }
                 $va_reps[$vn_i]['publication_targets'] = $va_targets;
                 $va_reps[$vn_i]['title'] = $t_object->get('ca_objects.memex_title');
                 $va_reps[$vn_i]['credit'] = $t_object->get('ca_objects.memex_credit_line');
                 $va_reps[$vn_i]['caption'] = $t_object->get('ca_objects.memex_caption');
                 if ($t_object->get('type_id') == $vn_exhibition_audio_type_id) {
                     $va_reps[$vn_i]['transcript'] = $t_object->get('ca_objects.final_text_inner_chamber');
                     $va_reps[$vn_i]['attribution'] = $t_object->get('ca_objects.remembrance_attribution');
                 }
                 if ($va_rep['num_multifiles'] > 0) {
                     $va_pages = $t_rep->getFileList($va_rep['representation_id'], null, null, array('page_preview'));
                     $va_page_urls = array();
                     foreach ($va_pages as $vn_file_id => $va_file_info) {
                         $va_page_urls[] = $va_file_info['page_preview_url'];
                     }
                     $va_reps[$vn_i]['page_images'] = $va_page_urls;
                 }
                 $va_reps[$vn_i]['clips'] = array();
                 if (is_array($va_annotations = $t_rep->getAnnotations()) && sizeof($va_annotations)) {
                     foreach ($va_annotations as $vn_index => $va_annotation) {
                         $vn_annotation_id = $va_annotation['annotation_id'];
                         //if ($va_annotation['access'] == 0) { continue; }
                         $t_annotation = new ca_representation_annotations($vn_annotation_id);
                         if ($vn_publish_annotation_id != $t_annotation->get('annotation_publication_targets')) {
                             continue;
                         }
                         // skip ones not marked for publication
                         unset($va_annotation['props']);
                         $va_annotation['description'] = $t_annotation->get('description');
                         $va_annotation['transcript'] = $t_annotation->get('transcript');
                         //$va_annotation['mp3'] = $t_annotation->getAppConfig()->get('site_host')."/service.php/ns11mmServices/Victim/getClip/id/{$vn_annotation_id}";
                         $va_annotation['mp3'] = $t_annotation->getMediaUrl('ca_representation_annotations.preview', 'original');
                         $va_annotation['md5'] = $t_annotation->getMediaInfo('ca_representation_annotations.preview', 'original', 'MD5');
                         $va_reps[$vn_i]['clips'][] = $va_annotation;
                     }
                 }
                 $va_filtered_reps[] = $va_reps[$vn_i];
             }
             if (sizeof($va_filtered_reps)) {
                 $va_data['media'][$va_object_info['object_id']] = $va_filtered_reps;
             }
         }
     }
     return $this->makeResponse($va_data);
 }
        $t_set_item->load($va_item["row_id"]);
        #print_r($va_item);
        $t_rep->load($t_set_item->getPrimaryRepresentationId());
        $vs_image = $t_rep->getMediaTag("media", $vs_version);
        $va_media_info = $t_rep->getMediaInfo("media", $vs_version);
        # --- pad the top to center vertically
        if ($vn_public_display) {
            $vn_height = 450;
        } else {
            $vn_height = 600;
        }
        $vn_top_padding = round(($vn_height - $va_media_info["HEIGHT"]) / 2) . "px";
        print "<div><div style='width:" . $va_media_info["WIDTH"] . "px; margin: 0px auto 0px auto; position:relative;'>";
        print "<div style='padding-top: " . $vn_top_padding . "'>" . caNavLink($this->request, $vs_image, "", "Detail", "Object", "Show", array("object_id" => $va_item["object_id"])) . "</div>";
        print "<div class='caSetsSlideshowCaption'>(" . $i . "/" . sizeof($va_items) . ")</br>";
        if ($t_rep->get("image_credit_line")) {
            print "<i>" . $t_rep->get("image_credit_line") . "</i>";
        }
        print " &ndash; &copy; INFGM";
        #print $t_set_item->get("idno").", ";
        #print "<i>".$va_item["set_item_label"]."</i>, ";
        #if($t_set_item->get("ca_objects.date.display_date")){
        #	print $t_set_item->get("ca_objects.date.display_date").", ";
        #}
        #if($t_set_item->get("ca_objects.technique")){
        #	print $t_set_item->get("ca_objects.technique");
        #}
        print "</div><!-- end caSetsSlideshowCaption -->";
        # --- next and previous buttons absolutely positioned to be along side image
        ?>
		<div id="caSetsSlideshowPrevious" class="caSetsSlideshowPreviousLink">&lsaquo;</div><!-- end caSetsSlideshowPrevious -->
 public function Custom()
 {
     $o_purifier = new HTMLPurifier();
     $pa_print_fields = $this->request->getParameter('print_fields', pArray);
     $pn_occurrence_id = $this->request->getParameter('occurrence_id', pString);
     $t_occurrence = new ca_occurrences($pn_occurrence_id);
     $va_access_values = caGetUserAccessValues($this->request);
     $va_occ_info[] = "<b>" . _t("Lesson type") . "</b>: " . $t_occurrence->getTypeName();
     $va_occ_info2 = array();
     # --- attributes that can be edited when customizing?
     $va_edit_attributes = array("lessonTopic", "learning_standard", "commonCore", "skills");
     foreach (array("gradelevel", "lessonTopic", "learning_standard", "commonCore", "skills", "EdProject", "funder") as $vs_attribute_code) {
         if (in_array($vs_attribute_code, $pa_print_fields) && ($va_values = $t_occurrence->get("ca_occurrences.{$vs_attribute_code}", array("convertCodesToDisplayText" => true, "returnAsArray" => true)))) {
             $va_output_parts = array();
             foreach ($va_values as $k => $va_value) {
                 $vs_value = "";
                 if ($vs_value = trim($va_value[$vs_attribute_code])) {
                     $va_output_parts[] = $vs_value;
                 }
             }
             if (sizeof($va_output_parts)) {
                 if (in_array($vs_attribute_code, $va_edit_attributes)) {
                     $va_occ_info[$vs_attribute_code] = "<b>" . $t_occurrence->getDisplayLabel("ca_occurrences.{$vs_attribute_code}") . "</b>: " . $o_purifier->purify($this->request->getParameter($vs_attribute_code, pString));
                 } else {
                     $va_occ_info[$vs_attribute_code] = "<b>" . $t_occurrence->getDisplayLabel("ca_occurrences.{$vs_attribute_code}") . "</b>: " . join(", ", $va_output_parts);
                 }
             }
         }
     }
     $va_occ_info["HR"] = "<HR>";
     # --- get the attributes the user may have altered
     $va_altered_attributes = array("theme", "guidelines", "sure", "directions", "context", "task", "glossary", "instructions", "essay", "essential", "check");
     foreach ($va_altered_attributes as $vs_attribute_code) {
         if (in_array($vs_attribute_code, $pa_print_fields) && ($vs_value = str_replace("\n", "<br/>", $o_purifier->purify($this->request->getParameter($vs_attribute_code, pString))))) {
             $va_occ_info[$vs_attribute_code] = "<b>" . $t_occurrence->getDisplayLabel("ca_occurrences.{$vs_attribute_code}") . "</b><br/>" . $vs_value;
         }
     }
     # --- get the 2nd block of attributes the user may have altered
     $va_altered_attributes = array("questions", "challenge", "connections", "resources", "transcription", "translation", "essay");
     foreach ($va_altered_attributes as $vs_attribute_code) {
         if (in_array($vs_attribute_code, $pa_print_fields) && ($vs_value = str_replace("\n", "<br/>", $o_purifier->purify($this->request->getParameter($vs_attribute_code, pString))))) {
             $va_occ_info2[$vs_attribute_code] = "<b>" . $t_occurrence->getDisplayLabel("ca_occurrences.{$vs_attribute_code}") . "</b><br/>" . $vs_value;
         }
     }
     # --- related objects
     $va_related_objects_links = $t_occurrence->get("ca_objects_x_occurrences.relation_id", array("returnAsArray" => true));
     $va_related_objects_info = array();
     if (sizeof($va_related_objects_links)) {
         $t_objects_x_occurrences = new ca_objects_x_occurrences();
         foreach ($va_related_objects_links as $vn_relation_id) {
             $va_object_info = array();
             $t_objects_x_occurrences->load($vn_relation_id);
             $va_reps = $t_objects_x_occurrences->get("ca_objects_x_occurrences.representation_list", array("returnAsArray" => true, 'idsOnly' => true));
             $vn_rep_displayed = 0;
             $va_reps_info = array();
             if (is_array($va_reps)) {
                 foreach ($va_reps as $vn_i => $va_attr) {
                     $t_rep = new ca_object_representations($va_attr['representation_list']);
                     if (in_array("rep" . $t_rep->get("representation_id"), $pa_print_fields)) {
                         $vn_rep_displayed = 1;
                         $va_media_info = $t_rep->getMediaInfo('media');
                         $vn_height = $va_media_info["large"]["HEIGHT"];
                         $vn_width = $va_media_info["large"]["WIDTH"];
                         if ($vn_height > 900) {
                             $vn_new_width = 900 * $vn_width / $vn_height;
                             $va_reps_info[] = "<img src='" . $t_rep->getMediaUrl('media', 'large') . "' style='height:900px; width:" . $vn_new_width . "px;'>";
                         } else {
                             $va_reps_info[] = $t_rep->getMediaTag('media', 'large');
                         }
                     }
                 }
             }
             $va_object_info["reps"] = $va_reps_info;
             # --- attributes on objects_x_occurrences record
             $va_attributes = array("caption", "transcription", "translation", "description", "questions");
             $va_md = array();
             foreach ($va_attributes as $vs_attribute_code) {
                 if (in_array($vs_attribute_code . "_related_object_" . $vn_relation_id, $pa_print_fields) && ($vs_value = str_replace("\n", "<br/>", $o_purifier->purify($this->request->getParameter($vs_attribute_code . "_related_object_" . $vn_relation_id, pString))))) {
                     $va_md[$vs_attribute_code] = "<b>" . $t_objects_x_occurrences->getDisplayLabel("ca_objects_x_occurrences.{$vs_attribute_code}") . "</b><br/>" . $vs_value;
                 }
             }
             # --- info from the related object record - only if at least one rep has been selected to print
             $vs_related_object_caption_info = "";
             if ($vn_rep_displayed == 1) {
                 $t_lists = new ca_lists();
                 $vn_original_date = $t_lists->getItemIDFromList("date_types", "dateOriginal");
                 $vs_related_object_caption_info = "<div style='font-size:11px; font-style:italic;'>" . $t_objects_x_occurrences->get("ca_objects.preferred_labels.name");
                 if ($va_dates = $t_objects_x_occurrences->get("ca_objects.date", array("returnAsArray" => true))) {
                     foreach ($va_dates as $va_date_info) {
                         if ($va_date_info["dc_dates_types"] == $vn_original_date) {
                             $vs_related_object_caption_info .= ", " . $va_date_info["dates_value"];
                         }
                     }
                 }
                 if ($t_objects_x_occurrences->get("ca_objects.repository")) {
                     $vs_related_object_caption_info .= ", " . $t_objects_x_occurrences->get("ca_objects.repository", array('delimiter' => ', ', 'convertCodesToDisplayText' => true));
                 }
                 $vs_related_object_caption_info .= ", " . $t_objects_x_occurrences->get("ca_objects.idno") . "</div>";
             }
             $va_object_info["object_caption_info"] = $vs_related_object_caption_info;
             $va_object_info["md"] = $va_md;
             $va_related_objects_info[$vn_relation_id] = $va_object_info;
         }
     }
     $this->view->setVar('related_objects_info', $va_related_objects_info);
     $this->view->setVar('title', $t_occurrence->getLabelForDisplay());
     $this->view->setVar('occ_info', $va_occ_info);
     $this->view->setVar('occ_info2', $va_occ_info2);
     require_once __CA_LIB_DIR__ . '/core/Parsers/dompdf/dompdf_config.inc.php';
     $vs_output_filename = $t_occurrence->getLabelForDisplay();
     $vs_output_file_name = preg_replace("/[^A-Za-z0-9\\-]+/", '_', $vs_output_filename);
     header("Content-Disposition: attachment; filename=export_results.pdf");
     header("Content-type: application/pdf");
     $vs_content = $this->render($this->ops_theme . '/ca_occ_pdf_html.php');
     $o_pdf = new DOMPDF();
     // Page sizes: 'letter', 'legal', 'A4'
     // Orientation:  'portrait' or 'landscape'
     $o_pdf->set_paper("letter", "portrait");
     $o_pdf->load_html($vs_content, 'utf-8');
     $o_pdf->render();
     $o_pdf->stream($vs_output_file_name . ".pdf");
     return;
 }