Created
October 9, 2014 07:01
-
-
Save anonymous/bc0e51006a12bedbdad7 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
defined('C5_EXECUTE') or die("Access Denied."); | |
$th = Loader::helper('text'); | |
$c = Page::getCurrentPage(); | |
$dh = Core::make('helper/date'); /* @var $dh \Concrete\Core\Localization\Service\Date */ | |
?> | |
<?php | |
// these lines make sorting by the custom attribute (event_date_time) work | |
$pl = new PageList(); | |
// prevents blog_entry page types from showing up when this custom template is used on the Events parent page | |
$pl->filterByCollectionTypeHandle('event_entry'); | |
// gets the current time minus 1 day as a unix timestamp | |
// http://us2.php.net/manual/en/datetime.formats.relative.php | |
$datetime = strtotime('-1 day'); | |
// takes the $datetime (unix timestamp format) and converts it to the mysql date time format - "Y-m-d H:i:s" | |
$mysqldate = date("Y-m-d H:i:s", $datetime); | |
// filters the database request for pages by the attribute "event_date_time" and that are no more than a day old | |
// "event_date_time" is a custom attribute for the time of the event, the value is a time | |
// $mysqldate is the current time minus one day | |
// the comparison is: event_date_time > $mysqldate | |
// if the event_date_time is greater (upcoming date time), then it will not be filtered | |
// $pl->filterbyAttribute($column, $value, '=') - the third argument is the comparison | |
$pl->filterbyAttribute('event_date_time', $mysqldate, '>'); | |
// sorts pages by custom attribute "event_date_time" in ascending order - the soonest to latest | |
// the custom attribute is prefixed with "ak_" | |
$pl->sortBy('ak_event_date_time', 'asc'); | |
$pagination = $pl->getPagination(); | |
// limits the page results - e.g. $pagination->setMaxPerPage(3); limits the results to 3 | |
$pagination->setMaxPerPage(3); | |
// retrieves the page results | |
$pages = $pagination->getCurrentPageResults(); | |
?> | |
<?php if ( $c->isEditMode() && $controller->isBlockEmpty()) { ?> | |
<div class="ccm-edit-mode-disabled-item"><?php echo t('Empty Page List Block.')?></div> | |
<?php } else { ?> | |
<div class="ccm-block-page-list-wrapper"> | |
<?php if ($pageListTitle): ?> | |
<div class="ccm-block-page-list-header"> | |
<h5><?php echo $pageListTitle?></h5> | |
</div> | |
<?php endif; ?> | |
<?php if ($rssUrl): ?> | |
<a href="<?php echo $rssUrl ?>" target="_blank" class="ccm-block-page-list-rss-feed"><i class="fa fa-rss"></i></a> | |
<?php endif; ?> | |
<div class="ccm-block-page-list-pages"> | |
<?php foreach ($pages as $page): | |
// get the event_date_time attribute | |
$event_date_time = $page->getAttribute('event_date_time'); | |
// convert the $event_date_time from MySQL format to a unix timestamp | |
// format the unix timestamp - "l F jS g:ia" - e.g. Thursday October 2nd 10:22pm | |
// http://us2.php.net/manual/en/function.date.php | |
$event_date_time = date("l F jS g:ia", strtotime($event_date_time)); | |
// Prepare data for each page being listed... | |
$buttonClasses = 'ccm-block-page-list-read-more'; | |
$entryClasses = 'ccm-block-page-list-page-entry'; | |
$title = $th->entities($page->getCollectionName()); | |
$url = $nh->getLinkToCollection($page); | |
$target = ($page->getCollectionPointerExternalLink() != '' && $page->openCollectionPointerExternalLinkInNewWindow()) ? '_blank' : $page->getAttribute('nav_target'); | |
$target = empty($target) ? '_self' : $target; | |
$description = $page->getCollectionDescription(); | |
$description = $controller->truncateSummaries ? $th->wordSafeShortText($description, $controller->truncateChars) : $description; | |
$description = $th->entities($description); | |
$thumbnail = false; | |
if ($displayThumbnail) { | |
$thumbnail = $page->getAttribute('thumbnail'); | |
} | |
$includeEntryText = false; | |
if ($includeName || $includeDescription || $useButtonForLink) { | |
$includeEntryText = true; | |
} | |
if (is_object($thumbnail) && $includeEntryText) { | |
$entryClasses = 'ccm-block-page-list-page-entry-horizontal'; | |
} | |
$date = $dh->formatDateTime($page->getCollectionDatePublic(), true); | |
//Other useful page data... | |
//$last_edited_by = $page->getVersionObject()->getVersionAuthorUserName(); | |
//$original_author = Page::getByID($page->getCollectionID(), 1)->getVersionObject()->getVersionAuthorUserName(); | |
/* CUSTOM ATTRIBUTE EXAMPLES: | |
* $example_value = $page->getAttribute('example_attribute_handle'); | |
* | |
* HOW TO USE IMAGE ATTRIBUTES: | |
* 1) Uncomment the "$ih = Loader::helper('image');" line up top. | |
* 2) Put in some code here like the following 2 lines: | |
* $img = $page->getAttribute('example_image_attribute_handle'); | |
* $thumb = $ih->getThumbnail($img, 64, 9999, false); | |
* (Replace "64" with max width, "9999" with max height. The "9999" effectively means "no maximum size" for that particular dimension.) | |
* (Change the last argument from false to true if you want thumbnails cropped.) | |
* 3) Output the image tag below like this: | |
* <img src="<?php echo $thumb->src ?>" width="<?php echo $thumb->width ?>" height="<?php echo $thumb->height ?>" alt="" /> | |
* | |
* ~OR~ IF YOU DO NOT WANT IMAGES TO BE RESIZED: | |
* 1) Put in some code here like the following 2 lines: | |
* $img_src = $img->getRelativePath(); | |
* $img_width = $img->getAttribute('width'); | |
* $img_height = $img->getAttribute('height'); | |
* 2) Output the image tag below like this: | |
* <img src="<?php echo $img_src ?>" width="<?php echo $img_width ?>" height="<?php echo $img_height ?>" alt="" /> | |
*/ | |
/* End data preparation. */ | |
/* The HTML from here through "endforeach" is repeated for every item in the list... */ ?> | |
<div class="<?php echo $entryClasses?>"> | |
<?php if (is_object($thumbnail)): ?> | |
<div class="ccm-block-page-list-page-entry-thumbnail"> | |
<?php | |
$img = Core::make('html/image', array($thumbnail)); | |
$tag = $img->getTag(); | |
$tag->addClass('img-responsive'); | |
print $tag; | |
?> | |
</div> | |
<?php endif; ?> | |
<?php if ($includeEntryText): ?> | |
<div class="ccm-block-page-list-page-entry-text"> | |
<div><?php echo $event_date_time ?></div> | |
<?php if ($includeName): ?> | |
<div class="ccm-block-page-list-title"> | |
<?php if ($useButtonForLink) { ?> | |
<?php echo $title; ?> | |
<?php } else { ?> | |
<a href="<?php echo $url ?>" target="<?php echo $target ?>"><?php echo $title ?></a> | |
<?php } ?> | |
</div> | |
<?php endif; ?> | |
<?php if ($includeDate): ?> | |
<div class="ccm-block-page-list-date"><?php echo $date?></div> | |
<?php endif; ?> | |
<?php if ($includeDescription): ?> | |
<div class="ccm-block-page-list-description"> | |
<?php echo $description ?> | |
</div> | |
<?php endif; ?> | |
<?php if ($useButtonForLink): ?> | |
<div class="ccm-block-page-list-page-entry-read-more"> | |
<a href="<?php echo $url?>" class="<?php echo $buttonClasses?>"><?php echo $buttonLinkText?></a> | |
</div> | |
<?php endif; ?> | |
</div> | |
<?php endif; ?> | |
</div> | |
<?php endforeach; ?> | |
</div> | |
<?php if (count($pages) == 0): ?> | |
<div class="ccm-block-page-list-no-pages"><?php echo $noResultsMessage?></div> | |
<?php endif;?> | |
</div><!-- end .ccm-block-page-list --> | |
<?php if ($showPagination): ?> | |
<?php echo $pagination;?> | |
<?php endif; ?> | |
<?php } ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment