예제 #1
0
파일: UserRest.php 프로젝트: xrlopez/TSW
 public function login($username)
 {
     $currentLogged = parent::authenticateUser();
     if ($currentLogged->getUsername() != $username) {
         header($_SERVER['SERVER_PROTOCOL'] . ' 403 Forbidden');
         echo "You are not authorized to login as anyone but you";
     } else {
         header($_SERVER['SERVER_PROTOCOL'] . ' 200 Ok');
         echo "Hello " . $username;
     }
 }
예제 #2
0
 public function getPercents($owner)
 {
     $currentUser = parent::authenticateUser();
     $startDate = $this->request->getStartDate();
     $endDate = $this->request->getEndDate();
     $types = $this->typeDAO->findByOwnerAndFilterWithPercents($owner, $startDate, $endDate);
     if ($types == NULL) {
         header($this->server->getServerProtocol() . ' 400 Bad request');
         echo "The defined interval time not contains percents";
         return;
     }
     header($this->server->getServerProtocol() . ' 200 Ok');
     header('Content-Type: application/json');
     echo json_encode($types);
 }
예제 #3
0
 public function getByOwner($owner)
 {
     $currentUser = parent::authenticateUser();
     $startDate = $this->request->getStartDate();
     $endDate = $this->request->getEndDate();
     $stocks = $this->stockDAO->findByOwnerAndFilter($owner, $startDate, $endDate);
     if ($stocks == NULL) {
         header($this->server->getServerProtocol() . ' 400 Bad request');
         echo "The defined interval time not contains stocks";
         return;
     }
     foreach ($stocks as $stock) {
         if ($stock->getOwner()->getLogin() != $currentUser->getLogin()) {
             header($this->server->getServerProtocol() . ' 403 Forbidden');
             echo "you are not the owner of this stock";
             return;
         }
     }
     $stock_array = [];
     foreach ($stocks as $stock) {
         array_push($stock_array, ["idStock" => $stock->getIdStock(), "date" => $stock->getDate(), "total" => $stock->getTotal(), "owner" => $stock->getOwner()->getLogin()]);
     }
     header($this->server->getServerProtocol() . ' 200 Ok');
     header('Content-Type: application/json');
     echo json_encode($stock_array);
 }
예제 #4
0
 public function getByOwner($owner, $param)
 {
     $currentUser = parent::authenticateUser();
     $startDate = $this->request->getStartDate();
     $endDate = $this->request->getEndDate();
     $revenues = [];
     $revenues_array = [];
     switch ($param) {
         case 'crud':
             $revenues = $this->revenueDAO->findByOwnerAndFilterWithTypes($owner, $startDate, $endDate);
             if ($revenues == NULL) {
                 header($this->server->getServerProtocol() . ' 400 Bad request');
                 echo "The defined interval time not contains revenues";
                 return;
             }
             foreach ($revenues as $revenue) {
                 if ($revenue->getOwner()->getLogin() != $currentUser->getLogin()) {
                     header($this->server->getServerProtocol() . ' 403 Forbidden');
                     echo "you are not the owner of this revenue";
                     return;
                 }
             }
             foreach ($revenues as $revenue) {
                 $types_array = [];
                 if ($revenue->getTypes() != NULL) {
                     foreach ($revenue->getTypes() as $type) {
                         array_push($types_array, ["idType" => $type->getIdType(), "name" => $type->getName(), "owner" => $currentUser->getLogin()]);
                     }
                 }
                 array_push($revenues_array, ["idRevenue" => $revenue->getIdRevenue(), "date" => $revenue->getDate(), "quantity" => $revenue->getQuantity(), "name" => $revenue->getName(), "owner" => $revenue->getOwner()->getLogin(), "types" => $types_array]);
             }
             break;
         case 'chart':
             $revenues = $this->revenueDAO->findByOwnerAndFilter($owner, $startDate, $endDate);
             if ($revenues == NULL) {
                 header($this->server->getServerProtocol() . ' 400 Bad request');
                 echo "The defined interval time not contains revenues";
                 return;
             }
             foreach ($revenues as $revenue) {
                 if ($revenue->getOwner()->getLogin() != $currentUser->getLogin()) {
                     header($this->server->getServerProtocol() . ' 403 Forbidden');
                     echo "you are not the owner of this revenue";
                     return;
                 }
             }
             $revenues_array = [];
             foreach ($revenues as $revenue) {
                 array_push($revenues_array, ["idRevenue" => $revenue->getIdRevenue(), "date" => $revenue->getDate(), "name" => $revenue->getName(), "quantity" => $revenue->getQuantity(), "owner" => $currentUser->getLogin()]);
             }
             break;
         default:
             break;
     }
     header($this->server->getServerProtocol() . ' 200 Ok');
     header('Content-Type: application/json');
     echo json_encode($revenues_array);
 }
예제 #5
0
파일: UserRest.php 프로젝트: adri229/wallas
 public function login($login)
 {
     $currentLogged = parent::authenticateUser();
     if ($currentLogged->getLogin() != $login) {
         header($this->server->getServerProtocol() . ' 403 Forbidden');
         echo "You are not authorized to login as anyone but you";
     } else {
         header($this->server->getServerProtocol() . ' 200 Ok');
         echo "Hello " . $login;
     }
 }
