private function workup($photo)
 {
     $photo['edit_rights'] = $this->photo_rights_model->checkRights($photo, true);
     $photo['private_url'] = photosPhotoModel::getPrivateUrl($photo);
     $photo['thumb_big'] = photosPhoto::getThumbInfo($photo, photosPhoto::getBigPhotoSize());
     $photo['thumb_middle'] = photosPhoto::getThumbInfo($photo, photosPhoto::getMiddlePhotoSize());
     $photo['thumb_crop'] = photosPhoto::getThumbInfo($photo, photosPhoto::getCropPhotoSize());
     $photo['thumb'] = photosPhoto::getThumbInfo($photo, photosPhoto::getThumbPhotoSize());
     return $photo;
 }
 public function getStack($id, $options = array())
 {
     $parent_id = $this->getStackParentId($id);
     if ($parent_id) {
         $stack = $this->getByParent($parent_id);
         if (!empty($options)) {
             $need_tags = isset($options['tags']) && $options['tags'];
             if ($need_tags) {
                 $photo_tags_model = new photosPhotoTagsModel();
             }
             foreach ($stack as &$s) {
                 if ($need_tags) {
                     $s['tags'] = $photo_tags_model->getTags($s['id']);
                 }
                 $s['thumb'] = photosPhoto::getThumbInfo($s, photosPhoto::getThumbPhotoSize());
                 $s['thumb_crop'] = photosPhoto::getThumbInfo($s, photosPhoto::getCropPhotoSize());
                 $s['thumb_big'] = photosPhoto::getThumbInfo($s, photosPhoto::getBigPhotoSize());
                 $s['thumb_middle'] = photosPhoto::getThumbInfo($s, photosPhoto::getMiddlePhotoSize());
             }
             unset($s);
         }
         return $stack;
     }
     return null;
 }
 public static function getPhotoCrop($photo_id)
 {
     static $photos = array();
     static $photo_model = null;
     $photo_model = !is_null($photo_model) ? $photo_model : new photosPhotoModel();
     if (!isset($photos[$photo_id])) {
         $photo = $photo_model->getById($photo_id);
         $photos[$photo_id] = photosPhoto::getPhotoUrl($photo, photosPhoto::getCropPhotoSize());
     }
     return $photos[$photo_id];
 }
 /**
  * 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;
 }