Inheritance: extends GenericObject
Exemplo n.º 1
0
 public function faqSend()
 {
     $question = new Question();
     $input = Input::all();
     $captcha_string = Input::get('g-recaptcha-response');
     $captcha_response = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=6LcCwgATAAAAAKaXhPJOGPTBwX-n2-PPLZ7iupKj&response=' . $captcha_string);
     $captcha_json = json_decode($captcha_response);
     if ($captcha_json->success) {
         $rules = ["sujetQuestion" => "required", "mail" => "required|email", "contenuQuestion" => "required"];
         $messages = ["required" => ":attribute est requis pour l'envoi d'une question", "email" => "L'adresse email précisée n'est pas valide"];
         $validator = Validator::make(Input::all(), $rules, $messages);
         if ($validator->fails()) {
             $messages = $validator->messages();
             Session::flash('flash_msg', "Certains champs spécifiés sont incorrects.");
             Session::flash('flash_type', "fail");
             return Redirect::to(URL::previous())->withErrors($validator);
         } else {
             $question->fill($input)->save();
             Session::flash('flash_msg', "Votre question nous est bien parvenue. Nous vous répondrons sous peu.");
             Session::flash('flash_type', "success");
             return Redirect::to(URL::previous());
         }
     } else {
         Session::flash('flash_msg', "Champ de vérification incorrect ou non coché.");
         Session::flash('flash_type', "fail");
         return Redirect::to(URL::previous());
     }
 }
Exemplo n.º 2
0
 public function makeQuestion()
 {
     $data = Input::all();
     $rules = ['question' => 'required', 'opt1' => 'required', 'opt2' => 'required', 'opt3' => 'required'];
     $validator = Validator::make($data, $rules);
     if ($validator->passes()) {
         $question = new Question();
         $question->question = $data['question'];
         if ($question->save()) {
             try {
                 for ($i = 1; $i < 4; $i++) {
                     $option = new QuestionOption();
                     $option->question_id = $question->id;
                     $option->option_details = $data["opt{$i}"];
                     $option->option_number = $i;
                     $option->save();
                 }
             } catch (Exception $e) {
                 Redirect::back()->withInfo('Something Interuppted');
             }
         } else {
             Redirect::back()->withInfo('Something Interuppted');
         }
         return Redirect::to('adm/h');
     } else {
         return Redirect::back()->withErrors($validator->messages());
     }
 }
Exemplo n.º 3
0
function add_question($node) {

	$objQuestion = new Question();
	$objQuestion->updateTitle(standard_text_escape($node->content));

	/**
	*Exercice type 1 refers to single response multiple choice question. 
	*Exercice type 2 refers to multiple response multiple choice question. 
	*QTILite allows only single response multiple choice questions.
	**/

	if($node->num_of_correct_answers > 1 ) {
		$objQuestion->updateType(2);
	} else {
		$objQuestion->updateType(1);
	}

	$objQuestion->save();

	$questionId = $objQuestion->selectId();

	$objAnswer = new Answer($questionId);
	$tmp_answer = array();

	if($node->answers) {
		foreach ($node->answers as $answer) {
			$objAnswer->createAnswer($answer['answer'], $answer['correct'], $answer['feedback'], $answer['weight'], 1);
		}
		$objAnswer->save();
	}
}
 public function notifyNewArgument(Question $q, Argument $a)
 {
     global $sDB, $sTimer, $sTemplate;
     $sTimer->start("notifyNewArgument");
     $res = $sDB->exec("SELECT `notifications`.`userId`, `notifications`.`flags`, `users`.`email`, `users`.`userName` FROM `notifications`\n                           LEFT JOIN `users` ON `users`.`userId` = `notifications`.`userId`\n                           WHERE `questionId` = '" . i($q->questionId()) . "';");
     while ($row = mysql_fetch_object($res)) {
         // no notifications for our own arguments.
         /*if($a->userId() == $row->userId)
           {
               continue;
           }*/
         $uId = new BaseConvert($row->userId);
         $qId = new BaseConvert($q->questionId());
         $profileUrl = $sTemplate->getShortUrlBase() . "u" . $uId->val();
         $unfollowUrl = $sTemplate->getShortUrlBase() . "f" . $qId->val();
         $url = $a->shortUrl();
         if (!SHORTURL_BASE) {
             $profileUrl = $sTemplate->getRoot() . "user/" . $row->userId . "/";
             $unfollowUrl = $sTemplate->getRoot() . "unfollow.php?qId=" . $q->questionId();
             $url = $a->fullurl();
         }
         $subject = $sTemplate->getString("NOTIFICATION_NEW_ARGUMENT_SUBJECT");
         $message = $sTemplate->getString("NOTIFICATION_NEW_ARGUMENT_BODY", array("[USERNAME]", "[AUTHOR]", "[URL]", "[QUESTION]", "[ARGUMENT]", "[UNFOLLOW_URL]", "[PROFILE_URL]"), array($row->userName, $a->author(), $url, $q->title(), $a->headline(), $unfollowUrl, $profileUrl));
         $this->sendMail($row->email, "", $subject, $message);
     }
     $sTimer->stop("notifyNewArgument");
 }
