Also adds support for calculating totals.
Use:
$list = $this->add('CompleteLister');
$list->setModel('User');
$list->addTotals();
Template (view/users.html):
Users
Joe Blogs
Sample template. Will be ignored
user.function formatRow() { //calculating url if ($this->model['custom_link']) { // if custom link contains http or https then redirect to that website $has_https = strpos($this->model['custom_link'], "https"); $has_http = strpos($this->model['custom_link'], "http"); if ($has_http === false or $has_https === false) { $url = $this->app->url($this->model['custom_link'], ['xsnb_category_id' => $this->model->id]); } else { $url = $this->model['custom_link']; } $this->current_row_html['url'] = $url; } else { $url = $this->app->url($this->options['url_page'], ['xsnb_category_id' => $this->model->id]); $this->current_row_html['url'] = $url; } $sub_cat = $this->add('xepan\\commerce\\Model_Category', ['name' => 'model_child_' . $this->model->id]); $sub_cat->addCondition('parent_category_id', $this->model->id); $sub_cat->addCondition('status', "Active"); $sub_cat->setOrder('display_sequence', 'desc'); if ($sub_cat->count()->getOne() > 0) { $sub_c = $this->add('xepan\\commerce\\View_CategoryLister', ['options' => $this->options], 'nested_category', ['view\\tool\\/' . $this->options['custom_template'], 'category_list']); $sub_c->setModel($sub_cat); $this->current_row_html['nested_category'] = $sub_c->getHTML(); } else { $this->current_row_html['nested_category'] = ""; } parent::formatRow(); }
function setController($name) { parent::setController($name); $this->dq = $this->controller->getModel()->view_dsql($this->name); $this->api->addHook('pre-render', array($this->controller, 'execQuery')); return $this; }
function formatRow() { if ($this->model['is_starred']) { $this->current_row['starred'] = 'starred'; } else { $this->current_row['starred'] = ''; } $einfo = $this->model['extra_info']; if (isset($einfo['seen_by']) and is_array($einfo['seen_by'])) { if (in_array($this->app->employee->id, $einfo['seen_by'])) { $this->current_row['unread'] = ''; } else { $this->current_row['unread'] = 'unread'; } } if (!$this->model['attachment_count']) { $this->current_row['check_attach'] = ''; } else { $this->current_row_html['check_attach'] = '<a href="#" class="attachment"><i class="fa fa-paperclip"></i></a>'; } if ($this->model['status'] == "Draft") { $this->current_row['draft'] = 'draft-message'; } $mailbox = explode('#', $this->model['mailbox']); $email_model = $this->add('xepan\\communication\\Model_Communication_EmailSetting'); $email_model->tryLoadBy('email_username', $mailbox); $this->current_row['body'] = strip_tags($this->current_row['body']); if ($this->model['status'] == 'Sent') { $this->current_row['email_name'] = $email_model['name'] . " / " . $this->model['status']; } else { $this->current_row['email_name'] = $email_model['name']; } parent::formatRow(); }
function formatRow() { $this->current_row_html['collapse_header'] = strip_tags($this->model['description']); $this->current_row_html['body'] = $this->model['description']; $attach = $this->add('xepan\\communication\\View_Lister_Attachment', null, 'attachments'); $attach->setModel('xepan\\communication\\Communication_Attachment')->addCondition('communication_id', $this->model['communication_id']); $this->current_row_html['attachments'] = $attach->getHtml(); parent::formatRow(); }
function formatRow() { if ($this->model['check_login'] != '0') { $this->current_row_html['color'] = "#8bc34a"; } else { $this->current_row_html['color'] = "red"; } parent::formatRow(); }
function init() { parent::init(); $total_alerts = $this->api->current_website->ref('Alerts')->count()->getOne(); $new_alerts = $this->api->current_website->ref('Alerts')->addCondition('is_read', false)->count()->getOne(); $this->template->trySet('total_alerts', $total_alerts); $this->template->trySet('new_alerts', $new_alerts); $b = $this->add('Button', null, 'viewAll')->setHTML('View All'); // if($b->isClicked()) }
function setModel($model) { $m = parent::setModel($model); $post = $this->add('xepan\\blog\\Model_BlogPost')->load($m['blog_post_id']); if ($post['show_comments'] === 'hide') { $this->template->del('comment_wrapper'); $this->template->trySet('msg', 'Comments are closed for this post'); } else { if ($post['anonymous_comment_config'] === 'none' && $post['registered_comment_config'] === 'none') { return $m; } } $sub_form = $this->add('Form', null, 'comment_form_' . $this->options['comment_form_position']); $comment_field = $sub_form->addField('text', 'Comment')->validate('required'); $sub_form->addSubmit('Submit')->addClass('btn btn-primary btn-lg'); if ($this->app->recall('comment')) { $comment_field->set($this->app->recall('comment')); $this->app->forget('comment'); } if ($sub_form->isSubmitted()) { if ($this->options['allow_anonymous_comment'] === false || $post['anonymous_comment_config'] === 'none') { $contact = $this->add('xepan\\base\\Model_Contact'); if ($contact->loadLoggedIn()) { $comment_model = $this->add('xepan\\blog\\Model_Comment'); $comment_model['comment'] = $sub_form['Comment']; $comment_model['blog_post_id'] = $m['blog_post_id']; $comment_model['created_by_id'] = $contact->id; $comment_model['status'] = $post['registered_comment_config'] == 'moderate' ? 'Pending' : 'Approved'; $comment_model->save(); if ($comment_model['status'] === 'Pending') { $msg_string = "Your message has been sent for approval"; } else { $msg_string = "Done"; } $sub_form->js(null, $this->js()->reload())->univ()->successMessage($msg_string)->execute(); } else { $this->api->memorize('comment', $sub_form['Comment']); $this->api->memorize('next_url', array('page' => $_GET['page'], 'post_id' => $_GET['post_id'])); $this->app->redirect($this->options['login_page']); } } $comment_model = $this->add('xepan\\blog\\Model_Comment'); $comment_model['comment'] = $sub_form['Comment']; $comment_model['blog_post_id'] = $m['blog_post_id']; $comment_model['status'] = $post['anonymous_comment_config'] == 'moderate' ? 'Pending' : 'Approved'; $comment_model->save(); if ($comment_model['status'] === 'Pending') { $msg_string = "Your message has been sent for approval"; } else { $msg_string = "Done"; } $sub_form->js(null, $this->js()->reload())->univ()->successMessage($msg_string)->execute(); } return $m; }
function init() { parent::init(); $total_messages = $this->api->current_website->ref('Messages')->count()->getOne(); $msg = $this->add('Model_Messages'); $msg->addCondition($msg->_dsql()->orExpr()->where('is_read', false)->where('watch', true)); $new_messages = $msg->count()->getOne(); $this->template->trySet('total_messages', $total_messages); $this->template->trySet('new_messages', $new_messages); $b = $this->add('Button', null, 'viewInbox')->setHTML('View Inbox'); }
function setModel($model, $fields = null) { // $model->setOrder('name'); parent::setModel($model, $fields); if ($this->model->count()->getOne() > 0) { $this->template->tryDel('no_record_found'); } if (!$this->loadmore) { $this->template->tryDel('loadmore'); } }
function init() { parent::init(); if ($this->pop) { if ($this->pop instanceof jQuery_Chain) { $this->on('click', '.do-cog', $this->pop); } else { $this->on('click', '.do-cog', $this->pop->showjS(array('width' => $this->pop_width ?: 450, 'my' => 'right top', 'at' => 'right+5 bottom+5', 'arrow' => 'vertical top right'))); } } else { $this->template->tryDel('cog'); } }
function formatRow() { $amount = $this->model['amountDr'] - $this->model['amountCr']; if ($amount > 0) { $balance = $amount . " DR"; } else { $balance = abs($amount) . " CR"; } $this->current_row['s_no'] = $this->sno++; $this->current_row['created_date'] = date('Y-m-d', strtotime($this->model->get('created_at'))); $this->current_row['balance'] = $balance; parent::formatRow(); }
function formatRow() { parent::formatRow(); $v = $this->add('View', 'search_' . $this->current_row['id'], 'name')->set($this->current_row['name']); if ($this->current_row['name'] == "clear") { $v->addClass('clear_filter'); } $v->addStyle('cursor', 'pointer'); if ($this->api->recall($this->owner->name . '_filter') == strtoupper($this->current_row['name'])) { $v->addClass('current'); } $v->js('click', array($this->owner->grid->js()->reload(array($this->owner->name . '_filter' => $v->js()->text())))); $this->current_row_html['name'] = $v->getHTML(); }
function applyHook() { if (!isset($this->source)) { if ($this->owner->dq) { $this->setSource($this->owner->dq); } } if (!isset($this->source)) { throw $this->exception('Unable to find source for Paginator'); } if ($this->source instanceof DB_dsql || $this->source instanceof Model_Array) { // Set the limit first, then execute $this->source->limit($this->ipp, $this->skip); if (!$this->source->stmt) { $this->source->execute(); } // execute early but not fetch $this->found_rows = $this->source->foundRows(); $this->cur_page = floor($this->skip / $this->ipp) + 1; $this->total_pages = ceil($this->found_rows / $this->ipp); if ($this->cur_page > $this->total_pages) { $this->cur_page = 1; $this->skip = $this->ipp * ($this->cur_page - 1); $this->source->limit($this->ipp, $this->skip); $this->source->rewind()->execute(); // re-execute the query } } else { // TODO: array_slice $this->found_rows = count($this->source); } if ($this->total_pages <= 1) { return $this->destroy(); } if ($this->cur_page > 1) { $this->add('View', null, 'prev')->setElement('a')->setAttr('href', $this->api->url(null, $u = array($this->name . '_skip' => $pn = max(0, $this->skip - $this->ipp))))->setAttr('data-skip', $pn)->set('← Prev'); } if ($this->cur_page < $this->total_pages) { $this->add('View', null, 'next')->setElement('a')->setAttr('href', $this->api->url(null, $u = array($this->name . '_skip' => $pn = $this->skip + $this->ipp)))->setAttr('data-skip', $pn)->set('Next →'); } // // generate our source now $data = array(); foreach (range(max(1, $this->cur_page - $this->range), min($this->total_pages, $this->cur_page + $this->range)) as $p) { $data[] = array('href' => $this->api->url(null, array($this->name . '_skip' => $pn = ($p - 1) * $this->ipp)), 'pn' => $pn, 'cur' => $p == $this->cur_page ? $this->template->get('cur') : '', 'label' => $p); } $this->js('click', $this->owner->js()->reload(array($this->name . '_skip' => $this->js()->_selectorThis()->attr('data-skip'))))->_selector('#' . $this->name . ' a'); parent::setSource($data); }
function formatRow() { $email = $this->add('xepan\\communication\\Model_Communication_Email_Received'); $email->addCondition('direction', 'In'); $email->addCondition('mailbox', $this->model['email_username'] . '#INBOX'); $email_count = $email->count()->getOne(); $unreademail = $this->add('xepan\\communication\\Model_Communication_Email_Received'); $unreademail->addCondition('direction', 'In'); $unreademail->addCondition('mailbox', $this->model['email_username'] . '#INBOX'); $unreademail->addCondition('extra_info', 'not like', '%' . $this->app->employee->id . '%'); $unread_email = $unreademail->count()->getOne(); $this->current_row['email_count'] = $email_count; $this->current_row['unread_email'] = $unread_email; return parent::formatRow(); }
function formatRow() { $jobcard = $this->add('xepan\\production\\Model_Jobcard'); $jobcard->addCondition('order_item_id', $this->order_detail_id); $jobcard->addCondition('department_id', $this->model->id); $jobcard->tryLoadAny(); $this->current_row_html['jobcard_no'] = $jobcard['id']; $this->current_row_html['status'] = $jobcard['status']; $this->current_row_html['created_at'] = $jobcard['created_at']; if ($jobcard->loaded()) { $this->current_row_html['active'] = "active"; } else { $this->current_row_html['active'] = "deactive"; } parent::formatRow(); }
function recursiveRender() { if (!$this->source) { if ($this->owner->model) { if ($this->owner instanceof Grid_Advanced) { $this->owner->getIterator(); } // force grid->model sorting implemented in Grid_Advanced $this->setSource($this->owner->model); } } if (!isset($this->source)) { throw $this->exception('Unable to find source for Paginator'); } if ($this->source instanceof DB_dsql) { $this->source->preexec(); $this->found_rows = $this->source->foundRows(); } else { $this->found_rows = count($this->source); } $this->cur_page = floor($this->skip / $this->ipp) + 1; $this->total_pages = ceil($this->found_rows / $this->ipp); if ($this->cur_page > $this->total_pages || $this->cur_page == 1 && $this->skip != 0) { $this->cur_page = 1; $this->learn('skip', $this->skip = 0); $this->source->limit($this->ipp, $this->skip); $this->source->rewind(); // re-execute the query } if ($this->total_pages <= 1) { return $this->destroy(); } if ($this->cur_page > 1) { $this->add('View', null, 'prev')->setElement('a')->setAttr('href', $this->api->url(null, $u = array($this->name . '_skip' => $pn = max(0, $this->skip - $this->ipp))))->setAttr('data-skip', $pn)->set('← Prev'); } if ($this->cur_page < $this->total_pages) { $this->add('View', null, 'next')->setElement('a')->setAttr('href', $this->api->url(null, $u = array($this->name . '_skip' => $pn = $this->skip + $this->ipp)))->setAttr('data-skip', $pn)->set('Next →'); } // generate our source now $data = array(); foreach (range(max(1, $this->cur_page - $this->range), min($this->total_pages, $this->cur_page + $this->range)) as $p) { $data[] = array('href' => $this->api->url(null, array($this->name . '_skip' => $pn = ($p - 1) * $this->ipp)), 'pn' => $pn, 'cur' => $p == $this->cur_page ? $this->template->get('cur') : '', 'label' => $p); } $this->js('click', $this->owner->js()->reload(array($this->name . '_skip' => $this->js()->_selectorThis()->attr('data-skip'))))->_selector('#' . $this->name . ' a'); parent::setSource($data); return parent::recursiveRender(); }
function setModel($model) { $model->addExpression('total_meetings')->set(function ($m, $q) { return $m->refSQL('Students_Attendance')->sum('total_attendance'); }); $model->addExpression('students_in_class')->set(function ($m, $q) { return "((select count(*) from `student` st2 where `st2`.`session_id` = `student`.`session_id` and `st2`.`class_id` = `student`.`class_id` ))"; }); $model->addExpression('all_attendance')->set(function ($m, $q) { return $m->refSQL('Students_Attendance')->sum('present'); }); parent::setModel($model); $extrarows = 10 - $model->count()->getOne(); for ($i = 1; $i <= $extrarows; $i++) { $this->add('View', null, 'ExtraRows', array('view/extrarows')); } }
function formatRow() { $this->current_row_html['body'] = $this->model['description']; $to_mail = json_decode($this->model['to_raw'], true); $to_lister = $this->app->add('CompleteLister', null, null, ['view\\communication\\all-communication-viewer', 'to_lister']); $to_lister->setSource($to_mail); $cc_raw = json_decode($this->model['cc_raw'], true); $cc_lister = $this->app->add('CompleteLister', null, null, ['view\\communication\\all-communication-viewer', 'cc_lister']); $cc_lister->setSource($cc_raw); $from_mail = json_decode($this->model['from_raw'], true); $from_lister = $this->app->add('CompleteLister', null, null, ['view\\communication\\all-communication-viewer', 'from_lister']); $from_lister->setSource($from_mail); $this->current_row_html['from_lister'] = $from_lister->getHtml(); $this->current_row_html['to_lister'] = $to_lister->getHtml(); $this->current_row_html['cc_lister'] = $cc_lister->getHtml(); return parent::formatRow(); }
function init() { parent::init(); $temp_array = []; foreach ($this->actions as $value) { $temp_array[] = ['action' => $value, 'action_title' => ucwords(str_replace("_", " ", $value)), 'row_id' => $this->id]; } $this->setSource($temp_array); $this->template->setHtml('status', $this->status); $this->template->set('status_label', $this->setLabelColor($this->status)); if ($this->action_btn_group) { $this->template->set('action_btn_group', $this->action_btn_group); } if (empty($temp_array)) { $this->template->del('dropdown'); $this->template->set('col_span', '12'); } }
function formatRow() { $attach = $this->add('xepan\\communication\\View_Lister_Attachment', null, 'Attachments'); $attach->setModel('xepan\\communication\\Communication_Attachment')->addCondition('communication_id', $this->model->id); // $a = $this->add('xepan\communication\Model_Communication_Attachment')->addCondition('communication_id',$this->model->id); $this->current_row_html['Attachments'] = $attach->getHtml(); $to_array = []; foreach ($this->model['to_raw'] as $to) { $to_array[] = $to['name']; } $this->current_row_html['to_name'] = implode(", ", $to_array); $this->current_row_html['from_name'] = $this->model['from_raw']['name']; if ($this->model['from_id'] === $this->app->employee->id) { $this->current_row_html['position'] = "left"; } else { $this->current_row_html['position'] = "right"; } // if($this->model['is_starred']){ // $this->current_row['starred']='starred'; // }else{ // $this->current_row['starred']=''; // } $einfo = $this->model['extra_info']; if (isset($einfo['seen_by']) and is_array($einfo['seen_by'])) { if (in_array($this->app->employee->id, $einfo['seen_by'])) { $this->current_row['unread'] = ''; } else { $this->current_row['unread'] = 'unread'; } } $this->current_row_html['message'] = $this->model['description']; if ($this->app->employee['scope'] != 'SuperUser') { $this->current_row_html['trash_wrapper'] = ''; } parent::formatRow(); }
function render() { $this->template->setHtml('title', $this->title); $this->template->setHtml('title_icon', $this->title_icon); parent::render(); }
function render() { $this->js(true)->_selector('.draggable-event')->draggable(array('helper' => 'clone')); parent::render(); }
function render() { $this->js(true)->_library('PNotify.desktop')->permission(); $this->js(true)->_load('xepan.pnotify')->univ()->ajaxec($this->api->url('xepan_hr_notificationexec')); return parent::render(); }
function render() { $this->max_depth = count(parent::setModel($this->model)) - 1; return parent::render(); }
/** * Format grid row * * Extends formatRow method of CompleteLister * * @return void */ function formatRow() { // execute CompleteLister row formating parent::formatRow(); if (!$this->columns) { throw $this->exception('No columns defined for grid'); } foreach ($this->columns as $field => $column) { $this->current_row[$field . '_original'] = @$this->current_row[$field]; // if model field has listData structure, then get value instead of key if ($this->model && ($f = $this->model->hasElement($field))) { if ($values = $f->listData()) { $this->current_row[$field] = $values[$this->current_row[$field]]; } } // process formatters $this->executeFormatters($field, $column, 'format_'); // setting cell parameters (tdparam) $this->applyTDParams($field); } }
function setModel($m) { parent::setModel($m); }
function render() { $this->setSource($this->items); parent::render(); }
function formatRow() { parent::formatRow(); $this->current_row['link'] = $this->api->url('./details', array('id' => $this->model->id)); //$this->current_row['img_url'] = $this->model->ref('image_id')->get('url'); }
function recursiveRender() { if ($ipp = $this->api->stickyGET($this->name . '_ipp')) { $this->ipp = $ipp; } // get data source if (!$this->source) { // force grid sorting implemented in Grid_Advanced if ($this->owner instanceof \Grid_Advanced) { $this->owner->getIterator(); } // set data source for Paginator if ($this->owner->model) { $this->setSource($this->owner->model); } elseif ($this->owner->dq) { $this->setSource($this->owner->dq); } else { throw $this->exception('Unable to find source for Paginator'); } } // calculate found rows if ($this->source instanceof \DB_dsql) { $this->source->preexec(); $this->found_rows = $this->source->foundRows(); } elseif ($this->source instanceof \Model) { $this->found_rows = (string) $this->source->count(); } else { $this->found_rows = count($this->source); } // calculate current page and total pages $this->cur_page = floor($this->skip / $this->ipp) + 1; $this->total_pages = ceil($this->found_rows / $this->ipp); if ($this->cur_page > $this->total_pages || $this->cur_page == 1 && $this->skip != 0) { $this->cur_page = 1; if ($this->memorize) { $this->memorize('skip', $this->skip = 0); } if ($this->source instanceof \DB_dsql) { $this->source->limit($this->ipp, $this->skip); $this->source->rewind(); // re-execute the query } elseif ($this->source instanceof \Model) { $this->source->setLimit($this->ipp, $this->skip); } else { // Imants: not sure if this is correct, but it was like this before $this->source->setLimit($this->ipp, $this->skip); } } // no need for paginator if there is only one page if ($this->total_pages <= 1) { return $this->destroy(); } if ($this->cur_page > 1) { $this->add('View', null, 'prev', 'prev')->template->set('href', $this->app->url($this->base_page, $u = array($this->skip_var => $pn = max(0, $this->skip - $this->ipp))))->set('pn', $pn)->set('label', '« Prev'); } else { $this->template->tryDel('prev'); } if ($this->cur_page < $this->total_pages) { $this->add('View', null, 'next', 'next')->template->set('href', $this->app->url($this->base_page, $u = array($this->skip_var => $pn = $this->skip + $this->ipp)))->set('pn', $pn)->set('label', 'Next »'); } else { $this->template->tryDel('next'); } // First page if ($this->cur_page > $this->range + 1) { $this->add('View', null, 'first', 'first')->template->set('href', $this->app->url($this->base_page, $u = array($this->skip_var => $pn = max(0, 0))))->set('pn', $pn)->set('label', '1'); if ($this->cur_page > $this->range + 2) { $this->add('View', null, 'points_left', 'points_left')->template->set('label', '...'); } } else { $this->template->del('first'); $this->template->tryDel('points_left'); } // Last page if ($this->cur_page < $this->total_pages - $this->range) { $this->add('View', null, 'last', 'last')->template->set('href', $this->app->url($this->base_page, $u = array($this->skip_var => $pn = max(0, ($this->total_pages - 1) * $this->ipp))))->set('pn', $pn)->set('label', $this->total_pages); if ($this->cur_page < $this->total_pages - $this->range - 1) { $this->add('View', null, 'points_right', 'points_right')->template->set('label', '...'); } } else { $this->template->del('last'); $this->template->tryDel('points_right'); } // generate source for Paginator Lister (pages, links, labels etc.) $data = array(); //setting cur as array seems not working in atk4.3. String is working $tplcur = $this->template->get('cur'); $tplcur = isset($tplcur[0]) ? $tplcur[0] : ''; foreach (range(max(1, $this->cur_page - $this->range), min($this->total_pages, $this->cur_page + $this->range)) as $p) { $data[] = array('href' => $this->app->url($this->base_page, array($this->skip_var => $pn = ($p - 1) * $this->ipp)), 'pn' => $pn, 'cur' => $p == $this->cur_page ? 'active' : '', 'label' => $p); } if ($this->ajax_reload) { $this->js('click', $this->owner->js()->reload(array($this->skip_var => $this->js()->_selectorThis()->attr('data-skip'), $this->name . '_ipp' => $this->js()->_selector('#ipp-selector-' . $this->name)->val())))->_selector('#' . $this->name . ' a'); $this->js(true)->_load('select2.min')->_css('libs/select2'); $this->js(true)->_selector('#ipp-selector-' . $this->name)->select2(); $this->js(true)->_selector('#ipp-selector-' . $this->name)->select2('val', $this->ipp); $this->js('change', $this->owner->js()->reload(array($this->skip_var => 0, $this->name . '_ipp' => $this->js()->_selector('#ipp-selector-' . $this->name)->val())))->_selector('#ipp-selector-' . $this->name); } parent::setSource($data); return parent::recursiveRender(); }
function renderRows() { $this->precacheTemplate(); parent::renderRows(); if (!$this->totals['row_count']) { $def_template = $this->defaultTemplate(); $this->totals = false; $this->template->del('full_table'); } else { $this->template->del('not_found'); } }