select() public static méthode

public static select ( $args ) : Dibi\Fluent
Résultat Dibi\Fluent
Exemple #1
0
 public function near($lat, $lon, $distance = 100000)
 {
     $key = 'events' . $lat . $lon . $distance;
     $cache = new Nette\Caching\Cache($this->context->cacheStorage);
     $ids = $cache->load($key);
     $ids = NULL;
     if ($ids === NULL) {
         /* Vytáhnu si všechny koordináty */
         $res = dibi::select('id, lat, lon')->from('subject')->where('deleted = 0')->and('map_coords !=""')->fetchAll();
         /* Zjistím vzdálenost jednotlivých ID od středu */
         $locs = array();
         foreach ($res as $r => $n) {
             $dist = Geolocation::getDistance($lat, $lon, $n['lat'], $n['lon']);
             if ($dist <= $distance && $dist > 1) {
                 $locs[] = array('id' => $n['id'], 'dist' => $dist);
             }
         }
         /* Nestliže nic nenajdu, tak vyhodím chybu. */
         if (count($locs) == 0) {
             throw new DibiException('There is no places', 1);
         }
         foreach ($locs as $key => $row) {
             $ids[$key] = $row['id'];
             $distances[$key] = $row['dist'];
         }
         foreach ($locs as $key => $row) {
             $aa[$row['id']] = $row['dist'];
         }
         array_multisort($distances, SORT_ASC, $ids, SORT_ASC, $locs);
         $cache->save($key, $ids, array(Nette\Caching\Cache::TAGS => array("events", "event", "distance"), Nette\Caching\Cache::EXPIRATION => '4 hours'));
     }
     $this->where('subject_id', $ids);
     return $this;
 }
