function & _fetch(&$counter, $params)
	{
		if(!$result =& parent :: _fetch($counter, $params))
			return $result;
		
		$user_ids = complex_array :: get_column_values('user_id', $result);

		$fetcher =& fetcher :: instance();
		
		$params = array(
			'restrict_by_class' => false
		);
		
		$user_counter = 0;
		$users =& $fetcher->fetch_by_ids($user_ids, 'user_object', $user_counter, $params, 'fetch_by_ids');

		foreach($result as $key => $data)
		{
			if (!isset($users[$data['user_id']]))
				continue;
				
			$customer_data = $users[$data['user_id']];
			$result[$key]['user_name'] = $customer_data['name'];
			$result[$key]['user_lastname'] = $customer_data['lastname'];
			$result[$key]['user_secondname'] = $customer_data['secondname'];
			$result[$key]['user_email'] = $customer_data['email'];
			$result[$key]['user_phone'] = $customer_data['phone'];
		}	

		return $result;
	}
	function & get_dataset(&$counter, $params=array())
	{
		$counter = 0;
		
		$mapped_node = map_request_to_node();
		
		$links_manager = new links_manager();
		
		$groups = array();
		
		if(isset($params['group_identifier']))
		{
		  if($group = $links_manager->fetch_group_by_identifier($params['group_identifier']))
		    $groups[$group['id']] = $group;
		}
		else
		  $groups = $links_manager->fetch_groups();

		if (!is_array($groups) || !count($groups))
		  return new empty_dataset();

		if(isset($params['back_links']) && $params['back_links'])
		  $links = $links_manager->fetch_back_links($mapped_node['id'], array_keys($groups));
		else
		  $links = $links_manager->fetch_target_links($mapped_node['id'], array_keys($groups));

		if (!is_array($links) || !count($links))
		  return new array_dataset($groups);
		
		$target_node_ids = complex_array :: get_column_values('target_node_id', $links);
				
		if (!is_array($target_node_ids) || !count($target_node_ids))
		  return new array_dataset($groups);

		$site_object_class_name = isset($params['loader_class_name']) ? $params['loader_class_name'] : 'site_object';
		$objects =& fetch_by_node_ids($target_node_ids, $site_object_class_name, $counter, array(
		  'restrict_by_class' => false
		));
		
		$result = array();
		
		foreach($groups as $group_id => $group)
		{
      $groups[$group_id]['links'] = array();
      
		  foreach($links as $link_id => $link)
		  {
		    if ($link['group_id']!= $group_id)
		      continue;
		    
		    //if (!isset($objects[$link['target_node_id']]))
		    //  continue;
        
        $link_data = array_merge($objects[$link['target_node_id']], $link);
        $groups[$group_id]['links'][$link_id] = $link_data;
		  }
		}
		
		return new array_dataset($groups);
	}		
