Thank you for downloading session.php
Your download should start in 3 seconds... If not please use the download link below
| 1 | <?php
|
|---|---|
| 2 | /**
|
| 3 | * JQuarks Component Session Model |
| 4 | * |
| 5 | * @version $Id: session.php 69 2010-04-23 07:52:57Z fnaccache $ |
| 6 | * @author IP-Tech Labs <labs@iptech-offshore.com> |
| 7 | * @copyright 2009-2010 IP-Tech |
| 8 | * @package JQuarks-Front-Office |
| 9 | * @subpackage Controllers |
| 10 | * @link http://www.iptechinside.com/labs/projects/show/jquarks |
| 11 | * @since 0.1 |
| 12 | * @license GNU/GPL2 |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or |
| 15 | * modify it under the terms of the GNU General Public License |
| 16 | * as published by the Free Software Foundation; version 2 |
| 17 | * of the License. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, write to the Free Software |
| 26 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 27 | * or see <http://www.gnu.org/licenses/> |
| 28 | */ |
| 29 | |
| 30 | defined('_JEXEC') or die(); |
| 31 | |
| 32 | jimport('joomla.application.component.model');
|
| 33 | |
| 34 | |
| 35 | class JQuarksModelSession extends JModel |
| 36 | {
|
| 37 | private $_id;
|
| 38 | private $_session;
|
| 39 | private $_results;
|
| 40 | private $_totalInput;
|
| 41 | private $_totalQuestions;
|
| 42 | private $_inputEvaluated;
|
| 43 | |
| 44 | |
| 45 | function __construct()
|
| 46 | {
|
| 47 | parent::__construct(); |
| 48 | $this->_id = JRequest::getInt('id') ; |
| 49 | } |
| 50 | |
| 51 | |
| 52 | public function getId() { |
| 53 | return $this->_id; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | public function getTotalQuestions() { |
| 58 | return $this->_totalQuestions; |
| 59 | } |
| 60 | |
| 61 | |
| 62 | public function getTotalInput() { |
| 63 | return $this->_totalInput; |
| 64 | } |
| 65 | |
| 66 | public function getInputEvaluated() { |
| 67 | return $this->_inputEvaluated; |
| 68 | } |
| 69 | |
| 70 | |
| 71 | /**
|
| 72 | * Get results after evaluation of answers |
| 73 | * |
| 74 | * @return arrayObject of questions and propositions evaluated |
| 75 | * |
| 76 | */ |
| 77 | function getResults()
|
| 78 | {
|
| 79 | $query = 'SELECT pp.question_id, pp.type_id, pp.statement,'.
|
| 80 | ' pp.proposition_id, pp.answer, pp.correct,'.
|
| 81 | ' aa.answer_id, aa.altanswer, aa.status, aa.score'.
|
| 82 | ' FROM (SELECT DISTINCT q.id AS question_id, q.type_id, q.statement, p.id AS proposition_id, p.answer, p.correct'.
|
| 83 | ' FROM #__jquarks_quizzes_answersessions ans'.
|
| 84 | ' INNER JOIN #__jquarks_questions q ON ans.question_id = q.id'.
|
| 85 | ' LEFT JOIN #__jquarks_propositions p ON q.id = p.question_id'.
|
| 86 | ' WHERE ans.quizsession_id = '. (int)$this->_id .') pp'. |
| 87 | ' LEFT JOIN (SELECT question_id, answer_id, altanswer, status, score'.
|
| 88 | ' FROM #__jquarks_quizzes_answersessions ans'.
|
| 89 | ' WHERE ans.quizsession_id = '. (int)$this->_id .') aa'. |
| 90 | ' ON ((pp.proposition_id = aa.answer_id AND pp.question_id = aa.question_id)'.
|
| 91 | ' OR (pp.type_id = 1 AND pp.question_id = aa.question_id AND aa.answer_id = 0)'.
|
| 92 | ' OR (pp.type_id > 2 AND pp.type_id < 5 AND pp.question_id = aa.question_id AND aa.answer_id = 0))';
|
| 93 | |
| 94 | // fetch and egt Results
|
| 95 | $this->_db->setQuery($query);
|
| 96 | $this->_results = $this->_db->loadObjectList(); |
| 97 | |
| 98 | // init vars
|
| 99 | $totalInput = 0;
|
| 100 | $totalQuestions = 0;
|
| 101 | $inputEvaluated = 0;
|
| 102 | |
| 103 | $idq = null;
|
| 104 | foreach($this->_results as $res) |
| 105 | {
|
| 106 | if($res->question_id != $idq)
|
| 107 | {
|
| 108 | $idq = $res->question_id; |
| 109 | $totalQuestions ++; |
| 110 | if($res->type_id == 1) { |
| 111 | $totalInput ++; |
| 112 | if($res->status != -1) { |
| 113 | $inputEvaluated ++; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | } |
| 119 | |
| 120 | $this->_totalInput = $totalInput;
|
| 121 | $this->_totalQuestions = $totalQuestions;
|
| 122 | $this->_inputEvaluated = $inputEvaluated;
|
| 123 | return $this->_results; |
| 124 | |
| 125 | } |
| 126 | |
| 127 | |
| 128 | |
| 129 | |
| 130 | /**
|
| 131 | * get the quiz Id of this session |
| 132 | * |
| 133 | * @return int - quiz id |
| 134 | */ |
| 135 | public function getQuizId() |
| 136 | {
|
| 137 | $query = 'SELECT quiz_id'.
|
| 138 | ' FROM #__jquarks_quizsession qs, #__jquarks_users_quizzes uq'.
|
| 139 | ' WHERE qs.id = uq.id'.
|
| 140 | ' AND qs.affected_id = ' . (int)$this->_id; |
| 141 | |
| 142 | $this->_db->setQuery($query);
|
| 143 | $quizId = $this->_db->loadResult();
|
| 144 | |
| 145 | return $quizId;
|
| 146 | |
| 147 | } |
| 148 | |
| 149 | |
| 150 | /**
|
| 151 | * Get the session of the current user's answer to the quiz |
| 152 | * |
| 153 | * @return array |
| 154 | * |
| 155 | * id (of the session), title (of the quiz), quiz_id, score, maxScore, unaswered, evaluate, |
| 156 | * spent_time, started_on, finished_on, ip_address |
| 157 | * user_id, givenname, familyname, email |
| 158 | * |
| 159 | */ |
| 160 | function getSession()
|
| 161 | {
|
| 162 | $query = 'SELECT quizSession.id AS id, quizzes.title, quizzes.id,' .
|
| 163 | ' ( SELECT sum(score)
|
| 164 | FROM #__jquarks_quizzes_answersessions |
| 165 | WHERE quizsession_id = quizSession.id |
| 166 | AND status <> -1 ) AS score,' .
|
| 167 | ' ( SELECT count(distinct(question_id))
|
| 168 | FROM #__jquarks_quizzes_answersessions |
| 169 | WHERE quizsession_id = quizSession.id ) AS maxScore,' .
|
| 170 | ' ( SELECT count(id)
|
| 171 | FROM #__jquarks_quizzes_answersessions |
| 172 | WHERE status=-2 |
| 173 | AND quizsession_id = quizSession.id ) AS unanswered,' .
|
| 174 | ' ( SELECT count(id)
|
| 175 | FROM #__jquarks_quizzes_answersessions |
| 176 | WHERE status=-1 |
| 177 | AND quizsession_id = quizSession.id ) AS evaluate,' .
|
| 178 | ' quizSession.spent_time, quizSession.started_on, quizSession.finished_on, quizSession.ip_address,' .
|
| 179 | ' sessionWho.user_id, sessionWho.givenname, sessionWho.familyname, sessionWho.email' .
|
| 180 | ' FROM #__jquarks_quizsession AS quizSession' .
|
| 181 | ' LEFT JOIN #__jquarks_users_quizzes AS users_quizzes ON users_quizzes.id = quizSession.affected_id' .
|
| 182 | ' LEFT JOIN #__jquarks_quizzes AS quizzes ON quizzes.id = users_quizzes.quiz_id' .
|
| 183 | ' LEFT JOIN #__jquarks_quizzes_answersessions AS quizSessAns ON quizSessAns.quizsession_id = quizSession.id' .
|
| 184 | ' LEFT JOIN #__jquarks_sessionwho AS sessionWho ON sessionWho.session_id = quizSession.id' .
|
| 185 | ' WHERE quizSession.id = ' . $this->_id ; |
| 186 | |
| 187 | $this->_db->setQuery($query) ;
|
| 188 | $this->_session = $this->_db->loadObject() ; |
| 189 | if ($this->_db->getErrorNum()){ |
| 190 | return false ; |
| 191 | } |
| 192 | |
| 193 | return $this->_session ; |
| 194 | } |
| 195 | |
| 196 | |
| 197 | } |