query() public static method

Generates and executes SQL query - Monostate for Dibi\Connection::query().
public static query ( $args ) : Dibi\Result | integer
return Dibi\Result | integer result set object (if any)
Ejemplo n.º 1
0
 public function renderDefault($url)
 {
     $res = dibi::query('
   SELECT
         workId,
         url as file,
         title,
         text,', Model::sqlCategory() . ' as category,
         authorUrl,
         CONCAT_WS(" ", name, surname) as authorName,
         year,', Model::sqlWorkClassName() . 'as workClass,', 'award,
         type, 
         pages,
         words,
         characters,
         [read],
         added,
         edited             
         FROM [works] 
         join [authors] on author = authorId
         WHERE `url`=%s', $url)->fetchAll();
     //$res[0]['award'] = ($res[0]['award'] != 99) ? $res[0]['award'] . ". místo" : "nominaci";
     //2010-08-19 22:43:25
     $res[0]['added'] = preg_replace('/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/', '$3.$2.$1 $4:$5', $res[0]['added']);
     $res[0]['edited'] = preg_replace('/(\\d{4})-(\\d{2})-(\\d{2}) (\\d{2}):(\\d{2}):(\\d{2})/', '$3.$2.$1 $4:$5', $res[0]['edited']);
     $this->template->data = $res[0];
     $this->template->files = FileModel::getFiles($res[0]['workId']);
     Model::increaseRead($res[0]['workId']);
 }
Ejemplo n.º 2
0
 /**
  * Performs an authentication
  *
  * @param  array
  * @return void
  * @throws AuthenticationException
  */
 public function authenticate(array $credentials)
 {
     $username = $credentials[self::USERNAME];
     $password = $credentials[self::PASSWORD];
     $sql = dibi::query('SELECT * FROM [' . TABLE_USERS . '] WHERE name=%s;', $username);
     $sql->setType('permission', Dibi::BOOL);
     $row = $sql->fetch();
     /*if (count($sql)==0) {
           throw new AuthenticationException('Unknown user', self::IDENTITY_NOT_FOUND);
       }*/
     /*if ($row->password !== md5($password)) {
           throw new AuthenticationException('Password not match', self::INVALID_CREDENTIAL);
       }*/
     if (count($sql) == 0 or $row->password !== md5($password)) {
         throw new AuthenticationException('Incorrect password or name', self::INVALID_CREDENTIAL);
     }
     // get roles
     $sql = dibi::query('SELECT r.key_name
                             FROM [' . TABLE_ROLES . '] AS r
                             RIGHT JOIN [' . TABLE_USERS_ROLES . '] AS us ON r.id=us.role_id
                             WHERE us.user_id=%i;', $row->id);
     $roles = $sql->fetchPairs();
     unset($row->password);
     return new Identity($username, $roles, $row);
 }
Ejemplo n.º 3
0
/**
 * Metainformation catalogue
 * --------------------------------------------------
 *
 * MICKA_LIB_INSERT.PHP for MicKa
 *
 * @link       http://www.bnhelp.cz
 * @package    Micka
 * @category   Metadata
 * @version    20101120
 * @authors		 DZ
 */
function deleteMd($user, $type, $value, $mode, $par = NULL)
{
    setMickaLog('micka_lib_insert.php (deleteMd)', 'DEBUG', "user={$user}, {$type}={$value}, mode={$mode}, par={$par}");
    $rs = FALSE;
    // autorizace
    if ($user == 'guest' || !canAction()) {
        return $rs;
    }
    $record = getMdHeader($type, $value, $col = '', $fetch = array('all', '='));
    if (isset($record[0]['RECNO']) && $record[0]['RECNO'] > -1) {
        if (!getMdRight('edit', $user, $record[0]['DATA_TYPE'], $record[0]['CREATE_USER'], $record[0]['EDIT_GROUP'], $record[0]['VIEW_GROUP'])) {
            return $rs;
        } else {
            $sql = array();
            if ($mode == 'all') {
                array_push($sql, 'DELETE FROM [md_values] WHERE [recno]=%i;', $record[0]['RECNO']);
                array_push($sql, 'DELETE FROM [md] WHERE [recno]=%i;', $record[0]['RECNO']);
            } elseif ($mode == 'value') {
                array_push($sql, 'DELETE FROM [md_values] WHERE [recno]=%i  AND md_id<>38;', $record[0]['RECNO']);
            }
            dibi::begin();
            try {
                dibi::query($sql);
                dibi::commit();
                $rs = TRUE;
            } catch (DibiException $e) {
                setMickaLog($e, 'ERROR', 'micka_lib_insert.php (deleteMd)');
                dibi::rollback();
            }
        }
    }
    //Debug::dump($rs);
    setMickaLog('micka_lib_insert.php (deleteMd)', 'DEBUG', "return={$rs}");
    return $rs;
}
Ejemplo n.º 4
0
 /**
  *
  */
 public function indexAction()
 {
     die('todo');
     $overwrite = !is_null(Core_Request::getInstance()->getArgv(4)) ? Core_Request::getInstance()->getArgv(4) : false;
     foreach (dibi::getDatabaseInfo()->getTables() as $table_data) {
         if ($table_data->getName() == Migration_MigrationModel::getTableName()) {
             continue;
         }
         $ddl_data = dibi::query('SHOW CREATE TABLE ' . $table_data->getName())->fetch()->toArray();
         $ddl_query = $ddl_data['Create Table'];
         $migration_time = time();
         $migration_name = 'Create' . ucfirst($table_data->getName());
         $migration_name = str_replace(' ', '', $migration_name);
         $migration_name = str_replace('-', '', $migration_name);
         $migration_name = str_replace('_', '', $migration_name);
         $filename = cfg()->migration_path . $migration_name . '.php';
         if (Core_Files::fileSize($filename) && !$overwrite) {
             echo PHP_EOL . 'Migration "Create ' . ucfirst($table_data->getName()) . '" Exists' . PHP_EOL;
             continue;
         }
         $template_data = Core_Files::getContent(cfg()->migration_path . Migration_FilesHelper::TEMPLATE_FILE_NAME);
         $template_data = str_replace('Template', $migration_name, $template_data);
         $template_data = str_replace('__NAME__', $migration_name, $template_data);
         $template_data = str_replace('__CREATED_AT__', $migration_time, $template_data);
         $template_data = str_replace('__CREATED_CFG__', Core_Request::getInstance()->getArgv(1), $template_data);
         $template_data = preg_replace('#//__UP_ACTION__#', $ddl_query, $template_data);
         $down_query = 'DROP TABLE IF EXISTS `' . $table_data->getName() . '`';
         $template_data = preg_replace('#//__DOWN_ACTION__#', $down_query, $template_data);
         Core_Files::putContent($filename, $template_data);
         echo PHP_EOL . 'Migration ' . $filename . ' created' . PHP_EOL;
     }
 }
Ejemplo n.º 5
0
 public function loadGroupsByUserId($id)
 {
     $query = "SELECT `id`, `pid`, `title`, `description` FROM\n\t\t\t`" . Config::DB_PREFIX . "user_groups` ug\n\t\t\tJOIN  `" . Config::DB_PREFIX . "groups` g ON g.`id` = ug.`group_id`\n\t\t\tWHERE ug.`user_id` = " . $id;
     $result = dibi::query($query)->fetchAssoc('id');
     $this->importRecord($result);
     return $this;
 }
Ejemplo n.º 6
0
    function renderXml_old()
    {
        //$this->id_lang
        $this->template->items = dibi::query('
SELECT 
product.id_product AS id, 
product_lang.name, 
product_lang.meta_description, 
product_lang.link_rewrite AS product_link,
category_product.id_category AS id_category,
category_lang.name AS category_name,
category_lang.link_rewrite AS category_link

FROM `product`
LEFT JOIN product_lang USING (id_product)
LEFT JOIN category_product USING (id_product)
LEFT JOIN category_lang USING (id_category)
WHERE product_lang.id_lang = 1 AND
 category_lang.id_lang = 1
GROUP BY (id_product)')->fetchAll();
        $this->template->baseUri = 'http://' . $_SERVER['HTTP_HOST'];
        $this->id_lang = 1;
        for ($i = 0; $i < count($this->template->items); $i++) {
            $this->template->items[$i]['url'] = $this->link(':Front:Product:default', array('id' => $this->template->items[$i]['id'], 'id_category' => $this->template->items[$i]['id_category']));
            $this->template->items[$i]['image'] = ProductModel::getImage($this->template->items[$i]['id']);
            $this->template->items[$i]['price_vat'] = round($productWithLowestPrice['price'], 2);
            $this->template->items[$i]['price'] = round($this->template->items[$i]['price_vat'] / 1.2, 2);
            $this->template->items[$i]['vat'] = '0.20';
            $this->template->items[$i]['size'] = $productWithLowestPrice['size'];
            $this->template->items[$i]['material'] = $productWithLowestPrice['material'];
        }
        dde($this->template->items);
    }
Ejemplo n.º 7
0
 private function loadAll()
 {
     // @todo odchytavat vyjimky z dibi pro pripad neexistujici tabulky.
     $query = "SELECT `module_functions_id`, `webinstance_id`, `pageid_id`, `command` FROM `" . Config::DB_PREFIX . 'routedynamic_' . $this->langSymbol . "`";
     $record = dibi::query($query)->fetchAll();
     $this->importRecord($record);
 }
Ejemplo n.º 8
0
 public function __construct($app)
 {
     $app->post('/rest/login/', function () use($app) {
         $user = json_decode($app->request->getBody(), true);
         if (!isset($user['username']) || empty($user['username'])) {
             $app->error();
         }
         if (!isset($user['password']) || empty($user['password'])) {
             $app->error();
         }
         $result = \dibi::query('select username FROM ::user where username = %s and password = %s', $user['username'], md5($user['password']))->fetchAll();
         if (sizeof($result) != 1) {
             return $app->error();
         }
         $oldToken = \dibi::query('select token from ::oauth where username = %s', $user['username'])->fetch();
         $token = bin2hex(openssl_random_pseudo_bytes(16));
         $auth = array();
         $auth["username"] = $user['username'];
         $auth["token"] = $token;
         if ($oldToken["token"]) {
             \dibi::query('update ::oauth set token = %s where username = %s', $token, $user['username']);
         } else {
             \dibi::query('insert into ::oauth', $auth);
         }
         echo json_encode($token);
     });
 }
Ejemplo n.º 9
0
 public function beforeRender()
 {
     $filters = $this->getUniqueValues(array('works' => array('year', 'award', 'type'), 'authors' => array('class')));
     $temp = $filters['authors'];
     unset($filters['authors']);
     //$filters['works']['category'] = Model::palicky();// + array(5=>'palice');    // 'category'=>'Kategorie',
     $filters['works']['grade'] = Model::rocniky();
     $filters['palicka']['category'] = Model::palicky();
     $filters['authors'] = $temp;
     //{link :Front:Default:works "category"=>palicka}
     $this->template->filters = $filters;
     $this->template->schoolYear = Model::getSchoolYear();
     $newest = dibi::query('SELECT
       url,
       title,
       CONCAT_WS(" ", name, surname) as authorName          
       FROM [works] 
       join [authors] on author = authorId', 'ORDER BY %by', array('added' => 'desc'), 'LIMIT %i', 2)->fetchAll();
     $this->template->newest = $newest;
     $mostread = dibi::query('SELECT
       url,
       title,
       CONCAT_WS(" ", name, surname) as authorName          
       FROM [works] 
       join [authors] on author = authorId', 'ORDER BY %by', array('read' => 'desc'), 'LIMIT %i', 3)->fetchAll();
     $this->template->mostread = $mostread;
     $user = Environment::getUser();
     if ($user->isLoggedIn()) {
         $this->template->adminMode = true;
     }
 }
Ejemplo n.º 10
0
 function saveArticle($values, $id_node)
 {
     $tmp = dibi::fetch("SELECT * FROM article WHERE id_node=%i", $id_node);
     unset($values['id_node']);
     //odstranenie premennych ktore niesu v databaze
     $values = Tools::getValuesForTable('article', $values);
     $name = NStrings::webalize($values['url_identifier']);
     $newname = "";
     $i = 0;
     while ($i < 50) {
         if ($i == 0) {
             $newname = $name;
         } else {
             $newname = NStrings::webalize($name . $i);
         }
         $s = dibi::fetchSingle("SELECT COUNT(id_node) FROM article WHERE url_identifier=%s", $newname, " AND id_node!=%i", $id_node);
         if ($s == 0) {
             break;
         } else {
             $i++;
         }
     }
     $values['url_identifier'] = $newname;
     dibi::query("UPDATE article SET ", $values, " WHERE id_node=%i", $id_node);
     NEnvironment::getService('Article')->invalidateCache();
 }
Ejemplo n.º 11
0
 /**
  * Nacte data.
  *
  * @return Bobr_Page_Page
  * @throws Bobr_Page_PageIAException Pokud neni vyplnena vlastnosti id.
  * @throws Bobr_Page_PageException Pokud nenajde zadne data.
  */
 public function load()
 {
     if (0 > $this->id) {
         throw new Bobr_Page_PageIAException('Neni zadano pageId ktere se ma nacist.');
     }
     if (!$this->loadFromCache()) {
         $query = 'SELECT `container_id`, `block_id`, `weight`
             FROM `' . Config::DB_PREFIX . 'pageid_container_block`
             WHERE `pageid_id` = ' . $this->id . ' ORDER BY `container_id`, `weight`';
         $data = dibi::query($query)->fetchAssoc('container_id,block_id');
         if (empty($data)) {
             throw new Bobr_Page_PageException('Zadana stranka nema zadne data.');
         }
         // Naimportujem data.
         $this->importRecord($data);
         try {
             $this->setPageId(new Bobr_Page_PageId($this->id));
         } catch (Bobr_Page_PageIdException $e) {
             // Nelze nacist PageId nelze sestavit Page.
             throw new Bobr_Page_PageException($e->getMessage());
         }
         // Ulozime Page do cache.
         $this->saveToCache();
     }
     return $this;
 }
Ejemplo n.º 12
0
    public function renderXml()
    {
        $this->template->items = dibi::query('
SELECT 
product.id_product AS id, 
product_lang.name, 
product_lang.description, 
product_lang.link_rewrite AS product_link,
category_product.id_category AS id_category,
category_lang.name AS category_name,
category_lang.link_rewrite AS category_link
FROM `product`
LEFT JOIN product_lang USING (id_product)
LEFT JOIN category_product USING (id_product)
LEFT JOIN category_lang USING (id_category)
WHERE product_lang.id_lang = 1 AND
 category_lang.id_lang = 1
GROUP BY (id_product)')->fetchAll();
        $this->template->baseUri = 'http://www.matrace-rosty.sk';
        $this->id_lang = 1;
        for ($i = 0; $i < count($this->template->items); $i++) {
            $productWithLowestPrice = dibi::query('SELECT * FROM product_param WHERE id_product = %i', $this->template->items[$i]['id'], ' ORDER BY price LIMIT 0,1')->fetch();
            $this->template->items[$i]['url'] = $this->getPresenter()->link('Eshop:current', array('categories' => $this->template->items[$i]['category_link'], 'url_identifier' => NStrings::webalize($this->template->items[$i]['product_link'])));
            $this->template->items[$i]['image'] = ProductModel::getImage($this->template->items[$i]['id']);
            $this->template->items[$i]['price_vat'] = round($productWithLowestPrice['price'], 2);
            $this->template->items[$i]['price'] = round($this->template->items[$i]['price_vat'] / 1.2, 2);
            $this->template->items[$i]['vat'] = '0.20';
            $this->template->items[$i]['size'] = $productWithLowestPrice['size'];
            $this->template->items[$i]['material'] = $productWithLowestPrice['material'];
        }
    }
Ejemplo n.º 13
0
 public static function show()
 {
     if (isset($_GET['ajax_action_section']) and $_GET['ajax_action_section'] == 'save_description') {
         dibi::query("\n  \t\t\tUPDATE [newsletter_emails] \n  \t\t\tSET description = %s", $_POST['description'], "WHERE id_newsletter_emails = %i", $_POST['id_newsletter_emails']);
         exit;
     }
     MT::addTemplate(APP_DIR . '/require_modules/newsletter/default.phtml', 'newsletter');
     $ds = NewsletterModel::getDatasource();
     if (isset($_GET['id_newsletter_delete'])) {
         NewsletterModel::delete($_GET['id_newsletter_delete']);
         header('location: admin.php?section=newsletter');
         exit;
     }
     if (isset($_GET['export'])) {
         $dse = clone $ds;
         MT::addVar('newsletter', 'export', $dse->where('active = 1 AND id_newsletter_emails IN %l', $_GET['id'])->fetchAll());
     }
     if (@$_GET['order_by'] == 'email') {
         $ds->orderBy('email');
     } else {
         $ds->orderBy('adddate');
     }
     //$vp = new MyPaginator($ds, 10);
     MT::addVar('newsletter', 'emails', $ds->fetchAll());
     //  	MT::addVar('newsletter', 'vp', $vp);
 }
Ejemplo n.º 14
0
 public function getToken()
 {
     session_start();
     $code = $_REQUEST["code"];
     if (empty($code)) {
         $_SESSION['state'] = md5(uniqid(rand(), TRUE));
         //CSRF protection
         $dialog_url = "https://www.facebook.com/dialog/oauth?client_id=" . APP_ID . "&redirect_uri=" . urlencode(REDIRECT_URI) . "&scope=" . PERMISSIONS . "&state=" . $_SESSION['state'];
         echo "<script> top.location.href='" . $dialog_url . "'</script>";
     }
     if ($_SESSION['state'] && $_SESSION['state'] === $_REQUEST['state']) {
         $token_url = "https://graph.facebook.com/oauth/access_token?" . "client_id=" . APP_ID . "&redirect_uri=" . urlencode(REDIRECT_URI) . "&client_secret=" . APP_SECRET . "&code=" . $code;
         $response = file_get_contents($token_url);
         $params = null;
         parse_str($response, $params);
         $date = new DateTime();
         $date->add(new DateInterval('PT' . $params["expires"] . 'S'));
         $arr = array('token' => $params['access_token'], 'expiration' => $date);
         dibi::query('TRUNCATE tokens');
         dibi::query('INSERT INTO tokens', $arr);
         echo "Thanks for your token :)";
     } else {
         echo "The state does not match. You may be a victim of CSRF.";
     }
 }
Ejemplo n.º 15
0
 protected function _writeMethodsForEavAttributes($model, $table)
 {
     $query = 'SELECT attribute_code as Field
         FROM eav_attribute a
         JOIN eav_entity_type t ON t.entity_type_id = a.entity_type_id
         WHERE entity_model = %s';
     $this->_writeMethodsForFields($model, $table, \dibi::query($query, $this->_classIdentifiers[$model]), 'eav');
 }
Ejemplo n.º 16
0
 public function gc($maxlifetime)
 {
     $old = time() - $maxlifetime;
     if (!isset($this->gc_stmt)) {
         $this->gc_stmt = \dibi::query("DELETE FROM session WHERE set_time < %s", $old);
     }
     return true;
 }
Ejemplo n.º 17
0
 /**
  * Find by product id
  * @param int
  * @return array
  */
 public function findByProductId($product_id)
 {
     if (!isset($this->pool[$product_id])) {
         $this->pool[$product_id] = array();
         $this->poolResults(dibi::query($this->query, 'WHERE [parameters].[product_id] = %i', $product_id));
     }
     return $this->pool[$product_id];
 }
Ejemplo n.º 18
0
 public function register($new_user)
 {
     $array = get_object_vars($new_user);
     $array['role'] = 0;
     unset($array['password2']);
     $array['password'] = $this->return_hash($array['password']);
     dibi::query('INSERT INTO user', $array);
 }
Ejemplo n.º 19
0
/**
 * Provedení sql dotazu a předání nalezených záznamů v požadovaném tvaru
 *
 * <b>Příklady:</b><br>
 * první políčko výsledku<br>
 * <code>_executeSql('select', $sql, array('single'));</code>
 * celá tabulka do indexovaného pole<br>
 * <code>_executeSql('select', $sql, array('all'));</code>
 * celá tabulka do asociativního pole a klíčem je políčko ‚recno‘
 * <code>_executeSql('select', array($pom['sql']), array('assoc', 'recno,#,='));</code>
 * asociativního pole klíč ⇒ hodnota
 * <code>_executeSql('select', array($pom['sql']), array('pairs', 'recno', 'xmldata'));</code>
 * update, insert, delete
 * <code>_executeSql('update', $sql, array());</code>
 *
 * @param string $type 'select', 'update', 'insert', 'delete'
 * @param array $sql
 * @param array $fetch 'single', 'all', 'assoc', 'pairs'
 */
function _executeSql($type, $sql, $fetch, $upper = TRUE)
{
    //setMickaLog("SQL TYPE=$type, fetch=" . $fetch[0], 'FUNCTION', 'micka_lib_db._executeSql.start');
    $rs = FALSE;
    if (count($sql) == 0) {
        setMickaLog("empty SQL", 'ERROR', 'micka_lib_db._executeSql');
        return $sql;
    }
    if (is_array($sql) && is_array($fetch) && $type == 'select') {
        $result = dibi::query($sql);
        setMickaLog(preg_replace("/\\s{2,}/", ' ', dibi::$sql), 'SQL', 'micka_lib_db._executeSql.sql');
        //Debugger::log('[micka_lib_db._executeSql.select] ' . dibi::$sql, 'INFO');
        //Debugger::log('[micka_lib_db._executeSql.select] ' . print_r($sql, true), 'INFO');
        if ($fetch[0] == 'single') {
            $rs = trim($result->fetchSingle());
        } elseif ($fetch[0] == 'all') {
            //setMickaLog("FETCH ALL START", 'DEBUG', 'micka_lib_db._executeSql');
            $blob = 'OCI-Lob';
            //if (count($result) > 0) { // FIXME: ORACLE - nefunguje
            foreach ($result as $n => $row) {
                foreach ($row as $key => $value) {
                    if (DB_DRIVER == 'oracle') {
                        if ($value instanceof $blob) {
                            $rs[$n][$key] = $value->load();
                        } else {
                            $rs[$n][$key] = is_string($value) ? rtrim($value) : $value;
                        }
                    } else {
                        $rs[$n][strtoupper($key)] = is_string($value) ? rtrim($value) : $value;
                    }
                }
            }
            //}
            //setMickaLog("FETCH ALL END", 'DEBUG', 'micka_lib_db._executeSql');
        } elseif ($fetch[0] == 'assoc') {
            $rs = setUpperColsName($result->fetchAssoc($fetch[1]));
        } elseif ($fetch[0] == 'pairs' && count($fetch) == 3) {
            if (DB_DRIVER == 'oracle') {
                $rs = $upper ? setUpperColsName($result->fetchPairs(strtoupper($fetch[1]), strtoupper($fetch[2]))) : $result->fetchPairs(strtoupper($fetch[1]), strtoupper($fetch[2]));
            } else {
                $rs = $upper ? setUpperColsName($result->fetchPairs($fetch[1], $fetch[2])) : $result->fetchPairs($fetch[1], $fetch[2]);
            }
        }
    } elseif (is_array($sql) && ($type == 'update' || $type == 'insert' || $type == 'delete')) {
        $rs = dibi::query($sql);
        setMickaLog(preg_replace("/\\s{2,}/", ' ', dibi::$sql), 'SQL', 'micka_lib_db._executeSql.sql');
        //Debugger::log('[micka_lib_db._executeSql.update] ' . dibi::$sql, 'INFO');
    } elseif (is_array($sql) && $type == 'pxml') {
        //Debugger::log('[micka_lib_db._executeSql.pxml] ' . $sql[0], 'INFO');
        $rs = dibi::query($sql[0]);
        //Debugger::log('[micka_lib_db._executeSql.pxml] OK', 'INFO');
    } else {
        setMickaLog("unknow TYPE SQL", 'ERROR', 'micka_lib_db._executeSql');
    }
    unset($result);
    setMickaLog("", 'FUNCTION', 'micka_lib_db._executeSql.end');
    return $rs;
}
 public static function exists($idPanel)
 {
     $result = \dibi::query('select 1 FROM ::panel where idpanel = %s', $idPanel);
     $panels = $result->fetchAll();
     if (sizeof($panels) == 0) {
         return false;
     }
     return true;
 }
Ejemplo n.º 21
0
 public function getRows($offset = 0, $limit = 10, $return_res = false)
 {
     $result = dibi::query("SELECT * FROM `{$this->db}`.`{$this->name}`\n\t\t\t\t\t\t\t  LIMIT {$offset}, {$limit}");
     if ($return_res) {
         return $result;
     } else {
         return $result->fetchAll();
     }
 }
Ejemplo n.º 22
0
 /**
  * All children of specific parent of resources placed in a array
  * 
  * @param   integer Parent id
  * @param   array Array of curent resources
  * @param   integer Depth of tree structure
  */
 public function getParents($parent_id, &$array, $depth)
 {
     $sql = dibi::query('SELECT id, name FROM [' . TABLE_RESOURCES . '] WHERE %and ORDER BY name;', array('parent_id' => $parent_id));
     $rows = $sql->fetchAll();
     foreach ($rows as $row) {
         $array[$row->id] = ($depth ? str_repeat('- - ', $depth) : '') . $row->name;
         $this->getParents($row->id, $array, $depth + 1);
     }
 }
Ejemplo n.º 23
0
 public static function getAllDatabases()
 {
     $res = dibi::query("SHOW DATABASES");
     $dbs = array();
     while ($db = $res->fetchSingle()) {
         $dbs[] = $db;
     }
     return $dbs;
 }
Ejemplo n.º 24
0
 public function editFormSubmitted(AppForm $form)
 {
     if (!$form['jmeno']->value and $form['id']->value) {
         dibi::query('DELETE FROM lide WHERE id = %i', $form['id']->value);
     } else {
         dibi::query('REPLACE INTO lide ', $form->values);
     }
     $this->redirect('this');
 }
Ejemplo n.º 25
0
    function createSQL()
    {
        dibi::query('
			CREATE TABLE `user_form` (
			  `id_node` int(11) NOT NULL,
			  `title` varchar(255) NOT NULL
			) ENGINE=MyISAM DEFAULT CHARSET=utf8;
		');
    }
 /**
  * Delete
  * @param int
  * @return bool
  */
 public function deleteOne($id)
 {
     try {
         dibi::query('DELETE FROM [:prefix:product_availabilities]', 'WHERE [id] = %i', $id);
         return TRUE;
     } catch (Exception $e) {
         return FALSE;
     }
 }
Ejemplo n.º 27
0
 public function handleDelete($id)
 {
     Model::delete($id, "authorId", "authors");
     $array = dibi::query('SELECT workId FROM works WHERE author=%i', $id)->fetchAssoc();
     foreach ($array as $val) {
         FileModel::deleteFiles($val['workId']);
     }
     Model::delete($id, "author", "works");
     $this->redirect('this');
 }
Ejemplo n.º 28
0
 /**
  * Nacte zakladni uzivatelske udaje podle id.
  *
  * @param integer $id 
  */
 private function loadUserInfo($id)
 {
     $this->setId($id);
     $query = "SELECT `id`, `nick`, `pass`, `email`, `status_id`\n\t\t\tFROM `" . Config::DB_PREFIX . "users`\n\t\t\tWHERE `id` = " . $this->id;
     $data = dibi::query($query)->fetch();
     if (empty($data)) {
         throw new Bobr_User_UserNotExistException('Uzivatel s id ' . $this->id . ' neexistuje.');
     }
     $this->importRecord($data);
 }
Ejemplo n.º 29
0
 /**
  * Insert
  * @param array
  * @return bool
  */
 public function insertOne(array $values)
 {
     try {
         $values['order_id'] = intval($values['order_id']);
         $values['sent_at'] = new DibiVariable('NOW()', 'sql');
         dibi::query('INSERT INTO [:prefix:order_emails]', $values);
         return TRUE;
     } catch (Exception $e) {
         return FALSE;
     }
 }
Ejemplo n.º 30
0
 function saveHome($values, $id_node)
 {
     $tmp = dibi::fetch("SELECT * FROM " . self::TABLE . " WHERE id_node=%i", $id_node);
     unset($values['id_node']);
     //odstranenie premennych ktore niesu v databaze
     foreach ($values as $key => $v) {
         if (!array_key_exists($key, $tmp)) {
             unset($values[$key]);
         }
     }
     dibi::query("UPDATE " . self::TABLE . " SET ", $values, " WHERE id_node=%i", $id_node);
 }