photos_cnt; } function getUser(){ return $this->relation_one('users', 'user_album_owner'); } function setOwner($user){ if (!$user) return false; $this->remove_relations('user_album_owner'); $this->add_relation($user, 'user_album_owner'); } function getPhotos(){ return $this->relation('photos', 'album_photos'); } function getPost(){ return $this->relation_one('posts', 'posted_user_album', 'in'); } function getCountry(){ return $this->relation_one('countries', 'album_country'); } function setCountry(\FW\Models\Geography\Country $country){ $this->remove_relations('album_country'); $this->add_relation($country, 'album_country'); //Repost if ($p = $this->post) $p->repost(); } function getLocality(){ return $this->relation_one('localities', 'album_locality'); } function setLocality($locality){ if (!$locality) return false; $this->remove_relations('album_locality'); $this->add_relation($locality, 'album_locality'); } function getPlace(){ return $this->relation_one('places', 'album_place'); } function setPlace($place){ if (!$place) return false; $this->remove_relations('album_place'); $this->add_relation($place, 'album_place'); } function getTour(){ return $this->relation_one('tours', 'album_tour'); } function setTour($tour){ if (!$tour) return false; $this->remove_relations('album_tour'); $this->add_relation($tour, 'album_tour'); } function getMainPhoto(){ return $this->relation_one('photos', 'main_photo'); } function setMainPhoto($photo){ if (!$photo) return false; $this->remove_relations('main_photo'); $this->add_relation($photo, 'main_photo'); } function recountPhotos(){ $photos = $this->photos; $cnt = 0; if ($photos) $cnt=sizeof($photos); //Save $this->update(array("photos_cnt" => $cnt)); return $cnt; } /* function repost(){ if (!$post = $this->post){ //First photo in album - so put it to the wall $h = array( "type_id" => WALL_TYPE_USER_ALBUM, "market_id" => $this->user->market_id, "title" => $this->name, "text" => $this->description, "author" => $this->user, "publisher" => $this->user, "photos" => $this->photos ); $post = $this->container->fw->models['posts']->post($h); $post->setUserAlbum($this); }else{ $post->rebuild(); $post->repost(); } } */ function addPhoto(\FW\Models\Photos\Row $photo){ $this->add_relation($photo, 'album_photos'); $this->setMainPhoto($photo); //For post's main photo if (!$this->post) $photo->toWall(WALL_TYPE_USER_ALBUM, $photo->user); else $this->post->repost(); } function delete($with_posts=true){ if ($photos = $this->photos) foreach ($photos as $photo){ if (($photo->post)&&(!$with_posts)){ $photo->unlinkAlbum($this); } else { if (!$photo->banner) $photo->delete(); } } $post = $this->post; if ($with_posts){ if ($post) $post->delete(); }else{ //Remove link if ($post) $post->update(array('link'=>false)); } $this->remove_relations(); parent::delete(); } } class Albums extends \FW\Database\Table{ function __construct($container){ parent::__construct($container, 'user_albums', '\FW\Models\User\Album'); } } $container->models['user_albums']=new Albums($container);