Ejemplo n.º 3
0
 function &fetch_sub_branch($path, $loader_class_name, &$counter, $params = array(), $fetch_method = 'fetch_by_ids')
 {
     $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->fetch_by_ids($object_ids, $loader_class_name, $counter, $params, $fetch_method);
     return $result;
 }
 function get_max_column_value($column_name, $array, &$index)
 {
     $index = 0;
     if (!($values = complex_array::get_column_values($column_name, $array))) {
         return false;
     }
     $max = max($values);
     $index = array_search($max, $values);
     return $max;
 }
 function get_classes_list()
 {
     $project_db = str_replace('_tests', '', DB_NAME);
     $db =& db_factory::instance();
     $db->select_db($project_db);
     $db->sql_select('sys_class', '*', 'class_name != "site_object"');
     $list = $db->get_array();
     $db->select_db(DB_NAME);
     return complex_array::get_column_values('class_name', $list);
 }
 function _check_db_table($db_table)
 {
     $table_name = $db_table->get_table_name();
     $primary_key_name = $db_table->get_primary_key_name();
     $columns = $db_table->get_columns();
     $this->db->sql_exec('SHOW TABLES LIKE "' . $table_name . '"');
     if (!($res = $this->db->fetch_row())) {
         //???
         return;
     }
     $this->assertEqual(sizeof($res), 1, $table_name . ' doesnt exist in db');
     $this->db->sql_exec('SHOW COLUMNS FROM ' . $table_name);
     $db_columns = $this->db->get_array();
     $a1 = complex_array::get_column_values('Field', $db_columns);
     $a2 = array_keys($columns);
     foreach ($a1 as $column) {
         $this->assertTrue(in_array($column, $a2), $table_name . ' column "' . $column . '" not in db');
     }
     $db_primary_key_name = '';
     foreach ($db_columns as $db_column) {
         if ($db_column['Key'] == 'PRI') {
             $db_primary_key_name = $db_column['Field'];
         }
         $status_string = 'db table:"' . $table_name . '"  field definition:"' . $db_column['Field'] . ' does not exist in class';
         $this->assertTrue(in_array($db_column['Field'], array_keys($columns)), $status_string);
         $type = $db_table->get_column_type($db_column['Field']);
         $status_string = 'db table:"' . $table_name . '"  column:"' . $db_column['Field'] . '"  db type: "' . $db_column['Type'] . '" expected: ';
         switch ($type) {
             case '':
             case 'string':
                 $this->assertWantedPattern('/char|text/', $db_column['Type'], $status_string . 'string');
                 break;
             case 'blob':
                 $this->assertWantedPattern('/blob/', $db_column['Type'], $status_string . 'blob');
                 break;
             case 'numeric':
                 $this->assertWantedPattern('/int|double|dec|float/', $db_column['Type'], $status_string . 'numeric');
                 break;
             case 'float':
                 $this->assertWantedPattern('/float/', $db_column['Type'], $status_string . 'float');
                 break;
             case 'date':
                 $this->assertWantedPattern('/date/', $db_column['Type'], $status_string . 'date');
                 break;
             default:
                 $this->assertTrue(false, 'Unknown type: ' . $status_string);
         }
     }
     if ($primary_key_name) {
         $this->assertEqual($db_primary_key_name, $primary_key_name, 'table ' . $table_name . ': ' . $primary_key_name . ' primary key not found');
     }
 }
  function _do_sort(& $tree_array, & $sorted_tree_array, $sort_params, $parent_id, $id_hash, $parent_hash)
  {
 		$children = array();
 		
  	foreach($tree_array as $index => $item)
  	{
  		if($item[$parent_hash] == $parent_id)
  		{
  			$children[] = $item;
  			unset($tree_array[$index]);
  		}
  	}

  	if(!($count = sizeof($children)))
  		return;
		
		$children = complex_array :: sort_array($children, $sort_params);
		
		if(!$sorted_tree_array)
		{
			$sorted_tree_array = $children;
		}
		else
		{
			$ids = complex_array :: get_column_values($id_hash, $sorted_tree_array);
			
			$offset = array_search($parent_id, $ids) + 1;
			
			array_splice($sorted_tree_array, $offset, 0, $children);
		}
		
    for($i=0; $i < $count; $i++)
    {
	   	tree_sorter :: _do_sort($tree_array, $sorted_tree_array, $sort_params, $children[$i][$id_hash], $id_hash, $parent_hash);
    }
  }  
	function assign_actions_to_objects(&$objects)
	{
		$controllers = array();
		$permitted_actions = array();
		
		if(isset($objects['id']))
		{
			$available_permissions = $this->_load_objects_available_permissions(array($objects['id']));
			$arr[] =& $objects;
		}
		else
		{
			$available_permissions = $this->_load_objects_available_permissions(complex_array :: get_column_values('id', $objects));
			$arr =& $objects;
		}
		
		foreach($arr as $key => $data)
		{
			$class_id = $data['class_id'];
			
			$arr[$key]['actions'] = array();
						
			if (!isset($actions_definitions[$class_id]))
			{
				$site_object_controller =& $this->_get_controller($data['class_name']);
				$actions_definitions[$class_id] = $site_object_controller->get_actions_definitions();
			}	

			if (!isset($permitted_type_actions[$class_id]))
				$permitted_actions[$class_id] = $this->_get_type_accessible_actions($class_id);
			
			$permitted_type_actions =& $permitted_actions[$class_id];			
			$all_actions =  $actions_definitions[$class_id];

			if (!isset($available_permissions[$data['id']]))
				continue;
				
			$object_available_permissions = $available_permissions[$data['id']];

			foreach($all_actions as $action_name => $action_params)
			{
				if (!isset($action_params['permissions_required']))
				{
			   	error('action permissions not set',
		    		 __FILE__ . ' : ' . __LINE__ . ' : ' .  __FUNCTION__, 
		    		array(
		    			'site_object_controller' => $controller_class_name,
		    			'action' => $action_name,
	    			)
		    	);
				}
				
				if ((($action_params['permissions_required'] == 'r' && $object_available_permissions['r'] > 0)
				 || ($action_params['permissions_required'] == 'w' && $object_available_permissions['w'] > 0)
				 || ($action_params['permissions_required'] == 'rw' && ($object_available_permissions['w'] > 0 && $object_available_permissions['r'] > 0)))
				&& (isset($permitted_type_actions[$action_name])))
				{
					$arr[$key]['actions'][$action_name] = $action_params;
				}	
			}			
		}
	}
	function _delete_operation($conditions, $affected_rows)
	{
		parent :: _delete_operation($conditions, $affected_rows);
		
		$this->_delete_media_files(complex_array :: get_column_values('id', $affected_rows));
	}	
