Esempio n. 1
0
 /**
  * Creates a new tag
  */
 public function createAction()
 {
     if (!$this->request->isPost()) {
         return $this->dispatcher->forward(array("controller" => "tags", "action" => "index"));
     }
     $tag = new Tags();
     $tag->id = $this->request->getPost("id");
     $tag->tag = $this->request->getPost("tag");
     if (!$tag->save()) {
         foreach ($tag->getMessages() as $message) {
             $this->flash->error($message);
         }
         return $this->dispatcher->forward(array("controller" => "tags", "action" => "new"));
     }
     $this->flash->success("tag was created successfully");
     return $this->dispatcher->forward(array("controller" => "tags", "action" => "index"));
 }
 public function newAction()
 {
     $response = new ApiResponse();
     if ($this->request->isPost()) {
         $tag = new Tags();
         $tag->id = uniqid();
         $tag->name = $this->request->getPost('name');
         if ($this->request->hasFiles() == true) {
             $baseLocation = 'files/';
             foreach ($this->request->getUploadedFiles() as $file) {
                 $photos = new Photos();
                 $unique_filename = $tag->id;
                 $photos->size = $file->getSize();
                 $photos->original_name = $file->getName();
                 $photos->file_name = $unique_filename;
                 $photos->extension = $file->getExtension();
                 $location = $baseLocation . $unique_filename . "." . $file->getExtension();
                 $photos->public_link = $location;
                 try {
                     if (!$photos->save()) {
                         $response->setResponseError($photos->getMessages());
                     } else {
                         //Move the file into the application
                         $file->moveTo($location);
                         $tag->icon = $photos->public_link;
                     }
                 } catch (PDOException $e) {
                     $response->setResponseError($e->getMessage());
                 }
             }
         }
         try {
             if ($tag->save() == false) {
                 $response->setResponseError($tag->getMessages());
             } else {
                 $response->setResponseMessage($tag->id);
             }
         } catch (PDOException $e) {
             $response->setResponseError($e->getMessage());
         }
     } else {
         $response->setResponseError('Wrong HTTP Method');
     }
     return $response;
 }
Esempio n. 3
0
  * 3) Saving the imageTag
  */
 foreach ($data as $tagRow) {
     $name = $filter->sanitize($tagRow['name'], 'string');
     //Get tag if it exists already
     $tag = Tags::findFirst("name = '" . $name . "' AND category_id = '" . $tagRow['category_id'] . "'");
     if (!$tag) {
         $tag = new Tags();
     }
     $tag->name = $name;
     $tag->category_id = $tagRow['category_id'];
     //If the tag could not be saved, dump the error messages
     if (!$tag->save()) {
         echo 'could not save tag.';
         var_dump($tagRow);
         var_dump($tag->getMessages());
         $app->response->setStatusCode('500');
         $app->response->send();
     }
     $tag->refresh();
     //Create an imageTag for each tag
     $imagesTags = new ImagesTags();
     $imagesTags->tag_id = $tag->id;
     $imagesTags->image_id = $image->id;
     $imagesTags->x = $tagRow['x'];
     $imagesTags->y = $tagRow['y'];
     $imagesTags->user_id = $user->getFbId();
     //If the imageTag could not be saved, dump the error message
     if (!$imagesTags->save()) {
         var_dump($imagesTags->getMessages());
         $app->response->setStatusCode('500');