$aResponse['message'] = ''; if (StudyPressUserWP::isLoggedIn()) { if (isset($_POST['action'])) { if (htmlentities($_POST['action'], ENT_QUOTES, 'UTF-8') == 'rating') { $lessonId = (int) (isset($_POST['idBox']) ? $_POST['idBox'] : 0); $value = (int) (isset($_POST['rate']) ? $_POST['rate'] : 0); $userId = (int) (isset($_POST['user']) ? $_POST['user'] : 0); $managerRate = new RateQualityManager(); $currentUser = new StudyPressUserWP(); if ($value >= 1 && $value <= 5 && $currentUser->id() === $userId) { if ($rate = $managerRate->voteExist($lessonId, $userId)) { $rate->setValue($value); $rate->setDateRate(StudyPressDB::getCurrentDateTime()); $managerRate->update($rate->getId(), $rate); } else { $managerRate->add(new RateQuality(array('value' => $value, 'userId' => $userId, 'activityId' => $lessonId, 'dateRate' => StudyPressDB::getCurrentDateTime()))); } if ($managerRate->isError()) { $success = false; } else { $success = true; } } else { $success = false; } if ($success) { $aResponse['message'] = 'Your rate has been successfuly recorded. Thanks for your rate :)'; $aResponse['server'] = $tr->__('Your rating has been recorded') . '<br />'; echo json_encode($aResponse); } else { $aResponse['error'] = true;
public function saveResult($quizId, $userId, $note, $response, $nbrQuestions, $nbrCorrects, $dateBegin, $valid) { $this->_access->delete(StudyPressDB::getTableNameResultQuiz(), array(StudyPressDB::COL_ID_QUIZ_RESULT => $quizId, StudyPressDB::COL_ID_USER_RESULT => $userId)); $a = array(StudyPressDB::COL_ID_QUIZ_RESULT => $quizId, StudyPressDB::COL_ID_USER_RESULT => $userId, StudyPressDB::COL_NOTE_RESULT => $note, StudyPressDB::COL_RESPONSE_RESULT => json_encode($response), StudyPressDB::COL_NBR_QUESTIONS_RESULT => $nbrQuestions, StudyPressDB::COL_NBR_CORRECTS_RESULT => $nbrCorrects, StudyPressDB::COL_VALIDATE_RESULT => $valid, StudyPressDB::COL_DATE_BEGIN_RESULT => $dateBegin, StudyPressDB::COL_DATE_RESULT => StudyPressDB::getCurrentDateTime()); $this->_access->insert(StudyPressDB::getTableNameResultQuiz(), $a); $idResult = $this->_access->getLastInsertId(); return $idResult; }
if (isset($_POST['action'])) { if (htmlentities($_POST['action'], ENT_QUOTES, 'UTF-8') == 'rating') { $activityId = (int) (isset($_POST['idBox']) ? $_POST['idBox'] : 0); $value = (int) (isset($_POST['rate']) ? $_POST['rate'] : 0); $userId = (int) (isset($_POST['user']) ? $_POST['user'] : 0); $domainId = (int) (isset($_POST['domain']) ? $_POST['domain'] : 0); $managerRate = new RateDomainManager(); $managerDomain = new DomainManager(); $currentUser = new StudyPressUserWP(); if ($value >= 1 && $value <= 5 && $currentUser->id() === $userId && $managerDomain->getById($domainId)) { if ($rate = $managerRate->voteExist($activityId, $userId, $domainId)) { $rate->setValue($value); $rate->setDateRate(StudyPressDB::getCurrentDateTime()); $managerRate->update($rate->getId(), $rate); } else { $managerRate->add(new RateDomain(array('value' => $value, 'userId' => $userId, 'activityId' => $activityId, 'dateRate' => StudyPressDB::getCurrentDateTime(), 'domainId' => $domainId))); } if ($managerRate->isError()) { $success = false; } else { $success = true; } } else { $success = false; } if ($success) { $aResponse['message'] = $tr->__('Your rating has been recorded'); $aResponse['server'] = $tr->__('Your rating has been recorded') . '<br />'; echo json_encode($aResponse); } else { $aResponse['error'] = true;
public function setVisitedActivity($userId, $activityId) { $userId = (int) $userId; $activityId = (int) $activityId; $visit = $this->_access->getRow("SELECT " . StudyPressDB::COL_ID_VISITE . " FROM " . StudyPressDB::getTableNameVisite() . " WHERE " . StudyPressDB::COL_ID_ACTIVITY_VISITE . " = '{$activityId}' AND " . StudyPressDB::COL_ID_USER_VISITE . " = '{$userId}'"); $currentTime = StudyPressDB::getCurrentDateTime(); if ($visit) { $this->_access->update(StudyPressDB::getTableNameVisite(), array(StudyPressDB::COL_DATE_VISITE => $currentTime), array(StudyPressDB::COL_ID_VISITE => $visit[StudyPressDB::COL_ID_VISITE])); } else { $this->_access->insert(StudyPressDB::getTableNameVisite(), array(StudyPressDB::COL_ID_ACTIVITY_VISITE => $activityId, StudyPressDB::COL_ID_USER_VISITE => $userId, StudyPressDB::COL_DATE_VISITE => $currentTime)); } }