Exemplo n.º 5
0
 public function actionIndex($alias = '')
 {
     // Определяем, выбрана или нет категория
     $category = null;
     if (!empty($alias)) {
         // Если выбрана категория
         $category = QuestionCategory::model()->published()->findByAlias($alias);
         if (is_null($category)) {
             throw new CHttpException(404);
         }
         $page = $category;
         $this->currentCategory = $category;
     } else {
         // Загружаем страницу "Новости"
         Yii::import("application.modules.page.PageModule");
         Yii::import("application.modules.page.models.Page");
         $page = Page::model()->findByPath("faq");
     }
     // Показываем только публичные новости
     $model = new Question('user_search');
     $model->unsetAttributes();
     // Категория
     if (!empty($category)) {
         $model->category_id = $category->id;
     }
     $dataProvider = $model->user_search();
     $this->render('index', ['dataProvider' => $dataProvider, 'page' => $page, 'currentCategory' => $category]);
 }
Exemplo n.º 6
0
 /**
  * Executes index action
  *
  * @param sfRequest $request A request object
  */
  public function executeInjection(sfWebRequest $request)
  {
	$this->form = new InjectionForm();
    if ($request->isMethod('post'))
    {
		$this->form->bind($request->getParameter('injection'), $request->getFiles('injection'));
		if ($this->form->isValid())
		{
		  $file = $this->form->getValue('fichier');
		  $file->save(sfConfig::get('sf_upload_dir').'/injection.csv');
		  
			if (($handle = fopen(sfConfig::get('sf_upload_dir').'/injection.csv', "r")) !== FALSE) {
				while (($data = fgetcsv($handle, 0, ";")) !== FALSE) {
					if ($data[9] != '') {
						$question = new Question();
						$question->setNom($data[4]);
						$question->setPrenom($data[5]);
						$question->setCodePostal($data[6]);
						$question->setPays($data[7]);
						$question->setTelephone($data[9]);
						$question->setEmail($data[8]);
						$question->setTexteQuestion(str_replace("\\", "", $data[3]));
	//					$question->setSite("lejuridique");
						$question->setDateQuestion($data[2]);
						$question->save();
					}
				}
				fclose($handle);
			}		  
		}
    }
	
  }
Exemplo n.º 7
0
 /**
  * @covers Genj\FaqBundle\Entity\Question::__toString
  */
 public function testToString()
 {
     $question = new Question();
     $question->setHeadline('John Doe');
     $questionToString = (string) $question;
     $this->assertEquals('John Doe', $questionToString);
 }
Exemplo n.º 8
0
 public static function import($file)
 {
     $fd = fopen($file, 'r');
     $quiz = new QuaranteDeuxCases();
     $quiz->title = fgets($fd);
     $quiz->filename = $file;
     $quiz->savetime = filemtime($file);
     $level_count = 0;
     while (!feof($fd)) {
         $lines = array();
         while (($line = trim(fgets($fd))) != '') {
             $lines[] = $line;
         }
         if (count($lines) > 0) {
             $question = new Question();
             $question->setStatement(array_shift($lines));
             $question->addAnswer(implode(' ', $lines), true);
             $quiz->addQuestion($question, $level_count++);
         }
     }
     while ($level_count < 7) {
         $question = new Question();
         $question->setStatement('');
         $question->addAnswer('', true);
         $quiz->addQuestion($question, $level_count++);
     }
     fclose($fd);
     if (!$quiz->isCompleted()) {
         throw new Exception("Quiz file incomplete");
     }
     return $quiz;
 }
