@@ -13,48 +13,48 @@ |
||
| 13 | 13 | */ |
| 14 | 14 | class MaintenanceProxyExtension extends Extension |
| 15 | 15 | { |
| 16 | - /** |
|
| 17 | - * Configures required environment settings for Composer's use, applies to |
|
| 18 | - * {@link \BringYourOwnIdeas\Maintenance\Util\ComposerLoader} and is applied before ComposerLoaderExtension in |
|
| 19 | - * bringyourownideas/silverstripe-composer-update-checker to ensure the proxy information is set before Composer |
|
| 20 | - * is created |
|
| 21 | - */ |
|
| 22 | - public function onAfterBuild() |
|
| 23 | - { |
|
| 24 | - // Provide access for Composer's StreamContextFactory, since it creates its own stream context |
|
| 25 | - if ($proxy = $this->getCwpProxy()) { |
|
| 26 | - $_SERVER['CGI_HTTP_PROXY'] = $proxy; |
|
| 27 | - } |
|
| 28 | - } |
|
| 16 | + /** |
|
| 17 | + * Configures required environment settings for Composer's use, applies to |
|
| 18 | + * {@link \BringYourOwnIdeas\Maintenance\Util\ComposerLoader} and is applied before ComposerLoaderExtension in |
|
| 19 | + * bringyourownideas/silverstripe-composer-update-checker to ensure the proxy information is set before Composer |
|
| 20 | + * is created |
|
| 21 | + */ |
|
| 22 | + public function onAfterBuild() |
|
| 23 | + { |
|
| 24 | + // Provide access for Composer's StreamContextFactory, since it creates its own stream context |
|
| 25 | + if ($proxy = $this->getCwpProxy()) { |
|
| 26 | + $_SERVER['CGI_HTTP_PROXY'] = $proxy; |
|
| 27 | + } |
|
| 28 | + } |
|
| 29 | 29 | |
| 30 | - /** |
|
| 31 | - * Provide proxy options for {@link \BringYourOwnIdeas\Maintenance\Util\ApiLoader} instances to use in |
|
| 32 | - * their Guzzle clients |
|
| 33 | - * |
|
| 34 | - * @param array $options |
|
| 35 | - */ |
|
| 36 | - public function updateClientOptions(&$options) |
|
| 37 | - { |
|
| 38 | - if ($proxy = $this->getCwpProxy()) { |
|
| 39 | - $options['proxy'] = $proxy; |
|
| 40 | - } |
|
| 41 | - } |
|
| 30 | + /** |
|
| 31 | + * Provide proxy options for {@link \BringYourOwnIdeas\Maintenance\Util\ApiLoader} instances to use in |
|
| 32 | + * their Guzzle clients |
|
| 33 | + * |
|
| 34 | + * @param array $options |
|
| 35 | + */ |
|
| 36 | + public function updateClientOptions(&$options) |
|
| 37 | + { |
|
| 38 | + if ($proxy = $this->getCwpProxy()) { |
|
| 39 | + $options['proxy'] = $proxy; |
|
| 40 | + } |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - /** |
|
| 44 | - * Returns a formatted CWP proxy string, e.g. `tcp://proxy.cwp.govt.nz:1234` |
|
| 45 | - * |
|
| 46 | - * @return string |
|
| 47 | - */ |
|
| 48 | - protected function getCwpProxy() |
|
| 49 | - { |
|
| 50 | - if (!Environment::getEnv('SS_OUTBOUND_PROXY') || !Environment::getEnv('SS_OUTBOUND_PROXY_PORT')) { |
|
| 51 | - return ''; |
|
| 52 | - } |
|
| 43 | + /** |
|
| 44 | + * Returns a formatted CWP proxy string, e.g. `tcp://proxy.cwp.govt.nz:1234` |
|
| 45 | + * |
|
| 46 | + * @return string |
|
| 47 | + */ |
|
| 48 | + protected function getCwpProxy() |
|
| 49 | + { |
|
| 50 | + if (!Environment::getEnv('SS_OUTBOUND_PROXY') || !Environment::getEnv('SS_OUTBOUND_PROXY_PORT')) { |
|
| 51 | + return ''; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - return sprintf( |
|
| 55 | - 'tcp://%s:%d', |
|
| 56 | - Environment::getEnv('SS_OUTBOUND_PROXY'), |
|
| 57 | - Environment::getEnv('SS_OUTBOUND_PROXY_PORT') |
|
| 58 | - ); |
|
| 59 | - } |
|
| 54 | + return sprintf( |
|
| 55 | + 'tcp://%s:%d', |
|
| 56 | + Environment::getEnv('SS_OUTBOUND_PROXY'), |
|
| 57 | + Environment::getEnv('SS_OUTBOUND_PROXY_PORT') |
|
| 58 | + ); |
|
| 59 | + } |
|
| 60 | 60 | } |
@@ -14,20 +14,20 @@ |
||
| 14 | 14 | */ |
| 15 | 15 | class CwpCommentingExtension extends Extension |
| 16 | 16 | { |
| 17 | - public function alterCommentForm(Form $form) |
|
| 18 | - { |
|
| 19 | - $fields = $form->Fields(); |
|
| 17 | + public function alterCommentForm(Form $form) |
|
| 18 | + { |
|
| 19 | + $fields = $form->Fields(); |
|
| 20 | 20 | |
| 21 | - if ($emailField = $fields->dataFieldByName('Email')) { |
|
| 22 | - $emailField |
|
| 23 | - ->setTitle(_t(__CLASS__ . '.EMAIL_TITLE', 'Email')) |
|
| 24 | - ->setDescription(_t(__CLASS__ . '.WILL_NOT_BE_PUBLISHED', 'Will not be published.')); |
|
| 25 | - } |
|
| 21 | + if ($emailField = $fields->dataFieldByName('Email')) { |
|
| 22 | + $emailField |
|
| 23 | + ->setTitle(_t(__CLASS__ . '.EMAIL_TITLE', 'Email')) |
|
| 24 | + ->setDescription(_t(__CLASS__ . '.WILL_NOT_BE_PUBLISHED', 'Will not be published.')); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - if ($urlField = $fields->dataFieldByName('URL')) { |
|
| 28 | - $urlField |
|
| 29 | - ->setTitle(_t(__CLASS__ . '.WEBSITE_TITLE', 'Your website (optional)')) |
|
| 30 | - ->setAttribute('placeholder', 'http://'); |
|
| 31 | - } |
|
| 32 | - } |
|
| 27 | + if ($urlField = $fields->dataFieldByName('URL')) { |
|
| 28 | + $urlField |
|
| 29 | + ->setTitle(_t(__CLASS__ . '.WEBSITE_TITLE', 'Your website (optional)')) |
|
| 30 | + ->setAttribute('placeholder', 'http://'); |
|
| 31 | + } |
|
| 32 | + } |
|
| 33 | 33 | } |
@@ -8,30 +8,30 @@ |
||
| 8 | 8 | |
| 9 | 9 | class RelatedPageLink extends DataObject |
| 10 | 10 | { |
| 11 | - private static $table_name = 'BasePage_RelatedPages'; |
|
| 11 | + private static $table_name = 'BasePage_RelatedPages'; |
|
| 12 | 12 | |
| 13 | - private static $extensions = [ |
|
| 14 | - Versioned::class, |
|
| 15 | - ]; |
|
| 13 | + private static $extensions = [ |
|
| 14 | + Versioned::class, |
|
| 15 | + ]; |
|
| 16 | 16 | |
| 17 | - private static $db = [ |
|
| 18 | - 'SortOrder' => 'Int', |
|
| 19 | - ]; |
|
| 17 | + private static $db = [ |
|
| 18 | + 'SortOrder' => 'Int', |
|
| 19 | + ]; |
|
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * For backwards compatibility these must match a traditional 'many_many' definition. |
|
| 23 | - * This was BasePage.RelatedPages => BasePage |
|
| 24 | - * ManyMany relations are normally joined by ${DefiningClass}ID && ${RelatedClass}ID |
|
| 25 | - * excepting in the case where ${DefiningClass} === ${RelatedClass} |
|
| 26 | - * Then the 'related class' column changes from ${RelatedClass}ID to "ChildID". |
|
| 27 | - * |
|
| 28 | - * {@see SilverStripe\ORM\DataObjectSchema->parseManyManyComponent()} |
|
| 29 | - * |
|
| 30 | - * @var array |
|
| 31 | - * @config |
|
| 32 | - */ |
|
| 33 | - private static $has_one = [ |
|
| 34 | - 'BasePage' => BasePage::class, |
|
| 35 | - 'Child' => BasePage::class, |
|
| 36 | - ]; |
|
| 21 | + /** |
|
| 22 | + * For backwards compatibility these must match a traditional 'many_many' definition. |
|
| 23 | + * This was BasePage.RelatedPages => BasePage |
|
| 24 | + * ManyMany relations are normally joined by ${DefiningClass}ID && ${RelatedClass}ID |
|
| 25 | + * excepting in the case where ${DefiningClass} === ${RelatedClass} |
|
| 26 | + * Then the 'related class' column changes from ${RelatedClass}ID to "ChildID". |
|
| 27 | + * |
|
| 28 | + * {@see SilverStripe\ORM\DataObjectSchema->parseManyManyComponent()} |
|
| 29 | + * |
|
| 30 | + * @var array |
|
| 31 | + * @config |
|
| 32 | + */ |
|
| 33 | + private static $has_one = [ |
|
| 34 | + 'BasePage' => BasePage::class, |
|
| 35 | + 'Child' => BasePage::class, |
|
| 36 | + ]; |
|
| 37 | 37 | } |
@@ -12,58 +12,58 @@ |
||
| 12 | 12 | */ |
| 13 | 13 | class CustomSiteConfig extends DataExtension |
| 14 | 14 | { |
| 15 | - private static $db = array( |
|
| 16 | - 'GACode' => 'Varchar(16)', |
|
| 17 | - 'FacebookURL' => 'Varchar(256)', // multitude of ways to link to Facebook accounts, best to leave it open. |
|
| 18 | - 'TwitterUsername' => 'Varchar(16)', // max length of Twitter username 15 |
|
| 19 | - ); |
|
| 15 | + private static $db = array( |
|
| 16 | + 'GACode' => 'Varchar(16)', |
|
| 17 | + 'FacebookURL' => 'Varchar(256)', // multitude of ways to link to Facebook accounts, best to leave it open. |
|
| 18 | + 'TwitterUsername' => 'Varchar(16)', // max length of Twitter username 15 |
|
| 19 | + ); |
|
| 20 | 20 | |
| 21 | - public function updateCMSFields(FieldList $fields) |
|
| 22 | - { |
|
| 23 | - $fields->addFieldToTab( |
|
| 24 | - 'Root.Main', |
|
| 25 | - $gaCode = TextField::create( |
|
| 26 | - 'GACode', |
|
| 27 | - _t(__CLASS__ . '.GaField', 'Google Analytics account') |
|
| 28 | - ) |
|
| 29 | - ); |
|
| 21 | + public function updateCMSFields(FieldList $fields) |
|
| 22 | + { |
|
| 23 | + $fields->addFieldToTab( |
|
| 24 | + 'Root.Main', |
|
| 25 | + $gaCode = TextField::create( |
|
| 26 | + 'GACode', |
|
| 27 | + _t(__CLASS__ . '.GaField', 'Google Analytics account') |
|
| 28 | + ) |
|
| 29 | + ); |
|
| 30 | 30 | |
| 31 | - $gaCode->setDescription( |
|
| 32 | - DBField::create_field('HTMLFragment', _t( |
|
| 33 | - __CLASS__ . '.GaFieldDesc', |
|
| 34 | - 'Account number to be used all across the site (in the format <strong>UA-XXXXX-X</strong>)' |
|
| 35 | - )) |
|
| 36 | - ); |
|
| 31 | + $gaCode->setDescription( |
|
| 32 | + DBField::create_field('HTMLFragment', _t( |
|
| 33 | + __CLASS__ . '.GaFieldDesc', |
|
| 34 | + 'Account number to be used all across the site (in the format <strong>UA-XXXXX-X</strong>)' |
|
| 35 | + )) |
|
| 36 | + ); |
|
| 37 | 37 | |
| 38 | - $fields->findOrMakeTab('Root.SocialMedia', _t(__CLASS__ . '.SocialMediaTab', 'Social Media')); |
|
| 38 | + $fields->findOrMakeTab('Root.SocialMedia', _t(__CLASS__ . '.SocialMediaTab', 'Social Media')); |
|
| 39 | 39 | |
| 40 | - $fields->addFieldToTab( |
|
| 41 | - 'Root.SocialMedia', |
|
| 42 | - $facebookURL = TextField::create( |
|
| 43 | - 'FacebookURL', |
|
| 44 | - _t(__CLASS__ . '.FbField', 'Facebook UID or username') |
|
| 45 | - ) |
|
| 46 | - ); |
|
| 47 | - $facebookURL->setDescription( |
|
| 48 | - DBField::create_field('HTMLFragment', _t( |
|
| 49 | - __CLASS__ . '.FbFieldDesc', |
|
| 50 | - 'Facebook link (everything after the "http://facebook.com/", eg http://facebook.com/' |
|
| 51 | - . '<strong>username</strong> or http://facebook.com/<strong>pages/108510539573</strong>)' |
|
| 52 | - )) |
|
| 53 | - ); |
|
| 40 | + $fields->addFieldToTab( |
|
| 41 | + 'Root.SocialMedia', |
|
| 42 | + $facebookURL = TextField::create( |
|
| 43 | + 'FacebookURL', |
|
| 44 | + _t(__CLASS__ . '.FbField', 'Facebook UID or username') |
|
| 45 | + ) |
|
| 46 | + ); |
|
| 47 | + $facebookURL->setDescription( |
|
| 48 | + DBField::create_field('HTMLFragment', _t( |
|
| 49 | + __CLASS__ . '.FbFieldDesc', |
|
| 50 | + 'Facebook link (everything after the "http://facebook.com/", eg http://facebook.com/' |
|
| 51 | + . '<strong>username</strong> or http://facebook.com/<strong>pages/108510539573</strong>)' |
|
| 52 | + )) |
|
| 53 | + ); |
|
| 54 | 54 | |
| 55 | - $fields->addFieldToTab( |
|
| 56 | - 'Root.SocialMedia', |
|
| 57 | - $twitterUsername = TextField::create( |
|
| 58 | - 'TwitterUsername', |
|
| 59 | - _t(__CLASS__ . '.TwitterField', 'Twitter username') |
|
| 60 | - ) |
|
| 61 | - ); |
|
| 62 | - $twitterUsername->setDescription( |
|
| 63 | - DBField::create_field('HTMLFragment', _t( |
|
| 64 | - __CLASS__ . '.TwitterFieldDesc', |
|
| 65 | - 'Twitter username (eg, http://twitter.com/<strong>username</strong>)' |
|
| 66 | - )) |
|
| 67 | - ); |
|
| 68 | - } |
|
| 55 | + $fields->addFieldToTab( |
|
| 56 | + 'Root.SocialMedia', |
|
| 57 | + $twitterUsername = TextField::create( |
|
| 58 | + 'TwitterUsername', |
|
| 59 | + _t(__CLASS__ . '.TwitterField', 'Twitter username') |
|
| 60 | + ) |
|
| 61 | + ); |
|
| 62 | + $twitterUsername->setDescription( |
|
| 63 | + DBField::create_field('HTMLFragment', _t( |
|
| 64 | + __CLASS__ . '.TwitterFieldDesc', |
|
| 65 | + 'Twitter username (eg, http://twitter.com/<strong>username</strong>)' |
|
| 66 | + )) |
|
| 67 | + ); |
|
| 68 | + } |
|
| 69 | 69 | } |
@@ -7,50 +7,50 @@ |
||
| 7 | 7 | |
| 8 | 8 | class NewsHolder extends DatedUpdateHolder |
| 9 | 9 | { |
| 10 | - private static $description = 'Container page for News Pages, provides news filtering and pagination'; |
|
| 11 | - |
|
| 12 | - private static $allowed_children = [ |
|
| 13 | - NewsPage::class, |
|
| 14 | - ]; |
|
| 15 | - |
|
| 16 | - private static $default_child = NewsPage::class; |
|
| 17 | - |
|
| 18 | - private static $update_name = 'News'; |
|
| 19 | - |
|
| 20 | - private static $update_class = NewsPage::class; |
|
| 21 | - |
|
| 22 | - private static $icon_class = 'font-icon-news'; |
|
| 23 | - |
|
| 24 | - private static $singular_name = 'News Holder'; |
|
| 25 | - |
|
| 26 | - private static $plural_name = 'News Holders'; |
|
| 27 | - |
|
| 28 | - private static $table_name = 'NewsHolder'; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Find all site's news items, based on some filters. |
|
| 32 | - * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
| 33 | - * |
|
| 34 | - * @param string $className The name of the class to fetch. |
|
| 35 | - * @param int $parentID The ID of the holder to extract the news items from. |
|
| 36 | - * @param int $tagID The ID of the tag to filter the news items by. |
|
| 37 | - * @param string $dateFrom The beginning of a date filter range. |
|
| 38 | - * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
| 39 | - * @param int $year Numeric value of the year to show. |
|
| 40 | - * @param int $monthNumber Numeric value of the month to show. |
|
| 41 | - * |
|
| 42 | - * @returns DataList|PaginatedList |
|
| 43 | - */ |
|
| 44 | - public static function AllUpdates( |
|
| 45 | - $className = NewsPage::class, |
|
| 46 | - $parentID = null, |
|
| 47 | - $tagID = null, |
|
| 48 | - $dateFrom = null, |
|
| 49 | - $dateTo = null, |
|
| 50 | - $year = null, |
|
| 51 | - $monthNumber = null |
|
| 52 | - ) { |
|
| 53 | - return parent::AllUpdates($className, $parentID, $tagID, $dateFrom, $dateTo, $year, $monthNumber) |
|
| 54 | - ->Sort('Date', 'DESC'); |
|
| 55 | - } |
|
| 10 | + private static $description = 'Container page for News Pages, provides news filtering and pagination'; |
|
| 11 | + |
|
| 12 | + private static $allowed_children = [ |
|
| 13 | + NewsPage::class, |
|
| 14 | + ]; |
|
| 15 | + |
|
| 16 | + private static $default_child = NewsPage::class; |
|
| 17 | + |
|
| 18 | + private static $update_name = 'News'; |
|
| 19 | + |
|
| 20 | + private static $update_class = NewsPage::class; |
|
| 21 | + |
|
| 22 | + private static $icon_class = 'font-icon-news'; |
|
| 23 | + |
|
| 24 | + private static $singular_name = 'News Holder'; |
|
| 25 | + |
|
| 26 | + private static $plural_name = 'News Holders'; |
|
| 27 | + |
|
| 28 | + private static $table_name = 'NewsHolder'; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Find all site's news items, based on some filters. |
|
| 32 | + * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
| 33 | + * |
|
| 34 | + * @param string $className The name of the class to fetch. |
|
| 35 | + * @param int $parentID The ID of the holder to extract the news items from. |
|
| 36 | + * @param int $tagID The ID of the tag to filter the news items by. |
|
| 37 | + * @param string $dateFrom The beginning of a date filter range. |
|
| 38 | + * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
| 39 | + * @param int $year Numeric value of the year to show. |
|
| 40 | + * @param int $monthNumber Numeric value of the month to show. |
|
| 41 | + * |
|
| 42 | + * @returns DataList|PaginatedList |
|
| 43 | + */ |
|
| 44 | + public static function AllUpdates( |
|
| 45 | + $className = NewsPage::class, |
|
| 46 | + $parentID = null, |
|
| 47 | + $tagID = null, |
|
| 48 | + $dateFrom = null, |
|
| 49 | + $dateTo = null, |
|
| 50 | + $year = null, |
|
| 51 | + $monthNumber = null |
|
| 52 | + ) { |
|
| 53 | + return parent::AllUpdates($className, $parentID, $tagID, $dateFrom, $dateTo, $year, $monthNumber) |
|
| 54 | + ->Sort('Date', 'DESC'); |
|
| 55 | + } |
|
| 56 | 56 | } |
@@ -6,13 +6,13 @@ |
||
| 6 | 6 | |
| 7 | 7 | class SitemapPage extends Page |
| 8 | 8 | { |
| 9 | - private static $description = 'Lists all pages on the site'; |
|
| 9 | + private static $description = 'Lists all pages on the site'; |
|
| 10 | 10 | |
| 11 | - private static $singular_name = 'Sitemap Page'; |
|
| 11 | + private static $singular_name = 'Sitemap Page'; |
|
| 12 | 12 | |
| 13 | - private static $plural_name = 'Sitemap Pages'; |
|
| 13 | + private static $plural_name = 'Sitemap Pages'; |
|
| 14 | 14 | |
| 15 | - private static $table_name = 'SitemapPage'; |
|
| 15 | + private static $table_name = 'SitemapPage'; |
|
| 16 | 16 | |
| 17 | - private static $icon_class = 'font-icon-sitemap'; |
|
| 17 | + private static $icon_class = 'font-icon-sitemap'; |
|
| 18 | 18 | } |
@@ -7,57 +7,57 @@ |
||
| 7 | 7 | |
| 8 | 8 | class EventHolder extends DatedUpdateHolder |
| 9 | 9 | { |
| 10 | - private static $description = 'Container page for Event Pages, provides event filtering and pagination'; |
|
| 11 | - |
|
| 12 | - private static $allowed_children = [ |
|
| 13 | - EventPage::class, |
|
| 14 | - ]; |
|
| 15 | - |
|
| 16 | - private static $default_child = EventPage::class; |
|
| 17 | - |
|
| 18 | - private static $update_name = 'Events'; |
|
| 19 | - |
|
| 20 | - private static $update_class = EventPage::class; |
|
| 21 | - |
|
| 22 | - private static $icon_class = 'font-icon-p-event-alt'; |
|
| 23 | - |
|
| 24 | - private static $singular_name = 'Event Holder'; |
|
| 25 | - |
|
| 26 | - private static $plural_name = 'Event Holders'; |
|
| 27 | - |
|
| 28 | - private static $table_name = 'EventHolder'; |
|
| 29 | - |
|
| 30 | - /** |
|
| 31 | - * Find all site's news items, based on some filters. |
|
| 32 | - * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
| 33 | - * |
|
| 34 | - * @param string $className The name of the class to fetch. |
|
| 35 | - * @param int $parentID The ID of the holder to extract the news items from. |
|
| 36 | - * @param int $tagID The ID of the tag to filter the news items by. |
|
| 37 | - * @param string $dateFrom The beginning of a date filter range. |
|
| 38 | - * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
| 39 | - * @param int $year Numeric value of the year to show. |
|
| 40 | - * @param int $monthNumber Numeric value of the month to show. |
|
| 41 | - * |
|
| 42 | - * @returns DataList|PaginatedList |
|
| 43 | - */ |
|
| 44 | - public static function AllUpdates( |
|
| 45 | - $className = 'Events', |
|
| 46 | - $parentID = null, |
|
| 47 | - $tagID = null, |
|
| 48 | - $dateFrom = null, |
|
| 49 | - $dateTo = null, |
|
| 50 | - $year = null, |
|
| 51 | - $monthNumber = null |
|
| 52 | - ) { |
|
| 53 | - return parent::AllUpdates( |
|
| 54 | - $className, |
|
| 55 | - $parentID, |
|
| 56 | - $tagID, |
|
| 57 | - $dateFrom, |
|
| 58 | - $dateTo, |
|
| 59 | - $year, |
|
| 60 | - $monthNumber |
|
| 61 | - )->Sort('Date', 'ASC'); |
|
| 62 | - } |
|
| 10 | + private static $description = 'Container page for Event Pages, provides event filtering and pagination'; |
|
| 11 | + |
|
| 12 | + private static $allowed_children = [ |
|
| 13 | + EventPage::class, |
|
| 14 | + ]; |
|
| 15 | + |
|
| 16 | + private static $default_child = EventPage::class; |
|
| 17 | + |
|
| 18 | + private static $update_name = 'Events'; |
|
| 19 | + |
|
| 20 | + private static $update_class = EventPage::class; |
|
| 21 | + |
|
| 22 | + private static $icon_class = 'font-icon-p-event-alt'; |
|
| 23 | + |
|
| 24 | + private static $singular_name = 'Event Holder'; |
|
| 25 | + |
|
| 26 | + private static $plural_name = 'Event Holders'; |
|
| 27 | + |
|
| 28 | + private static $table_name = 'EventHolder'; |
|
| 29 | + |
|
| 30 | + /** |
|
| 31 | + * Find all site's news items, based on some filters. |
|
| 32 | + * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
| 33 | + * |
|
| 34 | + * @param string $className The name of the class to fetch. |
|
| 35 | + * @param int $parentID The ID of the holder to extract the news items from. |
|
| 36 | + * @param int $tagID The ID of the tag to filter the news items by. |
|
| 37 | + * @param string $dateFrom The beginning of a date filter range. |
|
| 38 | + * @param string $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
| 39 | + * @param int $year Numeric value of the year to show. |
|
| 40 | + * @param int $monthNumber Numeric value of the month to show. |
|
| 41 | + * |
|
| 42 | + * @returns DataList|PaginatedList |
|
| 43 | + */ |
|
| 44 | + public static function AllUpdates( |
|
| 45 | + $className = 'Events', |
|
| 46 | + $parentID = null, |
|
| 47 | + $tagID = null, |
|
| 48 | + $dateFrom = null, |
|
| 49 | + $dateTo = null, |
|
| 50 | + $year = null, |
|
| 51 | + $monthNumber = null |
|
| 52 | + ) { |
|
| 53 | + return parent::AllUpdates( |
|
| 54 | + $className, |
|
| 55 | + $parentID, |
|
| 56 | + $tagID, |
|
| 57 | + $dateFrom, |
|
| 58 | + $dateTo, |
|
| 59 | + $year, |
|
| 60 | + $monthNumber |
|
| 61 | + )->Sort('Date', 'ASC'); |
|
| 62 | + } |
|
| 63 | 63 | } |
@@ -9,21 +9,21 @@ |
||
| 9 | 9 | |
| 10 | 10 | class NewsPageTest extends SapphireTest |
| 11 | 11 | { |
| 12 | - protected $usesDatabase = true; |
|
| 12 | + protected $usesDatabase = true; |
|
| 13 | 13 | |
| 14 | - public function testGetNewsPageAuthor() |
|
| 15 | - { |
|
| 16 | - $holder = new NewsHolder(); |
|
| 17 | - $holder->Title = 'Holder'; |
|
| 18 | - $holder->write(); |
|
| 14 | + public function testGetNewsPageAuthor() |
|
| 15 | + { |
|
| 16 | + $holder = new NewsHolder(); |
|
| 17 | + $holder->Title = 'Holder'; |
|
| 18 | + $holder->write(); |
|
| 19 | 19 | |
| 20 | - $page = new NewsPage(); |
|
| 21 | - $page->Author = 'Leslie Lawless'; |
|
| 22 | - $page->ParentID = $holder->ID; |
|
| 23 | - $page->write(); |
|
| 20 | + $page = new NewsPage(); |
|
| 21 | + $page->Author = 'Leslie Lawless'; |
|
| 22 | + $page->ParentID = $holder->ID; |
|
| 23 | + $page->write(); |
|
| 24 | 24 | |
| 25 | - $field = $page->getNewsPageAuthor(); |
|
| 26 | - $this->assertInstanceOf(DBField::class, $field); |
|
| 27 | - $this->assertSame('Leslie Lawless', $field->getValue()); |
|
| 28 | - } |
|
| 25 | + $field = $page->getNewsPageAuthor(); |
|
| 26 | + $this->assertInstanceOf(DBField::class, $field); |
|
| 27 | + $this->assertSame('Leslie Lawless', $field->getValue()); |
|
| 28 | + } |
|
| 29 | 29 | } |
@@ -160,7 +160,7 @@ discard block |
||
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | if (isset($tag)) { |
| 163 | - $tag = (int)$tag; |
|
| 163 | + $tag = (int) $tag; |
|
| 164 | 164 | } |
| 165 | 165 | try { |
| 166 | 166 | if (isset($from)) { |
@@ -184,10 +184,10 @@ discard block |
||
| 184 | 184 | } |
| 185 | 185 | } |
| 186 | 186 | if (isset($year)) { |
| 187 | - $year = (int)$year; |
|
| 187 | + $year = (int) $year; |
|
| 188 | 188 | } |
| 189 | 189 | if (isset($month)) { |
| 190 | - $month = (int)$month; |
|
| 190 | + $month = (int) $month; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | // If only "To" has been provided filter by single date. Normalise by swapping with "From". |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | $tagID = $this->request->getVar('tag'); |
| 271 | 271 | |
| 272 | 272 | if (isset($tagID)) { |
| 273 | - return TaxonomyTerm::get_by_id(TaxonomyTerm::class, (int)$tagID); |
|
| 273 | + return TaxonomyTerm::get_by_id(TaxonomyTerm::class, (int) $tagID); |
|
| 274 | 274 | } |
| 275 | 275 | } |
| 276 | 276 | |
@@ -35,370 +35,370 @@ |
||
| 35 | 35 | */ |
| 36 | 36 | class DatedUpdateHolderController extends PageController |
| 37 | 37 | { |
| 38 | - private static $allowed_actions = [ |
|
| 39 | - 'rss', |
|
| 40 | - 'atom', |
|
| 41 | - 'DateRangeForm', |
|
| 42 | - ]; |
|
| 43 | - |
|
| 44 | - private static $casting = [ |
|
| 45 | - 'MetaTitle' => 'Text', |
|
| 46 | - 'FilterDescription' => 'Text', |
|
| 47 | - ]; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * The session key for storing temporary form messages |
|
| 51 | - * |
|
| 52 | - * @var string |
|
| 53 | - */ |
|
| 54 | - const TEMP_FORM_MESSAGE = __CLASS__ . '.TempFormMessage'; |
|
| 55 | - |
|
| 56 | - /** |
|
| 57 | - * Get the meta title for the current action |
|
| 58 | - * |
|
| 59 | - * @return string |
|
| 60 | - */ |
|
| 61 | - public function getMetaTitle() |
|
| 62 | - { |
|
| 63 | - $title = $this->data()->getTitle(); |
|
| 64 | - $filter = $this->FilterDescription(); |
|
| 65 | - if ($filter) { |
|
| 66 | - $title = "{$title} - {$filter}"; |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - $this->extend('updateMetaTitle', $title); |
|
| 70 | - return $title; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - /** |
|
| 74 | - * Returns a description of the current filter |
|
| 75 | - * |
|
| 76 | - * @return string |
|
| 77 | - */ |
|
| 78 | - public function FilterDescription() |
|
| 79 | - { |
|
| 80 | - $params = $this->parseParams(); |
|
| 81 | - |
|
| 82 | - $filters = array(); |
|
| 83 | - if ($params['tag']) { |
|
| 84 | - $term = TaxonomyTerm::get_by_id(TaxonomyTerm::class, $params['tag']); |
|
| 85 | - if ($term) { |
|
| 86 | - $filters[] = _t( |
|
| 87 | - 'CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_WITHIN', |
|
| 88 | - 'within' |
|
| 89 | - ) . ' "' . $term->Name . '"'; |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - if ($params['from'] || $params['to']) { |
|
| 94 | - if ($params['from']) { |
|
| 95 | - $from = strtotime($params['from'] ?? ''); |
|
| 96 | - if ($params['to']) { |
|
| 97 | - $to = strtotime($params['to'] ?? ''); |
|
| 98 | - $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_BETWEEN', 'between') . ' ' |
|
| 99 | - . date('j/m/Y', $from) . ' and ' . date('j/m/Y', $to); |
|
| 100 | - } else { |
|
| 101 | - $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_ON', 'on') |
|
| 102 | - . ' ' . date('j/m/Y', $from); |
|
| 103 | - } |
|
| 104 | - } else { |
|
| 105 | - $to = strtotime($params['to'] ?? ''); |
|
| 106 | - $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_ON', 'on') |
|
| 107 | - . ' ' . date('j/m/Y', $to); |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - if ($params['year'] && $params['month']) { |
|
| 112 | - $timestamp = mktime(1, 1, 1, $params['month'], 1, $params['year']); |
|
| 113 | - $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_IN', 'in') |
|
| 114 | - . ' ' . date('F', $timestamp) . ' ' . $params['year']; |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - if ($filters) { |
|
| 118 | - return $this->getUpdateName() . ' ' . implode(' ', $filters); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - public function getUpdateName() |
|
| 123 | - { |
|
| 124 | - return Config::inst()->get($this->data()->ClassName, 'update_name'); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - protected function init() |
|
| 128 | - { |
|
| 129 | - parent::init(); |
|
| 130 | - RSSFeed::linkToFeed($this->Link() . 'rss', $this->getSubscriptionTitle()); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - /** |
|
| 134 | - * Parse URL parameters. |
|
| 135 | - * |
|
| 136 | - * @param bool $produceErrorMessages Set to false to omit session messages. |
|
| 137 | - */ |
|
| 138 | - public function parseParams($produceErrorMessages = true) |
|
| 139 | - { |
|
| 140 | - $tag = $this->request->getVar('tag'); |
|
| 141 | - $from = $this->request->getVar('from'); |
|
| 142 | - $to = $this->request->getVar('to'); |
|
| 143 | - $year = $this->request->getVar('year'); |
|
| 144 | - $month = $this->request->getVar('month'); |
|
| 145 | - |
|
| 146 | - if ($tag == '') { |
|
| 147 | - $tag = null; |
|
| 148 | - } |
|
| 149 | - if ($from == '') { |
|
| 150 | - $from = null; |
|
| 151 | - } |
|
| 152 | - if ($to == '') { |
|
| 153 | - $to = null; |
|
| 154 | - } |
|
| 155 | - if ($year == '') { |
|
| 156 | - $year = null; |
|
| 157 | - } |
|
| 158 | - if ($month == '') { |
|
| 159 | - $month = null; |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - if (isset($tag)) { |
|
| 163 | - $tag = (int)$tag; |
|
| 164 | - } |
|
| 165 | - try { |
|
| 166 | - if (isset($from)) { |
|
| 167 | - $from = urldecode($from ?? ''); |
|
| 168 | - $parser = DBDatetime::create(); |
|
| 169 | - $parser->setValue($from); |
|
| 170 | - $from = $parser->Format('y-MM-dd'); |
|
| 171 | - } |
|
| 172 | - if (isset($to)) { |
|
| 173 | - $to = urldecode($to ?? ''); |
|
| 174 | - $parser = DBDatetime::create(); |
|
| 175 | - $parser->setValue($to); |
|
| 176 | - $to = $parser->Format('y-MM-dd'); |
|
| 177 | - } |
|
| 178 | - } catch (InvalidArgumentException $e) { |
|
| 179 | - if ($produceErrorMessages) { |
|
| 180 | - $this->getRequest()->getSession()->set(self::TEMP_FORM_MESSAGE, _t( |
|
| 181 | - __CLASS__ . '.InvalidDateFormat', |
|
| 182 | - 'Dates must be in "y-MM-dd" format.' |
|
| 183 | - )); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - if (isset($year)) { |
|
| 187 | - $year = (int)$year; |
|
| 188 | - } |
|
| 189 | - if (isset($month)) { |
|
| 190 | - $month = (int)$month; |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - // If only "To" has been provided filter by single date. Normalise by swapping with "From". |
|
| 194 | - if (isset($to) && !isset($from)) { |
|
| 195 | - list($to, $from) = [$from, $to]; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - // Flip the dates if the order is wrong. |
|
| 199 | - if (isset($to) && isset($from) && strtotime($from ?? '') > strtotime($to ?? '')) { |
|
| 200 | - list($to, $from) = [$from, $to]; |
|
| 201 | - |
|
| 202 | - if ($produceErrorMessages) { |
|
| 203 | - $this->getRequest()->getSession()->set(self::TEMP_FORM_MESSAGE, _t( |
|
| 204 | - __CLASS__ . '.FilterAppliedMessage', |
|
| 205 | - 'Filter has been applied with the dates reversed.' |
|
| 206 | - )); |
|
| 207 | - } |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // Notify the user that filtering by single date is taking place. |
|
| 211 | - if (isset($from) && !isset($to)) { |
|
| 212 | - if ($produceErrorMessages) { |
|
| 213 | - $this->getRequest()->getSession()->set(self::TEMP_FORM_MESSAGE, _t( |
|
| 214 | - __CLASS__ . '.DateRangeFilterMessage', |
|
| 215 | - 'Filtered by a single date.' |
|
| 216 | - )); |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - return [ |
|
| 221 | - 'tag' => $tag, |
|
| 222 | - 'from' => $from, |
|
| 223 | - 'to' => $to, |
|
| 224 | - 'year' => $year, |
|
| 225 | - 'month' => $month, |
|
| 226 | - ]; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Build the link - keep the date range, reset the rest. |
|
| 231 | - */ |
|
| 232 | - public function AllTagsLink() |
|
| 233 | - { |
|
| 234 | - $link = HTTP::setGetVar('tag', null, null, '&'); |
|
| 235 | - $link = HTTP::setGetVar('month', null, $link, '&'); |
|
| 236 | - $link = HTTP::setGetVar('year', null, $link, '&'); |
|
| 237 | - $link = HTTP::setGetVar('start', null, $link, '&'); |
|
| 238 | - |
|
| 239 | - return $link; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * List tags and attach links. |
|
| 244 | - */ |
|
| 245 | - public function UpdateTagsWithLinks() |
|
| 246 | - { |
|
| 247 | - $tags = $this->UpdateTags(); |
|
| 248 | - |
|
| 249 | - $processed = ArrayList::create(); |
|
| 250 | - |
|
| 251 | - foreach ($tags as $tag) { |
|
| 252 | - // Build the link - keep the tag, and date range, but reset month, year and pagination. |
|
| 253 | - $link = HTTP::setGetVar('tag', $tag->ID, null, '&'); |
|
| 254 | - $link = HTTP::setGetVar('month', null, $link, '&'); |
|
| 255 | - $link = HTTP::setGetVar('year', null, $link, '&'); |
|
| 256 | - $link = HTTP::setGetVar('start', null, $link, '&'); |
|
| 257 | - |
|
| 258 | - $tag->Link = $link; |
|
| 259 | - $processed->push($tag); |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - return $processed; |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - /** |
|
| 266 | - * Get the TaxonomyTerm related to the current tag GET parameter. |
|
| 267 | - */ |
|
| 268 | - public function CurrentTag() |
|
| 269 | - { |
|
| 270 | - $tagID = $this->request->getVar('tag'); |
|
| 271 | - |
|
| 272 | - if (isset($tagID)) { |
|
| 273 | - return TaxonomyTerm::get_by_id(TaxonomyTerm::class, (int)$tagID); |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - /** |
|
| 278 | - * Extract the available months based on the current query. |
|
| 279 | - * Only tag is respected. Pagination and months are ignored. |
|
| 280 | - */ |
|
| 281 | - public function AvailableMonths() |
|
| 282 | - { |
|
| 283 | - $params = $this->parseParams(); |
|
| 284 | - |
|
| 285 | - return DatedUpdateHolder::ExtractMonths( |
|
| 286 | - $this->Updates($params['tag'], $params['from'], $params['to']), |
|
| 287 | - Director::makeRelative($_SERVER['REQUEST_URI']), |
|
| 288 | - $params['year'], |
|
| 289 | - $params['month'] |
|
| 290 | - ); |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - /** |
|
| 294 | - * Get the updates based on the current query. |
|
| 295 | - */ |
|
| 296 | - public function FilteredUpdates($pageSize = 20) |
|
| 297 | - { |
|
| 298 | - $params = $this->parseParams(); |
|
| 299 | - |
|
| 300 | - $items = $this->Updates( |
|
| 301 | - $params['tag'], |
|
| 302 | - $params['from'], |
|
| 303 | - $params['to'], |
|
| 304 | - $params['year'], |
|
| 305 | - $params['month'] |
|
| 306 | - ); |
|
| 307 | - |
|
| 308 | - // Apply pagination |
|
| 309 | - $list = PaginatedList::create($items, $this->getRequest()); |
|
| 310 | - $list->setPageLength($pageSize); |
|
| 311 | - return $list; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - /** |
|
| 315 | - * @return Form |
|
| 316 | - */ |
|
| 317 | - public function DateRangeForm() |
|
| 318 | - { |
|
| 319 | - $dateFromTitle = DBField::create_field('HTMLText', sprintf( |
|
| 320 | - '%s <span class="field-note">%s</span>', |
|
| 321 | - _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FROM_DATE', 'From date'), |
|
| 322 | - _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.DATE_EXAMPLE', '(example: 30/12/2017)') |
|
| 323 | - )); |
|
| 324 | - $dateToTitle = DBField::create_field('HTMLText', sprintf( |
|
| 325 | - '%s <span class="field-note">%s</span>', |
|
| 326 | - _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.TO_DATE', 'To date'), |
|
| 327 | - _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.DATE_EXAMPLE', '(example: 30/12/2017)') |
|
| 328 | - )); |
|
| 329 | - |
|
| 330 | - $fields = FieldList::create( |
|
| 331 | - DateField::create('from', $dateFromTitle), |
|
| 332 | - DateField::create('to', $dateToTitle), |
|
| 333 | - HiddenField::create('tag') |
|
| 334 | - ); |
|
| 335 | - |
|
| 336 | - $actions = FieldList::create( |
|
| 337 | - FormAction::create("doDateFilter") |
|
| 338 | - ->setTitle(_t(__CLASS__ . '.Filter', 'Filter')) |
|
| 339 | - ->addExtraClass('btn btn-primary primary'), |
|
| 340 | - FormAction::create("doDateReset") |
|
| 341 | - ->setTitle(_t(__CLASS__ . '.Clear', 'Clear')) |
|
| 342 | - ->addExtraClass('btn') |
|
| 343 | - ); |
|
| 344 | - |
|
| 345 | - $form = Form::create($this, 'DateRangeForm', $fields, $actions); |
|
| 346 | - $form->loadDataFrom($this->request->getVars()); |
|
| 347 | - $form->setFormMethod('get'); |
|
| 348 | - |
|
| 349 | - // Add any locally stored form messages before returning |
|
| 350 | - if ($formMessage = $this->getRequest()->getSession()->get(self::TEMP_FORM_MESSAGE)) { |
|
| 351 | - $form->setMessage($formMessage, ValidationResult::TYPE_WARNING); |
|
| 352 | - $this->getRequest()->getSession()->clear(self::TEMP_FORM_MESSAGE); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - return $form; |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - public function doDateFilter() |
|
| 359 | - { |
|
| 360 | - $params = $this->parseParams(); |
|
| 361 | - |
|
| 362 | - // Build the link - keep the tag, but reset month, year and pagination. |
|
| 363 | - $link = HTTP::setGetVar('from', $params['from'], $this->AbsoluteLink(), '&'); |
|
| 364 | - $link = HTTP::setGetVar('to', $params['to'], $link, '&'); |
|
| 365 | - if (isset($params['tag'])) { |
|
| 366 | - $link = HTTP::setGetVar('tag', $params['tag'], $link, '&'); |
|
| 367 | - } |
|
| 368 | - |
|
| 369 | - $this->redirect($link); |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - public function doDateReset() |
|
| 373 | - { |
|
| 374 | - $params = $this->parseParams(false); |
|
| 375 | - |
|
| 376 | - // Reset the link - only include the tag. |
|
| 377 | - $link = $this->AbsoluteLink(); |
|
| 378 | - if (isset($params['tag'])) { |
|
| 379 | - $link = HTTP::setGetVar('tag', $params['tag'], $link, '&'); |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - $this->redirect($link); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - public function rss() |
|
| 386 | - { |
|
| 387 | - $rss = RSSFeed::create( |
|
| 388 | - $this->Updates()->sort('Created DESC')->limit(20), |
|
| 389 | - $this->Link('rss'), |
|
| 390 | - $this->getSubscriptionTitle() |
|
| 391 | - ); |
|
| 392 | - return $rss->outputToBrowser(); |
|
| 393 | - } |
|
| 394 | - |
|
| 395 | - public function atom() |
|
| 396 | - { |
|
| 397 | - $atom = CwpAtomFeed::create( |
|
| 398 | - $this->Updates()->sort('Created DESC')->limit(20), |
|
| 399 | - $this->Link('atom'), |
|
| 400 | - $this->getSubscriptionTitle() |
|
| 401 | - ); |
|
| 402 | - return $atom->outputToBrowser(); |
|
| 403 | - } |
|
| 38 | + private static $allowed_actions = [ |
|
| 39 | + 'rss', |
|
| 40 | + 'atom', |
|
| 41 | + 'DateRangeForm', |
|
| 42 | + ]; |
|
| 43 | + |
|
| 44 | + private static $casting = [ |
|
| 45 | + 'MetaTitle' => 'Text', |
|
| 46 | + 'FilterDescription' => 'Text', |
|
| 47 | + ]; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * The session key for storing temporary form messages |
|
| 51 | + * |
|
| 52 | + * @var string |
|
| 53 | + */ |
|
| 54 | + const TEMP_FORM_MESSAGE = __CLASS__ . '.TempFormMessage'; |
|
| 55 | + |
|
| 56 | + /** |
|
| 57 | + * Get the meta title for the current action |
|
| 58 | + * |
|
| 59 | + * @return string |
|
| 60 | + */ |
|
| 61 | + public function getMetaTitle() |
|
| 62 | + { |
|
| 63 | + $title = $this->data()->getTitle(); |
|
| 64 | + $filter = $this->FilterDescription(); |
|
| 65 | + if ($filter) { |
|
| 66 | + $title = "{$title} - {$filter}"; |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + $this->extend('updateMetaTitle', $title); |
|
| 70 | + return $title; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + /** |
|
| 74 | + * Returns a description of the current filter |
|
| 75 | + * |
|
| 76 | + * @return string |
|
| 77 | + */ |
|
| 78 | + public function FilterDescription() |
|
| 79 | + { |
|
| 80 | + $params = $this->parseParams(); |
|
| 81 | + |
|
| 82 | + $filters = array(); |
|
| 83 | + if ($params['tag']) { |
|
| 84 | + $term = TaxonomyTerm::get_by_id(TaxonomyTerm::class, $params['tag']); |
|
| 85 | + if ($term) { |
|
| 86 | + $filters[] = _t( |
|
| 87 | + 'CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_WITHIN', |
|
| 88 | + 'within' |
|
| 89 | + ) . ' "' . $term->Name . '"'; |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + if ($params['from'] || $params['to']) { |
|
| 94 | + if ($params['from']) { |
|
| 95 | + $from = strtotime($params['from'] ?? ''); |
|
| 96 | + if ($params['to']) { |
|
| 97 | + $to = strtotime($params['to'] ?? ''); |
|
| 98 | + $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_BETWEEN', 'between') . ' ' |
|
| 99 | + . date('j/m/Y', $from) . ' and ' . date('j/m/Y', $to); |
|
| 100 | + } else { |
|
| 101 | + $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_ON', 'on') |
|
| 102 | + . ' ' . date('j/m/Y', $from); |
|
| 103 | + } |
|
| 104 | + } else { |
|
| 105 | + $to = strtotime($params['to'] ?? ''); |
|
| 106 | + $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_ON', 'on') |
|
| 107 | + . ' ' . date('j/m/Y', $to); |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + if ($params['year'] && $params['month']) { |
|
| 112 | + $timestamp = mktime(1, 1, 1, $params['month'], 1, $params['year']); |
|
| 113 | + $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_IN', 'in') |
|
| 114 | + . ' ' . date('F', $timestamp) . ' ' . $params['year']; |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + if ($filters) { |
|
| 118 | + return $this->getUpdateName() . ' ' . implode(' ', $filters); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + public function getUpdateName() |
|
| 123 | + { |
|
| 124 | + return Config::inst()->get($this->data()->ClassName, 'update_name'); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + protected function init() |
|
| 128 | + { |
|
| 129 | + parent::init(); |
|
| 130 | + RSSFeed::linkToFeed($this->Link() . 'rss', $this->getSubscriptionTitle()); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + /** |
|
| 134 | + * Parse URL parameters. |
|
| 135 | + * |
|
| 136 | + * @param bool $produceErrorMessages Set to false to omit session messages. |
|
| 137 | + */ |
|
| 138 | + public function parseParams($produceErrorMessages = true) |
|
| 139 | + { |
|
| 140 | + $tag = $this->request->getVar('tag'); |
|
| 141 | + $from = $this->request->getVar('from'); |
|
| 142 | + $to = $this->request->getVar('to'); |
|
| 143 | + $year = $this->request->getVar('year'); |
|
| 144 | + $month = $this->request->getVar('month'); |
|
| 145 | + |
|
| 146 | + if ($tag == '') { |
|
| 147 | + $tag = null; |
|
| 148 | + } |
|
| 149 | + if ($from == '') { |
|
| 150 | + $from = null; |
|
| 151 | + } |
|
| 152 | + if ($to == '') { |
|
| 153 | + $to = null; |
|
| 154 | + } |
|
| 155 | + if ($year == '') { |
|
| 156 | + $year = null; |
|
| 157 | + } |
|
| 158 | + if ($month == '') { |
|
| 159 | + $month = null; |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + if (isset($tag)) { |
|
| 163 | + $tag = (int)$tag; |
|
| 164 | + } |
|
| 165 | + try { |
|
| 166 | + if (isset($from)) { |
|
| 167 | + $from = urldecode($from ?? ''); |
|
| 168 | + $parser = DBDatetime::create(); |
|
| 169 | + $parser->setValue($from); |
|
| 170 | + $from = $parser->Format('y-MM-dd'); |
|
| 171 | + } |
|
| 172 | + if (isset($to)) { |
|
| 173 | + $to = urldecode($to ?? ''); |
|
| 174 | + $parser = DBDatetime::create(); |
|
| 175 | + $parser->setValue($to); |
|
| 176 | + $to = $parser->Format('y-MM-dd'); |
|
| 177 | + } |
|
| 178 | + } catch (InvalidArgumentException $e) { |
|
| 179 | + if ($produceErrorMessages) { |
|
| 180 | + $this->getRequest()->getSession()->set(self::TEMP_FORM_MESSAGE, _t( |
|
| 181 | + __CLASS__ . '.InvalidDateFormat', |
|
| 182 | + 'Dates must be in "y-MM-dd" format.' |
|
| 183 | + )); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + if (isset($year)) { |
|
| 187 | + $year = (int)$year; |
|
| 188 | + } |
|
| 189 | + if (isset($month)) { |
|
| 190 | + $month = (int)$month; |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + // If only "To" has been provided filter by single date. Normalise by swapping with "From". |
|
| 194 | + if (isset($to) && !isset($from)) { |
|
| 195 | + list($to, $from) = [$from, $to]; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + // Flip the dates if the order is wrong. |
|
| 199 | + if (isset($to) && isset($from) && strtotime($from ?? '') > strtotime($to ?? '')) { |
|
| 200 | + list($to, $from) = [$from, $to]; |
|
| 201 | + |
|
| 202 | + if ($produceErrorMessages) { |
|
| 203 | + $this->getRequest()->getSession()->set(self::TEMP_FORM_MESSAGE, _t( |
|
| 204 | + __CLASS__ . '.FilterAppliedMessage', |
|
| 205 | + 'Filter has been applied with the dates reversed.' |
|
| 206 | + )); |
|
| 207 | + } |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // Notify the user that filtering by single date is taking place. |
|
| 211 | + if (isset($from) && !isset($to)) { |
|
| 212 | + if ($produceErrorMessages) { |
|
| 213 | + $this->getRequest()->getSession()->set(self::TEMP_FORM_MESSAGE, _t( |
|
| 214 | + __CLASS__ . '.DateRangeFilterMessage', |
|
| 215 | + 'Filtered by a single date.' |
|
| 216 | + )); |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + return [ |
|
| 221 | + 'tag' => $tag, |
|
| 222 | + 'from' => $from, |
|
| 223 | + 'to' => $to, |
|
| 224 | + 'year' => $year, |
|
| 225 | + 'month' => $month, |
|
| 226 | + ]; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Build the link - keep the date range, reset the rest. |
|
| 231 | + */ |
|
| 232 | + public function AllTagsLink() |
|
| 233 | + { |
|
| 234 | + $link = HTTP::setGetVar('tag', null, null, '&'); |
|
| 235 | + $link = HTTP::setGetVar('month', null, $link, '&'); |
|
| 236 | + $link = HTTP::setGetVar('year', null, $link, '&'); |
|
| 237 | + $link = HTTP::setGetVar('start', null, $link, '&'); |
|
| 238 | + |
|
| 239 | + return $link; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * List tags and attach links. |
|
| 244 | + */ |
|
| 245 | + public function UpdateTagsWithLinks() |
|
| 246 | + { |
|
| 247 | + $tags = $this->UpdateTags(); |
|
| 248 | + |
|
| 249 | + $processed = ArrayList::create(); |
|
| 250 | + |
|
| 251 | + foreach ($tags as $tag) { |
|
| 252 | + // Build the link - keep the tag, and date range, but reset month, year and pagination. |
|
| 253 | + $link = HTTP::setGetVar('tag', $tag->ID, null, '&'); |
|
| 254 | + $link = HTTP::setGetVar('month', null, $link, '&'); |
|
| 255 | + $link = HTTP::setGetVar('year', null, $link, '&'); |
|
| 256 | + $link = HTTP::setGetVar('start', null, $link, '&'); |
|
| 257 | + |
|
| 258 | + $tag->Link = $link; |
|
| 259 | + $processed->push($tag); |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + return $processed; |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + /** |
|
| 266 | + * Get the TaxonomyTerm related to the current tag GET parameter. |
|
| 267 | + */ |
|
| 268 | + public function CurrentTag() |
|
| 269 | + { |
|
| 270 | + $tagID = $this->request->getVar('tag'); |
|
| 271 | + |
|
| 272 | + if (isset($tagID)) { |
|
| 273 | + return TaxonomyTerm::get_by_id(TaxonomyTerm::class, (int)$tagID); |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + /** |
|
| 278 | + * Extract the available months based on the current query. |
|
| 279 | + * Only tag is respected. Pagination and months are ignored. |
|
| 280 | + */ |
|
| 281 | + public function AvailableMonths() |
|
| 282 | + { |
|
| 283 | + $params = $this->parseParams(); |
|
| 284 | + |
|
| 285 | + return DatedUpdateHolder::ExtractMonths( |
|
| 286 | + $this->Updates($params['tag'], $params['from'], $params['to']), |
|
| 287 | + Director::makeRelative($_SERVER['REQUEST_URI']), |
|
| 288 | + $params['year'], |
|
| 289 | + $params['month'] |
|
| 290 | + ); |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + /** |
|
| 294 | + * Get the updates based on the current query. |
|
| 295 | + */ |
|
| 296 | + public function FilteredUpdates($pageSize = 20) |
|
| 297 | + { |
|
| 298 | + $params = $this->parseParams(); |
|
| 299 | + |
|
| 300 | + $items = $this->Updates( |
|
| 301 | + $params['tag'], |
|
| 302 | + $params['from'], |
|
| 303 | + $params['to'], |
|
| 304 | + $params['year'], |
|
| 305 | + $params['month'] |
|
| 306 | + ); |
|
| 307 | + |
|
| 308 | + // Apply pagination |
|
| 309 | + $list = PaginatedList::create($items, $this->getRequest()); |
|
| 310 | + $list->setPageLength($pageSize); |
|
| 311 | + return $list; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + /** |
|
| 315 | + * @return Form |
|
| 316 | + */ |
|
| 317 | + public function DateRangeForm() |
|
| 318 | + { |
|
| 319 | + $dateFromTitle = DBField::create_field('HTMLText', sprintf( |
|
| 320 | + '%s <span class="field-note">%s</span>', |
|
| 321 | + _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FROM_DATE', 'From date'), |
|
| 322 | + _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.DATE_EXAMPLE', '(example: 30/12/2017)') |
|
| 323 | + )); |
|
| 324 | + $dateToTitle = DBField::create_field('HTMLText', sprintf( |
|
| 325 | + '%s <span class="field-note">%s</span>', |
|
| 326 | + _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.TO_DATE', 'To date'), |
|
| 327 | + _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.DATE_EXAMPLE', '(example: 30/12/2017)') |
|
| 328 | + )); |
|
| 329 | + |
|
| 330 | + $fields = FieldList::create( |
|
| 331 | + DateField::create('from', $dateFromTitle), |
|
| 332 | + DateField::create('to', $dateToTitle), |
|
| 333 | + HiddenField::create('tag') |
|
| 334 | + ); |
|
| 335 | + |
|
| 336 | + $actions = FieldList::create( |
|
| 337 | + FormAction::create("doDateFilter") |
|
| 338 | + ->setTitle(_t(__CLASS__ . '.Filter', 'Filter')) |
|
| 339 | + ->addExtraClass('btn btn-primary primary'), |
|
| 340 | + FormAction::create("doDateReset") |
|
| 341 | + ->setTitle(_t(__CLASS__ . '.Clear', 'Clear')) |
|
| 342 | + ->addExtraClass('btn') |
|
| 343 | + ); |
|
| 344 | + |
|
| 345 | + $form = Form::create($this, 'DateRangeForm', $fields, $actions); |
|
| 346 | + $form->loadDataFrom($this->request->getVars()); |
|
| 347 | + $form->setFormMethod('get'); |
|
| 348 | + |
|
| 349 | + // Add any locally stored form messages before returning |
|
| 350 | + if ($formMessage = $this->getRequest()->getSession()->get(self::TEMP_FORM_MESSAGE)) { |
|
| 351 | + $form->setMessage($formMessage, ValidationResult::TYPE_WARNING); |
|
| 352 | + $this->getRequest()->getSession()->clear(self::TEMP_FORM_MESSAGE); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + return $form; |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + public function doDateFilter() |
|
| 359 | + { |
|
| 360 | + $params = $this->parseParams(); |
|
| 361 | + |
|
| 362 | + // Build the link - keep the tag, but reset month, year and pagination. |
|
| 363 | + $link = HTTP::setGetVar('from', $params['from'], $this->AbsoluteLink(), '&'); |
|
| 364 | + $link = HTTP::setGetVar('to', $params['to'], $link, '&'); |
|
| 365 | + if (isset($params['tag'])) { |
|
| 366 | + $link = HTTP::setGetVar('tag', $params['tag'], $link, '&'); |
|
| 367 | + } |
|
| 368 | + |
|
| 369 | + $this->redirect($link); |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + public function doDateReset() |
|
| 373 | + { |
|
| 374 | + $params = $this->parseParams(false); |
|
| 375 | + |
|
| 376 | + // Reset the link - only include the tag. |
|
| 377 | + $link = $this->AbsoluteLink(); |
|
| 378 | + if (isset($params['tag'])) { |
|
| 379 | + $link = HTTP::setGetVar('tag', $params['tag'], $link, '&'); |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + $this->redirect($link); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + public function rss() |
|
| 386 | + { |
|
| 387 | + $rss = RSSFeed::create( |
|
| 388 | + $this->Updates()->sort('Created DESC')->limit(20), |
|
| 389 | + $this->Link('rss'), |
|
| 390 | + $this->getSubscriptionTitle() |
|
| 391 | + ); |
|
| 392 | + return $rss->outputToBrowser(); |
|
| 393 | + } |
|
| 394 | + |
|
| 395 | + public function atom() |
|
| 396 | + { |
|
| 397 | + $atom = CwpAtomFeed::create( |
|
| 398 | + $this->Updates()->sort('Created DESC')->limit(20), |
|
| 399 | + $this->Link('atom'), |
|
| 400 | + $this->getSubscriptionTitle() |
|
| 401 | + ); |
|
| 402 | + return $atom->outputToBrowser(); |
|
| 403 | + } |
|
| 404 | 404 | } |