Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 162

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

Prepsana komponenta Table_Form - pridana podpora select boxu-filtru do vyhledavani.

Zobrazit rozdíly:

freenetis/trunk/kohana/application/models/device.php
protected $has_many = array('ifaces','ports');
protected $belongs_to = array('user');
public $arr_sql = array('id' => 'd.id', 'name' => 'd.name', 'user' => 'concat(users.name,\' \',users.surname)');
public $arr_sql = array('id' => 'd.id', 'name' => 'd.name', 'user' => 'concat(users.name,\' \',users.surname)', 'device_type'=>'d.type');
public function count_all_devices($filter_values = array())
{
......
if($key!='submit')
{
if($where!='WHERE ') $where .= ' AND ';
$where .= $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
$where .= ($key!='device_type') ? $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci' : $this->arr_sql[$key].' = '.$value;
}
}
......
if($key!='submit')
{
if($where!='WHERE ') $where .= ' AND ';
$where .= $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci';
$where .= ($key!='device_type') ? $this->arr_sql[$key].' LIKE \'%'.$value.'%\' COLLATE utf8_general_ci' : $this->arr_sql[$key].' = '.$value;
}
}
freenetis/trunk/kohana/application/controllers/members.php
$model_members = new Member_Model();
$filter=new Table_Form(url_lang::base()."members/show_all", "get", array(
"name"=>"Name",
"town"=>"Town",
"tr",
"street"=>"Street",
"td",
"submit"=>"Filter"
$filter=new Table_Form(url_lang::base()."members/show_all", "get", array(
new Table_Form_Item('text','name','Name'),
new Table_Form_Item('text','town','Town'),
"tr",
new Table_Form_Item('text','street','street'),
"td",
new Table_Form_Item('submit','submit','Filter')
)
);
freenetis/trunk/kohana/application/controllers/users.php
$data['heading'] = url_lang::lang('texts.Association members');
$model_users = new User_Model();
$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",
"member_name"=>"Member",
"tr",
"td",
"submit"=>"Filter"
$filter=new Table_Form(url_lang::base()."users/show_all", "get", array(
new Table_Form_Item('text','name','Name'),
new Table_Form_Item('text','surname','Surname'),
"tr",
new Table_Form_Item('text','email','Email'),
new Table_Form_Item('text','phone','Phone'),
"tr",
new Table_Form_Item('text','login','Login name'),
new Table_Form_Item('text','member_name','Member'),
"tr",
"td",
new Table_Form_Item('submit','submit','Filter')
)
);
//$dotaz=$model_users
freenetis/trunk/kohana/application/controllers/ip_addresses.php
$filter=new Table_Form(url_lang::base()."ip_addresses/show_all", "get", array(
"IP_address"=>"IP address",
"MAC"=>"MAC",
"tr",
"segment_name"=>"Segment name",
"device_name"=>"Device name",
"tr",
"user"=>"User",
"tr",
"td",
"submit"=>"Filter"
new Table_Form_Item('text','IP_address','IP address'),
new Table_Form_Item('text','MAC','MAC'),
"tr",
new Table_Form_Item('text','segment_name','Segment name'),
new Table_Form_Item('text','device_name','Device name'),
"tr",
new Table_Form_Item('text','user','User'),
"tr",
"td",
new Table_Form_Item('submit','submit','Filter')
)
);
freenetis/trunk/kohana/application/controllers/devices.php
//$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();
//$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();
$enum_type_model = new Enum_type_Model();
$arr_types = $enum_type_model->get_values(Enum_type_model::id_type_of_device);
$arr_types[0] = '----- '.url_lang::lang('texts.select type').' -----';
asort($arr_types);
$filter=new Table_Form(url_lang::base()."devices/show_all", "get", array(
"name"=>"Name",
"user"=>"User",
"tr",
"td",
"submit"=>"Filter"
new Table_Form_Item('text','name','Name'),
new Table_Form_Item('text','user','User'),
"tr",
new Table_Form_Item('select','device_type','Type',$arr_types),
"td",
new Table_Form_Item('submit','submit','Filter')
)
);
freenetis/trunk/kohana/application/libraries/Table_Form.php
else {
$values=array();
if ($input->$method("submit", true)) // if the form was submitted
foreach (array_keys($this->form_def) as $key) // check all its input fields
/* foreach (array_keys($this->form_def) as $key) // check all its input fields
if (!is_int($key) && $key!="submit") // ignore special fields
if (($getval=$input->$method($key, true))!="")
$values[$key]=$getval; // and store them into array as field=>values pairs
return $this->form_val=$values;
$values[$key]=$getval; // and store them into array as field=>values pairs */
foreach ($this->form_def as $value)
{
if (is_object($value) && $value->name!="submit")
{
if (($getval=$input->$method($value->name, true))!="")
$values[$value->name]=$getval;
}
}
return $this->form_val=$values;
}
}
freenetis/trunk/kohana/application/libraries/Table_Form_Item.php
<?php
class Table_Form_Item {
public $type,$name,$label,$values;
public function __construct($type='text',$name=NULL,$label=NULL,$values=array())
{
$this->type = $type;
$this->name = $name;
$this->label = $label;
$this->values = $values;
}
}
?>
freenetis/trunk/kohana/application/views/table_form.php
*
*/
echo form::open($uri, array('method'=>'get')) . "\n<table><tr>\n";
foreach ($form_def as $field=>$label) {
if (is_int($field))
switch ($label) {
case "tr":
echo "</tr><tr>\n"; break;
case "td":
echo " <td></td>\n"; break;
default:
echo $label;
} else {
switch ($field) {
foreach ($form_def as $value) {
if (is_object($value))
{
if (!isset($form_val[$value->name])) $val="";
else $val=$form_val[$value->name];
switch ($value->type) {
case "submit":
echo " <td><input name='submit' type='submit' value='"
.url_lang::lang("texts.$label")."' class=\"submit\" /></td>\n";
.url_lang::lang("texts.".$value->label)."' class=\"submit\" /></td>\n";
break;
case "select":
echo " <td><label for='".$value->name."'>".url_lang::lang('texts.'.$value->label).":</label></td><td><select name='".$value->name."'>\n";
foreach ($value->values as $key => $val_value)
{
echo " <option value='".$key."'";
echo ($val==$key) ? ' selected' : '';
echo ">".$val_value."</option>\n";
}
echo " </select></td>\n";
break;
/**
* case "input":
* here you can put implementation of other field types, like
* selections, check buttons etc.
*/
default:
if (!isset($form_val[$field])) $val="";
else $val=$form_val[$field];
echo " <td><label for='$field'>".url_lang::lang("texts.$label").":</label></td>\n"
." <td><input type='text' name='$field' value='$val'/></td>\n";
echo " <td><label for='".$value->name."'>".url_lang::lang("texts.".$value->label).":</label></td>\n"
." <td><input type='text' name='".$value->name."' value='$val'/></td>\n";
}
}
else
{
switch ($value) {
case "tr":
echo "</tr><tr>\n"; break;
case "td":
echo " <td></td>\n"; break;
default:
echo $value;
}
}
}

Také k dispozici: Unified diff