/** * Component factory. * @see Nette/ComponentContainer#createComponent() */ protected function createComponentDataGrid($name) { $grid = new DataGrid(); $grid->bindDataTable(dibi::getConnection()->dataSource('SELECT authorId as id, name, surname, class,', Model::sqlClassName(Model::getSchoolYear()) . 'as classMark, (SELECT COUNT(workId) FROM [works] WHERE author=authorId) as sum FROM [authors] ')); $grid->addColumn('name', 'Jméno'); $grid->addColumn('surname', 'Příjmení')->addDefaultSorting('asc'); $grid->addColumn('class', 'Maturita')->getCellPrototype()->style('text-align: center;'); $grid->addColumn('classMark', 'Třída')->getCellPrototype()->style('text-align: right;'); $grid->addColumn('sum', 'Počet prací')->getCellPrototype()->style('text-align: right;')->class('pages'); $grid->addActionColumn('Akce'); $grid->keyName = 'id'; $grid->addAction('Smazat', 'delete!', NULL, FALSE, DataGridAction::WITH_KEY); $grid['name']->addFilter(); $grid['surname']->addFilter(); $grid['class']->addSelectboxFilter(); $grid['classMark']->addSelectboxFilter(); $grid['sum']->addSelectboxFilter(); $grid->multiOrder = FALSE; $grid->itemsPerPage = $this->getCookiesItemsCount(15); $renderer = $grid->getRenderer(); $renderer->paginatorFormat = '%label% %input% z %count%'; $renderer->infoFormat = 'Autoři %from%. - %to%. z %count% | Zobrazit: %selectbox% | %reset%'; $renderer->onRowRender[] = array($this, 'OnRowRendered'); //$grid->rememberState = TRUE; $this->addComponent($grid, $name); return; }
public function beforeRender() { $filters = $this->getUniqueValues(array('works' => array('year', 'award', 'type'), 'authors' => array('class'))); $temp = $filters['authors']; unset($filters['authors']); //$filters['works']['category'] = Model::palicky();// + array(5=>'palice'); // 'category'=>'Kategorie', $filters['works']['grade'] = Model::rocniky(); $filters['palicka']['category'] = Model::palicky(); $filters['authors'] = $temp; //{link :Front:Default:works "category"=>palicka} $this->template->filters = $filters; $this->template->schoolYear = Model::getSchoolYear(); $newest = dibi::query('SELECT url, title, CONCAT_WS(" ", name, surname) as authorName FROM [works] join [authors] on author = authorId', 'ORDER BY %by', array('added' => 'desc'), 'LIMIT %i', 2)->fetchAll(); $this->template->newest = $newest; $mostread = dibi::query('SELECT url, title, CONCAT_WS(" ", name, surname) as authorName FROM [works] join [authors] on author = authorId', 'ORDER BY %by', array('read' => 'desc'), 'LIMIT %i', 3)->fetchAll(); $this->template->mostread = $mostread; $user = Environment::getUser(); if ($user->isLoggedIn()) { $this->template->adminMode = true; } }
public function actionDefault($url) { $this->id = $url; $res = dibi::query(' SELECT authorId, name, surname, class,', Model::sqlClassName(Model::getSchoolYear()) . 'as classMark,', Model::sqlSumWorks() . ' as sum FROM [authors] WHERE `authorUrl`=%s', $url)->fetchAll(); $this->template->data = $res[0]; $this->template->sum = $this->formCount($res[0]['sum'], 'prací', 'práce', 'práce', 'prací'); }
protected function createComponentAuthors($name) { $grid = new DataGrid(); $search = ""; if (isset($this->searchFull)) { foreach ($this->search as $one) { //$search .= "name LIKE '%".$one."%' OR surname LIKE '% ".$one."%' OR "; $search .= "name RLIKE '(^| ){$one}' OR surname RLIKE '(^| ){$one}' OR "; } foreach ($this->searchFull as $one) { $search .= "name RLIKE '(^| )" . $one . " ' OR surname RLIKE '(^| )" . $one . " ' OR "; } $search = substr($search, 0, -3); } $grid->bindDataTable(dibi::getConnection()->dataSource('SELECT authorUrl as link, name, surname,', $this->formColumns(array('class')), Model::sqlClassName(Model::getSchoolYear()) . 'as classMark,', Model::sqlSumWorks() . 'as [sum],', Model::sqlSumReads() . 'as [read]', 'FROM [authors]', 'WHERE %and', $this->where, '%if', isset($search), 'AND %sql', $search, '%end')); $grid->addColumn('name', 'Jméno')->getCellPrototype()->addClass('first'); $grid->addColumn('surname', 'Příjmení')->addDefaultSorting('asc'); if ($this->notCol('class')) { $grid->addColumn('class', 'Maturita')->getCellPrototype()->style('text-align: center;'); } $grid->addColumn('classMark', 'Třída')->getCellPrototype()->style('text-align: right;'); $grid->addColumn('sum', 'Počet prací')->getCellPrototype()->style('text-align: right;'); $grid->addColumn('read', 'Čtenost')->getCellPrototype()->style('text-align: right;'); $grid->multiOrder = FALSE; $grid->displayedItems = array('vše', 5, 8, 10, 20, 50, 100); $grid->itemsPerPage = $this->getCookiesItemsCount(8); $grid->nothingMessage = "Žádný autor nebyl nalezen."; $grid->hiddenFiltering = TRUE; $renderer = $grid->getRenderer(); $renderer->paginatorFormat = '%label% %input% z %count%'; $renderer->infoFormat = 'Autoři %from% - %to% z %count% | Zobrazit: %selectbox% | %reset%'; $renderer->onRowRender[] = array($this, 'authorsOnRowRendered'); //$renderer->onCellRender[] = array($this, 'gridOnCellRendered'); return $grid; //$this->addComponent($grid, $name); }
public function __toString() { $template = $this->getTemplate(); $template->setFile($this->file); $this->template->form = $this['form']; $this->template->schoolYear = Model::getSchoolYear(); $s = $template->__toString(TRUE); return mb_convert_encoding($s, 'HTML-ENTITIES', 'UTF-8'); }