Exemple #2
0
 static function createTable($table, $group)
 {
     // header
     $header = array();
     $res = dibi::select('COLUMN_COMMENT, COLUMN_NAME')->from('information_schema.COLUMNS')->where('(TABLE_NAME = %s AND COLUMN_NAME = %s)', 'general', 'name')->or('(TABLE_NAME = %s AND COLUMN_NAME = %s)', 'general', 'id')->or('(TABLE_NAME = %s)', $table)->execute();
     $header = $res->fetchAll();
     // Changing header so that it fits the JOINed select
     $header[1]['COLUMN_COMMENT'] = 'Summoner name';
     $header[1]['COLUMN_NAME'] = 'summoner_name';
     // body
     $existing_players = $group->getExistingPlayers();
     $t1_select = dibi::select('summoner_name, id')->as('id_general')->from('general');
     $t2_select = dibi::select("*")->from($table);
     $res = dibi::select('*')->from($t1_select)->as('t1')->innerJoin($t2_select)->as('t2')->on('t1.id_general = t2.id')->where('( id, region) ')->in($existing_players);
     // create column names to check if table can be ordered
     $column_names = array();
     foreach ($header as $column) {
         array_push($column_names, $column["COLUMN_NAME"]);
     }
     // check if ordering is set and according to it, rearrange selection from database
     if (isset($_SESSION["orderby"]) && isset($_SESSION["way"])) {
         if (in_array($_SESSION["orderby"], $column_names)) {
             $res = $res->orderBy($_SESSION["orderby"]);
             if ($_SESSION["way"] == "asc") {
                 $res = $res->asc();
             } else {
                 $res = $res->desc();
             }
         }
     }
     $res = $res->execute();
     $body = $res->fetchAll();
     $table_elements = array($header, $body);
     return $table_elements;
 }
 public function renderDefault()
 {
     //uvod
     $home = dibi::fetch("SELECT * FROM [menu_item] WHERE home = 1 AND lang = %s", $this->lang);
     if (!$home) {
         $home = dibi::fetch("SELECT * FROM [menu_item] WHERE lang = %s", $this->lang, "ORDER BY sequence LIMIT 1");
     }
     $this->template->id_menu_item = $home['id_menu_item'];
     /*
      * META INFO
      */
     $this['header']->addTitle($home['meta_title']);
     $this['header']->setDescription($home['meta_description']);
     $node = $this->getService('Node');
     $query = $node->getAll($this->template->id_menu_item);
     $this->template->node_list = $query->fetchAll();
     //produkty na uvode
     $list = dibi::select('id_product')->from('product')->where('home = 1');
     $count_list = clone $list;
     $count = $count_list->removeClause('select')->select('COUNT(id_product)')->fetchSingle();
     $vp = new VisualPaginator($this, 'paginator');
     $paginator = $vp->getPaginator();
     $paginator->itemsPerPage = 12;
     $paginator->itemCount = (int) $count;
     $this->template->products = $list->limit($paginator->offset . ',' . $paginator->itemsPerPage)->fetchAll();
     $this->template->paginator = $paginator;
     foreach ($this->template->products as $k => $p) {
         $this->template->products[$k] = ProductModel::getProductWithParams($p['id_product'], $this->id_lang, $this->user);
     }
     /* widget */
     $this['productNewsSaleAvaiableTable']->setIdLang($this->id_lang);
     $this['productNewsSaleAvaiableTable']->setUser($this->user);
 }
 /**
  * get owners' ids of packages containing checked file
  *
  * @return array
  */
 public function getOwnersOfPackagesContainingFile()
 {
     if (empty($this->ownersOfPackagesContainingFile)) {
         $this->ownersOfPackagesContainingFile = dibi::select('owner_id')->from(BaseModel::CLIENT_PACKAGES_TABLE)->as('cp')->join(BaseModel::FILES_2_CLIENT_PACKAGES_TABLE)->as('f2cp')->on('f2cp.client_packages_id = cp.id')->where('f2cp.files_id = %i', $this->id)->fetchAssoc('owner_id');
         $this->ownersOfPackagesContainingFile = array_keys($this->ownersOfPackagesContainingFile);
     }
     return $this->ownersOfPackagesContainingFile;
 }
 function beforeRender()
 {
     parent::beforeRender();
     $this->template->id_category = $this->id;
     $this->template->category_parents = CategoryModel::getParents($this->template->id_category, $this->id_lang);
     //ak je iba jeden parent zobraz kategorie, inak zobraz produkty
     if (count($this->template->category_parents) == 1) {
         $id_parent = current($this->template->category_parents);
         $category_list = CategoryModel::getFluent('id_category')->where('id_parent = %i', $id_parent)->fetchAll();
         $this->template->categories = array();
         foreach ($category_list as $l) {
             $_tmp = CategoryModel::get($l->id_category, $this->id_lang);
             $_tmp['product_count'] = dibi::fetchSingle("SELECT COUNT(id_product) FROM [product] JOIN [category_product] USING(id_product) WHERE id_category = %i", $l->id_category);
             $this->template->categories[] = $_tmp;
         }
         $this->template->product_count = dibi::fetchSingle("SELECT COUNT(id_product) FROM [product] JOIN [category_product] USING(id_product) WHERE id_category = %i", $this->id);
     } else {
         $list = dibi::select('id_product')->from('product')->join('category_product')->using('(id_product)')->join('product_param')->using('(id_product)')->where('id_category = ', $this->id, 'AND product.active = 1');
         /*
          * Filter
          */
         $orderSession = $this['quickFilter']->getSession();
         //			dde($orderSession['order']);
         //			$orderSession['order'] = 'price';
         if ($orderSession['order']) {
             $list->orderBy($orderSession['order']);
         } else {
             $order_array = $this['quickFilter']->getOrderFilterArray();
             $list->orderBy(key($order_array));
         }
         $list->groupBy('id_product');
         //			dump($order);
         //		print_r($list);
         $count_list = clone $list;
         //			$count = $count_list->removeClause('select')->select('COUNT(id_product)')->fetchSingle();
         $count = count($count_list);
         $vp = new VisualPaginator($this, 'paginator');
         $paginator = $vp->getPaginator();
         $numOnPageSession = $this['quickFilter']->getSession();
         if ($numOnPageSession['num']) {
             $paginator->itemsPerPage = $numOnPageSession['num'];
         } else {
             $num_on_page_array = $this['quickFilter']->getNumOnPageFilterArray();
             $paginator->itemsPerPage = key($num_on_page_array);
         }
         $paginator->itemCount = (int) $count;
         $this->template->product_count = $count;
         $this->template->products = $list->limit($paginator->offset . ',' . $paginator->itemsPerPage)->fetchAll();
         //dump($this->template->products);
         $this->template->paginator = $paginator;
         foreach ($this->template->products as $k => $p) {
             $this->template->products[$k] = ProductModel::getProductWithParams($p['id_product'], $this->id_lang, $this->user);
         }
         //		};
     }
     //		print_r($this->template->products);exit;
 }
