Skip to content

Instantly share code, notes, and snippets.

@goldhat
Created February 4, 2017 14:47
Show Gist options
  • Save goldhat/489064b2d03abea302734c9513b6d74f to your computer and use it in GitHub Desktop.
Save goldhat/489064b2d03abea302734c9513b6d74f to your computer and use it in GitHub Desktop.
Stats Save
public function save($quiz = null) {
$quizId = $this->_post['quizId'];
$array = $this->_post['results'];
$lockIp = $this->getIp();
$userId = get_current_user_id();
if ($lockIp === false) {
return false;
}
if ($quiz === null) {
$quizMapper = new QuizMaster_Model_QuizMapper();
$quiz = $quizMapper->fetch($quizId);
}
if (!$quiz->isStatisticsOn()) {
return false;
}
$values = $this->makeDataList($quizId, $array, $quiz->getQuizModus());
$formValues = $this->makeFormData($quiz, isset($this->_post['forms']) ? $this->_post['forms'] : null);
if ($values === false) {
return false;
}
if ($quiz->getStatisticsIpLock() > 0) {
$lockMapper = new QuizMaster_Model_LockMapper();
$lockTime = $quiz->getStatisticsIpLock() * 60;
$lockMapper->deleteOldLock($lockTime, $quiz->getId(), time(), QuizMaster_Model_Lock::TYPE_STATISTIC);
if ($lockMapper->isLock($quizId, $lockIp, $userId, QuizMaster_Model_Lock::TYPE_STATISTIC)) {
return false;
}
$lock = new QuizMaster_Model_Lock();
$lock->setQuizId($quizId)
->setLockIp($lockIp)
->setUserId($userId)
->setLockType(QuizMaster_Model_Lock::TYPE_STATISTIC)
->setLockDate(time());
$lockMapper->insert($lock);
}
$statisticRefModel = new QuizMaster_Model_StatisticRefModel();
$statisticRefModel->setCreateTime(time());
$statisticRefModel->setUserId($userId);
$statisticRefModel->setQuizId($quizId);
$statisticRefModel->setFormData($formValues);
$statisticRefMapper = new QuizMaster_Model_StatisticRefMapper();
$statisticRefMapper->statisticSave($statisticRefModel, $values);
return true;
}
@goldhat
Copy link
Author

goldhat commented Feb 4, 2017

Output:

string(6) "VALUES"
array(3) {
  [0]=>
  object(QuizMaster_Model_Statistic)#1275 (10) {
    ["_statisticRefId":protected]=>
    int(0)
    ["_questionId":protected]=>
    int(81)
    ["_correctCount":protected]=>
    int(1)
    ["_incorrectCount":protected]=>
    int(0)
    ["_hintCount":protected]=>
    int(0)
    ["_points":protected]=>
    int(1)
    ["_questionTime":protected]=>
    int(4)
    ["_answerData":protected]=>
    array(3) {
      [0]=>
      string(1) "1"
      [1]=>
      string(1) "0"
      [2]=>
      string(1) "0"
    }
    ["_solvedCount":protected]=>
    int(1)
    ["_mapper":protected]=>
    NULL
  }
  [1]=>
  object(QuizMaster_Model_Statistic)#1256 (10) {
    ["_statisticRefId":protected]=>
    int(0)
    ["_questionId":protected]=>
    int(101)
    ["_correctCount":protected]=>
    int(0)
    ["_incorrectCount":protected]=>
    int(1)
    ["_hintCount":protected]=>
    int(0)
    ["_points":protected]=>
    int(0)
    ["_questionTime":protected]=>
    int(4)
    ["_answerData":protected]=>
    array(4) {
      [0]=>
      string(1) "0"
      [1]=>
      string(1) "0"
      [2]=>
      string(1) "1"
      [3]=>
      string(1) "0"
    }
    ["_solvedCount":protected]=>
    int(1)
    ["_mapper":protected]=>
    NULL
  }
  [2]=>
  object(QuizMaster_Model_Statistic)#1257 (10) {
    ["_statisticRefId":protected]=>
    int(0)
    ["_questionId":protected]=>
    int(102)
    ["_correctCount":protected]=>
    int(0)
    ["_incorrectCount":protected]=>
    int(1)
    ["_hintCount":protected]=>
    int(0)
    ["_points":protected]=>
    int(0)
    ["_questionTime":protected]=>
    int(4)
    ["_answerData":protected]=>
    array(1) {
      [0]=>
      string(5) "fdsaf"
    }
    ["_solvedCount":protected]=>
    int(1)
    ["_mapper":protected]=>
    NULL
  }
}
string(11) "FORM VALUES"
NULL
[]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment