protected static function _sonnbPhotoIndexParams() { $albumModel = self::$controller->getModelFromCache('Nobita_Teams_Model_XenGallery_Album'); $options = XenForo_Application::get('options'); $visitor = XenForo_Visitor::getInstance(); $galleryAlbumModel = self::$controller->getModelFromCache('sonnb_XenGallery_Model_Album'); $page = max(1, self::$input->filterSingle('page', XenForo_Input::UINT)); $albumPerPage = $options->Teams_photosPerPage; $order = self::$input->filterSingle('order', XenForo_Input::STRING); $orderDirection = self::$input->filterSingle('direction', XenForo_Input::STRING); Nobita_Teams_sonnb_XenGallery_Helper::getAlbumSort($order, $orderDirection, $defaultOrder, $defaultOrderDirection); $conditions = self::_getDefaultConditions($team); $fetchElements = self::_getAlbumFetchElements($conditions); $albumFetchConditions = $fetchElements['conditions']; $albumFetchOptions = $fetchElements['options'] + array('perPage' => $albumPerPage, 'page' => $page, 'order' => $order, 'orderDirection' => $orderDirection); $totalAlbums = $galleryAlbumModel->countAlbums($albumFetchConditions); $pageRoute = TEAM_ROUTE_PREFIX . '/photos'; self::$controller->canonicalizePageNumber($page, $albumPerPage, $totalAlbums, $pageRoute, $team); $albums = $galleryAlbumModel->getAlbums($albumFetchConditions, $albumFetchOptions); $albums = $galleryAlbumModel->prepareAlbums($albums, $albumFetchOptions); foreach ($albums as $albumId => $album) { if (!$galleryAlbumModel->canViewAlbum($album)) { unset($albums[$albumId]); } } $albums = $galleryAlbumModel->attachCoversToAlbums($albums, $albumFetchOptions); $pageNavParams = array(); $pageNavParams['order'] = $order != $defaultOrder ? $order : false; $pageNavParams['direction'] = $orderDirection != $defaultOrderDirection ? $orderDirection : false; return array('templateName' => 'Team_photo', 'viewName' => 'sonnb_XenGallery_ViewPublic_Album_List', 'canCreateAlbum' => $albumModel->canCreateAlbum(), 'albums' => $albums, 'displayMostViewed' => false, 'order' => $order, 'orderDirection' => $orderDirection, 'pageNavParams' => $pageNavParams, 'page' => $page, 'canEmbedVideos' => false, 'albumsPerPage' => $albumPerPage, 'totalAlbums' => $totalAlbums, 'pageRoute' => $pageRoute, 'provider' => 'sonnb_xengallery'); }
public function actionIndex() { $album = $this->_getAlbumOrError(); if (empty($album['team_id'])) { return $this->responseRedirect(XenForo_ControllerResponse_Redirect::RESOURCE_CANONICAL_PERMANENT, $this->_buildLink('gallery/albums', $albums)); } list($team, $category) = $this->_getTeamHelper()->assertTeamValidAndViewable($album['team_id']); $this->_assertCanViewTab($team, $category); $options = XenForo_Application::get('options'); $visitor = XenForo_Visitor::getInstance(); $albumModel = $this->_getAlbumModel(); $page = max(1, $this->_input->filterSingle('page', XenForo_Input::UINT)); $order = $this->_input->filterSingle('order', XenForo_Input::STRING); $orderDirection = $this->_input->filterSingle('direction', XenForo_Input::STRING); Nobita_Teams_sonnb_XenGallery_Helper::getContentSort($order, $orderDirection, $defaultOrder, $defaultOrderDirection); $contentPerPage = $options->sonnbXG_photoPerPage; $commentOnLoad = $options->sonnbXG_commentPerPage; $contentFetchCondition = $this->_getContentModel()->getPermissionBasedContentFetchConditions(); $contentFetchOptions = array('join' => sonnb_XenGallery_Model_Content::FETCH_DATA | sonnb_XenGallery_Model_Content::FETCH_PHOTO | sonnb_XenGallery_Model_Content::FETCH_VIDEO, 'likeUserId' => $visitor['user_id'], 'watchUserId' => $visitor['user_id'], 'followingUserId' => $visitor['user_id'], 'perPage' => $contentPerPage, 'page' => $page, 'order' => $order, 'orderDirection' => $orderDirection); $totalContents = $this->_getContentModel()->countContentsByAlbumId($album['album_id'], $contentFetchCondition, $contentFetchOptions); $contents = $this->_getContentModel()->getContentsByAlbumId($album['album_id'], $contentFetchCondition, $contentFetchOptions); $contents = $this->_getContentModel()->prepareContents($contents, $contentFetchOptions); if (!empty($contents)) { $album['contents'] = array_slice($contents, 0, 4); } foreach ($contents as $_contentId => $_content) { if (!$_content['canView']) { unset($contents[$_contentId]); } } if ($commentOnLoad > 0) { $commentConditions = array('content_id' => $album['album_id'], 'content_type' => sonnb_XenGallery_Model_Album::$contentType) + $this->_getCommentModel()->getPermissionBasedCommentFetchConditions(); $commentFetchOptions = array('join' => sonnb_XenGallery_Model_Comment::FETCH_USER, 'likeUserId' => $visitor['user_id'], 'limit' => $commentOnLoad, 'order' => 'comment_date', 'orderDirection' => 'desc'); $album['comments'] = $this->_getCommentModel()->getComments($commentConditions, $commentFetchOptions); $album['comments'] = $this->_getCommentModel()->prepareComments($album['comments'], $commentFetchOptions); $album['comments'] = array_reverse($album['comments'], true); } if (!empty($album['comments'])) { $firstShownComment = reset($album['comments']); $firstShownCommentDate = $firstShownComment['comment_date']; $lastShownComment = end($album['comments']); $lastShownCommentDate = $lastShownComment['comment_date']; } else { $firstShownCommentDate = 0; $lastShownCommentDate = 0; } /* * Get page params for default sort, just for future use. */ $pageNavParams = array(); $pageNavParams['order'] = $order != $defaultOrder ? $order : false; $pageNavParams['direction'] = $orderDirection != $defaultOrderDirection ? $orderDirection : false; $albumModel->logAlbumView($album['album_id']); $inlineModOptions = $this->_getContentModel()->getInlineModeration(); $XG_category = null; $XG_categories = $this->_getCategoryModel()->getAllCachedCategories(); if (isset($XG_categories[$album['category_id']])) { $XG_category = $XG_categories[$album['category_id']]; } $fields = $this->_getFieldModel()->getApplicableFieldsByContentId(sonnb_XenGallery_Model_Album::$contentType, $album['album_id'], $XG_category, true, false); $viewParams = array('album' => $album, 'team' => $team, 'category' => $category, 'inlineModOptions' => $inlineModOptions, 'contents' => $contents, 'order' => $order, 'orderDirection' => $orderDirection, 'pageNavParams' => $pageNavParams, 'page' => $page, 'photosPerPage' => $contentPerPage, 'totalPhotos' => $totalContents, 'commentOnLoad' => $commentOnLoad, 'firstShownCommentDate' => $firstShownCommentDate, 'lastShownCommentDate' => $lastShownCommentDate, 'commentShownCount' => $album['comment_count'] > $commentOnLoad ? $commentOnLoad : $album['comment_count'], 'canEmbedVideos' => $this->_getGalleryModel()->canEmbedVideo(), 'includeTaggerJs' => $this->_getGalleryModel()->includeJsTagger(), 'XenGallery_categories' => $XG_categories, 'XenGallery_category' => $XG_category); return $this->_getTeamHelper()->getTeamViewWrapper('photos', $team, $category, $this->responseView('sonnb_XenGallery_ViewPublic_Album_View', 'Team_xengallery_album_view', $viewParams)); }