public function update()
 {
     /** @var $testLibrary \common\models\TestLibrary */
     $testLibrary = TestLibrary::findOne($this->testLibraryId);
     $testLibrary->problem = $this->problem;
     $testLibrary->question = $this->question;
     $testLibrary->options = $this->options;
     $testLibrary->answer = $this->answer;
     $testLibrary->createDate = DateFunctions::getCurrentDate();
     $user = \Yii::$app->session->get('user');
     $testLibrary->createUserId = $user['userId'];
     if (!$testLibrary->update()) {
         throw new Exception("UpdateTestLibraryForm update error");
     }
 }
Example #2
0
 /**
  * 根据用户判断用户所在的省份和专业是否有题目,缓存24小时、依赖题库数量的变化
  * @param $user
  * @return bool
  */
 public static function checkIsExist($user)
 {
     $dependency = new DbDependency(['sql' => 'select count(*) from testLibrary']);
     $result = TestLibrary::getDb()->cache(function () use($user) {
         return TestLibrary::findOne(['provinceId' => $user['provinceId'], 'majorJobId' => $user['majorJobId']]);
     }, 24 * 3600, $dependency);
     if ($result) {
         return true;
     }
     return false;
 }