예제 #1
0
 public function testFetchRowCallsPdoWithSqlAndParams()
 {
     $sql = 'SELECT * FROM `test_table` WHERE id = ? LIMIT 1';
     $sqlParameters = [1];
     $tableData = ['id' => 5];
     $mockPdoStatement = $this->createMock(\PDOStatement::class);
     $this->mockPdo->expects($this->once())->method('prepare')->with($sql)->willReturn($mockPdoStatement);
     $mockPdoStatement->expects($this->once())->method('execute')->with($sqlParameters);
     $mockPdoStatement->expects($this->once())->method('fetch')->willReturn($tableData);
     $this->assertEquals($tableData, $this->db->fetchRow($sql, $sqlParameters));
 }
예제 #2
0
 /**
  * Загружает видео из базы данных по ID
  * @param $id
  * @return array|null
  * @throws Exception
  */
 protected function getVideo($id)
 {
     $video = $this->db->fetchRow("SELECT * FROM video WHERE id = :id LIMIT 1", ['id' => $id]);
     if (empty($video)) {
         throw new Exception("Not found video");
     }
     return $video;
 }
예제 #3
0
 public static function onePagina($idPagina, $idioma = null)
 {
     if (is_null($idioma)) {
         $idioma = Translate::locale();
     }
     $result = Db::fetchRow(Db::select(array('inmuebles_paginas_contenidos.inmueble_pagina_contenido_id', 'inmuebles_paginas_contenidos.idioma', 'inmuebles_paginas_contenidos.nombre', 'inmuebles_paginas_contenidos.titulo', 'inmuebles_paginas_contenidos.url', 'inmuebles_paginas.inmueble_pagina_id', 'inmuebles_paginas.codigo', 'inmuebles_paginas.tipo', 'inmuebles_paginas.posicion'), 'inmuebles_paginas_contenidos', array('inmuebles_paginas.inmueble_pagina_id' => $idPagina, 'inmuebles_paginas_contenidos.idioma' => $idioma), null, 1, array('inmuebles_paginas', array('inmuebles_paginas.inmueble_pagina_id' => 'inmuebles_paginas_contenidos.inmueble_pagina_id'))));
     $contenido = new Inmuebles_Paginas_Contenidos();
     if ($result) {
         $contenido->found(true);
         $contenido->import($result);
     }
     return $contenido;
 }
예제 #4
0
파일: Model.php 프로젝트: joksnet/php-old
 public function query()
 {
     $this->found = false;
     if (!isset($this->values['id'])) {
         return false;
     }
     $values = Db::fetchRow(Db::select('*', $this->table, array($this->index => $this->values['id']), null, 1));
     if ($values) {
         $this->import($values);
         $this->found = true;
     }
     return $values ? true : false;
 }
예제 #5
0
파일: Model.php 프로젝트: joksnet/php-old
 /**
  * @param integer $id
  * @return boolean
  */
 public function get($id)
 {
     if (null === $this->identifier) {
         throw new Exception('Identifier not found.');
     }
     $result = $this->db->fetchRow($this->db->select('*', $this->table, array($this->identifier => $id)));
     if ($result) {
         foreach ($result as $name => $value) {
             $this->{":{$name}"} = $value;
         }
     }
     $this->hash = Model::hash($this->properties);
     return (bool) $result;
 }
예제 #6
0
<?php

