Selection is based on the great library NotORM http://www.notorm.com written by Jakub Vrana.
Author: Jakub Vrana
Author: Jan Skrasek
Inheritance: extends Nette\Object, implements Iterator, implements ArrayAccess, implements Countable
コード例 #1
0
 /**
  * @param int $limit
  * @param int $offset
  * @return array
  */
 public function getData($limit = NULL, $offset = NULL)
 {
     if ($limit !== NULL) {
         $this->source->limit($limit, $offset);
     }
     return $this->source->fetchAll();
 }
コード例 #2
0
ファイル: MonthControl.php プロジェクト: dansilovsky/calendar
 public function render()
 {
     $this->_calendarMonthData->rewind();
     $this->template->data = $this->_calendarMonthData;
     $this->template->setFile(__DIR__ . '/Month.latte');
     $this->template->render();
 }
コード例 #3
0
ファイル: BaseQuery.php プロジェクト: trejjam/utils
 static function appendLimit(Nette\Database\Table\Selection &$query, $limit = NULL, $offset = NULL)
 {
     if (!is_null($limit)) {
         $query->limit($limit, $offset);
     }
     return $query;
 }
コード例 #4
0
ファイル: BaseForm.php プロジェクト: ondrs/nette-bootstrap
 /**
  * Default form handler
  */
 public function process()
 {
     /** @var ArrayHash $values */
     $values = $this->values;
     try {
         $this->onBeforeProcess($this, $values);
         if (isset($values->id)) {
             $this->onBeforeUpdate($this, $values);
             $arr = (array) $values;
             unset($arr['id']);
             $row = $this->selection->wherePrimary($values->id)->fetch();
             $row->update($arr);
             $this->onAfterUpdate($row, $this, $values);
         } else {
             $this->onBeforeInsert($this, $values);
             $row = $this->selection->insert($values);
             $this->onAfterInsert($row, $this, $values);
         }
         $this->onAfterProcess($row, $this, $values);
     } catch (\PDOException $e) {
         $this->addError($e->getMessage());
         dump($e);
         Debugger::log($e);
     }
 }
コード例 #5
0
ファイル: DefaultDataSource.php プロジェクト: drahak/tables
 /**
  * Filter data
  * @param array $filter
  */
 public function filter(array $filter)
 {
     foreach ($filter as $key => $value) {
         $value = is_numeric($value) ? $value : '%' . $value . '%';
         $this->table->where($key . ' LIKE ?', $value);
     }
 }
コード例 #6
0
 public function validate(BaseControl $control)
 {
     $condition[$control->name] = $control->value;
     if ($this->id) {
         $condition['id!='] = $this->id;
     }
     return $this->selection->where($condition)->count() ? FALSE : TRUE;
 }
コード例 #7
0
 /**
  * @param Selection $context
  * @param int $sectionId
  * @param string $via [optional]
  * @return Selection
  */
 public function filterSection(Selection $context, $sectionId, $via = '')
 {
     $context->alias($this->sectionTableName, 'alternate_section');
     $filterFactory = new Filter\Factory($this->sectionTableName);
     $nFilter = $filterFactory->createN($context);
     $nFilter->setup('id', $sectionId)->via("{$via}:page_has_section");
     $nFilter->setup('id', $sectionId, 'alternate_section')->via($via);
     return $nFilter->build();
 }
コード例 #8
0
ファイル: AktualneClanky.php プロジェクト: petak23/echo-msz
  /** Nastavenie textov
 * @param array $texts
 * @return \App\FrontModule\Components\Clanky\AktualneClankyControl
 */
  public function setTexts($texts)
  {
      $this->texts = array_merge($this->texts, $texts);
      return $this;
  }
  /** Nastavenie cesty k titulnemu obrazku clanku
コード例 #9
0
ファイル: GridEmailLog.php プロジェクト: vsek/base
 /**
  * Nastavi model
  * @param Nette\Database\Table\Selection
  */
 public function setModel(\Nette\Database\Table\Selection $model)
 {
     if (isset($this->filter['email']) && $this->filter['email'] != '') {
         $model->where('adress REGEXP ?', $this->filter['email']);
     }
     if (isset($this->filter['subject']) && $this->filter['subject'] != '') {
         $model->where('subject REGEXP ?', $this->filter['subject']);
     }
     $this->model = $model;
 }
