function validate(&$dataspace) { if(!$value = $dataspace->get($this->field_name)) return; $tree = limb_tree :: instance(); if(!$nodes = $tree->get_children($this->parent_node_id)) return; foreach($nodes as $id => $node) { if($node['identifier'] != $value) continue; if($this->node_id == TREE_IDENTIFIER_RULE_UNKNOWN_NODE_ID) { $this->error('DUPLICATE_TREE_IDENTIFIER'); break; } elseif($id != $this->node_id) { $this->error('DUPLICATE_TREE_IDENTIFIER'); break; } } }
function setUp() { parent :: setUp(); $tree =& limb_tree :: instance(); $values['identifier'] = 'root'; $this->node_id_root = $tree->create_root_node($values, false, true); $values['identifier'] = 'ru'; $values['object_id'] = 1; $this->node_id_ru = $tree->create_sub_node($this->node_id_root, $values); $values['identifier'] = 'document'; $values['object_id'] = 10; $this->node_id_document = $tree->create_sub_node($this->node_id_ru, $values); $values['identifier'] = 'doc1'; $values['object_id'] = 20; $this->node_id_doc1 = $tree->create_sub_node($this->node_id_ru, $values); $values['identifier'] = 'doc2'; $values['object_id'] = 30; $this->node_id_doc2 = $tree->create_sub_node($this->node_id_ru, $values); }
function perform() { $tree =& limb_tree::instance(); if (isset($_REQUEST['id'])) { $node_id = (int) $_REQUEST['id']; } else { $node_id = get_mapped_id(); } if (!isset($_REQUEST['direction'])) { return false; } if (!($object_data = fetch_one_by_node_id($node_id))) { debug::write_error('Node is not accessible', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('node_id' => $node_id)); return false; } $direction = $_REQUEST['direction']; if (!($direction == 'up' || $direction == 'down')) { debug::write_error('Direction is not correct', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('direction' => $direction)); return false; } if ($tree->change_node_order($node_id, $direction)) { reload(PHP_SELF . '#' . $node_id); } return false; }
function perform() { $tree =& limb_tree::instance(); if (isset($_REQUEST['id'])) { $node_id = (int) $_REQUEST['id']; } else { $node_id = get_mapped_id(); } if (!isset($_REQUEST['direction'])) { return new failed_response(); } if (!($object_data = fetch_one_by_node_id($node_id))) { debug::write_error('Node is not accessible', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('node_id' => $node_id)); return new close_popup_response(RESPONSE_STATUS_FAILURE); } $direction = $_REQUEST['direction']; if (!($direction == 'up' || $direction == 'down')) { debug::write_error('Direction is not correct', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__, array('direction' => $direction)); return new close_popup_response(RESPONSE_STATUS_FAILURE); } if ($tree->change_node_order($node_id, $direction)) { return new close_popup_response(); } else { return new close_popup_response(RESPONSE_STATUS_FAILURE); } }
function setUp() { $this->_clean_up(); $this->object = new site_object_manipulation_test(); debug_mock :: init($this); $user =& user :: instance(); $user->_set_id(10); $tree =& limb_tree :: instance(); $values['identifier'] = 'root'; $root_node_id = $tree->create_root_node($values, false, true); $values['identifier'] = 'ru'; $values['object_id'] = 1; $this->parent_node_id = $tree->create_sub_node($root_node_id, $values); $class_id = $this->object->get_class_id(); $this->db->sql_insert('sys_site_object', array('id' => 1, 'class_id' => $class_id, 'current_version' => 1)); $values['identifier'] = 'document'; $values['object_id'] = 10; $this->sub_node_id = $tree->create_sub_node($this->parent_node_id, $values); $class_id = $this->object->get_class_id(); $this->db->sql_insert('sys_site_object', array('id' => 10, 'class_id' => $class_id, 'current_version' => 1)); }
function &search_fetch_sub_branch($path, $loader_class_name, &$counter, $params = array(), $fetch_method = 'fetch') { $tree =& limb_tree::instance(); $site_object =& site_object_factory::instance($loader_class_name); if (!isset($params['restrict_by_class']) || isset($params['restrict_by_class']) && (bool) $params['restrict_by_class']) { $class_id = $site_object->get_class_id(); } else { $class_id = null; } if (isset($params['check_expanded_parents'])) { $check_expanded_parents = (bool) $params['check_expanded_parents']; } else { $check_expanded_parents = false; } if (isset($params['include_parent'])) { $include_parent = (bool) $params['include_parent']; } else { $include_parent = false; } $depth = isset($params['depth']) ? $params['depth'] : 1; if (!($nodes = $tree->get_accessible_sub_branch_by_path($path, $depth, $include_parent, $check_expanded_parents, $class_id))) { return array(); } $object_ids = complex_array::get_column_values('object_id', $nodes); if (!count($object_ids)) { return array(); } $result =& $this->search_fetch_by_ids($object_ids, $loader_class_name, $counter, $params, $fetch_method); return $result; }
function _check_nesting_rules($node_id, $target_node_id, $mode) { $tree =& limb_tree::instance(); if ($mode == NESE_MOVE_AFTER || $mode == NESE_MOVE_BEFORE) { $target_node = $tree->get_node($target_node_id); return $this->_can_parent_accept_node($target_node['parent_id'], $node_id); } elseif ($mode == NESE_MOVE_BELOW) { return $this->_can_parent_accept_node($target_node_id, $node_id); } }
function _process_result_array($arr) { $tree =& limb_tree::instance(); $total = $this->stats_report->fetch_total_hits(); $result = array(); foreach ($arr as $index => $data) { $data['percentage'] = round($data['hits'] / $total * 100, 2); $result[$index] = $data; } return $result; }
function &_fetch(&$counter, $params) { $tree =& limb_tree::instance(); $tree_array =& parent::_fetch($counter, $params); $path_node = $tree->get_node_by_path($params['path']); if (isset($params['include_parent']) && (bool) $params['include_parent']) { $path_node_level = $path_node['level'] - 1; } else { $path_node_level = $path_node['level']; } $levels_status_array = array(); $size = count($tree_array); $current_pos = 0; $parent_data = array(); foreach ($tree_array as $id => $tree_item) { $parent_node_id = $tree_item['parent_node_id']; if (!isset($parent_data[$parent_node_id])) { if ($parent_node_id == 0) { $parent_data[$parent_node_id]['children_amount'] = 1; } else { $parent_data[$parent_node_id]['children_amount'] = $tree->count_accessible_children($parent_node_id); } $parent_data[$parent_node_id]['counter'] = 0; } $parent_data[$parent_node_id]['counter']++; if ($parent_data[$parent_node_id]['counter'] == 1) { $is_first_child = true; } else { $is_first_child = false; } if ($parent_data[$parent_node_id]['counter'] == $parent_data[$parent_node_id]['children_amount']) { $is_last_child = true; } else { $is_last_child = false; } $tree_array[$id]['level'] = $tree_array[$id]['level'] - $path_node_level; $levels_status_array[$tree_item['level'] - $path_node_level] = $is_last_child; $tree_array[$id]['level_' . $tree_array[$id]['level']] = 1; $tree_array[$id]['is_expanded'] = $tree->is_node_expanded($tree_item['node_id']); $tree_array[$id]['is_last_child'] = $is_last_child; $tree_array[$id]['is_first_child'] = $is_first_child; $tree_array[$id]['levels_status'] = $levels_status_array; if ($tree_array[$id]['class_name'] == 'image_object' || $tree_array[$id]['class_name'] == 'file_object') { $tree_array[$id]['icon'] = '/root?node_id=' . $tree_item['node_id'] . '&icon'; } elseif (isset($tree_item['icon']) && $tree_item['icon']) { $tree_array[$id]['icon'] = $tree_item['icon']; } else { $tree_array[$id]['icon'] = '/shared/images/generic.gif'; } } return $tree_array; }
function _retrieve_routes() { if (!$this->condition_changed) { return $this->routes_array; } $start_stamp = $this->start_date->get_stamp(); $finish_stamp = $this->finish_date->get_stamp(); $tree =& limb_tree::instance(); $root = $tree->get_node_by_path('/root'); $root_id = $root['id']; $sql = "SELECT sslog.time, sslog.action, sslog.session_id, ssu.uri\r\n\t\t\t\t\t\tFROM sys_stat_log sslog, sys_stat_uri ssu\r\n\t\t\t\t\t\tWHERE \n\t\t\t\t\t\tsslog.stat_uri_id = ssu.id AND \r\n\t\t\t\t\t\t((sslog.node_id={$root_id} AND ssu.uri='/root') OR (ssu.uri != '/root')) AND\r\n\t\t\t\t\t\tsslog.time BETWEEN {$start_stamp} AND {$finish_stamp} AND\n\t\t\t\t\t\tsslog.user_id = -1\r\n\t\t\t\t\t\tORDER BY sslog.session_id, sslog.time ASC"; $this->db->sql_exec($sql); $session_events = array(); $session_routes = array(); $prev_session_id = -1; while ($record = $this->db->fetch_row()) { $session_id = $record['session_id']; if ($prev_session_id != $session_id) { $counter = 0; $session_rotes[$session_id] = ''; $prev_record = array('uri' => '', 'action' => ''); } $prev_session_id = $session_id; if ($counter > 10) { continue; } if ($prev_record['uri'] != $record['uri'] || $prev_record['action'] != $record['action']) { $session_events[$session_id][] = $record; $prev_record = $record; $session_rotes[$session_id] .= '=>' . $record['uri'] . '***' . $record['action']; $counter++; } } $unique_routes = array_count_values($session_rotes); arsort($unique_routes); $total_routes = array_sum($unique_routes); $this->routes_array = array(); $i = 0; foreach ($unique_routes as $route => $hits) { $pieces = explode('=>', $route); array_shift($pieces); for ($level = 0; $level < sizeof($pieces); $level++) { list($uri, $action) = explode('***', $pieces[$level]); $this->routes_array[$i]['route'][$level] = array('uri' => $uri, 'action' => $action, 'level' => $level); } $this->routes_array[$i]['hits'] = $hits; $this->routes_array[$i++]['percentage'] = round($hits / $total_routes * 100, 2); } return $this->routes_array; }
function _insert_fake_sys_site_object_records() { $class_db_table = db_table_factory::instance('sys_class'); $class_db_table->insert(array('id' => 1001, 'class_name' => 'fake_class')); $db_table =& db_table_factory::instance('sys_site_object'); $tree =& limb_tree::instance(); $data = array(); for ($i = 11; $i <= 20; $i++) { $this->db->sql_insert('sys_site_object', array('id' => $i, 'class_id' => 1001, 'identifier' => 'object_' . $i, 'title' => 'object_' . $i . '_title', 'status' => 0, 'locale_id' => 'en')); $values['identifier'] = 'object_' . $i; $values['object_id'] = $i; $tree->create_sub_node($this->root_node_id, $values); } }
function perform() { $tree =& limb_tree::instance(); if (isset($_REQUEST['id'])) { $id = (int) $_REQUEST['id']; } else { $id = get_mapped_id(); } if (isset($_REQUEST['expand'])) { return $tree->expand_node($id); } elseif (isset($_REQUEST['collapse'])) { return $tree->collapse_node($id); } else { return $tree->toggle_node($id); } }
function _get_path_objects_ids_array() { if (count($this->object_ids_array)) { return $this->object_ids_array; } $tree =& limb_tree::instance(); $node = $tree->get_node($this->get_node_id()); $parents = $tree->get_parents($this->get_node_id()); $result = array(); if (is_array($parents) && count($parents)) { foreach ($parents as $parent_node) { $result[$parent_node['object_id']] = $parent_node['object_id']; } } if ($node) { $result[$node['object_id']] = $node['object_id']; } return $this->object_ids_array = $result; }
function _process_path() { $default_path = '/root/'; if (!isset($_REQUEST['path'])) { return $default_path; } else { $path = $_REQUEST['path']; } if (strpos($path, '?') !== false) { if (!($node = map_url_to_node($path))) { return $default_path; } $tree =& limb_tree::instance(); if (!($path = $tree->get_path_to_node($node))) { return $default_path; } } return $path; }
function validate(&$dataspace) { if (!($value = $dataspace->get($this->field_name))) { return; } if ($this->current_identifier && $this->current_identifier == $value) { return; } $tree = limb_tree::instance(); if (!($nodes = $tree->get_children($this->parent_id))) { return; } foreach ($nodes as $node) { if ($node['identifier'] == $value) { $this->error('DUPLICATE_TREE_IDENTIFIER'); break; } } }
function perform() { $tree =& limb_tree :: instance(); if(isset($_REQUEST['id'])) $id = (int)$_REQUEST['id']; else $id = get_mapped_id(); if(isset($_REQUEST['expand'])) $result = $tree->expand_node($id); elseif(isset($_REQUEST['collapse'])) $result = $tree->collapse_node($id); else $result = $tree->toggle_node($id); if($result) return new response(); else return new failed_response(); }
} header("HTTP/1.1 404 Not found"); exit; } if (isset($node['only_parent_found']) && $node['only_parent_found']) { if (isset($_REQUEST['action'])) { //only action significant when reload to found parent $params = '?action=' . $_REQUEST['action']; } $tree = limb_tree::instance(); reload($tree->get_path_to_node($node) . $params); exit; } if (($object_data =& fetch_one_by_node_id($node['id'])) === false) { if (!user::is_logged_in()) { $tree = limb_tree::instance(); reload('/root/login?redirect=' . $tree->get_path_to_node($node)); exit; } else { debug::write_error('content object not allowed or retrieved', __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__); ob_end_clean(); if (debug::is_console_enabled()) { echo debug::parse_html_console(); } header("HTTP/1.1 403 Access denied"); exit; } } if (isset($object_data['locale_id']) && $object_data['locale_id']) { define('CONTENT_LOCALE_ID', $object_data['locale_id']); } else {
function _can_delete_tree_node($node_id) { $tree =& limb_tree::instance(); return $tree->can_delete_node($node_id); }
function _compare_fetch_data($record) { $id = $this->object->get_id(); $this->assertEqual($record['id'], $id, 'site object id doesnt match'); $this->assertEqual($record['node_id'], $this->object->get_node_id(), __FILE__ . ' : ' . __LINE__ . ': node id doesnt match'); $this->assertEqual($record['class_id'], $this->object->get_class_id(), __FILE__ . ' : ' . __LINE__ . ': class_id doesnt match'); $this->assertEqual($record['class_name'], get_class($this->object), __FILE__ . ' : ' . __LINE__ . ': class name doesnt match'); $this->assertEqual($record['identifier'], $this->object->get_identifier(), __FILE__ . ' : ' . __LINE__ . ': identifier doesnt match'); $this->assertEqual($record['title'], $this->object->get_title(), __FILE__ . ' : ' . __LINE__ . ': title doesnt match'); $this->assertEqual($record['parent_node_id'], $this->object->get_parent_node_id(), __FILE__ . ' : ' . __LINE__ . ': parent_node_id doesnt match'); $this->assertEqual($record['version'], $this->object->get_version(), __FILE__ . ' : ' . __LINE__ . ': version doesnt match'); $tree =& limb_tree::instance(); $node = $tree->get_node($this->object->get_node_id()); $this->assertEqual($record['l'], $node['l'], __FILE__ . ' : ' . __LINE__ . ': l doesnt match'); $this->assertEqual($record['r'], $node['r'], __FILE__ . ' : ' . __LINE__ . ': r doesnt match'); $this->assertEqual($record['level'], $node['level'], __FILE__ . ' : ' . __LINE__ . ': level doesnt match'); }
function _assign_paths(&$objects_array, $append = '') { $tree =& limb_tree::instance(); $parent_paths = array(); foreach ($objects_array as $key => $data) { $parent_id = $data['parent_id']; if (!isset($parent_paths[$parent_id])) { $parents = $tree->get_parents($data['node_id']); $path = ''; foreach ($parents as $parent_data) { $path .= '/' . $parent_data['identifier']; } $parent_paths[$parent_id] = $path; } $objects_array[$key]['path'] = $parent_paths[$parent_id] . '/' . $data['identifier'] . $append; } }
function test_get_node_id() { $php_self = $_SERVER['PHP_SELF']; $_SERVER['PHP_SELF'] = '/object_300/object_301'; $node_id = $this->object->get_node_id(); $tree =& limb_tree::instance(); $node =& $tree->get_node_by_path($_SERVER['PHP_SELF']); $this->assertEqual($node_id, $node['id']); $_SERVER['PHP_SELF'] = $php_self; }
function _create_node($identifier) { static $object_id = 1; $tree =& limb_tree :: instance(); $values['identifier'] = $identifier; $values['object_id'] = ++$object_id; $tree->create_sub_node($this->parent_node_id, $values); $class_id = $this->object->get_class_id(); $this->db->sql_insert('sys_site_object', array('id' => $object_id, 'class_id' => $class_id, 'current_version' => 1)); }
function _set_object_filter() { if (!isset($_REQUEST['stats_object_path']) || !$_REQUEST['stats_object_path']) { return; } $tree =& limb_tree::instance(); if ($node = $tree->get_node_by_path($_REQUEST['stats_object_path'])) { $this->stats_event_report->set_object_filter($node['id']); } else { $this->stats_event_report->set_object_filter(-1); } }