function setUp()
 {
     $this->db =& db_factory::instance();
     $this->_clean_up();
     $this->_init_site_object();
     $this->object->set_attribute('controller_name', 'site_object_controller');
     $controller_id = site_object_controller::get_id('site_object_controller');
     $this->object->set_attribute('controller_id', $controller_id);
     debug_mock::init($this);
     $user =& user::instance();
     $user->_set_id(10);
     $tree =& tree::instance();
     $values['identifier'] = 'root';
     $values['object_id'] = 100;
     $this->root_node_id = $tree->create_root_node($values, false, true);
     $class_id = $this->object->get_class_id();
     $this->db->sql_insert('sys_site_object', array('id' => 100, 'class_id' => $class_id, 'current_version' => 1));
     $values['identifier'] = 'ru';
     $values['object_id'] = 1;
     $this->parent_node_id = $tree->create_sub_node($this->root_node_id, $values);
     $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);
     $this->db->sql_insert('sys_site_object', array('id' => 10, 'class_id' => $class_id, 'current_version' => 1));
 }
	function _get_objects_to_delete($node_ids)
	{
		$params = array(
			'restrict_by_class' => false
		);
		
		$objects =& fetch_by_node_ids($node_ids, 'site_object', $counter, $params);
		
		$result = array();
		$tree = tree :: instance();
		
		foreach($objects as $id => $item)
		{
			if (!isset($item['actions']['delete']))
			{
				$objects[$id]['delete_status'] = 1;
				$objects[$id]['delete_reason'] = strings :: get('delete_action_not_accessible', 'error');
				continue;
			}
			
			$site_object =& wrap_with_site_object($item);
			if (!$site_object->can_delete())
			{
				$objects[$id]['delete_status'] = 1;
				$objects[$id]['delete_reason'] = strings :: get('cant_be_deleted', 'error');
				continue;
			}	
			
			$objects[$id]['delete_reason'] = strings :: get('ok');
			$objects[$id]['delete_status'] = 0;
			$objects[$id]['ids'][$item['node_id']] = 1;
		}
		
		return $objects;
	}
 function perform(&$request, &$response)
 {
     $tree =& tree::instance();
     $tree->initialize_expanded_parents();
     $this->_set_template_tree();
     parent::perform($request, $response);
 }
  function validate(&$dataspace)
  {
    if(!$value = $dataspace->get($this->field_name))
      return;

    $tree = tree :: instance();

    if(!$tree->is_node($this->parent_node_id))
      return;

    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(strings :: get('error_duplicate_tree_identifier', 'error'));
        break;
      }
      elseif($id != $this->node_id)
      {
        $this->error(strings :: get('error_duplicate_tree_identifier', 'error'));
        break;
      }
    }
  }
 function &search_fetch_sub_branch($path, $loader_class_name, &$counter, $params = array(), $fetch_method = 'fetch')
 {
     $tree =& tree::instance();
     $site_object =& site_object_factory::create($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 setUp()
  {
    parent :: setUp();

    $this->db =& db_factory :: instance();

    $tree =& 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 _valid_perform(&$request, &$response)
 {
     $tree =& tree::instance();
     $params = array();
     $params['identifier'] = $this->dataspace->get('identifier');
     $params['class'] = $this->dataspace->get('class_name');
     $params['title'] = $this->dataspace->get('title');
     $params['parent_node_id'] = $this->dataspace->get('parent_node_id');
     $params['controller_id'] = site_object_controller::get_id($this->dataspace->get('controller_name'));
     $object =& site_object_factory::create($params['class']);
     if (!($parent_data = fetch_one_by_node_id($params['parent_node_id']))) {
         error("parent wasn't retrieved", __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__);
     }
     $object->merge_attributes($params);
     if (!$object->create()) {
         error("object wasn't registered", __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__);
     }
     $parent_object =& site_object_factory::create($parent_data['class_name']);
     $parent_object->merge_attributes($parent_data);
     $access_policy =& access_policy::instance();
     $access_policy->save_initial_object_access($object, $parent_object);
     $request->set_status(REQUEST_STATUS_FORM_SUBMITTED);
     if ($request->has_attribute('popup')) {
         $response->write(close_popup_response($request));
     }
 }
 function _valid_perform()
 {
     $tree =& tree::instance();
     $params = array();
     $params['identifier'] = $this->dataspace->get('identifier');
     $params['parent_path'] = $this->dataspace->get('parent_path');
     $params['class'] = $this->dataspace->get('class_name');
     $params['title'] = $this->dataspace->get('title');
     $object =& site_object_factory::create($params['class']);
     $is_root = false;
     if (!($parent_data = fetch_one_by_path($params['parent_path']))) {
         if ($params['parent_path'] == '/') {
             $is_root = true;
         } else {
             error("parent wasn't retrieved", __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__);
         }
     }
     if (!$is_root) {
         $params['parent_node_id'] = $parent_data['node_id'];
     } else {
         $params['parent_node_id'] = 0;
     }
     $object->import_attributes($params);
     if (!$object->create($is_root)) {
         error("object wasn't registered", __FILE__ . ' : ' . __LINE__ . ' : ' . __FUNCTION__);
     }
     if (!$is_root) {
         $parent_object =& site_object_factory::instance($parent_data['class_name']);
         $parent_object->import_attributes($parent_data);
         $access_policy =& access_policy::instance();
         $access_policy->save_object_access($object, $parent_object);
     }
     return new close_popup_response(RESPONSE_STATUS_FORM_SUBMITTED);
 }
 function &_fetch(&$counter, $params)
 {
     $tree =& tree::instance();
     if (isset($params['order'])) {
         $order = $params['order'];
         unset($params['order']);
     } else {
         $order = array('priority' => 'ASC');
     }
     $tree_array =& parent::_fetch($counter, $params);
     $tree_array =& tree_sorter::sort($tree_array, $order, 'node_id', 'parent_node_id');
     $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;
 }
Пример #10
0
 function _load_tree()
 {
     $tree =& tree::instance();
     if (file_exists($tree->get_cache_path())) {
         unlink($tree->get_cache_path());
     }
     $tree->load_tree();
 }
 function validate(&$dataspace)
 {
     $value = $dataspace->get($this->field_name);
     $tree = tree::instance();
     if (!$tree->get_node_by_path($value)) {
         $this->error(strings::get('error_invalid_tree_path', 'error'));
     }
 }
	function check($value)
	{
		$tree = tree :: instance();
		
		if(empty($value))
		  $this->error(strings :: get('error_invalid_tree_node_id', 'error'));
		elseif(!$tree->get_node((int)$value))
			$this->error(strings :: get('error_invalid_tree_node_id', 'error'));
	} 
 function perform(&$request, &$response)
 {
     $tree =& tree::instance();
     $tree->initialize_expanded_parents();
     if ($filter_groups = session::get('filter_groups')) {
         $this->dataspace->set('filter_groups', $filter_groups);
     }
     parent::perform($request, $response);
     $this->_fill_policy();
 }
 function _check_nesting_rules($node_id, $target_node_id, $mode)
 {
     $tree =& 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 =& 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 _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 =& 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            FROM sys_stat_log sslog, sys_stat_uri ssu\r\n            WHERE\r\n            sslog.stat_uri_id = ssu.id AND\r\n            ((sslog.node_id={$root_id} AND ssu.uri='/root') OR (ssu.uri != '/root')) AND\r\n            sslog.time BETWEEN {$start_stamp} AND {$finish_stamp} AND\r\n            sslog.user_id = -1\r\n            ORDER 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 =& 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 _valid_perform(&$request, &$response)
 {
     $object =& wrap_with_site_object(fetch_requested_object());
     if (!$object->delete()) {
         message_box::write_notice(strings::get('cant_be_deleted', 'error'));
         $request->set_status(REQUEST_STATUS_FAILURE);
         return;
     }
     $tree = tree::instance();
     $tree->update_expanded_parents();
     $request->set_status(REQUEST_STATUS_FORM_SUBMITTED);
     if ($request->has_attribute('popup')) {
         $response->write(close_popup_response($request, RELOAD_SELF_URL, true));
     }
 }
 function _process_path()
 {
     $default_path = '/root/';
     $request = request::instance();
     if (!($path = $request->get_attribute('path'))) {
         return $default_path;
     }
     if (strpos($path, '?') !== false) {
         if (!($node = map_url_to_node($path))) {
             return $default_path;
         }
         $tree =& tree::instance();
         if (!($path = $tree->get_path_to_node($node))) {
             return $default_path;
         }
     }
     return $path;
 }
 function _get_path_objects_ids_array()
 {
     if (count($this->object_ids_array)) {
         return $this->object_ids_array;
     }
     $tree =& 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 =& tree::instance();
         if (!($path = $tree->get_path_to_node($node))) {
             return $default_path;
         }
     }
     return $path;
 }
	function perform(&$request, &$response)
	{
		if($request->has_attribute('recursive_search_for_node'))
			return;
		
		$tree =& tree :: instance();
				
		if(!$id = $request->get_attribute('id'))
			$id = get_mapped_id();
			
		if($request->has_attribute('expand'))
			$result = $tree->expand_node($id);
		elseif($request->has_attribute('collapse'))
			$result = $tree->collapse_node($id);
		else
			$result = $tree->toggle_node($id);
			
		if(!$result)
		  $request->set_status(REQUEST_STATUS_FAILURE);
	}
 function perform(&$request, &$response)
 {
     if ($request->has_attribute('recursive_search_for_node')) {
         return;
     }
     $tree =& tree::instance();
     $tree->initialize_expanded_parents();
     if (!($id = $request->get_attribute('id'))) {
         $id = get_mapped_id();
     }
     if ($request->has_attribute('expand')) {
         $result = $tree->expand_node($id);
     } elseif ($request->has_attribute('collapse')) {
         $result = $tree->collapse_node($id);
     } else {
         $result = $tree->toggle_node($id);
     }
     if (!$result) {
         $request->set_status(REQUEST_STATUS_FAILURE);
     }
 }
 function setUp()
 {
     $this->db =& db_factory::instance();
     $this->_clean_up();
     $this->object = new site_object_manipulation_test_version();
     debug_mock::init($this);
     $user =& user::instance();
     $user->_set_id(10);
     $tree =& tree::instance();
     $values['identifier'] = 'root';
     $values['object_id'] = 100;
     $this->root_node_id = $tree->create_root_node($values, false, true);
     $class_id = $this->object->get_class_id();
     $this->db->sql_insert('sys_site_object', array('id' => 100, 'class_id' => $class_id, 'current_version' => 1));
     $values['identifier'] = 'ru';
     $values['object_id'] = 1;
     $this->parent_node_id = $tree->create_sub_node($this->root_node_id, $values);
     $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);
     $this->db->sql_insert('sys_site_object', array('id' => 10, 'class_id' => $class_id, 'current_version' => 1));
 }
 function perform()
 {
     if (isset($_REQUEST['recursive_search_for_node'])) {
         return new response();
     }
     $tree =& 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();
     }
 }
Пример #26
0
    $project_dir = $argv[1];
} else {
    die('project dir required');
}
if (isset($argv[2])) {
    $path = $argv[2];
} else {
    $path = '/root';
}
require_once $project_dir . '/setup.php';
require_once LIMB_DIR . '/core/tree/tree.class.php';
require_once LIMB_DIR . '/core/model/site_object_factory.class.php';
require_once LIMB_DIR . '/core/model/search/full_text_indexer.class.php';
require_once LIMB_DIR . '/core/lib/db/db_factory.class.php';
set_time_limit(3000);
$tree =& tree::instance();
$indexer =& new full_text_indexer();
$db =& db_factory::instance();
echo "getting nodes from {$path}...\n";
$nodes =& $tree->get_sub_branch_by_path($path);
echo "nodes retrieved...\n";
$total = sizeof($nodes);
echo 'total nodes count = ' . $total . "...\n";
$counter = 0;
$missed_objects = array();
foreach ($nodes as $node) {
    $db->sql_exec('SELECT sc.class_name FROM sys_site_object sso, sys_class sc 
		WHERE sso.class_id=sc.id AND sso.id=' . $node['object_id']);
    if (!($row = $db->fetch_row())) {
        $missed_objects[] = $node['object_id'];
        continue;
 function perform(&$request, &$response)
 {
   $tree =& tree :: instance();
   $tree->initialize_expanded_parents();
 }
  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 =& tree :: instance();

    $node = $tree->get_node($this->object->get_node_id());
    $this->assertEqual($record['level'], $node['level'], __FILE__ . ' : ' . __LINE__ . ': level doesnt match');
  }
Пример #29
0
	function _assign_paths(&$objects_array, $append = '')
	{
		$tree =& tree :: instance();
				
		$parent_paths = array();
		
		foreach($objects_array as $key => $data)
		{
			$parent_node_id = $data['parent_node_id'];
			if (!isset($parent_paths[$parent_node_id]))
			{
				$parents = $tree->get_parents($data['node_id']);
				$path = '';
				foreach($parents as $parent_data)
					$path .= '/' . $parent_data['identifier'];
				
				$parent_paths[$parent_node_id] = $path;	
			}

			$objects_array[$key]['path'] = $parent_paths[$parent_node_id] . '/' . $data['identifier'] . $append;
		}
	}
 function _create_node($identifier)
 {
     static $object_id = 1;
     $tree =& 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));
 }