public function update()
 {
     if ($this->provinceId == "" || $this->majorJobId == "") {
         CommonFunctions::createAlertMessage("省份或者专业类型不能为空", "error");
         return false;
     }
     $user = Yii::$app->session->get('user');
     $majorJob = MajorJob::findOne($this->majorJobId);
     if ($this->provinceId != $majorJob['provinceId']) {
         CommonFunctions::createAlertMessage("专业类型与所处省份不一致,请重新选择", "error");
         return false;
     }
     //修改省份或专业岗位,需要清除用户的在线练习相关信息
     if ($this->provinceId != $user['provinceId'] || $this->majorJobId != $user['majorJobId']) {
         CurrentTestLibrary::deleteAll(['userId' => $user['userId']]);
         //删除当前记录
         ErrorQuestion::deleteAll(['userId' => $user['userId']]);
         //删除错题记录
         Collection::deleteAll(['userId' => $user['userId']]);
         //删除收藏
     }
     /** @var $user \common\models\Users */
     $user = Users::findOne($user['userId']);
     $user->nickname = $this->nickname;
     $user->realname = $this->realname;
     $user->provinceId = $this->provinceId;
     $user->majorJobId = $this->majorJobId;
     $user->company = $this->company;
     $user->address = $this->address;
     if (!$user->save()) {
         throw new Exception("UpdateInfoForm update Save Error");
     }
     Yii::$app->session->set('user', $user);
     return true;
 }
Example #2
0
 /**
  * 保存或删除一个收藏
  * @param $userId
  * @param $testLibraryId
  * @return string
  * @throws Exception
  * @throws \Exception
  */
 public static function saveOrDelete($userId, $testLibraryId)
 {
     $collection = Collection::find()->where(['userId' => $userId, 'testLibraryId' => $testLibraryId])->one();
     if ($collection) {
         if (!$collection->delete()) {
             throw new Exception("Collection delete error");
         }
         return "delete";
     } else {
         $collection = new Collection();
         $collection->userId = $userId;
         $collection->testLibraryId = $testLibraryId;
         $collection->createDate = DateFunctions::getCurrentDate();
         if (!$collection->save()) {
             throw new Exception("Collection save error");
         }
         return "collected";
     }
 }
 public function actionManage($id)
 {
     \yii::$app->jsconfig->addData('searchUri', Url::to(['ajax/searchusers']));
     \yii::$app->jsconfig->addData('memberTargetId', '#member-select');
     \yii::$app->jsconfig->addData('managerTargetId', '#manager-select');
     \yii::$app->jsconfig->addData('collectionId', $id);
     \yii::$app->jsconfig->addData('addUri', Url::to(['ajax/adduser']));
     \yii::$app->jsconfig->addData('removeUri', Url::to(['ajax/removeuser']));
     \yii::$app->jsconfig->addData('memberType', Types::$member_type['member']['id']);
     \yii::$app->jsconfig->addData('managerType', Types::$member_type['manager']['id']);
     $collectionModel = Collection::findOne($id);
     if ($collectionModel === null) {
         throw new \yii\web\HttpException(404, yii::t('app', 'Cannot find collection.'));
     }
     return $this->render('manage', ['collectionModel' => $collectionModel]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Collection::find();
     // add conditions that should always apply here
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     // grid filtering conditions
     $query->andFilterWhere(['id' => $this->id, 'collection_type_id' => $this->collection_type_id, 'public_option_id' => $this->public_option_id, 'membership_duration' => $this->membership_duration, 'member_count' => $this->member_count, 'manager_count' => $this->manager_count, 'sort_order' => $this->sort_order, 'status_id' => $this->status_id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at, 'created_by' => $this->created_by, 'updated_by' => $this->updated_by]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'alias', $this->alias])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCollection()
 {
     return $this->hasOne(Collection::className(), ['id' => 'collection_id']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCollections()
 {
     return $this->hasMany(Collection::className(), ['collection_type_id' => 'id']);
 }
Example #7
0
 public function getProjects()
 {
     return $this->hasMany(Collection::className(), ['id' => 'id']);
 }
 /**
  * Finds the Collection model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Collection the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Collection::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * 收藏
  * @return string
  * @throws Exception
  */
 public function actionCollection()
 {
     $request = Yii::$app->request;
     if ($request->isAjax) {
         $session = Yii::$app->session;
         $testLibraryId = $request->post('testLibraryId');
         $user = $session->get('user');
         return Collection::saveOrDelete($user['userId'], $testLibraryId);
     } else {
         throw new Exception("非法提交");
     }
 }