/**
  * Add Action
  * Adds new photos to the database
  *
  * @param Rsc_Http_Request $request
  * @return Rsc_Http_Response
  */
 public function addAction(Rsc_Http_Request $request)
 {
     $env = $this->getEnvironment();
     $resources = $this->getModel('resources');
     $photos = new SupsysticSlider_Photos_Model_Photos();
     if ($env->getConfig()->isEnvironment(Rsc_Environment::ENV_DEVELOPMENT)) {
         $photos->setDebugEnabled(true);
     }
     $attachment = get_post($request->post->get('attachment_id'));
     $viewType = $request->post->get('view_type');
     $sliderId = $request->post->get('id');
     $stats = $this->getEnvironment()->getModule('stats');
     $stats->save('photos.add');
     if (!$photos->add($attachment->ID, $request->post->get('folder_id', 0))) {
         $response = array('error' => true, 'photo' => null, 'message' => sprintf($env->translate('Unable to save chosen photo %s: %s'), $attachment->post_title, $photos->getLastError()));
     } else {
         $photo = $env->getTwig()->render(sprintf('@ui/%s/image.twig', $viewType ? $viewType : 'block'), array('image' => $photos->getByAttachmentId($attachment->ID)));
         if ($sliderId && ($imageId = $photos->getByAttachmentId($attachment->ID)->id)) {
             $resources->add($sliderId, 'image', $imageId);
             $attachmentImage = wp_get_attachment_image_src($attachment->ID, array('60', '60'));
             $imageUrl = $attachmentImage[0];
             $message = '<img src="' . $imageUrl . '"/>Image was successfully imported to the Slider';
         } else {
             $message = 'Error importing image %s to Slider';
         }
         $response = array('error' => false, 'photo' => $photo, 'message' => sprintf($env->translate($message), $attachment->post_title));
     }
     return $this->response(Rsc_Http_Response::AJAX, $response);
 }