Ejemplo n.º 10
0
	function & fetch_sub_branch($path, $loader_class_name, &$counter, $params = array(), $fetch_method = 'fetch_by_ids')
	{		
		$tree =& tree :: instance();
		$site_object =& site_object_factory :: instance($loader_class_name);
		
		if ($loader_class_name != 'site_object' &&
				!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;

		if (isset($params['only_parents']))
			$only_parents = (bool)$params['only_parents'];
		else
			$only_parents = 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, $only_parents))
			return array();
						
		if(!$object_ids = complex_array :: get_column_values('object_id', $nodes))
			return array();
				
		$objects_data =& $this->fetch_by_ids($object_ids, $loader_class_name, $counter, $params, $fetch_method);
		
		return $objects_data;
	}
  function get_min_column_value($column_name, $array, &$index)
  {
    $index = 0;

    if(!$values = complex_array :: get_column_values($column_name, $array))
      return false;

    $min = min($values);

    $index = array_search($min, $values);

    return $min;
  }
Ejemplo n.º 12
0
 function remove(&$site_object)
 {
     $indexer =& indexer::instance();
     $indexer->db =& db_factory::instance();
     $object_id = $site_object->get_id();
     $indexer->db->sql_exec("SELECT word_id FROM sys_word_link WHERE object_id='{$object_id}'");
     $word_array =& $indexer->db->get_array();
     $word_ids_array = complex_array::get_column_values('word_id', $word_array);
     if (count($word_ids_array) > 0) {
         $word_id_string = implode(',', $word_ids_array);
         if (count($word_ids_array) > 0) {
             $indexer->db->sql_exec("UPDATE sys_word SET object_count=( object_count - 1 ) WHERE id in ( {$word_id_string} )");
         }
         $indexer->db->sql_exec("DELETE FROM sys_word WHERE object_count='0'");
         $indexer->db->sql_exec("DELETE FROM sys_word_link WHERE object_id='{$object_id}'");
     }
 }
  function fetch_back_links_node_ids($target_node_id, $groups_ids = array())
  {
    $links = $this->fetch_back_links($target_node_id, $groups_ids);

    return complex_array :: get_column_values('linker_node_id', $links);
  }