Ejemplo n.º 1
0
 /**
  * 
  * @param \Entity\Equipment $equipment
  */
 private function validateEquipment($equipment)
 {
     if (get_class($equipment) != 'Entity\\Equipment') {
         throw new \Exception('Equipamento inválido');
     }
     if (strlen($equipment->getName()) < 1) {
         throw new \Exception('Tamanho mínimo é 1 caracter');
     }
     if (strlen($equipment->getName()) > 50) {
         throw new \Exception('Tamanho máximo é 80 caracteres');
     }
     $areaRep = new \Repository\AreaRepository();
     $area = $areaRep->getArea($equipment->getAreaId());
     if (get_class($area) != 'Entity\\Area') {
         throw new \Exception('Equipamento inválido');
     }
     if ($area->getAreaId() != $equipment->getAreaId()) {
         throw new \Exception('Equipamento inválido');
     }
     return true;
 }
Ejemplo n.º 2
0
 public function deleteAreaAction($id)
 {
     try {
         $app = \Slim\Slim::getInstance();
         $app->add(new \Slim\Middleware\ContentTypes());
         $data = $app->request()->getBody();
         $areaRep = new \Repository\AreaRepository();
         $area = $areaRep->getArea($id);
         $areaRep->delete($area);
         $resource = new \League\Fractal\Resource\Item($area, new \Transformer\AreaTransformer());
         return $this->writeJson($resource, 200);
     } catch (\Exception $exc) {
         return $this->error($exc->getMessage());
     }
 }