/** * 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."); } }
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)); } }
/** * 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']); } }
/** * 返回用户信息 * */ 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; }
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]]); } }
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))); }
/** * 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; } }
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']); } } }
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); } }
/** * 用户组绑定权限 */ 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)); }
/** * 过滤字段 */ static function filter() { $all = DB::all('comment_filter'); if (!$all) { return array(); } foreach ($all as $v) { $row[$v['name']] = $v['replace'] ?: '*'; } return $row; }
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)); }
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)); }
/** * 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; }