Exemplo n.º 9
0
 /**
  * Store a newly created post in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validate = Validator::make(Input::all(), Question::$rules);
     if ($validate->passes()) {
         //save a new Question
         $question = new Question();
         $question->title = Input::get('title');
         $question->body = Input::get('body');
         $question->user_id = Auth::id();
         $question->save();
         $question_id = $question->id;
         //saving Tags in Tag Table
         /*	convert input to array 	*/
         $tags_arr = explode(',', Input::get('tag'));
         /*	
         save in Tag table and return object for saving in 
         Tagmap table
         */
         foreach ($tags_arr as $tag_str) {
             $tag_obj = Tag::firstOrCreate(array('title' => $tag_str));
             //this line will attach a tag ( insert and save automatically )
             $new_question->tags()->attach($tag_obj->id);
         }
         return Redirect::action('QuestionController@index');
     }
     return Redirect::back()->withErrors($validate)->withInput();
 }
 public function parse()
 {
     // 定义题型样式
     $qp = $this->patterning($this->qp, 'us');
     // 提取题型
     $questionTextArray = array();
     preg_match_all($qp, preg_replace($this->patterning(QuestionType::$PATTERNS[QuestionType::SHORT_ANSWER], 'us'), '', $this->_sectionText), $questionTextArray);
     if (count($questionTextArray) == 0 || count($questionTextArray[0]) == 0) {
         return null;
     }
     // 处理题型
     $questionArray = array();
     $questionDescArray = $questionTextArray[1];
     // 每个问题的描述部分
     $questionSetArray = $questionTextArray[2];
     // 每个问题的提问部分
     for ($i = 0; $i < count($questionDescArray); $i++) {
         // 拆解每个题型并生成对应的Question
         $question = new Question();
         // 大问题部分
         $question->Set_content(ext_trim($questionDescArray[$i]));
         $question->Set_type(QuestionType::SHORT_ANSWER);
         $question->Set_questions(array());
         $subQuestionArray =& $question->Get_questions();
         $questionArray[] = $question;
         // 追加大问题
         // 生成子问题以及选项
         $questionSet = array();
         preg_match_all($this->patterning(array($this->qnp, '.+?(?=(?:\\n', $this->qnp, '|$))'), 'us'), $questionSetArray[$i], $questionSet);
         $questionSet = count($questionSet) > 0 ? $questionSet[0] : null;
         if (!$questionSet) {
             continue;
         }
         foreach ($questionSet as $optionText) {
             $subQuestion = new Question();
             // 子问题
             $subQuestion->Set_content(ext_trim(preg_replace($this->patterning(array('.*?', $this->qnp), 'us'), '', $optionText)));
             $subQuestion->Set_type(QuestionType::SHORT_ANSWER);
             //                $subQuestion->Set_options(array());
             $subQuestionArray[] = $subQuestion;
             // 追加子问题
             //                $subOptionArray = &$subQuestion->Get_options();
             //                // 整理每个选项组
             //                $optionSetTextArray = array();
             //                preg_match_all($this->patterning(array($this->onp, '.+?', '(?:(?=', $this->onp, ')|(?=$))'), 'us'), $optionText, $optionSetTextArray);
             //                foreach ($optionSetTextArray as $eachOptionTextArray) {
             //                    foreach ($eachOptionTextArray as $eachOptionText) {
             //                        $option = new Option();
             //                        $option->Set_option_content(ext_trim(preg_replace($this->patterning($this->onp), '', $eachOptionText)));
             //                        $option->Set_item_tag(preg_replace($this->patterning(array('(', $this->onp, ').+')), '$1', $eachOptionText));
             //                        $option->Set_type(QuestionType::SHORT_ANSWER);
             //                        $subOptionArray[] = $option;
             //                    }
             //                }
         }
     }
     // 返回结果
     return $questionArray;
 }
Exemplo n.º 11
0
 static function find($id)
 {
     $question = new Question($id);
     if ($question->isError()) {
         throw new RecordNotFound();
     }
     return $question;
 }
Exemplo n.º 12
0
 /**
  * Builds a domain object from a DB row.
  * Must be overridden by child classes.
  */
 protected function buildDomainObject($row)
 {
     $question = new Question();
     $question->setIdQuestion($row['id_question']);
     $question->setIdSurvey($row['id_sondage']);
     $question->setLibelle($row['libelle']);
     return $question;
 }
Exemplo n.º 13
0
 function delete()
 {
     $this->is_loggedin();
     global $runtime;
     $to_trash = new Question($runtime['ident']);
     $to_trash->delete();
     redirect('questions/all');
 }
