public function getAlbums($public_only = false, $type = null, $owned_only = false, $count = true)
 {
     $user = wa()->getUser();
     if ($count) {
         $sql = "SELECT a.*, ac.count FROM " . $this->table . " a LEFT JOIN\n            photos_album_count ac ON a.id = ac.album_id AND ac.contact_id = i:contact_id";
     } else {
         $sql = "SELECT a.* FROM " . $this->table . " a";
     }
     if ($public_only) {
         $sql .= " WHERE a.status = 1";
     } else {
         $sql .= " JOIN photos_album_rights r ON a.id = r.album_id AND ";
         if ($user->isAdmin('photos')) {
             $sql .= '(r.group_id >= 0 OR r.group_id = -i:contact_id)';
         } else {
             $group_ids = $user->getGroups();
             $group_ids[] = 0;
             $group_ids[] = -$user->getId();
             $sql .= 'r.group_id IN (' . implode(",", $group_ids) . ')';
         }
         $sql .= " WHERE 1";
         if ($type !== null) {
             $sql .= " AND a.type = " . $this->escape($type, 'int');
         }
         if ($owned_only) {
             $sql .= " AND a.contact_id = i:contact_id";
         }
     }
     $sql .= " ORDER BY parent_id, sort";
     $albums = $this->query($sql, array('contact_id' => $user->getId()))->fetchAll($this->id);
     if ($count && $user->getId()) {
         $album_photos_model = new photosAlbumPhotosModel();
         $counter = $album_photos_model->getCountByAlbum();
         foreach ($albums as $id => &$album) {
             $album['count_new'] = 0;
             if (isset($counter[$id])) {
                 $album['count_new'] = max(0, $counter[$id] - $album['count']);
             }
         }
         unset($album);
     }
     return $albums;
 }