Projekt

Obecné

Profil

<?php defined('SYSPATH') or die('No direct script access.');
/*
* This file is part of open source system FreeNetIS
* and it is release under GPLv3 licence.
*
* More info about licence can be found:
* http://www.gnu.org/licenses/gpl-3.0.html
*
* More info about project can be found:
* http://www.freenetis.org/
*
*/

/**
*
* @package Model
*/
class Aro_group_Model extends ORM
{
/**
* Get parent id
* @param integer $id
* @return unknown_type
*/
public function get_parent_id_by_id($id)
{
return $this->db->query("
SELECT parent_id
FROM aro_groups
WHERE id=?
", array($id));
}

/**
* Get all with ID
* @param integer $id
* @return unknown_type
*/
public function get_by_id($id)
{
return $this->db->query("
SELECT *
FROM aro_groups
WHERE id=?
", array($id));
}

/**
* Gets all
* @return unknown_type
*/
public function get_all_values()
{
return $this->db->query("
SELECT * FROM aro_groups
");
}

/**
* Gets all by tree walk
* @return unknown_type
*/
public function get_traverz_tree()
{
return $this->db->query("
SELECT id, name, lft, parent_id, rgt, value
FROM aro_groups
ORDER BY lft
");
}

/**
* Gets aro groups by fk_id and type
* @return unknown_type
*/
public function get_aro_groups_by_fk_id($fk_id, $type)
{
return $this->db->query("
SELECT a.* FROM votes v
LEFT JOIN aro_groups a ON v.aro_group_id = a.id
WHERE v.fk_id = ? AND v.type = ?
GROUP BY v.aro_group_id
ORDER BY v.priority
", array($fk_id, $type));
}

/**
* Gets count of parents
* @param integer $id
* @return integer
*/
public static function count_parent($id)
{
$aro_group_model = new Aro_group_Model();

$parents = $aro_group_model->get_parent_id_by_id($id);

if ($parents->count())
{
return (1 + self::count_parent($parents->current()->parent_id));
}
return 0;
}
}
(13-13/87)