/** * @covers Screen::tableName * @todo Implement testTableName(). */ public function testTableName() { $this->assertEquals('tbl_user', $this->object->tableName()); }
public static function getOrmUsers($arr = array()) { $result = self::$_allUsers; if ($result !== null && !$arr) { return $result; } if (!$arr) { $cacheID = "all_users_by_user_id"; $result = AF::cache()->get($cacheID); } if (!$result || $arr) { $user = new User(); $where = ''; if ($arr) { $arr = array_unique($arr); $where = self::$_msql->parse(" WHERE user_id IN (?a)", $arr); } $sql = "SELECT *\n FROM ?n\n {$where}\n ORDER BY `user_id` DESC"; $result = self::$_msql->getInd('user_id', $sql, $user->tableName()); if (!$arr) { self::$_allUsers = $result; AF::cache()->set($cacheID, self::$_allUsers); } } return $result; }
public function testChangeColumn() { $user = new User(); $this->_conn->addColumn('users', 'age', 'integer'); $oldColumns = $this->_conn->columns($user->tableName(), "User Columns"); $found = false; foreach ($oldColumns as $c) { if ($c->getName() == 'age' && $c->getType() == 'integer') { $found = true; } } $this->assertTrue($found); $this->_conn->changeColumn('users', 'age', 'string'); $newColumns = $this->_conn->columns($user->tableName(), "User Columns"); $found = false; foreach ($newColumns as $c) { if ($c->getName() == 'age' && $c->getType() == 'integer') { $found = true; } } $this->assertFalse($found); $found = false; foreach ($newColumns as $c) { if ($c->getName() == 'age' && $c->getType() == 'string') { $found = true; } } $this->assertTrue($found); $found = false; foreach ($oldColumns as $c) { if ($c->getName() == 'approved' && $c->getType() == 'boolean' && $c->getDefault() == true) { $found = true; } } $this->assertTrue($found); // changeColumn() throws exception on error $this->_conn->changeColumn('users', 'approved', 'boolean', array('default' => false)); $newColumns = $this->_conn->columns($user->tableName(), "User Columns"); $found = false; foreach ($newColumns as $c) { if ($c->getName() == 'approved' && $c->getType() == 'boolean' && $c->getDefault() == true) { $found = true; } } $this->assertFalse($found); $found = false; foreach ($newColumns as $c) { if ($c->getName() == 'approved' && $c->getType() == 'boolean' && $c->getDefault() == false) { $found = true; } } $this->assertTrue($found); // changeColumn() throws exception on error $this->_conn->changeColumn('users', 'approved', 'boolean', array('default' => true)); }
/** * @return array user list. */ public function user_list($val = null) { $connection = Yii::app()->db; $table = User::tableName(); $sql = "SELECT id,user_code FROM `{$table}` where valid=1 ORDER BY id DESC"; $command = $connection->createCommand($sql); $result = $command->queryAll(); foreach ($result as $value) { $array[$value['id']] = $value['user_code']; } //$array = array('1'=>'全新','2'=>'使用过-很新','3'=>'使用过-较好','4'=>'使用过-较旧'); if ($val) { return $array[$val]; } else { return $array; } }
public function cacheDependencies() { return array(array('class' => 'system.caching.dependencies.CDbCacheDependency', 'sql' => 'SELECT CONCAT(MAX(`create`),MAX(`modify`)) FROM `' . User::tableName() . '`')); }
public function User($dbObj = null, $tableName = 'user') { self::$dbObj = $dbObj; self::$tableName = $tableName; }