Example #1
0
 /**
  * Tries to find content that matches the input query
  * @param string $query
  */
 public function find($query)
 {
     $q = implode('%', explode(' ', $query));
     $sql = 'SELECT content.* FROM content JOIN idiom ON content.idiom_id = idiom.id
         WHERE idiom.code = ? AND content.publish = 1 
             AND (
                 content.keywords like (?)
                 OR content.alias like (?) 
                 OR content.title like (?)
                 OR content.description like (?)
                 OR content.intro like (?)
                 OR content.html like (?)
                 )
         ORDER BY visits DESC';
     // Prepare values and run query
     $q = "%{$q}%";
     $rows = R::getAll($sql, array(BootWiki::getIdiom(), $q, $q, $q, $q, $q, $q));
     $results = R::convertToBeans('content', $rows);
     if (!empty($results)) {
         foreach ($results as $item) {
             $content = new Content($item->alias);
             $content->importBean($item);
             $this->items[] = $content;
         }
     }
 }
Example #2
0
 /**
  * Fetch all allowed operatations for user
  *
  * @return array
  */
 protected function getData()
 {
     // Get results from cache if they exist
     $this->manager->getCache() && ($rows = $this->manager->getCache()->get($this->cacheKey . $this->identity));
     if (isset($rows) && is_array($rows) && count($rows) > 0) {
         return $this->parse(static::ITEM_CLASS, $rows);
     }
     // Nothing found in cache, or cached array is empty, lookup from db
     $rows = R::getAll("\n          SELECT\n            DISTINCT `role`.`name` AS item_name,\n            `role`.`id` AS item_id,\n            `role`.`description` AS item_desc\n          FROM `role`\n          JOIN `role_user` ON (`role_user`.`role_id` = `role`.`id`)\n          WHERE `role_user`.`user_id` = :id\n          ORDER BY item_name ASC\n        ", [':id' => $this->identity]);
     // Save to cache
     $this->manager->getCache() && $this->manager->getCache()->set($this->cacheKey . $this->identity, $rows, $this->cacheTtl);
     return $this->parse(static::ITEM_CLASS, $rows);
 }
Example #3
0
 static function getUserID($name)
 {
     $user = R::getAll('SELECT id FROM user WHERE name = ?', [$name]);
     return $user[0][id];
 }
Example #4
0
 static function getGroups($model)
 {
     return R::getAll('SELECT ag.name collection FROM models m INNER JOIN rel_model_attr r ON m.id = r.model_id INNER JOIN attributes a ON a.id = r.attr_id INNER JOIN attr_groups ag ON ag.id = a.group_id WHERE m.name = ? AND Coalesce(m.deleted, 0) = 0 GROUP BY ag.name ORDER BY ag.id', [$model]);
 }
<?php

use RedBean_Facade as R;
$q = R::getAll('SELECT * FROM `question` ORDER BY `id`');
foreach ($q as $key => $val) {
    $q[$key]['options'] = json_decode($val['options'], true);
}
$app->result = $q;
Example #6
0
 static function getShopModels($shop)
 {
     return R::getAll('SELECT name, image, description FROM models WHERE shop_id = (SELECT id FROM shops WHERE name = ?) AND Coalesce(deleted, 0) = 0', [$shop]);
 }
Example #7
0
<?php

use RedBean_Facade as R;
if (empty($userid)) {
    throw new \Exception('userid is required', 412);
}
$app->result = R::getAll('SELECT * FROM `answer` WHERE `userid` = :userid ORDER BY `questionid`', array(':userid' => $userid));
Example #8
0
 /**
  * This loads all content items
  */
 public function loadAll()
 {
     // Load featured
     $sql = '
     SELECT content.* FROM content 
     LEFT JOIN idiom ON content.idiom_id = idiom.id
     WHERE idiom.code = ? AND content.featured = 1 AND content.publish = 1';
     $rows = R::getAll($sql, array(BootWiki::getIdiom()));
     $beans = R::convertToBeans('content', $rows);
     $featured = array();
     foreach ($beans as $item) {
         $content = new Content();
         $content->importBean($item);
         $featured[] = $content;
     }
     $this->featured = $featured;
 }