function question_model_test($delete)
{
    include_once "page_model.php";
    $qa_pairs = array("question" => "where would you like to go?", "answers" => array("1" => "left", "2" => "right", "3" => "south"));
    $question = new QuestionModel(PageModel::first()->id, serialize($qa_pairs), date("Y-m-d H:i:s"));
    $question->save();
    $question->print_fields();
    $qa_pairs = array("question" => "Will you open the door?", "answers" => array("1" => "yes", "2" => "no"));
    $question->set("q_and_a", serialize($qa_pairs));
    $question->save();
    $question->print_fields();
    if ($delete) {
        $question->delete();
    }
    $qm = QuestionModel::find(QuestionModel::last()->id);
    $qm->print_fields();
    QuestionModel::find(999);
}
예제 #2
0
 public function actionAdd()
 {
     $model = new QuestionModel();
     $msg = '';
     if (!empty($_POST['QuestionModel'])) {
         $model->attributes = $_POST['QuestionModel'];
         if ($model->validate()) {
             $model->user_id = Yii::app()->user->getId();
             $model->save();
             $msg = 'Спасибо за Ваш вопрос. Стоимость вопроса ' . $model->getCost();
         }
     }
     $this->render('add', ['model' => $model, 'msg' => $msg]);
 }
예제 #3
0
 public function actionAdd()
 {
     if (Yii::app()->user->isGuest) {
         Yii::app()->user->setFlash('error', 'Вопрос может задать только зарегестрированный пользователь');
         $this->redirect($this->createUrl('site/index'));
     }
     $model = new QuestionModel();
     $model->setScenario('insert');
     $user = UserModel::model()->findByPk(Yii::app()->user->id);
     $text = null;
     if (!empty($_POST['QuestionModel'])) {
         if (isset($_POST['QuestionModel']['cost'])) {
             if ($user->balance < $_POST['QuestionModel']['cost']) {
                 Yii::app()->user->setFlash('error', 'Недостаточно средств, пожалуйсто пополните счет');
                 $this->refresh();
             }
         }
         $model->attributes = $_POST['QuestionModel'];
         $model->status = QuestionModel::STATUS_NEW;
         $model->user_id = Yii::app()->user->getId();
         if ($_POST['QuestionModel']['type'] == 'free') {
             $model->setScenario('free');
             Yii::app()->user->setFlash('success', 'Спасибо за Ваш вопрос');
         }
         if ($model->save()) {
             if ($_POST['QuestionModel']['type'] == 'pay') {
                 $user->balance = $user->balance - $_POST['QuestionModel']['cost'];
                 $user->save(false);
                 Yii::app()->user->setFlash('success', 'Спасибо за Ваш вопрос была снята сумма ' . $model->cost . ' руб');
             }
             $userQuestion = new UserQuestion();
             $userQuestion->attributes = $_POST['UserQuestion'];
             $userQuestion->email = $user->email;
             $userQuestion->question_id = $model->id;
             $userQuestion->save();
         }
     }
     $this->render('add', ['model' => $model]);
 }
