/** * Return array containing information about all hierarchies, including their root_id's * For non-adhoc hierarchies such as places, this call returns the contents of the place_hierarchies list * with some extra information such as the # of top-level items in each hierarchy. * * For an ad-hoc hierarchy like that of an object, there is only ever one hierarchy to display - that of the current object. * So for adhoc hierarchies we just return a single entry corresponding to the root of the current object hierarchy */ public function getHierarchyList($pb_dummy = false) { $vn_pk = $this->getPrimaryKey(); $vs_template = $this->getAppConfig()->get('ca_objects_hierarchy_browser_display_settings'); if (!$vn_pk) { $o_db = new Db(); if (is_array($va_type_ids = caMergeTypeRestrictionLists($this, array())) && sizeof($va_type_ids)) { $qr_res = $o_db->query("\n\t\t\t\t\tSELECT o.object_id, count(*) c\n\t\t\t\t\tFROM ca_objects o\n\t\t\t\t\tINNER JOIN ca_objects AS p ON p.parent_id = o.object_id\n\t\t\t\t\tWHERE o.parent_id IS NULL AND o.type_id IN (?)\n\t\t\t\t\tGROUP BY o.object_id\n\t\t\t\t", array($va_type_ids)); } else { $qr_res = $o_db->query("\n\t\t\t\t\tSELECT o.object_id, count(*) c\n\t\t\t\t\tFROM ca_objects o\n\t\t\t\t\tINNER JOIN ca_objects AS p ON p.parent_id = o.object_id\n\t\t\t\t\tWHERE o.parent_id IS NULL\n\t\t\t\t\tGROUP BY o.object_id\n\t\t\t\t"); } $va_hiers = array(); $va_object_ids = $qr_res->getAllFieldValues('object_id'); $qr_res->seek(0); $va_labels = $this->getPreferredDisplayLabelsForIDs($va_object_ids); while ($qr_res->nextRow()) { $va_hiers[$vn_object_id = $qr_res->get('object_id')] = array('object_id' => $vn_object_id, 'item_id' => $vn_object_id, 'name' => caProcessTemplateForIDs($vs_template, 'ca_objects', array($vn_object_id)), 'hierarchy_id' => $vn_object_id, 'children' => (int) $qr_res->get('c')); } return $va_hiers; } else { // return specific object as root of hierarchy $vs_label = $this->getLabelForDisplay(false); $vs_hier_fld = $this->getProperty('HIERARCHY_ID_FLD'); $vs_parent_fld = $this->getProperty('PARENT_ID_FLD'); $vn_hier_id = $this->get($vs_hier_fld); if ($this->get($vs_parent_fld)) { // currently loaded row is not the root so get the root $va_ancestors = $this->getHierarchyAncestors(); if (!is_array($va_ancestors) || sizeof($va_ancestors) == 0) { return null; } $t_object = new ca_objects($va_ancestors[0]); } else { $t_object =& $this; } $va_children = $t_object->getHierarchyChildren(null, array('idsOnly' => true)); $va_object_hierarchy_root = array($t_object->get($vs_hier_fld) => array('object_id' => $vn_pk, 'item_id' => $vn_pk, 'name' => $vs_name = caProcessTemplateForIDs($vs_template, 'ca_objects', array($vn_pk)), 'hierarchy_id' => $vn_hier_id, 'children' => sizeof($va_children))); return $va_object_hierarchy_root; } }
/** * Download all media attached to specified object (not necessarily open for editing) * Includes all representation media attached to the specified object + any media attached to oter * objects in the same object hierarchy as the specified object. Used by the book viewer interfacce to * initiate a download. */ public function DownloadMedia() { if (!caObjectsDisplayDownloadLink($this->request)) { $this->postError(1100, _t('Cannot download media'), 'DetailController->DownloadMedia'); return; } $pn_object_id = $this->request->getParameter('object_id', pInteger); $t_object = new ca_objects($pn_object_id); if (!($vn_object_id = $t_object->getPrimaryKey())) { return; } $ps_version = $this->request->getParameter('version', pString); if (!$ps_version) { $ps_version = 'original'; } $this->view->setVar('version', $ps_version); $va_ancestor_ids = $t_object->getHierarchyAncestors(null, array('idsOnly' => true, 'includeSelf' => true)); if ($vn_parent_id = array_pop($va_ancestor_ids)) { $t_object->load($vn_parent_id); array_unshift($va_ancestor_ids, $vn_parent_id); } $va_child_ids = $t_object->getHierarchyChildren(null, array('idsOnly' => true)); foreach ($va_ancestor_ids as $vn_id) { array_unshift($va_child_ids, $vn_id); } $vn_c = 1; $va_file_names = array(); $va_file_paths = array(); foreach ($va_child_ids as $vn_object_id) { $t_object = new ca_objects($vn_object_id); if (!$t_object->getPrimaryKey()) { continue; } $va_reps = $t_object->getRepresentations(array($ps_version)); $vs_idno = $t_object->get('idno'); foreach ($va_reps as $vn_representation_id => $va_rep) { $va_rep_info = $va_rep['info'][$ps_version]; $vs_idno_proc = preg_replace('![^A-Za-z0-9_\\-]+!', '_', $vs_idno); switch ($this->request->user->getPreference('downloaded_file_naming')) { case 'idno': $vs_file_name = $vs_idno_proc . '_' . $vn_c . '.' . $va_rep_info['EXTENSION']; break; case 'idno_and_version': $vs_file_name = $vs_idno_proc . '_' . $ps_version . '_' . $vn_c . '.' . $va_rep_info['EXTENSION']; break; case 'idno_and_rep_id_and_version': $vs_file_name = $vs_idno_proc . '_representation_' . $vn_representation_id . '_' . $ps_version . '.' . $va_rep_info['EXTENSION']; break; case 'original_name': default: if ($va_rep['info']['original_filename']) { $va_tmp = explode('.', $va_rep['info']['original_filename']); if (sizeof($va_tmp) > 1) { if (strlen($vs_ext = array_pop($va_tmp)) < 3) { $va_tmp[] = $vs_ext; } } $vs_file_name = join('_', $va_tmp); } else { $vs_file_name = $vs_idno_proc . '_representation_' . $vn_representation_id . '_' . $ps_version; } if (isset($va_file_names[$vs_file_name . '.' . $va_rep_info['EXTENSION']])) { $vs_file_name .= "_{$vn_c}"; } $vs_file_name .= '.' . $va_rep_info['EXTENSION']; break; } $va_file_names[$vs_file_name] = true; $this->view->setVar('version_download_name', $vs_file_name); // // Perform metadata embedding $t_rep = new ca_object_representations($va_rep['representation_id']); if (!($vs_path = caEmbedMetadataIntoRepresentation($t_object, $t_rep, $ps_version))) { $vs_path = $t_rep->getMediaPath('media', $ps_version); } $va_file_paths[$vs_path] = $vs_file_name; $vn_c++; } } if (sizeof($va_file_paths) > 1) { if (!($vn_limit = ini_get('max_execution_time'))) { $vn_limit = 30; } set_time_limit($vn_limit * 2); $o_zip = new ZipFile(); foreach ($va_file_paths as $vs_path => $vs_name) { $o_zip->addFile($vs_path, $vs_name, null, array('compression' => 0)); // don't try to compress } $this->view->setVar('archive_path', $vs_path = $o_zip->output(ZIPFILE_FILEPATH)); $this->view->setVar('archive_name', preg_replace('![^A-Za-z0-9\\.\\-]+!', '_', $t_object->get('idno')) . '.zip'); $this->response->sendHeaders(); $vn_rc = $this->render('Details/object_download_media_binary.php'); $this->response->sendContent(); if ($vs_path) { unlink($vs_path); } } else { foreach ($va_file_paths as $vs_path => $vs_name) { $this->view->setVar('archive_path', $vs_path); $this->view->setVar('archive_name', $vs_name); } $this->response->sendHeaders(); $vn_rc = $this->render('Details/object_download_media_binary.php'); $this->response->sendContent(); } return $vn_rc; }