当前位置: 首页>>代码示例>>PHP>>正文


PHP Question::validate方法代码示例

本文整理汇总了PHP中Question::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Question::validate方法的具体用法?PHP Question::validate怎么用?PHP Question::validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Question的用法示例。


在下文中一共展示了Question::validate方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: store

 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store($quiz_id)
 {
     try {
         DB::beginTransaction();
         $quiz = Quiz::find($quiz_id);
         foreach (Input::get('question') as $input_question) {
             $question_params = array("name" => $input_question['name']);
             $question_validator = Question::validate($question_params);
             if ($question_validator->fails()) {
                 throw new Exception("Question can't be saved");
             }
             $question = new Question($question_params);
             $question = $quiz->questions()->save($question);
             foreach ($input_question['options'] as $value) {
                 $option_params = array("name" => $value['name'], "is_correct" => array_key_exists("is_correct", $value) ? true : false);
                 $option_validator = Option::validate($option_params);
                 if ($option_validator->fails()) {
                     throw new Exception("Option can't be saved");
                 }
                 $option = new Option($option_params);
                 $option = $question->options()->save($option);
             }
         }
         DB::commit();
         return Redirect::to("quizzes/" . $quiz->id . '/questions');
     } catch (Exception $e) {
         DB::rollback();
         //throw new Exception($e);
         return Redirect::to('quizzes/' . $quiz->id . '/questions/create');
     }
 }
开发者ID:shankargiri,项目名称:Quantum-Vic-La-Trobe-L4,代码行数:36,代码来源:QuestionsController.php

示例2: actionCreate

 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $question = new Question();
     if (isset($_POST['Question'])) {
         $this->forcePostRequest();
         $_POST = Yii::app()->input->stripClean($_POST);
         $question->attributes = $_POST['Question'];
         $question->content->populateByForm();
         $question->post_type = "question";
         if ($question->validate()) {
             $question->save();
             if (isset($_POST['Tags'])) {
                 // Split tag string into array
                 $tags = explode(", ", $_POST['Tags']);
                 foreach ($tags as $tag) {
                     $tag = Tag::model()->firstOrCreate($tag);
                     $question_tag = new QuestionTag();
                     $question_tag->question_id = $question->id;
                     $question_tag->tag_id = $tag->id;
                     $question_tag->save();
                 }
             }
             $this->redirect($this->createUrl('//questionanswer/question/view', array('id' => $question->id)));
         }
     }
     $this->render('create', array('model' => $question));
 }
开发者ID:tejrajs,项目名称:humhub-modules-questionanswer,代码行数:31,代码来源:QuestionController.php