Exemple #6
0
 private function getkey($id)
 {
     if (!isset($this->key_stmt)) {
         $this->key_stmt = \dibi::select('session_key')->from('session')->where('id = %i', $id)->fetchSingle();
     }
     if ($this->key_stmt) {
         return $this->key_stmt;
     } else {
         $random_key = hash('sha512', uniqid(mt_rand(1, mt_getrandmax()), true));
         return $random_key;
     }
 }
Exemple #7
0
 /**
  * Vraci vsechny polozky omezene poctem a smerem
  * @param $offset scalar
  * @param $limit scalar
  * @param $orderBy string
  * @param $sort string
  * @return DibiResult
  */
 public function fetchAll($page = 1, $limit = 15, $orderBy = 'created', $sort = 'desc')
 {
     $filters = $this->prepareFilter($this->session->filter);
     $offset = ($page - 1) * $limit;
     $res = dibi::select('*')->from('[guestbook]');
     //     	$res->where('[deleted]','=','0');
     if ($filters) {
         $res->where('1', $filters);
     }
     $res->orderBy($orderBy, $sort);
     $res->offset($offset);
     $res->limit($limit);
     return $res->fetchAll();
 }
Exemple #8
0
 /**
  * Performs an authentication
  * @param  array
  * @return IIdentity
  * @throws AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     $username = strtolower($credentials[self::USERNAME]);
     $password = strtolower($credentials[self::PASSWORD]);
     $row = dibi::select('*')->from('users')->where('username=%s', $username)->fetch();
     if (!$row) {
         throw new AuthenticationException("User '{$username}' not found.", self::IDENTITY_NOT_FOUND);
     }
     if ($row->password !== $password) {
         throw new AuthenticationException("Invalid password.", self::INVALID_CREDENTIAL);
     }
     unset($row->password);
     return new Nette\Security\Identity($row->id, NULL, $row);
 }
 /**
  * Get one article
  * @param $id
  * @return bool|Row|FALSE
  */
 public function getArticle($id)
 {
     if (!$id) {
         return False;
     }
     try {
         $article = \dibi::select('*')->from('articles')->where('id = %s', $id)->fetch();
         if ($article instanceof Row) {
             return $article;
         } else {
             return False;
         }
     } catch (Exception $e) {
         throw new $e();
     }
 }
