/** * Returns the URI to a page * * @param int $page * @param string $label * @return string * @access protected **/ protected function getUriLoc($page, $label = "") { if (empty($label)) { $label = $page + 1; } $page = (string) $page; $uri = Gecko_HTML::LinkTag($label, Gecko_URL::getSelfURI(array($this->pageParam => $page))) . "\n"; return $uri; }
/** * This method will generate the DataGrid * * @return boolean */ public function buildTable() { /** * Setup basic model settings **/ if ($this->sorting) { $sortColumn = Gecko_URL::getRequestParam($this->sortparam); $sortOrder = Gecko_URL::getRequestParam($this->sortorderparam); $sortcol = empty($sortColumn) ? $this->sortcol : $sortColumn; $sortord = empty($sortOrder) ? $this->sortorder : $sortOrder; $this->model->setOrder($sortcol, $sortord); } if ($this->paginate && $this->model instanceof Gecko_DataSource_Paginate_Interface) { $page = (int) $this->getCurrentPage(); if ($page > 0) { --$page; } $lstart = $page * $this->maxrows; if ($lstart < 0) { $lstart = 0; } $max = $this->maxrows; $this->model->limitResults($lstart, $max); } /** * Setup Model **/ $this->model->setup(); /** * Begin Table Construction **/ $numColumns = $this->model->getTotalColumns(); $totalRowset = $this->model->getTotalRowset(); $tblSettings = array('id' => $this->name, 'cellspacing' => '0', 'class' => $this->theme); $this->formatter->beginTable($tblSettings); /** * If we are going to show headers... **/ if ($this->sHeaders == true) { $this->formatter->beginRow('header'); for ($i = 0; $i < $numColumns; $i++) { $fieldname = $this->model->getColumnAt($i); if (in_array($fieldname, $this->skipColumns)) { continue; } $headerName = $this->formatter->getColumnName($fieldname); $header = $headerName; if ($this->sorting) { $sparam = array($this->sortparam => $fieldname); $oparam = array(); if ($fieldname == $sortcol) { $img = ''; $imgtag = '<img src="%s" border="0" alt="Sort %s %s" />'; switch ($sortord) { case 'ASC': $img = sprintf($imgtag, $this->supi, $fieldname, "DESC"); $oparam = array($this->sortorderparam => 'DESC'); break; case 'DESC': $img = sprintf($imgtag, $this->sdni, $fieldname, "ASC"); $oparam = array($this->sortorderparam => 'ASC'); break; } $uri = Gecko_URL::getSelfURI(array_merge($sparam, $oparam)); $header = Gecko_HTML::LinkTag($headerName . $img, $uri); } else { $uri = Gecko_URL::getSelfURI($sparam); $header = Gecko_HTML::LinkTag($headerName, $uri); } if (in_array($fieldname, $this->noSortColumns)) { $header = $headerName; } } $this->formatter->addHeader($header); } $this->formatter->endRow(); } /** * If no rows are found... **/ if ($totalRowset == 0) { $noRecords = $this->_getTranslatedLabel($this->noRecords); $this->formatter->beginRow(0); $this->formatter->addCell("<div style=\"text-align: center\">{$noRecords}</div>", 'norecords', array("colspan" => $numColumns)); $this->formatter->endTable(); $this->parsed = true; if ($this->paginate) { $this->_generatePaginator(); } return true; } /** * All clear begin grid construction **/ $isColor = false; if ($this->customcolors) { if (strpos($this->color1, "#") !== false) { $isColor = true; } if (strpos($this->color2, "#") !== false) { $isColor = true; } } $color = ""; for ($i = 0; $i < $totalRowset; $i++) { /** * Get the row from the model **/ $row = $this->model->getRowAt($i); if ($this->customcolors) { $color = $i % 2 == 0 ? $this->color1 : $this->color2; } /* Set OnClick Handler */ $js = ''; if (!empty($this->onClick)) { $params = ""; if (is_array($this->onClickParams)) { $params = array(); foreach ($this->onClickParams as $field) { $params[] = "'" . $row[$field] . "'"; } $params = implode(",", $params); } else { if ($this->onClickParams == "NumRows") { $params = $n_rows; } else { $params = "'" . $row[$this->onClickParams] . "'"; } } $js = "{$this->onClick}({$params})"; } /* Set OnDblClick Handler */ $js2 = ''; if (!empty($this->ondblClick)) { $params = ""; if (is_array($this->ondblClickParams)) { $params = array(); foreach ($this->onClickParams as $field) { $params[] = "'" . $row[$field] . "'"; } $params = implode(",", $params); } else { if ($this->ondblClickParams == "NumRows") { $params = $n_rows; } else { $params = $row[$this->ondblClickParams]; } } $js2 = "{$this->ondblClick}({$params})"; } $TRSettings = array(); if (!empty($js)) { $TRSettings['onclick'] = $js; } if (!empty($js2)) { $TRSettings['ondblclick'] = $js2; } if (!empty($color)) { if ($isColor) { $TRSettings["style"] = "background: {$color};"; } else { $TRSettings["class"] = $color; } } $this->formatter->beginRow($i, $TRSettings); /** Begin adding the cells to the Grid **/ $cellNum = 0; foreach ($row as $cell) { $fieldname = $this->model->getColumnAt($cellNum); $cellNum++; if (in_array($fieldname, $this->skipColumns)) { continue; } $this->formatter->addCell($cell, $fieldname); } $this->formatter->endRow(); } $this->formatter->endTable(); $this->parsed = true; if ($this->paginate) { $this->_generatePaginator(); } return true; }