Exemple #1
0
 /**
  * Returns the HTML rendered object
  * @return string
  */
 public function getAsString()
 {
     $id = $this->getId();
     if (!$this->isVisible()) {
         return "<div id='{$id}' class='hidden'></div>";
     }
     // if for some reason this page is empty we go back to page one
     $num_page = $this->getCurrentPageNumber();
     $rows = $this->data->page($num_page, false);
     if (empty($rows)) {
         $num_page = 1;
         $this->setCurrentPageNumber($num_page);
         $rows = $this->data->page($num_page, false);
     }
     if ($this->toolbar !== null and $this->toolbar->isVisible()) {
         $this->addTempVar('toolbar', $this->toolbar->getAsString());
     }
     if ($this->navigation_bar !== null) {
         if ($this->_auto_navigation_bar) {
             if ($this->data->getNumPages() > 1) {
                 $this->addTempVar('navigation_bar', $this->navigation_bar->getAsString());
             }
         } else {
             if ($this->navigation_bar->isVisible()) {
                 $this->addTempVar('navigation_bar', $this->navigation_bar->getAsString());
             }
         }
     }
     $visible_cols = $this->getVisibleCols();
     if ($this->_show_headers) {
         $headers = array();
         $i = 0;
         $is_sortable = false;
         $order_field = null;
         $order_mode = null;
         if ($this->data->isSortable()) {
             $is_sortable = true;
             if ($this->data->hasOrder()) {
                 $order = $this->data->getOrder();
                 list($order_field, $order_mode) = each($order);
             }
         }
         foreach ($visible_cols as $col_name) {
             $col =& $this->cols->{$col_name};
             if ($col->getType() == 'action') {
                 $headers[$i]['value'] = '&nbsp;';
                 $headers[$i]['order'] = '';
                 $headers[$i]['action'] = '';
             } else {
                 $headers[$i]['value'] = __($col->getLabel());
                 $headers[$i]['order'] = null;
                 if ($is_sortable and $col->isSortable()) {
                     $headers[$i]['action'] = $col->composeStringActions(null, false);
                 } else {
                     $headers[$i]['action'] = "";
                 }
                 $data_field =& $this->data->fields->{$col->getName()};
                 $field_name = $data_field->getName();
                 $complete_field_name = $data_field->getSchemaTableField();
                 if ($is_sortable and ($order_field == $field_name or $order_field == $complete_field_name)) {
                     $headers[$i]['order'] = strtolower($order_mode);
                 }
             }
             $i++;
         }
         $this->addTempVar('headers', $headers);
     }
     $table_cols = array();
     foreach ($visible_cols as $col_name) {
         $col =& $this->cols->{$col_name};
         $a = array();
         $a['properties'] = $col->composeStringProperties();
         $table_cols[] = $a;
     }
     $this->addTempVar('table_cols', $table_cols);
     if ($this->data->getNumRows() > 0) {
         $this->addTempVar('table_rows', $this->getRows($num_page, $rows));
     } else {
         $this->addTempVar('table_rows', null);
     }
     $return = $this->fetchTemplate();
     $this->clearTempVars();
     return $return;
 }