/** * Given a item_id (request parameter 'id') returns a list of ancestors for use in the hierarchy browser * Returned data is JSON format */ public function getFacetHierarchyAncestorList() { $pn_id = $this->request->getParameter('id', pInteger); $ps_facet_name = $this->request->getParameter('facet', pString); if (!is_array($va_facet_info = $this->opo_browse->getInfoForFacet($ps_facet_name))) { return null; } $va_ancestors = array(); switch ($va_facet_info['type']) { case 'attribute': // is it a list attribute? $t_element = new ca_metadata_elements(); if ($t_element->load(array('element_code' => $va_facet_info['element_code']))) { if ($t_element->get('datatype') == 3) { // 3=list if (!$pn_id) { $t_list = new ca_lists(); $pn_id = $t_list->getRootListItemID($t_element->get('list_id')); } $t_item = new ca_list_items($pn_id); if ($t_item->getPrimaryKey()) { $va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'idsOnly' => true))); array_shift($va_ancestors); } } } break; case 'label': // label facet $va_facet_info['table'] = $this->ops_tablename; // fall through to default case // fall through to default case default: $t_item = $this->opo_datamodel->getInstanceByTableName($va_facet_info['table']); $t_item->load($pn_id); if (method_exists($t_item, "getHierarchyList")) { $va_access_values = caGetUserAccessValues($this->request); $va_facet = $this->opo_browse->getFacet($ps_facet_name, array('sort' => 'name', 'checkAccess' => $va_access_values)); $va_hierarchy_list = $t_item->getHierarchyList(true); $vn_hierarchies_in_use = 0; foreach ($va_hierarchy_list as $vn_i => $va_item) { if (isset($va_facet[$va_item[$t_item->primaryKey()]])) { $vn_hierarchies_in_use++; if ($vn_hierarchies_in_use > 1) { break; } } } } if ($t_item->getPrimaryKey()) { $va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'idsOnly' => true))); if (!is_array($va_ancestors)) { $va_ancestors = array(); } } if ($vn_hierarchies_in_use <= 1) { array_shift($va_ancestors); } break; } $this->view->setVar('ancestors', $va_ancestors); return $this->render('Browse/facet_hierarchy_ancestors_json.php'); }
/** * Given a item_id (request parameter 'id') returns a list of direct children for use in the hierarchy browser * Returned data is JSON format */ public function getFacetHierarchyLevel() { $va_access_values = caGetUserAccessValues($this->request); $ps_facet_name = $this->request->getParameter('facet', pString); $this->opo_browse->setTypeRestrictions(array($this->opn_type_restriction_id)); if (!is_array($va_facet_info = $this->opo_browse->getInfoForFacet($ps_facet_name))) { return null; } $va_facet = $this->opo_browse->getFacet($ps_facet_name, array('sort' => 'name', 'checkAccess' => $va_access_values)); $pa_ids = explode(";", $ps_ids = $this->request->getParameter('id', pString)); if (!sizeof($pa_ids)) { $pa_ids = array(null); } $va_level_data = array(); if (($vn_max_items_per_page = $this->request->getParameter('max', pInteger)) < 1 || $vn_max_items_per_page > 1000) { $vn_max_items_per_page = null; } $t_model = $this->opo_datamodel->getInstanceByTableName($this->ops_tablename, true); $o_config = Configuration::load(); if (!is_array($va_sorts = $o_config->getList($this->ops_tablename . '_hierarchy_browser_sort_values')) || !sizeof($va_sorts)) { $va_sorts = array(); } foreach ($va_sorts as $vn_i => $vs_sort_fld) { $va_tmp = explode(".", $vs_sort_fld); if ($va_tmp[1] == 'preferred_labels') { $va_tmp[0] = $vs_label_table_name; if (!($va_tmp[1] = $va_tmp[2])) { $va_tmp[1] = $vs_label_display_field_name; } unset($va_tmp[2]); $va_sorts[$vn_i] = join(".", $va_tmp); } } if (!in_array($vs_sort_dir = strtolower($o_config->get($this->ops_tablename . '_hierarchy_browser_sort_direction')), array('asc', 'desc'))) { $vs_sort_dir = 'asc'; } $va_expanded_facet = array(); $t_item = new ca_list_items(); foreach ($va_facet as $vn_id => $va_facet_item) { $va_expanded_facet[$vn_id] = true; $va_ancestors = $t_item->getHierarchyAncestors($vn_id, array('idsOnly' => true)); if (is_array($va_ancestors)) { foreach ($va_ancestors as $vn_ancestor_id) { $va_expanded_facet[$vn_ancestor_id] = true; } } } foreach ($pa_ids as $pn_id) { $va_json_data = array('_primaryKey' => 'item_id'); $va_tmp = explode(":", $pn_id); $vn_id = $va_tmp[0]; $vn_start = (int) $va_tmp[1]; if ($vn_start < 0) { $vn_start = 0; } switch ($va_facet_info['type']) { case 'attribute': // is it a list attribute? $t_element = new ca_metadata_elements(); if ($t_element->load(array('element_code' => $va_facet_info['element_code']))) { if ($t_element->get('datatype') == 3) { // 3=list $t_list = new ca_lists(); if (!$vn_id) { $vn_id = $t_list->getRootListItemID($t_element->get('list_id')); } $t_item = new ca_list_items($vn_id); $va_children = $t_item->getHierarchyChildren(null, array('idsOnly' => true)); $va_child_counts = $t_item->getHierarchyChildCountsForIDs($va_children); $qr_res = caMakeSearchResult('ca_list_items', $va_children); $vs_pk = $t_model->primaryKey(); if ($qr_res) { while ($qr_res->nextHit()) { $vn_parent_id = $qr_res->get('ca_list_items.parent_id'); $vn_item_id = $qr_res->get('ca_list_items.item_id'); if (!isset($va_expanded_facet[$vn_item_id])) { continue; } $va_item = array(); $va_item['item_id'] = $vn_item_id; $va_item['name'] = $qr_res->get('ca_list_items.preferred_labels'); $va_item['children'] = isset($va_child_counts[$vn_item_id]) && $va_child_counts[$vn_item_id] ? $va_child_counts[$vn_item_id] : 0; $va_json_data[$vn_item_id] = $va_item; } } } } break; case 'label': // label facet $va_facet_info['table'] = $this->ops_tablename; // fall through to default case // fall through to default case default: if (!$vn_id) { $va_hier_ids = $this->opo_browse->getHierarchyIDsForFacet($ps_facet_name, array('checkAccess' => $va_access_values)); $t_item = $this->opo_datamodel->getInstanceByTableName($va_facet_info['table']); $t_item->load($vn_id); $vn_id = $vn_root = $t_item->getHierarchyRootID(); $va_hierarchy_list = $t_item->getHierarchyList(true); $vn_last_id = null; $vn_c = 0; foreach ($va_hierarchy_list as $vn_i => $va_item) { if (!in_array($vn_i, $va_hier_ids)) { continue; } // only show hierarchies that have items in browse result if ($vn_start <= $vn_c) { $va_item['item_id'] = $va_item[$t_item->primaryKey()]; if (!isset($va_facet[$va_item['item_id']]) && $vn_root == $va_item['item_id']) { continue; } unset($va_item['parent_id']); unset($va_item['label']); $va_json_data[$va_item['item_id']] = $va_item; $vn_last_id = $va_item['item_id']; } $vn_c++; if (!is_null($vn_max_items_per_page) && $vn_c >= $vn_max_items_per_page + $vn_start) { break; } } if (sizeof($va_json_data) == 2) { // if only one hierarchy root (root + _primaryKey in array) then don't bother showing it $vn_id = $vn_last_id; unset($va_json_data[$vn_last_id]); } } if ($vn_id) { $vn_c = 0; foreach ($va_facet as $vn_i => $va_item) { if ($va_item['parent_id'] == $vn_id) { if ($vn_start <= $vn_c) { $va_item['item_id'] = $va_item['id']; $va_item['name'] = $va_item['label']; $va_item['children'] = $va_item['child_count']; unset($va_item['label']); unset($va_item['child_count']); unset($va_item['id']); $va_json_data[$va_item['item_id']] = $va_item; } $vn_c++; if (!is_null($vn_max_items_per_page) && $vn_c >= $vn_max_items_per_page + $vn_start) { break; } } } } break; } $vs_rank_fld = $t_item->getProperty('RANK'); $va_sorted_items = array(); foreach ($va_json_data as $vn_id => $va_node) { if (!is_array($va_node)) { continue; } $vs_key = preg_replace('![^A-Za-z0-9]!', '_', $va_node['name']); if (isset($va_node['sort']) && $va_node['sort']) { $va_sorted_items[$va_node['sort']][$vs_key] = $va_node; } else { if ($vs_rank_fld && ($vs_rank = (int) sprintf("%08d", $va_node[$vs_rank_fld]))) { $va_sorted_items[$vs_rank][$vs_key] = $va_node; } else { $va_sorted_items[$vs_key][$vs_key] = $va_node; } } } ksort($va_sorted_items); if ($vs_sort_dir == 'desc') { $va_sorted_items = array_reverse($va_sorted_items); } $va_json_data = array(); $va_sorted_items = array_slice($va_sorted_items, $vn_start, $vn_max_items_per_page); foreach ($va_sorted_items as $vs_k => $va_v) { ksort($va_v); if ($vs_sort_dir == 'desc') { $va_v = array_reverse($va_v); } $va_json_data = array_merge($va_json_data, $va_v); } $va_json_data['_itemCount'] = sizeof($va_json_data); $va_json_data['_sortOrder'] = array_keys($va_json_data); $va_json_data['_primaryKey'] = $t_model->primaryKey(); // pass the name of the primary key so the hierbrowser knows where to look for item_id's $va_level_data[$pn_id] = $va_json_data; } if (!trim($this->request->getParameter('init', pString))) { $this->opo_result_context->setParameter($ps_facet_name . '_browse_last_id', $pn_id); $this->opo_result_context->saveContext(); } $this->view->setVar('facet_list', $va_level_data); return $this->render('Browse/facet_hierarchy_level_json.php'); }
/** * Returns list of types present for items in set * * @param array $pa_options * user_id = Restricts access to sets accessible by the current user. If omitted then all sets, regardless of access are returned. * checkAccess = Restricts returned sets to those with an public access level with the specified values. If omitted sets are returned regardless of public access (ca_sets.access) value. Can be a single value or array if you wish to filter on multiple public access values. * includeParents = Include parent types in the returned type list. [Default is false] * @return array List of types. Keys are integer type_ids, values are plural type names for the current locale */ public function getTypesForItems($pa_options = null) { if (!($vn_set_id = $this->getPrimaryKey())) { return null; } if (!is_array($pa_options)) { $pa_options = array(); } if ($pa_options['user_id'] && !$this->haveAccessToSet($pa_options['user_id'], __CA_SET_READ_ACCESS__)) { return false; } $o_db = $this->getDb(); $o_dm = $this->getAppDatamodel(); if (!($t_rel_table = $o_dm->getInstanceByTableNum($this->get('table_num'), true))) { return null; } if (!($vs_type_id_fld = $t_rel_table->getTypeFieldName())) { return array(); } // get set items $vs_access_sql = ''; if (isset($pa_options['checkAccess']) && is_array($pa_options['checkAccess']) && sizeof($pa_options['checkAccess']) && $t_rel_table->hasField('access')) { $vs_access_sql = ' AND rel.access IN (' . join(',', $pa_options['checkAccess']) . ')'; } $vs_deleted_sql = ''; if ($t_rel_table->hasField('deleted')) { $vs_deleted_sql = ' AND rel.deleted = 0'; } $va_type_list = method_exists($t_rel_table, "getTypeList") ? $t_rel_table->getTypeList() : array(); $qr_res = $o_db->query("\n\t\t\tSELECT distinct rel.{$vs_type_id_fld}\n\t\t\tFROM ca_set_items casi\n\t\t\tINNER JOIN " . $t_rel_table->tableName() . " AS rel ON rel." . $t_rel_table->primaryKey() . " = casi.row_id\n\t\t\tWHERE\n\t\t\t\tcasi.set_id = ? {$vs_access_sql} {$vs_deleted_sql}\n\t\t", array($vn_set_id)); $va_type_ids = array(); while ($qr_res->nextRow()) { $va_type_ids[$vn_type_id = $qr_res->get($vs_type_id_fld)] = $va_type_list[$vn_type_id]['name_plural']; } if (caGetOption('includeParents', $pa_options, false)) { $t_item = new ca_list_items(); $va_expanded_types = $va_type_ids; $va_labels = $t_item->getPreferredDisplayLabelsForIDs($va_type_ids); foreach ($va_type_ids as $vn_type_id => $vs_type) { if (is_array($va_parents = $t_item->getHierarchyAncestors($vn_type_id, array('idsOnly' => true)))) { foreach ($va_parents as $vn_parent_id) { $va_expanded_types[$vn_parent_id] = $va_labels[$vn_parent_id]; } } } $va_type_ids = $va_expanded_types; } return $va_type_ids; }
print "<div class='unit'><b>" . _t('Era') . ": </b>" . caReturnDefaultIfBlank($vs_era) . "</div>"; print "<div class='unit'><b>" . _t('Period') . ": </b>" . caReturnDefaultIfBlank(str_replace(", -", "", $vs_period)) . "</div>"; print "<div class='unit'><b>" . _t('Epoch') . ": </b>" . caReturnDefaultIfBlank($vs_epoch) . "</div>"; print "<div class='unit'><b>" . _t('Age') . ": </b>" . caReturnDefaultIfBlank($vs_ageNALMA) . "</div>"; print "<div class='unit'><b>" . _t('Zone') . ": </b>" . caReturnDefaultIfBlank($vs_unit) . "</div>"; print "<div class='unit'><b>" . _t('Group') . ": </b>" . caReturnDefaultIfBlank($vs_group) . "</div>"; print "<div class='unit'><b>" . _t('Formation') . ": </b>" . caReturnDefaultIfBlank($vs_formation) . "</div>"; print "<div class='unit'><b>" . _t('Member') . ": </b>" . caReturnDefaultIfBlank($vs_member) . "</div>"; } elseif (in_array($t_object->get('ca_objects.type_id'), $va_track_type_ids)) { # --- Tracks, Tracings if ($vs_other = $t_object->get("ca_objects.other_catalog_number")) { print "<div class='unit'><b>" . _t('Other Catalog Number') . ":</b> {$vs_other}</div><!-- end unit -->"; } if ($vn_taxonomy = $t_object->get('ca_objects.taxonomic_rank', array('idsOnly' => true))) { $t_list_item = new ca_list_items(); $va_hierarchy = caExtractValuesByUserLocale($t_list_item->getHierarchyAncestors($vn_taxonomy, array("includeSelf" => true, "additionalTableToJoin" => "ca_list_item_labels", "additionalTableSelectFields" => array("name_singular")))); $va_hierarchy = array_reverse($va_hierarchy); foreach ($va_hierarchy as $va_hier_taxonomy) { if ($va_hier_taxonomy["parent_id"]) { print "<div class='unit'><b>" . $t_lists->getItemFromListForDisplayByItemID("list_item_types", $va_hier_taxonomy["type_id"]) . ": </b>" . $va_hier_taxonomy["name_singular"] . "</div>"; } } } if ($va_ichnogenus = $t_object->get('ca_objects.ichnogenus', array('convertCodesToDisplayText' => true))) { print "<div class='unit'><b>" . _t('Ichnogenus') . ":</b> " . $va_ichnogenus . "</div>"; } if ($vs_ichnospecies = $t_object->get("ca_objects.ichnospecies")) { print "<div class='unit'><b>" . _t('Ichnospecies') . ":</b> {$vs_ichnospecies}</div><!-- end unit -->"; } if ($vs_clade = $t_object->get("ca_objects.clade", array('convertCodesToDisplayText' => true, 'delimiter' => ', '))) { print "<div class='unit'><b>" . _t('Trackmaker clade') . ":</b> {$vs_clade}</div><!-- end unit -->";
/** * Given a item_id (request parameter 'id') returns a list of ancestors for use in the hierarchy browser * Returned data is JSON format */ public function getFacetHierarchyAncestorList() { $pn_id = $this->request->getParameter('id', pInteger); $va_access_values = caGetUserAccessValues($this->request); $ps_facet_name = $this->request->getParameter('facet', pString); $this->view->setVar("facet_name", $ps_facet_name); $this->view->setVar("key", $this->request->getParameter('key', pString)); $ps_browse_type = $this->request->getParameter('browseType', pString); if (!($va_browse_info = caGetInfoForBrowseType($ps_browse_type))) { // invalid browse type – throw error die("Invalid browse type"); } $this->view->setVar("browse_type", $ps_browse_type); $vs_class = $va_browse_info['table']; $o_browse = caGetBrowseInstance($vs_class); if (!is_array($va_facet_info = $o_browse->getInfoForFacet($ps_facet_name))) { return null; } if ($ps_cache_key = $this->request->getParameter('key', pString)) { $o_browse->reload($ps_cache_key); } $va_ancestors = array(); switch ($va_facet_info['type']) { case 'attribute': // is it a list attribute? $t_element = new ca_metadata_elements(); if ($t_element->load(array('element_code' => $va_facet_info['element_code']))) { if ($t_element->get('datatype') == 3) { // 3=list if (!$pn_id) { $t_list = new ca_lists(); $pn_id = $t_list->getRootListItemID($t_element->get('list_id')); } $t_item = new ca_list_items($pn_id); if ($t_item->getPrimaryKey()) { $vs_primary_key = $t_item->primaryKey(); $this->view->setVar("primary_key", $vs_primary_key); $vs_display_fld = $t_item->getLabelDisplayField(); $this->view->setVar("display_field", $vs_display_fld); $vs_label_table_name = $t_item->getLabelTableName(); $va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'additionalTableToJoin' => $vs_label_table_name, 'additionalTableJoinType' => 'LEFT', 'additionalTableSelectFields' => array($vs_display_fld, 'locale_id'), 'additionalTableWheres' => array('(' . $vs_label_table_name . '.is_preferred = 1 OR ' . $vs_label_table_name . '.is_preferred IS NULL)')))); array_shift($va_ancestors); } } } break; case 'label': // label facet $va_facet_info['table'] = $this->ops_tablename; // fall through to default case // fall through to default case default: $t_item = $this->request->datamodel->getInstanceByTableName($va_facet_info['table']); $t_item->load($pn_id); if (method_exists($t_item, "getHierarchyList")) { $va_access_values = caGetUserAccessValues($this->request); $va_facet = $o_browse->getFacet($ps_facet_name, array('sort' => 'name', 'checkAccess' => $va_access_values)); $va_hierarchy_list = $t_item->getHierarchyList(true); $vn_hierarchies_in_use = 0; foreach ($va_hierarchy_list as $vn_i => $va_item) { if (isset($va_facet[$va_item[$t_item->primaryKey()]])) { $vn_hierarchies_in_use++; if ($vn_hierarchies_in_use > 1) { break; } } } } if ($t_item->getPrimaryKey()) { $vs_primary_key = $t_item->primaryKey(); $this->view->setVar("primary_key", $vs_primary_key); $vs_display_fld = $t_item->getLabelDisplayField(); $this->view->setVar("display_field", $vs_display_fld); $vs_label_table_name = $t_item->getLabelTableName(); $va_ancestors = array_reverse($t_item->getHierarchyAncestors(null, array('includeSelf' => true, 'additionalTableToJoin' => $vs_label_table_name, 'additionalTableJoinType' => 'LEFT', 'additionalTableSelectFields' => array($vs_display_fld, 'locale_id'), 'additionalTableWheres' => array('(' . $vs_label_table_name . '.is_preferred = 1 OR ' . $vs_label_table_name . '.is_preferred IS NULL)')))); } if ($vn_hierarchies_in_use <= 1) { array_shift($va_ancestors); } break; } $this->view->setVar('ancestors', $va_ancestors); switch ($this->request->getParameter('returnAs', pString)) { case "json": return $this->render('Browse/facet_hierarchy_ancestors_json.php'); break; # ------------------------------------------------ # ------------------------------------------------ case "html": default: return $this->render('Browse/facet_hierarchy_ancestors_html.php'); break; # ------------------------------------------------ } }
print "<div class='unit'><b>" . _t("Lesson type") . "</b>: " . unicode_ucfirst($t_occurrence->getTypeName()) . "</div><!-- end unit -->"; } # --- attributes in label: value format $va_attributes = array("gradelevel", "lessonTopic", "learning_standard", "commonCore", "skills", "EdProject", "funder"); # --- which of these attributes can be edited when customizing? $va_edit_attributes = array("lessonTopic", "learning_standard", "commonCore", "skills"); if (is_array($va_attributes) && sizeof($va_attributes) > 0) { foreach ($va_attributes as $vs_attribute_code) { if ($va_values = $t_occurrence->get("ca_occurrences.{$vs_attribute_code}", array("convertCodesToDisplayText" => false, "returnAsArray" => true))) { $va_output_parts = array(); foreach ($va_values as $k => $va_value) { if ($va_value[$vs_attribute_code]) { # --- display hierarchy path for "lessonTopic", "learning_standard", "commonCore" if (in_array($vs_attribute_code, array("lessonTopic", "learning_standard", "commonCore"))) { $vs_tmp = ""; $va_hierarchy_ancestors = $t_list_items->getHierarchyAncestors($va_value[$vs_attribute_code], array("idsOnly" => true, "includeSelf" => true)); if (is_array($va_hierarchy_ancestors) && sizeof($va_hierarchy_ancestors)) { # --- remove the root - we don't want to display it $va_root = array_pop($va_hierarchy_ancestors); if (is_array($va_hierarchy_ancestors) && sizeof($va_hierarchy_ancestors)) { foreach ($va_hierarchy_ancestors as $vni => $vn_list_item_id) { $vs_tmp = $t_lists->getItemForDisplayByItemID($vn_list_item_id) . ($vni > 0 ? " > " . $vs_tmp : ""); } $va_output_parts[] = $vs_tmp; } } } else { $vs_value = ""; if ($vs_value = trim($va_value[$vs_attribute_code])) { $va_output_parts[] = $t_lists->getItemForDisplayByItemID($vs_value); }
/** * Load type restriction for specified table and type and return loaded model instance. * Will return specific restriction for type_id, or a general (type_id=null) restriction if no * type-specific restriction is defined. * * @param $pn_table_num - table_num of type restriction * @param $pn_type_id - type_id of type restriction; leave null if you want a non-type-specific restriction * @return ca_metadata_type_restrictions instance - will be loaded with type restriction */ public function getTypeRestrictionInstanceForElement($pn_table_num, $pn_type_id) { if (!($vn_element_id = $this->getPrimaryKey())) { return null; } // element must be loaded if ($this->get('parent_id')) { return null; } // element must be root of hierarchy $t_restriction = new ca_metadata_type_restrictions(); if ($pn_type_id > 0 && $t_restriction->load(array('table_num' => (int) $pn_table_num, 'type_id' => (int) $pn_type_id, 'element_id' => (int) $vn_element_id))) { return $t_restriction; } else { if ($t_restriction->load(array('table_num' => (int) $pn_table_num, 'type_id' => null, 'element_id' => (int) $vn_element_id))) { return $t_restriction; } // try going up the hierarchy to find one that we can inherit from if ($pn_type_id && ($t_type_instance = new ca_list_items($pn_type_id))) { $va_ancestors = $t_type_instance->getHierarchyAncestors(null, array('idsOnly' => true)); if (is_array($va_ancestors)) { array_pop($va_ancestors); // get rid of root if (sizeof($va_ancestors)) { $qr_res = $this->getDb()->query("\n\t\t\t\t\t\t\tSELECT restriction_id\n\t\t\t\t\t\t\tFROM ca_metadata_type_restrictions\n\t\t\t\t\t\t\tWHERE\n\t\t\t\t\t\t\t\ttype_id IN (?) AND table_num = ? AND include_subtypes = 1 AND element_id = ?\n\t\t\t\t\t\t", array($va_ancestors, (int) $pn_table_num, (int) $vn_element_id)); if ($qr_res->nextRow()) { if ($t_restriction->load($qr_res->get('restriction_id'))) { return $t_restriction; } } } } } } return null; }
/** * Returns an associative array of relationship types for the relationship * organized by the sub_type_id specified by $ps_orientation. If $ps_orientation is the name of the "right" table * then sub_type_left_id is used for keys in the array, if $ps_orientation is the name of the "left" table * then sub_type_right_id is used for keys. * * For example, for ca_objects_x_entities, if $ps_orientation is ca_objects then then sub_type_right_id is * used as the key; if ca_entities is passed then sub_type_left_id is used; if a table name is passed that * is not either side of the relation then an empty array is returned * */ public function getRelationshipTypesBySubtype($ps_orientation, $pn_type_id, $pa_options = null) { unset($pa_options['request']); if (!$this->hasField('type_id')) { return array(); } $vs_left_table_name = $this->getLeftTableName(); $vs_right_table_name = $this->getRightTableName(); $vb_dont_include_subtypes_in_type_restriction = caGetOptions('dont_include_subtypes_in_type_restriction', $pa_options, false); $o_db = $this->getDb(); $t_rel_type = new ca_relationship_types(); $vs_restrict_to_relationship_type_sql = ''; if (isset($pa_options['restrict_to_relationship_types']) && $pa_options['restrict_to_relationship_types']) { if (!is_array($pa_options['restrict_to_relationship_types'])) { $pa_options['restrict_to_relationship_types'] = array($pa_options['restrict_to_relationship_types']); } if (sizeof($pa_options['restrict_to_relationship_types'])) { $va_restrict_to_type_list = array(); foreach ($pa_options['restrict_to_relationship_types'] as $vs_type_code) { if (!strlen(trim($vs_type_code))) { continue; } $va_criteria = array('table_num' => $this->tableNum()); if (is_numeric($vs_type_code)) { $va_criteria['type_id'] = (int) $vs_type_code; } else { $va_criteria['type_code'] = $vs_type_code; } if ($t_rel_type->load($va_criteria)) { $va_restrict_to_type_list[] = "(crt.hier_left >= " . $t_rel_type->get('hier_left') . " AND crt.hier_right <= " . $t_rel_type->get('hier_right') . ")"; } } if (sizeof($va_restrict_to_type_list)) { $vs_restrict_to_relationship_type_sql = " AND (" . join(' OR ', $va_restrict_to_type_list) . ")"; } } } $qr_res = $o_db->query("\n\t\t\t\tSELECT *\n\t\t\t\tFROM ca_relationship_types crt\n\t\t\t\tINNER JOIN ca_relationship_type_labels AS crtl ON crt.type_id = crtl.type_id\n\t\t\t\tWHERE\n\t\t\t\t\t(crt.table_num = ?)\n\t\t\t\t\t{$vs_restrict_to_relationship_type_sql}\n\t\t\t", $this->tableNum()); // Support hierarchical subtypes - if the subtype restriction is a type with parents then include those as well // Allows subtypes to "inherit" bindings from parent types $t_list_item = new ca_list_items($pn_type_id); if (!$vb_dont_include_subtypes_in_type_restriction) { if (!is_array($va_ancestor_ids = $t_list_item->getHierarchyAncestors(null, array('idsOnly' => true, 'includeSelf' => true)))) { $va_ancestor_ids = array(); } // remove hierarchy root from ancestor list, otherwise invalid bindings // from root nodes (which are not "real" rel types) may be inherited array_pop($va_ancestor_ids); } else { $va_ancestor_ids = array($pn_type_id); } $va_types = array(); $va_parent_ids = array(); $vn_l = 0; $vn_root_id = $t_rel_type->load(array('parent_id' => null, 'table_num' => $this->tableNum())) ? $t_rel_type->getPrimaryKey() : null; $va_hier = array(); if ($vs_left_table_name === $vs_right_table_name) { // ---------------------------------------------------------------------------------------- // self relationship while ($qr_res->nextRow()) { $va_row = $qr_res->getRow(); $vn_parent_id = $va_row['parent_id']; $va_hier[$vn_parent_id][] = $va_row['type_id']; // skip type if it has a subtype set and it's not in our list $vs_subtype_orientation = null; $vs_subtype = null; if ($va_row['sub_type_left_id'] && !in_array($va_row['sub_type_left_id'], $va_ancestor_ids)) { // not left if ($va_row['sub_type_right_id'] && !in_array($va_row['sub_type_right_id'], $va_ancestor_ids)) { // not left and not right continue; } else { // not left and right $vs_subtype = $va_row['sub_type_left_id']; $vs_subtype_orientation = "left"; } } else { if ($va_row['sub_type_left_id'] && in_array($va_row['sub_type_left_id'], $va_ancestor_ids)) { // left if ($va_row['sub_type_right_id'] && in_array($va_row['sub_type_right_id'], $va_ancestor_ids)) { // left and right $vs_subtype = $va_row['sub_type_right_id']; $vs_subtype_orientation = ""; } else { // left and not right $vs_subtype_orientation = "right"; $vs_subtype = $va_row['sub_type_right_id']; } } } if (!$vs_subtype) { $vs_subtype = 'NULL'; } switch ($vs_subtype_orientation) { case 'left': $va_tmp = $va_row; $vs_key = strlen($va_tmp['rank']) > 0 ? sprintf("%08d", (int) $va_tmp['rank']) . preg_replace('![^A-Za-z0-9_]+!', '_', $va_tmp['typename_reverse']) : preg_replace('![^A-Za-z0-9_]+!', '_', $va_tmp['typename_reverse']); $va_tmp['typename'] = $va_tmp['typename_reverse']; unset($va_tmp['typename_reverse']); // we pass the typename adjusted for direction in 'typename', so there's no need to include typename_reverse in the returned values $va_types[$vn_parent_id][$vs_subtype][$vs_key][$va_row['type_id']][$va_row['locale_id']] = $va_tmp; break; case 'right': $va_tmp = $va_row; $vs_key = strlen($va_tmp['rank']) > 0 ? sprintf("%08d", (int) $va_tmp['rank']) . preg_replace('![^A-Za-z0-9_]+!', '_', $va_tmp['typename']) : preg_replace('![^A-Za-z0-9_]+!', '_', $va_tmp['typename']); unset($va_tmp['typename_reverse']); // we pass the typename adjusted for direction in 'typename', so there's no need to include typename_reverse in the returned values $va_types[$vn_parent_id][$vs_subtype][$vs_key][$va_row['type_id']][$va_row['locale_id']] = $va_tmp; break; default: $va_tmp = $va_row; if (trim($va_tmp['typename']) == trim($va_tmp['typename_reverse'])) { // // If the sides of the self-relationship are the same then treat it like a normal relationship type: one entry in the // list and a plain type_id value // unset($va_tmp['typename_reverse']); // we pass the typename adjusted for direction in 'typename', so there's no need to include typename_reverse in the returned values $va_tmp['direction'] = null; $vs_key = strlen($va_tmp['rank']) > 0 ? sprintf("%08d", (int) $va_tmp['rank']) . preg_replace('![^A-Za-z0-9_]+!', '_', $va_tmp['typename']) : preg_replace('![^A-Za-z0-9_]+!', '_', $va_tmp['typename']); $va_types[$vn_parent_id][$vs_subtype][$vs_key][$va_row['type_id']][$va_row['locale_id']] = $va_tmp; } else { // // If each side of the self-relationship type are different then add both to the list with special type_id values that // indicate the directionality of the typename (ltor = left to right = "typename"; rtor = right to left = "typename_reverse") // $va_tmp = $va_row; unset($va_tmp['typename_reverse']); // we pass the typename adjusted for direction in 'typename', so there's no need to include typename_reverse in the returned values $vs_key = strlen($va_tmp['rank']) > 0 ? sprintf("%08d", (int) $va_tmp['rank']) . preg_replace('![^A-Za-z0-9_]+!', '_', $va_tmp['typename']) : preg_replace('![^A-Za-z0-9_]+!', '_', $va_tmp['typename']); $va_tmp['direction'] = 'ltor'; $va_types[$vn_parent_id][$vs_subtype][$vs_key]['ltor_' . $va_row['type_id']][$va_row['locale_id']] = $va_tmp; $va_tmp = $va_row; $va_tmp['typename'] = $va_tmp['typename_reverse']; unset($va_tmp['typename_reverse']); // we pass the typename adjusted for direction in 'typename', so there's no need to include typename_reverse in the returned values $vs_key = strlen($va_tmp['rank']) > 0 ? sprintf("%08d", (int) $va_tmp['rank']) . preg_replace('![^A-Za-z0-9_]+!', '_', $va_tmp['typename_reverse']) : preg_replace('![^A-Za-z0-9_]+!', '_', $va_tmp['typename_reverse']); $va_tmp['direction'] = 'rtol'; $va_types[$vn_parent_id][$vs_subtype][$vs_key]['rtol_' . $va_row['type_id']][$va_row['locale_id']] = $va_tmp; } break; } } $va_types = $this->_processRelationshipHierarchy($vn_root_id, $va_hier, $va_types, 1); $va_processed_types = array('_type_map' => array()); $va_subtype_lookups = array(); foreach ($va_types as $vs_subtype => $va_types_by_subtype) { $va_types_by_locale = array(); foreach ($va_types_by_subtype as $vs_key => $va_types_by_key) { foreach ($va_types_by_key as $vs_k => $va_v) { foreach ($va_v as $vs_k2 => $vs_v2) { $va_types_by_locale[$vs_k][$vs_k2] = $vs_v2; } } } if (!$vb_dont_include_subtypes_in_type_restriction) { // include mapping from parent type used in restriction to child types that inherit the binding if ($vs_subtype != 'NULL' && (!isset($va_subtype_lookups[$vs_subtype]) || !$va_subtype_lookups[$vs_subtype])) { $va_children = $t_list_item->getHierarchyChildren($vs_subtype, array('idsOnly' => true)); foreach ($va_children as $vn_child) { $va_processed_types['_type_map'][$vn_child] = $vs_subtype; } $va_subtype_lookups[$vs_subtype] = true; } } $va_processed_types[$vs_subtype] = caExtractValuesByUserLocale($va_types_by_locale, null, null, array('returnList' => true)); } } else { // ---------------------------------------------------------------------------------------- // regular relationship if (!in_array($ps_orientation, array($vs_left_table_name, $vs_right_table_name))) { return array(); } while ($qr_res->nextRow()) { $va_row = $qr_res->getRow(); $vn_parent_id = $va_row['parent_id']; $va_hier[$vn_parent_id][] = $va_row['type_id']; if ($ps_orientation == $vs_left_table_name) { // right-to-left // expand subtype $va_subtypes_to_check = $va_row['sub_type_left_id'] > 0 ? caMakeTypeIDList($vs_left_table_name, array($va_row['sub_type_left_id'])) : null; // skip type if it has a subtype set and it's not in our list if (!(!$va_subtypes_to_check || sizeof(array_intersect($va_subtypes_to_check, $va_ancestor_ids)))) { continue; } $vs_subtype = $va_row['sub_type_right_id']; $vs_key = strlen($va_row['rank']) > 0 ? sprintf("%08d", (int) $va_row['rank']) . preg_replace('![^A-Za-z0-9_]+!', '_', $va_row['typename']) : preg_replace('![^A-Za-z0-9_]+!', '_', $va_row['typename']); } else { // left-to-right // expand subtype $va_subtypes_to_check = $va_row['sub_type_right_id'] > 0 ? caMakeTypeIDList($vs_right_table_name, array($va_row['sub_type_right_id'])) : null; // skip type if it has a subtype set and it's not in our list if (!(!$va_subtypes_to_check || sizeof(array_intersect($va_subtypes_to_check, $va_ancestor_ids)))) { continue; } $vs_subtype = $va_row['sub_type_left_id']; $va_row['typename'] = $va_row['typename_reverse']; $vs_key = strlen($va_row['rank']) > 0 ? sprintf("%08d", (int) $va_row['rank']) . preg_replace('![^A-Za-z0-9_]+!', '_', $va_row['typename_reverse']) : preg_replace('![^A-Za-z0-9_]+!', '_', $va_row['typename_reverse']); } unset($va_row['typename_reverse']); // we pass the typename adjusted for direction in '_display', so there's no need to include typename_reverse in the returned values if (!$vs_subtype) { $vs_subtype = 'NULL'; } $vn_type_id = $va_row['type_id']; $va_types[$vn_parent_id][$vs_subtype][$vs_key][$vn_type_id][$va_row['locale_id']] = $va_row; } $va_types = $this->_processRelationshipHierarchy($vn_root_id, $va_hier, $va_types, 1); $va_processed_types = array('_type_map' => array()); $va_subtype_lookups = array(); foreach ($va_types as $vs_subtype => $va_types_by_subtype) { $va_types_by_locale = array(); foreach ($va_types_by_subtype as $vs_key => $va_types_by_key) { foreach ($va_types_by_key as $vn_locale_id => $va_t) { if (!is_array($va_types_by_locale[$vn_locale_id])) { $va_types_by_locale[$vn_locale_id] = array(); } $va_types_by_locale[$vn_locale_id] += $va_t; } } if (!$vb_dont_include_subtypes_in_type_restriction) { // include mapping from parent type used in restriction to child types that inherit the binding if ($vs_subtype != 'NULL' && (!isset($va_subtype_lookups[$vs_subtype]) || !$va_subtype_lookups[$vs_subtype])) { $va_children = $t_list_item->getHierarchyChildren($vs_subtype, array('idsOnly' => true)); foreach ($va_children as $vn_child) { $va_processed_types['_type_map'][$vn_child] = $vs_subtype; } $va_subtype_lookups[$vs_subtype] = true; } } $va_processed_types[$vs_subtype] = caExtractValuesByUserLocale($va_types_by_locale, null, null, array('returnList' => true)); } } return $va_processed_types; }
public function Full() { $t_lists = new ca_lists(); $t_list_items = new ca_list_items(); $o_purifier = new HTMLPurifier(); $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(); foreach (array("gradelevel", "lessonTopic", "learning_standard", "commonCore", "skills", "EdProject", "funder") as $vs_attribute_code) { if ($va_values = $t_occurrence->get("ca_occurrences.{$vs_attribute_code}", array("convertCodesToDisplayText" => false, "returnAsArray" => true))) { $va_output_parts = array(); foreach ($va_values as $k => $va_value) { if ($va_value[$vs_attribute_code]) { # --- display hierarchy path for "lessonTopic", "learning_standard", "commonCore" if (in_array($vs_attribute_code, array("lessonTopic", "learning_standard", "commonCore"))) { $vs_tmp = ""; $va_hierarchy_ancestors = $t_list_items->getHierarchyAncestors($va_value[$vs_attribute_code], array("idsOnly" => true, "includeSelf" => true)); if (is_array($va_hierarchy_ancestors) && sizeof($va_hierarchy_ancestors)) { # --- remove the root - we don't want to display it $va_root = array_pop($va_hierarchy_ancestors); if (is_array($va_hierarchy_ancestors) && sizeof($va_hierarchy_ancestors)) { foreach ($va_hierarchy_ancestors as $vni => $vn_list_item_id) { $vs_tmp = $t_lists->getItemForDisplayByItemID($vn_list_item_id) . ($vni > 0 ? " > " . $vs_tmp : ""); } $va_output_parts[] = $vs_tmp; } } } else { $vs_value = ""; if ($vs_value = trim($va_value[$vs_attribute_code])) { $va_output_parts[] = $t_lists->getItemForDisplayByItemID($vs_value); } } } } if (sizeof($va_output_parts)) { $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>"; $va_attributes = array("theme", "guidelines", "sure", "directions", "context", "task", "glossary", "instructions", "essay", "essential", "check"); foreach ($va_attributes as $vs_attribute_code) { if ($vs_value = $t_occurrence->get("ca_occurrences.{$vs_attribute_code}", array("convertLineBreaks" => true, "delimiter" => "<br/>"))) { if ($vs_attribute_code == "glossary") { $va_glossary_terms = array(); $va_values = $t_occurrence->get("ca_occurrences.{$vs_attribute_code}", array("convertLineBreaks" => true, "returnAsArray" => true)); foreach ($va_values as $va_value) { $va_glossary_terms[] = $va_value["glossary"]; } sort($va_glossary_terms); $vs_value = implode("<br/>", $va_glossary_terms); $va_occ_info[$vs_attribute_code] = "<div class='unit'><b>" . $t_occurrence->getDisplayLabel("ca_occurrences.{$vs_attribute_code}") . "</b><br/>" . $vs_value . "</div><!-- end unit -->"; } else { $va_occ_info[$vs_attribute_code] = "<div class='unit'><b>" . $t_occurrence->getDisplayLabel("ca_occurrences.{$vs_attribute_code}") . "</b><br/>" . str_replace("*", "• ", $vs_value) . "</div><!-- end unit -->"; } } } $va_attributes = array("questions", "challenge", "connections", "resources", "transcription", "translation", "essay"); foreach ($va_attributes as $vs_attribute_code) { if ($vs_value = $t_occurrence->get("ca_occurrences.{$vs_attribute_code}", array("convertLineBreaks" => true, "delimiter" => "<br/>"))) { if (in_array($vs_attribute_code, array("questions", "resources"))) { $va_values = $t_occurrence->get("ca_occurrences.{$vs_attribute_code}", array("convertLineBreaks" => true, "delimiter" => "<br/>", "returnAsArray" => true)); $vs_tmp = ""; $vs_tmp .= "<div class='unit'><b>" . $t_occurrence->getDisplayLabel("ca_occurrences.{$vs_attribute_code}") . "</b><ol>"; foreach ($va_values as $va_value_info) { $vs_tmp .= "<li>" . $va_value_info[$vs_attribute_code] . "</li>"; } $vs_tmp .= "</ol></div><!-- end unit -->"; $va_occ_info2[$vs_attribute_code] = $vs_tmp; } else { $va_occ_info2[$vs_attribute_code] = "<div class='unit'><b>" . $t_occurrence->getDisplayLabel("ca_occurrences.{$vs_attribute_code}") . "</b><br/>" . str_replace("*", "• ", $vs_value) . "</div><!-- end unit -->"; } } } # --- 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)); $va_reps_info = array(); if (is_array($va_reps)) { foreach ($va_reps as $vn_relation_id => $va_attr) { $t_rep = new ca_object_representations($va_attr['representation_list']); $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 ($vs_value = $t_objects_x_occurrences->get("ca_objects_x_occurrences.{$vs_attribute_code}", array("convertLineBreaks" => true, "delimiter" => "<br/>"))) { $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 $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; }