예제 #4
0
 /**
  * Update any disable rules associated with this response.
  */
 private function updateDisableRules()
 {
     if (!isset($this->parent)) {
         $this->parent = new QuestionModel(array('questionID' => $this->responseRow->questionID, 'depth' => 'question'));
     }
     $question = $this->parent;
     foreach ($question->prompts as $prompt) {
         foreach ($prompt['rules'] as $rule) {
             if ($prompt['promptID'] == $this->responseText) {
                 if ($rule->enabled != 'Y') {
                     $rule->enabled = 'Y';
                     $rule->save();
                     if (preg_match('/.+Page$/', $rule->type)) {
                         $page = new PageModel(array('pageID' => $rule->targetID, 'depth' => 'question'));
                         $page->save();
                     } elseif (preg_match('/.+Section$/', $rule->type)) {
                         $section = new SectionModel(array('sectionID' => $rule->targetID, 'depth' => 'question'));
                         $section->save();
                     } elseif (preg_match('/.+Question$/', $rule->type)) {
                         $question = new QuestionModel(array('questionID' => $rule->targetID, 'depth' => 'question'));
                         $question->save();
                     }
                 }
             } else {
                 if ($rule->enabled != 'N') {
                     $rule->enabled = 'N';
                     $rule->save();
                     if (preg_match('/.+Page$/', $rule->type)) {
                         $page = new PageModel(array('pageID' => $rule->targetID, 'depth' => 'question'));
                         $page->save();
                     } elseif (preg_match('/.+Section$/', $rule->type)) {
                         $section = new SectionModel(array('sectionID' => $rule->targetID, 'depth' => 'question'));
                         $section->save();
                     } elseif (preg_match('/.+Question$/', $rule->type)) {
                         $question = new QuestionModel(array('questionID' => $rule->targetID, 'depth' => 'question'));
                         $question->save();
                     }
                 }
             }
         }
     }
 }
예제 #5
0
 public function AnswerDeleteAction()
 {
     $request = Project::getRequest();
     $request_user_id = (int) Project::getUser()->getShowedUser()->id;
     $user_id = (int) Project::getUser()->getDbUser()->id;
     $question_id = $request->getKeyByNumber(0);
     $answer_id = $request->getKeyByNumber(1);
     $answer_model = new AnswerModel($answer_id);
     $question_model = new QuestionModel();
     $question_model->load($question_id);
     if ($answer_model->id > 0 && $question_model->id > 0 && $answer_model->question_id == $question_model->id) {
         if ($answer_model->user_id == $user_id || $question_model->user_id == $user_id) {
             $answer_model->delete($answer_model->user_id, $answer_id);
             $question_model->a_count--;
             $question_model->save();
         }
     }
     Project::getResponse()->redirect($request->createUrl('QuestionAnswer', 'ViewQuestion', array($question_model->id)));
 }
 public function EditQuestionAction()
 {
     $request = Project::getRequest();
     $id = $request->getKeyByNumber(0);
     $data = array();
     if (!$request->getKeyByNumber(1)) {
         if ($id > 0) {
             $model = new QuestionModel();
             $cat_model = new QuestionCatModel();
             $tag_model = new QuestionTagModel();
             $data['question'] = $model->load($id);
             $data['cat_list'] = $cat_model->loadAll();
             $tags_model = new QuestionTagModel();
             $tags = $tags_model->loadWhere(null, null, $id);
             foreach ($tags as $tag) {
                 $data['tags'] .= $tag['name'] . ', ';
             }
             $data['tags'] = rtrim($data['tags'], ', ');
             $this->BaseAdminData();
             $this->_view->EditQuestion($data);
             $this->_view->ajax();
         }
     } else {
         if ($id > 0) {
             $model = new QuestionModel();
             $model->load($id);
             $model->q_text = $request->question_text;
             $model->questions_cat_id = (int) $request->cat_id;
             $id = $model->save();
             $tag_model = new QuestionTagModel();
             $question_tag_model = new QTagModel();
             $tags_ar = array();
             $tags_ar = explode(",", $request->tags);
             foreach ($tags_ar as $tag) {
                 $tag = trim($tag);
                 if (count($tag_model->loadByName($tag)) > 0) {
                     if (count($question_tag_model->loadWhere($id, $tag_model->id)) <= 0) {
                         $question_tag_model->question_id = $id;
                         $question_tag_model->question_tag_id = $tag_model->id;
                         $question_tag_model->save();
                         $question_tag_model->clear();
                     }
                 } else {
                     $tag_model->name = $tag;
                     $tag_id = $tag_model->save();
                     $tag_model->clear();
                     $question_tag_model->question_id = $id;
                     $question_tag_model->question_tag_id = $tag_id;
                     $question_tag_model->save();
                     $question_tag_model->clear();
                 }
             }
         }
         Project::getResponse()->Redirect($request->createUrl('AdminQuestionAnswer', 'QuestionList'));
     }
 }