コード例 #1
0
 /**
  * Export
  *
  * @param object $object
  * @param string $format
  * @return string
  */
 public static function export($object, $format = 'html')
 {
     $header = ['name' => i18n(null, object_controller::title()), 'filter' => numbers_frontend_html_list_filter::human($object)];
     // sort
     if (!empty($object->orderby)) {
         $temp = [];
         foreach ($object->orderby as $k => $v) {
             if ($k == 'full_text_search') {
                 $temp[] = i18n(null, 'Text Search') . ' ' . ($v == SORT_ASC ? 'Asc.' : 'Desc.');
             } else {
                 $temp[] = i18n(null, $object->columns[$k]['name']) . ' ' . ($v == SORT_ASC ? 'Asc.' : 'Desc.');
             }
         }
         $header['filter'][i18n(null, 'Sort')] = implode(', ', $temp);
     }
     // report object
     $report = new numbers_frontend_html_report_base($header);
     // adding columns
     $columns = [];
     foreach ($object->columns as $k => $v) {
         if ($k == 'action') {
             continue;
         }
         $columns[] = ['value' => i18n(null, $v['name']), 'bold' => true, 'width' => 10];
     }
     $report->add($columns, 'columns');
     // adding data to report
     if (empty($object->rows)) {
         $report->add([['value' => i18n(null, object_content_messages::no_rows_found)]]);
     } else {
         $counter = 1;
         foreach ($object->rows as $k => $v) {
             $data = [];
             foreach ($object->columns as $k2 => $v2) {
                 // we skip action column when exporting
                 if ($k2 == 'action') {
                     continue;
                 }
                 $value = [];
                 // process rows
                 if ($k2 == 'row_number') {
                     $value['value'] = $counter . '.';
                 } else {
                     if ($k2 == 'offset_number') {
                         $value['value'] = $object->offset + $counter . '.';
                     } else {
                         if (!empty($v2['options']) && !is_array($v[$k2])) {
                             $value['value'] = $v2['options'][$v[$k2]]['name'];
                         } else {
                             if (isset($v[$k2])) {
                                 $value['value'] = $v[$k2];
                             } else {
                                 $value['value'] = null;
                             }
                         }
                     }
                 }
                 // put value into row
                 $data[] = $value;
             }
             $report->add($data);
             $counter++;
         }
     }
     // render report
     return $report->render($format);
 }
コード例 #2
0
ファイル: base.php プロジェクト: volodymyr-volynets/frontend
 /**
  * Render list
  *
  * @return string
  */
 public final function render()
 {
     $result = '';
     // css & js
     layout::add_css('/numbers/media_submodules/numbers_frontend_html_list_media_css_base.css', 9000);
     layout::add_js('/numbers/media_submodules/numbers_frontend_html_list_media_js_base.js', 9000);
     // load mask
     numbers_frontend_media_libraries_loadmask_base::add();
     // hidden fields
     $result .= html::hidden(['name' => 'offset', 'id' => 'offset', 'value' => $this->offset]);
     $result .= html::hidden(['name' => 'limit', 'id' => 'limit', 'value' => $this->limit]);
     // get total number of rows from count datasource
     if (!empty($this->datasources['count'])) {
         $temp = factory::model($this->datasources['count']['model'])->get($this->datasources['count']['options']);
         $this->total = $temp[0]['count'] ?? 0;
     }
     // get rows
     if (!empty($this->datasources['data'])) {
         $this->rows = factory::model($this->datasources['data']['model'])->get($this->datasources['data']['options']);
         $this->num_rows = count($this->rows);
     }
     // new record
     if (object_controller::can('record_new')) {
         $mvc = application::get('mvc');
         $url = $mvc['controller'] . '/_edit';
         $this->actions['list_new'] = ['value' => 'New', 'sort' => -32000, 'icon' => 'file-o', 'href' => $url];
     }
     // filter
     if (!empty($this->filter)) {
         $this->actions['list_filter'] = ['value' => 'Filter', 'sort' => 1, 'icon' => 'filter', 'onclick' => "numbers.modal.show('list_{$this->list_link}_filter');"];
         $result .= numbers_frontend_html_list_filter::render($this);
     }
     // order by
     $this->actions['list_sort'] = ['value' => 'Sort', 'sort' => 2, 'icon' => 'sort-alpha-asc', 'onclick' => "numbers.modal.show('list_{$this->list_link}_sort');"];
     $result .= numbers_frontend_html_list_sort::render($this);
     // export, before pagination
     if (object_controller::can('list_export')) {
         // add export link to the panel
         $result .= numbers_frontend_html_list_export::render($this);
         $this->actions['list_export'] = ['value' => 'Export/Print', 'sort' => 3, 'icon' => 'print', 'onclick' => "numbers.modal.show('list_{$this->list_link}_export');"];
         // if we are exporting
         if (!empty($this->options['input']['submit_export']) && !empty($this->options['input']['export']['format'])) {
             $result .= numbers_frontend_html_list_export::export($this, $this->options['input']['export']['format']);
             goto finish;
         }
     }
     // refresh
     $this->actions['form_refresh'] = ['value' => 'Refresh', 'sort' => 32000, 'icon' => 'refresh', 'href' => 'javascript:location.reload();', 'internal_action' => true];
     // pagination top
     if (!empty($this->pagination['top'])) {
         $result .= factory::model($this->pagination['top'])->render($this, 'top');
     }
     // data
     $result .= '<hr class="simple"/>';
     if (method_exists($this, 'render_data')) {
         $result .= $this->render_data();
     } else {
         $result .= $this->render_data_default();
     }
     $result .= '<hr class="simple"/>';
     // pagination bottom
     if (!empty($this->pagination['bottom'])) {
         $result .= factory::model($this->pagination['bottom'])->render($this, 'bottom');
     }
     finish:
     $value = '';
     if (!empty($this->actions)) {
         $value .= '<div style="text-align: right;">' . $this->render_actions() . '</div>';
         $value .= '<hr class="simple" />';
     }
     // we add hidden submit element
     $result .= html::submit(['name' => 'submit_hidden', 'value' => 1, 'style' => 'display: none;']);
     // build a form
     $value .= html::form(['name' => "list_{$this->list_link}_form", 'id' => "list_{$this->list_link}_form", 'value' => $result, 'onsubmit' => 'return numbers.frontend_list.on_form_submit(this);']);
     // if we came from ajax we return as json object
     if (!empty($this->options['input']['__ajax'])) {
         $result = ['success' => true, 'html' => $value, 'js' => layout::$onload];
         layout::render_as($result, 'application/json');
     }
     $value = "<div id=\"list_{$this->list_link}_form_mask\"><div id=\"list_{$this->list_link}_form_wrapper\">" . $value . '</div></div>';
     $temp = ['type' => 'primary', 'value' => $value];
     return html::segment($temp);
 }