예제 #1
0
 /**
  * 
  * @param int $course_id
  * @return \APP\Module\Course\DataRow\Course
  */
 public function get($course_id)
 {
     $dbal = DBAL::select('courses');
     $dbal->setDataRowClass('\\APP\\Module\\Course\\DataRow\\Course');
     $dbal->byId($course_id);
     return $dbal->getOne();
 }
 public function loadDetails($uid)
 {
     $dbal = DBAL::select('default.user');
     $dbal->setDataRowClass('\\APP\\Module\\Test\\DataRow\\Test');
     $dbal->byId($uid);
     $rs = $dbal->getOne();
     $this->set('Details', $rs);
 }
 public function loadUsers($page)
 {
     $dbal = DBAL::select('user');
     $dbal->setPage($page, '2');
     $dbal->setDataRowClass('\\APP\\Module\\Test\\DataRow\\Test');
     $list = $dbal->execute();
     $pagination = new Pagination($list, $dbal->getTotalCount(), $page, 2);
     $this->set('list', $list);
     $this->set('patgination', $pagination);
 }
 public static function getAllPermissions()
 {
     static $permissions;
     if (!isset($permissions)) {
         $permissions = array();
         $result = DBAL::select(DB::getPermissionTableName())->execute();
         foreach ($result as $dataRow) {
             $permissions[$dataRow->get('role_id')] = explode(',', $dataRow['permissions']);
         }
     }
     return $permissions;
 }
예제 #5
0
 /**
  * @return \ORC\App\User\Roles
  */
 public static function getAllRoles()
 {
     static $roles;
     if (!isset($roles)) {
         $roles = new self();
         $dbal = DBAL::select(DB::getRoleTableName());
         $result = $dbal->execute();
         foreach ($result as $row) {
             $role = new Role($row);
             //$this->_roles[$role->getId()] = $role;
             $roles[$role->getId()] = $role;
         }
     }
     return $roles;
 }
예제 #6
0
 public function __invoke($cacher, $key, &$value)
 {
     $expiration = $this->getCacheExpiration();
     $pk = $this->_table->getPrimaryKey();
     $dbal = DBAL::select($this->_table);
     $dbal->setSelect($pk);
     if ($this->_order_by) {
         $dbal->orderBy($this->_order_by);
     }
     $value = $dbal->execute()->getByName($pk);
     if ($expiration) {
         $cacher->set($key, $value, $expiration);
         return false;
     }
     return true;
 }
 protected function start()
 {
     if ($this->started()) {
         return true;
     }
     $dbal = DBAL::select($this->table);
     $dbal->bySessionId($this->getId());
     $row = $dbal->getOne();
     if ($row) {
         $data = @unserialize(gzuncompress($row['value']));
         if (is_array($data)) {
             $this->_data = $data;
         }
     }
     $this->session_started = true;
 }
예제 #8
0
 public function __invoke(ICacher $cacher, array $keys, array &$values)
 {
     $expiration = $this->getCacheExpiration();
     $dbal = DBAL::select($this->_table);
     $dbal->pk($keys);
     if ($this->_row_classname) {
         $dbal->setDataRowClass($this->_row_classname);
     }
     $values = $dbal->execute()->toArray($this->_table->getPrimaryKey());
     foreach ($keys as $key) {
         if (!isset($values[$key])) {
             $values[$key] = ICacher::EMPTY_VALUE;
         }
     }
     if ($expiration) {
         $cacher->setMult($values, $expiration);
         return false;
     }
     return true;
 }
예제 #9
0
 /**
  * 
  * @param string $table_name
  * @param bool $cache
  * @return \ORC\DAO\Table\DataList
  */
 public static function getTableData($table_name, $cache = true)
 {
     if ($cache) {
         $cacheKey = sprintf('table_%s', $table_name);
         $cacher = CacheFactory::get(null, 'db');
         $data = $cacher->get($cacheKey);
         if (is_object($data)) {
             return $data;
         }
         if (@strcmp($data, ICacher::EMPTY_VALUE) == 0) {
             return new DataList(array(), new Table($table_name));
         }
     }
     $dbal = DBAL::select($table_name);
     $list = $dbal->execute();
     if ($cache) {
         if ($list) {
             $cacher->set($cacheKey, $list);
         } else {
             $cacher->set($cacheKey, ICacher::EMPTY_VALUE);
         }
     }
     return $list;
 }