$root = '.';
include_once "{$root}/config.php";
include_once "{$root}/common.php";
if (!isset($_GET['pid'])) {
    die('Missing parameter');
}
$pid = (int) $_GET['pid'];
if (!Session::$logged) {
    header("Location: {$config['root']}signin/?next={$config['root']}dd/projects/{$pid}/delete/");
}
$title = __('ProjectsDeleteTitle');
$project = Db::fetchRow("SELECT name, description, uid\n     FROM projects\n     WHERE pid = '{$pid}'");
if ($project) {
    $name = $project['name'];
    $description = $project['description'];
    if ($project['uid'] == Session::_('uid')) {
        $access = true;
    }
}
if (!empty($_POST)) {
    if ($pid) {
        Db::query("DELETE FROM projects\n             WHERE pid = '{$pid}'");
    }
    header("Location: {$config['root']}dd/projects/");
}
require_once "{$root}/themes/{$theme}/ddprojectsdelete.php";
예제 #7
0
 public function update($id, $data)
 {
     $db = new Db($this->subgridConfig, $this->statusVariables);
     $oldData = $db->fetchRow($id);
     $fields = $this->subgridConfig->fields();
     $dbData = array();
     $languageData = array();
     $languages = ipContent()->getLanguages();
     foreach ($fields as $field) {
         if (empty($field['field']) || $field['field'] == $this->subgridConfig->idField() || isset($field['allowUpdate']) && !$field['allowUpdate'] || !empty($field['type']) && $field['type'] == 'Tab' || !empty($field['ignoreDb'])) {
             continue;
         }
         $fieldObject = $this->subgridConfig->fieldObject($field);
         $fieldObject->beforeUpdate($id, $oldData, $data);
         //the same event for both: multilingual and non multilingual fields. Each field may store it's multilingual state from constructor and act differently on this event if needed. $oldData is not very correct in multilingual context. But that's still the bets way to go.
         if (empty($field['multilingual'])) {
             $fieldData = $fieldObject->updateData($data);
             if (!is_array($fieldData)) {
                 throw new \Ip\Exception("updateData method in class " . esc(get_class($fieldObject)) . " has to return array.");
             }
             $dbData = array_merge($dbData, $fieldData);
         } else {
             foreach ($languages as $language) {
                 $tmpData = $data;
                 if (isset($data[$field['field'] . '_' . $language->getCode()])) {
                     $tmpData[$field['field']] = $data[$field['field'] . '_' . $language->getCode()];
                 }
                 $fieldObject = $this->subgridConfig->fieldObject($field);
                 $fieldData = $fieldObject->updateData($tmpData);
                 if (!is_array($fieldData)) {
                     throw new \Ip\Exception("createData method in class " . esc(get_class($fieldObject)) . " has to return array.");
                 }
                 if (empty($languageData[$language->getCode()])) {
                     $languageData[$language->getCode()] = array();
                 }
                 $languageData[$language->getCode()] = array_merge($languageData[$language->getCode()], $fieldData);
             }
         }
     }
     if ($this->subgridConfig->updateFilter()) {
         $dbData = call_user_func($this->subgridConfig->updateFilter(), $id, $dbData);
     }
     if ($this->subgridConfig->isMultilingual() && $this->subgridConfig->updateLanguageFilter()) {
         $languageData = call_user_func($this->subgridConfig->updateLanguageFilter(), $id, $languageData);
     }
     $this->updateDb($this->subgridConfig->rawTableName(), $dbData, $id);
     if (!empty($languageData)) {
         foreach ($languageData as $languageCode => $rawData) {
             $translationExists = ipDb()->selectRow($this->subgridConfig->rawLanguageTableName(), '*', array($this->subgridConfig->languageCodeField() => $languageCode, $this->subgridConfig->languageForeignKeyField() => $id));
             if (!$translationExists) {
                 $insertData = $rawData;
                 $insertData[$this->subgridConfig->languageCodeField()] = $languageCode;
                 $insertData[$this->subgridConfig->languageForeignKeyField()] = $id;
                 ipDb()->insert($this->subgridConfig->rawLanguageTableName(), $insertData);
             }
             $this->updateDb($this->subgridConfig->rawTableName(), $rawData, $id, $languageCode);
         }
     }
     foreach ($fields as $field) {
         $this->subgridConfig->fieldObject($field)->afterUpdate($id, $oldData, $data);
     }
 }
예제 #8
0
<?php

$root = '.';
include_once "{$root}/config.php";
include_once "{$root}/common.php";
if (!isset($_GET['pid'])) {
    die('Missing parameter');
}
$pid = (int) $_GET['pid'];
if (!Session::$logged) {
    header("Location: {$config['root']}signin/?next={$config['root']}dd/projects/{$pid}/");
}
$project = Db::fetchRow("SELECT pid, uid, name, description, public\n     FROM projects\n     WHERE pid = '{$pid}'");
$title = empty($project) ? __('ProjectNotFound') : $project['name'];
if (!empty($project)) {
    $access = false;
    if ($project['public']) {
        $access = true;
    } elseif ($project['uid'] == Session::_('uid')) {
        $access = true;
    } else {
        $usersAccess = Db::fetchPairs("SELECT uid, aid\n             FROM projects_access\n             WHERE pid = '{$pid}'\n               AND uid != 0");
        if (!empty($usersAccess)) {
            $access = isset($usersAccess[Session::_('uid')]) ? true : false;
        }
    }
    $names = Db::fetchAssoc("SELECT n.nid, n.name, n.description, u.uid, u.email\n         FROM projects_names n\n         INNER JOIN users u ON u.uid = n.uid\n         WHERE n.pid = '{$pid}'");
}
require_once "{$root}/themes/{$theme}/ddprojectsview.php";
예제 #9
0
파일: index.php 프로젝트: joksnet/php-old
 protected function select($id)
 {
     $this->user = Db::fetchRow("SELECT users.id_user AS id\n                  , users.name\n                  , users.username\n                  , users.location\n                  , users.description\n                  , users.image\n                  , users.url\n                  , users.token\n                  , users.secret\n                  , users.address\n                  , users.x\n                  , users.y\n                  , users.sex\n                  , users.age\n                  , users.modified\n                  , users.created\n             FROM twcensus_users AS users\n             WHERE id_user = '******'");
     return $this->user;
 }
