Exemple #1
0
 /**
  * Generate YUI view of table and paging
  *
  * @param mr_html_table $table Table instance
  * @param mr_html_paging $paging Paging instance
  * @param bool $autoload
  * @param null $id
  * @return string
  */
 public function mr_html_table_ajax(mr_html_table $table, mr_html_paging $paging, $autoload = true, $id = null)
 {
     global $PAGE;
     // Columns
     $columns = array();
     foreach ($table->get_columns(true) as $column) {
         // Must set sortable to false if table is not sort enabled or if empty $rows
         if (!$table->get_sortenabled()) {
             $column->set_config('sortable', false);
         }
         $col = (object) array('key' => $column->get_name(), 'label' => $column->get_config()->heading, 'sortable' => $column->get_config()->sortable);
         if ($column->get_config()->editor) {
             $col->editor = $column->get_config()->editor;
         }
         $columns[] = $col;
     }
     // Page size
     $opts = array();
     if ($paging->get_perpageopts()) {
         foreach ($paging->get_perpageopts() as $opt) {
             if ($opt == 'all') {
                 $opts[] = (object) array('value' => 10000, 'text' => get_string('all'));
             } else {
                 $opts[] = (object) array('value' => $opt, 'text' => $opt);
             }
         }
     }
     // Place holder div's ID
     if (empty($id)) {
         $id = html_writer::random_id();
     }
     $loadingmsg = $this->output->pix_icon('i/ajaxloader', get_string('loadingdotdotdot', 'local_mr')) . ' ' . get_string('loadingdotdotdot', 'local_mr');
     $module = array('name' => 'local_mr', 'fullpath' => '/local/mr/renderer.js', 'requires' => array('yui2-yahoo', 'yui2-dom', 'yui2-event', 'yui2-element', 'yui2-paginator', 'yui2-datasource', 'yui2-json', 'yui2-connection', 'yui2-get', 'yui2-dragdrop', 'yui2-datatable', 'moodle-local_mr-livelog'), 'strings' => array(array('tablesortedbydesc', 'local_mr'), array('tablesortedbyasc', 'local_mr')));
     $arguments = (object) array('id' => $id, 'url' => $table->get_url()->out(false, array('tjson' => 1)), 'sort' => $table->get_sort(), 'order' => $table->get_order(), 'page' => $paging->get_page(), 'perpage' => $paging->get_perpage(), 'loadingmsg' => $loadingmsg, 'perpageopts' => $opts, 'columns' => $columns, 'asc' => SORT_ASC, 'desc' => SORT_DESC, 'autoload' => $autoload);
     if (!is_null($table->get_summary())) {
         $arguments->summary = $table->get_summary();
     }
     if (!empty($table->caption)) {
         $arguments->caption = $table->caption;
     }
     $PAGE->requires->js_init_call('M.local_mr.init_mr_html_table', array($arguments), false, $module);
     $PAGE->requires->strings_for_js(array('paginatorfirstlabel', 'paginatorfirsttitle', 'paginatorlastlabel', 'paginatorlasttitle', 'paginatorprevlabel', 'paginatorprevtitle', 'paginatornextlabel', 'paginatornexttitle'), 'local_mr');
     return html_writer::tag('div', '', array('id' => $id, 'class' => 'mr_html_table mr_ajax_table'));
 }