/**
  * Returns photos in this collection.
  *
  * @param string|array $fields
  * @param int $offset
  * @param int $limit
  * @param bool $escape
  * @return array [photo_id][field] = field value in appropriate field format
  * @throws waException
  */
 public function getPhotos($fields = "*,thumb,tags", $offset = 0, $limit = 50, $escape = true)
 {
     $sql = $this->getSQL();
     $sql = "SELECT " . ($this->joins ? 'DISTINCT ' : '') . $this->getFields($fields) . " " . $sql;
     //$sql .= $this->getGroupBy();
     $sql .= $this->getOrderBy();
     $sql .= " LIMIT " . ($offset ? $offset . ',' : '') . (int) $limit;
     $data = $this->getModel()->query($sql)->fetchAll('id');
     if (!$data) {
         return array();
     }
     if ($this->post_fields) {
         $ids = array_keys($data);
         foreach ($this->post_fields as $table => $fields) {
             if ($table == '_internal') {
                 foreach ($fields as $i => $f) {
                     if ($f == 'thumb' || substr($f, 0, 6) == 'thumb_') {
                         if ($f == 'thumb') {
                             $size = photosPhoto::getThumbPhotoSize();
                         } else {
                             $size = substr($f, 6);
                             switch ($size) {
                                 case 'crop':
                                     $size = photosPhoto::getCropPhotoSize();
                                     break;
                                 case 'middle':
                                     $size = photosPhoto::getMiddlePhotoSize();
                                     break;
                                 case 'big':
                                     $size = photosPhoto::getBigPhotoSize();
                                     break;
                                 case 'mobile':
                                     $size = photosPhoto::getMobilePhotoSize();
                                     break;
                             }
                         }
                         foreach ($data as $id => &$v) {
                             $v[$f] = photosPhoto::getThumbInfo($v, $size);
                         }
                         unset($v);
                     }
                     if ($f == 'frontend_link') {
                         foreach ($data as $id => &$v) {
                             $v['frontend_link'] = photosFrontendPhoto::getLink(array('url' => $this->frontend_base_url ? $this->frontend_base_url . '/' . $v['url'] : $v['url']));
                         }
                         unset($v);
                     }
                     if ($f == 'edit_rights') {
                         $photo_model_rights = new photosPhotoRightsModel();
                         $photo_ids = array();
                         foreach ($data as $id => &$v) {
                             $photo_ids[] = $id;
                             $v['edit_rights'] = false;
                         }
                         unset($v);
                         foreach ($photo_model_rights->filterAllowedPhotoIds($photo_ids, true) as $photo_id) {
                             $data[$photo_id]['edit_rights'] = true;
                         }
                     }
                 }
             } elseif ($table == 'tags') {
                 $model = $this->getModel('photo_tags');
                 $tags = $model->getTags($ids);
                 foreach ($data as $id => &$v) {
                     $v['tags'] = isset($tags[$id]) ? $tags[$id] : array();
                 }
                 unset($v);
             }
         }
     }
     if ($escape) {
         self::escapePhotoFields($data);
     }
     return $data;
 }