예제 #10
0
파일: signin.php 프로젝트: joksnet/php-old
}
$title = __('SignInTitle');
$error = array();
if (isset($_GET['email']) && isEmail($_GET['email'])) {
    $email = $_GET['email'];
}
if (!empty($_POST)) {
    $email = $_POST['email'];
    $password = $_POST['password'];
    if (!isEmail($email)) {
        $error['email'] = true;
    }
    if (strlen($password) < 6) {
        $error['password'] = true;
    }
    if (empty($error)) {
        $data = Db::fetchRow("SELECT uid, email, password\n             FROM users\n             WHERE email = '{$email}'\n               AND password = MD5('{$password}')");
        if (empty($data)) {
            $error['signin'] = true;
        }
    }
    if (empty($error) && $data) {
        Session::register($data);
        if (isset($_POST['next'])) {
            header("Location: {$_POST['next']}");
        } else {
            header("Location: {$config['root']}dd/");
        }
    }
}
require_once "{$root}/themes/{$theme}/signin.php";
예제 #11
0
 public function updateForm($id)
 {
     $db = new Db($this->subgridConfig, $this->statusVariables);
     $form = new \Ip\Form();
     $form->addAttribute('autocomplete', 'off');
     $curData = $db->fetchRow($id);
     $curDataMultilingual = array();
     if ($this->subgridConfig->isMultilingual()) {
         //fetch multilingual data
         $languages = ipContent()->getLanguages();
         foreach ($languages as $language) {
             $langDb = new Db($this->subgridConfig, $this->statusVariables);
             $langDb->setDefaultLanguageCode($language->getCode());
             $curDataMultilingual[$language->getCode()] = $langDb->fetchRow($id);
         }
     }
     foreach ($this->subgridConfig->fields() as $key => $fieldData) {
         if (isset($fieldData['allowUpdate']) && !$fieldData['allowUpdate']) {
             continue;
         }
         if (!empty($fieldData['type']) && $fieldData['type'] == 'Tab') {
             //tabs (fieldsets)
             $title = '';
             if (!empty($fieldData['label'])) {
                 $title = $fieldData['label'];
             }
             if ($key == 0) {
                 $fieldsets = $form->getFieldsets();
                 $fieldset = $fieldsets[0];
                 $fieldset->setLabel($title);
             } else {
                 $fieldset = new \Ip\Form\Fieldset($title);
                 $form->addFieldset($fieldset);
             }
             $fieldset->addAttribute('id', 'autoGridTabId' . rand(0, 100000000000));
             if ($key == 0) {
                 $fieldset->addAttribute('class', 'tab-pane active');
             } else {
                 $fieldset->addAttribute('class', 'tab-pane');
             }
         } else {
             //fields
             if (!empty($fieldData['multilingual'])) {
                 $languages = ipContent()->getLanguages();
                 foreach ($languages as $language) {
                     $tmpFieldData = $fieldData;
                     $field = $this->updateField($tmpFieldData, $curDataMultilingual[$language->getCode()]);
                     $field->setName($field->getName() . '_' . $language->getCode());
                     if ($field) {
                         $field->setLabel($field->getLabel() . ' ' . $language->getAbbreviation());
                         $form->addField($field);
                     }
                 }
             } else {
                 $field = $this->updateField($fieldData, $curData);
                 if ($field) {
                     $form->addField($field);
                 }
             }
         }
     }
     $field = new \Ip\Form\Field\Hidden(array('name' => $this->subgridConfig->idField(), 'value' => $id));
     $form->addField($field);
     $field = new \Ip\Form\Field\Hidden(array('name' => 'method', 'value' => 'update'));
     $form->addField($field);
     $field = new \Ip\Form\Field\HiddenSubmit();
     $form->addField($field);
     if (count($form->getFieldsets()) > 1) {
         $form->addClass('tab-content');
     }
     if ($this->subgridConfig->updateFormFilter()) {
         $form = call_user_func($this->subgridConfig->updateFormFilter(), $form);
     }
     return $form;
 }