1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212 |
- <?php
- class Exercise
- {
- public $id;
- public $name;
- public $title;
- public $exercise;
- public $description;
- public $sound;
- public $type;
- public $random;
- public $random_answers;
- public $active;
- public $timeLimit;
- public $attempts;
- public $feedback_type;
- public $end_time;
- public $start_time;
- public $questionList;
- public $results_disabled;
- public $expired_time;
- public $course;
- public $course_id;
- public $propagate_neg;
- public $review_answers;
- public $randomByCat;
- public $text_when_finished;
- public $display_category_name;
- public $pass_percentage;
- public $edit_exercise_in_lp = false;
- public $is_gradebook_locked = false;
- public $exercise_was_added_in_lp = false;
- public $lpList = array();
- public $force_edit_exercise_in_lp = false;
- public $sessionId = 0;
- public $debug = false;
-
- public function __construct($course_id = null)
- {
- $this->id = 0;
- $this->exercise = '';
- $this->description = '';
- $this->sound = '';
- $this->type = ALL_ON_ONE_PAGE;
- $this->random = 0;
- $this->random_answers = 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;
- $this->expired_time = '0000-00-00 00:00:00';
- $this->propagate_neg = 0;
- $this->review_answers = false;
- $this->randomByCat = 0;
- $this->text_when_finished = '';
- $this->display_category_name = 0;
- $this->pass_percentage = '';
- if (!empty($course_id)) {
- $course_info = api_get_course_info_by_id($course_id);
- } else {
- $course_info = api_get_course_info();
- }
- $this->course_id = $course_info['real_id'];
- $this->course = $course_info;
- $this->sessionId = api_get_session_id();
- }
-
- public function read($id)
- {
- $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
- $table_lp_item = Database::get_course_table(TABLE_LP_ITEM);
- $id = intval($id);
- if (empty($this->course_id)) {
- return false;
- }
- $sql = "SELECT * FROM $TBL_EXERCISES WHERE c_id = ".$this->course_id." AND id = ".$id;
- $result = Database::query($sql);
-
- if ($object = Database::fetch_object($result)) {
- $this->id = $id;
- $this->exercise = $object->title;
- $this->name = $object->title;
- $this->title = $object->title;
- $this->description = $object->description;
- $this->sound = $object->sound;
- $this->type = $object->type;
- if (empty($this->type)) {
- $this->type = ONE_PER_PAGE;
- }
- $this->random = $object->random;
- $this->random_answers = $object->random_answers;
- $this->active = $object->active;
- $this->results_disabled = $object->results_disabled;
- $this->attempts = $object->max_attempt;
- $this->feedback_type = $object->feedback_type;
- $this->propagate_neg = $object->propagate_neg;
- $this->randomByCat = $object->random_by_category;
- $this->text_when_finished = $object->text_when_finished;
- $this->display_category_name = $object->display_category_name;
- $this->pass_percentage = $object->pass_percentage;
- $this->sessionId = $object->session_id;
- $this->is_gradebook_locked = api_resource_is_locked_by_gradebook($id, LINK_EXERCISE);
- $this->review_answers = (isset($object->review_answers) && $object->review_answers == 1) ? true : false;
- $sql = "SELECT lp_id, max_score
- FROM $table_lp_item
- WHERE c_id = {$this->course_id} AND
- item_type = '".TOOL_QUIZ."' AND
- path = '".$id."'";
- $result = Database::query($sql);
- if (Database::num_rows($result) > 0) {
- $this->exercise_was_added_in_lp = true;
- $this->lpList = Database::store_result($result, 'ASSOC');
- }
- $this->force_edit_exercise_in_lp = api_get_configuration_value('force_edit_exercise_in_lp');
- if ($this->exercise_was_added_in_lp) {
- $this->edit_exercise_in_lp = $this->force_edit_exercise_in_lp == true;
- } else {
- $this->edit_exercise_in_lp = true;
- }
- if ($object->end_time != '0000-00-00 00:00:00') {
- $this->end_time = $object->end_time;
- }
- if ($object->start_time != '0000-00-00 00:00:00') {
- $this->start_time = $object->start_time;
- }
-
- $this->expired_time = $object->expired_time;
-
- $this->questionList = $this->selectQuestionList(true);
-
-
-
-
- return true;
- }
- return false;
- }
-
- public function getCutTitle()
- {
- return cut($this->exercise, EXERCISE_MAX_NAME_SIZE);
- }
-
- public function selectId()
- {
- return $this->id;
- }
-
- public function selectTitle()
- {
- return $this->exercise;
- }
-
- public function selectAttempts()
- {
- return $this->attempts;
- }
-
- public function selectFeedbackType()
- {
- return $this->feedback_type;
- }
-
- public function selectTimeLimit()
- {
- return $this->timeLimit;
- }
-
- public function selectDescription()
- {
- return $this->description;
- }
-
- public function selectSound()
- {
- return $this->sound;
- }
-
- public function selectType()
- {
- return $this->type;
- }
-
- public function selectDisplayCategoryName()
- {
- return $this->display_category_name;
- }
-
- public function selectPassPercentage()
- {
- return $this->pass_percentage;
- }
-
- public function updateDisplayCategoryName($in_txt)
- {
- $this->display_category_name = $in_txt;
- }
-
- public function selectTextWhenFinished()
- {
- return $this->text_when_finished;
- }
-
- public function updateTextWhenFinished($in_txt)
- {
- $this->text_when_finished = $in_txt;
- }
-
- public function selectRandomByCat()
- {
- return $this->randomByCat;
- }
-
- public function isRandomByCat()
- {
- $res = 0;
- if ($this->randomByCat == 1) {
- $res = 1;
- } else if ($this->randomByCat == 2) {
- $res = 2;
- }
- return $res;
- }
-
- public function updateRandomByCat($in_randombycat)
- {
- if ($in_randombycat == 1) {
- $this->randomByCat = 1;
- } else if ($in_randombycat == 2) {
- $this->randomByCat = 2;
- } else {
- $this->randomByCat = 0;
- }
- }
-
- public function selectResultsDisabled()
- {
- return $this->results_disabled;
- }
-
- public function isRandom()
- {
- if($this->random > 0 || $this->random == -1) {
- return true;
- } else {
- return false;
- }
- }
-
- public function selectRandomAnswers()
- {
- return $this->random_answers;
- }
-
- public function getShuffle()
- {
- return $this->random;
- }
-
- public function selectStatus()
- {
- return $this->active;
- }
-
- public function selectQuestionList($from_db = false)
- {
- if ($from_db && !empty($this->id)) {
- $TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
- $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
- $sql = "SELECT DISTINCT e.question_order
- FROM $TBL_EXERCISE_QUESTION e
- INNER JOIN $TBL_QUESTIONS q
- ON (e.question_id = q.id AND e.c_id = ".$this->course_id." AND q.c_id = ".$this->course_id.")
- WHERE e.exercice_id = ".intval($this->id);
- $result = Database::query($sql);
- $count_question_orders = Database::num_rows($result);
- $sql = "SELECT DISTINCT e.question_id, e.question_order
- FROM $TBL_EXERCISE_QUESTION e
- INNER JOIN $TBL_QUESTIONS q
- ON (e.question_id= q.id AND e.c_id = ".$this->course_id." AND q.c_id = ".$this->course_id.")
- WHERE e.exercice_id = ".intval($this->id)."
- ORDER BY question_order";
- $result = Database::query($sql);
-
-
- $temp_question_list = array();
- $counter = 1;
- $question_list = array();
- while ($new_object = Database::fetch_object($result)) {
- $question_list[$new_object->question_order]= $new_object->question_id;
- $temp_question_list[$counter] = $new_object->question_id;
- $counter++;
- }
- if (!empty($temp_question_list)) {
- if (count($temp_question_list) != $count_question_orders) {
- $question_list = $temp_question_list;
- }
- }
- return $question_list;
- }
- return $this->questionList;
- }
-
- public function selectNbrQuestions()
- {
- return sizeof($this->questionList);
- }
-
- public function selectPropagateNeg()
- {
- return $this->propagate_neg;
- }
-
- public function selectRandomList()
- {
- $nbQuestions = $this->selectNbrQuestions();
- $temp_list = $this->questionList;
-
- if($this->random == 0 || $nbQuestions < 2) {
- return $this->questionList;
- }
- if ($nbQuestions != 0) {
- shuffle($temp_list);
- $my_random_list = array_combine(range(1,$nbQuestions),$temp_list);
- $my_question_list = array();
-
- if ($this->random > 0) {
- $i = 0;
- foreach ($my_random_list as $item) {
- if ($i < $this->random) {
- $my_question_list[$i] = $item;
- } else {
- break;
- }
- $i++;
- }
- } else {
- $my_question_list = $my_random_list;
- }
- return $my_question_list;
- }
- }
-
- public function isInList($questionId)
- {
- if (is_array($this->questionList))
- return in_array($questionId,$this->questionList);
- else
- return false;
- }
-
- public function updateTitle($title)
- {
- $this->exercise=$title;
- }
-
- public function updateAttempts($attempts)
- {
- $this->attempts=$attempts;
- }
-
- public function updateFeedbackType($feedback_type)
- {
- $this->feedback_type=$feedback_type;
- }
-
- public function updateDescription($description)
- {
- $this->description=$description;
- }
-
- public function updateExpiredTime($expired_time)
- {
- $this->expired_time = $expired_time;
- }
-
- public function updatePropagateNegative($value)
- {
- $this->propagate_neg = $value;
- }
-
- public function updateReviewAnswers($value)
- {
- $this->review_answers = isset($value) && $value ? true : false;
- }
-
- public function updatePassPercentage($value)
- {
- $this->pass_percentage = $value;
- }
-
- public function updateSound($sound,$delete)
- {
- global $audioPath, $documentPath;
- $TBL_DOCUMENT = Database::get_course_table(TABLE_DOCUMENT);
- 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 c_id = ".$this->course_id." AND path='".str_replace($documentPath,'',$audioPath).'/'.$this->sound."'";
- $result=Database::query($query);
- if (!Database::num_rows($result)) {
- $id = add_document(
- $this->course,
- str_replace($documentPath,'',$audioPath).'/'.$this->sound,
- 'file',
- $sound['size'],
- $sound['name']
- );
- api_item_property_update(
- $this->course,
- TOOL_DOCUMENT,
- $id,
- 'DocumentAdded',
- api_get_user_id()
- );
- item_property_update_on_folder(
- $this->course,
- str_replace($documentPath, '', $audioPath),
- api_get_user_id()
- );
- }
- }
- } elseif($delete && is_file($audioPath.'/'.$this->sound)) {
- $this->sound='';
- }
- }
-
- public function updateType($type)
- {
- $this->type=$type;
- }
-
- public function setRandom($random)
- {
-
- $this->random = $random;
- }
-
- public function updateRandomAnswers($random_answers)
- {
- $this->random_answers = $random_answers;
- }
-
- public function enable()
- {
- $this->active=1;
- }
-
- public function disable()
- {
- $this->active=0;
- }
-
- public function disable_results()
- {
- $this->results_disabled = true;
- }
-
- public function enable_results()
- {
- $this->results_disabled = false;
- }
-
- public function updateResultsDisabled($results_disabled)
- {
- $this->results_disabled = intval($results_disabled);
- }
-
- public function save($type_e = '')
- {
- $_course = $this->course;
- $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
- $id = $this->id;
- $exercise = $this->exercise;
- $description = $this->description;
- $sound = $this->sound;
- $type = $this->type;
- $attempts = isset($this->attempts) ? $this->attempts : 0;
- $feedback_type = isset($this->feedback_type) ? $this->feedback_type : 0;
- $random = $this->random;
- $random_answers = $this->random_answers;
- $active = $this->active;
- $propagate_neg = $this->propagate_neg;
- $review_answers = isset($this->review_answers) && $this->review_answers ? 1 : 0;
- $randomByCat = $this->randomByCat;
- $text_when_finished = $this->text_when_finished;
- $display_category_name = intval($this->display_category_name);
- $pass_percentage = intval($this->pass_percentage);
- $session_id = $this->sessionId;
-
- if ($feedback_type == EXERCISE_FEEDBACK_TYPE_DIRECT) {
- $results_disabled = 0;
- } else {
- $results_disabled = intval($this->results_disabled);
- }
- $expired_time = intval($this->expired_time);
-
- if ($id) {
-
- if (!empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00') {
- $start_time = $this->start_time;
- } else {
- $start_time = '0000-00-00 00:00:00';
- }
- if (!empty($this->end_time) && $this->end_time != '0000-00-00 00:00:00') {
- $end_time = $this->end_time;
- } else {
- $end_time = '0000-00-00 00:00:00';
- }
- $params = [
- 'title' => $exercise,
- 'description' => $description,
- ];
- $paramsExtra = [];
- if ($type_e != 'simple') {
- $paramsExtra = [
- 'sound' => $sound,
- 'type' => $type,
- 'random' => $random,
- 'random_answers' => $random_answers,
- 'active' => $active,
- 'feedback_type' => $feedback_type,
- 'start_time' => $start_time,
- 'end_time' => $end_time,
- 'max_attempt' => $attempts,
- 'expired_time' => $expired_time,
- 'propagate_neg' => $propagate_neg,
- 'review_answers' => $review_answers,
- 'random_by_category' => $randomByCat,
- 'text_when_finished' => $text_when_finished,
- 'display_category_name' => $display_category_name,
- 'pass_percentage' => $pass_percentage,
- 'results_disabled' => $results_disabled,
- ];
- }
- $params = array_merge($params, $paramsExtra);
- Database::update(
- $TBL_EXERCISES,
- $params,
- ['c_id = ? AND id = ?' => [$this->course_id, $id]]
- );
-
- api_item_property_update(
- $_course,
- TOOL_QUIZ,
- $id,
- 'QuizUpdated',
- api_get_user_id()
- );
- if (api_get_setting('search_enabled')=='true') {
- $this->search_engine_edit();
- }
- } else {
-
-
-
-
-
-
- if (!empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00') {
- $start_time = $this->start_time;
- } else {
- $start_time = '0000-00-00 00:00:00';
- }
- if (!empty($this->end_time) && $this->end_time != '0000-00-00 00:00:00') {
- $end_time = $this->end_time;
- } else {
- $end_time = '0000-00-00 00:00:00';
- }
- $params = [
- 'c_id' => $this->course_id,
- 'start_time' => $start_time,
- 'end_time' => $end_time,
- 'title' => $exercise,
- 'description' => $description,
- 'sound' => $sound,
- 'type' => $type,
- 'random' => $random,
- 'random_answers' => $random_answers,
- 'active' => $active,
- 'results_disabled' => $results_disabled,
- 'max_attempt' => $attempts,
- 'feedback_type' => $feedback_type,
- 'expired_time' => $expired_time,
- 'session_id' => $session_id,
- 'review_answers' => $review_answers,
- 'random_by_category' => $randomByCat,
- 'text_when_finished' => $text_when_finished,
- 'display_category_name' => $display_category_name,
- 'pass_percentage' => $pass_percentage
- ];
- $this->id = Database::insert($TBL_EXERCISES, $params);
- if ($this->id) {
- $sql = "UPDATE $TBL_EXERCISES SET id = iid WHERE iid = {$this->id} ";
- Database::query($sql);
-
- api_item_property_update(
- $this->course,
- TOOL_QUIZ,
- $this->id,
- 'QuizAdded',
- api_get_user_id()
- );
-
-
- api_set_default_visibility(
- $this->id,
- TOOL_QUIZ,
- null,
- $this->course
- );
- if (api_get_setting('search_enabled') == 'true' && extension_loaded('xapian')) {
- $this->search_engine_save();
- }
- }
- }
-
- $this->update_question_positions();
- }
-
- public function update_question_positions()
- {
- $quiz_question_table = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
-
- $question_list = $this->selectQuestionList(true);
- if (!empty($question_list)) {
- foreach ($question_list as $position => $questionId) {
- $sql = "UPDATE $quiz_question_table SET
- question_order ='".intval($position)."'
- WHERE
- c_id = ".$this->course_id." AND
- question_id = ".intval($questionId)." AND
- exercice_id=".intval($this->id);
- Database::query($sql);
- }
- }
- }
-
- public 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;
- }
-
- public function removeFromList($questionId)
- {
-
- $pos = array_search($questionId,$this->questionList);
-
- if ($pos === false) {
- return false;
- } else {
-
-
- if ($this->isRandom() && $this->isRandomByCat() == 0) {
- if (count($this->questionList) >= $this->random && $this->random > 0) {
- $this->random -= 1;
- $this->save();
- }
- }
-
- unset($this->questionList[$pos]);
- return true;
- }
- }
-
- public function delete()
- {
- $TBL_EXERCISES = Database::get_course_table(TABLE_QUIZ_TEST);
- $sql = "UPDATE $TBL_EXERCISES SET active='-1'
- WHERE c_id = ".$this->course_id." AND id = ".intval($this->id)."";
- Database::query($sql);
- api_item_property_update($this->course, TOOL_QUIZ, $this->id, 'QuizDeleted', api_get_user_id());
- api_item_property_update($this->course, TOOL_QUIZ, $this->id, 'delete', api_get_user_id());
- if (api_get_setting('search_enabled')=='true' && extension_loaded('xapian') ) {
- $this->search_engine_delete();
- }
- }
-
- public function createForm($form, $type='full')
- {
- 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'),
- array('id' => 'exercise_title')
- );
- $form->addElement('advanced_settings', 'advanced_params', get_lang('AdvancedParameters'));
- $form->addElement('html', '<div id="advanced_params_options" style="display:none">');
- $editor_config = array(
- 'ToolbarSet' => 'TestQuestionDescription',
- 'Width' => '100%',
- 'Height' => '150',
- );
- if (is_array($type)){
- $editor_config = array_merge($editor_config, $type);
- }
- $form->addHtmlEditor(
- 'exerciseDescription',
- get_lang('ExerciseDescription'),
- false,
- false,
- $editor_config
- );
- if ($type == 'full') {
-
- if ($this->selectFeedbackType() != EXERCISE_FEEDBACK_TYPE_DIRECT) {
-
- $radios_feedback = array();
- $radios_feedback[] = $form->createElement(
- 'radio',
- 'exerciseFeedbackType',
- null,
- get_lang('ExerciseAtTheEndOfTheTest'),
- '0',
- array(
- 'id' => 'exerciseType_0',
- 'onclick' => 'check_feedback()',
- )
- );
- if (api_get_setting('enable_quiz_scenario') == 'true') {
-
- if ($this->selectNbrQuestions() == 0) {
- $radios_feedback[] = $form->createElement(
- 'radio',
- 'exerciseFeedbackType',
- null,
- get_lang('DirectFeedback'),
- '1',
- array(
- 'id' => 'exerciseType_1',
- 'onclick' => 'check_direct_feedback()',
- )
- );
- }
- }
- $radios_feedback[] = $form->createElement(
- 'radio',
- 'exerciseFeedbackType',
- null,
- get_lang('NoFeedback'),
- '2',
- array('id' => 'exerciseType_2')
- );
- $form->addGroup($radios_feedback, null, array(get_lang('FeedbackType'),get_lang('FeedbackDisplayOptions')), '');
-
- $radios_results_disabled = array();
- $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id'=>'result_disabled_0'));
- $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1',array('id'=>'result_disabled_1','onclick' => 'check_results_disabled()'));
- $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2', array('id'=>'result_disabled_2'));
-
- $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'), '');
-
- $radios = array();
- $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id'=>'option_page_all'));
- $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'),'2', array('onclick' => 'check_per_page_one()', 'id'=>'option_page_one'));
- $form->addGroup($radios, null, get_lang('QuestionsPerPage'), '');
- } else {
-
- if ($this->selectNbrQuestions() == 0) {
-
- $radios_feedback = array();
- $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('ExerciseAtTheEndOfTheTest'),'0',array('id' =>'exerciseType_0', 'onclick' => 'check_feedback()'));
- if (api_get_setting('enable_quiz_scenario') == 'true') {
- $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('DirectFeedback'), '1', array('id' =>'exerciseType_1' , 'onclick' => 'check_direct_feedback()'));
- }
- $radios_feedback[] = $form->createElement('radio', 'exerciseFeedbackType', null, get_lang('NoFeedback'),'2',array('id' =>'exerciseType_2'));
- $form->addGroup($radios_feedback, null, array(get_lang('FeedbackType'),get_lang('FeedbackDisplayOptions')));
-
- $radios_results_disabled = array();
- $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id'=>'result_disabled_0'));
- $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1',array('id'=>'result_disabled_1','onclick' => 'check_results_disabled()'));
- $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2',array('id'=>'result_disabled_2','onclick' => 'check_results_disabled()'));
- $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'),'');
-
- $radios = array();
- $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1');
- $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'),'2');
- $form->addGroup($radios, null, get_lang('ExerciseType'));
- } else {
-
- $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('ShowScoreAndRightAnswer'), '0', array('id'=>'result_disabled_0'));
- $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('DoNotShowScoreNorRightAnswer'), '1',array('id'=>'result_disabled_1','onclick' => 'check_results_disabled()'));
- $radios_results_disabled[] = $form->createElement('radio', 'results_disabled', null, get_lang('OnlyShowScore'), '2',array('id'=>'result_disabled_2','onclick' => 'check_results_disabled()'));
- $result_disable_group = $form->addGroup($radios_results_disabled, null, get_lang('ShowResultsToStudents'),'');
- $result_disable_group->freeze();
-
- $form->addElement('hidden', 'exerciseFeedbackType', EXERCISE_FEEDBACK_TYPE_DIRECT);
- $form->addElement('hidden', 'exerciseType', ONE_PER_PAGE);
-
- $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SimpleExercise'), '1', array('onclick' => 'check_per_page_all()', 'id'=>'option_page_all'));
- $radios[] = $form->createElement('radio', 'exerciseType', null, get_lang('SequentialExercise'),'2', array('onclick' => 'check_per_page_one()', 'id'=>'option_page_one'));
- $type_group = $form->addGroup($radios, null, get_lang('QuestionsPerPage'), '');
- $type_group->freeze();
- }
- }
-
- $max = ($this->id > 0) ? $this->selectNbrQuestions() : 10 ;
- $option = range(0,$max);
- $option[0] = get_lang('No');
- $option[-1] = get_lang('AllQuestionsShort');
- $form->addElement('select', 'randomQuestions',array(get_lang('RandomQuestions'), get_lang('RandomQuestionsHelp')), $option, array('id'=>'randomQuestions'));
-
- $radios_random_answers = array();
- $radios_random_answers[] = $form->createElement('radio', 'randomAnswers', null, get_lang('Yes'),'1');
- $radios_random_answers[] = $form->createElement('radio', 'randomAnswers', null, get_lang('No'),'0');
- $form->addGroup($radios_random_answers, null, get_lang('RandomAnswers'), '');
-
- $form->addElement('html','<div class="clear"> </div>');
- $radiocat = array();
- $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('YesWithCategoriesShuffled'),'1');
- $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('YesWithCategoriesSorted'),'2');
- $radiocat[] = $form->createElement('radio', 'randomByCat', null, get_lang('No'),'0');
- $radioCatGroup = $form->addGroup($radiocat, null, get_lang('RandomQuestionByCategory'), '');
- $form->addElement('html','<div class="clear"> </div>');
-
- $radio_display_cat_name = array();
- $radio_display_cat_name[] = $form->createElement('radio', 'display_category_name', null, get_lang('Yes'), '1');
- $radio_display_cat_name[] = $form->createElement('radio', 'display_category_name', null, get_lang('No'), '0');
- $form->addGroup($radio_display_cat_name, null, get_lang('QuestionDisplayCategoryName'), '');
-
- $attempt_option = range(0, 10);
- $attempt_option[0] = get_lang('Infinite');
- $form->addElement(
- 'select',
- 'exerciseAttempts',
- get_lang('ExerciseAttempts'),
- $attempt_option,
- ['id' => 'exerciseAttempts']
- );
-
- $form->addElement('checkbox', 'activate_start_date_check',null, get_lang('EnableStartTime'), array('onclick' => 'activate_start_date()'));
- $var = Exercise::selectTimeLimit();
- if (($this->start_time != '0000-00-00 00:00:00'))
- $form->addElement('html','<div id="start_date_div" style="display:block;">');
- else
- $form->addElement('html','<div id="start_date_div" style="display:none;">');
- $form->addElement('date_time_picker', 'start_time');
- $form->addElement('html','</div>');
- $form->addElement('checkbox', 'activate_end_date_check', null , get_lang('EnableEndTime'), array('onclick' => 'activate_end_date()'));
- if (($this->end_time != '0000-00-00 00:00:00'))
- $form->addElement('html','<div id="end_date_div" style="display:block;">');
- else
- $form->addElement('html','<div id="end_date_div" style="display:none;">');
- $form->addElement('date_time_picker', 'end_time');
- $form->addElement('html','</div>');
-
- $diplay = 'block';
- $form->addElement('checkbox', 'propagate_neg', null, get_lang('PropagateNegativeResults'));
- $form->addElement('html','<div class="clear"> </div>');
- $form->addElement('checkbox', 'review_answers', null, get_lang('ReviewAnswers'));
- $form->addElement('html','<div id="divtimecontrol" style="display:'.$diplay.';">');
-
-
-
- $form->addElement(
- 'checkbox',
- 'enabletimercontrol',
- null,
- get_lang('EnableTimerControl'),
- array(
- 'onclick' => 'option_time_expired()',
- 'id' => 'enabletimercontrol',
- 'onload' => 'check_load_time()',
- )
- );
- $expired_date = (int)$this->selectExpiredTime();
- if (($expired_date!='0')) {
- $form->addElement('html','<div id="timercontrol" style="display:block;">');
- } else {
- $form->addElement('html','<div id="timercontrol" style="display:none;">');
- }
- $form->addText(
- 'enabletimercontroltotalminutes',
- get_lang('ExerciseTotalDurationInMinutes'),
- false,
- [
- 'id' => 'enabletimercontroltotalminutes',
- 'cols-size' => [2, 2, 8]
- ]
- );
- $form->addElement('html','</div>');
- $form->addElement(
- 'text',
- 'pass_percentage',
- array(get_lang('PassPercentage'), null, '%'),
- array('id' => 'pass_percentage')
- );
- $form->addRule('pass_percentage', get_lang('Numeric'), 'numeric');
-
- $form->addHtmlEditor(
- 'text_when_finished',
- get_lang('TextWhenFinished'),
- false,
- false,
- $editor_config
- );
- $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 ('select_language', 'language', get_lang('SearchFeatureDocumentLanguage'));
- $specific_fields = get_specific_field_list();
- foreach ($specific_fields as $specific_field) {
- $form->addElement ('text', $specific_field['code'], $specific_field['name']);
- $filter = array(
- 'c_id' => api_get_course_int_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>');
- $form->addElement('html','</div>');
- }
-
- if (isset($_GET['exerciseId'])) {
- $form->addButtonSave(get_lang('ModifyExercise'), 'submitExercise');
- } else {
- $form->addButtonUpdate(get_lang('ProcedToQuestions'), 'submitExercise');
- }
- $form->addRule('exerciseTitle', get_lang('GiveExerciseName'), 'required');
- if ($type == 'full') {
-
- $form->addRule('exerciseAttempts', get_lang('Numeric'), 'numeric');
- $form->addRule('start_time', get_lang('InvalidDate'), 'datetime');
- $form->addRule('end_time', get_lang('InvalidDate'), 'datetime');
- }
-
- if ($type=='full') {
- if ($this->id > 0) {
- if ($this->random > $this->selectNbrQuestions()) {
- $defaults['randomQuestions'] = $this->selectNbrQuestions();
- } else {
- $defaults['randomQuestions'] = $this->random;
- }
- $defaults['randomAnswers'] = $this->selectRandomAnswers();
- $defaults['exerciseType'] = $this->selectType();
- $defaults['exerciseTitle'] = $this->get_formated_title();
- $defaults['exerciseDescription'] = $this->selectDescription();
- $defaults['exerciseAttempts'] = $this->selectAttempts();
- $defaults['exerciseFeedbackType'] = $this->selectFeedbackType();
- $defaults['results_disabled'] = $this->selectResultsDisabled();
- $defaults['propagate_neg'] = $this->selectPropagateNeg();
- $defaults['review_answers'] = $this->review_answers;
- $defaults['randomByCat'] = $this->selectRandomByCat();
- $defaults['text_when_finished'] = $this->selectTextWhenFinished();
- $defaults['display_category_name'] = $this->selectDisplayCategoryName();
- $defaults['pass_percentage'] = $this->selectPassPercentage();
- if (($this->start_time != '0000-00-00 00:00:00')) {
- $defaults['activate_start_date_check'] = 1;
- }
- if ($this->end_time != '0000-00-00 00:00:00') {
- $defaults['activate_end_date_check'] = 1;
- }
- $defaults['start_time'] = ($this->start_time!='0000-00-00 00:00:00') ? api_get_local_time($this->start_time) : date('Y-m-d 12:00:00');
- $defaults['end_time'] = ($this->end_time!='0000-00-00 00:00:00') ? api_get_local_time($this->end_time) : date('Y-m-d 12:00:00', time()+84600);
-
- if ($this->expired_time != '0') {
- $defaults['enabletimercontrol'] = 1;
- $defaults['enabletimercontroltotalminutes'] = $this->expired_time;
- } else {
- $defaults['enabletimercontroltotalminutes'] = 0;
- }
- } else {
- $defaults['exerciseType'] = 2;
- $defaults['exerciseAttempts'] = 0;
- $defaults['randomQuestions'] = 0;
- $defaults['randomAnswers'] = 0;
- $defaults['exerciseDescription'] = '';
- $defaults['exerciseFeedbackType'] = 0;
- $defaults['results_disabled'] = 0;
- $defaults['randomByCat'] = 0;
- $defaults['text_when_finished'] = "";
- $defaults['start_time'] = date('Y-m-d 12:00:00');
- $defaults['display_category_name'] = 1;
- $defaults['end_time'] = date('Y-m-d 12:00:00', time()+84600);
- $defaults['pass_percentage'] = '';
- }
- } else {
- $defaults['exerciseTitle'] = $this->selectTitle();
- $defaults['exerciseDescription'] = $this->selectDescription();
- }
- if (api_get_setting('search_enabled') === 'true') {
- $defaults['index_document'] = 'checked="checked"';
- }
- $form->setDefaults($defaults);
-
- if ($this->id != 0 && $this->edit_exercise_in_lp == false) {
- $elementsToFreeze = array(
- 'randomQuestions',
-
- 'exerciseAttempts',
- 'propagate_neg',
- 'enabletimercontrol',
- 'review_answers'
- );
- foreach ($elementsToFreeze as $elementName) {
-
- $element = $form->getElement($elementName);
- $element->freeze();
- }
- $radioCatGroup->freeze();
- }
- }
-
- function processCreation($form, $type = '')
- {
- $this->updateTitle(Exercise::format_title_variable($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->updateRandomAnswers($form->getSubmitValue('randomAnswers'));
- $this->updateResultsDisabled($form->getSubmitValue('results_disabled'));
- $this->updateExpiredTime($form->getSubmitValue('enabletimercontroltotalminutes'));
- $this->updatePropagateNegative($form->getSubmitValue('propagate_neg'));
- $this->updateRandomByCat($form->getSubmitValue('randomByCat'));
- $this->updateTextWhenFinished($form->getSubmitValue('text_when_finished'));
- $this->updateDisplayCategoryName($form->getSubmitValue('display_category_name'));
- $this->updateReviewAnswers($form->getSubmitValue('review_answers'));
- $this->updatePassPercentage($form->getSubmitValue('pass_percentage'));
- if ($form->getSubmitValue('activate_start_date_check') == 1) {
- $start_time = $form->getSubmitValue('start_time');
- $this->start_time = api_get_utc_datetime($start_time);
- } else {
- $this->start_time = '0000-00-00 00:00:00';
- }
- if ($form->getSubmitValue('activate_end_date_check') == 1) {
- $end_time = $form->getSubmitValue('end_time');
- $this->end_time = api_get_utc_datetime($end_time);
- } else {
- $this->end_time = '0000-00-00 00:00:00';
- }
- if ($form->getSubmitValue('enabletimercontrol') == 1) {
- $expired_total_time = $form->getSubmitValue('enabletimercontroltotalminutes');
- if ($this->expired_time == 0) {
- $this->expired_time = $expired_total_time;
- }
- } else {
- $this->expired_time = 0;
- }
- if ($form->getSubmitValue('randomAnswers') == 1) {
- $this->random_answers=1;
- } else {
- $this->random_answers=0;
- }
- $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/ChamiloIndexer.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 ChamiloIndexer();
- 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);
- Database::query($sql);
- }
- }
- 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 = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- require_once(api_get_path(LIBRARY_PATH) . 'search/ChamiloIndexer.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 ChamiloIndexer();
- 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);
- Database::query($sql);
- $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);
- Database::query($sql);
- }
- } else {
- $this->search_engine_save();
- }
- }
- }
- 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 = Database::query($sql);
- if (Database::num_rows($res) > 0) {
- $row = Database::fetch_array($res);
- require_once(api_get_path(LIBRARY_PATH) .'search/ChamiloIndexer.class.php');
- $di = new ChamiloIndexer();
- $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 = Database::query($sql);
- 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);
- Database::query($sql);
-
- require_once api_get_path(LIBRARY_PATH) .'specific_fields_manager.lib.php';
- delete_all_values_for_item($course_id, TOOL_QUIZ, $this->id);
- }
- }
- function selectExpiredTime()
- {
- return $this->expired_time;
- }
-
- public function clean_results($cleanLpTests = false, $cleanResultBeforeDate = null)
- {
- $table_track_e_exercises = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
- $table_track_e_attempt = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
- $sql_where = ' AND
- orig_lp_id = 0 AND
- orig_lp_item_id = 0';
-
- if ($cleanLpTests) {
- $sql_where = "";
- }
-
-
- if (!empty($cleanResultBeforeDate)) {
- $cleanResultBeforeDate = Database::escape_string($cleanResultBeforeDate);
- if (api_is_valid_date($cleanResultBeforeDate)) {
- $sql_where .= " AND exe_date <= '$cleanResultBeforeDate' ";
- } else {
- return 0;
- }
- }
- $sql = "SELECT exe_id
- FROM $table_track_e_exercises
- WHERE
- c_id = ".api_get_course_int_id()." AND
- exe_exo_id = ".$this->id." AND
- session_id = ".api_get_session_id()." ".
- $sql_where;
- $result = Database::query($sql);
- $exe_list = Database::store_result($result);
-
-
- $i = 0;
- if (is_array($exe_list) && count($exe_list) > 0) {
- foreach ($exe_list as $item) {
- $sql = "DELETE FROM $table_track_e_attempt
- WHERE exe_id = '".$item['exe_id']."'";
- Database::query($sql);
- $i++;
- }
- }
- $session_id = api_get_session_id();
-
- $sql = "DELETE FROM $table_track_e_exercises
- WHERE c_id = ".api_get_course_int_id()."
- AND exe_exo_id = ".$this->id."
- $sql_where
- AND session_id = ".$session_id."";
- Database::query($sql);
- Event::addEvent(
- LOG_EXERCISE_RESULT_DELETE,
- LOG_EXERCISE_ID,
- $this->id,
- null,
- null,
- api_get_course_int_id(),
- $session_id
- );
- return $i;
- }
-
- public function copy_exercise()
- {
- $exercise_obj= new Exercise();
- $exercise_obj = $this;
-
- $exercise_obj->updateTitle($exercise_obj->selectTitle().' - '.get_lang('Copy'));
-
- $exercise_obj->updateStatus(false);
- $exercise_obj->updateId(0);
- $exercise_obj->save();
- $new_exercise_id = $exercise_obj->selectId();
- $question_list = $exercise_obj->selectQuestionList();
- if (!empty($question_list)) {
-
- foreach ($question_list as $old_question_id) {
- $old_question_obj = Question::read($old_question_id);
- $new_id = $old_question_obj->duplicate();
- if ($new_id) {
- $new_question_obj = Question::read($new_id);
- if (isset($new_question_obj) && $new_question_obj) {
- $new_question_obj->addToList($new_exercise_id);
-
- $new_answer_obj = new Answer($old_question_id);
- $new_answer_obj->read();
- $new_answer_obj->duplicate($new_id);
- }
- }
- }
- }
- }
-
- private function updateId($id)
- {
- $this->id = $id;
- }
-
- function updateStatus($status)
- {
- $this->active = $status;
- }
-
- public function get_stat_track_exercise_info(
- $lp_id = 0,
- $lp_item_id = 0,
- $lp_item_view_id = 0,
- $status = 'incomplete'
- ) {
- $track_exercises = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
- if (empty($lp_id)) {
- $lp_id = 0;
- }
- if (empty($lp_item_id)) {
- $lp_item_id = 0;
- }
- if (empty($lp_item_view_id)) {
- $lp_item_view_id = 0;
- }
- $condition = ' WHERE exe_exo_id = ' . "'" . $this->id . "'" .' AND
- exe_user_id = ' . "'" . api_get_user_id() . "'" . ' AND
- c_id = ' . api_get_course_int_id() . ' AND
- status = ' . "'" . Database::escape_string($status). "'" . ' AND
- orig_lp_id = ' . "'" . $lp_id . "'" . ' AND
- orig_lp_item_id = ' . "'" . $lp_item_id . "'" . ' AND
- orig_lp_item_view_id = ' . "'" . $lp_item_view_id . "'" . ' AND
- session_id = ' . "'" . api_get_session_id() . "' LIMIT 1";
- $sql_track = 'SELECT * FROM '.$track_exercises.$condition;
- $result = Database::query($sql_track);
- $new_array = array();
- if (Database::num_rows($result) > 0 ) {
- $new_array = Database::fetch_array($result, 'ASSOC');
- $new_array['num_exe'] = Database::num_rows($result);
- }
- return $new_array;
- }
-
- public function save_stat_track_exercise_info(
- $clock_expired_time = 0,
- $safe_lp_id = 0,
- $safe_lp_item_id = 0,
- $safe_lp_item_view_id = 0,
- $questionList = array(),
- $weight = 0
- ) {
- $track_exercises = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
- $safe_lp_id = intval($safe_lp_id);
- $safe_lp_item_id = intval($safe_lp_item_id);
- $safe_lp_item_view_id = intval($safe_lp_item_view_id);
- if (empty($safe_lp_id)) {
- $safe_lp_id = 0;
- }
- if (empty($safe_lp_item_id)) {
- $safe_lp_item_id = 0;
- }
- if (empty($clock_expired_time)) {
- $clock_expired_time = 0;
- }
- $questionList = array_map('intval', $questionList);
- $params = array(
- 'exe_exo_id' => $this->id ,
- 'exe_user_id' => api_get_user_id(),
- 'c_id' => api_get_course_int_id(),
- 'status' => 'incomplete',
- 'session_id' => api_get_session_id(),
- 'data_tracking' => implode(',', $questionList) ,
- 'start_date' => api_get_utc_datetime(),
- 'orig_lp_id' => $safe_lp_id,
- 'orig_lp_item_id' => $safe_lp_item_id,
- 'orig_lp_item_view_id' => $safe_lp_item_view_id,
- 'exe_weighting'=> $weight,
- 'user_ip' => api_get_real_ip()
- );
- if ($this->expired_time != 0) {
- $params['expired_time_control'] = $clock_expired_time;
- }
- $id = Database::insert($track_exercises, $params);
- return $id;
- }
-
- public function show_button($question_id, $questionNum, $questions_in_media = array(), $currentAnswer = '')
- {
- global $origin, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id;
- $nbrQuestions = $this->get_count_question_list();
- $all_button = $html = $label = '';
- $hotspot_get = isset($_POST['hotspot']) ? Security::remove_XSS($_POST['hotspot']):null;
- if ($this->selectFeedbackType() == EXERCISE_FEEDBACK_TYPE_DIRECT && $this->type == ONE_PER_PAGE) {
- $urlTitle = get_lang('ContinueTest');
- if ($questionNum == count($this->questionList)) {
- $urlTitle = get_lang('EndTest');
- }
- $html .= Display::url(
- $urlTitle,
- 'exercise_submit_modal.php?' . http_build_query([
- 'learnpath_id' => $safe_lp_id,
- 'learnpath_item_id' => $safe_lp_item_id,
- 'learnpath_item_view_id' => $safe_lp_item_view_id,
- 'origin' => $origin,
- 'hotspot' => $hotspot_get,
- 'nbrQuestions' => $nbrQuestions,
- 'num' => $questionNum,
- 'exerciseType' => $this->type,
- 'exerciseId' => $this->id
- ]),
- [
- 'class' => 'ajax btn btn-default',
- 'data-title' => $urlTitle,
- 'data-size' => 'md'
- ]
- );
- $html .='<br />';
- } else {
-
- if (api_is_allowed_to_session_edit()) {
- if ($this->type == ALL_ON_ONE_PAGE || $nbrQuestions == $questionNum) {
- if ($this->review_answers) {
- $label = get_lang('ReviewQuestions');
- $class = 'btn btn-success';
- } else {
- $label = get_lang('EndTest');
- $class = 'btn btn-warning';
- }
- } else {
- $label = get_lang('NextQuestion');
- $class = 'btn btn-primary';
- }
- $class .= ' question-validate-btn';
- if ($this->type == ONE_PER_PAGE) {
- if ($questionNum != 1) {
- $prev_question = $questionNum - 2;
- $all_button .= '<a href="javascript://" class="btn btn-default" onclick="previous_question_and_save('.$prev_question.', '.$question_id.' ); ">'.get_lang('PreviousQuestion').'</a>';
- }
-
- if (!empty($questions_in_media)) {
- $questions_in_media = "['".implode("','",$questions_in_media)."']";
- $all_button .= ' <a href="javascript://" class="'.$class.'" onclick="save_question_list('.$questions_in_media.'); ">'.$label.'</a>';
- } else {
- $all_button .= ' <a href="javascript://" class="'.$class.'" onclick="save_now('.$question_id.', \'\', \''.$currentAnswer.'\'); ">'.$label.'</a>';
- }
- $all_button .= '<span id="save_for_now_'.$question_id.'" class="exercise_save_mini_message"></span> ';
- $html .= $all_button;
- } else {
- if ($this->review_answers) {
- $all_label = get_lang('ReviewQuestions');
- $class = 'btn btn-success';
- } else {
- $all_label = get_lang('EndTest');
- $class = 'btn btn-warning';
- }
- $class .= ' question-validate-btn';
- $all_button = ' <a href="javascript://" class="'.$class.'" onclick="validate_all(); ">'.$all_label.'</a>';
- $all_button .= ' ' . Display::span(null, ['id' => 'save_all_reponse']);
- $html .= $all_button;
- }
- }
- }
- return $html;
- }
-
- public function show_time_control_js($time_left)
- {
- $time_left = intval($time_left);
- return "<script>
- function get_expired_date_string(expired_time) {
- var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
- var day, month, year, hours, minutes, seconds, date_string;
- var obj_date = new Date(expired_time);
- day = obj_date.getDate();
- if (day < 10) day = '0' + day;
- month = obj_date.getMonth();
- year = obj_date.getFullYear();
- hours = obj_date.getHours();
- if (hours < 10) hours = '0' + hours;
- minutes = obj_date.getMinutes();
- if (minutes < 10) minutes = '0' + minutes;
- seconds = obj_date.getSeconds();
- if (seconds < 10) seconds = '0' + seconds;
- date_string = months[month] +' ' + day + ', ' + year + ' ' + hours + ':' + minutes + ':' + seconds;
- return date_string;
- }
- function open_clock_warning() {
- $('#clock_warning').dialog({
- modal:true,
- height:250,
- closeOnEscape: false,
- resizable: false,
- buttons: {
- '".addslashes(get_lang("EndTest"))."': function() {
- $('#clock_warning').dialog('close');
- }
- },
- close: function() {
- send_form();
- }
- });
- $('#clock_warning').dialog('open');
- $('#counter_to_redirect').epiclock({
- mode: $.epiclock.modes.countdown,
- offset: {seconds: 5},
- format: 's'
- }).bind('timer', function () {
- send_form();
- });
- }
- function send_form() {
- if ($('#exercise_form').length) {
- $('#exercise_form').submit();
- } else {
- //In reminder
- final_submit();
- }
- }
- function onExpiredTimeExercise() {
- $('#wrapper-clock').hide();
- $('#exercise_form').hide();
- $('#expired-message-id').show();
- //Fixes bug #5263
- $('#num_current_id').attr('value', '".$this->selectNbrQuestions()."');
- open_clock_warning();
- }
- $(document).ready(function() {
- var current_time = new Date().getTime();
- var time_left = parseInt(".$time_left."); // time in seconds when using minutes there are some seconds lost
- var expired_time = current_time + (time_left*1000);
- var expired_date = get_expired_date_string(expired_time);
- $('#exercise_clock_warning').epiclock({
- mode: $.epiclock.modes.countdown,
- offset: {seconds: time_left},
- format: 'x:i:s',
- renderer: 'minute'
- }).bind('timer', function () {
- onExpiredTimeExercise();
- });
- $('#submit_save').click(function () {});
- });
- </script>";
- }
-
- public function show_lp_javascript()
- {
- return "";
- }
-
- public function manage_answer(
- $exeId,
- $questionId,
- $choice,
- $from = 'exercise_show',
- $exerciseResultCoordinates = array(),
- $saved_results = true,
- $from_database = false,
- $show_result = true,
- $propagate_neg = 0,
- $hotspot_delineation_result = array()
- ) {
- global $debug;
-
- global $learnpath_id, $learnpath_item_id;
- require_once api_get_path(LIBRARY_PATH).'geometry.lib.php';
- $em = Database::getManager();
- $feedback_type = $this->selectFeedbackType();
- $results_disabled = $this->selectResultsDisabled();
- if ($debug) {
- error_log("<------ manage_answer ------> ");
- error_log('exe_id: '.$exeId);
- error_log('$from: '.$from);
- error_log('$saved_results: '.intval($saved_results));
- error_log('$from_database: '.intval($from_database));
- error_log('$show_result: '.$show_result);
- error_log('$propagate_neg: '.$propagate_neg);
- error_log('$exerciseResultCoordinates: '.print_r($exerciseResultCoordinates, 1));
- error_log('$hotspot_delineation_result: '.print_r($hotspot_delineation_result, 1));
- error_log('$learnpath_id: '.$learnpath_id);
- error_log('$learnpath_item_id: '.$learnpath_item_id);
- error_log('$choice: '.print_r($choice, 1));
- }
- $extra_data = array();
- $final_overlap = 0;
- $final_missing = 0;
- $final_excess = 0;
- $overlap_color = 0;
- $missing_color = 0;
- $excess_color = 0;
- $threadhold1 = 0;
- $threadhold2 = 0;
- $threadhold3 = 0;
- $arrques = null;
- $arrans = null;
- $questionId = intval($questionId);
- $exeId = intval($exeId);
- $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
- $table_ans = Database::get_course_table(TABLE_QUIZ_ANSWER);
-
- $course_id = $this->course_id;
- $objQuestionTmp = Question::read($questionId, $course_id);
- if ($objQuestionTmp === false) {
- return false;
- }
- $questionName = $objQuestionTmp->selectTitle();
- $questionWeighting = $objQuestionTmp->selectWeighting();
- $answerType = $objQuestionTmp->selectType();
- $quesId = $objQuestionTmp->selectId();
- $extra = $objQuestionTmp->extra;
- $next = 1;
-
- if (!empty($extra)) {
- $extra = explode(':', $extra);
- if ($debug) {
- error_log(print_r($extra, 1));
- }
-
- $true_score = floatval(trim($extra[0]));
- $false_score = floatval(trim($extra[1]));
- $doubt_score = floatval(trim($extra[2]));
- }
- $totalWeighting = 0;
- $totalScore = 0;
-
- unset($objQuestionTmp);
-
- $objAnswerTmp = new Answer($questionId);
- $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
- if ($debug) {
- error_log('Count of answers: '.$nbrAnswers);
- error_log('$answerType: '.$answerType);
- }
- if ($answerType == FREE_ANSWER ||
- $answerType == ORAL_EXPRESSION ||
- $answerType == CALCULATED_ANSWER
- ) {
- $nbrAnswers = 1;
- }
- $nano = null;
- if ($answerType == ORAL_EXPRESSION) {
- $exe_info = Event::get_exercise_results_by_attempt($exeId);
- $exe_info = isset($exe_info[$exeId]) ? $exe_info[$exeId] : null;
- $params = array();
- $params['course_id'] = $course_id;
- $params['session_id'] = api_get_session_id();
- $params['user_id'] = isset($exe_info['exe_user_id'])? $exe_info['exe_user_id'] : api_get_user_id();
- $params['exercise_id'] = isset($exe_info['exe_exo_id'])? $exe_info['exe_exo_id'] : $this->id;
- $params['question_id'] = $questionId;
- $params['exe_id'] = isset($exe_info['exe_id']) ? $exe_info['exe_id'] : $exeId;
- $nano = new Nanogong($params);
-
- if ($feedback_type == 0) {
- $nano->replace_with_real_exe($exeId);
- }
- }
- $user_answer = '';
-
- $sql = "SELECT id_auto, id, answer
- FROM $table_ans
- WHERE c_id = $course_id AND question_id = $questionId";
- $res_answer = Database::query($sql);
- $answerMatching = array();
- while ($real_answer = Database::fetch_array($res_answer)) {
- $answerMatching[$real_answer['id_auto']] = $real_answer['answer'];
- }
- $real_answers = array();
- $quiz_question_options = Question::readQuestionOption(
- $questionId,
- $course_id
- );
- $organs_at_risk_hit = 0;
- $questionScore = 0;
- if ($debug) error_log('Start answer loop ');
- $answer_correct_array = array();
- $orderedHotspots = [];
- if ($answerType == HOT_SPOT) {
- $orderedHotspots = $em
- ->getRepository('ChamiloCoreBundle:TrackEHotspot')
- ->findBy([
- 'hotspotQuestionId' => $questionId,
- 'cId' => $course_id,
- 'hotspotExeId' => $exeId
- ],
- ['hotspotId' => 'ASC']
- );
- }
- for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
- $answer = $objAnswerTmp->selectAnswer($answerId);
- $answerComment = $objAnswerTmp->selectComment($answerId);
- $answerCorrect = $objAnswerTmp->isCorrect($answerId);
- $answerWeighting = (float)$objAnswerTmp->selectWeighting($answerId);
- $answerAutoId = $objAnswerTmp->selectAutoId($answerId);
- $answer_correct_array[$answerId] = (bool)$answerCorrect;
- if ($debug) {
- error_log("answer auto id: $answerAutoId ");
- error_log("answer correct: $answerCorrect ");
- }
-
- $delineation_cord = $objAnswerTmp->selectHotspotCoordinates(1);
- $answer_delineation_destination=$objAnswerTmp->selectDestination(1);
- switch ($answerType) {
-
- case UNIQUE_ANSWER:
- case UNIQUE_ANSWER_IMAGE:
- case UNIQUE_ANSWER_NO_OPTION:
- if ($from_database) {
- $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT
- WHERE
- exe_id = '".$exeId."' AND
- question_id= '".$questionId."'";
- $result = Database::query($sql);
- $choice = Database::result($result,0,"answer");
- $studentChoice = $choice == $answerAutoId ? 1 : 0;
- if ($studentChoice) {
- $questionScore += $answerWeighting;
- $totalScore += $answerWeighting;
- }
- } else {
- $studentChoice = $choice == $answerAutoId ? 1 : 0;
- if ($studentChoice) {
- $questionScore += $answerWeighting;
- $totalScore += $answerWeighting;
- }
- }
- break;
-
- case MULTIPLE_ANSWER_TRUE_FALSE:
- if ($from_database) {
- $choice = array();
- $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT
- WHERE
- exe_id = $exeId AND
- question_id = ".$questionId;
- $result = Database::query($sql);
- while ($row = Database::fetch_array($result)) {
- $ind = $row['answer'];
- $values = explode(':', $ind);
- $my_answer_id = isset($values[0]) ? $values[0] : '';
- $option = isset($values[1]) ? $values[1] : '';
- $choice[$my_answer_id] = $option;
- }
- }
- $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
- if (!empty($studentChoice)) {
- if ($studentChoice == $answerCorrect) {
- $questionScore += $true_score;
- } else {
- if ($quiz_question_options[$studentChoice]['name'] == "Don't know" ||
- $quiz_question_options[$studentChoice]['name'] == "DoubtScore"
- ) {
- $questionScore += $doubt_score;
- } else {
- $questionScore += $false_score;
- }
- }
- } else {
-
- $studentChoice = 3;
- $questionScore += $doubt_score;
- }
- $totalScore = $questionScore;
- break;
- case MULTIPLE_ANSWER:
- if ($from_database) {
- $choice = array();
- $sql = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
- WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'";
- $resultans = Database::query($sql);
- while ($row = Database::fetch_array($resultans)) {
- $ind = $row['answer'];
- $choice[$ind] = 1;
- }
- $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
- $real_answers[$answerId] = (bool)$studentChoice;
- if ($studentChoice) {
- $questionScore +=$answerWeighting;
- }
- } else {
- $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
- $real_answers[$answerId] = (bool)$studentChoice;
- if (isset($studentChoice)) {
- $questionScore += $answerWeighting;
- }
- }
- $totalScore += $answerWeighting;
- if ($debug) error_log("studentChoice: $studentChoice");
- break;
- case GLOBAL_MULTIPLE_ANSWER:
- if ($from_database) {
- $choice = array();
- $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT
- WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'";
- $resultans = Database::query($sql);
- while ($row = Database::fetch_array($resultans)) {
- $ind = $row['answer'];
- $choice[$ind] = 1;
- }
- $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
- $real_answers[$answerId] = (bool)$studentChoice;
- if ($studentChoice) {
- $questionScore +=$answerWeighting;
- }
- } else {
- $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
- if (isset($studentChoice)) {
- $questionScore += $answerWeighting;
- }
- $real_answers[$answerId] = (bool)$studentChoice;
- }
- $totalScore += $answerWeighting;
- if ($debug) error_log("studentChoice: $studentChoice");
- break;
- case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
- if ($from_database) {
- $sql = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
- WHERE exe_id = $exeId AND question_id= ".$questionId;
- $resultans = Database::query($sql);
- while ($row = Database::fetch_array($resultans)) {
- $ind = $row['answer'];
- $result = explode(':',$ind);
- if (isset($result[0])) {
- $my_answer_id = isset($result[0]) ? $result[0] : '';
- $option = isset($result[1]) ? $result[1] : '';
- $choice[$my_answer_id] = $option;
- }
- }
- $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : '';
- if ($answerCorrect == $studentChoice) {
-
- $real_answers[$answerId] = true;
- } else {
-
- $real_answers[$answerId] = false;
- }
- } else {
- $studentChoice = $choice[$answerAutoId];
- if ($answerCorrect == $studentChoice) {
-
- $real_answers[$answerId] = true;
- } else {
-
- $real_answers[$answerId] = false;
- }
- }
- break;
- case MULTIPLE_ANSWER_COMBINATION:
- if ($from_database) {
- $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT
- WHERE exe_id = $exeId AND question_id= $questionId";
- $resultans = Database::query($sql);
- while ($row = Database::fetch_array($resultans)) {
- $ind = $row['answer'];
- $choice[$ind] = 1;
- }
- $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
- if ($answerCorrect == 1) {
- if ($studentChoice) {
- $real_answers[$answerId] = true;
- } else {
- $real_answers[$answerId] = false;
- }
- } else {
- if ($studentChoice) {
- $real_answers[$answerId] = false;
- } else {
- $real_answers[$answerId] = true;
- }
- }
- } else {
- $studentChoice = isset($choice[$answerAutoId]) ? $choice[$answerAutoId] : null;
- if ($answerCorrect == 1) {
- if ($studentChoice) {
- $real_answers[$answerId] = true;
- } else {
- $real_answers[$answerId] = false;
- }
- } else {
- if ($studentChoice) {
- $real_answers[$answerId] = false;
- } else {
- $real_answers[$answerId] = true;
- }
- }
- }
- break;
- case FILL_IN_BLANKS:
- $str = '';
- if ($from_database) {
- $sql = "SELECT answer
- FROM $TBL_TRACK_ATTEMPT
- WHERE
- exe_id = $exeId AND
- question_id= ".intval($questionId);
- $result = Database::query($sql);
- $str = Database::result($result, 0, 'answer');
- }
- if ($saved_results == false && strpos($str, 'font color') !== false) {
-
-
-
-
-
-
- $pre_array = explode('::', $answer);
-
- $last = count($pre_array) - 1;
- $is_set_switchable = explode('@', $pre_array[$last]);
- $switchable_answer_set = false;
- if (isset ($is_set_switchable[1]) && $is_set_switchable[1] == 1) {
- $switchable_answer_set = true;
- }
- $answer = '';
- for ($k = 0; $k < $last; $k++) {
- $answer .= $pre_array[$k];
- }
-
- $answerWeighting = explode(',', $is_set_switchable[0]);
-
- $temp = $answer;
- $answer = '';
- $j = 0;
-
- $user_tags = $correct_tags = $real_text = array();
-
- while (1) {
-
- if (($pos = api_strpos($temp, '[')) === false) {
-
- $answer = $temp;
- $real_text[] = $answer;
- break;
- }
-
-
- $real_text[] = api_substr($temp, 0, $pos +1);
- $answer .= api_substr($temp, 0, $pos +1);
-
- $temp = api_substr($temp, $pos +1);
-
- if (($pos = api_strpos($temp, ']')) === false) {
-
- $answer .= $temp;
- break;
- }
- if ($from_database) {
- $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
- WHERE
- exe_id = '".$exeId."' AND
- question_id= ".intval($questionId)."";
- $resfill = Database::query($queryfill);
- $str = Database::result($resfill, 0, 'answer');
- api_preg_match_all('#\[([^[]*)\]#', $str, $arr);
- $str = str_replace('\r\n', '', $str);
- $choice = $arr[1];
- if (isset($choice[$j])) {
- $tmp = api_strrpos($choice[$j], ' / ');
- $choice[$j] = api_substr($choice[$j], 0, $tmp);
- $choice[$j] = trim($choice[$j]);
-
- $choice[$j] = stripslashes($choice[$j]);
- } else {
- $choice[$j] = null;
- }
- } else {
-
- $choice[$j] = api_htmlentities(trim($choice[$j]));
- }
- $user_tags[] = $choice[$j];
-
- $correct_tags[] = api_substr($temp, 0, $pos);
- $j++;
- $temp = api_substr($temp, $pos +1);
- }
- $answer = '';
- $real_correct_tags = $correct_tags;
- $chosen_list = array();
- for ($i = 0; $i < count($real_correct_tags); $i++) {
- if ($i == 0) {
- $answer .= $real_text[0];
- }
- if (!$switchable_answer_set) {
-
- $user_tags[$i] = stripslashes($user_tags[$i]);
- if ($correct_tags[$i] == $user_tags[$i]) {
-
- $questionScore += $answerWeighting[$i];
-
- $totalScore += $answerWeighting[$i];
-
- $answer .= $correct_tags[$i];
- } elseif (!empty($user_tags[$i])) {
-
-
- $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
- } else {
-
- $answer .= '';
- }
- } else {
-
- if (in_array($user_tags[$i], $correct_tags)) {
- $chosen_list[] = $user_tags[$i];
- $correct_tags = array_diff($correct_tags, $chosen_list);
-
- $questionScore += $answerWeighting[$i];
-
- $totalScore += $answerWeighting[$i];
-
- $answer .= $user_tags[$i];
- } elseif (!empty ($user_tags[$i])) {
-
-
- $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
- } else {
-
- $answer .= '';
- }
- }
-
- $answer .= ' / <font color="green"><b>' . $real_correct_tags[$i] . '</b></font>]';
- if (isset($real_text[$i +1])) {
- $answer .= $real_text[$i +1];
- }
- }
- } else {
-
-
-
- $listCorrectAnswers = FillBlanks::getAnswerInfo(
- $answer
- );
- $switchableAnswerSet = $listCorrectAnswers["switchable"];
- $answerWeighting = $listCorrectAnswers["tabweighting"];
-
-
- if ($from_database) {
- $sql = "SELECT answer
- FROM $TBL_TRACK_ATTEMPT
- WHERE
- exe_id = $exeId AND
- question_id= ".intval($questionId);
- $result = Database::query($sql);
- $str = Database::result($result, 0, 'answer');
- $listStudentResults = FillBlanks::getAnswerInfo(
- $str,
- true
- );
- $choice = $listStudentResults['studentanswer'];
- }
-
- if (!$switchableAnswerSet) {
-
- for ($i = 0; $i < count(
- $listCorrectAnswers['tabwords']
- ); $i++) {
- $studentAnswer = isset($choice[$i]) ? trim(
- $choice[$i]
- ) : '';
-
-
- if (!$from_database) {
- $studentAnswer = htmlentities(
- api_utf8_encode($studentAnswer)
- );
- }
- $correctAnswer = $listCorrectAnswers['tabwords'][$i];
- $isAnswerCorrect = 0;
- if (FillBlanks::isGoodStudentAnswer(
- $studentAnswer,
- $correctAnswer
- )
- ) {
-
- $questionScore += $answerWeighting[$i];
-
- $totalScore += $answerWeighting[$i];
- $isAnswerCorrect = 1;
- }
- $listCorrectAnswers['studentanswer'][$i] = $studentAnswer;
- $listCorrectAnswers['studentscore'][$i] = $isAnswerCorrect;
- }
- } else {
-
- $listStudentAnswerTemp = $choice;
- $listTeacherAnswerTemp = $listCorrectAnswers['tabwords'];
-
- for ($i = 0; $i < count(
- $listStudentAnswerTemp
- ); $i++) {
- $studentAnswer = trim(
- $listStudentAnswerTemp[$i]
- );
- $found = false;
- for ($j = 0; $j < count(
- $listTeacherAnswerTemp
- ); $j++) {
- $correctAnswer = $listTeacherAnswerTemp[$j];
- if (!$found) {
- if (FillBlanks::isGoodStudentAnswer(
- $studentAnswer,
- $correctAnswer
- )
- ) {
- $questionScore += $answerWeighting[$i];
- $totalScore += $answerWeighting[$i];
- $listTeacherAnswerTemp[$j] = "";
- $found = true;
- }
- }
- }
- $listCorrectAnswers['studentanswer'][$i] = $studentAnswer;
- if (!$found) {
- $listCorrectAnswers['studentscore'][$i] = 0;
- } else {
- $listCorrectAnswers['studentscore'][$i] = 1;
- }
- }
- }
- $answer = FillBlanks::getAnswerInStudentAttempt(
- $listCorrectAnswers
- );
- }
- break;
-
- case CALCULATED_ANSWER:
- $answer = $objAnswerTmp->selectAnswer($_SESSION['calculatedAnswerId'][$questionId]);
- $preArray = explode('@@', $answer);
- $last = count($preArray) - 1;
- $answer = '';
- for ($k = 0; $k < $last; $k++) {
- $answer .= $preArray[$k];
- }
- $answerWeighting = array($answerWeighting);
-
- $temp = $answer;
- $answer = '';
- $j = 0;
-
- $userTags = $correctTags = $realText = array();
-
- while (1) {
-
- if (($pos = api_strpos($temp, '[')) === false) {
-
- $answer = $temp;
- $realText[] = $answer;
- break;
- }
-
-
- $realText[] = api_substr($temp, 0, $pos +1);
- $answer .= api_substr($temp, 0, $pos +1);
-
- $temp = api_substr($temp, $pos +1);
-
- if (($pos = api_strpos($temp, ']')) === false) {
-
- $answer .= $temp;
- break;
- }
- if ($from_database) {
- $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT."
- WHERE
- exe_id = '".$exeId."' AND
- question_id= ".intval($questionId)."";
- $resfill = Database::query($queryfill);
- $str = Database::result($resfill, 0, 'answer');
- api_preg_match_all('#\[([^[]*)\]#', $str, $arr);
- $str = str_replace('\r\n', '', $str);
- $choice = $arr[1];
- if (isset($choice[$j])) {
- $tmp = api_strrpos($choice[$j], ' / ');
- $choice[$j] = api_substr($choice[$j], 0, $tmp);
- $choice[$j] = trim($choice[$j]);
-
- $choice[$j] = stripslashes($choice[$j]);
- } else {
- $choice[$j] = null;
- }
- } else {
-
- $choice[$j] = api_htmlentities(trim($choice[$j]));
- }
- $userTags[] = $choice[$j];
-
- $correctTags[] = api_substr($temp, 0, $pos);
- $j++;
- $temp = api_substr($temp, $pos +1);
- }
- $answer = '';
- $realCorrectTags = $correctTags;
- for ($i = 0; $i < count($realCorrectTags); $i++) {
- if ($i == 0) {
- $answer .= $realText[0];
- }
-
- $userTags[$i] = stripslashes($userTags[$i]);
- if ($correctTags[$i] == $userTags[$i]) {
-
- $questionScore += $answerWeighting[$i];
-
- $totalScore += $answerWeighting[$i];
-
- $answer .= $correctTags[$i];
- } elseif (!empty($userTags[$i])) {
-
-
- $answer .= '<font color="red"><s>' . $userTags[$i] . '</s></font>';
- } else {
-
- $answer .= '';
- }
-
- $answer .= ' / <font color="green"><b>' . $realCorrectTags[$i] . '</b></font>]';
- if (isset($realText[$i +1])) {
- $answer .= $realText[$i +1];
- }
- }
- break;
-
- case FREE_ANSWER:
- if ($from_database) {
- $query = "SELECT answer, marks FROM ".$TBL_TRACK_ATTEMPT."
- WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'";
- $resq = Database::query($query);
- $data = Database::fetch_array($resq);
- $choice = $data['answer'];
- $choice = str_replace('\r\n', '', $choice);
- $choice = stripslashes($choice);
- $questionScore = $data['marks'];
- if ($questionScore == -1) {
- $totalScore+= 0;
- } else {
- $totalScore+= $questionScore;
- }
- if ($questionScore == '') {
- $questionScore = 0;
- }
- $arrques = $questionName;
- $arrans = $choice;
- } else {
- $studentChoice = $choice;
- if ($studentChoice) {
-
- $questionScore = 0;
- $totalScore += 0;
- }
- }
- break;
- case ORAL_EXPRESSION:
- if ($from_database) {
- $query = "SELECT answer, marks FROM ".$TBL_TRACK_ATTEMPT."
- WHERE exe_id = '".$exeId."' AND question_id= '".$questionId."'";
- $resq = Database::query($query);
- $choice = Database::result($resq,0,'answer');
- $choice = str_replace('\r\n', '', $choice);
- $choice = stripslashes($choice);
- $questionScore = Database::result($resq,0,"marks");
- if ($questionScore==-1) {
- $totalScore+=0;
- } else {
- $totalScore+=$questionScore;
- }
- $arrques = $questionName;
- $arrans = $choice;
- } else {
- $studentChoice = $choice;
- if ($studentChoice) {
-
- $questionScore = 0;
- $totalScore += 0;
- }
- }
- break;
- case DRAGGABLE:
-
- case MATCHING_DRAGGABLE:
-
- case MATCHING:
- if ($from_database) {
- $sql = 'SELECT id, answer, id_auto
- FROM '.$table_ans.'
- WHERE
- c_id = '.$course_id.' AND
- question_id = "'.$questionId.'" AND
- correct = 0';
- $res_answer = Database::query($sql);
-
- $real_list = array();
- while ($real_answer = Database::fetch_array($res_answer)) {
- $real_list[$real_answer['id_auto']] = $real_answer['answer'];
- }
- $sql = 'SELECT id, answer, correct, id_auto, ponderation
- FROM '.$table_ans.'
- WHERE
- c_id = '.$course_id.' AND
- question_id="'.$questionId.'" AND
- correct <> 0
- ORDER BY id_auto';
- $res_answers = Database::query($sql);
- $questionScore = 0;
- while ($a_answers = Database::fetch_array($res_answers)) {
- $i_answer_id = $a_answers['id'];
- $s_answer_label = $a_answers['answer'];
- $i_answer_correct_answer = $a_answers['correct'];
- $i_answer_id_auto = $a_answers['id_auto'];
- $sql = "SELECT answer FROM $TBL_TRACK_ATTEMPT
- WHERE
- exe_id = '$exeId' AND
- question_id = '$questionId' AND
- position = '$i_answer_id_auto'";
- $res_user_answer = Database::query($sql);
- if (Database::num_rows($res_user_answer) > 0) {
-
- $s_user_answer = Database::result($res_user_answer, 0, 0);
- } else {
- $s_user_answer = 0;
- }
- $i_answerWeighting = $a_answers['ponderation'];
- $user_answer = '';
- if (!empty($s_user_answer)) {
- if ($answerType == DRAGGABLE) {
- if ($s_user_answer == $i_answer_correct_answer) {
- $questionScore += $i_answerWeighting;
- $totalScore += $i_answerWeighting;
- $user_answer = Display::label(get_lang('Correct'), 'success');
- } else {
- $user_answer = Display::label(get_lang('Incorrect'), 'danger');
- }
- } else {
- if ($s_user_answer == $i_answer_correct_answer) {
- $questionScore += $i_answerWeighting;
- $totalScore += $i_answerWeighting;
- if (isset($real_list[$i_answer_id])) {
- $user_answer = Display::span($real_list[$i_answer_id]);
- }
- } else {
- $user_answer = Display::span(
- $real_list[$s_user_answer],
- ['style' => 'color: #FF0000; text-decoration: line-through;']
- );
- }
- }
- } elseif ($answerType == DRAGGABLE) {
- $user_answer = Display::label(get_lang('Incorrect'), 'danger');
- }
- if ($show_result) {
- echo '<tr>';
- echo '<td>' . $s_answer_label . '</td>';
- echo '<td>' . $user_answer;
- if (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) {
- if (isset($real_list[$i_answer_correct_answer])) {
- echo Display::span(
- $real_list[$i_answer_correct_answer],
- ['style' => 'color: #008000; font-weight: bold;']
- );
- }
- }
- echo '</td>';
- echo '</tr>';
- }
- }
- break(2);
- } else {
- if ($answerCorrect) {
- if (isset($choice[$answerAutoId]) &&
- $answerCorrect == $choice[$answerAutoId]
- ) {
- $questionScore += $answerWeighting;
- $totalScore += $answerWeighting;
- $user_answer = Display::span($answerMatching[$choice[$answerAutoId]]);
- } else {
- if (isset($answerMatching[$choice[$answerAutoId]])) {
- $user_answer = Display::span(
- $answerMatching[$choice[$answerAutoId]],
- ['style' => 'color: #FF0000; text-decoration: line-through;']
- );
- }
- }
- $matching[$answerAutoId] = $choice[$answerAutoId];
- }
- break;
- }
- case HOT_SPOT:
- if ($from_database) {
- $TBL_TRACK_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
- $sql = "SELECT hotspot_correct
- FROM $TBL_TRACK_HOTSPOT
- WHERE
- hotspot_exe_id = '".$exeId."' AND
- hotspot_question_id= '".$questionId."' AND
- hotspot_answer_id = ".intval($answerAutoId)."";
- $result = Database::query($sql);
- $studentChoice = Database::result($result, 0, "hotspot_correct");
- if ($studentChoice) {
- $questionScore += $answerWeighting;
- $totalScore += $answerWeighting;
- }
- } else {
- if (!isset($choice[$answerAutoId])) {
- $choice[$answerAutoId] = 0;
- } else {
- $studentChoice = $choice[$answerAutoId];
- $choiceIsValid = false;
- if (!empty($studentChoice)) {
- $hotspotType = $objAnswerTmp->selectHotspotType($answerId);
- $hotspotCoordinates = $objAnswerTmp->selectHotspotCoordinates($answerId);
- $choicePoint = Geometry::decodePoint($studentChoice);
- switch ($hotspotType) {
- case 'square':
- $hotspotProperties = Geometry::decodeSquare($hotspotCoordinates);
- $choiceIsValid = Geometry::pointIsInSquare($hotspotProperties, $choicePoint);
- break;
- case 'circle':
- $hotspotProperties = Geometry::decodeEllipse($hotspotCoordinates);
- $choiceIsValid = Geometry::pointIsInEllipse($hotspotProperties, $choicePoint);
- break;
- case 'poly':
- $hotspotProperties = Geometry::decodePolygon($hotspotCoordinates);
- $choiceIsValid = Geometry::pointIsInPolygon($hotspotProperties, $choicePoint);
- break;
- }
- }
- $choice[$answerAutoId] = 0;
- if ($choiceIsValid) {
- $questionScore += $answerWeighting;
- $totalScore += $answerWeighting;
- $choice[$answerAutoId] = 1;
- }
- }
- }
- break;
-
-
- case HOT_SPOT_ORDER :
- $studentChoice = $choice['order'][$answerId];
- if ($studentChoice == $answerId) {
- $questionScore += $answerWeighting;
- $totalScore += $answerWeighting;
- $studentChoice = true;
- } else {
- $studentChoice = false;
- }
- break;
-
- case HOT_SPOT_DELINEATION :
- if ($from_database) {
-
- $TBL_TRACK_HOTSPOT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
- $query = "SELECT hotspot_correct, hotspot_coordinate
- FROM $TBL_TRACK_HOTSPOT
- WHERE
- hotspot_exe_id = '".$exeId."' AND
- hotspot_question_id= '".$questionId."' AND
- hotspot_answer_id='1'";
-
- $resq = Database::query($query);
- $row = Database::fetch_array($resq,'ASSOC');
- $choice = $row['hotspot_correct'];
- $user_answer = $row['hotspot_coordinate'];
-
-
- $coords = explode('/',$user_answer);
- $user_array = '';
- foreach ($coords as $coord) {
- list($x,$y) = explode(';',$coord);
- $user_array .= round($x).';'.round($y).'/';
- }
- $user_array = substr($user_array,0,-1);
- } else {
- if (!empty($studentChoice)) {
- $newquestionList[] = $questionId;
- }
- if ($answerId === 1) {
- $studentChoice = $choice[$answerId];
- $questionScore += $answerWeighting;
- if ($hotspot_delineation_result[1]==1) {
- $totalScore += $answerWeighting;
- }
- }
- }
- $_SESSION['hotspot_coord'][1] = $delineation_cord;
- $_SESSION['hotspot_dest'][1] = $answer_delineation_destination;
- break;
- }
- if ($show_result) {
- if ($debug) error_log('show result '.$show_result);
- if ($from == 'exercise_result') {
- if ($debug) error_log('Showing questions $from '.$from);
-
- if (
- !in_array(
- $answerType,
- [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE]
- ) ||
- $answerCorrect
- ) {
- if (
- in_array(
- $answerType,
- array(
- UNIQUE_ANSWER,
- UNIQUE_ANSWER_IMAGE,
- UNIQUE_ANSWER_NO_OPTION,
- MULTIPLE_ANSWER,
- MULTIPLE_ANSWER_COMBINATION,
- GLOBAL_MULTIPLE_ANSWER
- )
- )
- ) {
-
- ExerciseShowFunctions::display_unique_or_multiple_answer(
- $feedback_type,
- $answerType,
- $studentChoice,
- $answer,
- $answerComment,
- $answerCorrect,
- 0,
- 0,
- 0,
- $results_disabled
- );
-
- } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
-
- ExerciseShowFunctions::display_multiple_answer_true_false(
- $feedback_type,
- $answerType,
- $studentChoice,
- $answer,
- $answerComment,
- $answerCorrect,
- 0,
- $questionId,
- 0,
- $results_disabled
- );
-
- } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) {
-
- ExerciseShowFunctions::display_multiple_answer_combination_true_false(
- $feedback_type,
- $answerType,
- $studentChoice,
- $answer,
- $answerComment,
- $answerCorrect,
- 0,
- 0,
- 0,
- $results_disabled
- );
-
- } elseif ($answerType == FILL_IN_BLANKS) {
-
- ExerciseShowFunctions::display_fill_in_blanks_answer($feedback_type, $answer,0,0, $results_disabled);
-
- } elseif ($answerType == CALCULATED_ANSWER) {
-
- ExerciseShowFunctions::display_calculated_answer($feedback_type, $answer,0,0);
-
- } elseif ($answerType == FREE_ANSWER) {
-
- ExerciseShowFunctions::display_free_answer(
- $feedback_type,
- $choice,
- $exeId,
- $questionId,
- $questionScore
- );
-
- } elseif ($answerType == ORAL_EXPRESSION) {
-
-
- ExerciseShowFunctions::display_oral_expression_answer(
- $feedback_type,
- $choice,
- 0,
- 0,
- $nano);
-
- } elseif ($answerType == HOT_SPOT) {
-
- foreach ($orderedHotspots as $correctAnswerId => $hotspot) {
- if ($hotspot->getHotspotAnswerId() == $answerAutoId) {
- break;
- }
- }
- ExerciseShowFunctions::display_hotspot_answer(
- $feedback_type,
- ++$correctAnswerId,
- $answer,
- $studentChoice,
- $answerComment,
- $results_disabled,
- $answerId
- );
-
- } elseif ($answerType == HOT_SPOT_ORDER) {
-
- ExerciseShowFunctions::display_hotspot_order_answer(
- $feedback_type,
- $answerId,
- $answer,
- $studentChoice,
- $answerComment
- );
-
- } elseif ($answerType == HOT_SPOT_DELINEATION) {
- $user_answer = $_SESSION['exerciseResultCoordinates'][$questionId];
-
- $coords = explode('/',$user_answer);
- $user_array = '';
- foreach ($coords as $coord) {
- list($x,$y) = explode(';',$coord);
- $user_array .= round($x).';'.round($y).'/';
- }
- $user_array = substr($user_array,0,-1);
- if ($next) {
- $user_answer = $user_array;
-
- $answer_question = $_SESSION['hotspot_coord'][1];
- $answerDestination = $_SESSION['hotspot_dest'][1];
-
- $poly_user = convert_coordinates($user_answer, '/');
- $poly_answer = convert_coordinates($answer_question, '|');
- $max_coord = poly_get_max($poly_user, $poly_answer);
- $poly_user_compiled = poly_compile($poly_user, $max_coord);
- $poly_answer_compiled = poly_compile($poly_answer, $max_coord);
- $poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord);
- $overlap = $poly_results['both'];
- $poly_answer_area = $poly_results['s1'];
- $poly_user_area = $poly_results['s2'];
- $missing = $poly_results['s1Only'];
- $excess = $poly_results['s2Only'];
-
-
- if ($debug > 0) {
- error_log(__LINE__ . ' - Polygons results are ' . print_r($poly_results, 1), 0);
- }
- if ($overlap < 1) {
-
- $final_overlap = 0;
- $final_missing = 100;
- $final_excess = 100;
- } else {
-
-
- $final_overlap = round(((float) $overlap / (float) $poly_answer_area) * 100);
- if ($debug > 1) {
- error_log(__LINE__ . ' - Final overlap is ' . $final_overlap, 0);
- }
-
-
- $final_missing = 100 - $final_overlap;
- if ($debug > 1) {
- error_log(__LINE__ . ' - Final missing is ' . $final_missing, 0);
- }
-
-
- $final_excess = round((((float) $poly_user_area - (float) $overlap) / (float) $poly_answer_area) * 100);
- if ($debug > 1) {
- error_log(__LINE__ . ' - Final excess is ' . $final_excess, 0);
- }
- }
-
- $destination_items= explode('@@', $answerDestination);
- $threadhold_total = $destination_items[0];
- $threadhold_items=explode(';',$threadhold_total);
- $threadhold1 = $threadhold_items[0];
- $threadhold2 = $threadhold_items[1];
- $threadhold3 = $threadhold_items[2];
-
- if ($answerId===1) {
-
- if ($final_overlap>=$threadhold1) {
- $overlap_color=true;
- }
-
- if ($final_excess<=$threadhold2) {
- $excess_color=true;
- }
-
- if ($final_missing<=$threadhold3) {
- $missing_color=true;
- }
-
- if (
- $final_overlap >= $threadhold1 &&
- $final_missing <= $threadhold3 &&
- $final_excess <= $threadhold2
- ) {
- $next=1;
- $result_comment=get_lang('Acceptable');
- $final_answer = 1;
- } else {
- $next=0;
- $result_comment=get_lang('Unacceptable');
- $comment=$answerDestination=$objAnswerTmp->selectComment(1);
- $answerDestination=$objAnswerTmp->selectDestination(1);
-
- $destination_items= explode('@@', $answerDestination);
- }
- } elseif($answerId>1) {
- if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') {
- if ($debug>0) {
- error_log(__LINE__.' - answerId is of type noerror',0);
- }
-
- $next = 1;
- continue;
- }
- if ($debug>0) {
- error_log(__LINE__.' - answerId is >1 so we\'re probably in OAR',0);
- }
-
-
-
-
- $inter= $result['success'];
-
- $delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId);
- $poly_answer = convert_coordinates($delineation_cord,'|');
- $max_coord = poly_get_max($poly_user,$poly_answer);
- $poly_answer_compiled = poly_compile($poly_answer,$max_coord);
- $overlap = poly_touch($poly_user_compiled, $poly_answer_compiled,$max_coord);
- if ($overlap == false) {
-
- $next = 1;
- continue;
- } else {
- if ($debug>0) {
- error_log(__LINE__.' - Overlap is '.$overlap.': OAR hit',0);
- }
- $organs_at_risk_hit++;
-
- $next=0;
- $comment=$answerDestination=$objAnswerTmp->selectComment($answerId);
- $answerDestination=$objAnswerTmp->selectDestination($answerId);
- $destination_items= explode('@@', $answerDestination);
- $try_hotspot=$destination_items[1];
- $lp_hotspot=$destination_items[2];
- $select_question_hotspot=$destination_items[3];
- $url_hotspot=$destination_items[4];
- }
- }
- } else {
- if ($debug>0) {
- error_log(__LINE__.' first',0);
- }
- }
- } elseif (in_array($answerType, [MATCHING, MATCHING_DRAGGABLE])) {
- echo '<tr>';
- echo Display::tag('td', $answerMatching[$answerId]);
- echo Display::tag(
- 'td',
- "$user_answer / " . Display::tag(
- 'strong',
- $answerMatching[$answerCorrect],
- ['style' => 'color: #008000; font-weight: bold;']
- )
- );
- echo '</tr>';
- }
- }
- } else {
- if ($debug) error_log('Showing questions $from '.$from);
- switch ($answerType) {
- case UNIQUE_ANSWER:
- case UNIQUE_ANSWER_IMAGE:
- case UNIQUE_ANSWER_NO_OPTION:
- case MULTIPLE_ANSWER:
- case GLOBAL_MULTIPLE_ANSWER :
- case MULTIPLE_ANSWER_COMBINATION:
- if ($answerId == 1) {
- ExerciseShowFunctions::display_unique_or_multiple_answer(
- $feedback_type,
- $answerType,
- $studentChoice,
- $answer,
- $answerComment,
- $answerCorrect,
- $exeId,
- $questionId,
- $answerId,
- $results_disabled
- );
- } else {
- ExerciseShowFunctions::display_unique_or_multiple_answer(
- $feedback_type,
- $answerType,
- $studentChoice,
- $answer,
- $answerComment,
- $answerCorrect,
- $exeId,
- $questionId,
- "",
- $results_disabled
- );
- }
- break;
- case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
- if ($answerId == 1) {
- ExerciseShowFunctions::display_multiple_answer_combination_true_false(
- $feedback_type,
- $answerType,
- $studentChoice,
- $answer,
- $answerComment,
- $answerCorrect,
- $exeId,
- $questionId,
- $answerId,
- $results_disabled
- );
- } else {
- ExerciseShowFunctions::display_multiple_answer_combination_true_false(
- $feedback_type,
- $answerType,
- $studentChoice,
- $answer,
- $answerComment,
- $answerCorrect,
- $exeId,
- $questionId,
- "",
- $results_disabled
- );
- }
- break;
- case MULTIPLE_ANSWER_TRUE_FALSE:
- if ($answerId == 1) {
- ExerciseShowFunctions::display_multiple_answer_true_false(
- $feedback_type,
- $answerType,
- $studentChoice,
- $answer,
- $answerComment,
- $answerCorrect,
- $exeId,
- $questionId,
- $answerId,
- $results_disabled
- );
- } else {
- ExerciseShowFunctions::display_multiple_answer_true_false(
- $feedback_type,
- $answerType,
- $studentChoice,
- $answer,
- $answerComment,
- $answerCorrect,
- $exeId,
- $questionId,
- "",
- $results_disabled
- );
- }
- break;
- case FILL_IN_BLANKS:
- ExerciseShowFunctions::display_fill_in_blanks_answer(
- $feedback_type,
- $answer,
- $exeId,
- $questionId,
- $results_disabled,
- $str
- );
- break;
- case CALCULATED_ANSWER:
- ExerciseShowFunctions::display_calculated_answer(
- $feedback_type,
- $answer,
- $exeId,
- $questionId
- );
- break;
- case FREE_ANSWER:
- echo ExerciseShowFunctions::display_free_answer(
- $feedback_type,
- $choice,
- $exeId,
- $questionId,
- $questionScore
- );
- break;
- case ORAL_EXPRESSION:
- echo '<tr>
- <td valign="top">' . ExerciseShowFunctions::display_oral_expression_answer(
- $feedback_type,
- $choice,
- $exeId,
- $questionId,
- $nano
- ) . '</td>
- </tr>
- </table>';
- break;
- case HOT_SPOT:
- ExerciseShowFunctions::display_hotspot_answer(
- $feedback_type,
- $answerId,
- $answer,
- $studentChoice,
- $answerComment,
- $results_disabled);
- break;
- case HOT_SPOT_DELINEATION:
- $user_answer = $user_array;
- if ($next) {
-
-
-
- $user_answer = $user_array;
-
- $answer_question = $_SESSION['hotspot_coord'][1];
- $answerDestination = $_SESSION['hotspot_dest'][1];
-
- $poly_user = convert_coordinates($user_answer, '/');
- $poly_answer = convert_coordinates($answer_question, '|');
- $max_coord = poly_get_max($poly_user, $poly_answer);
- $poly_user_compiled = poly_compile($poly_user, $max_coord);
- $poly_answer_compiled = poly_compile($poly_answer, $max_coord);
- $poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord);
- $overlap = $poly_results['both'];
- $poly_answer_area = $poly_results['s1'];
- $poly_user_area = $poly_results['s2'];
- $missing = $poly_results['s1Only'];
- $excess = $poly_results['s2Only'];
-
- if ($debug > 0) {
- error_log(__LINE__ . ' - Polygons results are ' . print_r($poly_results, 1), 0);
- }
- if ($overlap < 1) {
-
- $final_overlap = 0;
- $final_missing = 100;
- $final_excess = 100;
- } else {
-
- $final_overlap = round(((float) $overlap / (float) $poly_answer_area) * 100);
- if ($debug > 1) {
- error_log(__LINE__ . ' - Final overlap is ' . $final_overlap, 0);
- }
-
- $final_missing = 100 - $final_overlap;
- if ($debug > 1) {
- error_log(__LINE__ . ' - Final missing is ' . $final_missing, 0);
- }
-
- $final_excess = round((((float) $poly_user_area - (float) $overlap) / (float) $poly_answer_area) * 100);
- if ($debug > 1) {
- error_log(__LINE__ . ' - Final excess is ' . $final_excess, 0);
- }
- }
-
- $destination_items = explode('@@', $answerDestination);
- $threadhold_total = $destination_items[0];
- $threadhold_items = explode(';', $threadhold_total);
- $threadhold1 = $threadhold_items[0];
- $threadhold2 = $threadhold_items[1];
- $threadhold3 = $threadhold_items[2];
-
- if ($answerId === 1) {
-
- if ($final_overlap >= $threadhold1) {
- $overlap_color = true;
- }
-
- if ($final_excess <= $threadhold2) {
- $excess_color = true;
- }
-
- if ($final_missing <= $threadhold3) {
- $missing_color = true;
- }
-
- if ($final_overlap >= $threadhold1 && $final_missing <= $threadhold3 && $final_excess <= $threadhold2) {
- $next = 1;
- $result_comment = get_lang('Acceptable');
- $final_answer = 1;
- } else {
- $next = 0;
- $result_comment = get_lang('Unacceptable');
- $comment = $answerDestination = $objAnswerTmp->selectComment(1);
- $answerDestination = $objAnswerTmp->selectDestination(1);
-
- $destination_items = explode('@@', $answerDestination);
- }
- } elseif ($answerId > 1) {
- if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') {
- if ($debug > 0) {
- error_log(__LINE__ . ' - answerId is of type noerror', 0);
- }
-
- $next = 1;
- continue;
- }
- if ($debug > 0) {
- error_log(__LINE__ . ' - answerId is >1 so we\'re probably in OAR', 0);
- }
-
-
-
-
- $inter = $result['success'];
-
- $delineation_cord = $objAnswerTmp->selectHotspotCoordinates($answerId);
- $poly_answer = convert_coordinates($delineation_cord, '|');
- $max_coord = poly_get_max($poly_user, $poly_answer);
- $poly_answer_compiled = poly_compile($poly_answer, $max_coord);
- $overlap = poly_touch($poly_user_compiled, $poly_answer_compiled,$max_coord);
- if ($overlap == false) {
-
- $next = 1;
- continue;
- } else {
- if ($debug > 0) {
- error_log(__LINE__ . ' - Overlap is ' . $overlap . ': OAR hit', 0);
- }
- $organs_at_risk_hit++;
-
- $next = 0;
- $comment = $answerDestination = $objAnswerTmp->selectComment($answerId);
- $answerDestination = $objAnswerTmp->selectDestination($answerId);
- $destination_items = explode('@@', $answerDestination);
- $try_hotspot = $destination_items[1];
- $lp_hotspot = $destination_items[2];
- $select_question_hotspot = $destination_items[3];
- $url_hotspot=$destination_items[4];
- }
- }
- } else {
- if ($debug > 0) {
- error_log(__LINE__ . ' first', 0);
- }
- }
- break;
- case HOT_SPOT_ORDER:
- ExerciseShowFunctions::display_hotspot_order_answer(
- $feedback_type,
- $answerId,
- $answer,
- $studentChoice,
- $answerComment
- );
- break;
- case DRAGGABLE:
-
- case MATCHING_DRAGGABLE:
-
- case MATCHING:
- echo '<tr>';
- echo Display::tag('td', $answerMatching[$answerId]);
- echo Display::tag(
- 'td',
- "$user_answer / " . Display::tag(
- 'strong',
- $answerMatching[$answerCorrect],
- ['style' => 'color: #008000; font-weight: bold;']
- )
- );
- echo '</tr>';
- break;
- }
- }
- }
- if ($debug) error_log(' ------ ');
- }
- if ($debug) error_log('-- end answer loop --');
- $final_answer = true;
- foreach ($real_answers as $my_answer) {
- if (!$my_answer) {
- $final_answer = false;
- }
- }
-
- if ($answerType == MULTIPLE_ANSWER_COMBINATION ||
- $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE
- ) {
- if ($final_answer) {
-
- $answerWeighting = $objAnswerTmp->selectWeighting(1);
- $questionScore += $answerWeighting;
- $totalScore += $answerWeighting;
- }
- }
-
-
-
- $extra_data = array(
- 'final_overlap' => $final_overlap,
- 'final_missing'=>$final_missing,
- 'final_excess'=> $final_excess,
- 'overlap_color' => $overlap_color,
- 'missing_color'=>$missing_color,
- 'excess_color'=> $excess_color,
- 'threadhold1' => $threadhold1,
- 'threadhold2'=>$threadhold2,
- 'threadhold3'=> $threadhold3,
- );
- if ($from == 'exercise_result') {
-
-
-
-
- if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER || $answerType == HOT_SPOT_DELINEATION ) {
- if ($debug) error_log('$from AND this is a hotspot kind of question ');
- $my_exe_id = 0;
- $from_database = 0;
- if ($answerType == HOT_SPOT_DELINEATION) {
- if (0) {
- if ($overlap_color) {
- $overlap_color='green';
- } else {
- $overlap_color='red';
- }
- if ($missing_color) {
- $missing_color='green';
- } else {
- $missing_color='red';
- }
- if ($excess_color) {
- $excess_color='green';
- } else {
- $excess_color='red';
- }
- if (!is_numeric($final_overlap)) {
- $final_overlap = 0;
- }
- if (!is_numeric($final_missing)) {
- $final_missing = 0;
- }
- if (!is_numeric($final_excess)) {
- $final_excess = 0;
- }
- if ($final_overlap>100) {
- $final_overlap = 100;
- }
- $table_resume='<table class="data_table">
- <tr class="row_odd" >
- <td></td>
- <td ><b>' . get_lang('Requirements') . '</b></td>
- <td><b>' . get_lang('YourAnswer') . '</b></td>
- </tr>
- <tr class="row_even">
- <td><b>' . get_lang('Overlap') . '</b></td>
- <td>' . get_lang('Min') . ' ' . $threadhold1 . '</td>
- <td><div style="color:' . $overlap_color . '">'
- . (($final_overlap < 0) ? 0 : intval($final_overlap)) . '</div></td>
- </tr>
- <tr>
- <td><b>' . get_lang('Excess') . '</b></td>
- <td>' . get_lang('Max') . ' ' . $threadhold2 . '</td>
- <td><div style="color:' . $excess_color . '">'
- . (($final_excess < 0) ? 0 : intval($final_excess)) . '</div></td>
- </tr>
- <tr class="row_even">
- <td><b>' . get_lang('Missing') . '</b></td>
- <td>' . get_lang('Max') . ' ' . $threadhold3 . '</td>
- <td><div style="color:' . $missing_color . '">'
- . (($final_missing < 0) ? 0 : intval($final_missing)) . '</div></td>
- </tr>
- </table>';
- if ($next == 0) {
- $try = $try_hotspot;
- $lp = $lp_hotspot;
- $destinationid = $select_question_hotspot;
- $url = $url_hotspot;
- } else {
-
-
- $comment = $answerComment = $objAnswerTmp->selectComment($nbrAnswers);
- $answerDestination = $objAnswerTmp->selectDestination($nbrAnswers);
- }
- echo '<h1><div style="color:#333;">' . get_lang('Feedback') . '</div></h1>
- <p style="text-align:center">';
- $message = '<p>' . get_lang('YourDelineation') . '</p>';
- $message .= $table_resume;
- $message .= '<br />' . get_lang('ResultIs') . ' ' . $result_comment . '<br />';
- if ($organs_at_risk_hit > 0) {
- $message .= '<p><b>' . get_lang('OARHit') . '</b></p>';
- }
- $message .='<p>' . $comment . '</p>';
- echo $message;
- } else {
- echo $hotspot_delineation_result[0];
- $from_database = 1;
- }
-
- if (1) {
-
- $final_answer = $hotspot_delineation_result[1];
- if ($final_answer == 0) {
- $questionScore = 0;
- }
-
- Event::saveQuestionAttempt($questionScore, 1, $quesId, $exeId, 0);
-
- Event::saveExerciseAttemptHotspot(
- $exeId,
- $quesId,
- 1,
- $hotspot_delineation_result[1],
- $exerciseResultCoordinates[$quesId]
- );
- } else {
- if ($final_answer==0) {
- $questionScore = 0;
- $answer=0;
- Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0);
- if (is_array($exerciseResultCoordinates[$quesId])) {
- foreach($exerciseResultCoordinates[$quesId] as $idx => $val) {
- Event::saveExerciseAttemptHotspot($exeId,$quesId,$idx,0,$val);
- }
- }
- } else {
- Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0);
- if (is_array($exerciseResultCoordinates[$quesId])) {
- foreach($exerciseResultCoordinates[$quesId] as $idx => $val) {
- Event::saveExerciseAttemptHotspot($exeId,$quesId,$idx,$choice[$idx],$val);
- }
- }
- }
- }
- $my_exe_id = $exeId;
- }
- }
- if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) {
-
- if ($show_result) {
- $relPath = api_get_path(REL_PATH);
-
- echo '</table></td></tr>';
- echo "
- <tr>
- <td colspan=\"2\">
- <p><em>" . get_lang('HotSpot') . "</em></p>
- <div id=\"hotspot-solution-$questionId\"></div>
- <script>
- $(document).on('ready', function () {
- new HotspotQuestion({
- questionId: $questionId,
- exerciseId: $exeId,
- selector: '#hotspot-solution-$questionId',
- for: 'solution',
- relPath: '$relPath'
- });
- });
- </script>
- </td>
- </tr>
- ";
-
- }
- }
-
- if ($show_result) {
- echo '</table>';
- }
-
- }
- unset ($objAnswerTmp);
- $totalWeighting += $questionWeighting;
-
-
-
- if ($saved_results) {
- if ($debug) error_log("Save question results $saved_results");
- if ($debug) error_log(print_r($choice ,1 ));
- if (empty($choice)) {
- $choice = 0;
- }
- if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
- if ($choice != 0) {
- $reply = array_keys($choice);
- for ($i = 0; $i < sizeof($reply); $i++) {
- $ans = $reply[$i];
- Event::saveQuestionAttempt(
- $questionScore,
- $ans . ':' . $choice[$ans],
- $quesId,
- $exeId,
- $i,
- $this->id
- );
- if ($debug) {
- error_log('result =>' . $questionScore . ' ' . $ans . ':' . $choice[$ans]);
- }
- }
- } else {
- Event::saveQuestionAttempt($questionScore, 0, $quesId, $exeId, 0, $this->id);
- }
- } elseif ($answerType == MULTIPLE_ANSWER || $answerType == GLOBAL_MULTIPLE_ANSWER) {
- if ($choice != 0) {
- $reply = array_keys($choice);
- if ($debug) {
- error_log("reply " . print_r($reply, 1) . "");
- }
- for ($i = 0; $i < sizeof($reply); $i++) {
- $ans = $reply[$i];
- Event::saveQuestionAttempt($questionScore, $ans, $quesId, $exeId, $i, $this->id);
- }
- } else {
- Event::saveQuestionAttempt($questionScore, 0, $quesId, $exeId, 0, $this->id);
- }
- } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) {
- if ($choice != 0) {
- $reply = array_keys($choice);
- for ($i = 0; $i < sizeof($reply); $i++) {
- $ans = $reply[$i];
- Event::saveQuestionAttempt($questionScore, $ans, $quesId, $exeId, $i, $this->id);
- }
- } else {
- Event::saveQuestionAttempt($questionScore, 0, $quesId, $exeId, 0, $this->id);
- }
- } elseif (in_array($answerType, [MATCHING, DRAGGABLE, MATCHING_DRAGGABLE])) {
- if (isset($matching)) {
- foreach ($matching as $j => $val) {
- Event::saveQuestionAttempt($questionScore, $val, $quesId, $exeId, $j, $this->id);
- }
- }
- } elseif ($answerType == FREE_ANSWER) {
- $answer = $choice;
- Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
- } elseif ($answerType == ORAL_EXPRESSION) {
- $answer = $choice;
- Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id, $nano);
- } elseif (in_array($answerType, [UNIQUE_ANSWER, UNIQUE_ANSWER_IMAGE, UNIQUE_ANSWER_NO_OPTION])) {
- $answer = $choice;
- Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id);
-
- } elseif ($answerType == HOT_SPOT) {
- $answer = [];
- if (isset($exerciseResultCoordinates[$questionId]) && !empty($exerciseResultCoordinates[$questionId])) {
- Database::delete(
- Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT),
- [
- 'hotspot_exe_id = ? AND hotspot_question_id = ? AND c_id = ?' => [
- $exeId,
- $questionId,
- api_get_course_int_id()
- ]
- ]
- );
- foreach ($exerciseResultCoordinates[$questionId] as $idx => $val) {
- $answer[] = $val;
- Event::saveExerciseAttemptHotspot($exeId, $quesId, $idx, $choice[$idx], $val, false, $this->id);
- }
- }
- Event::saveQuestionAttempt($questionScore, implode('|', $answer), $quesId, $exeId, 0, $this->id);
- } else {
- Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0,$this->id);
- }
- }
- if ($propagate_neg == 0 && $questionScore < 0) {
- $questionScore = 0;
- }
- if ($saved_results) {
- $stat_table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
- $sql = 'UPDATE ' . $stat_table . ' SET
- exe_result = exe_result + ' . floatval($questionScore) . '
- WHERE exe_id = ' . $exeId;
- if ($debug) error_log($sql);
- Database::query($sql);
- }
- $return_array = array(
- 'score' => $questionScore,
- 'weight' => $questionWeighting,
- 'extra' => $extra_data,
- 'open_question' => $arrques,
- 'open_answer' => $arrans,
- 'answer_type' => $answerType
- );
- return $return_array;
- }
-
- public function send_mail_notification_for_exam($question_list_answers, $origin, $exe_id)
- {
- if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1 ) {
- return null;
- }
-
- $courseCode = api_get_course_id();
- $courseInfo = api_get_course_info($courseCode);
- $sessionId = api_get_session_id();
- if (empty($courseInfo)) {
- return false;
- }
- $url_email = api_get_path(WEB_CODE_PATH)
- . 'exercice/exercise_show.php?'
- . api_get_cidreq()
- . '&id_session='
- . $sessionId
- . '&id='
- . $exe_id
- . '&action=qualify';
- $user_info = api_get_user_info(api_get_user_id());
- $msg = get_lang('ExerciseAttempted').'<br /><br />'
- .get_lang('AttemptDetails').' : <br /><br />'.
- '<table>'
- .'<tr>'
- .'<td><em>'.get_lang('CourseName').'</em></td>'
- .'<td> <b>#course#</b></td>'
- .'</tr>'
- .'<tr>'
- .'<td>'.get_lang('TestAttempted').'</td>'
- .'<td> #exercise#</td>'
- .'</tr>'
- .'<tr>'
- .'<td>'.get_lang('StudentName').'</td>'
- .'<td> #firstName# #lastName#</td>'
- .'</tr>'
- .'<tr>'
- .'<td>'.get_lang('StudentEmail').'</td>'
- .'<td> #email#</td>'
- .'</tr>'
- .'</table>';
- $open_question_list = null;
- $msg = str_replace("#email#", $user_info['email'], $msg);
- $msg1 = str_replace("#exercise#", $this->exercise, $msg);
- $msg = str_replace("#firstName#", $user_info['firstname'], $msg1);
- $msg1 = str_replace("#lastName#", $user_info['lastname'], $msg);
- $msg = str_replace("#course#", $courseInfo['name'], $msg1);
- if ($origin != 'learnpath') {
- $msg.= '<br /><a href="#url#">'.get_lang('ClickToCommentAndGiveFeedback').'</a>';
- }
- $msg1 = str_replace("#url#", $url_email, $msg);
- $mail_content = $msg1;
- $subject = get_lang('ExerciseAttempted');
- if (!empty($sessionId)) {
- $teachers = CourseManager::get_coach_list_from_course_code($courseCode, $sessionId);
- } else {
- $teachers = CourseManager::get_teacher_list_from_course_code($courseCode);
- }
- if (!empty($teachers)) {
- foreach ($teachers as $user_id => $teacher_data) {
- MessageManager::send_message_simple(
- $user_id,
- $subject,
- $mail_content
- );
- }
- }
- }
-
- function send_notification_for_open_questions($question_list_answers, $origin, $exe_id)
- {
- if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1 ) {
- return null;
- }
-
- $courseCode = api_get_course_id();
- $course_info = api_get_course_info($courseCode);
- $url_email = api_get_path(WEB_CODE_PATH)
- . 'exercice/exercise_show.php?'
- . api_get_cidreq()
- . '&id_session='
- . api_get_session_id()
- . '&id='
- . $exe_id
- . '&action=qualify';
- $user_info = api_get_user_info(api_get_user_id());
- $msg = get_lang('OpenQuestionsAttempted').'<br /><br />'
- .get_lang('AttemptDetails').' : <br /><br />'
- .'<table>'
- .'<tr>'
- .'<td><em>'.get_lang('CourseName').'</em></td>'
- .'<td> <b>#course#</b></td>'
- .'</tr>'
- .'<tr>'
- .'<td>'.get_lang('TestAttempted').'</td>'
- .'<td> #exercise#</td>'
- .'</tr>'
- .'<tr>'
- .'<td>'.get_lang('StudentName').'</td>'
- .'<td> #firstName# #lastName#</td>'
- .'</tr>'
- .'<tr>'
- .'<td>'.get_lang('StudentEmail').'</td>'
- .'<td> #mail#</td>'
- .'</tr>'
- .'</table>';
- $open_question_list = null;
- foreach ($question_list_answers as $item) {
- $question = $item['question'];
- $answer = $item['answer'];
- $answer_type = $item['answer_type'];
- if (!empty($question) && !empty($answer) && $answer_type == FREE_ANSWER) {
- $open_question_list .=
- '<tr>'
- .'<td width="220" valign="top" bgcolor="#E5EDF8"> '.get_lang('Question').'</td>'
- .'<td width="473" valign="top" bgcolor="#F3F3F3">'.$question.'</td>'
- .'</tr>'
- .'<tr>'
- .'<td width="220" valign="top" bgcolor="#E5EDF8"> '.get_lang('Answer').'</td>'
- .'<td valign="top" bgcolor="#F3F3F3">'.$answer.'</td>'
- .'</tr>';
- }
- }
- if (!empty($open_question_list)) {
- $msg .= '<p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>'.
- '<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
- $msg .= $open_question_list;
- $msg .= '</table><br />';
- $msg1 = str_replace("#exercise#", $this->exercise, $msg);
- $msg = str_replace("#firstName#", $user_info['firstname'],$msg1);
- $msg1 = str_replace("#lastName#", $user_info['lastname'],$msg);
- $msg = str_replace("#mail#", $user_info['email'],$msg1);
- $msg = str_replace("#course#", $course_info['name'],$msg1);
- if ($origin != 'learnpath') {
- $msg .= '<br /><a href="#url#">'.get_lang('ClickToCommentAndGiveFeedback').'</a>';
- }
- $msg1 = str_replace("#url#", $url_email, $msg);
- $mail_content = $msg1;
- $subject = get_lang('OpenQuestionsAttempted');
- if (api_get_session_id()) {
- $teachers = CourseManager::get_coach_list_from_course_code($courseCode, api_get_session_id());
- } else {
- $teachers = CourseManager::get_teacher_list_from_course_code($courseCode);
- }
- if (!empty($teachers)) {
- foreach ($teachers as $user_id => $teacher_data) {
- MessageManager::send_message_simple(
- $user_id,
- $subject,
- $mail_content
- );
- }
- }
- }
- }
- function send_notification_for_oral_questions($question_list_answers, $origin, $exe_id)
- {
- if (api_get_course_setting('email_alert_manager_on_new_quiz') != 1 ) {
- return null;
- }
-
- $courseCode = api_get_course_id();
- $course_info = api_get_course_info($courseCode);
- $url_email = api_get_path(WEB_CODE_PATH)
- . 'exercice/exercise_show.php?'
- . api_get_cidreq()
- . '&id_session='
- . api_get_session_id()
- . '&id='
- . $exe_id
- . '&action=qualify';
- $user_info = api_get_user_info(api_get_user_id());
- $oral_question_list = null;
- foreach ($question_list_answers as $item) {
- $question = $item['question'];
- $answer = $item['answer'];
- $answer_type = $item['answer_type'];
- if (!empty($question) && !empty($answer) && $answer_type == ORAL_EXPRESSION) {
- $oral_question_list.='<br /><table width="730" height="136" border="0" cellpadding="3" cellspacing="3">'
- .'<tr>'
- .'<td width="220" valign="top" bgcolor="#E5EDF8"> '.get_lang('Question').'</td>'
- .'<td width="473" valign="top" bgcolor="#F3F3F3">'.$question.'</td>'
- .'</tr>'
- .'<tr>'
- .'<td width="220" valign="top" bgcolor="#E5EDF8"> '.get_lang('Answer').'</td>'
- .'<td valign="top" bgcolor="#F3F3F3">'.$answer.'</td>'
- .'</tr></table>';
- }
- }
- if (!empty($oral_question_list)) {
- $msg = get_lang('OralQuestionsAttempted').'<br /><br />
- '.get_lang('AttemptDetails').' : <br /><br />'
- .'<table>'
- .'<tr>'
- .'<td><em>'.get_lang('CourseName').'</em></td>'
- .'<td> <b>#course#</b></td>'
- .'</tr>'
- .'<tr>'
- .'<td>'.get_lang('TestAttempted').'</td>'
- .'<td> #exercise#</td>'
- .'</tr>'
- .'<tr>'
- .'<td>'.get_lang('StudentName').'</td>'
- .'<td> #firstName# #lastName#</td>'
- .'</tr>'
- .'<tr>'
- .'<td>'.get_lang('StudentEmail').'</td>'
- .'<td> #mail#</td>'
- .'</tr>'
- .'</table>';
- $msg .= '<br />'.sprintf(get_lang('OralQuestionsAttemptedAreX'),$oral_question_list).'<br />';
- $msg1 = str_replace("#exercise#", $this->exercise, $msg);
- $msg = str_replace("#firstName#", $user_info['firstname'], $msg1);
- $msg1 = str_replace("#lastName#", $user_info['lastname'], $msg);
- $msg = str_replace("#mail#", $user_info['email'], $msg1);
- $msg = str_replace("#course#", $course_info['name'], $msg1);
- if ($origin != 'learnpath') {
- $msg.= '<br /><a href="#url#">'.get_lang('ClickToCommentAndGiveFeedback').'</a>';
- }
- $msg1 = str_replace("#url#", $url_email, $msg);
- $mail_content = $msg1;
- $subject = get_lang('OralQuestionsAttempted');
- if (api_get_session_id()) {
- $teachers = CourseManager::get_coach_list_from_course_code($courseCode, api_get_session_id());
- } else {
- $teachers = CourseManager::get_teacher_list_from_course_code($courseCode);
- }
- if (!empty($teachers)) {
- foreach ($teachers as $user_id => $teacher_data) {
- MessageManager::send_message_simple(
- $user_id,
- $subject,
- $mail_content
- );
- }
- }
- }
- }
-
- public function show_exercise_result_header($user_data, $start_date = null, $duration = null, $ip = null)
- {
- $array = array();
- if (!empty($user_data)) {
- $array[] = array('title' => get_lang('Name'), 'content' => $user_data['complete_name']);
- $array[] = array('title' => get_lang('Username'), 'content' => $user_data['username']);
- if (!empty($user_data['official_code'])) {
- $array[] = array(
- 'title' => get_lang('OfficialCode'),
- 'content' => $user_data['official_code']
- );
- }
- }
-
-
-
-
- if (!empty($start_date)) {
- $array[] = array('title' => get_lang('StartDate'), 'content' => $start_date);
- }
- if (!empty($duration)) {
- $array[] = array('title' => get_lang('Duration'), 'content' => $duration);
- }
- if (!empty($ip)) {
- $array[] = array('title' => get_lang('IP'), 'content' => $ip);
- }
- $html = '<div class="question-result">';
- $html .= Display::page_header(
- Display::return_icon('test-quiz.png', get_lang('Result'),null, ICON_SIZE_MEDIUM).' '.$this->exercise.' : '.get_lang('Result')
- );
- $html .= Display::description($array);
- $html .="</div>";
- return $html;
- }
-
- public function createExercise(
- $title,
- $expired_time = 0,
- $type = 2,
- $random = 0,
- $active = 1,
- $results_disabled = 0,
- $max_attempt = 0,
- $feedback = 3,
- $propagateNegative = 0
- ) {
- $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
- $type = intval($type);
- $random = intval($random);
- $active = intval($active);
- $results_disabled = intval($results_disabled);
- $max_attempt = intval($max_attempt);
- $feedback = intval($feedback);
- $expired_time = intval($expired_time);
- $title = Database::escape_string($title);
- $propagateNegative = intval($propagateNegative);
- $sessionId = api_get_session_id();
- $course_id = api_get_course_int_id();
-
- $sql = "INSERT INTO $tbl_quiz (
- c_id,
- title,
- type,
- random,
- active,
- results_disabled,
- max_attempt,
- start_time,
- end_time,
- feedback_type,
- expired_time,
- session_id,
- propagate_neg
- )
- VALUES (
- '$course_id',
- '$title',
- $type,
- $random,
- $active,
- $results_disabled,
- $max_attempt,
- '',
- '',
- $feedback,
- $expired_time,
- $sessionId,
- $propagateNegative
- )";
- Database::query($sql);
- $quiz_id = Database::insert_id();
- if ($quiz_id) {
- $sql = "UPDATE $tbl_quiz SET id = iid WHERE iid = {$quiz_id} ";
- Database::query($sql);
- }
- return $quiz_id;
- }
- function process_geometry()
- {
- }
-
- public function get_exercise_result($exe_id)
- {
- $result = array();
- $track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($exe_id);
- if (!empty($track_exercise_info)) {
- $totalScore = 0;
- $objExercise = new Exercise();
- $objExercise->read($track_exercise_info['exe_exo_id']);
- if (!empty($track_exercise_info['data_tracking'])) {
- $question_list = explode(',', $track_exercise_info['data_tracking']);
- }
- foreach ($question_list as $questionId) {
- $question_result = $objExercise->manage_answer(
- $exe_id,
- $questionId,
- '',
- 'exercise_show',
- array(),
- false,
- true,
- false,
- $objExercise->selectPropagateNeg()
- );
- $totalScore += $question_result['score'];
- }
- if ($objExercise->selectPropagateNeg() == 0 && $totalScore < 0) {
- $totalScore = 0;
- }
- $result = array(
- 'score' => $totalScore,
- 'weight' => $track_exercise_info['exe_weighting']
- );
- }
- return $result;
- }
-
- public function is_visible(
- $lp_id = 0,
- $lp_item_id = 0,
- $lp_item_view_id = 0,
- $filter_by_admin = true
- ) {
-
- $is_visible = true;
- $message = null;
-
- if ($filter_by_admin) {
- if (api_is_platform_admin() || api_is_course_admin()) {
- return array('value' => true, 'message' => '');
- }
- }
-
- if ($this->active == -1) {
- return array(
- 'value' => false,
- 'message' => Display::return_message(get_lang('ExerciseNotFound'), 'warning', false)
- );
- }
-
- $visibility = api_get_item_visibility(
- api_get_course_info(),
- TOOL_QUIZ,
- $this->id,
- api_get_session_id()
- );
- if ($visibility == 0 || $visibility == 2) {
- $this->active = 0;
- }
-
- if (empty($lp_id)) {
-
- if ($this->active == 0) {
- return array(
- 'value' => false,
- 'message' => Display::return_message(get_lang('ExerciseNotFound'), 'warning', false)
- );
- }
- } else {
-
- if ($this->active == 0 && !learnpath::is_lp_visible_for_student($lp_id, api_get_user_id())) {
- return array(
- 'value' => false,
- 'message' => Display::return_message(get_lang('ExerciseNotFound'), 'warning', false)
- );
- }
- }
-
- $limit_time_exists = (
- (!empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00') ||
- (!empty($this->end_time) && $this->end_time != '0000-00-00 00:00:00')
- ) ? true : false;
- if ($limit_time_exists) {
- $time_now = time();
- if (!empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00') {
- $is_visible = (($time_now - api_strtotime($this->start_time, 'UTC')) > 0) ? true : false;
- }
- if ($is_visible == false) {
- $message = sprintf(
- get_lang('ExerciseAvailableFromX'),
- api_convert_and_format_date($this->start_time)
- );
- }
- if ($is_visible == true) {
- if ($this->end_time != '0000-00-00 00:00:00') {
- $is_visible = ((api_strtotime($this->end_time, 'UTC') > $time_now) > 0) ? true : false;
- if ($is_visible == false) {
- $message = sprintf(
- get_lang('ExerciseAvailableUntilX'),
- api_convert_and_format_date($this->end_time)
- );
- }
- }
- }
- if (
- $is_visible == false &&
- $this->start_time != '0000-00-00 00:00:00' &&
- $this->end_time != '0000-00-00 00:00:00'
- ) {
- $message = sprintf(
- get_lang('ExerciseWillBeActivatedFromXToY'),
- api_convert_and_format_date($this->start_time),
- api_convert_and_format_date($this->end_time)
- );
- }
- }
-
- $exerciseAttempts = $this->selectAttempts();
- if ($is_visible) {
- if ($exerciseAttempts > 0) {
- $attempt_count = Event::get_attempt_count_not_finished(
- api_get_user_id(),
- $this->id,
- $lp_id,
- $lp_item_id,
- $lp_item_view_id
- );
- if ($attempt_count >= $exerciseAttempts) {
- $message = sprintf(
- get_lang('ReachedMaxAttempts'),
- $this->name,
- $exerciseAttempts
- );
- $is_visible = false;
- }
- }
- }
- if (!empty($message)){
- $message = Display::return_message($message, 'warning', false);
- }
- return array(
- 'value' => $is_visible,
- 'message' => $message
- );
- }
- public function added_in_lp()
- {
- $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM);
- $sql = "SELECT max_score FROM $TBL_LP_ITEM
- WHERE c_id = {$this->course_id} AND item_type = '" . TOOL_QUIZ . "' AND path = '{$this->id}'";
- $result = Database::query($sql);
- if (Database::num_rows($result) > 0) {
- return true;
- }
- return false;
- }
- function get_media_list()
- {
- $media_questions = array();
- $question_list = $this->get_validated_question_list();
- if (!empty($question_list)) {
- foreach ($question_list as $questionId) {
- $objQuestionTmp = Question::read($questionId);
- if (isset($objQuestionTmp->parent_id) && $objQuestionTmp->parent_id != 0) {
- $media_questions[$objQuestionTmp->parent_id][] = $objQuestionTmp->id;
- } else {
-
- $media_questions[999][] = $objQuestionTmp->id;
- }
- }
- }
- return $media_questions;
- }
- function media_is_activated($media_list)
- {
- $active = false;
- if (isset($media_list) && !empty($media_list)) {
- $media_count = count($media_list);
- if ($media_count > 1) {
- return true;
- } elseif ($media_count == 1) {
- if (isset($media_list[999])) {
- return false;
- } else {
- return true;
- }
- }
- }
- return $active;
- }
- function get_validated_question_list()
- {
- $tabres = array();
- $isRandomByCategory = $this->isRandomByCat();
- if ($isRandomByCategory == 0) {
- if ($this->isRandom()) {
- $tabres = $this->selectRandomList();
- } else {
- $tabres = $this->selectQuestionList();
- }
- } else {
- if ($this->isRandom()) {
-
-
-
-
-
- $questionList = array();
- $tabCategoryQuestions = TestCategory::getQuestionsByCat($this->id);
- $isRandomByCategory = $this->selectRandomByCat();
-
-
-
- if ($isRandomByCategory == 2) {
- $tabCategoryQuestions = TestCategory::sortTabByBracketLabel($tabCategoryQuestions);
- }
- while (list($cat_id, $tabquestion) = each($tabCategoryQuestions)) {
- $number_of_random_question = $this->random;
- if ($this->random == -1) {
- $number_of_random_question = count($this->questionList);
- }
- $questionList = array_merge(
- $questionList,
- TestCategory::getNElementsFromArray(
- $tabquestion,
- $number_of_random_question
- )
- );
- }
-
- if ($isRandomByCategory == 1) {
- shuffle($questionList);
- }
- $tabres = $questionList;
- } else {
-
-
-
- }
- }
- return $tabres;
- }
- function get_question_list($expand_media_questions = false)
- {
- $question_list = $this->get_validated_question_list();
- $question_list = $this->transform_question_list_with_medias($question_list, $expand_media_questions);
- return $question_list;
- }
- function transform_question_list_with_medias($question_list, $expand_media_questions = false)
- {
- $new_question_list = array();
- if (!empty($question_list)) {
- $media_questions = $this->get_media_list();
- $media_active = $this->media_is_activated($media_questions);
- if ($media_active) {
- $counter = 1;
- foreach ($question_list as $question_id) {
- $add_question = true;
- foreach ($media_questions as $media_id => $question_list_in_media) {
- if ($media_id != 999 && in_array($question_id, $question_list_in_media)) {
- $add_question = false;
- if (!in_array($media_id, $new_question_list)) {
- $new_question_list[$counter] = $media_id;
- $counter++;
- }
- break;
- }
- }
- if ($add_question) {
- $new_question_list[$counter] = $question_id;
- $counter++;
- }
- }
- if ($expand_media_questions) {
- $media_key_list = array_keys($media_questions);
- foreach ($new_question_list as &$question_id) {
- if (in_array($question_id, $media_key_list)) {
- $question_id = $media_questions[$question_id];
- }
- }
- $new_question_list = array_flatten($new_question_list);
- }
- } else {
- $new_question_list = $question_list;
- }
- }
- return $new_question_list;
- }
-
- public function get_stat_track_exercise_info_by_exe_id($exe_id)
- {
- $track_exercises = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
- $exe_id = intval($exe_id);
- $sql_track = "SELECT * FROM $track_exercises WHERE exe_id = $exe_id ";
- $result = Database::query($sql_track);
- $new_array = array();
- if (Database::num_rows($result) > 0 ) {
- $new_array = Database::fetch_array($result, 'ASSOC');
- $new_array['duration'] = null;
- $start_date = api_get_utc_datetime($new_array['start_date'], true);
- $end_date = api_get_utc_datetime($new_array['exe_date'], true);
- if (!empty($start_date) && !empty($end_date)) {
- $start_date = api_strtotime($start_date, 'UTC');
- $end_date = api_strtotime($end_date, 'UTC');
- if ($start_date && $end_date) {
- $mytime = $end_date- $start_date;
- $new_learnpath_item = new learnpathItem(null);
- $time_attemp = $new_learnpath_item->get_scorm_time('js', $mytime);
- $h = get_lang('h');
- $time_attemp = str_replace('NaN', '00' . $h . '00\'00"', $time_attemp);
- $new_array['duration'] = $time_attemp;
- }
- }
- }
- return $new_array;
- }
- public function edit_question_to_remind($exe_id, $question_id, $action = 'add')
- {
- $exercise_info = self::get_stat_track_exercise_info_by_exe_id($exe_id);
- $question_id = intval($question_id);
- $exe_id = intval($exe_id);
- $track_exercises = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
- if ($exercise_info) {
- if (empty($exercise_info['questions_to_check'])) {
- if ($action == 'add') {
- $sql = "UPDATE $track_exercises SET questions_to_check = '$question_id' WHERE exe_id = $exe_id ";
- $result = Database::query($sql);
- }
- } else {
- $remind_list = explode(',',$exercise_info['questions_to_check']);
- $remind_list_string = '';
- if ($action == 'add') {
- if (!in_array($question_id, $remind_list)) {
- $remind_list[] = $question_id;
- if (!empty($remind_list)) {
- sort($remind_list);
- array_filter($remind_list);
- }
- $remind_list_string = implode(',', $remind_list);
- }
- } elseif ($action == 'delete') {
- if (!empty($remind_list)) {
- if (in_array($question_id, $remind_list)) {
- $remind_list = array_flip($remind_list);
- unset($remind_list[$question_id]);
- $remind_list = array_flip($remind_list);
- if (!empty($remind_list)) {
- sort($remind_list);
- array_filter($remind_list);
- $remind_list_string = implode(',', $remind_list);
- }
- }
- }
- }
- $remind_list_string = Database::escape_string($remind_list_string);
- $sql = "UPDATE $track_exercises SET questions_to_check = '$remind_list_string' WHERE exe_id = $exe_id ";
- Database::query($sql);
- }
- }
- }
- public function fill_in_blank_answer_to_array($answer)
- {
- api_preg_match_all('/\[[^]]+\]/', $answer, $teacher_answer_list);
- $teacher_answer_list = $teacher_answer_list[0];
- return $teacher_answer_list;
- }
- public function fill_in_blank_answer_to_string($answer)
- {
- $teacher_answer_list = $this->fill_in_blank_answer_to_array($answer);
- $result = '';
- if (!empty($teacher_answer_list)) {
- $i = 0;
- foreach ($teacher_answer_list as $teacher_item) {
- $value = null;
-
- $value = strip_tags($teacher_item);
- $value = api_substr($value, 1, api_strlen($value) - 2);
- $value = explode('/', $value);
- if (!empty($value[0])) {
- $value = trim($value[0]);
- $value = str_replace(' ', '', $value);
- $result .= $value;
- }
- }
- }
- return $result;
- }
- function return_time_left_div()
- {
- $html = '<div id="clock_warning" style="display:none">';
- $html .= Display::return_message(
- get_lang('ReachedTimeLimit'),
- 'warning'
- );
- $html .= ' ';
- $html .= sprintf(
- get_lang('YouWillBeRedirectedInXSeconds'),
- '<span id="counter_to_redirect" class="red_alert"></span>'
- );
- $html .= '</div>';
- $html .= '<div id="exercise_clock_warning" class="count_down"></div>';
- return $html;
- }
- function get_count_question_list()
- {
-
- $question_count = 0;
- $question_list = $this->get_question_list();
- if (!empty($question_list)) {
- $question_count = count($question_list);
- }
- return $question_count;
- }
- function get_exercise_list_ordered()
- {
- $table_exercise_order = Database::get_course_table(TABLE_QUIZ_ORDER);
- $course_id = api_get_course_int_id();
- $session_id = api_get_session_id();
- $sql = "SELECT exercise_id, exercise_order FROM $table_exercise_order WHERE c_id = $course_id AND session_id = $session_id ORDER BY exercise_order";
- $result = Database::query($sql);
- $list = array();
- if (Database::num_rows($result)) {
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $list[$row['exercise_order']] = $row['exercise_id'];
- }
- }
- return $list;
- }
-
- public function get_max_score()
- {
- $out_max_score = 0;
- $tab_question_list = $this->selectQuestionList(true);
-
- if ($this->random > 0 && $this->randomByCat == 0) {
- $nb_random_questions = $this->random;
- $tab_questions_score = array();
- for ($i = 1; $i <= count($tab_question_list); $i++) {
- $tmpobj_question = Question::read($tab_question_list[$i]);
- $tab_questions_score[] = $tmpobj_question->weighting;
- }
- rsort($tab_questions_score);
-
- for ($i = 0; $i < min($nb_random_questions, count($tab_questions_score)); $i++) {
- $out_max_score += $tab_questions_score[$i];
- }
- }
-
-
- else if ($this->random > 0 && $this->randomByCat > 0) {
- $nb_random_questions = $this->random;
- $tab_categories_scores = array();
- for ($i = 1; $i <= count($tab_question_list); $i++) {
- $question_category_id = TestCategory::getCategoryForQuestion($tab_question_list[$i]);
- if (!is_array($tab_categories_scores[$question_category_id])) {
- $tab_categories_scores[$question_category_id] = array();
- }
- $tmpobj_question = Question::read($tab_question_list[$i]);
- $tab_categories_scores[$question_category_id][] = $tmpobj_question->weighting;
- }
-
- while (list($key, $tab_scores) = each($tab_categories_scores)) {
- rsort($tab_scores);
- for ($i = 0; $i < min($nb_random_questions, count($tab_scores)); $i++) {
- $out_max_score += $tab_scores[$i];
- }
- }
- }
-
- else {
- for ($i = 1; $i <= count($tab_question_list); $i++) {
- $tmpobj_question = Question::read($tab_question_list[$i]);
- $out_max_score += $tmpobj_question->weighting;
- }
- }
- return $out_max_score;
- }
-
- public function get_formated_title()
- {
- return api_html_entity_decode($this->selectTitle());
- }
-
- public static function get_formated_title_variable($in_title)
- {
- return api_html_entity_decode($in_title);
- }
-
- public function format_title()
- {
- return api_htmlentities($this->title);
- }
-
- public static function format_title_variable($in_title)
- {
- return api_htmlentities($in_title);
- }
-
- public function getExercisesByCouseSession($courseId, $sessionId)
- {
- $courseId = intval($courseId);
- $sessionId = intval($sessionId);
- $tbl_quiz = Database::get_course_table(TABLE_QUIZ_TEST);
- $sql = "SELECT * FROM $tbl_quiz cq
- WHERE
- cq.c_id = %s AND
- (cq.session_id = %s OR cq.session_id = 0) AND
- cq.active = 0
- ORDER BY cq.id";
- $sql = sprintf($sql, $courseId, $sessionId);
- $result = Database::query($sql);
- $rows = array();
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $rows[] = $row;
- }
- return $rows;
- }
-
- public function getExerciseAndResult($courseId, $sessionId, $quizId = array())
- {
- if (empty($quizId)) {
- return array();
- }
- $sessionId = intval($sessionId);
- $ids = is_array($quizId) ? $quizId : array($quizId);
- $ids = array_map('intval', $ids);
- $ids = implode(',', $ids);
- $track_exercises = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
- if ($sessionId != 0) {
- $sql = "SELECT * FROM $track_exercises te
- INNER JOIN c_quiz cq ON cq.id = te.exe_exo_id AND te.c_id = cq.c_id
- WHERE
- te.id = %s AND
- te.session_id = %s AND
- cq.id IN (%s)
- ORDER BY cq.id";
- $sql = sprintf($sql, $courseId, $sessionId, $ids);
- } else {
- $sql = "SELECT * FROM $track_exercises te
- INNER JOIN c_quiz cq ON cq.id = te.exe_exo_id AND te.c_id = cq.c_id
- WHERE
- te.id = %s AND
- cq.id IN (%s)
- ORDER BY cq.id";
- $sql = sprintf($sql, $courseId, $ids);
- }
- $result = Database::query($sql);
- $rows = array();
- while ($row = Database::fetch_array($result, 'ASSOC')) {
- $rows[] = $row;
- }
- return $rows;
- }
- }
|