Exemple #10
0
 public function fileUploadSuccess(AppForm $form)
 {
     try {
         foreach ($form->values->image as $image) {
             $file = new \File();
             $d = $image->getImageSize();
             if ($d[0] < 300 && $d[1] < 300) {
                 throw new InvalidArgumentException('Obrázek je příliš malý. Musí mít minimálně jeden rozměr vyšší než 300px. Nahrajte prosím větší obrázek.');
             }
             if ($d[0] > 3000 || $d[1] > 3000) {
                 throw new InvalidArgumentException('Obrázek je až zbytečně veliký. Žádný rozměr by neměl být vyšší než 3000px. Nahrajte prosím menší obrázek.');
             }
             $file->file_prefix = "";
             $file->file_sufix = "_u" . $this->context->user->id . "_" . substr(sha1(time()), 0, 4);
             $file->user_id = $this->context->user->id;
             $file->insertUploaded($image, FILESTORAGE_DIR);
             $file->visible = 1;
             // automaticka publikace
             $file->save();
             if ($form->values->type == "event") {
                 dibi::query('INSERT INTO event_x_file', array('event_id' => $form->values->id, 'file_id' => $file->id));
                 $res = dibi::select('*')->from('event_x_file')->where('first', '=', 1)->where('event_id', '=', $form->values->id);
                 if (count($res) == 0) {
                     $res = dibi::select('*')->from('event_x_file')->where('event_id', '=', $form->values->id)->fetch();
                     dibi::query('UPDATE event_x_file SET ', array('first' => 1), 'WHERE event_id = ', $res->event_id, 'AND file_id =', $res->file_id);
                 }
             } elseif ($form->values->type == "place") {
                 dibi::query('INSERT INTO subject_x_file', array('subject_id' => $form->values->id, 'file_id' => $file->id));
                 $res = dibi::select('*')->from('subject_x_file')->where('first', '=', 1)->where('subject_id', '=', $form->values->id);
                 if (count($res) == 0) {
                     $res = dibi::select('*')->from('subject_x_file')->where('subject_id', '=', $form->values->id)->fetch();
                     dibi::query('UPDATE subject_x_file SET ', array('first' => 1), 'WHERE subject_id = ', $res->subject_id, 'AND file_id =', $res->file_id);
                 }
             }
         }
     } catch (Exception $e) {
         $form->addError($e->getMessage());
     }
     if ($form->isSuccess()) {
         $cache = new \Nette\Caching\Cache($this->context->cacheStorage);
         $cache->clean(array('files', 'images', 'file', 'image', $form->values->type, $form->values->type . 's'));
         $this->presenter->flashMessage('Dobrá zpráva, fotografie se podařilo vložit!', 'success');
         $this->redirect('this');
     }
 }
 /**
  * nacita prelozene stringy do slovnika
  * 
  * @param array $supportedLangs pole podporovanych jazykov
  * @param bool $rebuild rebuild dictionary by pulling phrases out of .php and .phtml and updating database
  * @return void
  *
  */
 public function buildDictionary($supportedLangs = NULL, $rebuild = false)
 {
     if (!isset($this->langs) && !$supportedLangs) {
         throw new Exception('nastav podporovane jazyky');
     } elseif ($supportedLangs) {
         $this->langs = $supportedLangs;
     }
     if ($rebuild) {
         $this->findAllStrings();
         // calls buildDictionary() so return
         return;
     }
     $lang = Environment::getVariable('lang');
     $dictionary = Environment::getCache('dictionary');
     if ($dictionary['data'] === null) {
         $data = array();
         foreach ($this->langs as $lang) {
             $data[$lang] = dibi::select("msg_id, IF(msg_{$lang} = '', msg_id, msg_{$lang}) AS msg")->from(self::TABLE)->fetchPairs('msg_id', 'msg');
         }
         $dictionary['data'] = $data;
     }
     $this->dictionary = $dictionary['data'][$lang];
     //		dump($this->dictionary);
 }
 protected function createComponentNavigation($name)
 {
     $nav = new NavigationControl($this, $name);
     $menuItems = dibi::select("id, label_{$this->lang} AS label, nette_link, nette_link_args, current_link, uri")->from('menu')->where('is_visible = 1')->orderBy('sort')->fetchAll();
     foreach ($menuItems as $item) {
         $args = !is_null($item->nette_link_args) ? Basic::string2array(str_replace('%id%', $item->id, $item->nette_link_args)) : array();
         // expand nette link args
         $uri = $item->nette_link !== null ? $this->link($item->nette_link, $args) : $item->uri;
         // nette link or standard URI
         $nav->add($item->label, $uri, $item->current_link);
     }
 }
