/** * Get BaseModel instance for given table and optionally load the record with the specified ID * @param string $ps_table table name, e.g. "ca_objects" * @param mixed $pn_id integer primary key value of the record to load, or string idno value for the record to load * @return BaseModel */ protected function _getTableInstance($ps_table, $pn_id = null) { // $pn_id might be a string if the user is fetching by idno if (!in_array($ps_table, $this->opa_valid_tables)) { $this->opa_errors[] = _t("Accessing this table directly is not allowed"); return false; } $vb_include_deleted = intval($this->opo_request->getParameter("include_deleted", pInteger)); $t_instance = $this->opo_dm->getInstanceByTableName($ps_table); if ($pn_id && !is_numeric($pn_id) && ($vs_idno_fld = $t_instance->getProperty('ID_NUMBERING_ID_FIELD')) && preg_match("!^[A-Za-z0-9_\\-\\.,\\[\\]]+\$!", $pn_id)) { // User is loading by idno $va_load_spec = array($vs_idno_fld => $pn_id); if (!$vb_include_deleted && $t_instance->hasField('deleted')) { $va_load_spec['deleted'] = 0; } if (!$t_instance->load($va_load_spec)) { $this->opa_errors[] = _t("idno does not exist"); return false; } else { if (!$vb_include_deleted && $t_instance->get("deleted")) { $this->opa_errors[] = _t("idno does not exist"); return false; } } } else { if ($pn_id > 0) { if (!$t_instance->load($pn_id)) { $this->opa_errors[] = _t("ID does not exist"); return false; } else { if (!$vb_include_deleted && $t_instance->get("deleted")) { $this->opa_errors[] = _t("ID does not exist"); return false; } } } } return $t_instance; }
/** * Return rendered HTML for media viewer for both re * * @param RequestHTTP $po_request * @param array $pa_options * @param array $pa_additional_display_options * @return string HTML output */ function caGetMediaViewerHTMLBundle($po_request, $pa_options = null, $pa_additional_display_options = null) { $va_access_values = isset($pa_options['access']) && is_array($pa_options['access']) ? $pa_options['access'] : array(); $vs_display_type = isset($pa_options['display']) && $pa_options['display'] ? $pa_options['display'] : 'media_overlay'; $vs_container_dom_id = isset($pa_options['containerID']) && $pa_options['containerID'] ? $pa_options['containerID'] : null; $t_subject = isset($pa_options['t_subject']) && $pa_options['t_subject'] ? $pa_options['t_subject'] : null; $t_rep = isset($pa_options['t_representation']) && $pa_options['t_representation'] ? $pa_options['t_representation'] : null; $vn_representation_id = $t_rep ? $t_rep->getPrimaryKey() : null; $t_attr_val = isset($pa_options['t_attribute_value']) && $pa_options['t_attribute_value'] ? $pa_options['t_attribute_value'] : null; $vn_value_id = $t_attr_val ? $t_attr_val->getPrimaryKey() : null; $vn_item_id = isset($pa_options['item_id']) && $pa_options['item_id'] ? $pa_options['item_id'] : null; $vn_order_item_id = isset($pa_options['order_item_id']) && $pa_options['order_item_id'] ? $pa_options['order_item_id'] : null; $vb_media_editor = isset($pa_options['mediaEditor']) && $pa_options['mediaEditor'] ? true : false; $vb_no_controls = isset($pa_options['noControls']) && $pa_options['noControls'] ? true : false; $vn_item_id = isset($pa_options['item_id']) && $pa_options['item_id'] ? $pa_options['item_id'] : null; $vn_subject_id = $t_subject ? $t_subject->getPrimaryKey() : null; if (!$vn_value_id && !$vn_representation_id) { $t_rep->load($t_subject->getPrimaryRepresentationID(array('checkAccess' => $va_access_values))); } $o_view = new View($po_request, $po_request->getViewsDirectoryPath() . '/bundles/'); $t_set_item = new ca_set_items(); if ($vn_item_id) { $t_set_item->load($vn_item_id); } $t_order_item = new ca_commerce_order_items(); if ($vn_order_item_id) { $t_order_item->load($vn_order_item_id); } $o_view->setVar('containerID', $vs_container_dom_id); $o_view->setVar('t_subject', $t_subject); $o_view->setVar('t_representation', $t_rep); if ($vn_representation_id && (!sizeof($va_access_values) || in_array($t_rep->get('access'), $va_access_values))) { // check rep access $va_rep_display_info = caGetMediaDisplayInfo($vs_display_type, $t_rep->getMediaInfo('media', 'INPUT', 'MIMETYPE')); $va_rep_display_info['poster_frame_url'] = $t_rep->getMediaUrl('media', $va_rep_display_info['poster_frame_version']); $o_view->setVar('num_multifiles', $t_rep->numFiles()); if (isset($pa_options['use_book_viewer'])) { $va_rep_display_info['use_book_viewer'] = (bool) $pa_options['use_book_viewer']; } $o_view->setVar('display_type', $vs_display_type); if (is_array($pa_additional_display_options)) { $va_rep_display_info = array_merge($va_rep_display_info, $pa_additional_display_options); } $o_view->setVar('display_options', $va_rep_display_info); $o_view->setVar('representation_id', $vn_representation_id); $o_view->setVar('versions', $va_versions = $t_rep->getMediaVersions('media')); $t_media = new Media(); $o_view->setVar('version_type', $t_media->getMimetypeTypename($t_rep->getMediaInfo('media', 'original', 'MIMETYPE'))); if ($vn_subject_id) { $o_view->setVar('reps', $va_reps = $t_subject->getRepresentations(array('icon'), null, array("return_with_access" => $va_access_values))); $vn_next_rep = $vn_prev_rep = null; $va_rep_list = array_values($va_reps); foreach ($va_rep_list as $vn_i => $va_rep) { if ($va_rep['representation_id'] == $vn_representation_id) { if (isset($va_rep_list[$vn_i - 1])) { $vn_prev_rep = $va_rep_list[$vn_i - 1]['representation_id']; } if (isset($va_rep_list[$vn_i + 1])) { $vn_next_rep = $va_rep_list[$vn_i + 1]['representation_id']; } $o_view->setVar('representation_index', $vn_i + 1); } } $o_view->setVar('previous_representation_id', $vn_prev_rep); $o_view->setVar('next_representation_id', $vn_next_rep); } $ps_version = $po_request->getParameter('version', pString); if (!in_array($ps_version, $va_versions)) { if (!($ps_version = $va_rep_display_info['display_version'])) { $ps_version = null; } } $o_view->setVar('version', $ps_version); $o_view->setVar('version_info', $t_rep->getMediaInfo('media', $ps_version)); $o_view->setVar('t_set_item', $t_set_item); $o_view->setVar('t_order_item', $t_order_item); $o_view->setVar('use_media_editor', $vb_media_editor); $o_view->setVar('noControls', $vb_no_controls); } else { //$t_attr = new ca_attributes($t_attr_val->get('attribute_id')); $t_attr_val->useBlobAsMediaField(true); $va_rep_display_info = caGetMediaDisplayInfo($vs_display_type, $t_attr_val->getMediaInfo('value_blob', 'INPUT', 'MIMETYPE')); $va_rep_display_info['poster_frame_url'] = $t_attr_val->getMediaUrl('value_blob', $va_rep_display_info['poster_frame_version']); $o_view->setVar('num_multifiles', $t_attr_val->numFiles()); if (isset($pa_options['use_book_viewer'])) { $va_rep_display_info['use_book_viewer'] = (bool) $pa_options['use_book_viewer']; } $o_view->setVar('display_type', $vs_display_type); if (is_array($pa_additional_display_options)) { $va_rep_display_info = array_merge($va_rep_display_info, $pa_additional_display_options); } $o_view->setVar('display_options', $va_rep_display_info); $o_view->setVar('representation_id', $vn_representation_id); $o_view->setVar('t_attribute_value', $t_attr_val); $o_view->setVar('versions', $va_versions = $t_attr_val->getMediaVersions('value_blob')); $t_media = new Media(); $o_view->setVar('version_type', $t_media->getMimetypeTypename($t_attr_val->getMediaInfo('value_blob', 'original', 'MIMETYPE'))); $o_view->setVar('reps', array()); $ps_version = $po_request->getParameter('version', pString); if (!in_array($ps_version, $va_versions)) { if (!($ps_version = $va_rep_display_info['display_version'])) { $ps_version = null; } } $o_view->setVar('version', $ps_version); $o_view->setVar('version_info', $t_attr_val->getMediaInfo('value_blob', $ps_version)); $o_view->setVar('t_subject', $t_subject); $o_view->setVar('t_set_item', $t_set_item); $o_view->setVar('t_order_item', $t_order_item); $o_view->setVar('use_media_editor', $vb_media_editor); $o_view->setVar('noControls', $vb_no_controls); } return $o_view->render('representation_viewer_html.php'); }
/** * * * @param RequestHTTP $po_request * @param array $pa_options * @param array $pa_additional_display_options * @return string HTML output */ function caRepresentationViewerHTMLBundleForSearchResult($po_data, $po_request, $pa_options = null, $pa_additional_display_options = null) { $ps_version = $po_request->getParameter('version', pString); $va_access_values = isset($pa_options['access']) && is_array($pa_options['access']) ? $pa_options['access'] : array(); $vs_display_type = isset($pa_options['display']) && $pa_options['display'] ? $pa_options['display'] : 'media_overlay'; $vs_container_dom_id = isset($pa_options['containerID']) && $pa_options['containerID'] ? $pa_options['containerID'] : null; $vn_object_id = isset($pa_options['object_id']) && $pa_options['object_id'] ? $pa_options['object_id'] : null; $vn_item_id = isset($pa_options['item_id']) && $pa_options['item_id'] ? $pa_options['item_id'] : null; $vn_order_item_id = isset($pa_options['order_item_id']) && $pa_options['order_item_id'] ? $pa_options['order_item_id'] : null; $vb_media_editor = isset($pa_options['mediaEditor']) && $pa_options['mediaEditor'] ? true : false; $vb_no_controls = isset($pa_options['noControls']) && $pa_options['noControls'] ? true : false; $vn_item_id = isset($pa_options['item_id']) && $pa_options['item_id'] ? $pa_options['item_id'] : null; $t_object = new ca_objects($vn_object_id); //if (!$t_object->getPrimaryKey()) { return false; } if (!$po_data->getPrimaryKey() && $t_object->getPrimaryKey() && method_exists($po_data, 'load')) { $po_data->load($t_object->getPrimaryRepresentationID(array('checkAccess' => $va_access_values))); } $t_set_item = new ca_set_items(); if ($vn_item_id) { $t_set_item->load($vn_item_id); } $t_order_item = new ca_commerce_order_items(); if ($vn_order_item_id) { $t_order_item->load($vn_order_item_id); } $o_view = new View($po_request, $po_request->getViewsDirectoryPath() . '/bundles/'); $o_view->setVar('t_object', $t_object); $o_view->setVar('t_set_item', $t_set_item); $o_view->setVar('t_order_item', $t_order_item); $o_view->setVar('use_media_editor', $vb_media_editor); $o_view->setVar('noControls', $vb_no_controls); $va_rep_display_info = array(); if (isset($pa_options['use_book_viewer'])) { $va_rep_display_info['use_book_viewer'] = (bool) $pa_options['use_book_viewer']; } if ($t_object->getPrimaryKey()) { $o_view->setVar('reps', $va_reps = $t_object->getRepresentations(array('icon'), null, array("return_with_access" => $va_access_values))); } $t_media = new Media(); $va_buf = array(); while ($po_data->nextHit()) { if (method_exists($po_data, 'numFiles')) { $o_view->setVar('num_multifiles', $po_data->numFiles()); } $o_view->setVar('t_object_representation', $po_data); if (($vn_representation_id = $po_data->getPrimaryKey()) && (!sizeof($va_access_values) || in_array($po_data->get('access'), $va_access_values))) { // check rep access $va_rep_display_info = caGetMediaDisplayInfo($vs_display_type, $vs_mimetype = $po_data->getMediaInfo('media', 'INPUT', 'MIMETYPE')); $va_rep_display_info['poster_frame_url'] = $po_data->getMediaUrl('media', $va_rep_display_info['poster_frame_version']); $va_additional_display_options = array(); if (is_array($pa_additional_display_options) && isset($pa_additional_display_options[$vs_mimetype]) && is_array($pa_additional_display_options[$vs_mimetype])) { $va_additional_display_options = $pa_additional_display_options[$vs_mimetype]; } $o_view->setVar('display_options', caGetMediaDisplayInfo('detail', $vs_mimetype)); $o_view->setVar('display_type', $vs_display_type); $o_view->setVar('representation_id', $vn_representation_id); $o_view->setVar('t_object_representation', $po_data); $o_view->setVar('versions', $va_versions = $po_data->getMediaVersions('media')); $o_view->setVar('containerID', $vs_container_dom_id . $vn_representation_id); $o_view->setVar('version_type', $t_media->getMimetypeTypename($po_data->getMediaInfo('media', 'original', 'MIMETYPE'))); if ($t_object->getPrimaryKey()) { $vn_next_rep = $vn_prev_rep = null; $va_rep_list = array_values($va_reps); foreach ($va_rep_list as $vn_i => $va_rep) { if ($va_rep['representation_id'] == $vn_representation_id) { if (isset($va_rep_list[$vn_i - 1])) { $vn_prev_rep = $va_rep_list[$vn_i - 1]['representation_id']; } if (isset($va_rep_list[$vn_i + 1])) { $vn_next_rep = $va_rep_list[$vn_i + 1]['representation_id']; } $o_view->setVar('representation_index', $vn_i + 1); } } $o_view->setVar('previous_representation_id', $vn_prev_rep); $o_view->setVar('next_representation_id', $vn_next_rep); } if (!in_array($ps_version, $va_versions)) { if (!($ps_version = $va_rep_display_info['display_version'])) { $ps_version = null; } } $o_view->setVar('version_info', $po_data->getMediaInfo('media', $ps_version)); $o_view->setVar('version', $ps_version); } $va_buf[$vn_representation_id] = $o_view->render('representation_viewer_html.php'); } return $va_buf; }
/** * @param array $pa_config * @param RequestHTTP $po_request * @return array * @throws Exception */ private static function runSearchEndpoint($pa_config, $po_request) { $o_dm = Datamodel::load(); // load blank instance $t_instance = $o_dm->getInstance($pa_config['table']); if (!$t_instance instanceof BundlableLabelableBaseModelWithAttributes) { throw new Exception('invalid table'); } if (!($ps_q = $po_request->getParameter('q', pString))) { throw new Exception('No query specified'); } $o_search = caGetSearchInstance($pa_config['table']); // restrictToTypes if ($pa_config['restrictToTypes'] && is_array($pa_config['restrictToTypes']) && sizeof($pa_config['restrictToTypes']) > 0) { $va_type_filter = array(); foreach ($pa_config['restrictToTypes'] as $vs_type_code) { $va_type_filter[] = caGetListItemID($t_instance->getTypeListCode(), $vs_type_code); } $o_search->addResultFilter($t_instance->tableName() . '.type_id', 'IN', join(",", $va_type_filter)); } $o_res = $o_search->search($ps_q, array('sort' => $po_request->getParameter('sort', pString), 'sortDirection' => $po_request->getParameter('sortDirection', pString), 'start' => $po_request->getParameter('start', pInteger), 'limit' => $po_request->getParameter('limit', pInteger), 'checkAccess' => $pa_config['checkAccess'])); $va_return = array(); while ($o_res->nextHit()) { $va_hit = array(); foreach ($pa_config['content'] as $vs_key => $vs_template) { $va_hit[self::sanitizeKey($vs_key)] = $o_res->getWithTemplate($vs_template); } $va_return[$o_res->get($t_instance->primaryKey(true))] = $va_hit; } return $va_return; }
/** * @param RequestHTTP $po_request * @param string $ps_form_prefix * @param string $ps_placement_code */ public function _processRelatedSets($po_request, $ps_form_prefix, $ps_placement_code) { require_once __CA_MODELS_DIR__ . '/ca_sets.php'; foreach ($_REQUEST as $vs_key => $vs_value) { // check for new relationships to add if (preg_match("/^{$ps_placement_code}{$ps_form_prefix}_idnew_([\\d]+)/", $vs_key, $va_matches)) { $vn_c = intval($va_matches[1]); if ($vn_new_id = $po_request->getParameter("{$ps_placement_code}{$ps_form_prefix}_idnew_{$vn_c}", pString)) { $t_set = new ca_sets($vn_new_id); $t_set->addItem($this->getPrimaryKey(), null, $po_request->getUserID()); } } // check for delete keys if (preg_match("/^{$ps_placement_code}{$ps_form_prefix}_([\\d]+)_delete/", $vs_key, $va_matches)) { $vn_c = intval($va_matches[1]); $t_set = new ca_sets($vn_c); $t_set->removeItem($this->getPrimaryKey()); } } }
private function _evaluateRequirements(&$pa_requirements) { if (sizeof($pa_requirements) == 0) { return true; } // empty requirements means anyone may access the nav item $vs_result = $vs_value = null; foreach ($pa_requirements as $vs_requirement => $vs_boolean) { $vs_boolean = strtoupper($vs_boolean) == "AND" ? "AND" : "OR"; $va_tmp = explode(':', $vs_requirement); switch (strtolower($va_tmp[0])) { case 'availabletypes': $vn_min_access = sizeof($va_tmp) >= 3 ? constant($va_tmp[2]) : __CA_BUNDLE_ACCESS_EDIT__; $vn_min_types = sizeof($va_tmp) >= 4 ? (int) $va_tmp[3] : 1; $va_types = caGetTypeListForUser($va_tmp[1], array('access' => $vn_min_access)); $vs_value = sizeof($va_types) >= $vn_min_types ? true : false; break; case 'session': if (isset($va_tmp[2])) { $vs_value = $this->opo_request->session->getVar($va_tmp[1]) == $va_tmp[2] ? true : false; } else { $vs_value = $this->opo_request->session->getVar($va_tmp[1]) ? true : false; } break; case 'action': if ($va_tmp[1]) { $vs_value = $this->opo_request->user->canDoAction($va_tmp[1]) ? 1 : 0; } else { $vs_value = 1; } break; case 'parameter': if (isset($va_tmp[2])) { $vs_value = $this->opo_request->getParameter($va_tmp[1], pString) == $va_tmp[2] ? true : false; } else { $vs_value = $this->opo_request->getParameter($va_tmp[1], pString) ? true : false; } break; case 'configuration': $vs_pref = $va_tmp[1]; if ($vb_not = substr($vs_pref, 0, 1) == '!' ? true : false) { $vs_pref = substr($vs_pref, 1); } if ($vb_not && !intval($this->opo_request->config->get($vs_pref)) || !$vb_not && intval($this->opo_request->config->get($vs_pref))) { $vs_value = true; } else { $vs_value = false; } break; case 'global': if (isset($va_tmp[2])) { $vs_value = $GLOBALS[$va_tmp[1]] == $va_tmp[2] ? true : false; } else { $vs_value = $GLOBALS[$va_tmp[1]] ? true : false; } break; default: $vs_value = $vs_value ? true : false; break; } if (is_null($vs_result)) { $vs_result = $vs_value; } else { if ($vs_boolean == "AND") { $vs_result = $vs_result && $vs_value; } else { $vs_result = $vs_result || $vs_value; } } } return $vs_result; }
/** * Sets and saves form element settings, taking parameters off of the request as needed. Does an update() * on the ca_search_forms instance to save settings to the database * * @param RequestHTTP $po_request * @param array|null $pa_options * @return mixed */ public function setSettingsFromHTMLForm($po_request, $pa_options = null) { $va_locales = ca_locales::getLocaleList(array('sort_field' => '', 'sort_order' => 'asc', 'index_by_code' => true, 'available_for_cataloguing_only' => true)); $va_available_settings = $this->getAvailableSettings(); $this->o_instance->setMode(ACCESS_WRITE); $va_values = array(); $vs_id_prefix = caGetOption('id', $pa_options, 'setting'); $vs_placement_code = caGetOption('placement_code', $pa_options, ''); foreach (array_keys($va_available_settings) as $vs_setting) { $va_properties = $va_available_settings[$vs_setting]; if (isset($va_properties['takesLocale']) && $va_properties['takesLocale']) { foreach ($va_locales as $vs_locale => $va_locale_info) { $va_values[$vs_setting][$va_locale_info['locale_id']] = $po_request->getParameter("{$vs_placement_code}{$vs_id_prefix}{$vs_setting}_{$vs_locale}", pString); } } else { if (isset($va_properties['useRelationshipTypeList']) && $va_properties['useRelationshipTypeList'] && $va_properties['height'] > 1 || isset($va_properties['useList']) && $va_properties['useList'] && $va_properties['height'] > 1 || isset($va_properties['showLists']) && $va_properties['showLists'] && $va_properties['height'] > 1 || isset($va_properties['showVocabularies']) && $va_properties['showVocabularies'] && $va_properties['height'] > 1) { $va_values[$vs_setting] = $po_request->getParameter("{$vs_placement_code}{$vs_id_prefix}{$vs_setting}", pArray); } else { switch ($va_properties['formatType']) { case FT_BIT: // skip bits if they're not set in the form; otherwise they default to 'No' even // though the default might be set to 'Yes' the settings definition. $vs_val = $po_request->getParameter("{$vs_placement_code}{$vs_id_prefix}{$vs_setting}", pString); if ($vs_val == '') { continue; } $va_values[$vs_setting] = $vs_val; break; default: $va_values[$vs_setting] = $po_request->getParameter("{$vs_placement_code}{$vs_id_prefix}{$vs_setting}", pString); break; } } } foreach ($va_values as $vs_setting_key => $vs_value) { $this->setSetting($vs_setting, $vs_value); } } return $this->o_instance->update(); }