Exemplo n.º 14
0
 function xmoney_close_clicked()
 {
     $dialog = new Question($this->Owner, 'Sair do X-Money?');
     $result = $dialog->ask();
     if ($result != Gtk::RESPONSE_YES) {
         return;
     }
     Gtk::main_quit();
 }
 private function setQuestions()
 {
     $categories = new Categorie();
     $questions = new Question();
     $questions->readQuestions($categories->getCategories());
     $tabUn = $questions->getUn();
     $tabAutre = $questions->getAutre();
     $this->_questions = array('lun1' => $tabUn[0], 'lautre1' => $tabAutre[0], 'lun2' => $tabUn[1], 'lautre2' => $tabAutre[1]);
 }
Exemplo n.º 16
0
 public function makeNewQues($batchid)
 {
     $question = new Question();
     $question->user_id = Auth::id();
     $question->batchentry_id = $batchid;
     $question->complete = 0;
     $question->save();
     Session::put('currentqid', $question->id);
     return $question->id;
 }
Exemplo n.º 17
0
 function delete_event()
 {
     $dialog = new Question($this->Owner, 'Sair do X-Money?');
     $result = $dialog->ask();
     if ($result == Gtk::RESPONSE_YES) {
         exit(0);
     } else {
         return true;
     }
 }
Exemplo n.º 18
0
 function render()
 {
     $this->title = __('Answers the Question of the Day');
     $question = new Question();
     $params = array('cnt' => FALSE, 'show' => 1, 'page' => 1, 'is_active' => 1, 'sort_by' => 'changed', 'direction' => 'DESC');
     $data = $question->load_many($params);
     $this->links = objtoarray($data);
     $this->inner_HTML = $this->generate_inner_html();
     $network_stats = parent::render();
     return $network_stats;
 }
Exemplo n.º 19
0
 /**
  * Store a newly created resource in storage.
  *
  * @param Request $request
  * @return \Illuminate\Http\JsonResponse
  */
 public function store(Request $request)
 {
     $validator = Validator::make($request->all(), ['title' => 'required|max:150', 'description' => 'required']);
     if ($validator->fails()) {
         return response()->json($validator->errors(), 400);
     } else {
         $question = new Question(['title' => $request->title, 'description' => $request->description, 'user_id' => Auth::user()->id]);
         $question->save();
         return response()->json($question, 201);
     }
 }
Exemplo n.º 20
0
 public function admin_add_question()
 {
     $question = null;
     if (array_key_exists('question', $_POST)) {
         $question = new Question($this->question_collection, $_POST['question']);
         $question->save();
         header("Location: /?p=admin");
     }
     $this->load_template('admin/add_question');
     return $this->render($question);
 }
/**
 * Add content to the created admin columns for questions
 * @param (string) the column title
 * @param (int) the post ID
 * @return (void / output buffer)
 */
function han_dwa_qa_question_admin_columns_content($column, $postId)
{
    $question = new Question($postId);
    if ($column === 'email') {
        echo $question->getEmail();
    } elseif ($column === 'votes') {
        echo $question->getVotes();
    } elseif ($column === 'qa') {
        $qa = $question->getQa();
        echo sprintf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post' => $qa->ID, 'action' => 'edit'), 'post.php')), esc_html(sanitize_term_field('name', $qa->post_title, $qa->ID, 'name', 'display')));
    }
}
 private function prepareQuestion(Question $question)
 {
     $text = $question->direction . PHP_EOL;
     if ($question->isGraded()) {
         $text .= 'Awarded Points: ' . $question->awardedPoints . PHP_EOL;
         if (!empty($question->correctAnswer)) {
             $text .= 'Correct Response: ' . $question->correctAnswer . PHP_EOL;
         }
     }
     $text .= 'User Response: ' . $question->userAnswer . PHP_EOL;
     return $text;
 }
 function get_links()
 {
     $question = new Question();
     $param = array('cnt' => TRUE);
     $this->Paging["count"] = $question->load_many($param);
     $params = array('cnt' => FALSE, 'show' => $this->Paging["show"], 'page' => $this->Paging["page"], 'sort_by' => 'changed', 'direction' => 'DESC');
     $data = $question->load_many($params);
     $links = objtoarray($data);
     $params = array('cnt' => FALSE, 'show' => 1, 'page' => 1, 'is_active' => 1, 'sort_by' => 'changed', 'direction' => 'DESC');
     $data = $question->load_many($params);
     $this->selected = @$data[0]->content_id;
     return $links;
 }