コード例 #10
0
ファイル: Last.php プロジェクト: petak23/echo-msz
     if (is_int($pocet) && $pocet > 1) {
         $this->pocet = $pocet;
     }
 }
 /** Zakladny render */
 public function render()
 {
     $this->template->setFile(__DIR__ . '/Last.latte');
     $this->template->h3 = 'Posledných ' . $this->pocet . ' prihlásení';
     $this->template->last = $this->last->order('prihlasenie_datum DESC')->limit($this->pocet);
     $this->template->render();
コード例 #11
0
 /**
  * @param \Nette\Database\Table\Selection $selection
  * @param string|Callable $callback
  */
 private function apply(Selection $selection, $callback)
 {
     if (!$callback) {
         return;
     }
     if (is_string($callback)) {
         $selection->select($callback);
     } else {
         $callback($selection);
     }
 }
コード例 #12
0
ファイル: Produkt_lang.php プロジェクト: petak23/echo-msz
 /** Nacitanie udajov o produkte
  * @param int $id Id produktu
  * @param int $id_lang Id jazyka
  * @return array|FALSE
  */
 public function getProdukt($id, $id_lang = 1)
 {
     $hlavne_menu_lang = $this->hlavne_menu_lang->where(array("id_hlavne_menu" => $id, "id_lang" => $id_lang));
     if ($hlavne_menu_lang === FALSE) {
         return FALSE;
     }
     $produkt = $this->find($hlavne_menu_lang->hlavne_menu->clanok);
     if ($produkt === FALSE) {
         return FALSE;
     }
     return array("hlavne_menu_lang" => $hlavne_menu_lang, "produkt" => $produkt);
 }
コード例 #13
0
 protected function buildJoins($val, $inner = FALSE)
 {
     $driver = $this->selection->getConnection()->getSupplementalDriver();
     $reflection = $this->selection->getConnection()->getDatabaseReflection();
     $joins = array();
     preg_match_all('~\\b([a-z][\\w.:]*[.:])([a-z]\\w*|\\*)(\\s+IS\\b|\\s*<=>)?~i', $val, $matches);
     foreach ($matches[1] as $names) {
         $parent = $this->selection->getName();
         if ($names !== "{$parent}.") {
             // case-sensitive
             preg_match_all('~\\b([a-z][\\w]*|\\*)([.:])~i', $names, $matches, PREG_SET_ORDER);
             foreach ($matches as $match) {
                 list(, $name, $delimiter) = $match;
                 if ($delimiter === ':') {
                     list($table, $primary) = $reflection->getHasManyReference($parent, $name);
                     $column = $reflection->getPrimary($parent);
                 } else {
                     list($table, $column) = $reflection->getBelongsToReference($parent, $name);
                     $primary = $reflection->getPrimary($table);
                 }
                 $joins[$name] = ' ' . (!isset($joins[$name]) && $inner && !isset($match[3]) ? 'INNER' : 'LEFT') . ' JOIN ' . $driver->delimite($table) . ($table !== $name ? ' AS ' . $driver->delimite($name) : '') . ' ON ' . $driver->delimite($parent) . '.' . $driver->delimite($column) . ' = ' . $driver->delimite($name) . '.' . $driver->delimite($primary);
                 $parent = $name;
             }
         }
     }
     return $joins;
 }
コード例 #14
0
ファイル: EventsTerms.php プロジェクト: soundake/pd
 public function update($data, $forceRegenerateTimes = FALSE)
 {
     parent::update($data);
     if ($forceRegenerateTimes || rand(0, 100) < 10) {
         $this->generateAllTimes();
     }
 }
コード例 #15
0
ファイル: ActiveRow.php プロジェクト: kovkus/r-cms
 public function access($key, $delete = FALSE)
 {
     if ($this->table->connection->getCache() && !isset($this->modified[$key]) && $this->table->access($key, $delete)) {
         $id = isset($this->data[$this->table->primary]) ? $this->data[$this->table->primary] : $this->data;
         $this->data = $this->table[$id]->data;
     }
 }
コード例 #16
0
ファイル: Searcher.php プロジェクト: sg3tester/songator
 public function search($q)
 {
     $query = "";
     $count = count($this->columns);
     $i = 0;
     $phldrs = array();
     foreach ($this->columns as $column) {
         $query .= new \Nette\Database\SqlLiteral($column . " " . $this->method . " ?");
         $phldrs[] = str_replace($this->placeholder, $q, $this->mask);
         if ($i < $count - 1) {
             $query .= " OR ";
         }
         $i++;
     }
     return $this->model->where($query, $phldrs);
 }
コード例 #17
0
ファイル: PadPresenter.php プロジェクト: shutkos/notejam
 /**
  * Pad:default.
  * @param int         $id
  * @param string|null $order
  * @throws BadRequestException
  */
 public function actionDefault($id, $order)
 {
     $this->loadPad($id);
     $this->notes = $this->noteManager->findByPad($id);
     if ($order) {
         $this->notes->order(OrderHelper::translateParameterToColumns($order));
     }
 }
コード例 #18
0
ファイル: Selection.php プロジェクト: redwormik/fakeorm
 protected function execute()
 {
     if ($this->rows !== NULL) {
         return;
     }
     parent::execute();
     $this->onExecute();
 }
コード例 #19
0
ファイル: NahodnaFotka.php プロジェクト: petak23/echo-msz
 /** Render funkcia pre vypisanie odkazu na clanok 
  * @see Nette\Application\Control#render()
  */
 public function render()
 {
     if (count($this->dokumenty)) {
         //Ak nieco mam, tak najdem nahodny
         $obrazky = $this->dokumenty->limit(1, rand(0, count($this->dokumenty) - 1))->fetch();
         $alt = $obrazky->popis;
         $src = $obrazky->subor;
     } else {
         $alt = $this->texty["notFound"];
         $src = "www/images/otaznik.png";
     }
     $this->template->setFile(__DIR__ . '/NahodnaFotka.latte');
     $this->template->h4 = $this->texty["h4"];
     $this->template->alt = $alt;
     $this->template->src = $src;
     $this->template->render();
 }
コード例 #20
0
ファイル: NetteDbDataSource.php プロジェクト: adusak/DataGrid
 public function setRelated($table, $key, $column, $as = NULL, $primary = 'id')
 {
     if (is_null($this->context)) {
         throw new Grid_Exception('Related require set Nette database context in constructor.');
     }
     $this->related[$table] = array($table, $key, $column, $as, $primary);
     $this->nette_table->select($table . '.' . $column . (!is_null($as) ? ' AS ' . $as : ''));
     return $this;
 }
コード例 #21
0
ファイル: Selection.php プロジェクト: fabik/database
 /**
  * @param  string
  * @param  IModelManager
  */
 public function __construct($table, IModelManager $manager)
 {
     if (NETTE_VERSION_ID >= 20100) {
         parent::__construct($manager->getConnection(), $table, $manager->getDatabaseReflection(), $manager->getCacheStorage());
     } else {
         parent::__construct($table, $manager->getConnection());
     }
     $this->manager = $manager;
 }
コード例 #22
0
ファイル: OznamPresenter.php プロジェクト: petak23/echo-msz
 /** Akcia pre nacitanie aktualnych oznamov */
 public function actionDefault()
 {
     //Z DB zisti ako budu oznamy usporiadane
     if (($pomocna = $this->udaje->getKluc("oznam_usporiadanie")) !== FALSE) {
         $oznamy_usporiadanie = (bool) $pomocna->text;
     } else {
         $oznamy_usporiadanie = FALSE;
     }
     $this->aktualne = $this->oznam->aktualne($oznamy_usporiadanie);
     //Ak nie su oznamy najdi 1. clanok cez udaje a ak je tak presmeruj na neho
     if ($this->aktualne->count() == 0) {
         if (($id = $this->udaje->getUdajInt('oznam_prva_stranka')) > 0) {
             $this->flashRedirect(['Clanky:default', $id], $this->trLang('ziaden_aktualny'), 'info');
         } else {
             $this->setView("prazdne");
         }
     }
 }
コード例 #23
0
ファイル: EntityCollection.php プロジェクト: uestla/easyblog
 /** @return int */
 public function count()
 {
     if ($this->data !== NULL) {
         return count($this->data);
     }
     if ($this->count === NULL) {
         $this->count = $this->selection->count('*');
     }
     return $this->count;
 }
コード例 #24
0
ファイル: ErrorGrid.php プロジェクト: RiKap/ErrorMonitoring
 protected function configure($presenter)
 {
     $this->selection->select("error.id, title, message, error_dt, project_id.name AS project_name, error_status_id.status AS status");
     $source = new \NiftyGrid\DataSource\NDataSource($this->selection);
     $self = $this;
     $this->setDataSource($source);
     $this->setDefaultOrder("error_dt DESC");
     $this->addColumn("project_name", "Project")->setTableName("project_id")->setSortable()->setSelectFilter($this->projectEntity->findAll()->fetchPairs("id", "name"));
     $this->addColumn("title", "Title")->setTextFilter()->setSortable();
     $this->addColumn("message", "Message")->setSortable()->setTextFilter()->setRenderer(function ($row) use($presenter) {
         return \Nette\Utils\Html::el("a")->setText(trim($row["message"]) ? Strings::truncate($row["message"], 60) : $row["id"])->addAttributes(array("target" => "_blank"))->href($presenter->link("ErrorList:display", $row["id"]));
     });
     $this->addColumn("status", "Status")->setTableName("error_status_id")->setSelectFilter($this->lstErrorStatus->findAll()->fetchPairs("id", "status"))->setRenderer(function ($row) use($presenter) {
         $label = "";
         if ($row["status"] == "New") {
             $label = "label-important";
         }
         return \Nette\Utils\Html::el("span")->setText($row["status"])->addAttributes(array("class" => "label {$label}"));
     });
     if (!isset($this->filter['status'])) {
         $this->filter['status'] = '1';
     }
     $this->addColumn("error_dt", "Date", "150px")->setDateFilter()->setSortable()->setRenderer(function ($row) {
         return $row["error_dt"]->format("j.n.Y H:i:s");
     });
     $this->addButton("archive", "Archive")->setText("Archive")->setAjax()->setLink(function ($row) use($presenter) {
         return $presenter->link("archive!", $row['id']);
     })->setClass("btn-success btn-solve");
     /*
     		$this->addButton("createTask", "Create Task")
     			->setText('Create task')
     			->setAjax()
     			->setLink(function($row) use ($presenter){return $presenter->link("createTask!", $row['id']);})
     			->setClass("btn-info");
     */
     $this->addAction("archive", "Archive")->setAjax(true)->setCallback(function ($selectedItems) use($self) {
         $self->handleArchive($selectedItems);
     });
     $this->addAction("unarchive", "Unarchive")->setAjax(true)->setCallback(function ($selectedItems) use($self) {
         $self->handleUnArchive($selectedItems);
     });
 }
コード例 #25
0
ファイル: ActiveRow.php プロジェクト: nakoukal/fakturace
	protected function getReference($table, $column)
	{
		$this->accessColumn($column);
		if (array_key_exists($column, $this->data)) {
			$value = $this->data[$column];
			$referenced = $this->table->getReferencedTable($table, $column, $value);
			return isset($referenced[$value]) ? $referenced[$value] : NULL; // referenced row may not exist
		}

		return FALSE;
	}
コード例 #26
0
ファイル: FlagFilter.php プロジェクト: sg3tester/songator
 /**
  * Filter IT!
  * @param string $flags
  */
 public function filter($flags)
 {
     //One and main logic!
     $columns = array();
     foreach (str_split($flags) as $char) {
         if (!array_key_exists($char, $this->flags)) {
             throw new \Nette\InvalidArgumentException("Unrecognized flag '{$char}'", 3315);
         }
         $flag = $this->flags[$char];
         if (!is_array($flag)) {
             $arr = array();
             $arr["column"] = $flag;
             $arr["by"] = " = 1";
             $columns[] = $arr;
         } else {
             $columns[] = $flag;
         }
     }
     return $this->model->where($this->getQueryString($columns));
 }
コード例 #27
0
ファイル: Factory.php プロジェクト: filsedla/hyperrow
 /**
  * @param Selection $selection
  * @return HyperSelection
  */
 public function createSelection(Selection $selection)
 {
     $tableName = $selection->getName();
     $className = Helpers::substituteClassWildcard($this->selectionMapping, $tableName);
     $baseClass = HyperSelection::class;
     if (!class_exists($className) || !is_subclass_of($className, $baseClass)) {
         throw new InvalidStateException("HyperSelection class {$className} does not exist or does not extend {$baseClass}.");
     }
     $names = $this->container->findByType($className);
     if (count($names) > 1) {
         throw new InvalidStateException("Multiple services of type {$className} found: " . implode(', ', $names) . '.');
     } elseif (count($names) == 0) {
         $inst = $this->container->createInstance($className);
     } else {
         $name = array_shift($names);
         $inst = $this->container->createService($name);
     }
     /** @var HyperSelection $inst */
     $inst->setFactory($this);
     $inst->setSelection($selection);
     return $inst;
 }
コード例 #28
0
 public function &__get($key)
 {
     $this->access($key);
     if (array_key_exists($key, $this->data)) {
         return $this->data[$key];
     }
     list($table, $column) = $this->table->getConnection()->getDatabaseReflection()->getBelongsToReference($this->table->getName(), $key);
     $referenced = $this->getReference($table, $column);
     if ($referenced !== false) {
         $this->access($key, false);
         return $referenced;
     }
     $this->access($key, null);
     throw new Nette\MemberAccessException("Cannot read an undeclared column \"{$key}\".");
 }
コード例 #29
0
ファイル: Hlavne_menu.php プロジェクト: petak23/scspp
          $for_link = $abs_link . ($v->druh->presenter == "Menu" ? "Clanky" : $v->druh->presenter) . ":";
          $temp_pol = new \App\FrontModule\Components\Menu\MenuNode();
          $temp_pol->name = $ja->nazov;
          $temp_pol->tooltip = $ja->h1part2;
          $temp_pol->avatar = $v->avatar;
          $temp_pol->anotacia = $v->druh->presenter == "Clanky" && isset($ja->clanok_lang->anotacia) ? $ja->clanok_lang->anotacia : FALSE;
          $temp_pol->node_class = $v->ikonka !== NULL && strlen($v->ikonka) > 2 ? "fa fa-" . $v->ikonka : NULL;
          $temp_pol->link = $v->druh->je_spec_naz ? array($for_link) : $for_link;
          $temp_pol->absolutna = $v->absolutna;
          $temp_pol->novinka = $v->id_dlzka_novinky > 1 ? $v->modified->add(new \DateInterval('P' . $v->dlzka_novinky->dlzka . 'D')) : NULL;
          $temp_pol->id = $v->id;
          $temp_pol->poradie_podclankov = $v->poradie_podclankov;
          $out[] = array("node" => $temp_pol, "nadradena" => isset($v->id_nadradenej) ? $v->id_nadradenej : -1 * $v->hlavne_menu_cast->id);
          unset($temp_pol);
      }
      return $out;
  }
  /** Vypis menu pre Admin modul
 * @param int $id_reg         Min. id registrácie
 * @param type $lang_id       Id jazyka
 * @return array|FALSE
 */
  public function getMenuAdmin($id_reg, $lang_id = 1)
  {
      $polozky = $this->hlavne_menu_lang->where("hlavne_menu.id_registracia <= ?", $id_reg)->where("id_lang", $lang_id)->where("hlavne_menu.druh.modul IS NULL OR hlavne_menu.druh.modul = ?", "Admin")->order('hlavne_menu.id_hlavne_menu_cast, hlavne_menu.uroven, hlavne_menu.poradie ASC');
      return $polozky !== FALSE && count($polozky) ? $this->_getMenuAdmin($polozky) : FALSE;
  }
  /** Vytvorenie menu pre administraciu
 * @param Nette\Database\Table\Selection $polozky Vyber poloziek hl. menu
 * @return array|FALSE
 */
  private function _getMenuAdmin($polozky)
  {
      $cislo_casti = 0;
      //aktualne cislo casti
      $casti = array();
      $out = array();
      foreach ($polozky as $ja) {
          $v = $ja->hlavne_menu;
          //Mam taku istu cast ako pred tym? Ak nie nastav cislo casti, ale len ak je to dovolene cez $casti
          if ($cislo_casti !== $v->id_hlavne_menu_cast) {
              //Mam taku istu cast ako pred tym? Ak nie nastav cislo casti
              $cislo_casti = $v->id_hlavne_menu_cast;
              $casti[] = $cislo_casti;
              $temp_pol = new \App\AdminModule\Components\Menu\MenuNode();
              $temp_pol->name = $v->hlavne_menu_cast->nazov;
              $temp_pol->link = array("Homepage:");
              $temp_pol->id = -1 * $v->hlavne_menu_cast->id;
              $out[] = array("node" => $temp_pol, "nadradena" => FALSE);
コード例 #30
0
ファイル: ActiveRow.php プロジェクト: exesek/nette20login
 protected function getReference($table, $column)
 {
     if (array_key_exists($column, $this->data)) {
         $this->access($column);
         $value = $this->data[$column];
         $value = $value instanceof ActiveRow ? $value->getPrimary() : $value;
         $referenced = $this->table->getReferencedTable($table, $column, !empty($this->modified[$column]));
         $referenced = isset($referenced[$value]) ? $referenced[$value] : NULL;
         // referenced row may not exist
         if (!empty($this->modified[$column])) {
             // cause saving changed column and prevent regenerating referenced table for $column
             $this->modified[$column] = 0;
             // 0 fails on empty, pass on isset
         }
         return $referenced;
     }
 }