public function updateRate() { if (empty($_POST['entityId']) || empty($_POST['entityType']) || empty($_POST['rate']) || empty($_POST['ownerId'])) { exit(json_encode(array('errorMessage' => 'Invalid request'))); } $service = BOL_RateService::getInstance(); $entityId = (int) $_POST['entityId']; $entityType = trim($_POST['entityType']); $rate = (int) $_POST['rate']; $ownerId = (int) $_POST['ownerId']; $userId = OW::getUser()->getId(); if (!OW::getUser()->isAuthenticated()) { exit(json_encode(array('errorMessage' => OW::getLanguage()->text('base', 'rate_cmp_auth_error_message')))); } if ($userId === $ownerId) { exit(json_encode(array('errorMessage' => OW::getLanguage()->text('base', 'rate_cmp_owner_cant_rate_error_message')))); } if (false) { //TODO add authorization error exit(json_encode(array('errorMessage' => 'Auth error'))); } if (BOL_UserService::getInstance()->isBlocked(OW::getUser()->getId(), $ownerId)) { exit(json_encode(array('errorMessage' => OW::getLanguage()->text('base', 'user_block_message')))); } $rateItem = $service->findRate($entityId, $entityType, $userId); if ($rateItem === null) { $rateItem = new BOL_Rate(); $rateItem->setEntityId($entityId)->setEntityType($entityType)->setUserId($userId)->setActive(true); } $rateItem->setScore($rate)->setTimeStamp(time()); $service->saveRate($rateItem); $totalScoreCmp = new BASE_CMP_TotalScore($entityId, $entityType); exit(json_encode(array('totalScoreCmp' => $totalScoreCmp->render(), 'message' => OW::getLanguage()->text('base', 'rate_cmp_success_message')))); }
public function updateRate() { $service = BOL_RateService::getInstance(); $entityId = (int) $_POST['entityId']; $entityType = trim($_POST['entityType']); $rate = (int) $_POST['rate']; $ownerId = (int) $_POST['ownerId']; $userId = OW::getUser()->getId(); if (!OW::getUser()->isAuthenticated()) { echo json_encode(array('errorMessage' => OW::getLanguage()->text('base', 'rate_cmp_auth_error_message'))); exit; } if ($userId === $ownerId) { echo json_encode(array('errorMessage' => OW::getLanguage()->text('base', 'rate_cmp_owner_cant_rate_error_message'))); exit; } if (false) { echo json_encode(array('errorMessage' => 'Auth error')); exit; } $rateItem = $service->findRate($entityId, $entityType, $userId); if ($rateItem === null) { $rateItem = new BOL_Rate(); $rateItem->setEntityId($entityId)->setEntityType($entityType)->setUserId($userId)->setActive(true); } $rateItem->setScore($rate)->setTimeStamp(time()); $service->saveRate($rateItem); $event = new OW_Event('ocstopusers.rate_user', array('ownerId' => $entityId, 'userId' => $userId, 'rate' => $rate)); OW::getEventManager()->trigger($event); $totalScoreCmp = new OCSTOPUSERS_CMP_TotalScore($entityId, $entityType); echo json_encode(array('totalScoreCmp' => $totalScoreCmp->render(), 'message' => OW::getLanguage()->text('base', 'rate_cmp_success_message'))); exit; }
public function ajaxRate($params) { if (empty($params['entityId']) || empty($params['rate']) || empty($params['ownerId'])) { return array('result' => FALSE, 'error' => 'Invalid request'); } $entityId = (int) $params['entityId']; $rate = (int) $params['rate']; $ownerId = (int) $params['ownerId']; $userId = OW::getUser()->getId(); if (!OW::getUser()->isAuthenticated()) { return array('result' => FALSE, 'error' => OW::getLanguage()->text('base', 'rate_cmp_auth_error_message')); } if ($userId === $ownerId) { return array('result' => FALSE, 'error' => OW::getLanguage()->text('base', 'rate_cmp_owner_cant_rate_error_message')); } if (BOL_UserService::getInstance()->isBlocked(OW::getUser()->getId(), $ownerId)) { return array('result' => FALSE, 'error' => OW::getLanguage()->text('base', 'user_block_message')); } $service = BOL_RateService::getInstance(); if (($rateItem = $service->findRate($entityId, 'photo_rates', $userId)) === NULL) { $rateItem = new BOL_Rate(); $rateItem->setEntityId($entityId)->setEntityType('photo_rates')->setUserId($userId)->setActive(TRUE); } $rateItem->setScore($rate)->setTimeStamp(time()); $service->saveRate($rateItem); return array('result' => TRUE, 'rateInfo' => $service->findRateInfoForEntityItem($entityId, 'photo_rates'), 'msg' => OW::getLanguage()->text('base', 'rate_cmp_success_message')); }