public function initialize() { parent::initialize(); $this->view->dbs = Db::find(); $this->view->currentDbId = $this->request->get('id'); $this->allowRoles(); }
/** * Extend ControllerBase initialize() */ public function initialize() { parent::initialize(); $this->view->dbs = Db::find(); //list all dbs in the left column $this->view->currentDbId = $this->request->get('id'); }
static function get_no_bind_users($wx_id) { $self_table = self::$table_name; $wx_connect_table = WxConnect::table(); $sql = "select {$self_table}.wx_openid from {$self_table}"; $sql .= " left join {$wx_connect_table}"; $sql .= " on {$self_table}.wx_openid = {$wx_connect_table}.wx_openid"; $sql .= " where {$self_table}.wx_id = '{$wx_id}'"; $sql .= " and {$self_table}.status = " . self::STATUS_YES; $sql .= " and {$wx_connect_table}.wx_openid is null"; return Db::find($sql); }
static function list_user($page, $size, $where = '') { if ($page < 1) { $page = 1; } if (strlen($where)) { $where = " where 1 and {$where}"; } $start = ($page - 1) * $size; $limit = "limit {$start}, {$size}"; $sql = "select user_id from " . self::table(); $sql .= " {$where} {$limit}"; $ret = Db::find($sql); return $ret; }
function calculate($ctx) { $where = 1; $where = "status = '" . Contract::STATUS_NEW . "'"; $real_data = RealData::get_cache(); $real_price = $real_data['amount']; $sql = "SELECT name, strike_amount, ask_amount,"; $sql .= " ({$real_price}*(1+0.1)-strike_amount)/ask_amount as level_10,"; $sql .= " ({$real_price}*(1+0.15)-strike_amount)/ask_amount as level_15,"; $sql .= " ({$real_price}*(1+0.20)-strike_amount)/ask_amount as level_20"; $sql .= " FROM " . Contract::table(); $sql .= " WHERE status = '" . Contract::STATUS_NEW . "'"; $sql .= "order by level_20 desc, level_15 desc, level_10 desc"; $ctx->ds = Db::find($sql); }
/** * Just like Db::finda() but will return an array of objects * * @param string $class * @param array $query * @param array $options * @return array **/ static function finda($class, $query = array(), $options = array()) { $collection = self::getCollection($class); $result = Db::find($collection, $query, $options); $objects = array(); foreach ($result as $data) { $objects[] = new $class($data); } return $objects; }
public function on_collaboration_handle_transactions($pars) { $colls = $pars['colls']; if (!is_array($colls)) { self::raiseError('Invalid data received.'); } $response = array(); $n = sizeof($colls); for ($i = 0; $i < $n; $i++) { $coll = explode('|', $colls[$i]); $document_id = Db::quote_literal($coll[0]); $collaborator_id = Db::quote_literal($coll[1]); $last_transid = Db::quote_literal($coll[2]); unset($coll[0]); unset($coll[1]); unset($coll[2]); $log = Db::quote_literal(str_replace('\\', '\\\\', implode('|', $coll))); $coll_response = array(); if (false !== ($res = Db::find("SELECT * FROM amy.coll_handle_transactions({$document_id}, {$collaborator_id}, {$last_transid}, '{$log}')"))) { while (false !== ($r = pg_fetch_assoc($res))) { $coll_response[] = $r; } } else { $coll_response = Db::last_error(); } $response[] = array('document_id' => $document_id, 'transactions' => $coll_response); } self::setResult($response); }
/** * @param Db object <code>$db</code>, array of strings <code>$cols</code>, string <code>$cond</code> * @return array of associative arrays; keys are column headings or null if zero rows returned */ public static function find(Db $db, $cols, $cond) { return $db->find($cols, $cond, self::$table); }
/** * Manage permission for an defined user */ public function permissionModalAction() { $db = Db::find(); $user = User::findById($this->request->get('id')); $this->view->dbm = $db; $this->view->user = $user; }
public function register($username, $password = null, $service = 'amy', $credentials = array()) { $username = Db::quote_literal($username); if ('' == trim($username)) { throw new Exception('Username cannot be empty.'); } $service = Db::quote_literal($service); $hashed_password = null == $password ? '' : md5($password); $q_data = array(); if (is_array($credentials)) { foreach (array('email', 'nickname', 'picture', 'bio') as $key) { $q_data[$key] = isset($credentials[$key]) ? Db::quote_literal($credentials[$key]) : ''; } } if (false === ($row = Db::find_first("SELECT * FROM amy.user_create('{$username}', '{$hashed_password}', '{$service}', '" . $q_data['email'] . "', '" . $q_data['nickname'] . "', '" . $q_data['picture'] . "', '" . $q_data['bio'] . "')"))) { throw new Exception("User registration failed: `" . Db::last_error() . "'."); } $this->load_user_info($row); try { $this->setup_support_dir(); } catch (Exception $e) { Db::find("SELECT amy.user_delete(" . $this->userId . ")"); throw new Exception($e->getMessage()); } return $this; }