Created
February 4, 2017 14:47
-
-
Save goldhat/489064b2d03abea302734c9513b6d74f to your computer and use it in GitHub Desktop.
Stats Save
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Output: