示例#1
0
 /**
  * Menghapus record tertentu berdasarkan column id.
  *
  * @param integer $id
  * @return bool
  */
 public function delete($id)
 {
     try {
         $this->db->delete($this->table, [$this->primaryKey, '=', $id]);
         return true;
     } catch (\Exception $e) {
         throw new \Exception("Cannot delete record.");
     }
 }
示例#2
0
 static function set_config($name, $value)
 {
     $one = DB::one('core_config', array('where' => array('slug' => $name)));
     if ($one) {
         DB::update('core_config', array('body' => $value), 'slug=:slug', array(':slug' => $name));
     } else {
         DB::insert('core_config', array('slug' => $name, 'body' => $value));
     }
 }
示例#3
0
文件: Project.php 项目: Hometgar/ppe3
 /**
  * Project constructor.
  * @param $_id
  * @param $_titre
  * @param $_dead_line
  * @param $_task_list
  */
 public function __construct($_id, $_titre, $_dead_line)
 {
     $this->_id = $_id;
     $this->_titre = $_titre;
     $this->_dead_line = $_dead_line;
     $tasks = DB::getInstance()->query('SELECT * FROM tache WHERE id_projet = ?', [$_id]);
     foreach ($tasks as $task) {
         $this->_task_liste[] = new Task($task['id'], $task['intitule'], $task['commenntaire'], $task['is_sstache'], $task['sous_tache_id'], $task['done']);
     }
 }
示例#4
0
 /**
  * 返回用户信息
  *
  */
 static function get_member($id)
 {
     $cacheId = 'get_member_' . $id;
     $one = \Yii::$app->cache->get($cacheId);
     if (!$one) {
         $one = DB::one('oauth_users', array('where' => array('id' => $id)));
         $one = (object) $one;
         \Yii::$app->cache->set($cacheId, $one, 86400 * 360 * 360);
     }
     return $one;
 }
示例#5
0
 public function findAll($params = null)
 {
     var_dump($params);
     if (!is_array($params)) {
         return DB::getInstance()->query('SELECT * FROM users');
         echo 'SELECT * FROM users';
     } else {
         echo 'SELECT * FROM users WHERE ' . $params[0] . ' = "' . $params[1] . '"';
         //return DB::getInstance()->query('SELECT * FROM users WHERE '.$params[0].' = ?', [$params[1]]);
     }
 }
示例#6
0
 function actionDisplay($id, $form)
 {
     $id = (int) $id;
     if ($id < 1) {
         exit;
     }
     $one = DB::one('comment', array('where' => array('id' => $id)));
     $display = $one['display'] == 1 ? 0 : 1;
     DB::update('comment', array('display' => $display), 'id=:id', array(':id' => $id));
     flash('success', __('sucessful'));
     $this->redirect(url('comment/site/index', array('form' => $form)));
 }
示例#7
0
 /**
  * Update model.
  *
  * @param int $id
  * @return bool
  */
 public function update($id)
 {
     $keys = array_keys($this->attributesValues);
     $preparedKeys = array_map(function ($key) {
         return $key . '=:' . $key;
     }, $keys);
     $preparedKeysString = implode(', ', $preparedKeys);
     $this->attributesValues[$this->primaryKey] = (int) $id;
     try {
         $query = $this->db->prepare('UPDATE ' . $this->table . ' SET ' . $preparedKeysString . ' ' . ' WHERE ' . $this->primaryKey . ' = :' . $this->primaryKey);
         $query->execute($this->attributesValues);
     } catch (PDOException $e) {
         Router::ErrorResponse('Invalid request.');
         die;
     }
 }
示例#8
0
 static function controller()
 {
     $value = Classes::get_config('module_host');
     if ($value == 1) {
         $all = DB::all('host');
         if (!$all) {
             return;
         }
         foreach ($all as $v) {
             $url = $v['url'];
             $redirect = $v['redirect'];
             $arr[$url] = $redirect;
         }
         $host = Str::new_replace(host(), array('http://' => '', 'https://' => ''));
         if ($arr[$host]) {
             redirect("http://" . $arr[$host] . $_SERVER['REQUEST_URI']);
         }
     }
 }
