one() public method

Executes the query and returns a single row of result.
public one ( Connection $db = null ) : array | boolean
$db Connection the Mongo connection used to execute the query. If this parameter is not given, the `mongodb` application component will be used.
return array | boolean the first row (in terms of an array) of the query result. False is returned if the query results in nothing.
Exemplo n.º 1
0
 public function actionCheck_login()
 {
     $username = $_POST['username'];
     $pwd = $_POST['pwd'];
     $query = new Query();
     $query->select(['name', 'status', 'password'])->from('admin')->where(['name' => $username]);
     $arr = $query->one();
     if ($arr) {
         if ($arr['password'] == md5($pwd)) {
             $_SESSION['user_id'] = $arr['_id'];
             $_SESSION['user_name'] = $arr['name'];
             if ($arr['name'] != "admin") {
                 $userid = $arr['_id'];
                 //根据用户id查找用户的角色ID
                 $query->select(['role_id'])->from('user_role')->where(['user_id' => "{$userid}"]);
                 $res = $query->one();
                 $role_id = $res['role_id'];
                 //根据角色ID查询所有权限ID,将其ID存入字符串中
                 $q = new Query();
                 $q->select(['node_id'])->from('role_node')->where(['role_id' => $role_id]);
                 $ar = $q->all();
                 $que = new Query();
                 foreach ($ar as $key => $v) {
                     // $node[$key] = $v['node_id'];
                     $idd = $v['node_id'];
                     $que->select(['n_name', 'nickname', 'n_level', 'p_id'])->from('node')->where(['_id' => "{$idd}"])->andwhere(['n_level' => "1"]);
                     $quan[$key] = $que->all();
                 }
                 $yi_quan = array_filter($quan);
                 $_SESSION['yi_quan'] = $yi_quan;
                 $quee = new Query();
                 foreach ($ar as $kk => $vv) {
                     // $node[$key] = $v['node_id'];
                     $iddd = $vv['node_id'];
                     $quee->select(['n_name', 'nickname', 'n_level', 'p_id'])->from('node')->where(['_id' => "{$iddd}"])->andwhere(['n_level' => "2"]);
                     $quanx[$kk] = $quee->all();
                 }
                 $er_quan = array_filter($quanx);
                 $_SESSION['er_quan'] = $er_quan;
             } else {
                 $que = new Query();
                 $que->select(['n_name', 'nickname', 'n_level', 'p_id'])->from('node')->where(['n_level' => "1"]);
                 $yi_quan = $que->all();
                 $_SESSION['yi_q'] = $yi_quan;
                 $quee = new Query();
                 $quee->select(['n_name', 'nickname', 'n_level', 'p_id'])->from('node')->where(['n_level' => "2"]);
                 $er_quan = $quee->all();
                 $_SESSION['er_q'] = $er_quan;
             }
             echo "<script>location.href='index.php?r=site/index'</script>";
         } else {
             echo "<script>alert('密码错误');location.href='index.php?r=public/login'</script>";
         }
     } else {
         echo "<script>alert('用户名或密码错误');location.href='index.php?r=public/login'</script>";
     }
 }
Exemplo n.º 2
0
 public function actionXiugai()
 {
     $id = $_GET['id'];
     $query = new Query();
     $query->select(['email', 'name', 'status'])->from('admin')->where(['_id' => $id]);
     $rows = $query->one();
     return $this->renderPartial('save', compact('rows'));
 }
Exemplo n.º 3
0
 public function actionXiugai()
 {
     $id = $_GET['id'];
     $query = new Query();
     $query->select(['n_name', 'nickname', 'n_level'])->from('node')->where(['_id' => $id]);
     $rows = $query->one();
     return $this->renderPartial('save', compact('rows'));
 }
Exemplo n.º 4
0
 static function GetUserFormsById($id)
 {
     $query = new Query();
     // compose the query
     $query->select(['data'])->from('forms')->where(['_id' => $id]);
     // execute the query
     $row = $query->one();
     return $row;
 }
Exemplo n.º 5
0
 /**
  * @inheritdoc
  */
 public function one($db = null)
 {
     $row = parent::one($db);
     if ($row !== false) {
         $models = $this->populate([$row]);
         return reset($models) ?: null;
     } else {
         return null;
     }
 }
Exemplo n.º 6
0
 public function actionEdit()
 {
     $id = $_GET['id'];
     $query = new Query();
     $query->select(['type_name', 'level', 'p_id'])->from('type')->where(['_id' => $id]);
     $data['rows'] = $query->one();
     $query->select(['type_name', 'level', 'p_id'])->from('type')->where(['p_id' => '0']);
     $data['arr'] = $query->all();
     return $this->renderPartial("edit", $data);
 }
