本文整理汇总了PHP中ca_lists::getRootListItemID方法的典型用法代码示例。如果您正苦于以下问题:PHP ca_lists::getRootListItemID方法的具体用法?PHP ca_lists::getRootListItemID怎么用?PHP ca_lists::getRootListItemID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ca_lists
的用法示例。
在下文中一共展示了ca_lists::getRootListItemID方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getFacetHierarchyLevel
/**
* 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));
//.........这里部分代码省略.........
示例2: getFacetHierarchyAncestorList
/**
* 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');
}
示例3: caGetListRootID
/**
* Fetch the id of the root item in list
*
* @param string $ps_list_code List code
* @param array $pa_options Options include:
* transaction = transaction to execute queries within. [Default=null]
* @return int item_id of the root list item or null if no default item was found
*/
function caGetListRootID($ps_list_code, $pa_options = null)
{
$t_list = new ca_lists();
if ($o_trans = caGetOption('transaction', $pa_options, null)) {
$t_list->setTransaction($o_trans);
}
return $t_list->getRootListItemID($ps_list_code);
}
示例4: getFacetHierarchyAncestorList
/**
* 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;
# ------------------------------------------------
}
}
示例5: getItemsForList
/**
* Returns items contained in list, including their labels. This method will returned the list items sorted according to the default_sort field setting of
* the list they belong to. Note that correct order when sorting by label is only guaranteed if 'extractValuesByUserLocale' is set to true [default is false].
* This is due to the list return format: since each item is indexed by item_id first, it can only have a single position in the return structure. If multiple labels are returned
* for an item then the item will only be in the correct sort order for one of the labels in most cases. To ensure proper sort order by label text, labels must be restricted to a
* single locale.
*
* @param $pm_list_name_or_id mixed - list_code or list_id of desired list
* @param $pa_options array - optional array of options. Supported options include:
* returnHierarchyLevels = if true list is returned with 'LEVEL' field set to hierarchical level of item, and items are returned in order such that if you loop through the returned list and indent each item according to its level you get a nicely formatted hierarchical display. Default is false.
* extractValuesByUserLocale = if true then values are processed to be appropriate for current user locale; default is false: return values for all locales
* directChildrenOnly = if true, only children immediately below the specified item are returned; [default is false]
* includeSelf = if true, the specified item is included in the returned set of items; [default is false]
* type_id = optional list item type to limit returned items by; default is to not limit by type (eg. type_id = null)
* item_id = optional item_id to use as root of hierarchy for returned items; if this is not set (the default) then all items in the list are returned
* sort = if set to a __CA_LISTS_SORT_BY_*__ constant, will force the list to be sorted by that criteria overriding the sort order set in the ca_lists.default_sort field
* idsOnly = if true, only the primary key id values of the list items are returned
* enabledOnly = return only enabled list items [default=false]
* labelsOnly = if true only labels in the current locale are returns in an array key'ed on item_id
*
* @return array List of items indexed first on item_id and then on locale_id of label
*/
public function getItemsForList($pm_list_name_or_id, $pa_options = null)
{
$vn_list_id = $this->_getListID($pm_list_name_or_id);
if (!is_array($pa_options)) {
$pa_options = array();
}
if (!isset($pa_options['returnHierarchyLevels'])) {
$pa_options['returnHierarchyLevels'] = false;
}
if (isset($pa_options['directChildrenOnly']) && $pa_options['directChildrenOnly']) {
$pa_options['returnHierarchyLevels'] = false;
}
$vb_enabled_only = caGetOption('enabledOnly', $pa_options, false);
$vb_labels_only = false;
if (isset($pa_options['labelsOnly']) && $pa_options['labelsOnly']) {
$pa_options['extractValuesByUserLocale'] = true;
$pa_options['returnHierarchyLevels'] = false;
$vb_labels_only = true;
}
$vs_cache_key = caMakeCacheKeyFromOptions(array_merge($pa_options, array('list_id' => $vn_list_id)));
if (is_array(ca_lists::$s_list_item_cache[$vs_cache_key])) {
return ca_lists::$s_list_item_cache[$vs_cache_key];
}
$t_list = new ca_lists($vn_list_id);
$pn_type_id = isset($pa_options['type_id']) ? (int) $pa_options['type_id'] : null;
$pn_sort = isset($pa_options['sort']) ? (int) $pa_options['sort'] : $t_list->get('default_sort');
if (!($pn_item_id = isset($pa_options['item_id']) ? (int) $pa_options['item_id'] : null)) {
$pn_item_id = $t_list->getRootListItemID($vn_list_id);
}
$t_list_item = new ca_list_items($pn_item_id);
if (!$t_list_item->getPrimaryKey() || $t_list_item->get('list_id') != $vn_list_id) {
return null;
}
$vs_hier_sql = '';
if ($t_list_item->getPrimaryKey()) {
$vs_hier_sql = " AND ((cli.hier_left >= " . floatval($t_list_item->get('hier_left')) . ") AND (cli.hier_right <= " . floatval($t_list_item->get('hier_right')) . "))";
}
if (!isset($pa_options['returnHierarchyLevels']) || !$pa_options['returnHierarchyLevels']) {
$vs_type_sql = '';
if ($pn_type_id) {
$vs_type_sql = ' AND (cli.type_id = ' . intval($pn_type_id) . ')';
}
$vs_order_by = '';
switch ($pn_sort) {
case __CA_LISTS_SORT_BY_LABEL__:
// by label
$vs_order_by = 'clil.name_plural';
break;
case __CA_LISTS_SORT_BY_RANK__:
// by rank
$vs_order_by = 'cli.rank';
break;
case __CA_LISTS_SORT_BY_VALUE__:
// by value
$vs_order_by = 'cli.item_value';
break;
case __CA_LISTS_SORT_BY_IDENTIFIER__:
// by identifier
$vs_order_by = 'cli.idno_sort';
break;
}
if ($vs_order_by) {
$vs_order_by = "ORDER BY {$vs_order_by}";
}
$vs_enabled_sql = '';
if ($vb_enabled_only) {
$vs_enabled_sql = ' AND (cli.is_enabled = 1)';
}
$vs_direct_children_sql = '';
if (isset($pa_options['directChildrenOnly']) && $pa_options['directChildrenOnly']) {
$vs_direct_children_sql = " AND cli.parent_id = " . (int) $pn_item_id;
}
$o_db = $this->getDb();
$vs_sql = "\n\t\t\t\tSELECT clil.*, cli.*\n\t\t\t\tFROM ca_list_items cli\n\t\t\t\tINNER JOIN ca_list_item_labels AS clil ON clil.item_id = cli.item_id\n\t\t\t\tWHERE\n\t\t\t\t\t(cli.deleted = 0) AND (clil.is_preferred = 1) AND (cli.list_id = ?) {$vs_type_sql} {$vs_direct_children_sql} {$vs_hier_sql} {$vs_enabled_sql}\n\t\t\t\t{$vs_order_by}\n\t\t\t";
//print $vs_sql;
$qr_res = $o_db->query($vs_sql, (int) $vn_list_id);
$va_seen_locales = array();
$va_items = array();
//.........这里部分代码省略.........
示例6: caLoadULAN
//.........这里部分代码省略.........
switch ($o_xml->nodeType) {
case XMLReader::ELEMENT:
$o_xml->read();
$va_subject['non_preferred_term_ids'][] = $o_xml->value;
break;
}
break;
case 'Non-Preferred_Term':
break 2;
}
}
break;
# ---------------------------
# ---------------------------
case 'VP_Subject_ID':
switch ($o_xml->nodeType) {
case XMLReader::ELEMENT:
$o_xml->read();
$va_subject['related_subjects'][] = $o_xml->value;
break;
}
break;
# ---------------------------
}
}
$o_xml->close();
}
$o_log->logInfo("Begin linking ULAN terms in hierarchy");
print "\n\nLINKING TERMS IN HIERARCHY...\n";
$vn_last_message_length = 0;
$t_list = new ca_lists();
$t_item = new ca_list_items();
$t_item->setMode(ACCESS_WRITE);
$vn_list_root_id = $t_list->getRootListItemID($vn_list_id);
foreach ($va_parent_child_links as $vs_child_id => $vs_parent_id) {
print str_repeat(chr(8), $vn_last_message_length);
$vs_message = "\tLINKING {$vs_child_id} to parent {$vs_parent_id}";
if (($vn_l = 100 - strlen($vs_message)) < 1) {
$vn_l = 1;
}
$vs_message .= str_repeat(' ', $vn_l);
$vn_last_message_length = strlen($vs_message);
print $vs_message;
if (in_array($vs_parent_id, array('500000000', '500000001'))) {
if (!$t_item->load($vn_child_item_id)) {
$o_log->logError("Could not load item for {$vs_child_id} (was translated to item_id={$vn_child_item_id})");
continue;
}
$t_item->set('parent_id', $vn_list_root_id);
$t_item->update(array('dontCheckCircularReferences' => true, 'dontSetHierarchicalIndexing' => true));
if ($t_item->numErrors()) {
$o_log->logError("Could not set parent_id for {$vs_child_id} to root): " . join('; ', $t_item->getErrors()));
continue;
}
$va_ulan_id_to_item_id[$vs_parent_id] = $vn_list_root_id;
}
if (!($vn_child_item_id = $va_ulan_id_to_item_id[$vs_child_id])) {
$o_log->logError("No list item id for child_id {$vs_child_id} (were there previous errors?)");
continue;
}
if (!($vn_parent_item_id = $va_ulan_id_to_item_id[$vs_parent_id])) {
$o_log->logError("No list item id for parent_id {$vs_parent_id} (were there previous errors?)");
continue;
}
if (!$t_item->load($vn_child_item_id)) {
$o_log->logError("Could not load item for {$vs_child_id} (was translated to item_id={$vn_child_item_id})");