Exemplo n.º 24
0
 public function getQuestions($limit, $mode)
 {
     $questions = array();
     $result = array();
     foreach ($this->dbGetCol('SELECT question_id from test_content WHERE test_id=:test_id ', array('test_id' => $this->id)) as $quest_id) {
         $question = new Question();
         $question->createFromID($quest_id);
         $questions[] = $question;
     }
     $this->avg_diff = $this->countAvgDiff($questions);
     $result = $this->testMode($mode, $limit, $questions);
     return $result;
 }
Exemplo n.º 25
0
 public function getFollowedQuestions()
 {
     global $sDB, $sUser;
     $qF = array();
     $res = $sDB->exec("SELECT `questions`.* FROM `notifications`\r\n                          LEFT JOIN `questions` ON `questions`.questionId = `notifications`.`questionId`\r\n                          WHERE `notifications`.`userId` = '" . $this->userId . "' ORDER BY `dateAdded` DESC;");
     while ($row = mysql_fetch_object($res)) {
         $q = new Question($row->questionId, $row);
         if ($q->group() && $q->group()->getPermission($sUser, ACTION_VIEW_GROUP) == PERMISSION_DISALLOWED) {
         }
         array_push($qF, $q);
     }
     return $qF;
 }
Exemplo n.º 26
0
/**
 * Callback after creating the meta box
 * @param (object) the post object
 * @return (void)
 */
function han_dwa_qa_question_details_meta_box_callback($post)
{
    global $hanDwaQaQuestionDetailsActionId;
    global $hanDwaQaQuestionDetailsNonceId;
    // Set a nonce
    wp_nonce_field($hanDwaQaQuestionDetailsActionId, $hanDwaQaQuestionDetailsNonceId);
    // Prepare the content
    $question = new Question($post->ID);
    $questions = $question->getQuestions();
    $references = $question->getReferences();
    // Output
    include_once 'question_details_html.php';
}
Exemplo n.º 27
0
 function get_links()
 {
     $question = new Question();
     $params = array('cnt' => FALSE, 'show' => 1, 'page' => 1, 'sort_by' => 'changed', 'direction' => 'DESC');
     $data = $question->load_many($params);
     $links = objtoarray($data);
     $this->title = $links[0]['body'];
     $this->question_id = $links[0]['content_id'];
     $comment = new Comment();
     $comment->parent_id = $this->question_id;
     $comment->parent_type = TYPE_ANSWER;
     $this->Paging["count"] = $comment->get_multiples_comment($cnt = TRUE);
     $links = $comment->get_multiples_comment($cnt = FALSE, $this->Paging["show"], $this->Paging["page"]);
     return $links;
 }
Exemplo n.º 28
0
 public function action_create()
 {
     $project = Project::find(Input::get('project_id'));
     if (!$project || !$project->question_period_is_open()) {
         return Redirect::to_route('project', $project->id);
     }
     $question = new Question(array('project_id' => Input::get('project_id'), 'question' => Input::get('question')));
     $question->vendor_id = Auth::user()->vendor->id;
     if ($question->validator()->passes()) {
         $question->save();
         return Response::json(array("status" => "success", "question" => $question->to_array(), "html" => View::make('projects.partials.question')->with('question', $question)->render()));
     } else {
         return Response::json(array("status" => "error", "errors" => $question->validator()->errors->all()));
     }
 }
 public function test_check_answer()
 {
     $ques = ORM::factory('question', 10);
     $question = Question::factory($ques);
     $submitted = array(0 => array(0 => "s dasda s", 1 => "asd asd"), 1 => array(0 => "asd asdasdasd", 1 => "asda sasdasd"), 2 => array(0 => "dsf dsdfsdfsdf", 1 => "sa asasd assad"));
     $this->assertTrue($question->check_answer($submitted));
 }
Exemplo n.º 30
0
 /**
  * 构造方法
  * @param string $question 问题
  * @param array  $choices  选项
  * @param mixed  $default  默认答案
  */
 public function __construct($question, array $choices, $default = null)
 {
     parent::__construct($question, $default);
     $this->choices = $choices;
     $this->setValidator($this->getDefaultValidator());
     $this->setAutocompleterValues($choices);
 }