예제 #10
0
 private function getRoles()
 {
     //read the role from table every time to make sure it's correct
     static $roles;
     if (isset($roles)) {
         return $roles;
     }
     $dbal = DBAL::select('admin_user_roles');
     $dbal->byUserId($this->getId());
     $roles = $dbal->execute()->getByName('role_id');
     return $roles;
 }
예제 #11
0
 public function getAllKnowledgePoints()
 {
     $catalogs = $this->getCatalogs();
     $catalog_ids = $catalogs->getByName('id');
     $dbal = DBAL::select('course_catalog_kps');
     $dbal->byCourseCatalogId($catalog_ids);
     $list = $dbal->execute();
     $list->groupBy('course_catalog_id');
 }
예제 #12
0
 public function autoLogin($id)
 {
     $this->flushRoles();
     $dbal = DBAL::select(DB::getUserTableName())->pk($id);
     $result = $dbal->getOne();
     if ($result instanceof \ORC\DAO\Table\DataRow) {
         $this->_data = $result->getAllData();
         return true;
     }
     return false;
 }
 public function execute()
 {
     $request = $this->getRequest();
     //注意!为了演示dao和dbal的用法,把所有代码放在这里,但实际上要利用model
     switch ($request->get('action')) {
         case 'add':
             return $this->HTMLView('DB.Add');
             break;
         case 'save':
             $key1 = $request->get('key1');
             $key2 = $request->get('key2');
             $dbal = DBAL::insert('test');
             $dbal->set('key1', $key1);
             $dbal->set('key_2', $key2);
             //$dbal->setKey2($key2);//两种写法都可以,推荐用上面的
             $id = $dbal->execute();
             return $this->HTMLRedirect($this->generateURL('DB.Demo'), '保存成功', '页面保存成功');
             break;
         case 'view2':
             //利用key2作为主键
             $key2 = $request->get(0, 'safe', '');
             //注意request的get的用法
             $dao = DaoFactory::get('default');
             //得到一个default的dao,也可以使用dbal的getDao方法
             $dao->beginTransaction();
             //开始一个事务, 注意这里select没有加锁(select for update)
             $dbal = DBAL::select('default.test');
             //default是配置文件里的server name,不是database name
             $dbal->setDataRowClass('\\APP\\Module\\Test\\DataRow\\Test');
             //指定datarow class,否则使用ORC\DAO\Table\DataRow
             $dbal->byKey2($key2);
             //注意虽然在数据库中字段是key_2,这里不要有_
             $row = $dbal->getOne();
             //给计数器加1
             $dbal = DBAL::update('test');
             $dbal->increase('count', 1);
             $dbal->execute();
             $dao->commit();
             //提交
             $model = $this->getModel('DB.Test');
             $model->set('record', $row);
             return $this->HTMLView('DB.ViewDemo');
             break;
         case 'view':
             $id = $request->get('id', 'posint', 0);
             $dbal = DBAL::select('default.test');
             //default是配置文件里的server name,不是database name
             $dbal->setDataRowClass('\\APP\\Module\\Test\\DataRow\\Test');
             //指定datarow class,否则使用ORC\DAO\Table\DataRow
             $dbal->byId($id);
             $result = $dbal->getOne();
             //直接得到一个DataRow,这里直接得到Test对象
             $model = $this->getModel('DB.Test');
             $model->set('record', $result);
             return $this->HTMLView('DB.ViewDemo');
             break;
         case 'list':
         default:
             $dbal = DBAL::select('test');
             //获得一个dbal select对象
             $dbal->setDataRowClass('\\APP\\Module\\Test\\DataRow\\Test');
             //指定datarow class,否则使用ORC\DAO\Table\DataRow
             $list = $dbal->execute();
             $model = $this->getModel('DB.Test');
             $model->set('list', $list);
             //如果要分页的话
             $dbal = DBAL::select('test');
             //获得一个dbal select对象
             $dbal->setDataRowClass('\\APP\\Module\\Test\\DataRow\\Test');
             //指定datarow class,否则使用ORC\DAO\Table\DataRow
             $dbal->setPage(1, 20);
             //第一页,每页20条
             $list = $dbal->execute();
             $pagination = new Pagination($list, $dbal->getTotalCount(), 1, 20);
             return $this->HTMLView('DB.List');
             break;
     }
 }