Revize 1004
Přidáno uživatelem Michal Kliment před více než 13 roky(ů)
freenetis/branches/search_filters/application/i18n/cs_CZ/texts.php | ||
---|---|---|
'contact information' => 'Kontaktní informace',
|
||
'contact list on redirect page' => 'Kontaktní informace na stránce přesměrování',
|
||
'contact value' => 'Data kontaktu',
|
||
'contains' => 'obsahuje',
|
||
'contains not' => 'neobsahuje',
|
||
'content of file htaccess' => 'Obsah souboru .htaccess',
|
||
'content of the message' => 'Obsah zprávy',
|
||
'contractual increase' => 'Smluvní navýšení',
|
||
... | ... | |
'ip addresses list of member' => 'Seznam IP adres člena',
|
||
'ip addresses' => 'IP adresy',
|
||
'ip_address' => 'IP adresa',
|
||
'is' => 'je',
|
||
'is not' => 'není',
|
||
'it can means that username/password/host are bad or host is unavailable' => 'To může znamenat, že uživatelské jméno/heslo/hostitel je špatné nebo je hostitel nedostupný.',
|
||
'it is not possible delete used template' => 'Není možné smazat použitou šablonu.',
|
||
'it is not possible delete item of used template' => 'Není možné smazat položku použité šablony.',
|
freenetis/branches/search_filters/application/models/member.php | ||
---|---|---|
* @param $filter_values used for filtering
|
||
* @return unknown_type
|
||
*/
|
||
public function get_all_members($limit_from = 0, $limit_results = 50, $order_by = 'id', $order_by_direction = 'asc', $filter_values = array())
|
||
public function get_all_members($limit_from = 0, $limit_results = 50, $order_by = 'id', $order_by_direction = 'asc', $filter_sql = "")
|
||
{
|
||
// building of where clause
|
||
$where = array();
|
||
foreach($filter_values as $key => $value)
|
||
{
|
||
if (isset(self::$keys[$key]))
|
||
{
|
||
$column_name = (isset(self::$keys[$key]['column_name'])) ? self::$keys[$key]['column_name'] : $key;
|
||
$where = '';
|
||
if ($filter_sql != '')
|
||
$where = "WHERE $filter_sql";
|
||
|
||
// key is type of string
|
||
if (self::$keys[$key]['type'] == 'string')
|
||
{
|
||
$value = trim($value);
|
||
$items = explode(',',trim($value,','));
|
||
|
||
// split into array of conditions
|
||
$clauses = array();
|
||
foreach ($items as $item)
|
||
{
|
||
$item = trim($item);
|
||
if ($item!='')
|
||
$clauses[] = "$column_name LIKE '%".$item."%' COLLATE utf8_general_ci";
|
||
}
|
||
|
||
// convert array of conditions to one string condition
|
||
$where[] = '('.implode(' OR ', $clauses).')';
|
||
}
|
||
else if (self::$keys[$key]['type'] == 'number')
|
||
{
|
||
$value = trim($value);
|
||
|
||
// value is interval format
|
||
if (preg_match('/^([0-9]+)?-([0-9]+)?$/', $value, $matches))
|
||
{
|
||
// finding min and max of interval
|
||
$min = ($matches[1]!='')? $matches[1] : 0;
|
||
$max = (isset($matches[2]) && $matches[2]!='')? $matches[2] : 0;
|
||
|
||
if ($min && $max)
|
||
$where[] = "$column_name >= ".$min." AND $column_name <= ".$max;
|
||
else if ($min)
|
||
$where[] = "$column_name >= ".$min;
|
||
else
|
||
$where[] = "$column_name <= ".$max;
|
||
}
|
||
// value is one number
|
||
else
|
||
$where[] = "$column_name = ".(int)$value;
|
||
}
|
||
}
|
||
|
||
// special member types to filter
|
||
if ($key == 'type')
|
||
{
|
||
if ($value != 0)
|
||
{
|
||
$where[] = "m.type = $value";
|
||
}
|
||
else
|
||
// all without former members, default option
|
||
{
|
||
$enum_model = new Enum_type_Model();
|
||
$value = $enum_model->get_type_id('Former member');
|
||
$where[] = "m.type <> $value";
|
||
}
|
||
}
|
||
|
||
if ($key == 'redirect' && $value != self::$all)
|
||
{
|
||
if ($value == self::$all_redirected)
|
||
$where[] = "m.redirect > 0";
|
||
if ($value == self::$membership_interrupt)
|
||
$where[] = "m.redirect & 1 = 1";
|
||
if ($value == self::$debtors)
|
||
$where[] = "m.redirect & 2 = 2";
|
||
if ($value == self::$payment_notice)
|
||
$where[] = "m.redirect & 4 = 4";
|
||
if ($value == self::$optional_message)
|
||
$where[] = "m.redirect & 8 = 8";
|
||
}
|
||
}
|
||
// default filtering
|
||
if (count($filter_values) == 0)
|
||
{
|
||
$enum_model = new Enum_type_Model();
|
||
$value = $enum_model->get_type_id('Former member');
|
||
$where[] = "m.type <> $value";
|
||
}
|
||
|
||
$where = implode(" AND ",$where);
|
||
$where = ($where!='') ? 'WHERE '.$where : '';
|
||
|
||
return $this->db->query("
|
||
SELECT id, id AS member_id, registration, name, street, street_number, town, quarter, variable_symbol, aid, balance, redirect, GROUP_CONCAT(a_comment SEPARATOR ', \n\n') AS a_comment, a_comments_thread_id, type_name FROM
|
||
(
|
freenetis/branches/search_filters/application/controllers/members.php | ||
---|---|---|
*/
|
||
function show_all($limit_results = 100, $order_by = 'id', $order_by_direction = 'ASC', $page_word = null, $page = 1)
|
||
{
|
||
$filter_form = new Filter_form('m');
|
||
$filter_form->add('id')->type('number');
|
||
$filter_form->add('name');
|
||
$filter_form->add('type');
|
||
$filter_form->add('variable_symbol');
|
||
$filter_form->add('comment');
|
||
$filter_form->add('balance')->table('a')->type('number');
|
||
$filter_form->add('town')->table('t');
|
||
$filter_form->add('street')->table('s');
|
||
$filter_form->add('street_number')->type('number')->table('ap');
|
||
|
||
// access rights
|
||
if (!$this->acl_check_view(get_class($this),'members'))
|
||
Controller::error(ACCESS);
|
||
... | ... | |
$total_members = $model_members->count_all_members($filter->values());
|
||
if (($sql_offset = ($page - 1) * $limit_results) > $total_members)
|
||
$sql_offset = 0;
|
||
$query = $model_members->get_all_members($sql_offset, (int)$limit_results, $order_by, $order_by_direction, $filter->values());
|
||
$query = $model_members->get_all_members($sql_offset, (int)$limit_results, $order_by, $order_by_direction, $filter_form->as_sql ());
|
||
// it creates grid to view all members
|
||
$headline = url_lang::lang('texts.List of all members');
|
||
$grid = new Grid(url_lang::base().'members', null, array(
|
||
... | ... | |
'order_by_direction' => $order_by_direction,
|
||
'limit_results' => $limit_results,
|
||
'query_string' => $query_string,
|
||
'filter' => $filter->view
|
||
'filter' => $filter_form
|
||
));
|
||
// grid buttons
|
||
if ($this->acl_check_new(get_class($this), 'members'))
|
freenetis/branches/search_filters/application/libraries/Filter_form.php | ||
---|---|---|
<?php
|
||
|
||
class Filter_form
|
||
{
|
||
protected $template = 'filter_form_template';
|
||
|
||
protected $filters = array();
|
||
|
||
protected $opers = array(
|
||
1 => array(
|
||
'name' => 'contains',
|
||
'sql' => "LIKE '%{VALUE}%'",
|
||
),
|
||
2 => array(
|
||
'name' => 'contains not',
|
||
'sql' => "NOT LIKE '%{VALUE}%'",
|
||
),
|
||
3 => array(
|
||
'name' => 'is',
|
||
'sql' => "LIKE '{VALUE}'"
|
||
),
|
||
4 => array(
|
||
'name' => 'is not',
|
||
'sql' => "NOT LIKE '{VALUE}'" ,
|
||
),
|
||
5 => array(
|
||
'name' => '=',
|
||
'sql' => "= '{VALUE}'",
|
||
),
|
||
6 => array(
|
||
'name' => '!=',
|
||
'sql' => "<> '{VALUE}'",
|
||
),
|
||
7 => array(
|
||
'name' => '<',
|
||
'sql' => "< '{VALUE}'",
|
||
),
|
||
8 => array(
|
||
'name' => '<=',
|
||
'sql' => "<= '{VALUE}'",
|
||
),
|
||
9 => array(
|
||
'name' => '>',
|
||
'sql' => "> '{VALUE}'",
|
||
),
|
||
10 => array(
|
||
'name' => '>=',
|
||
'sql' => ">= '{VALUE}'",
|
||
)
|
||
);
|
||
protected $operation_types = array(
|
||
'string' => array(1,2,3,4),
|
||
'number' => array(5,6,7,8,9,10)
|
||
);
|
||
|
||
public function __construct($table = '')
|
||
{
|
||
$this->table = $table;
|
||
|
||
$this->template = new View ($this->template);
|
||
|
||
$this->types = (count($types = Input::instance()->get('t'))) ? $types : array();
|
||
$this->operations = Input::instance()->get('o');
|
||
$this->values = Input::instance()->get('v');
|
||
}
|
||
|
||
public function add ($name)
|
||
{
|
||
$filter = new Filter($name, $this->table);
|
||
|
||
$this->filters[$name] = $filter;
|
||
|
||
return $filter;
|
||
}
|
||
|
||
public function html()
|
||
{
|
||
$types = array();
|
||
foreach ($this->filters as $filter)
|
||
{
|
||
$types[$filter->name] = $filter->label;
|
||
}
|
||
|
||
$operations = array();
|
||
foreach ($this->opers as $i => $operation)
|
||
{
|
||
$operations[$i] = url_lang::lang('texts.'.$operation['name']);
|
||
}
|
||
|
||
$this->template->type_values = $types;
|
||
$this->template->operation_values = $operations;
|
||
|
||
$this->template->types = $this->types;
|
||
$this->template->operations = $this->operations;
|
||
$this->template->values = $this->values;
|
||
return $this->template->render();
|
||
}
|
||
|
||
public function as_sql ()
|
||
{
|
||
$queries = array();
|
||
foreach ($this->types as $i => $type)
|
||
{
|
||
$value = trim($this->values[$i]);
|
||
if ($value != '')
|
||
{
|
||
$filter = $this->filters[$type];
|
||
|
||
$queries[] = "$filter->table.$filter->name ".str_replace("{VALUE}", mysql_real_escape_string($value), $this->opers[$this->operations[$i]]['sql']);
|
||
}
|
||
}
|
||
|
||
return implode (" AND ", $queries);
|
||
}
|
||
|
||
public function __toString()
|
||
{
|
||
return $this->html();
|
||
}
|
||
}
|
||
|
||
?>
|
freenetis/branches/search_filters/application/libraries/Filter.php | ||
---|---|---|
<?php
|
||
|
||
class Filter
|
||
{
|
||
protected $data = array('type' => 'string');
|
||
|
||
public function __construct($name, $table = '')
|
||
{
|
||
$this->data['name'] = $name;
|
||
$this->data['label'] = url_lang::lang('texts.'.utf8::ucwords(inflector::humanize($name)));
|
||
$this->data['table'] = $table;
|
||
}
|
||
|
||
public function __get ($key)
|
||
{
|
||
if (isset ($this->data[$key]))
|
||
{
|
||
return $this->data[$key];
|
||
}
|
||
}
|
||
|
||
public function __call($method, $args)
|
||
{
|
||
if ($method == 'name')
|
||
{
|
||
// do nothing
|
||
}
|
||
else
|
||
{
|
||
$this->data[$method] = $args[0];
|
||
}
|
||
return $this;
|
||
}
|
||
}
|
||
|
||
?>
|
freenetis/branches/search_filters/application/views/filter_form_template.php | ||
---|---|---|
<?php echo form::open(NULL, array('method' => 'get')) ?>
|
||
|
||
<?php foreach ($types as $i => $type): ?>
|
||
<?php if (trim($values[$i]) != ''): ?>
|
||
<?php echo form::dropdown ('t[]', $type_values, $type) ?>
|
||
<?php echo form::dropdown ('o[]', $operation_values, $operations[$i]) ?>
|
||
<?php echo form::input(array('name' => 'v[]', 'class' => 'required', 'value' => trim($values[$i]))) ?>
|
||
<br />
|
||
<?php endif ?>
|
||
<?php endforeach ?>
|
||
<?php echo form::dropdown ('t[]', $type_values) ?>
|
||
<?php echo form::dropdown ('o[]', $operation_values) ?>
|
||
<?php echo form::input(array('name' => 'v[]', 'class' => 'required')) ?>
|
||
<br />
|
||
|
||
<?php echo form::submit(NULL, 'Send') ?>
|
||
<?php echo form::close() ?>
|
Také k dispozici: Unified diff
Takrka implementovany nove filtry. Jeste zbyva dodelat nektere javascriptove vychytavky pro vetsi komfort uzivatelu.