Example #1
0
 /**
  * Action: add note
  */
 public function action_note()
 {
     $this->history = false;
     /** @var  Model_Gallery  $gallery */
     $gallery_id = (int) $this->request->param('gallery_id');
     $gallery = new Model_Gallery($gallery_id);
     if (!$gallery->loaded()) {
         throw new Model_Exception($gallery, $gallery_id);
     }
     /** @var  Model_Image $image */
     $image_id = $this->request->param('id');
     $image = new Model_Image($image_id);
     if (!$image->loaded()) {
         throw new Model_Exception($image, $image_id);
     }
     // Permission check
     Permission::required($image, Model_Image::PERMISSION_NOTE, self::$user);
     // Create note
     if (isset($_POST['name']) && trim($_POST['name'] != '')) {
         // Get note user
         $username = trim($_POST['name']);
         $user = Model_User::find_user($username);
         if (!$user && ($user_id = Arr::get($_POST, 'user_id'))) {
             $user = Model_User::find_user($user_id);
         }
         try {
             $position = Arr::intersect($_POST, array('x', 'y', 'width', 'height'), true);
             $image->add_note(self::$user->id, count($position) == 4 ? $position : null, $user ? $user : $username);
             // Newsfeed
             if ($user) {
                 NewsfeedItem_Galleries::note(self::$user, $gallery, $image, $user);
             }
         } catch (Validation_Exception $e) {
         }
     }
     // Redirect back to image
     // @todo: ajaxify for more graceful approach
     $this->request->redirect(Route::get('gallery_image')->uri(array('gallery_id' => Route::model_id($gallery), 'id' => $image->id, 'action' => '')));
 }