예제 #6
0
파일: PostRest.php 프로젝트: xrlopez/TSW
 public function createComment($postId, $data)
 {
     $currentUser = parent::authenticateUser();
     $post = $this->postMapper->findById($postId);
     if ($post == NULL) {
         header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad request');
         echo "Post with id " . $postId . " not found";
     }
     $comment = new Comment();
     $comment->setContent($data->content);
     $comment->setAuthor($currentUser);
     $comment->setPost($post);
     try {
         $comment->checkIsValidForCreate();
         // if it fails, ValidationException
         $this->commentMapper->save($comment);
         header($_SERVER['SERVER_PROTOCOL'] . ' 201 Created');
     } catch (ValidationException $e) {
         header($_SERVER['SERVER_PROTOCOL'] . ' 400 Bad request');
         echo json_encode($e->getErrors());
     }
 }
예제 #7
0
파일: TypeRest.php 프로젝트: adri229/wallas
 public function getByOwner($owner)
 {
     $currentUser = parent::authenticateUser();
     $types = $this->typeDAO->findByOwner($owner);
     if ($types == NULL) {
         header($this->server->getServerProtocol() . ' 400 Bad request');
         echo "The defined interval time not contains Spendings";
         return;
     }
     foreach ($types as $type) {
         if ($type->getOwner()->getLogin() != $currentUser->getLogin()) {
             header($this->server->getServerProtocol() . ' 403 Forbidden');
             echo "you are not the owner of this type";
             return;
         }
     }
     $type_array = array();
     foreach ($types as $type) {
         array_push($type_array, array("idType" => $type->getIdType(), "name" => $type->getName(), "owner" => $type->getOwner()->getLogin()));
     }
     header($this->server->getServerProtocol() . ' 200 Ok');
     header('Content-Type: application/json');
     echo json_encode($type_array);
 }
예제 #8
0
 /**
  * Metodo que contiene el algoritmo para la generacion de posiciones.
  * Ver diagrama de actividades del Manual Tecnico, pag 67.
  *
  */
 public function getPositions($owner)
 {
     $currentUser = parent::authenticateUser();
     $startDate = $this->request->getStartDate();
     $endDate = $this->request->getEndDate();
     $stockRef = $this->stockDAO->findByOwnerAndDate($owner, $startDate);
     $stocks = $this->stockDAO->findByOwnerAndFilter($owner, $startDate, $endDate);
     $spendings = $this->spendingDAO->findByOwnerAndFilter($owner, $startDate, $endDate);
     $revenues = $this->revenueDAO->findByOwnerAndFilter($owner, $startDate, $endDate);
     if ($stocks == NULL && $spendings == NULL && $revenues == NULL) {
         header($this->server->getServerProtocol() . ' 400 Bad request');
         echo "The defined interval time not contains spendings";
         return;
     }
     $stocksChart = [];
     $stocks_array = [];
     $begin = new DateTime($startDate);
     $end = new DateTime($endDate);
     $interval = DateInterval::createFromDateString('1 month');
     $period = new DatePeriod($begin, $interval, $end);
     foreach ($period as $dt) {
         $aux = new DateTime($dt->format("Y-m-d"));
         $initMonth = $dt;
         $topMonth = $aux->add($interval);
         foreach ($stocks as $stock) {
             if ($stock->getDate() >= $initMonth->format("Y-m-d") && $stock->getDate() < $topMonth->format("Y-m-d")) {
                 $stockRef = $stock;
             }
         }
         $quantitySpendings = 0;
         foreach ($spendings as $spending) {
             if ($stockRef != NULL) {
                 if ($spending->getDate() >= $stockRef->getDate() && $spending->getDate() <= $topMonth->format("Y-m-d")) {
                     $quantitySpendings += $spending->getQuantity();
                 }
             } else {
                 if ($spending->getDate() <= $topMonth->format("Y-m-d")) {
                     $quantitySpendings += $spending->getQuantity();
                 }
             }
         }
         $quantityRevenues = 0;
         foreach ($revenues as $revenue) {
             if ($stockRef != NULL) {
                 if ($revenue->getDate() >= $stockRef->getDate() && $revenue->getDate() < $topMonth->format("Y-m-d")) {
                     $quantityRevenues += $revenue->getQuantity();
                 }
             } else {
                 if ($revenue->getDate() <= $topMonth->format("Y-m-d")) {
                     $quantityRevenues += $revenue->getQuantity();
                 }
             }
         }
         if ($stockRef != NULL) {
             $total = $stockRef->getTotal() + $quantityRevenues - $quantitySpendings;
         } else {
             $total = $quantityRevenues - $quantitySpendings;
         }
         $stockChart = new Stock();
         $stockChart->setTotal($total);
         $stockChart->setDate($dt->format("Y-m-d"));
         array_push($stocksChart, $stockChart);
         $quantitySpendings = 0;
         $quantityRevenues = 0;
     }
     foreach ($stocksChart as $stock) {
         array_push($stocks_array, ["date" => $stock->getDate(), "total" => $stock->getTotal()]);
     }
     header($this->server->getServerProtocol() . ' 200 Ok');
     header('Content-Type: application/json');
     echo json_encode($stocks_array);
 }