Exemple #13
0
 public function generateAllTimes($times = 30, $term_id = 0, $limit = 120)
 {
     $limit = new DibiDateTime(strtotime('+' . $limit . ' days', time()));
     dibi::begin();
     if ($term_id) {
         dibi::query('DELETE FROM event_time_all WHERE event_time_id = %i', $term_id);
         // smaze tabulku casu s daným ID termínu
         $res = dibi::select('*, DATEDIFF(event_time.date_to, event_time.date_from) AS diff_dates')->from('event_time')->where('visible', '=', '1')->where('id', '=', $term_id)->fetchAll();
     } else {
         //dibi::query('TRUNCATE TABLE event_time_all'); // smaze celou tabulku casu
         dibi::query('UPDATE event_time SET visible = 0 WHERE (DATEDIFF(event_time.date_from, CURDATE()) < 0 AND DATEDIFF(event_time.date_to, CURDATE()) < 0) OR (DATEDIFF(event_time.date_from, CURDATE()) < 0 AND isnull(`event_time`.`date_to`))');
         // prevede vsechny starsi casy do neaktivni polohy
         $res = dibi::select('*, DATEDIFF(event_time.date_to, event_time.date_from) AS diff_dates')->from('event_time')->where('visible', '=', '1')->fetchAll();
     }
     foreach ($res as $key => $event) {
         $interval = date_diff($event->date_from, date_create());
         if ($interval->days > 0 && $interval->invert) {
             $date_from = $event->date_from;
             //dump('od '.$date_from);
         } else {
             $date_from = new DibiDateTime();
             //dump('od dnes');
         }
         $nextmonday = new DibiDateTime(date('N', strtotime('today')) == 1 ? strtotime('today') : strtotime('next monday', $date_from->getTimestamp()));
         $nexttuesday = new DibiDateTime(date('N', strtotime('today')) == 2 ? strtotime('today') : strtotime('next tuesday', $date_from->getTimestamp()));
         $nextwednesday = new DibiDateTime(date('N', strtotime('today')) == 3 ? strtotime('today') : strtotime('next wednesday', $date_from->getTimestamp()));
         $nextthursday = new DibiDateTime(date('N', strtotime('today')) == 4 ? strtotime('today') : strtotime('next thursday', $date_from->getTimestamp()));
         $nextfriday = new DibiDateTime(date('N', strtotime('today')) == 5 ? strtotime('today') : strtotime('next friday', $date_from->getTimestamp()));
         $nextsaturday = new DibiDateTime(date('N', strtotime('today')) == 6 ? strtotime('today') : strtotime('next saturday', $date_from->getTimestamp()));
         $nextsunday = new DibiDateTime(date('N', strtotime('today')) == 7 ? strtotime('today') : strtotime('next sunday', $date_from->getTimestamp()));
         //dump($date_from);
         if ($event->repeat == 1) {
             if ($event->every_monday == 1) {
                 for ($i = 0; $i < $times * 7; $i = $i + 7) {
                     $day = new DibiDateTime(strtotime('+' . $i . ' days', $nextmonday->getTimestamp()));
                     if ($day->getTimestamp() > $limit->getTimestamp()) {
                         continue;
                     }
                     $query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
                     dibi::query($query);
                 }
             }
             if ($event->every_tuesday == 1) {
                 for ($i = 0; $i < $times * 7; $i = $i + 7) {
                     $day = new DibiDateTime(strtotime('+' . $i . ' days', $nexttuesday->getTimestamp()));
                     if ($day->getTimestamp() > $limit->getTimestamp()) {
                         continue;
                     }
                     $query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
                     dibi::query($query);
                 }
             }
             if ($event->every_wednesday == 1) {
                 for ($i = 0; $i < $times * 7; $i = $i + 7) {
                     $day = new DibiDateTime(strtotime('+' . $i . ' days', $nextwednesday->getTimestamp()));
                     if ($day->getTimestamp() > $limit->getTimestamp()) {
                         continue;
                     }
                     $query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
                     dibi::query($query);
                 }
             }
             if ($event->every_thursday == 1) {
                 for ($i = 0; $i < $times * 7; $i = $i + 7) {
                     $day = new DibiDateTime(strtotime('+' . $i . ' days', $nextthursday->getTimestamp()));
                     if ($day->getTimestamp() > $limit->getTimestamp()) {
                         continue;
                     }
                     $query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
                     dibi::query($query);
                 }
             }
             if ($event->every_friday == 1) {
                 for ($i = 0; $i < $times * 7; $i = $i + 7) {
                     $day = new DibiDateTime(strtotime('+' . $i . ' days', $nextfriday->getTimestamp()));
                     if ($day->getTimestamp() > $limit->getTimestamp()) {
                         continue;
                     }
                     $query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
                     dibi::query($query);
                 }
             }
             if ($event->every_saturday == 1) {
                 for ($i = 0; $i < $times * 7; $i = $i + 7) {
                     $day = new DibiDateTime(strtotime('+' . $i . ' days', $nextsaturday->getTimestamp()));
                     if ($day->getTimestamp() > $limit->getTimestamp()) {
                         continue;
                     }
                     $query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
                     dibi::query($query);
                 }
             }
             if ($event->every_sunday == 1) {
                 for ($i = 0; $i < $times * 7; $i = $i + 7) {
                     $day = new DibiDateTime(strtotime('+' . $i . ' days', $nextsunday->getTimestamp()));
                     if ($day->getTimestamp() > $limit->getTimestamp()) {
                         continue;
                     }
                     $query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $day . "', '" . $event->date_to . "'); \r\n";
                     dibi::query($query);
                 }
             }
         } else {
             $query = "INSERT IGNORE INTO event_time_all (event_time_id, date_from, date_to) VALUES ('" . $event->id . "', '" . $event->date_from . "', '" . $event->date_to . "'); \r\n";
             dibi::query($query);
         }
     }
     dibi::query('DELETE FROM event_time_all WHERE date_to < date_from AND date_to !="0000-00-00"');
     dibi::commit();
 }
 /**
  * get supervisorId from DB
  *
  * @param int resourceId
  * @return int supervisorId
  */
 protected function getDependencies($id)
 {
     return dibi::select('COALESCE(supervisor_id, id)')->from(BaseModel::USERS_TABLE)->where('id = %i', $id)->fetchSingle();
 }
 /**
  * get ownerId from DB
  *
  * @param int resourceId
  * @return int ownerId
  */
 protected function getDependencies($id)
 {
     return dibi::select('owner_id')->from(BaseModel::LIGHTBOXES_TABLE)->where('id = %i', $id)->fetchSingle();
 }
 public static function findIdByUriDB($uri, $table)
 {
     //		$id = dibi::select('id')
     $id = dibi::select(static::$idKey)->from($table)->where('%n = %s', static::$uriKey, $uri)->fetchSingle();
     return $id === false ? null : $id;
 }
