public function setItemInfo() { $va_access_values = caGetUserAccessValues($this->request); $pn_set_id = $this->request->getParameter('set_id', pInteger); $t_set = new ca_sets($pn_set_id); $this->view->setVar('set_id', $pn_set_id); $pn_set_item_id = $this->request->getParameter('set_item_id', pInteger); $t_set_item = new ca_set_items($pn_set_item_id); $va_set_item_info = array(); $va_items = $t_set->getItemIDs(array("checkAccess" => $va_access_values)); $pn_previous_id = ""; foreach ($va_items as $vn_item_id => $va_item_info) { if ($va_set_item_info["item_id"]) { $va_set_item_info["next_id"] = $vn_item_id; break; } if ($pn_set_item_id == $vn_item_id) { $va_set_item_info["previous_id"] = $pn_previous_id; $va_set_item_info["item_id"] = $vn_item_id; } $pn_previous_id = $vn_item_id; } $va_set_item_info["item_id"] = $t_set_item->get("item_id"); $va_reps = $t_set_item->getRepresentations(array("mediumlarge", "small"), null, array("return_with_access" => $va_access_values)); $va_rep = array_shift($va_rep); $this->view->setVar('t_object_representation', $t_rep = new ca_object_representations($va_rep['representation_id'])); $va_rep_display_info = caGetMediaDisplayInfo('cropped_gallery_media_overlay', $t_rep->getMediaInfo('media', 'INPUT', 'MIMETYPE')); $this->view->setVar('rep_display_version', $va_rep_display_info['display_version']); unset($va_display_info['display_version']); $va_rep_display_info['poster_frame_url'] = $t_rep->getMediaUrl('media', $va_rep_display_info['poster_frame_version']); unset($va_display_info['poster_frame_version']); $this->view->setVar('rep_display_options', $va_rep_display_info); $va_set_item_info["info"] = $va_rep['info']; $va_set_item_info["label"] = $t_set_item->getLabelForDisplay(); $va_set_item_info["description"] = $t_set_item->get($this->opo_plugin_config->get('set_description_element_code'), array('convertLineBreaks' => true)); $va_set_item_info["item_description"] = $t_set_item->get($this->opo_plugin_config->get('set_item_description_element_code'), array('convertLineBreaks' => true)); $va_set_item_info["row_id"] = $t_set_item->get("row_id"); $va_set_item_info["lesson"] = $t_set_item->get('set_item_description'); $t_object = new ca_objects($t_set_item->get("row_id")); $va_set_item_info["object_label"] = $t_object->getLabelForDisplay(); $this->view->setVar('item_info', $va_set_item_info); $this->render($this->ops_theme . '/ajax_item_info_html.php'); }
/** * Get a record summary that is easier to parse when importing to another system */ private function getItemInfoForImport() { if (!($t_instance = $this->_getTableInstance($this->ops_table, $this->opn_id))) { return false; } $o_dm = Datamodel::load(); $t_list = new ca_lists(); $t_locales = new ca_locales(); // // Options // if (!($vs_delimiter = $this->opo_request->getParameter('delimiter', pString))) { $vs_delimiter = "; "; } if (!($vs_flatten = $this->opo_request->getParameter('flatten', pString))) { $vs_flatten = null; } $va_flatten = preg_split("![ ]*[;]+[ ]*!", $vs_flatten); $va_flatten = array_flip($va_flatten); $va_locales = $t_locales->getLocaleList(array("available_for_cataloguing_only" => true)); $va_return = array(); // allow user-defined template to be passed; allows flexible formatting of returned "display" value if (!($vs_template = $this->opo_request->getParameter('template', pString))) { $vs_template = ''; } if ($vs_template) { $va_return['display'] = caProcessTemplateForIDs($vs_template, $this->ops_table, array($this->opn_id)); } // "intrinsic" fields foreach ($t_instance->getFieldsArray() as $vs_field_name => $va_field_info) { $vs_list = null; if (!is_null($vs_val = $t_instance->get($vs_field_name))) { if (preg_match("/^hier\\_/", $vs_field_name)) { continue; } if (preg_match("/\\_sort\$/", $vs_field_name)) { continue; } if ($vs_field_name == $t_instance->primaryKey()) { continue; } if (isset($va_field_info["LIST_CODE"])) { // typical example: type_id $va_item = $t_list->getItemFromListByItemID($va_field_info["LIST_CODE"], $vs_val); if ($t_item = new ca_list_items($va_item["item_id"])) { $vs_val = $t_item->get('idno'); } } $va_return['intrinsic'][$vs_field_name] = $vs_val; } } // preferred labels $va_labels = $t_instance->get($this->ops_table . ".preferred_labels", array("returnAllLocales" => true)); $va_labels = end($va_labels); $vs_display_field_name = $t_instance->getLabelDisplayField(); if (is_array($va_labels)) { foreach ($va_labels as $vn_locale_id => $va_labels_by_locale) { foreach ($va_labels_by_locale as $va_tmp) { $va_label = array(); $va_label['locale'] = $va_locales[$vn_locale_id]["code"]; // add only UI fields to return foreach (array_merge($t_instance->getLabelUIFields(), array('type_id')) as $vs_label_fld) { $va_label[$vs_label_fld] = $va_tmp[$vs_label_fld]; } $va_label[$vs_label_fld] = $va_tmp[$vs_label_fld]; $va_label['label'] = $va_tmp[$vs_display_field_name]; $va_return["preferred_labels"][$va_label['locale']] = $va_label; } } if (isset($va_flatten['locales'])) { $va_return["preferred_labels"] = array_pop(caExtractValuesByUserLocale(array($va_return["preferred_labels"]))); } } // nonpreferred labels $va_labels = $t_instance->get($this->ops_table . ".nonpreferred_labels", array("returnAllLocales" => true)); $va_labels = end($va_labels); if (is_array($va_labels)) { foreach ($va_labels as $vn_locale_id => $va_labels_by_locale) { foreach ($va_labels_by_locale as $va_tmp) { $va_label = array(); $va_label['locale'] = $va_locales[$vn_locale_id]["code"]; // add only UI fields to return foreach (array_merge($t_instance->getLabelUIFields(), array('type_id')) as $vs_label_fld) { $va_label[$vs_label_fld] = $va_tmp[$vs_label_fld]; } $va_return["nonpreferred_labels"][$va_label['locale']] = $va_label; } } if (isset($va_flatten['locales'])) { $va_return["nonpreferred_labels"] = array_pop(caExtractValuesByUserLocale(array($va_return["nonpreferred_labels"]))); } } // attributes $va_codes = $t_instance->getApplicableElementCodes(); foreach ($va_codes as $vs_code) { if ($va_vals = $t_instance->get($this->ops_table . "." . $vs_code, array("convertCodesToDisplayText" => false, "returnAllLocales" => true))) { $va_vals_as_text = end($t_instance->get($this->ops_table . "." . $vs_code, array("convertCodesToDisplayText" => true, "returnAllLocales" => true))); $va_vals_by_locale = end($va_vals); foreach ($va_vals_by_locale as $vn_locale_id => $va_locale_vals) { foreach ($va_locale_vals as $vs_val_id => $va_actual_data) { if (!is_array($va_actual_data)) { continue; } $vs_locale_code = isset($va_locales[$vn_locale_id]["code"]) ? $va_locales[$vn_locale_id]["code"] : "none"; foreach ($va_actual_data as $vs_f => $vs_v) { if (isset($va_vals_as_text[$vn_locale_id][$vs_val_id][$vs_f]) && $vs_v != $va_vals_as_text[$vn_locale_id][$vs_val_id][$vs_f]) { $va_actual_data[$vs_f . '_display'] = $va_vals_as_text[$vn_locale_id][$vs_val_id][$vs_f]; if ($vs_item_idno = caGetListItemIdno($va_actual_data[$vs_f])) { $va_actual_data[$vs_f] = $vs_item_idno; } } } $va_return['attributes'][$vs_code][$vs_locale_code][] = array_merge(array('locale' => $vs_locale_code), $va_actual_data); } } } } if (isset($va_flatten['locales'])) { $va_return['attributes'] = caExtractValuesByUserLocale($va_return['attributes']); } // relationships // yes, not all combinations between these tables have // relationships but it also doesn't hurt to query foreach ($this->opa_valid_tables as $vs_rel_table) { $t_rel = $o_dm->getInstanceByTableName($vs_rel_table, true); // // set-related hacks if ($this->ops_table == "ca_sets" && $vs_rel_table == "ca_tours") { // throw SQL error in getRelatedItems continue; } $va_related_items = $t_instance->get($vs_rel_table, array("returnAsArray" => true, 'returnLocaleCodes' => true, 'groupFields' => true)); if ($this->ops_table == "ca_objects" && $vs_rel_table == "ca_object_representations") { $va_versions = $t_instance->getMediaVersions('media'); if (isset($va_flatten['all'])) { $va_reps = $t_instance->getRepresentations(array('original')); $va_urls = array(); foreach ($va_reps as $vn_i => $va_rep) { $va_urls[] = $va_rep['urls']['original']; } $va_return['representations'] = join($vs_delimiter, $va_urls); } else { $va_return['representations'] = $t_instance->getRepresentations($va_versions); } foreach ($va_return['representations'] as $vn_i => $va_rep) { unset($va_return['representations'][$vn_i]['media']); unset($va_return['representations'][$vn_i]['media_metadata']); } } if (is_array($va_related_items) && sizeof($va_related_items) > 0) { foreach ($va_related_items as $va_rel_item) { $va_item_add = array(); foreach ($va_rel_item as $vs_fld => $vs_val) { if (!is_array($vs_val) && strlen(trim($vs_val)) > 0) { // rewrite and ignore certain field names switch ($vs_fld) { case 'item_type_id': $va_item_add[$vs_fld] = $vs_val; $va_item_add['type_id'] = $vs_val; break; default: $va_item_add[$vs_fld] = $vs_val; break; } } else { if (in_array($vs_fld, array('preferred_labels', 'intrinsic'))) { $va_item_add[$vs_fld] = $vs_val; } } } if ($vs_rel_table == "ca_object_representations") { $t_rep = new ca_object_representations($va_rel_item['representation_id']); $va_item_add['media'] = $t_rep->getMediaUrl('media', 'original'); } $va_return["related"][$vs_rel_table][] = $va_item_add; } } } return $va_return; }
public function downloadCustomWorksheet() { $o_purifier = new HTMLPurifier(); $pn_occurrence_id = $this->request->getParameter('occurrence_id', pInteger); $pn_relation_id = $this->request->getParameter('relation_id', pInteger); $t_objects_x_occurrences = new ca_objects_x_occurrences($pn_relation_id); # --- get the images $pa_print_rep = $this->request->getParameter('print_reps', pArray); $va_images = array(); if (is_array($pa_print_rep)) { $t_rep = new ca_object_representations(); foreach ($pa_print_rep as $vn_i => $vn_rep_id) { $t_rep->load($vn_rep_id); $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; $vs_image = "<img src='" . $t_rep->getMediaUrl('media', 'large') . "' style='height:900px; width:" . $vn_new_width . "px;'>"; } else { $vs_image = $t_rep->getMediaTag("media", "large"); } $va_images[] = $vs_image; } } $this->view->setVar("images", $va_images); $t_lists = new ca_lists(); $vn_original_date = $t_lists->getItemIDFromList("date_types", "dateOriginal"); $vs_image_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_image_info .= ", " . $va_date_info["dates_value"]; } } } if ($t_objects_x_occurrences->get("ca_objects.repository")) { $vs_image_info .= ", " . $t_objects_x_occurrences->get("ca_objects.repository", array('delimiter' => ', ', 'convertCodesToDisplayText' => true)); } $vs_image_info .= ", " . $t_objects_x_occurrences->get("ca_objects.idno") . "</div>"; $this->view->setVar("image_info", $vs_image_info); # --- get the attributes the user may have altered $va_info = array(); $va_attributes = $this->opa_worksheet_attributes; foreach ($va_attributes as $vs_attribute_code => $vs_title) { if ($vs_value = str_replace("\n", "<br/>", $o_purifier->purify($this->request->getParameter($vs_attribute_code, pString)))) { if ($vs_attribute_code == "title") { $va_info[$vs_attribute_code] = $vs_value; } else { $va_info[$vs_attribute_code] = "<b>" . $vs_title . "</b><br/>" . $vs_value; } } else { $va_info[$vs_attribute_code] = ""; } } $this->view->setvar("worksheet_info", $va_info); require_once __CA_LIB_DIR__ . '/core/Parsers/dompdf/dompdf_config.inc.php'; if ($vs_title = $o_purifier->purify($this->request->getParameter($vs_attribute_code, pString))) { $vs_output_filename = $vs_title; } else { $vs_output_filename = "NYSA_Custom_WorkSheet"; } $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 . '/custom_worksheet_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; }