Exemplo n.º 7
0
 private function formatCookbookForAPI($cookbook)
 {
     //averageScore
     if (!isset($cookbook['averageScore'])) {
         $cookbook['averageScore'] = 0.0;
     }
     //isNewest
     for ($i = 0; $i < count($cookbook['type']); $i++) {
         if ($cookbook['type'][$i] == '最新食譜') {
             $cookbook['isNewest'] = 'Y';
         } else {
             $cookbook['isNewest'] = 'N';
         }
     }
     //collection number
     $cookbookId = $cookbook['cookbookId'];
     $query = new Query();
     $query->from('uhkklpUserCookbook')->where(['cookbookId' => $cookbookId])->andWhere(['collection' => 'Y']);
     $collectionNumber = $query->count();
     $cookbook['collectionNumber'] = $collectionNumber;
     //score number
     $cookbookId = $cookbook['cookbookId'];
     $query = new Query();
     $query->from('uhkklpUserCookbook')->where(['cookbookId' => $cookbookId]);
     $scorerNumber = $query->count();
     $cookbook['scorerNumber'] = $scorerNumber;
     //sample
     $sample = $cookbook['sample'];
     for ($j = 0; $j < count($sample); $j++) {
         $querySample = new Query();
         $querySample->from('uhkklpSample')->where(['_id' => $sample[$j]['id']]);
         $sampleDate = $querySample->one();
         $cookbook['sample'][$j]['imgUrl'] = $sampleDate['imgUrl'];
         $cookbook['sample'][$j]['explain'] = $sampleDate['quantity'];
         unset($cookbook['sample'][$j]['quantity']);
     }
     return $cookbook;
 }
Exemplo n.º 8
0
 public function actionAddrole_node()
 {
     $role_id = $_POST['role_id'];
     $quan_id = $_POST['quanxian'];
     $query = new Query();
     $query->select(['_id'])->from('role_node')->where(['node_id' => $quan_id]);
     $ar = $query->one();
     $collection = Yii::$app->mongodb->getCollection('role_node');
     if (empty($ar)) {
         $res = $collection->insert(['role_id' => $role_id, 'node_id' => $quan_id, 'pid' => 0, 'level' => 1]);
     }
     @($s_id = $_POST['s_id']);
     if (empty($s_id)) {
         if ($res) {
             echo "<script>alert('权限分配成功');location.href='index.php?r=role/role_list';</script>";
         } else {
             echo "<script>alert('权限分配失败~~');location.href='index.php?r=role/add';</script>";
         }
     } else {
         $que = new Query();
         $que->select(['_id'])->from('role_node')->where(['node_id' => $s_id]);
         $arr = $que->one();
         if ($arr) {
             echo "<script>alert('二级权限已存在,请从新添加~~');location.href='index.php?r=role/role_list';</script>";
         } else {
             $data = $collection->insert(['role_id' => $role_id, 'node_id' => $s_id, 'pid' => $quan_id, 'level' => 2]);
             if ($data) {
                 echo "<script>alert('权限分配成功');location.href='index.php?r=role/role_list';</script>";
             } else {
                 echo "<script>alert('权限分配失败~~');location.href='index.php?r=role/add';</script>";
             }
         }
     }
 }
Exemplo n.º 9
0
 /**
  * Executes query and returns a single row of result.
  * @param Connection $db the Mongo connection used to execute the query.
  * If null, the Mongo connection returned by [[modelClass]] will be used.
  * @return ActiveRecord|array|null a single row of query result. Depending on the setting of [[asArray]],
  * the query result may be either an array or an ActiveRecord object. Null will be returned
  * if the query results in nothing.
  */
 public function one($db = null)
 {
     $row = parent::one($db);
     if ($row !== false) {
         if ($this->asArray) {
             $model = $row;
         } else {
             /* @var $class ActiveRecord */
             $class = $this->modelClass;
             $model = $class::instantiate($row);
             $class::populateRecord($model, $row);
         }
         if (!empty($this->with)) {
             $models = [$model];
             $this->findWith($this->with, $models);
             $model = $models[0];
         }
         if (!$this->asArray) {
             $model->afterFind();
         }
         return $model;
     } else {
         return null;
     }
 }
Exemplo n.º 10
0
 public function actionGetById()
 {
     $cookingtypeId = Yii::$app->request->get('cookingtypeId', '');
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     if ($cookingtypeId != '') {
         $query = new Query();
         $query->from('uhkklpCookingtype')->where(['_id' => $cookingtypeId]);
         $cookingType = $query->one();
         return ['code' => 200, 'msg' => 'OK', 'result' => $this->formatCookingType($cookingType)];
     }
     return ['code' => 1204, 'msg' => 'Type is not exist'];
 }
Exemplo n.º 11
0
 public function actionGetById()
 {
     $sampleId = Yii::$app->request->get('sampleId', '');
     $query = new Query();
     $query->from('uhkklpSample')->where(['_id' => $sampleId]);
     $sample = $query->one();
     Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['code' => 200, 'msg' => 'OK', 'result' => $sample];
 }
Exemplo n.º 12
0
 public function actionSec_save()
 {
     $id = $_GET['id'];
     $query = new Query();
     $query->select(['z_name', 'z_introduce', 'parent_id', 'z_content', 'practice_type'])->from('chapter_class')->where(["_id" => $id]);
     $rows = $query->one();
     $que = new Query();
     $que->select(['cha_name', 'lecturer'])->from('goods_class');
     $data = $que->all();
     return $this->renderPartial("sec_save", ['rows' => $rows, 'data' => $data]);
 }
Exemplo n.º 13
0
 public function actionJob_save()
 {
     $request = Yii::$app->request;
     $id = $request->get('id');
     $query = new Query();
     $query->select(['j_name', 'add_time'])->from('work_direction')->where(['_id' => $id]);
     $arr = $query->one();
     //print_r($res);die;
     return $this->renderPartial('job_save', compact('arr'));
 }