Exemple #17
0
<div class="page-header">
  <h1><i class="fa fa-list"></i> Logs <a class="btn btn-default" href='/new'><i class="fa fa-plus"></i> Add a new log</a>
  </h1>
</div>
<?php 
$logs = dibi::select('*')->from('logs')->orderBy('time DESC')->limit(10);
if (!isset($_GET['station'])) {
    // ..
} else {
    $limit = array('station = %s', $_GET['station']);
    $logs->where($limit[0], $limit[1]);
    echo 'Showing only ' . htmlspecialchars($_GET['station']);
}
$logs = $logs->fetchAll();
echo '<table class="table table-hover table-condensed">';
echo '<thead><tr><th>Time</th><th>Station</th><th>Frequency</th><th>Call #1</th><th>Call #2</th><th>Groups</th><th>Reporter</th></tr></thead><tbody>';
foreach ($logs as $row) {
    echo '<tr>';
    echo '<td><time class="timeago" datetime="' . $row->time->format(DateTime::ISO8601) . '"></time>' . '</td><td><b>' . $row->station . '</b></td><td>' . $row->qrh . '</td><td>' . $row->callup . '</td><td>' . $row->callup2 . '</td><td>' . $row->gc . '</td><td>' . $row->reporter . '</td>';
    echo '<td>';
    if ($row->gc > 0 && $row->body != '') {
        echo '<a class="btn btn-default btn-sm" href="javascript:alert(\'' . $row->body . '\')">groups</a>';
    }
    echo '</td>';
    echo '</tr>';
}
echo '</tbody></table>';
 static function getQuery()
 {
     return dibi::select('id_product')->from('product')->join('product_lang')->using('(id_product)')->join('product_param')->using('(id_product)')->join('category_product')->using('(id_product)')->join('category')->using('(id_category)')->where("product.active = 1 AND category.active = 1");
 }
Exemple #19
0
 public static function getAnswerFluent($id_poll)
 {
     return dibi::select('*')->from('poll_answer')->where('id_poll = %i', $id_poll);
 }
Exemple #20
0
<h1>Using Fluent Syntax | dibi</h1>

<?php 
require_once 'Nette/Debug.php';
require_once '../dibi/dibi.php';
date_default_timezone_set('Europe/Prague');
dibi::connect(array('driver' => 'sqlite', 'database' => 'data/sample.sdb'));
$id = 10;
$record = array('title' => 'Super product', 'price' => 318, 'active' => TRUE);
// SELECT ...
dibi::select('product_id')->as('id')->select('title')->from('products')->innerJoin('orders')->using('(product_id)')->innerJoin('customers USING (customer_id)')->orderBy('title')->test();
// -> SELECT [product_id] AS [id] , [title] FROM [products] INNER JOIN [orders]
//    USING (product_id) INNER JOIN customers USING (customer_id) ORDER BY [title]
// SELECT ...
echo dibi::select('title')->as('id')->from('products')->fetchSingle();
// -> Chair (as result of query: SELECT [title] AS [id] FROM [products])
// INSERT ...
dibi::insert('products', $record)->setFlag('IGNORE')->test();
// -> INSERT IGNORE INTO [products] ([title], [price], [active]) VALUES ('Super product', 318, 1)
// UPDATE ...
dibi::update('products', $record)->where('product_id = %d', $id)->test();
// -> UPDATE [products] SET [title]='Super product', [price]=318, [active]=1 WHERE product_id = 10
// DELETE ...
dibi::delete('products')->where('product_id = %d', $id)->test();
// -> DELETE FROM [products] WHERE product_id = 10
// custom commands
dibi::command()->update('products')->where('product_id = %d', $id)->set($record)->test();
// -> UPDATE [products] SET [title]='Super product', [price]=318, [active]=1 WHERE product_id = 10
dibi::command()->truncate('products')->test();
// -> TRUNCATE [products]
Exemple #21
0
 static function getFluent()
 {
     return dibi::select('*')->from('product_weight');
 }
