Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1d217727

Přidáno uživatelem David Raška před asi 9 roky(ů)

refs #967: Filtering destination account

Zobrazit rozdíly:

application/controllers/transfers.php
// destination account, instead of origin one
$dst_accounts = $oa->get_some_doubleentry_account_names_grouped($origin_account_id);
$dst_accounts = arr::merge(array
(
NULL => '----- ' . __('Select account') . ' -----'
), $dst_accounts);
// default destination account
$operating = ORM::factory('account')->where(
'account_attribute_id', Account_attribute_Model::OPERATING
......
->options($dst_accounts)
->rules('required')
->selected($operating->id)
->style('width:450px');
->style('width:450px')
->filter_button('transfers');
// other information
$form->group('Transfer');
......
}
}
/**
* Method used for popup filtering
*
* @author David Raska
*/
public function filter()
{
// access rights
if (!$this->acl_check_view('Accounts_Controller', 'transfers'))
{
self::error(ACCESS);
}
// account attributes for types of accounts
$aa_model = new Account_attribute_Model();
$account_attributes = $aa_model->get_account_attributes();
foreach ($account_attributes as $aattr)
{
$arr_attributes[$aattr->id] = $aattr->id . ' ' . $aattr->name;
}
// create filter form
$filter_form = new Filter_form();
$filter_form->add('member_id')
->label('Member ID')
->type('number');
$filter_form->add('mname')
->label('Member name')
->callback('json/member_name');
$filter_form->add('aname')
->label('Account name');
$filter_form->add('id')
->label('Account ID')
->type('number');
$filter_form->add('account_attribute_id')
->label('Account type')
->type('select')
->values($arr_attributes);
// filter form is submited => print only result in JSON format
if (!$filter_form->is_first_load())
{
$filter_sql = $filter_form->as_sql();
$account_model = new Account_Model();
$accounts = $account_model->get_accounts_to_dropdown($filter_sql);
// keys
$keys = array(__('Association'), __('Members'));
// result
$grouped_accounts = array
(
$keys[0] => array(),
$keys[1] => array()
);
// transform members from objects to array
$x = 0;
foreach ($accounts as $account)
{
if ($account->member_id == Member_Model::ASSOCIATION)
{
$i = 0;
}
else
{
$i = 1;
}
$grouped_accounts[$keys[$i]][$x++] = array
(
'id' => $account->id,
'name' => $account->aname.' ('.$account->id.', '.$account->account_attribute_id.', '.$account->member_id.')'
);
}
// print array with members in JSON
die(json_encode($grouped_accounts));
}
// filter form is not submited => print only form
else
{
$title = __('Filter accounts');
$view = new View('main');
$view->title = $title;
$view->content = new View('form');
$view->content->headline = $title;
$view->content->form = $filter_form;
$view->render(TRUE);
}
}
}
application/i18n/cs_CZ/texts.php
'fill in your e-mail or username' => 'Vyplňte Váš e-mail nebo přihlašovací jméno',
'filled' => 'Vyplněno',
'filter' => 'Filtrovat',
'filter accounts' => 'Filtrovat účty',
'filter devices' => 'Filtrovat zařízení',
'filter members' => 'Filtrovat členy',
'filter query has been successfully added' => 'Dotaz filtru byl úspěšně přidán.',
......
'send sms notice about received payment to member' => 'Odeslat členovi SMS zprávu s oznámením o jeho přijaté platbě',
'send verify message' => 'Odeslat ověřovací zprávu',
'select' => 'Vyber',
'select account' => 'Vyber účet',
'select account type' => 'Vyber typ účtu',
'select action' => 'Vyber činnost',
'select admin' => 'Vyber správce',
application/models/account.php
return $this->in('account_attribute_id', $aaids, TRUE)
->select_list('id', $concat, 'account_attribute_id');
}
/**
* Returns grouped accounts for use in json response for account filter
*
* @param string $filter_sql
* @return Database_Result
*/
public function get_accounts_to_dropdown($filter_sql = '')
{
$having = '';
// filter
if (!empty($filter_sql))
{
$having = "HAVING $filter_sql";
}
// query
return $this->db->query("
SELECT a.id, a.member_id, a.name as aname, m.name as mname, a.account_attribute_id
FROM accounts a
LEFT JOIN members m ON m.id = a.member_id
$having
ORDER BY aname
");
}
}
application/views/js/base.php
dropdown.append('<option>'+first_option_text+'</option>');
data = jQuery.parseJSON(data);
for (key in data)
{
dropdown.append('<option value="'+data[key].id+'">'+data[key].name+'</option>');
if ($.isArray(data[key])) // is grouped?
{
dropdown.append('<optgroup label="'+key+'">');
for (subkey in data[key])
{
dropdown.append('<option value="'+data[key][subkey].id+'">'+data[key][subkey].name+'</option>');
}
dropdown.append('</optgroup>');
}
else // no group
{
dropdown.append('<option value="'+data[key].id+'">'+data[key].name+'</option>');
}
}
}
});

Také k dispozici: Unified diff