public function get($id) { $clanek = $this->database->fetch("SELECT c.*, cr.perex, cr.text,cr.datum as aktualizovano, k.nazev as kategorie,cr.id as crid,\n ko.komentaru, u.alt, u.title\n FROM clanky c\n JOIN (select * from clanky_revize where id in (SELECT max(id) from clanky_revize group by clanek_id )) cr ON (c.id=cr.clanek_id)\n JOIN kategorie k ON (c.kategorie_id = k.id)\n LEFT JOIN (select clanek_id,count(*) as komentaru from komentare group by clanek_id) ko ON (ko.clanek_id=c.id)\n LEFT JOIN upload u ON (c.obrazek_id = u.id)\n WHERE c.id=? and c.smazano=0 ORDER BY cr.id DESC LIMIT 1;", $id); $stitky = $this->database->fetchPairs("SELECT stitek FROM stitky WHERE clanek_id=?;", $id); if (!empty($clanek)) { $clanek->stitky = array_unique($stitky); } return $clanek; }
public function actionDefault($param) { // Yes, I hate this code, too. // Yes, it was the fastest way to build a prototype. // Yes, it would just kill the database server later on. // No, do not use anywhere. // Yes, you have just been warned. $this->tags = array_filter(preg_split('/\\s+/', $param)); if (empty($this->tags)) { $query = 'SELECT * FROM urls'; } else { $query = 'SELECT * FROM urls WHERE id IN ( SELECT s1.url_id FROM (SELECT ut.url_id FROM url_tags ut JOIN tags t ON ut.tag_id = t.id WHERE t.tag IN (?)) s1' . "\n"; for ($i = 2; $i <= count($this->tags); $i++) { $query .= "JOIN (SELECT ut.url_id FROM url_tags ut JOIN tags t ON ut.tag_id = t.id WHERE t.tag IN (?)) s{$i} ON s1.url_id = s{$i}.url_id\n"; } $query .= ')'; } $result = call_user_func_array([$this->database, 'fetchAll'], array_merge([$query], $this->tags)); $urls = array(); foreach ($result as $url) { $urls[$url->id] = $url; $urls[$url->id]->tags = array(); } if (!empty($urls)) { $urlTags = $this->database->fetchAll(' SELECT ut.url_id AS urlId, t.tag, tc.category AS category FROM tags t JOIN url_tags ut ON t.id = ut.tag_id LEFT JOIN tag_categories tc ON t.category_id = tc.id WHERE ut.url_id IN (?) ORDER BY t.category_id, t.tag ', array_keys($urls)); foreach ($urlTags as $tag) { $urls[$tag->urlId]->tags[] = $tag; } } $allTags = array_values($this->database->fetchPairs('SELECT id, tag FROM tags ORDER BY tag')); $this->template->tags = $this->tags; $this->template->urls = $urls; $this->template->allTags = $allTags; }
public function getRolePairs() { return $this->database->fetchPairs("SELECT id, nazev FROM role;"); }
public function getPairs() { return $this->database->fetchPairs("SELECT id, alt from upload order by id desc;"); }
public function getPairs() { return $this->database->fetchPairs("SELECT id, nazev FROM kategorie;"); }