Exemple #22
0
 /**
  * @param $data
  * @return array
  */
 public static function getAllAssoc($data)
 {
     return dibi::select('*')->from(static::$table)->where($data)->fetchAssoc('id');
 }
Exemple #23
0
 static function getFluent($onlyActivated = true)
 {
     return dibi::select(TABLE_USERS_INFO . '.*,' . TABLE_USERS . '.login,' . TABLE_USERS . '.surname,' . TABLE_USERS . '.name,' . TABLE_USERS . '.lastvisit,' . TABLE_USERS . '.email,' . TABLE_USERS . '.activate,' . TABLE_USERS . '.id AS id_gui_user')->from(TABLE_USERS)->leftJoin(TABLE_USERS_INFO)->on(' (' . TABLE_USERS . '.id = ' . TABLE_USERS_INFO . '.user_id) ')->leftJoin(TABLE_USERS_COUNTRY)->using('(iso)')->where("1=1 %if", $onlyActivated, "AND activate = 1 %end");
 }
Exemple #24
0
 static function getFluent($select = '*')
 {
     return dibi::select($select)->from('category')->leftJoin('category_lang')->using('(id_category)');
 }
Exemple #25
0
 /**
  * @param scalar|array $id
  * @return array
  */
 public function fetch($id)
 {
     if (is_array($id)) {
         $account = dibi::select('*')->from('user')->where($id);
         return $account->fetch();
     } else {
         $account = dibi::select('*')->from('user')->where('id', '=', $id)->fetch();
         if (!$account) {
             return false;
         }
         $details = dibi::select('*')->from('user')->where('id', '=', $id)->fetch();
         $account['details'] = (array) $details;
         return $account;
     }
 }
Exemple #26
0
 public function getUserId4TemporaryLogin($token, $email)
 {
     $data = dibi::select('users_id, UNIX_TIMESTAMP(expire) AS expire')->from(self::TEMPORARY_LOGIN_TABLE)->where('token = %s', $token)->where('email = %s', $email)->fetch();
     if (!$data) {
         return $data;
     }
     if ($data->expire < time()) {
         throw new TokenExpiredException();
     } else {
         return $data->users_id;
     }
 }
 protected function createComponentTestProductTabella($name)
 {
     $grid = new Maite\Tabella(array('context' => $this->context, 'source' => dibi::select('*')->from('lang_translate'), 'id_table' => 'id_lang', 'limit' => 10));
     $grid->addColumn('Nazov', 'translate');
     $grid->addColumn('+', Tabella::ADD, array('type' => Tabella::DELETE));
     return $grid;
 }
Exemple #28
0
 public static function getAll()
 {
     return $rows = dibi::select('id, name, lang')->from('languages')->orderBy('sort ASC')->fetchAll();
 }
Exemple #29
0
 function isInDatabase($codename, $region)
 {
     $table = "group";
     $res = dibi::select('id')->from($table)->where('codename = %s and region = %s', $codename, $region)->execute();
     $result_1 = $res->fetchAll();
     $row_exists = count($result_1);
     // if is in database
     if ($row_exists) {
         $inner_select = dibi::select('last_updated')->from($table)->where('codename = %s and region = %s', $codename, $region);
         $main_select = dibi::select('time_to_sec(timediff(current_timestamp, (' . $inner_select . ') ))')->as('diff')->execute();
         $result = $main_select->fetchAll();
         $diff = $result[0]["diff"];
         // if needs update
         if ($diff < MAIN_CACHE_TIME) {
             $id = $result_1[0]["id"];
             $this->addIdRegion($id, $region);
             // adds id and region of existing player into array existing_players
             return True;
         }
     }
     return False;
 }
Exemple #30
0
 /**
  * check if $col $val is available
  *
  * @param string value to search for
  * @param string db column name to search in
  * @return bool
  */
 public function isAvailable($val, $col = 'name')
 {
     return !(bool) dibi::select('COUNT(*)')->from(static::TABLE)->where('%n = %s', $col, $val)->fetchSingle();
 }