public function action_postAddPhoto()
 {
     $targetDir = "/assets/uploads/";
     try {
         Model_Photo::validate($_POST, $_FILES, $this->user);
         $target_file = $targetDir . basename($_FILES["file"]["name"]);
         $photo = new Model_Photo();
         $photo->add($_POST, $_FILES);
         Session::set('message', "Zdjęcie zostało dodane.");
         $this->redirect("/index.php/photos");
     } catch (Validation_Exception $exception) {
         $this->content = new View("photos/addPhoto");
         $this->content->passData('user', $this->user);
         $this->content->passData('isLogged', $this->user != null);
         $this->content->passData('errorField', $exception->field);
         $this->content->passData('error', $exception->error);
     }
 }
 public function action_searchPhotos($text)
 {
     $photos = new Model_Photo();
     $allPhotos = [];
     $this->view = new View("photos/searchPhotos");
     foreach ($photos->getAll() as $photo) {
         $p = new Model_Photo();
         $p->get($photo['_id']);
         if ($p->loaded && isset($p->bigPath) && isset($p->smallPath) && file_exists("assets/uploads/" . $p->bigPath) && file_exists("assets/uploads/" . $p->smallPath) && stripos(strtolower($p->title), strtolower($text)) !== false) {
             if (isset($p->autorUser)) {
                 $autor = new Model_User();
                 $autor->get($p->autorUser);
                 $p->autor = $autor->username;
                 if ($p->tryb == "private" && (!$this->user || $autor->username != $this->user->username)) {
                     continue;
                 }
             }
             $allPhotos[] = $p;
         }
     }
     $this->view->passData('photos', $allPhotos);
 }