12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265 |
- <?php
- if(!class_exists('Exercise')):
- class Exercise
- {
- var $id;
- var $exercise;
- var $description;
- var $sound;
- var $type;
- var $random;
- var $active;
- var $timeLimit;
- var $attempts;
- var $feedbacktype;
- var $end_time;
- var $start_time;
- var $questionList;
- var $results_disabled;
-
- function Exercise()
- {
- $this->id=0;
- $this->exercise='';
- $this->description='';
- $this->sound='';
- $this->type=1;
- $this->random=0;
- $this->active=1;
- $this->questionList=array();
- $this->timeLimit = 0;
- $this->end_time = '0000-00-00 00:00:00';
- $this->start_time = '0000-00-00 00:00:00';
- $this->results_disabled =1;
- }
-
- function read($id)
- {
- global $_course;
- global $_configuration;
- global $questionList;
- $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
- $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
- $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
-
- $sql="SELECT title,description,sound,type,random,active, results_disabled, max_attempt,start_time,end_time,feedback_type FROM $TBL_EXERCICES WHERE id='".Database::escape_string($id)."'";
- $result=api_sql_query($sql,__FILE__,__LINE__);
-
- if($object=Database::fetch_object($result))
- {
- $this->id=$id;
- $this->exercise=$object->title;
- $this->description=$object->description;
- $this->sound=$object->sound;
- $this->type=$object->type;
- $this->random=$object->random;
- $this->active=$object->active;
- $this->results_disabled =$object->results_disabled;
- $this->attempts = $object->max_attempt;
- $this->feedbacktype = $object->feedback_type;
- $this->end_time = $object->end_time;
- $this->start_time = $object->start_time;
- $sql="SELECT question_id, question_order FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS WHERE question_id=id AND exercice_id='".Database::escape_string($id)."' ORDER BY question_order";
- $result=api_sql_query($sql,__FILE__,__LINE__);
-
-
- while($object=Database::fetch_object($result))
- {
-
- while(isset($this->questionList[$object->question_order]))
- {
- $object->question_order++;
- }
- $this->questionList[$object->question_order]=$object->question_id;
- }
-
- if($this->random > 0){
- $this->questionList = $this->selectRandomList();
- }
-
-
-
-
- if($this->type == 2 && $_configuration['live_exercise_tracking']==true && $_SERVER['REQUEST_METHOD']!='POST' && defined('QUESTION_LIST_ALREADY_LOGGED'))
- {
-
- $this->questionList = $questionList;
- }
- return true;
- }
-
- return false;
- }
-
- function selectId()
- {
- return $this->id;
- }
-
- function selectTitle()
- {
- return $this->exercise;
- }
-
-
- function selectAttempts()
- {
- return $this->attempts;
- }
-
-
- function selectFeedbackType()
- {
- return $this->feedbacktype;
- }
-
-
-
- function selectTimeLimit()
- {
- return $this->timeLimit;
- }
-
- function selectDescription()
- {
- return $this->description;
- }
-
- function selectSound()
- {
- return $this->sound;
- }
-
- function selectType()
- {
- return $this->type;
- }
-
- function selectResultsDisabled()
- {
- return $this->results_disabled;
- }
-
- function isRandom()
- {
- if($this->random > 0){
- return true;
- }
- else{
- return false;
- }
- }
-
- function getShuffle()
- {
- return $this->random;
- }
-
- function selectStatus()
- {
- return $this->active;
- }
-
- function selectQuestionList()
- {
- return $this->questionList;
- }
-
- function selectNbrQuestions()
- {
- return sizeof($this->questionList);
- }
-
- function selectRandomList()
- {
- $nbQuestions = $this->selectNbrQuestions();
- $temp_list = $this->questionList;
-
-
- if (count($temp_list)<>0) {
- shuffle($temp_list);
- return array_combine(range(1,$nbQuestions),$temp_list);
- }
-
- $nbQuestions = $this->selectNbrQuestions();
-
-
- if($this->random == 0 || $nbQuestions < 2)
- {
- return $this->questionList;
- }
- $randQuestionList = array();
- $alreadyChosen = array();
-
- for($i=0; $i < $this->random; $i++)
- {
- if($i < $nbQuestions){
- do
- {
- $rand=rand(1,$nbQuestions);
- }
- while(in_array($rand,$alreadyChosen));
-
- $alreadyChosen[]=$rand;
- $randQuestionList[$rand] = $this->questionList[$rand];
- }
- }
- return $randQuestionList;
- }
-
- function isInList($questionId)
- {
- if (is_array($this->questionList))
- return in_array($questionId,$this->questionList);
- else
- return false;
- }
-
- function updateTitle($title)
- {
- $this->exercise=$title;
- }
-
-
- function updateAttempts($attempts)
- {
- $this->attempts=$attempts;
- }
-
-
-
- function updateFeedbackType($feedback_type)
- {
- $this->feedbacktype=$feedback_type;
- }
-
-
- function updateDescription($description)
- {
- $this->description=$description;
- }
-
- function updateSound($sound,$delete)
- {
- global $audioPath, $documentPath,$_course, $_user;
- $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
- $TBL_ITEM_PROPERTY = Database::get_course_table(TABLE_ITEM_PROPERTY);
- if($sound['size'] && (strstr($sound['type'],'audio') || strstr($sound['type'],'video')))
- {
- $this->sound=$sound['name'];
- if(@move_uploaded_file($sound['tmp_name'],$audioPath.'/'.$this->sound))
- {
- $query="SELECT 1 FROM $TBL_DOCUMENT "
- ." WHERE path='".str_replace($documentPath,'',$audioPath).'/'.$this->sound."'";
- $result=api_sql_query($query,__FILE__,__LINE__);
- if(!mysql_num_rows($result))
- {
-
- $id = add_document($_course,str_replace($documentPath,'',$audioPath).'/'.$this->sound,'file',$sound['size'],$sound['name']);
-
-
-
-
-
- api_item_property_update($_course, TOOL_DOCUMENT, $id, 'DocumentAdded',$_user['user_id']);
- item_property_update_on_folder($_course,str_replace($documentPath,'',$audioPath),$_user['user_id']);
- }
- }
- }
- elseif($delete && is_file($audioPath.'/'.$this->sound))
- {
- $this->sound='';
- }
- }
-
- function updateType($type)
- {
- $this->type=$type;
- }
-
- function setRandom($random)
- {
- $this->random=$random;
- }
-
- function enable()
- {
- $this->active=1;
- }
-
- function disable()
- {
- $this->active=0;
- }
-
- function disable_results()
- {
- $this->results_disabled = true;
- }
-
- function enable_results()
- {
- $this->results_disabled = false;
- }
- function updateResultsDisabled($results_disabled)
- {
- if ($results_disabled==1){
- $this->results_disabled = true;
- } else {
- $this->results_disabled = false;
- }
- }
-
-
- function save($type_e='')
- {
- global $_course,$_user;
- $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
- $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
- $TBL_QUIZ_QUESTION= Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
- $id=$this->id;
- $exercise=$this->exercise;
- $description=$this->description;
- $sound=$this->sound;
- $type=$this->type;
- $attempts=$this->attempts;
- $feedbacktype=$this->feedbacktype;
- $random=$this->random;
- $active=$this->active;
- if ($feedbacktype==1){
- $results_disabled = 1;
- } else {
- $results_disabled = intval($this->results_disabled);
- }
- $start_time = Database::escape_string($this->start_time);
- $end_time = Database::escape_string($this->end_time);
-
- if($id) {
-
- $sql="UPDATE $TBL_EXERCICES SET
- title='".Database::escape_string($exercise)."',
- description='".Database::escape_string($description)."'";
-
- if ($type_e != 'simple') {
- $sql .= ", sound='".Database::escape_string($sound)."',
- type='".Database::escape_string($type)."',
- random='".Database::escape_string($random)."',
- active='".Database::escape_string($active)."',
- feedback_type='".Database::escape_string($feedbacktype)."',
- start_time='$start_time',end_time='$end_time',
- max_attempt='".Database::escape_string($attempts)."', " .
- "results_disabled='".Database::escape_string($results_disabled)."'";
- }
- $sql .= " WHERE id='".Database::escape_string($id)."'";
-
-
- api_sql_query($sql,__FILE__,__LINE__);
-
-
- api_item_property_update($_course, TOOL_QUIZ, $id,'QuizUpdated',$_user['user_id']);
-
- if (api_get_setting('search_enabled')=='true') {
- $this -> search_engine_edit();
- }
- } else {
-
-
-
- $sql="INSERT INTO $TBL_EXERCICES(start_time,end_time,title,description,sound,type,random,active, results_disabled, max_attempt,feedback_type)
- VALUES(
- '$start_time','$end_time',
- '".Database::escape_string($exercise)."',
- '".Database::escape_string($description)."',
- '".Database::escape_string($sound)."',
- '".Database::escape_string($type)."',
- '".Database::escape_string($random)."',
- '".Database::escape_string($active)."',
- '".Database::escape_string($results_disabled)."',
- '".Database::escape_string($attempts)."',
- '".Database::escape_string($feedbacktype)."'
- )";
- api_sql_query($sql,__FILE__,__LINE__);
- $this->id=Database::insert_id();
-
-
- api_item_property_update($_course, TOOL_QUIZ, $this->id,'QuizAdded',$_user['user_id']);
- if (api_get_setting('search_enabled')=='true' && extension_loaded('xapian')) {
- $this -> search_engine_save();
- }
- }
-
- $this->update_question_positions();
- }
- function update_question_positions() {
-
- $TBL_QUIZ_QUESTION= Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
- foreach($this->questionList as $position=>$questionId)
- {
-
- $sql="UPDATE $TBL_QUIZ_QUESTION SET question_order='".Database::escape_string($position)."' " .
- "WHERE question_id='".Database::escape_string($questionId)."' and exercice_id=".Database::escape_string($this->id)."";
- api_sql_query($sql,__FILE__,__LINE__);
- }
- }
-
- function moveUp($id)
- {
-
-
-
-
-
- $question_list =array();
- foreach($this->questionList as $position=>$questionId)
- {
- $question_list[]= $questionId;
- }
- $len=count($question_list);
- $orderlist=array_keys($this->questionList);
- for($i=0;$i<$len;$i++)
- {
- $questionId = $question_list[$i];
- if($questionId == $id)
- {
-
- $pos1=$orderlist[$i];
- $pos2=$orderlist[$i-1];
- if($pos2===null)
- {
- $pos2 = $orderlist[$len-1];
- }
-
- if(!$pos2)
- {
- $pos2=$orderlist[0];
- $i=0;
- }
- break;
- }
- }
-
- $temp=$this->questionList[$pos2];
- $this->questionList[$pos2]=$this->questionList[$pos1];
- $this->questionList[$pos1]=$temp;
- }
-
- function moveDown($id)
- {
-
-
-
-
-
-
- $question_list =array();
- foreach($this->questionList as $position=>$questionId)
- {
- $question_list[]= $questionId;
- }
- $len=count($question_list);
- $orderlist=array_keys($this->questionList);
-
- for($i=0;$i<$len;$i++)
- {
- $questionId = $question_list[$i];
- if($questionId == $id)
- {
- $pos1=$orderlist[$i+1];
- $pos2 =$orderlist[$i];
- if(!$pos2)
- {
-
- }
- break;
- }
- }
-
-
- $temp=$this->questionList[$pos2];
- $this->questionList[$pos2]=$this->questionList[$pos1];
- $this->questionList[$pos1]=$temp;
- }
-
- function addToList($questionId)
- {
-
- if(!$this->isInList($questionId))
- {
-
- if(!$this->selectNbrQuestions())
- {
- $pos=1;
- }
- else
- {
- if (is_array($this->questionList))
- $pos=max(array_keys($this->questionList))+1;
- }
- $this->questionList[$pos]=$questionId;
- return true;
- }
- return false;
- }
-
- function removeFromList($questionId)
- {
-
- $pos=array_search($questionId,$this->questionList);
-
- if($pos === false)
- {
- return false;
- }
- else
- {
-
- unset($this->questionList[$pos]);
- return true;
- }
- }
-
- function delete(){
- global $_course,$_user;
- $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
- $sql="UPDATE $TBL_EXERCICES SET active='-1' WHERE id='".Database::escape_string($this->id)."'";
- api_sql_query($sql);
- api_item_property_update($_course, TOOL_QUIZ, $this->id,'QuizDeleted',$_user['user_id']);
-
- if (api_get_setting('search_enabled')=='true' && extension_loaded('xapian') ) {
- $this -> search_engine_delete();
- }
- }
-
- function createForm ($form, $type='full')
- {
- global $id;
- if(empty($type)){
- $type='full';
- }
-
- if (!empty($_GET['exerciseId'])) {
- $form_title = get_lang('ModifyExercise');
- } else {
- $form_title = get_lang('NewEx');
- }
- $form->addElement('header', '', $form_title);
-
- $form -> addElement('text', 'exerciseTitle', get_lang('ExerciseName'),'class="input_titles"');
-
-
- $form -> addElement('html','<div class="row">
- <div class="label"></div>
- <div class="formw" style="height:50px">
- <a href="javascript://" onclick=" return show_media()"> <span id="media_icon"> <img src="../img/looknfeel.png" alt="" /> '.get_lang('ExerciseDescription').'</span></a>
- </div>
- </div>');
-
- $form -> addElement ('html','<div id="media" style="display:none;">');
- $form -> addElement ('html_editor', 'exerciseDescription', null, null, array('ToolbarSet' => 'TestDescription', 'Width' => '100%', 'Height' => '200'));
- $form -> addElement ('html','</div>');
-
- $form -> addElement('html','<div class="row">
- <div class="label"> </div>
- <div class="formw">
- <a href="javascript://" onclick=" return advanced_parameters()"><span id="img_plus_and_minus"><div style="vertical-align:top" ><img src="../img/div_show.gif" alt="" /> '.get_lang('AdvancedParameters').'</div></span></a>
- </div>
- </div>');
-
-
- $form -> addElement('html','<div id="options" style="display:none">');
-
- if($type=='full') {
-
- $radios_feedback = array();
- $radios_feedback[] = FormValidator :: createElement ('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'),'0');
- $radios_feedback[] = FormValidator :: createElement ('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'),'2');
- $form -> addGroup($radios_feedback, null, get_lang('FeedbackType'));
-
- $feedback_option[0]=get_lang('ExerciseAtTheEndOfTheTest');
- $feedback_option[1]=get_lang('DirectFeedback');
- $feedback_option[2]=get_lang('NoFeedback');
-
-
- if ($this->selectFeedbackType() != 1 ) {
-
-
- $radios = array();
- $radios[] = FormValidator :: createElement ('radio', 'exerciseType', null, get_lang('QuestionsPerPageOne'),'2');
- $radios[] = FormValidator :: createElement ('radio', 'exerciseType', null, get_lang('QuestionsPerPageAll'),'1');
- $form -> addGroup($radios, null, get_lang('QuestionsPerPage'));
- } else {
-
- if ($this->selectNbrQuestions()== 0) {
- $form -> addElement('select', 'exerciseFeedbackType',get_lang('FeedbackType'),$feedback_option,'onchange="javascript:feedbackselection()"');
-
- $radios = array();
- $radios[] = FormValidator :: createElement ('radio', 'exerciseType', null, get_lang('SimpleExercise'),'1');
- $radios[] = FormValidator :: createElement ('radio', 'exerciseType', null, get_lang('SequentialExercise'),'2');
- $form -> addGroup($radios, null, get_lang('ExerciseType'));
- } else {
-
- $form -> addElement('hidden', 'exerciseFeedbackType','1');
- $form -> addElement('hidden', 'exerciseType','2');
- }
- }
-
- $radios_results_disabled = array();
- $radios_results_disabled[] = FormValidator :: createElement ('radio', 'results_disabled', null, get_lang('Yes'),'0');
- $radios_results_disabled[] = FormValidator :: createElement ('radio', 'results_disabled', null, get_lang('No'),'1');
- $form -> addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'));
-
- $random = array();
- $option=array();
- $max = ($this->id > 0) ? $this->selectNbrQuestions() : 10 ;
- $option = range(0,$max);
- $option[0]=get_lang('No');
-
- $random[] = FormValidator :: createElement ('select', 'randomQuestions',null,$option);
- $random[] = FormValidator :: createElement ('static', 'help','help','<span style="font-style: italic;">'.get_lang('RandomQuestionsHelp').'</span>');
-
- $form -> addGroup($random,null,get_lang('RandomQuestions'),'<br />');
-
- $attempt_option=range(0,10);
- $attempt_option[0]=get_lang('Infinite');
-
- $form -> addElement('select', 'exerciseAttempts',get_lang('ExerciseAttempts'),$attempt_option);
-
- $form -> addElement('checkbox', 'enabletimelimit',get_lang('EnableTimeLimits'),null,'onclick = " return timelimit() "');
-
- $var= Exercise::selectTimeLimit();
-
- $form -> addElement('html','</div>');
-
- if(($this -> start_time!='0000-00-00 00:00:00')||($this -> end_time!='0000-00-00 00:00:00'))
- $form -> addElement('html','<div id="options2" style="display:block;">');
- else
- $form -> addElement('html','<div id="options2" style="display:none;">');
-
-
-
- $form->addElement('datepicker', 'start_time', get_lang('ExeStartTime'), array('form_name'=>'exercise_admin'));
- $form->addElement('datepicker', 'end_time', get_lang('ExeEndTime'), array('form_name'=>'exercise_admin'));
-
-
- $form -> addElement('html','</div>');
-
- $defaults = array();
-
- if (api_get_setting('search_enabled') === 'true') {
- require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
-
- $form -> addElement ('checkbox', 'index_document','', get_lang('SearchFeatureDoIndexDocument'));
- $form -> addElement ('html','<br /><div class="row">');
- $form -> addElement ('html', '<div class="label">'. get_lang('SearchFeatureDocumentLanguage') .'</div>');
- $form -> addElement ('html', '<div class="formw">'. api_get_languages_combo() .'</div>');
- $form -> addElement ('html','</div><div class="sub-form">');
-
- $specific_fields = get_specific_field_list();
- foreach ($specific_fields as $specific_field) {
- $form -> addElement ('text', $specific_field['code'], $specific_field['name']);
- $filter = array('course_code'=> "'". api_get_course_id() ."'", 'field_id' => $specific_field['id'], 'ref_id' => $this->id, 'tool_id' => '\''. TOOL_QUIZ .'\'');
- $values = get_specific_field_values_list($filter, array('value'));
- if ( !empty($values) ) {
- $arr_str_values = array();
- foreach ($values as $value) {
- $arr_str_values[] = $value['value'];
- }
- $defaults[$specific_field['code']] = implode(', ', $arr_str_values);
- }
- }
- $form -> addElement ('html','</div>');
- }
- }
-
-
- isset($_GET['exerciseId'])?$text=get_lang('ModifyExercise'):$text=get_lang('ProcedToQuestions');
- $form -> addElement('html', '<br /><br />');
- $form -> addElement('style_submit_button', 'submitExercise', $text, 'class="save"');
-
- $form -> addRule ('exerciseTitle', get_lang('GiveExerciseName'), 'required');
- if($type=='full') {
-
- $form -> addRule ('exerciseAttempts', get_lang('Numeric'), 'numeric');
- $form -> addRule ('start_time', get_lang('InvalidDate'), 'date');
- $form -> addRule ('end_time', get_lang('InvalidDate'), 'date');
- $form -> addRule(array ('start_time', 'end_time'), get_lang('StartDateShouldBeBeforeEndDate'), 'date_compare', 'lte');
- }
-
- if($type=='full') {
- if($this -> id > 0) {
- if ($this -> random > $this->selectNbrQuestions()) {
- $defaults['randomQuestions'] = $this->selectNbrQuestions();
- } else {
- $defaults['randomQuestions'] = $this -> random;
- }
-
- $defaults['exerciseType'] = $this -> selectType();
- $defaults['exerciseTitle'] = $this -> selectTitle();
- $defaults['exerciseDescription'] = $this -> selectDescription();
- $defaults['exerciseAttempts'] = $this->selectAttempts();
- $defaults['exerciseFeedbackType'] = $this->selectFeedbackType();
- $defaults['results_disabled'] = $this->selectResultsDisabled();
-
- if(($this -> start_time!='0000-00-00 00:00:00')||($this -> end_time!='0000-00-00 00:00:00'))
- $defaults['enabletimelimit'] = 1;
-
- $defaults['start_time'] = ($this->start_time!='0000-00-00 00:00:00')? $this -> start_time : date('Y-m-d 12:00:00');
- $defaults['end_time'] = ($this->end_time!='0000-00-00 00:00:00')?$this -> end_time : date('Y-m-d 12:00:00',time()+84600);
-
- } else {
- $defaults['exerciseType'] = 2;
- $defaults['exerciseAttempts'] = 0;
- $defaults['randomQuestions'] = 0;
- $defaults['exerciseDescription'] = '';
- $defaults['exerciseFeedbackType'] = 0;
- $defaults['results_disabled'] = 0;
-
- $defaults['start_time'] = date('Y-m-d 12:00:00');
- $defaults['end_time'] = date('Y-m-d 12:00:00',time()+84600);
- }
- } else {
- $defaults['exerciseTitle'] = $this -> selectTitle();
- $defaults['exerciseDescription'] = $this -> selectDescription();
- }
- if (api_get_setting('search_enabled') === 'true') {
- $defaults['index_document'] = 'checked="checked"';
- }
- $form -> setDefaults($defaults);
- }
-
- function processCreation($form,$type='')
- {
- $this -> updateTitle($form -> getSubmitValue('exerciseTitle'));
- $this -> updateDescription($form -> getSubmitValue('exerciseDescription'));
- $this -> updateAttempts($form -> getSubmitValue('exerciseAttempts'));
- $this -> updateFeedbackType($form -> getSubmitValue('exerciseFeedbackType'));
- $this -> updateType($form -> getSubmitValue('exerciseType'));
- $this -> setRandom($form -> getSubmitValue('randomQuestions'));
- $this -> updateResultsDisabled($form -> getSubmitValue('results_disabled'));
- if($form -> getSubmitValue('enabletimelimit')==1)
- {
- $start_time = $form -> getSubmitValue('start_time');
- $this->start_time = $start_time['Y'].'-'.$start_time['F'].'-'.$start_time['d'].' '.$start_time['H'].':'.$start_time['i'].':00';
- $end_time = $form -> getSubmitValue('end_time');
- $this->end_time = $end_time['Y'].'-'.$end_time['F'].'-'.$end_time['d'].' '.$end_time['H'].':'.$end_time['i'].':00';
- }
- else
- {
- $this->start_time = '0000-00-00 00:00:00';
- $this->end_time = '0000-00-00 00:00:00';
- }
-
- $this -> save($type);
- }
- function search_engine_save() {
- if ($_POST['index_document'] != 1) {
- return;
- }
- $course_id = api_get_course_id();
- require_once(api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
- require_once(api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php');
- require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
- $specific_fields = get_specific_field_list();
- $ic_slide = new IndexableChunk();
- $all_specific_terms = '';
- foreach ($specific_fields as $specific_field) {
- if (isset($_REQUEST[$specific_field['code']])) {
- $sterms = trim($_REQUEST[$specific_field['code']]);
- if (!empty($sterms)) {
- $all_specific_terms .= ' '. $sterms;
- $sterms = explode(',', $sterms);
- foreach ($sterms as $sterm) {
- $ic_slide->addTerm(trim($sterm), $specific_field['code']);
- add_specific_field_value($specific_field['id'], $course_id, TOOL_QUIZ, $this->id, $sterm);
- }
- }
- }
- }
-
- $ic_slide->addValue("title", $this->exercise);
- $ic_slide->addCourseId($course_id);
- $ic_slide->addToolId(TOOL_QUIZ);
- $xapian_data = array(
- SE_COURSE_ID => $course_id,
- SE_TOOL_ID => TOOL_QUIZ,
- SE_DATA => array('type' => SE_DOCTYPE_EXERCISE_EXERCISE, 'exercise_id' => (int)$this->id),
- SE_USER => (int)api_get_user_id(),
- );
- $ic_slide->xapian_data = serialize($xapian_data);
- $exercise_description = $all_specific_terms .' '. $this->description;
- $ic_slide->addValue("content", $exercise_description);
- $di = new DokeosIndexer();
- isset($_POST['language'])? $lang=Database::escape_string($_POST['language']): $lang = 'english';
- $di->connectDb(NULL, NULL, $lang);
- $di->addChunk($ic_slide);
-
- $did = $di->index();
- if ($did) {
-
- $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
- $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, search_did)
- VALUES (NULL , \'%s\', \'%s\', %s, %s)';
- $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id, $did);
- api_sql_query($sql,__FILE__,__LINE__);
- }
- }
- function search_engine_edit() {
-
- if (api_get_setting('search_enabled')=='true' && extension_loaded('xapian')) {
- $course_id = api_get_course_id();
-
-
- $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
- $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s LIMIT 1';
- $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id);
- $res = api_sql_query($sql, __FILE__, __LINE__);
- if (Database::num_rows($res) > 0) {
- require_once(api_get_path(LIBRARY_PATH) . 'search/DokeosIndexer.class.php');
- require_once(api_get_path(LIBRARY_PATH) . 'search/IndexableChunk.class.php');
- require_once(api_get_path(LIBRARY_PATH) . 'specific_fields_manager.lib.php');
- $se_ref = Database::fetch_array($res);
- $specific_fields = get_specific_field_list();
- $ic_slide = new IndexableChunk();
- $all_specific_terms = '';
- foreach ($specific_fields as $specific_field) {
- delete_all_specific_field_value($course_id, $specific_field['id'], TOOL_QUIZ, $this->id);
- if (isset($_REQUEST[$specific_field['code']])) {
- $sterms = trim($_REQUEST[$specific_field['code']]);
- $all_specific_terms .= ' '. $sterms;
- $sterms = explode(',', $sterms);
- foreach ($sterms as $sterm) {
- $ic_slide->addTerm(trim($sterm), $specific_field['code']);
- add_specific_field_value($specific_field['id'], $course_id, TOOL_QUIZ, $this->id, $sterm);
- }
- }
- }
-
- $ic_slide->addValue("title", $this->exercise);
- $ic_slide->addCourseId($course_id);
- $ic_slide->addToolId(TOOL_QUIZ);
- $xapian_data = array(
- SE_COURSE_ID => $course_id,
- SE_TOOL_ID => TOOL_QUIZ,
- SE_DATA => array('type' => SE_DOCTYPE_EXERCISE_EXERCISE, 'exercise_id' => (int)$this->id),
- SE_USER => (int)api_get_user_id(),
- );
- $ic_slide->xapian_data = serialize($xapian_data);
- $exercise_description = $all_specific_terms .' '. $this->description;
- $ic_slide->addValue("content", $exercise_description);
- $di = new DokeosIndexer();
- isset($_POST['language'])? $lang=Database::escape_string($_POST['language']): $lang = 'english';
- $di->connectDb(NULL, NULL, $lang);
- $di->remove_document((int)$se_ref['search_did']);
- $di->addChunk($ic_slide);
-
- $did = $di->index();
- if ($did) {
-
- $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=\'%s\'';
- $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id);
- api_sql_query($sql,__FILE__,__LINE__);
-
- $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, search_did)
- VALUES (NULL , \'%s\', \'%s\', %s, %s)';
- $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id, $did);
- api_sql_query($sql,__FILE__,__LINE__);
- }
- }
- }
- }
- function search_engine_delete() {
-
- if (api_get_setting('search_enabled') == 'true' && extension_loaded('xapian') ) {
- $course_id = api_get_course_id();
- $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF);
- $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level IS NULL LIMIT 1';
- $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id);
- $res = api_sql_query($sql, __FILE__, __LINE__);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- require_once(api_get_path(LIBRARY_PATH) .'search/DokeosIndexer.class.php');
- $di = new DokeosIndexer();
- $di->remove_document((int)$row['search_did']);
- unset($di);
- $tbl_quiz_question = Database::get_course_table(TABLE_QUIZ_QUESTION);
- foreach ( $this->questionList as $question_i) {
- $sql = 'SELECT type FROM %s WHERE id=%s';
- $sql = sprintf($sql, $tbl_quiz_question, $question_i);
- $qres = api_sql_query($sql, __FILE__, __LINE__);
- if (Database::num_rows($qres) > 0) {
- $qrow = Database::fetch_array($qres);
- $objQuestion = Question::getInstance($qrow['type']);
- $objQuestion = Question::read((int)$question_i);
- $objQuestion->search_engine_edit($this->id, FALSE, TRUE);
- unset($objQuestion);
- }
- }
- }
- $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level IS NULL LIMIT 1';
- $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id);
- api_sql_query($sql, __FILE__, __LINE__);
-
- require_once(api_get_path(LIBRARY_PATH) .'specific_fields_manager.lib.php');
- delete_all_values_for_item($course_id, TOOL_QUIZ, $this->id);
- }
- }
- }
- endif;
- ?>
|