Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 142

Přidáno uživatelem Michal Kliment před více než 15 roky(ů)

Zkvalitnení prace s filtry u uzivatelu, clenu a zarizenich.

Zobrazit rozdíly:

freenetis/trunk/kohana/application/models/device.php
class Device_Model extends ORM {
protected $has_many = array('ifaces','ports');
protected $belongs_to = array('user');
protected $belongs_to = array('user');
public $arr_sql = array('id' => 'd.id', 'name' => 'd.name', 'user' => 'concat(users.name,\' \',users.surname)');
public function count_all_devices()
public function count_all_devices($filter_values = array())
{
return self::$db->count_records('devices');
$where = '';
if(count($filter_values)>0) $where .= 'WHERE ';
foreach($filter_values as $key => $value)
{
if($key!='submit')
{
if($where!='WHERE ') $where .= ' AND ';
$where .= $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
}
}
$devices = self::$db->query('SELECT d.id,IFNULL(f.translated_term,e.value) as type,d.name, CONCAT(users.name, \' \', users.surname) AS u_name,
IFNULL(ifaces.iface_count,0) AS iface_count,
IFNULL(ports.port_count,0) AS port_count FROM devices d
JOIN users ON d.user_id = users.id
LEFT JOIN enum_types e on d.type = e.id
LEFT JOIN (SELECT * FROM translations WHERE lang = "'.Config::item('locale.lang').'") f on e.value = f.original_term
LEFT JOIN (SELECT COUNT(*) as iface_count,device_id FROM ifaces GROUP BY ifaces.device_id) ifaces ON d.id=ifaces.device_id
LEFT JOIN (SELECT COUNT(*) as port_count,device_id FROM ports GROUP BY ports.device_id) ports ON d.id=ports.device_id
'.$where);
return count($devices);
}
public function get_all_devices($limit_from = 0, $limit_results = 50, $order_by = 'devices.id', $order_by_direction = 'ASC', $user_id = null, $filters = array())
{
//return self::$db->select(array('CONCAT(users.name,\' \',users.surname) as u_name', 'devices.*'))->from('devices')->join('users', 'users.id = devices.user_id')->get();
$arr_sql = array('name' => 'd.name', 'user' => 'concat(users.name,\' \',users.surname)');
if (in_array($order_by,$this->arr_sql)) $order_by = $this->arr_sql[$order_by];
$where = '';
......
if($key!='submit')
{
if($where!='WHERE ') $where .= ' AND ';
$where .= $arr_sql[$key].' LIKE \'%'.$value.'%\'';
$where .= $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
}
}
freenetis/trunk/kohana/application/models/member.php
}
public function count_all_members()
{
public function count_all_members($filter_values = array())
{
return self::$db->from('members')->count_records();
$where = '';
if(count($filter_values)>0) $where .= 'WHERE ';
foreach($filter_values as $key => $value)
{
if($key!='submit')
{
if($where!='WHERE ') $where .= ' AND ';
$where .= $key.' LIKE \'%'.trim($value).'%\' COLLATE utf8_general_ci';
}
}
$members = self::$db->query('select m.id from members m '.$where);
return count($members);
}
freenetis/trunk/kohana/application/models/user.php
protected $belongs_to = array('member');
protected $has_many = array('jobs');
public $arr_sql = array('id' => 'u.id', 'name' => 'u.name', 'surname' => 'u.surname', 'email' => 'u.email', 'phone' => 'u.phone', 'login' => 'u.login', 'member_name' => 'm.name');
public function __construct($id = false)
{
parent::__construct($id);
}
}
public function get_all_users($limit_from = 0, $limit_results = 50, $order_by = 'devices.id', $order_by_direction = 'ASC', $filter_values = array(),$member_id=NULL)
{
//return self::$db->query('select m.id, m.registration, concat(u.surname,\' \',u.name) as name, ifnull(m.street,\'-\') as street,
// ifnull(m.street_number,\'-\') as street_number,ifnull(m.town,\'-\') as town from members m
// left join users u on m.id = u.member_id group by m.id order by name limit '.$min.','.$limit_results);
$where = '';
if(count($filter_values)>0) $where .= 'WHERE ';
foreach($filter_values as $key => $value)
{
if($key!='submit')
{
if($where!='WHERE ') $where .= ' AND ';
$where .= $this->arr_sql[$key].' LIKE \'%'.trim($value).'%\' COLLATE utf8_general_ci';
}
}
if($member_id)
{
if($where=='') $where = 'WHERE u.member_id = '.$member_id;
else $where .= ' AND u.member_id = '.$member_id;
}
return self::$db->query('select u.id, u.name, u.surname, u.login, u.email, m.name as member_name from users u
join members m on u.member_id = m.id '.$where.' order by '.$this->arr_sql[$order_by].' '.$order_by_direction.' LIMIT '.$limit_from.','.$limit_results);
}
public function login_request($username = '', $password = '')
{
......
// return (bool) self::$db->where('login', $username)->where('password', sha1($password))->count_records('user');
}
public function count_all_users()
public function count_all_users($filter_values = array(), $member_id=NULL)
{
return (int) self::$db->count_records('users');
$where = '';
if(count($filter_values)>0) $where .= 'WHERE ';
foreach($filter_values as $key => $value)
{
if($key!='submit')
{
if($where!='WHERE ') $where .= ' AND ';
$where .= $this->arr_sql[$key].' LIKE \'%'.trim($value).'%\' COLLATE utf8_general_ci';
}
}
if($member_id)
{
if($where=='') $where = 'WHERE u.member_id = '.$member_id;
else $where .= ' AND u.member_id = '.$member_id;
}
$users = self::$db->query('select u.id from users u join members m on m.id = u.member_id '.$where);
return count($users);
}
public function count_all_users_by_member($member_id = NULL)
freenetis/trunk/kohana/application/controllers/members.php
$model_members = new Member_Model();
$filter=new Table_Form("get", array(
$filter=new Table_Form(url_lang::base()."members/show_all", "get", array(
"name"=>"Name",
"town"=>"Town",
"tr",
......
$sql_offset = (isset($url_array[7])) ? (int) ($url_array[7] - 1) * $limit_results : 0;
$dotaz = $model_members->get_all_members($sql_offset, (int)$limit_results, $order_by, $order_by_direction, $filter->values());
//$total_members = count($dotaz); // count all members in database
$total_members = $model_members->count_all_members();
$total_members = $model_members->count_all_members($filter->values());// count all members in database
unset($url_array);
freenetis/trunk/kohana/application/controllers/users.php
if (is_numeric($this->input->get('record_per_page'))) $limit_results = (int) $this->input->get('record_per_page');
// parameters control
$allowed_order_type = array('street', 'street_number', 'town', 'ZIP_code', 'type', 'name', 'surname','login','birthday','comment','phone','email', 'id', 'members_id');
if (!in_array(strtolower($order_by),$allowed_order_type)) $order_by = 'id';
//$allowed_order_type = array('street', 'street_number', 'town', 'ZIP_code', 'type', 'name', 'surname','login','birthday','comment','phone','email', 'id', 'member_id');
//if (!in_array(strtolower($order_by),$allowed_order_type)) $order_by = 'id';
if (strtolower($order_by_direction) != 'asc' && strtolower($order_by_direction) != 'desc') $order_by_direction = 'asc';
$data['title'] = url_lang::lang('texts.Association members');
$data['heading'] = url_lang::lang('texts.Association members');
$model_users = new User_Model();
$total_users = $model_users->count_all_users(); // count all members in database
$url_array = explode('/', trim(url::current(), '/'));
$sql_offset = (isset($url_array[7])) ? (int) ($url_array[7] - 1) * $limit_results : 0;
unset($url_array);
$sql_offset = ($sql_offset>$total_users) ? 0 : $sql_offset;
$filter=new Table_Form("get", array(
$filter=new Table_Form(url_lang::base()."users/show_all", "get", array(
"name"=>"Name",
"surname"=>"Surname",
"tr",
"email"=>"Email",
"phone"=>"Phone",
"tr",
"login"=>"Login name",
"td",
"login"=>"Login name",
"member_name"=>"Member",
"tr",
"td",
"submit"=>"Filter"
)
);
$dotaz=$model_users
-> like($filter->values())
-> orderby($order_by,$order_by_direction)
-> limit($limit_results,$sql_offset)
-> find_all();
//$dotaz=$model_users
// -> like($filter->values())
// -> orderby($order_by,$order_by_direction)
// -> limit($limit_results,$sql_offset)
// -> find_all();
$total_users = $model_users->count_all_users($filter->values()); // count all members in database
$url_array = explode('/', trim(url::current(), '/'));
$sql_offset = (isset($url_array[7])) ? (int) ($url_array[7] - 1) * $limit_results : 0;
unset($url_array);
$sql_offset = ($sql_offset>$total_users) ? 0 : $sql_offset;
$dotaz = $model_users->get_all_users($sql_offset, (int)$limit_results, $order_by, $order_by_direction, $filter->values());
$grid = new Grid(url_lang::base().'users', url_lang::lang('texts.List of all users'),array(
'separator' => '',
//'use_paginator' => false,
......
'style' => 'classic',
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results
'limit_results' => $limit_results,
'query_string' => $this->input->get()
));
//$grid->add_new_button(url_lang::base().'users/add', url_lang::lang('texts.Add new user'));
......
$grid->order_field('name')->label(url_lang::lang('texts.Name'));
$grid->order_field('surname')->label(url_lang::lang('texts.Surname'));
$grid->order_field('login')->label(url_lang::lang('texts.Username'));
$grid->order_field('email')->label('E-mail');
$grid->order_field('email')->label('E-mail');
$grid->order_field('member_name')->label(url_lang::lang('texts.Member'));
$grid->action_field('id') ->label(url_lang::lang('texts.Show')) ->url(url_lang::base().'users/show') ->action(url_lang::lang('texts.Show'));
$grid->action_field('id') ->label(url_lang::lang('texts.Edit')) ->url(url_lang::base().'users/edit') ->action(url_lang::lang('texts.Edit'));
// $grid->action_field('id')->label(url_lang::lang('texts.Delete'))->url(url_lang::base().'users/delete')->action(url_lang::lang('texts.Delete'))->script('onclick="return potvrd(\''.url_lang::lang('texts.delete_user').'\');"');
......
$total_users = $model_users->count_all_users_by_member($member_id); // count all members in database
$url_array = explode('/', trim(url::current(), '/'));
$sql_offset = (isset($url_array[8])) ? (int) ($url_array[8] - 1) * $limit_results : 0;
unset($url_array);
$sql_offset = ($sql_offset>$total_users) ? 0 : $sql_offset;
$filter=new Table_Form("get", array(
$filter=new Table_Form(url_lang::base()."users/show_by_member/".$member_id, "get", array(
"name"=>"Name",
"surname"=>"Surname",
"tr",
......
"submit"=>"Filter"
)
);
$dotaz=$model_users
-> like($filter->values())
-> orderby($order_by,$order_by_direction)
-> where('member_id',$member_id)
-> limit($limit_results,$sql_offset)
-> find_all();
//$dotaz=$model_users
// -> like($filter->values())
// -> orderby($order_by,$order_by_direction)
// -> where('member_id',$member_id)
// -> limit($limit_results,$sql_offset)
// -> find_all();
$total_users = $model_users->count_all_users($filter->values(),$member_id); // count all members in database
$url_array = explode('/', trim(url::current(), '/'));
$sql_offset = (isset($url_array[8])) ? (int) ($url_array[8] - 1) * $limit_results : 0;
unset($url_array);
$sql_offset = ($sql_offset>$total_users) ? 0 : $sql_offset;
$dotaz = $model_users->get_all_users($sql_offset, (int)$limit_results, $order_by, $order_by_direction, $filter->values(),$member_id);
$grid = new Grid(url_lang::base().'users', url_lang::lang('texts.List of users of member').' '.$member->name,array(
'separator' => '',
......
'selector_increace' => 200, // increace
'selector_min' => 200, // minimum where selector start
'selector_max_multiplier' => 10,
'base_url' => Config::item('locale.lang').'/users/show_all/'.$limit_results.'/'.$order_by.'/'.$order_by_direction ,
'base_url' => Config::item('locale.lang').'/users/show_by_member/'.$member_id.'/'.$limit_results.'/'.$order_by.'/'.$order_by_direction ,
'uri_segment' => 'page', // pass a string as uri_segment to trigger former 'label' functionality
'total_items' => $total_users, // use db count query here of course
'items_per_page' => $limit_results, // it may be handy to set defaults for stuff like this in config/pagination.php
freenetis/trunk/kohana/application/controllers/devices.php
$device_model = new Device_Model;
$total_devices = $device_model->count_all_devices(); // count all members in database
// get new selector
if (is_numeric($this->input->get('record_per_page'))) $limit_results = (int) $this->input->get('record_per_page');
$url_array = explode('/', trim(url::current(), '/'));
$sql_offset = (isset($url_array[7])) ? (int) ($url_array[7] - 1) * $limit_results : 0;
unset($url_array);
$sql_offset = ($sql_offset>$total_devices) ? 0 : $sql_offset;
//$dotaz = $this->model_members->get_all_members($sql_offset, (int)$limit_results, $order_by, $order_by_direction); // get all members from database
//$dotaz = $device_model->find_all();
//$dotaz = $device_model->select(array('CONCAT(users.name,\' \',users.surname) as u_name', 'devices.*'))->join('users', 'devices.user_id = users.id')->orderby($order_by,$order_by_direction)->limit($limit_results,$sql_offset)->find_all();
$filter=new Table_Form("get", array(
$filter=new Table_Form(url_lang::base()."devices/show_all", "get", array(
"name"=>"Name",
"user"=>"User",
"tr",
......
)
);
$filters = $filter->values();
$query = $device_model->get_all_devices($sql_offset, (int)$limit_results, $order_by, $order_by_direction, NULL, $filters);
$total_devices = $device_model->count_all_devices($filter->values());
// get new selector
if (is_numeric($this->input->get('record_per_page'))) $limit_results = (int) $this->input->get('record_per_page');
$url_array = explode('/', trim(url::current(), '/'));
$sql_offset = (isset($url_array[7])) ? (int) ($url_array[7] - 1) * $limit_results : 0;
unset($url_array);
$sql_offset = ($sql_offset>$total_devices) ? 0 : $sql_offset;
$query = $device_model->get_all_devices($sql_offset, (int)$limit_results, $order_by, $order_by_direction, NULL, $filter->values());
$grid = new Grid(url_lang::base().'devices', url_lang::lang('texts.Devices list'),array(
//'separator' => '<br />-----------',
//'use_paginator' => false,
......
'style' => 'classic',
'order_by' => $order_by,
'order_by_direction' => $order_by_direction,
'limit_results' => $limit_results
'limit_results' => $limit_results,
'query_string' => $this->input->get()
));
$grid->add_new_button(url_lang::base().'devices/add', url_lang::lang('texts.Add new device'));
freenetis/trunk/kohana/application/views/table_form.php
* which contains the initial values for the form fields
*
*/
echo form::open(NULL, array('method'=>'get')) . "\n<table><tr>\n";
echo form::open($uri, array('method'=>'get')) . "\n<table><tr>\n";
foreach ($form_def as $field=>$label) {
if (is_int($field))
switch ($label) {

Také k dispozici: Unified diff