示例#9
0
 function member_get_third_set_user($me, $oauth_id, $token)
 {
     $me['email'] = $me['email'] ?: 'info';
     $uniqid = md5(uniqid(microtime()));
     if (!$me['id']) {
         flash('error', __('login failed'));
         $this->redirect(return_url());
     }
     $one = DB::one('oauth_users', array('where' => array('uid' => $me['id'], 'oauth_id' => $oauth_id)));
     if ($one) {
         DB::update('oauth_users', array('name' => $me['name'], 'email' => $me['email'], 'token' => $token, 'uuid' => $uniqid), "id=:id", array(':id' => $one['id']));
     } else {
         DB::insert('oauth_users', array('uid' => $me['id'], 'name' => $me['name'], 'email' => $me['email'], 'oauth_id' => $oauth_id, 'token' => $token, 'uuid' => $uniqid));
     }
     $one = DB::one('oauth_users', array('where' => array('uuid' => $uniqid, 'oauth_id' => $oauth_id)));
     if ($one) {
         $value = array('id' => $one['id'], 'name' => $one['name'], 'email' => $one['email'], 'oauth' => true);
         cookie('user', json_encode($value), 0);
     }
 }
示例#10
0
 /**
  * 用户组绑定权限
  */
 public function actionIndex($id)
 {
     $id = (int) $id;
     $model = \app\modules\auth\models\Group::find($id);
     foreach ($model->access as $g) {
         $access[] = $g->access_id;
     }
     $d = $this->_get_modules();
     Access::generate($d);
     $rows = DB::all('auth_access', array('select' => "id,name,pid"));
     foreach ($rows as $v) {
         $out[$v['id']] = $v;
     }
     $rows = Arr::_tree_id($rows);
     if ($_POST) {
         $auth = $_POST['auth'];
         GroupAccess::saveAccess($id, $auth);
         flash('success', __('set access success'));
         redirect(url('auth/auth/index', array('id' => $id)));
     }
     echo $this->render('index', array('rows' => $rows, 'out' => $out, 'model' => $model, 'id' => $id, 'access' => $access));
 }
示例#11
0
 /**
  * 过滤字段
  */
 static function filter()
 {
     $all = DB::all('comment_filter');
     if (!$all) {
         return array();
     }
     foreach ($all as $v) {
         $row[$v['name']] = $v['replace'] ?: '*';
     }
     return $row;
 }
示例#12
0
 function run()
 {
     $rows = DB::all('oauth_config', array('orderBy' => 'sort desc,id desc', 'where' => array('display' => 1)));
     echo $this->render('@app/modules/oauth/widget/views/login', array('rows' => $rows, 'img' => $this->img));
 }
示例#13
0
 function run()
 {
     $this->formId = 'pagination.' . $this->formId;
     $rows = DB::pagination('comment', array('where' => array('slug_id' => Classes::one($this->slug), 'display' => $this->display), 'orderBy' => 'sort desc,id desc'), 'comment/ajax/index');
     echo $this->render('@app/modules/comment/widget/views/pagination', array('rows' => $rows, 'formId' => $this->formId));
 }
示例#14
0
 /**
  * delete the current model from database based on primary key value
  * @return boolean
  */
 public function delete()
 {
     if (!isset($this->{$this->primary})) {
         throw new \InvalidArgumentException("No value found for key {$this->primary}");
     }
     $this->sqlDelete = str_replace(['{delete}', '{primary}'], [$this->table, $this->primary], $this->sqlDelete);
     $this->pdo = DB::getInstance();
     $stmt = $this->pdo->prepare($this->sqlDelete);
     $stmt->bindParam(':primary', $this->{$this->primary}, $this->pdoType(gettype($this->{$this->primary})));
     $return = $stmt->execute();
     $this->errorInfo = $stmt->errorInfo();
     return $return;
 }