Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow record sliding in page.resources.fal with traits #825

Merged
merged 4 commits into from
Aug 8, 2015
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[TASK] Make AbstractContentViewHelper use SlideViewHelperTrait
The sliding-related code from AbstractContentViewHelper was adopted into SlideViewHelperTrait and thus does not need to be duplicated here.
  • Loading branch information
pkerling committed Jun 16, 2015
commit e1dae68752206a1c5785da7379313f899016c2f2
74 changes: 11 additions & 63 deletions Classes/ViewHelpers/Content/AbstractContentViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
* LICENSE.md file that was distributed with this source code.
*/

use FluidTYPO3\Vhs\Service\PageSelectService;
use FluidTYPO3\Vhs\Traits\SlideViewHelperTrait;
use TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
use TYPO3\CMS\Fluid\Core\ViewHelper\AbstractViewHelper;

Expand All @@ -25,6 +25,8 @@
*/
abstract class AbstractContentViewHelper extends AbstractViewHelper {

use SlideViewHelperTrait;

/**
* @var \TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer
*/
Expand All @@ -35,10 +37,6 @@ abstract class AbstractContentViewHelper extends AbstractViewHelper {
*/
protected $configurationManager;

/**
* @var \FluidTYPO3\Vhs\Service\PageSelectService
*/
protected $pageSelect;

/**
* @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
Expand All @@ -49,77 +47,33 @@ public function injectConfigurationManager(ConfigurationManagerInterface $config
$this->contentObject = $configurationManager->getContentObject();
}

/**
* @param \FluidTYPO3\Vhs\Service\PageSelectService $pageSelect
* @return void
*/
public function injectPageSelectService(PageSelectService $pageSelect) {
$this->pageSelect = $pageSelect;
}

/**
* Initialize
*/
public function initializeArguments() {
$this->registerArgument('column', 'integer', 'Name of the column to render', FALSE, 0);
$this->registerArgument('limit', 'integer', 'Optional limit to the number of content elements to render');
$this->registerArgument('order', 'string', 'Optional sort field of content elements - RAND() supported', FALSE, 'sorting');
$this->registerArgument('order', 'string', 'Optional sort field of content elements - RAND() supported. Note that when sliding is enabled, the sorting will be applied to records on a per-page basis and not to the total set of collected records.', FALSE, 'sorting');
$this->registerArgument('sortDirection', 'string', 'Optional sort direction of content elements', FALSE, 'ASC');
$this->registerArgument('pageUid', 'integer', 'If set, selects only content from this page UID', FALSE, 0);
$this->registerArgument('contentUids', 'array', 'If used, replaces all conditions with an "uid IN (1,2,3)" style condition using the UID values from this array');
$this->registerArgument('sectionIndexOnly', 'boolean', 'If TRUE, only renders/gets content that is marked as "include in section index"', FALSE, FALSE);
$this->registerArgument('slide', 'integer', 'Enables Content Sliding - amount of levels which shall get walked up the rootline. For infinite sliding (till the rootpage) set to -1)', FALSE, 0);
$this->registerArgument('slideCollect', 'integer', 'If TRUE, content is collected up the root line. If FALSE, only the first PID which has content is used. If greater than zero, this value overrides $slide', FALSE, 0);
$this->registerArgument('slideCollectReverse', 'boolean', 'Normally when collecting content elements the elements from the actual page get shown on the top and those from the parent pages below those. You can invert this behaviour (actual page elements at bottom) by setting this flag))', FALSE, 0);
$this->registerArgument('loadRegister', 'array', 'List of LOAD_REGISTER variable');
$this->registerArgument('render', 'boolean', 'Optional returning variable as original table rows', FALSE, TRUE);
$this->registerArgument('hideUntranslated', 'boolean', 'If FALSE, will NOT include elements which have NOT been translated, if current language is NOT the default language. Default is to show untranslated elements but never display the original if there is a translated version', FALSE, FALSE);
$this->registerSlideArguments();
}

/**
* Get content records based on column and pid
*
* @param integer $limit
* @param string $order
* @return array
*/
protected function getContentRecords($limit = NULL, $order = NULL) {
protected function getContentRecords() {
$limit = $this->arguments['limit'];

$pageUid = $this->getPageUid();
$slide = (integer) $this->arguments['slide'];
$slideCollectReverse = (boolean) $this->arguments['slideCollectReverse'];
$slideCollect = (integer) $this->arguments['slideCollect'];
if (0 < $slideCollect) {
// $slideCollect overrides $slide to automatically start sliding if
// collection is enabled.
$slide = $slideCollect;
}

// find out which storage page UIDs to read from, respecting slide depth
$storagePageUids = array();
if (0 === $slide) {
$storagePageUids[] = $pageUid;
} else {
$rootLine = $this->pageSelect->getRootLine($pageUid, NULL, $slideCollectReverse);
if (-1 !== $slide) {
$rootLine = array_slice($rootLine, 0, $slide);
}
foreach ($rootLine as $page) {
$storagePageUids[] = (integer) $page['uid'];
}
}
// select content elements, respecting slide and slideCollect.
$contentRecords = array();
do {
$storagePageUid = array_shift($storagePageUids);
$contentFromPageUid = $this->getContentRecordsFromPage($storagePageUid, $limit, $order);
if (0 < count($contentFromPageUid)) {
$contentRecords = array_merge($contentRecords, $contentFromPageUid);
if (0 === $slideCollect) {
// stop collecting because argument said so and we've gotten at least one record now.
break;
}
}
} while (0 < count($storagePageUids));
$contentRecords = $this->getSlideRecords($pageUid, $limit);

if (TRUE === (boolean) $this->arguments['render']) {
$contentRecords = $this->getRenderedRecords($contentRecords);
Expand All @@ -131,17 +85,11 @@ protected function getContentRecords($limit = NULL, $order = NULL) {
/**
* @param integer $pageUid
* @param integer $limit
* @param string $order
* @return array[]
*/
protected function getContentRecordsFromPage($pageUid, $limit, $order) {
protected function getSlideRecordsFromPage($pageUid, $limit) {
$column = (integer) $this->arguments['column'];
if (NULL === $limit && FALSE === empty($this->arguments['limit'])) {
$limit = (integer) $this->arguments['limit'];
}
if (NULL === $order && FALSE === empty($this->arguments['order'])) {
$order = $this->arguments['order'];
}
$order = $this->arguments['order'];
if (FALSE === empty($order)) {
$sortDirection = strtoupper(trim($this->arguments['sortDirection']));
if ('ASC' !== $sortDirection && 'DESC' !== $sortDirection) {
Expand Down