Ejemplo n.º 1
0
 /**
  * Returns photo list
  *
  * @param string $type
  * @param int $page
  * @param int $limit
  * @param bool $checkPrivacy
  * @param null $exclude
  * @return array of PHOTO_BOL_Photo
  */
 public function findPhotoList($type, $page, $limit, $checkPrivacy = true, $exclude = null)
 {
     if ($type == 'toprated') {
         $first = ($page - 1) * $limit;
         $topRatedList = BOL_RateService::getInstance()->findMostRatedEntityList('photo_rates', $first, $limit, $exclude);
         if (!$topRatedList) {
             return array();
         }
         $photoArr = $this->photoDao->findPhotoInfoListByIdList(array_keys($topRatedList));
         $photos = array();
         foreach ($photoArr as $key => $photo) {
             $photos[$key] = $photo;
             $photos[$key]['score'] = $topRatedList[$photo['id']]['avgScore'];
             $photos[$key]['rates'] = $topRatedList[$photo['id']]['ratesCount'];
         }
         usort($photos, array('PHOTO_BOL_PhotoService', 'sortArrayItemByDesc'));
     } else {
         $photos = $this->photoDao->getPhotoList($type, $page, $limit, $checkPrivacy, $exclude);
     }
     if ($photos) {
         foreach ($photos as $key => $photo) {
             $photos[$key]['url'] = $this->getPhotoPreviewUrl($photo['id'], $photo['hash']);
         }
     }
     return $photos;
 }
Ejemplo n.º 2
0
 /**
  * Returns photo list
  *
  * @param string $type
  * @param int $page
  * @param int $limit
  * @param null $exclude
  * @return array of PHOTO_BOL_Photo
  */
 public function findPhotoList($listType, $page, $limit, $exclude = null, $type = self::TYPE_PREVIEW)
 {
     $first = ($page - 1) * $limit;
     if (in_array($listType, array('toprated', 'most_discussed'))) {
         switch ($listType) {
             case 'toprated':
                 $topRatedList = BOL_RateService::getInstance()->findMostRatedEntityList('photo_rates', $first, $limit, $exclude);
                 if (!$topRatedList) {
                     return array();
                 }
                 $photoArr = $this->photoDao->findPhotoInfoListByIdList(array_keys($topRatedList), $listType);
                 $photos = array();
                 foreach ($photoArr as $key => $photo) {
                     $photos[$key] = $photo;
                     $photos[$key]['score'] = $topRatedList[$photo['id']]['avgScore'];
                     $photos[$key]['rates'] = $topRatedList[$photo['id']]['ratesCount'];
                 }
                 usort($photos, array('PHOTO_BOL_PhotoService', 'sortArrayItemByDesc'));
                 break;
             case 'most_discussed':
                 $discussedList = BOL_CommentService::getInstance()->findMostCommentedEntityList('photo_comments', $first, $limit);
                 if (empty($discussedList)) {
                     return array();
                 }
                 $photoArr = $this->photoDao->findPhotoInfoListByIdList(array_keys($discussedList), $listType);
                 $photos = array();
                 foreach ($photoArr as $key => $photo) {
                     $photos[$key] = $photo;
                     $photos[$key]['commentCount'] = $discussedList[$photo['id']]['commentCount'];
                 }
                 usort($photos, array('PHOTO_BOL_PhotoService', 'sortArrayItemByCommentCount'));
                 break;
         }
     } else {
         $photos = $this->photoDao->getPhotoList($listType, $first, $limit, $exclude, FALSE);
     }
     if ($photos) {
         if (!in_array($type, $this->getPhotoTypes())) {
             $type = self::TYPE_PREVIEW;
         }
         foreach ($photos as $key => $photo) {
             $photos[$key]['url'] = $this->getPhotoUrlByType($photo['id'], $type, $photo['hash'], !empty($photo['dimension']) ? $photo['dimension'] : FALSE);
         }
     }
     return $photos;
 }