示例3: update

 /**
  * Update the specified resource in storage.
  * PUT /commonquestions/{id}
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $validator = Question::validate(Input::only('topic', 'description'));
     if ($validator->fails()) {
         return Redirect::to('/commonCreate')->withErrors($validator)->withInput(Input::all());
     } else {
         $question = Question::find($id);
         $question->topic = Input::get('topic');
         $question->description = Input::get('description');
         if ($question->save()) {
             return Redirect::to('/common')->with('message', 'You have successfully updated the question');
         }
     }
 }
开发者ID:shankargiri,项目名称:taylor_latest,代码行数:21,代码来源:CommonquestionsController.php

示例4: actionPublish

 public function actionPublish()
 {
     if (Yii::app()->user->isGuest) {
         Yii::app()->user->loginRequired();
     } else {
         $user = User::model()->findByPk(Yii::app()->user->id);
         if (!$user->canPublish()) {
             Yii::app()->user->setFlash('publish-fail', '当前等级' . $user->getLevel() . ',每日能提' . $user->getLevel() . '个问题。<br>今日已达上限。');
             $this->redirect(Yii::app()->request->urlReferrer);
         }
         $model = new Question();
         if (isset($_POST['Question'])) {
             $model->attributes = $_POST['Question'];
             if ($model->validate() && $model->publish()) {
                 $criteria = new CDbCriteria();
                 $criteria->addCondition("userId=" . Yii::app()->user->id);
                 $criteria->order = "createTime DESC";
                 $question = Question::model()->find($criteria);
                 $this->redirect(array('view', 'qid' => $question->id));
             }
         }
         $this->render('publish', array('model' => $model));
     }
 }
开发者ID:hanyilu,项目名称:iQuestion,代码行数:24,代码来源:QuestionController.php

示例5: XMLImportSurvey


//.........这里部分代码省略.........
            foreach ($row as $key => $value) {
                $insertdata[(string) $key] = (string) $value;
            }
            if (!in_array($insertdata['language'], $aLanguagesSupported) || $insertdata['gid'] == 0) {
                continue;
            }
            $iOldSID = $insertdata['sid'];
            $insertdata['sid'] = $iNewSID;
            $insertdata['gid'] = $aGIDReplacements[$insertdata['gid']];
            $oldqid = $insertdata['qid'];
            unset($insertdata['qid']);
            // save the old qid
            // now translate any links
            if ($bTranslateInsertansTags) {
                $insertdata['question'] = translateLinks('survey', $iOldSID, $iNewSID, $insertdata['question']);
                $insertdata['help'] = translateLinks('survey', $iOldSID, $iNewSID, $insertdata['help']);
            }
            // Insert the new question
            if (isset($aQIDReplacements[$oldqid])) {
                $insertdata['qid'] = $aQIDReplacements[$oldqid];
                switchMSSQLIdentityInsert('questions', true);
            }
            if ($insertdata) {
                XSSFilterArray($insertdata);
            }
            if (!$bConvertInvalidQuestionCodes) {
                $sScenario = 'archiveimport';
            } else {
                $sScenario = 'import';
            }
            $oQuestion = new Question($sScenario);
            $oQuestion->setAttributes($insertdata, false);
            // Try to fix question title for valid question code enforcement
            if (!$oQuestion->validate(array('title'))) {
                $sOldTitle = $oQuestion->title;
                $sNewTitle = preg_replace("/[^A-Za-z0-9]/", '', $sOldTitle);
                if (is_numeric(substr($sNewTitle, 0, 1))) {
                    $sNewTitle = 'q' . $sNewTitle;
                }
                $oQuestion->title = $sNewTitle;
            }
            $attempts = 0;
            // Try to fix question title for unique question code enforcement
            while (!$oQuestion->validate(array('title'))) {
                if (!isset($index)) {
                    $index = 0;
                    $rand = mt_rand(0, 1024);
                } else {
                    $index++;
                }
                $sNewTitle = 'r' . $rand . 'q' . $index;
                $oQuestion->title = $sNewTitle;
                $attempts++;
                if ($attempts > 10) {
                    safeDie($clang->gT("Error") . ": Failed to resolve question code problems after 10 attempts.<br />");
                }
            }
            if (!$oQuestion->save()) {
                // safeDie($clang->gT("Error while saving: "). print_r($oQuestion->errors, true));
                //
                // In PHP 5.2.10 a bug is triggered that resets the foreach loop when inserting a record
                // Problem is that it is the default PHP version on Ubuntu 12.04 LTS (which is currently very common in use)
                // For this reason we ignore insertion errors (because it is most likely a duplicate)
                // and continue with the next one
                continue;
            }
开发者ID:rouben,项目名称:LimeSurvey,代码行数:67,代码来源:import_helper.php

示例6: actionNew_question

 /** 
  * Method to show the views for 
  * asking a new question and actually
  * creating the new question
  */
 public function actionNew_question()
 {
     error_reporting(E_ALL);
     ini_set("display_errors", 1);
     $model = new Question();
     $model->created_by = Yii::app()->user->id;
     $model->post_type = "question";
     if (isset($_POST['Question'])) {
         $model->attributes = $_POST['Question'];
         if ($model->validate()) {
             $model->save();
             // Question has been saved, add the tags
             if (isset($_POST['Tags'])) {
                 // Split tag string into array
                 $tags = explode(", ", $_POST['Tags']);
                 foreach ($tags as $tag) {
                     $tag = Tag::model()->firstOrCreate($tag);
                     $question_tag = new QuestionTag();
                     $question_tag->question_id = $model->id;
                     $question_tag->tag_id = $tag->id;
                     $question_tag->save();
                 }
             } else {
                 // throw error(?) no tag provided
             }
             $this->redirect($this->createUrl('//questionanswer/main/view', array('id' => $model->id)));
         }
     }
     $this->render('new_question', array('model' => $model));
 }
开发者ID:tejrajs,项目名称:humhub-modules-questionanswer,代码行数:35,代码来源:MainController.php


注:本文中的Question::validate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。