PageRenderTime 32ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 0ms

/components/com_ariquizlite/frontend_pages/question.php

https://bitbucket.org/linoyepost/epg_intranet_innokat
PHP | 201 lines | 159 code | 32 blank | 10 comment | 27 complexity | ff821a7bc657968483f6c0216ddc9db6 MD5 | raw file
Possible License(s): LGPL-2.1, GPL-2.0, Apache-2.0, BSD-3-Clause
  1. <?php
  2. /*
  3. * ARI Quiz Lite
  4. *
  5. * @package ARI Quiz Lite
  6. * @version 1.0.0
  7. * @author ARI Soft
  8. * @copyright Copyright (c) 2009 www.ari-soft.com. All rights reserved
  9. * @license GNU/GPL (http://www.gnu.org/copyleft/gpl.html)
  10. *
  11. */
  12. defined('ARI_FRAMEWORK_LOADED') or die('Direct Access to this location is not allowed.');
  13. AriKernel::import('Web.Utils.Util');
  14. AriKernel::import('Controllers.FileController');
  15. AriKernel::import('Cache.FileCache');
  16. class questionAriPage extends AriUserQuizPageBase
  17. {
  18. function execute()
  19. {
  20. $this->_loadQuestion();
  21. parent::execute();
  22. }
  23. function _loadQuestion($ticketId = null)
  24. {
  25. global $option, $Itemid;
  26. $mainframe =& JFactory::getApplication();
  27. $user =& JFactory::getUser();
  28. if (empty($ticketId)) $ticketId = JRequest::getString('ticketId', '');
  29. $userId = $user->get('id');
  30. if (!AriQuizFrontHelper::_checkQuizAvailability($userId, $ticketId)) return ;
  31. $statistics = $this->_quizController->call('getNextQuestion', $ticketId);
  32. if (empty($statistics) || empty($statistics->StatisticsId))
  33. {
  34. $isQuizFinished = $this->_quizController->call('isQuizFinished', $ticketId);
  35. if ($isQuizFinished)
  36. {
  37. $mainframe->redirect(
  38. AriQuizFrontHelper::addTmplToLink('index.php?option=' . $option . '&task=quiz_finished&ticketId=' . $ticketId . '&Itemid=' . $Itemid));
  39. exit();
  40. }
  41. else
  42. {
  43. $mainframe->redirect(
  44. AriQuizFrontHelper::addTmplToLink('index.php?option=' . $option . '&task=quiz_list&ItemId=' . $Itemid));
  45. exit();
  46. }
  47. }
  48. if (empty($statistics->StartDate))
  49. {
  50. $this->_quizController->call('setStatisticsStart', $statistics->StatisticsId, ArisUtils::getIP());
  51. }
  52. $quizInfo = $this->_quizController->call('getUserQuizInfo', $ticketId);
  53. $completedCount = $this->_quizController->call('getUserCompletedQuestion', $ticketId);
  54. $questionVersionId = $statistics->Question->QuestionVersionId;
  55. $questionVersion = $statistics->Question->QuestionVersion;
  56. $questionEntity = EntityFactory::createInstance($questionVersion->QuestionType->ClassName, ARI_QUESTIONENTITY_GROUP);
  57. $questionData = $questionEntity->getDataFromXml($questionVersion->Data);
  58. $questionTime = null;
  59. if (!empty($statistics->QuestionTime))
  60. {
  61. $questionTime = !empty($statistics->StartDate)
  62. ? strtotime($statistics->StartDate) + $statistics->QuestionTime - strtotime(ArisDate::getDbUTC()) - $statistics->UsedTime
  63. : $statistics->QuestionTime - $statistics->UsedTime;
  64. if ($questionTime < 0)
  65. {
  66. $this->_loadQuestion($ticketId);
  67. }
  68. }
  69. $questionCount = $quizInfo->QuestionCount;
  70. $progressPercent = $questionCount != 0 ? floor((100 * $completedCount) / $questionCount) : 0;
  71. $totalTime = null;
  72. if ($quizInfo->TotalTime)
  73. {
  74. $totalTime = $quizInfo->TotalTime - $quizInfo->Now + $quizInfo->StartDate;
  75. }
  76. $this->_includeCssFile($quizInfo);
  77. $this->addVar('totalTime', $totalTime);
  78. $this->addVar('completedCount', $completedCount);
  79. $this->addVar('progressPercent', $progressPercent);
  80. $this->addVar('ticketId', $ticketId);
  81. $this->addVar('questionVersion', $questionVersion);
  82. $this->addVar('questionVersionId', $questionVersionId);
  83. $this->addVar('questionTime', $questionTime);
  84. $this->addVar('quizInfo', $quizInfo);
  85. $this->addVar('statistics', $statistics);
  86. $this->addVar('questionData', $questionData);
  87. }
  88. function _includeCssFile($quizInfo)
  89. {
  90. global $option;
  91. $siteUrl = JURI::root(true);
  92. $cssFilePath = 'components/' . $option . '/css/';
  93. $cssFile = 'default.css';
  94. $cacheDir = JPATH_SITE . '/administrator/components/' . $option . '/cache/files/' . ARI_QUIZ_FILE_TEMPLATEGROUP . '/';
  95. $webCacheDir = $siteUrl . '/administrator/components/' . $option . '/cache/files/' . ARI_QUIZ_FILE_TEMPLATEGROUP . '/';
  96. if (!empty($quizInfo) && $quizInfo->CssTemplateId)
  97. {
  98. $fileName = $cacheDir . $quizInfo->CssTemplateId . '.css';
  99. $isExists = file_exists($fileName);
  100. if (!$isExists)
  101. {
  102. $fileController = new AriFileController(ARI_QUIZ_FILE_TABLE);
  103. $file = $fileController->getFile($quizInfo->CssTemplateId, ARI_QUIZ_FILE_TEMPLATEGROUP);
  104. if (!empty($file))
  105. {
  106. AriFileCache::saveTextFile($file->Content, $fileName);
  107. $isExists = file_exists($fileName);
  108. }
  109. }
  110. if ($isExists)
  111. {
  112. $cssFilePath = 'administrator/components/' . $option . '/cache/files/' . ARI_QUIZ_FILE_TEMPLATEGROUP . '/';
  113. $cssFile = $quizInfo->CssTemplateId . '.css';
  114. }
  115. }
  116. $doc = JFactory::getDocument();
  117. $doc->addStyleSheet($cssFilePath . '/' . $cssFile);
  118. }
  119. function _registerEventHandlers()
  120. {
  121. $this->_registerEventHandler('skip', 'clickSkip');
  122. $this->_registerEventHandler('save', 'clickSave');
  123. }
  124. function clickSkip($eventArgs)
  125. {
  126. global $option, $Itemid;
  127. $mainframe =& JFactory::getApplication();
  128. $user =& JFactory::getUser();
  129. $userId = $user->get('id');
  130. $skipDate = ArisDate::getDbUTC();
  131. $ticketId = JRequest::getString('ticketId', '');
  132. if (!AriQuizFrontHelper::_checkQuizAvailability($userId, $ticketId)) return ;
  133. $qid = JRequest::getInt('qid');
  134. $statistics = $this->_quizController->call('getCurrentQuestion', $ticketId);
  135. if (!empty($statistics) && $statistics->Question->QuestionId == $qid)
  136. {
  137. $quiz = $this->_quizController->call('getQuizByTicketId', $ticketId);
  138. if (!empty($quiz) && !empty($quiz->QuizId) && $quiz->CanSkip)
  139. {
  140. $this->_quizController->call('skipQuestion', $statistics->StatisticsId, $skipDate);
  141. }
  142. }
  143. $mainframe->redirect(
  144. AriQuizFrontHelper::addTmplToLink('index.php?option=' . $option . '&task=question&ticketId=' . $ticketId . '&t=' . uniqid('uv_') . '&Itemid=' . $Itemid));
  145. }
  146. function clickSave($eventArgs)
  147. {
  148. global $option, $Itemid;
  149. $mainframe =& JFactory::getApplication();
  150. $user =& JFactory::getUser();
  151. $userId = $user->get('id');
  152. $ticketId = JRequest::getString('ticketId', '');
  153. if (!AriQuizFrontHelper::_checkQuizAvailability($userId, $ticketId)) return ;
  154. $qid = JRequest::getInt('qid');
  155. $statistics = $this->_quizController->call('getCurrentQuestion', $ticketId);
  156. if (!empty($statistics) && $statistics->Question->QuestionId == $qid)
  157. {
  158. $questionVersion = $statistics->Question->QuestionVersion;
  159. $questionEntity = EntityFactory::createInstance($questionVersion->QuestionType->ClassName, ARI_QUESTIONENTITY_GROUP);
  160. $statistics->EndDate = ArisDate::getDbUTC();
  161. $statistics->Data = $questionEntity->getFrontXml();
  162. $statistics->Score = $questionEntity->isCorrect($statistics->Data, $questionVersion->Data) ? $questionVersion->Score : 0;
  163. $this->_quizController->call('updateStatisticsInfo', $statistics);
  164. }
  165. $mainframe->redirect(
  166. AriQuizFrontHelper::addTmplToLink('index.php?option=' . $option . '&task=question&ticketId=' . $ticketId . '&t=' . uniqid('uv_') . '&Itemid=' . $Itemid));
  167. }
  168. }
  169. ?>