Example #1
0
 /**
  * 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;
 }
Example #2
0
 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);
 }
Example #4
0
 protected function createComponentForm($name)
 {
     $form = new AppForm();
     //$form->getElementPrototype()->id('editform');
     $form->addText('title', 'Název', 50)->addRule(Form::FILLED, "Jméno je potřeba vyplnit");
     $items = dibi::query('SELECT
     authorId,
     CONCAT_WS(" ", name, surname,', Model::sqlClassName(Model::getSchoolYear()), ') as authorName
     FROM [authors]
     ORDER BY surname, class desc')->fetchPairs();
     $keys = array_keys($items);
     $form->addSelect('author', 'Autor', array("0" => 'Nový') + $items)->setValue($keys[0]);
     $form->addTextArea('text', 'Text')->getControlPrototype()->style = 'width: 100%';
     $form->addSelect('award', 'Ocenění', array("0" => 'Nové') + $this->setKeys(Model::getValues('award', 'works')));
     $form->addText('newAward', '');
     $form->addSelect('year', 'Ročník ChP', $this->generateYears())->setDefaultValue(Model::getSchoolYear());
     $form->addSelect('type', 'Typ', array("0" => 'Nový') + $this->setKeys(Model::getValues('type', 'works')));
     $form->addText('newType', '');
     if ($this->setId == '') {
         $form->addFile('file', "Soubor:");
     }
     $form['newAward']->addConditionOn($form['award'], Form::EQUAL, 0)->addRule(Form::FILLED, 'Pokud nevyberete ocenění, musíte zadat nové');
     $form['newType']->addConditionOn($form['type'], Form::EQUAL, 0)->addRule(Form::FILLED, 'Pokud nevyberete typ, musíte zadat nový');
     $form->addSubmit('ok', 'Přidat práci')->onClick[] = array($this, 'addClicked');
     $form->addHidden("authorId")->setValue('false');
     if ($this->setId != '') {
         $dataSource = dibi::query('SELECT * FROM [works] WHERE workId=%i', $this->setId)->fetch();
         $form->setDefaults($dataSource);
         $form['ok']->onClick = array(array($this, 'saveClicked'));
         $form['ok']->caption = "Uložit práci";
         $form->addHidden("workId")->setValue($this->setId);
     } else {
         $s = Environment::getSession('workform');
         if (isset($s->author) && array_search($s->author, $keys) === FALSE) {
             $s->author = $keys[0];
         }
         if (isset($s->author)) {
             $form->setDefaults($s);
         }
     }
     $this->addComponent($form, $name);
     $form->getRenderer()->wrappers['control']['container'] .= ' class="wide"';
     return;
 }