コード例 #1
0
ファイル: actions.class.php プロジェクト: voota/voota
 private function post_review($data)
 {
     try {
         $userId = oauthSecurityManager::checkAuthorized();
     } catch (Exception $e) {
         throw new NotAuthorizedException($e->getMessage());
     }
     $entityId = $this->getRequestParameter("entity");
     $value = $this->getRequestParameter("value");
     $text = $this->getRequestParameter("text", false);
     $type = $this->getRequestParameter("type");
     $key = oauthSecurityManager::getConsummerKey();
     if (!$entityId || !$value || !$type) {
         throw new BadRequestException("Not enough parameters.");
     }
     if ($value != -1 && $value != 1) {
         throw new BadRequestException("Invalid data for 'value'.");
     }
     $typeId = -1;
     switch ($type) {
         case 'politician':
             $typeId = Politico::NUM_ENTITY;
             $entity = PoliticoPeer::retrieveByPK($entityId);
             break;
         case 'party':
             $typeId = Partido::NUM_ENTITY;
             $entity = PartidoPeer::retrieveByPK($entityId);
             break;
         case 'proposal':
             $typeId = Propuesta::NUM_ENTITY;
             $entity = PropuestaPeer::retrieveByPK($entityId);
             break;
         default:
             throw new BadRequestException('Invalid type.');
     }
     try {
         $this->review = SfReviewManager::postReview($userId, $typeId, $entityId, $value, $text, $entity, false, 0, $key);
     } catch (Exception $e) {
         throw new Exception($e->getMessage());
     }
     return "saved.";
 }