@@ -10,46 +10,46 @@ |
||
| 10 | 10 | |
| 11 | 11 | class PopulateThemeSampleDataTaskTest extends SapphireTest |
| 12 | 12 | { |
| 13 | - protected $usesDatabase = true; |
|
| 14 | - |
|
| 15 | - /** |
|
| 16 | - * Ensure that the "contact" user form is only created once |
|
| 17 | - */ |
|
| 18 | - public function testOnlyCreateContactFormOnce() |
|
| 19 | - { |
|
| 20 | - $createdMessage = 'Created "contact" UserDefinedForm'; |
|
| 21 | - |
|
| 22 | - $task = new PopulateThemeSampleDataTask; |
|
| 23 | - |
|
| 24 | - // Run the task |
|
| 25 | - $this->assertContains($createdMessage, $this->bufferedTask($task)); |
|
| 26 | - |
|
| 27 | - // Run a second time |
|
| 28 | - $this->assertNotContains($createdMessage, $this->bufferedTask($task)); |
|
| 29 | - |
|
| 30 | - // Change the page name |
|
| 31 | - $form = UserDefinedForm::get()->filter('URLSegment', 'contact')->first(); |
|
| 32 | - $form->URLSegment = 'testing'; |
|
| 33 | - $form->write(); |
|
| 34 | - |
|
| 35 | - // Ensure the old version is still detected in draft, so not recreated |
|
| 36 | - $this->assertNotContains($createdMessage, $this->bufferedTask($task)); |
|
| 37 | - |
|
| 38 | - // Delete the page, then ensure it's recreated again (DataObject::delete will remove staged versions) |
|
| 39 | - $form->delete(); |
|
| 40 | - $this->assertContains($createdMessage, $this->bufferedTask($task)); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Run a BuildTask while buffering its output, and return the result |
|
| 45 | - * |
|
| 46 | - * @param BuildTask $task |
|
| 47 | - * @return string |
|
| 48 | - */ |
|
| 49 | - protected function bufferedTask(BuildTask $task) |
|
| 50 | - { |
|
| 51 | - ob_start(); |
|
| 52 | - $task->run(new HTTPRequest('GET', '/')); |
|
| 53 | - return ob_get_clean(); |
|
| 54 | - } |
|
| 13 | + protected $usesDatabase = true; |
|
| 14 | + |
|
| 15 | + /** |
|
| 16 | + * Ensure that the "contact" user form is only created once |
|
| 17 | + */ |
|
| 18 | + public function testOnlyCreateContactFormOnce() |
|
| 19 | + { |
|
| 20 | + $createdMessage = 'Created "contact" UserDefinedForm'; |
|
| 21 | + |
|
| 22 | + $task = new PopulateThemeSampleDataTask; |
|
| 23 | + |
|
| 24 | + // Run the task |
|
| 25 | + $this->assertContains($createdMessage, $this->bufferedTask($task)); |
|
| 26 | + |
|
| 27 | + // Run a second time |
|
| 28 | + $this->assertNotContains($createdMessage, $this->bufferedTask($task)); |
|
| 29 | + |
|
| 30 | + // Change the page name |
|
| 31 | + $form = UserDefinedForm::get()->filter('URLSegment', 'contact')->first(); |
|
| 32 | + $form->URLSegment = 'testing'; |
|
| 33 | + $form->write(); |
|
| 34 | + |
|
| 35 | + // Ensure the old version is still detected in draft, so not recreated |
|
| 36 | + $this->assertNotContains($createdMessage, $this->bufferedTask($task)); |
|
| 37 | + |
|
| 38 | + // Delete the page, then ensure it's recreated again (DataObject::delete will remove staged versions) |
|
| 39 | + $form->delete(); |
|
| 40 | + $this->assertContains($createdMessage, $this->bufferedTask($task)); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Run a BuildTask while buffering its output, and return the result |
|
| 45 | + * |
|
| 46 | + * @param BuildTask $task |
|
| 47 | + * @return string |
|
| 48 | + */ |
|
| 49 | + protected function bufferedTask(BuildTask $task) |
|
| 50 | + { |
|
| 51 | + ob_start(); |
|
| 52 | + $task->run(new HTTPRequest('GET', '/')); |
|
| 53 | + return ob_get_clean(); |
|
| 54 | + } |
|
| 55 | 55 | } |
@@ -14,54 +14,54 @@ |
||
| 14 | 14 | class FooterHolder extends RedirectorPage |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - private static $description = 'Holder page that displays all child pages as links in the footer'; |
|
| 17 | + private static $description = 'Holder page that displays all child pages as links in the footer'; |
|
| 18 | 18 | |
| 19 | - private static $singular_name = 'Footer Holder'; |
|
| 19 | + private static $singular_name = 'Footer Holder'; |
|
| 20 | 20 | |
| 21 | - private static $plural_name = 'Footer Holders'; |
|
| 21 | + private static $plural_name = 'Footer Holders'; |
|
| 22 | 22 | |
| 23 | - private static $defaults = [ |
|
| 24 | - 'ShowInMenus' => 0, |
|
| 25 | - 'ShowInSearch' => 0, |
|
| 26 | - ]; |
|
| 23 | + private static $defaults = [ |
|
| 24 | + 'ShowInMenus' => 0, |
|
| 25 | + 'ShowInSearch' => 0, |
|
| 26 | + ]; |
|
| 27 | 27 | |
| 28 | - private static $table_name = 'FooterHolder'; |
|
| 28 | + private static $table_name = 'FooterHolder'; |
|
| 29 | 29 | |
| 30 | - public function getCMSFields() |
|
| 31 | - { |
|
| 32 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 33 | - $fields->removeByName('RedirectorDescHeader'); |
|
| 34 | - $fields->removeByName('RedirectionType'); |
|
| 35 | - $fields->removeByName('LinkToID'); |
|
| 36 | - $fields->removeByName('ExternalURL'); |
|
| 37 | - }); |
|
| 38 | - return parent::getCMSFields(); |
|
| 39 | - } |
|
| 30 | + public function getCMSFields() |
|
| 31 | + { |
|
| 32 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 33 | + $fields->removeByName('RedirectorDescHeader'); |
|
| 34 | + $fields->removeByName('RedirectionType'); |
|
| 35 | + $fields->removeByName('LinkToID'); |
|
| 36 | + $fields->removeByName('ExternalURL'); |
|
| 37 | + }); |
|
| 38 | + return parent::getCMSFields(); |
|
| 39 | + } |
|
| 40 | 40 | |
| 41 | - /** |
|
| 42 | - * Return the link to the first child page. |
|
| 43 | - */ |
|
| 44 | - public function redirectionLink() |
|
| 45 | - { |
|
| 46 | - $childPage = $this->Children()->first(); |
|
| 41 | + /** |
|
| 42 | + * Return the link to the first child page. |
|
| 43 | + */ |
|
| 44 | + public function redirectionLink() |
|
| 45 | + { |
|
| 46 | + $childPage = $this->Children()->first(); |
|
| 47 | 47 | |
| 48 | - if ($childPage) { |
|
| 49 | - // If we're linking to another redirectorpage then just return the URLSegment, to prevent a cycle of |
|
| 50 | - // redirector pages from causing an infinite loop. Instead, they will cause a 30x redirection loop in |
|
| 51 | - // the browser, but this can be handled sufficiently gracefully by the browser. |
|
| 52 | - if ($childPage instanceof RedirectorPage) { |
|
| 53 | - return $childPage->regularLink(); |
|
| 54 | - } |
|
| 55 | - // For all other pages, just return the link of the page. |
|
| 56 | - return $childPage->Link(); |
|
| 57 | - } |
|
| 58 | - } |
|
| 48 | + if ($childPage) { |
|
| 49 | + // If we're linking to another redirectorpage then just return the URLSegment, to prevent a cycle of |
|
| 50 | + // redirector pages from causing an infinite loop. Instead, they will cause a 30x redirection loop in |
|
| 51 | + // the browser, but this can be handled sufficiently gracefully by the browser. |
|
| 52 | + if ($childPage instanceof RedirectorPage) { |
|
| 53 | + return $childPage->regularLink(); |
|
| 54 | + } |
|
| 55 | + // For all other pages, just return the link of the page. |
|
| 56 | + return $childPage->Link(); |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | 59 | |
| 60 | - public function syncLinkTracking() |
|
| 61 | - { |
|
| 62 | - // If we don't have anything to link to, then we have a broken link. |
|
| 63 | - if (!$this->Children()) { |
|
| 64 | - $this->HasBrokenLink = true; |
|
| 65 | - } |
|
| 66 | - } |
|
| 60 | + public function syncLinkTracking() |
|
| 61 | + { |
|
| 62 | + // If we don't have anything to link to, then we have a broken link. |
|
| 63 | + if (!$this->Children()) { |
|
| 64 | + $this->HasBrokenLink = true; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | } |
@@ -29,7 +29,7 @@ |
||
| 29 | 29 | |
| 30 | 30 | public function getCMSFields() |
| 31 | 31 | { |
| 32 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 32 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
| 33 | 33 | $fields->removeByName('RedirectorDescHeader'); |
| 34 | 34 | $fields->removeByName('RedirectionType'); |
| 35 | 35 | $fields->removeByName('LinkToID'); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | if (isset($tag)) { |
| 147 | - $tag = (int)$tag; |
|
| 147 | + $tag = (int) $tag; |
|
| 148 | 148 | } |
| 149 | 149 | if (isset($from)) { |
| 150 | 150 | $from = urldecode($from); |
@@ -159,10 +159,10 @@ discard block |
||
| 159 | 159 | $to = $parser->Format('y-MM-dd'); |
| 160 | 160 | } |
| 161 | 161 | if (isset($year)) { |
| 162 | - $year = (int)$year; |
|
| 162 | + $year = (int) $year; |
|
| 163 | 163 | } |
| 164 | 164 | if (isset($month)) { |
| 165 | - $month = (int)$month; |
|
| 165 | + $month = (int) $month; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | // If only "To" has been provided filter by single date. Normalise by swapping with "From". |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // Flip the dates if the order is wrong. |
| 174 | - if (isset($to) && isset($from) && strtotime($from)>strtotime($to)) { |
|
| 174 | + if (isset($to) && isset($from) && strtotime($from) > strtotime($to)) { |
|
| 175 | 175 | list($to, $from) = array($from, $to); |
| 176 | 176 | |
| 177 | 177 | if ($produceErrorMessages) { |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | $tagID = $this->request->getVar('tag'); |
| 250 | 250 | |
| 251 | 251 | if (isset($tagID)) { |
| 252 | - return TaxonomyTerm::get_by_id(TaxonomyTerm::class, (int)$tagID); |
|
| 252 | + return TaxonomyTerm::get_by_id(TaxonomyTerm::class, (int) $tagID); |
|
| 253 | 253 | } |
| 254 | 254 | } |
| 255 | 255 | |
@@ -33,357 +33,357 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | class DatedUpdateHolderController extends PageController |
| 35 | 35 | { |
| 36 | - private static $allowed_actions = [ |
|
| 37 | - 'rss', |
|
| 38 | - 'atom', |
|
| 39 | - 'DateRangeForm', |
|
| 40 | - ]; |
|
| 41 | - |
|
| 42 | - private static $casting = [ |
|
| 43 | - 'MetaTitle' => 'Text', |
|
| 44 | - 'FilterDescription' => 'Text', |
|
| 45 | - ]; |
|
| 46 | - |
|
| 47 | - /** |
|
| 48 | - * Get the meta title for the current action |
|
| 49 | - * |
|
| 50 | - * @return string |
|
| 51 | - */ |
|
| 52 | - public function getMetaTitle() |
|
| 53 | - { |
|
| 54 | - $title = $this->data()->getTitle(); |
|
| 55 | - $filter = $this->FilterDescription(); |
|
| 56 | - if ($filter) { |
|
| 57 | - $title = "{$title} - {$filter}"; |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - $this->extend('updateMetaTitle', $title); |
|
| 61 | - return $title; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - /** |
|
| 65 | - * Returns a description of the current filter |
|
| 66 | - * |
|
| 67 | - * @return string |
|
| 68 | - */ |
|
| 69 | - public function FilterDescription() |
|
| 70 | - { |
|
| 71 | - $params = $this->parseParams(); |
|
| 72 | - |
|
| 73 | - $filters = array(); |
|
| 74 | - if ($params['tag']) { |
|
| 75 | - $term = TaxonomyTerm::get_by_id(TaxonomyTerm::class, $params['tag']); |
|
| 76 | - if ($term) { |
|
| 77 | - $filters[] = _t( |
|
| 78 | - 'CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_WITHIN', |
|
| 79 | - 'within' |
|
| 80 | - ) . ' "' . $term->Name . '"'; |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - if ($params['from'] || $params['to']) { |
|
| 85 | - if ($params['from']) { |
|
| 86 | - $from = strtotime($params['from']); |
|
| 87 | - if ($params['to']) { |
|
| 88 | - $to = strtotime($params['to']); |
|
| 89 | - $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_BETWEEN', 'between') . ' ' |
|
| 90 | - . date('j/m/Y', $from) . ' and ' . date('j/m/Y', $to); |
|
| 91 | - } else { |
|
| 92 | - $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_ON', 'on') |
|
| 93 | - . ' ' . date('j/m/Y', $from); |
|
| 94 | - } |
|
| 95 | - } else { |
|
| 96 | - $to = strtotime($params['to']); |
|
| 97 | - $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_ON', 'on') |
|
| 98 | - . ' ' . date('j/m/Y', $to); |
|
| 99 | - } |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if ($params['year'] && $params['month']) { |
|
| 103 | - $timestamp = mktime(1, 1, 1, $params['month'], 1, $params['year']); |
|
| 104 | - $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_IN', 'in') |
|
| 105 | - . ' ' . date('F', $timestamp) . ' ' . $params['year']; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - if ($filters) { |
|
| 109 | - return $this->getUpdateName() . ' ' . implode(' ', $filters); |
|
| 110 | - } |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - public function getUpdateName() |
|
| 114 | - { |
|
| 115 | - return Config::inst()->get($this->data()->ClassName, 'update_name'); |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - protected function init() |
|
| 119 | - { |
|
| 120 | - parent::init(); |
|
| 121 | - RSSFeed::linkToFeed($this->Link() . 'rss', $this->getSubscriptionTitle()); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * Parse URL parameters. |
|
| 126 | - * |
|
| 127 | - * @param bool $produceErrorMessages Set to false to omit session messages. |
|
| 128 | - */ |
|
| 129 | - public function parseParams($produceErrorMessages = true) |
|
| 130 | - { |
|
| 131 | - $tag = $this->request->getVar('tag'); |
|
| 132 | - $from = $this->request->getVar('from'); |
|
| 133 | - $to = $this->request->getVar('to'); |
|
| 134 | - $year = $this->request->getVar('year'); |
|
| 135 | - $month = $this->request->getVar('month'); |
|
| 136 | - |
|
| 137 | - if ($tag == '') { |
|
| 138 | - $tag = null; |
|
| 139 | - } |
|
| 140 | - if ($from == '') { |
|
| 141 | - $from = null; |
|
| 142 | - } |
|
| 143 | - if ($to == '') { |
|
| 144 | - $to = null; |
|
| 145 | - } |
|
| 146 | - if ($year == '') { |
|
| 147 | - $year = null; |
|
| 148 | - } |
|
| 149 | - if ($month == '') { |
|
| 150 | - $month = null; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - if (isset($tag)) { |
|
| 154 | - $tag = (int)$tag; |
|
| 155 | - } |
|
| 156 | - if (isset($from)) { |
|
| 157 | - $from = urldecode($from); |
|
| 158 | - $parser = DBDatetime::create(); |
|
| 159 | - $parser->setValue($from); |
|
| 160 | - $from = $parser->Format('y-MM-dd'); |
|
| 161 | - } |
|
| 162 | - if (isset($to)) { |
|
| 163 | - $to = urldecode($to); |
|
| 164 | - $parser = DBDatetime::create(); |
|
| 165 | - $parser->setValue($to); |
|
| 166 | - $to = $parser->Format('y-MM-dd'); |
|
| 167 | - } |
|
| 168 | - if (isset($year)) { |
|
| 169 | - $year = (int)$year; |
|
| 170 | - } |
|
| 171 | - if (isset($month)) { |
|
| 172 | - $month = (int)$month; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // If only "To" has been provided filter by single date. Normalise by swapping with "From". |
|
| 176 | - if (isset($to) && !isset($from)) { |
|
| 177 | - list($to, $from) = array($from, $to); |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // Flip the dates if the order is wrong. |
|
| 181 | - if (isset($to) && isset($from) && strtotime($from)>strtotime($to)) { |
|
| 182 | - list($to, $from) = array($from, $to); |
|
| 183 | - |
|
| 184 | - if ($produceErrorMessages) { |
|
| 185 | - // @todo replace |
|
| 36 | + private static $allowed_actions = [ |
|
| 37 | + 'rss', |
|
| 38 | + 'atom', |
|
| 39 | + 'DateRangeForm', |
|
| 40 | + ]; |
|
| 41 | + |
|
| 42 | + private static $casting = [ |
|
| 43 | + 'MetaTitle' => 'Text', |
|
| 44 | + 'FilterDescription' => 'Text', |
|
| 45 | + ]; |
|
| 46 | + |
|
| 47 | + /** |
|
| 48 | + * Get the meta title for the current action |
|
| 49 | + * |
|
| 50 | + * @return string |
|
| 51 | + */ |
|
| 52 | + public function getMetaTitle() |
|
| 53 | + { |
|
| 54 | + $title = $this->data()->getTitle(); |
|
| 55 | + $filter = $this->FilterDescription(); |
|
| 56 | + if ($filter) { |
|
| 57 | + $title = "{$title} - {$filter}"; |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + $this->extend('updateMetaTitle', $title); |
|
| 61 | + return $title; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + /** |
|
| 65 | + * Returns a description of the current filter |
|
| 66 | + * |
|
| 67 | + * @return string |
|
| 68 | + */ |
|
| 69 | + public function FilterDescription() |
|
| 70 | + { |
|
| 71 | + $params = $this->parseParams(); |
|
| 72 | + |
|
| 73 | + $filters = array(); |
|
| 74 | + if ($params['tag']) { |
|
| 75 | + $term = TaxonomyTerm::get_by_id(TaxonomyTerm::class, $params['tag']); |
|
| 76 | + if ($term) { |
|
| 77 | + $filters[] = _t( |
|
| 78 | + 'CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_WITHIN', |
|
| 79 | + 'within' |
|
| 80 | + ) . ' "' . $term->Name . '"'; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + if ($params['from'] || $params['to']) { |
|
| 85 | + if ($params['from']) { |
|
| 86 | + $from = strtotime($params['from']); |
|
| 87 | + if ($params['to']) { |
|
| 88 | + $to = strtotime($params['to']); |
|
| 89 | + $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_BETWEEN', 'between') . ' ' |
|
| 90 | + . date('j/m/Y', $from) . ' and ' . date('j/m/Y', $to); |
|
| 91 | + } else { |
|
| 92 | + $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_ON', 'on') |
|
| 93 | + . ' ' . date('j/m/Y', $from); |
|
| 94 | + } |
|
| 95 | + } else { |
|
| 96 | + $to = strtotime($params['to']); |
|
| 97 | + $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_ON', 'on') |
|
| 98 | + . ' ' . date('j/m/Y', $to); |
|
| 99 | + } |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if ($params['year'] && $params['month']) { |
|
| 103 | + $timestamp = mktime(1, 1, 1, $params['month'], 1, $params['year']); |
|
| 104 | + $filters[] = _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FILTER_IN', 'in') |
|
| 105 | + . ' ' . date('F', $timestamp) . ' ' . $params['year']; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + if ($filters) { |
|
| 109 | + return $this->getUpdateName() . ' ' . implode(' ', $filters); |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + public function getUpdateName() |
|
| 114 | + { |
|
| 115 | + return Config::inst()->get($this->data()->ClassName, 'update_name'); |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + protected function init() |
|
| 119 | + { |
|
| 120 | + parent::init(); |
|
| 121 | + RSSFeed::linkToFeed($this->Link() . 'rss', $this->getSubscriptionTitle()); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * Parse URL parameters. |
|
| 126 | + * |
|
| 127 | + * @param bool $produceErrorMessages Set to false to omit session messages. |
|
| 128 | + */ |
|
| 129 | + public function parseParams($produceErrorMessages = true) |
|
| 130 | + { |
|
| 131 | + $tag = $this->request->getVar('tag'); |
|
| 132 | + $from = $this->request->getVar('from'); |
|
| 133 | + $to = $this->request->getVar('to'); |
|
| 134 | + $year = $this->request->getVar('year'); |
|
| 135 | + $month = $this->request->getVar('month'); |
|
| 136 | + |
|
| 137 | + if ($tag == '') { |
|
| 138 | + $tag = null; |
|
| 139 | + } |
|
| 140 | + if ($from == '') { |
|
| 141 | + $from = null; |
|
| 142 | + } |
|
| 143 | + if ($to == '') { |
|
| 144 | + $to = null; |
|
| 145 | + } |
|
| 146 | + if ($year == '') { |
|
| 147 | + $year = null; |
|
| 148 | + } |
|
| 149 | + if ($month == '') { |
|
| 150 | + $month = null; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + if (isset($tag)) { |
|
| 154 | + $tag = (int)$tag; |
|
| 155 | + } |
|
| 156 | + if (isset($from)) { |
|
| 157 | + $from = urldecode($from); |
|
| 158 | + $parser = DBDatetime::create(); |
|
| 159 | + $parser->setValue($from); |
|
| 160 | + $from = $parser->Format('y-MM-dd'); |
|
| 161 | + } |
|
| 162 | + if (isset($to)) { |
|
| 163 | + $to = urldecode($to); |
|
| 164 | + $parser = DBDatetime::create(); |
|
| 165 | + $parser->setValue($to); |
|
| 166 | + $to = $parser->Format('y-MM-dd'); |
|
| 167 | + } |
|
| 168 | + if (isset($year)) { |
|
| 169 | + $year = (int)$year; |
|
| 170 | + } |
|
| 171 | + if (isset($month)) { |
|
| 172 | + $month = (int)$month; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // If only "To" has been provided filter by single date. Normalise by swapping with "From". |
|
| 176 | + if (isset($to) && !isset($from)) { |
|
| 177 | + list($to, $from) = array($from, $to); |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // Flip the dates if the order is wrong. |
|
| 181 | + if (isset($to) && isset($from) && strtotime($from)>strtotime($to)) { |
|
| 182 | + list($to, $from) = array($from, $to); |
|
| 183 | + |
|
| 184 | + if ($produceErrorMessages) { |
|
| 185 | + // @todo replace |
|
| 186 | 186 | // Session::setFormMessage( |
| 187 | 187 | // 'Form_DateRangeForm', |
| 188 | 188 | // _t('DateUpdateHolder.FilterAppliedMessage', 'Filter has been applied with the dates reversed.'), |
| 189 | 189 | // 'warning' |
| 190 | 190 | // ); |
| 191 | - } |
|
| 192 | - } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | 193 | |
| 194 | - // Notify the user that filtering by single date is taking place. |
|
| 195 | - if (isset($from) && !isset($to)) { |
|
| 196 | - if ($produceErrorMessages) { |
|
| 197 | - // @todo replace |
|
| 194 | + // Notify the user that filtering by single date is taking place. |
|
| 195 | + if (isset($from) && !isset($to)) { |
|
| 196 | + if ($produceErrorMessages) { |
|
| 197 | + // @todo replace |
|
| 198 | 198 | // Session::setFormMessage( |
| 199 | 199 | // 'Form_DateRangeForm', |
| 200 | 200 | // _t('DateUpdateHolder.DateRangeFilterMessage', 'Filtered by a single date.'), |
| 201 | 201 | // 'warning' |
| 202 | 202 | // ); |
| 203 | - } |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return [ |
|
| 207 | - 'tag' => $tag, |
|
| 208 | - 'from' => $from, |
|
| 209 | - 'to' => $to, |
|
| 210 | - 'year' => $year, |
|
| 211 | - 'month' => $month, |
|
| 212 | - ]; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Build the link - keep the date range, reset the rest. |
|
| 217 | - */ |
|
| 218 | - public function AllTagsLink() |
|
| 219 | - { |
|
| 220 | - $link = HTTP::setGetVar('tag', null, null, '&'); |
|
| 221 | - $link = HTTP::setGetVar('month', null, $link, '&'); |
|
| 222 | - $link = HTTP::setGetVar('year', null, $link, '&'); |
|
| 223 | - $link = HTTP::setGetVar('start', null, $link, '&'); |
|
| 224 | - |
|
| 225 | - return $link; |
|
| 226 | - } |
|
| 227 | - |
|
| 228 | - /** |
|
| 229 | - * List tags and attach links. |
|
| 230 | - */ |
|
| 231 | - public function UpdateTagsWithLinks() |
|
| 232 | - { |
|
| 233 | - $tags = $this->UpdateTags(); |
|
| 234 | - |
|
| 235 | - $processed = ArrayList::create(); |
|
| 236 | - |
|
| 237 | - foreach ($tags as $tag) { |
|
| 238 | - // Build the link - keep the tag, and date range, but reset month, year and pagination. |
|
| 239 | - $link = HTTP::setGetVar('tag', $tag->ID, null, '&'); |
|
| 240 | - $link = HTTP::setGetVar('month', null, $link, '&'); |
|
| 241 | - $link = HTTP::setGetVar('year', null, $link, '&'); |
|
| 242 | - $link = HTTP::setGetVar('start', null, $link, '&'); |
|
| 243 | - |
|
| 244 | - $tag->Link = $link; |
|
| 245 | - $processed->push($tag); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - return $processed; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Get the TaxonomyTerm related to the current tag GET parameter. |
|
| 253 | - */ |
|
| 254 | - public function CurrentTag() |
|
| 255 | - { |
|
| 256 | - $tagID = $this->request->getVar('tag'); |
|
| 257 | - |
|
| 258 | - if (isset($tagID)) { |
|
| 259 | - return TaxonomyTerm::get_by_id(TaxonomyTerm::class, (int)$tagID); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - |
|
| 263 | - /** |
|
| 264 | - * Extract the available months based on the current query. |
|
| 265 | - * Only tag is respected. Pagination and months are ignored. |
|
| 266 | - */ |
|
| 267 | - public function AvailableMonths() |
|
| 268 | - { |
|
| 269 | - $params = $this->parseParams(); |
|
| 270 | - |
|
| 271 | - return DatedUpdateHolder::ExtractMonths( |
|
| 272 | - $this->Updates($params['tag'], $params['from'], $params['to']), |
|
| 273 | - Director::makeRelative($_SERVER['REQUEST_URI']), |
|
| 274 | - $params['year'], |
|
| 275 | - $params['month'] |
|
| 276 | - ); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - /** |
|
| 280 | - * Get the updates based on the current query. |
|
| 281 | - */ |
|
| 282 | - public function FilteredUpdates($pageSize = 20) |
|
| 283 | - { |
|
| 284 | - $params = $this->parseParams(); |
|
| 285 | - |
|
| 286 | - $items = $this->Updates( |
|
| 287 | - $params['tag'], |
|
| 288 | - $params['from'], |
|
| 289 | - $params['to'], |
|
| 290 | - $params['year'], |
|
| 291 | - $params['month'] |
|
| 292 | - ); |
|
| 293 | - |
|
| 294 | - // Apply pagination |
|
| 295 | - $list = PaginatedList::create($items, $this->getRequest()); |
|
| 296 | - $list->setPageLength($pageSize); |
|
| 297 | - return $list; |
|
| 298 | - } |
|
| 299 | - |
|
| 300 | - /** |
|
| 301 | - * @return Form |
|
| 302 | - */ |
|
| 303 | - public function DateRangeForm() |
|
| 304 | - { |
|
| 305 | - $dateFromTitle = DBField::create_field('HTMLText', sprintf( |
|
| 306 | - '%s <span class="field-note">%s</span>', |
|
| 307 | - _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FROM_DATE', 'From date'), |
|
| 308 | - _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.DATE_EXAMPLE', '(example: 2017/12/30)') |
|
| 309 | - )); |
|
| 310 | - $dateToTitle = DBField::create_field('HTMLText', sprintf( |
|
| 311 | - '%s <span class="field-note">%s</span>', |
|
| 312 | - _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.TO_DATE', 'To date'), |
|
| 313 | - _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.DATE_EXAMPLE', '(example: 2017/12/30)') |
|
| 314 | - )); |
|
| 315 | - |
|
| 316 | - $fields = FieldList::create( |
|
| 317 | - DateField::create('from', $dateFromTitle), |
|
| 318 | - DateField::create('to', $dateToTitle), |
|
| 319 | - HiddenField::create('tag') |
|
| 320 | - ); |
|
| 321 | - |
|
| 322 | - $actions = FieldList::create( |
|
| 323 | - FormAction::create("doDateFilter") |
|
| 324 | - ->setTitle(_t(__CLASS__ . '.Filter', 'Filter')) |
|
| 325 | - ->addExtraClass('btn btn-primary primary'), |
|
| 326 | - FormAction::create("doDateReset") |
|
| 327 | - ->setTitle(_t(__CLASS__ . '.Clear', 'Clear')) |
|
| 328 | - ->addExtraClass('btn') |
|
| 329 | - ); |
|
| 330 | - |
|
| 331 | - $form = Form::create($this, 'DateRangeForm', $fields, $actions); |
|
| 332 | - $form->loadDataFrom($this->request->getVars()); |
|
| 333 | - $form->setFormMethod('get'); |
|
| 334 | - |
|
| 335 | - // Manually extract the message so we can clear it. |
|
| 336 | - $form->ErrorMessage = $form->getMessage(); |
|
| 337 | - $form->ErrorMessageType = $form->getMessageType(); |
|
| 338 | - $form->clearMessage(); |
|
| 339 | - |
|
| 340 | - return $form; |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - public function doDateFilter() |
|
| 344 | - { |
|
| 345 | - $params = $this->parseParams(); |
|
| 346 | - |
|
| 347 | - // Build the link - keep the tag, but reset month, year and pagination. |
|
| 348 | - $link = HTTP::setGetVar('from', $params['from'], $this->AbsoluteLink(), '&'); |
|
| 349 | - $link = HTTP::setGetVar('to', $params['to'], $link, '&'); |
|
| 350 | - if (isset($params['tag'])) { |
|
| 351 | - $link = HTTP::setGetVar('tag', $params['tag'], $link, '&'); |
|
| 352 | - } |
|
| 353 | - |
|
| 354 | - $this->redirect($link); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - public function doDateReset() |
|
| 358 | - { |
|
| 359 | - $params = $this->parseParams(false); |
|
| 360 | - |
|
| 361 | - // Reset the link - only include the tag. |
|
| 362 | - $link = $this->AbsoluteLink(); |
|
| 363 | - if (isset($params['tag'])) { |
|
| 364 | - $link = HTTP::setGetVar('tag', $params['tag'], $link, '&'); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - $this->redirect($link); |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - public function rss() |
|
| 371 | - { |
|
| 372 | - $rss = RSSFeed::create( |
|
| 373 | - $this->Updates()->sort('Created DESC')->limit(20), |
|
| 374 | - $this->Link('rss'), |
|
| 375 | - $this->getSubscriptionTitle() |
|
| 376 | - ); |
|
| 377 | - return $rss->outputToBrowser(); |
|
| 378 | - } |
|
| 379 | - |
|
| 380 | - public function atom() |
|
| 381 | - { |
|
| 382 | - $atom = CwpAtomFeed::create( |
|
| 383 | - $this->Updates()->sort('Created DESC')->limit(20), |
|
| 384 | - $this->Link('atom'), |
|
| 385 | - $this->getSubscriptionTitle() |
|
| 386 | - ); |
|
| 387 | - return $atom->outputToBrowser(); |
|
| 388 | - } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return [ |
|
| 207 | + 'tag' => $tag, |
|
| 208 | + 'from' => $from, |
|
| 209 | + 'to' => $to, |
|
| 210 | + 'year' => $year, |
|
| 211 | + 'month' => $month, |
|
| 212 | + ]; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Build the link - keep the date range, reset the rest. |
|
| 217 | + */ |
|
| 218 | + public function AllTagsLink() |
|
| 219 | + { |
|
| 220 | + $link = HTTP::setGetVar('tag', null, null, '&'); |
|
| 221 | + $link = HTTP::setGetVar('month', null, $link, '&'); |
|
| 222 | + $link = HTTP::setGetVar('year', null, $link, '&'); |
|
| 223 | + $link = HTTP::setGetVar('start', null, $link, '&'); |
|
| 224 | + |
|
| 225 | + return $link; |
|
| 226 | + } |
|
| 227 | + |
|
| 228 | + /** |
|
| 229 | + * List tags and attach links. |
|
| 230 | + */ |
|
| 231 | + public function UpdateTagsWithLinks() |
|
| 232 | + { |
|
| 233 | + $tags = $this->UpdateTags(); |
|
| 234 | + |
|
| 235 | + $processed = ArrayList::create(); |
|
| 236 | + |
|
| 237 | + foreach ($tags as $tag) { |
|
| 238 | + // Build the link - keep the tag, and date range, but reset month, year and pagination. |
|
| 239 | + $link = HTTP::setGetVar('tag', $tag->ID, null, '&'); |
|
| 240 | + $link = HTTP::setGetVar('month', null, $link, '&'); |
|
| 241 | + $link = HTTP::setGetVar('year', null, $link, '&'); |
|
| 242 | + $link = HTTP::setGetVar('start', null, $link, '&'); |
|
| 243 | + |
|
| 244 | + $tag->Link = $link; |
|
| 245 | + $processed->push($tag); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + return $processed; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Get the TaxonomyTerm related to the current tag GET parameter. |
|
| 253 | + */ |
|
| 254 | + public function CurrentTag() |
|
| 255 | + { |
|
| 256 | + $tagID = $this->request->getVar('tag'); |
|
| 257 | + |
|
| 258 | + if (isset($tagID)) { |
|
| 259 | + return TaxonomyTerm::get_by_id(TaxonomyTerm::class, (int)$tagID); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + |
|
| 263 | + /** |
|
| 264 | + * Extract the available months based on the current query. |
|
| 265 | + * Only tag is respected. Pagination and months are ignored. |
|
| 266 | + */ |
|
| 267 | + public function AvailableMonths() |
|
| 268 | + { |
|
| 269 | + $params = $this->parseParams(); |
|
| 270 | + |
|
| 271 | + return DatedUpdateHolder::ExtractMonths( |
|
| 272 | + $this->Updates($params['tag'], $params['from'], $params['to']), |
|
| 273 | + Director::makeRelative($_SERVER['REQUEST_URI']), |
|
| 274 | + $params['year'], |
|
| 275 | + $params['month'] |
|
| 276 | + ); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + /** |
|
| 280 | + * Get the updates based on the current query. |
|
| 281 | + */ |
|
| 282 | + public function FilteredUpdates($pageSize = 20) |
|
| 283 | + { |
|
| 284 | + $params = $this->parseParams(); |
|
| 285 | + |
|
| 286 | + $items = $this->Updates( |
|
| 287 | + $params['tag'], |
|
| 288 | + $params['from'], |
|
| 289 | + $params['to'], |
|
| 290 | + $params['year'], |
|
| 291 | + $params['month'] |
|
| 292 | + ); |
|
| 293 | + |
|
| 294 | + // Apply pagination |
|
| 295 | + $list = PaginatedList::create($items, $this->getRequest()); |
|
| 296 | + $list->setPageLength($pageSize); |
|
| 297 | + return $list; |
|
| 298 | + } |
|
| 299 | + |
|
| 300 | + /** |
|
| 301 | + * @return Form |
|
| 302 | + */ |
|
| 303 | + public function DateRangeForm() |
|
| 304 | + { |
|
| 305 | + $dateFromTitle = DBField::create_field('HTMLText', sprintf( |
|
| 306 | + '%s <span class="field-note">%s</span>', |
|
| 307 | + _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.FROM_DATE', 'From date'), |
|
| 308 | + _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.DATE_EXAMPLE', '(example: 2017/12/30)') |
|
| 309 | + )); |
|
| 310 | + $dateToTitle = DBField::create_field('HTMLText', sprintf( |
|
| 311 | + '%s <span class="field-note">%s</span>', |
|
| 312 | + _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.TO_DATE', 'To date'), |
|
| 313 | + _t('CWP\\CWP\\PageTypes\\DatedUpdateHolder.DATE_EXAMPLE', '(example: 2017/12/30)') |
|
| 314 | + )); |
|
| 315 | + |
|
| 316 | + $fields = FieldList::create( |
|
| 317 | + DateField::create('from', $dateFromTitle), |
|
| 318 | + DateField::create('to', $dateToTitle), |
|
| 319 | + HiddenField::create('tag') |
|
| 320 | + ); |
|
| 321 | + |
|
| 322 | + $actions = FieldList::create( |
|
| 323 | + FormAction::create("doDateFilter") |
|
| 324 | + ->setTitle(_t(__CLASS__ . '.Filter', 'Filter')) |
|
| 325 | + ->addExtraClass('btn btn-primary primary'), |
|
| 326 | + FormAction::create("doDateReset") |
|
| 327 | + ->setTitle(_t(__CLASS__ . '.Clear', 'Clear')) |
|
| 328 | + ->addExtraClass('btn') |
|
| 329 | + ); |
|
| 330 | + |
|
| 331 | + $form = Form::create($this, 'DateRangeForm', $fields, $actions); |
|
| 332 | + $form->loadDataFrom($this->request->getVars()); |
|
| 333 | + $form->setFormMethod('get'); |
|
| 334 | + |
|
| 335 | + // Manually extract the message so we can clear it. |
|
| 336 | + $form->ErrorMessage = $form->getMessage(); |
|
| 337 | + $form->ErrorMessageType = $form->getMessageType(); |
|
| 338 | + $form->clearMessage(); |
|
| 339 | + |
|
| 340 | + return $form; |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + public function doDateFilter() |
|
| 344 | + { |
|
| 345 | + $params = $this->parseParams(); |
|
| 346 | + |
|
| 347 | + // Build the link - keep the tag, but reset month, year and pagination. |
|
| 348 | + $link = HTTP::setGetVar('from', $params['from'], $this->AbsoluteLink(), '&'); |
|
| 349 | + $link = HTTP::setGetVar('to', $params['to'], $link, '&'); |
|
| 350 | + if (isset($params['tag'])) { |
|
| 351 | + $link = HTTP::setGetVar('tag', $params['tag'], $link, '&'); |
|
| 352 | + } |
|
| 353 | + |
|
| 354 | + $this->redirect($link); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + public function doDateReset() |
|
| 358 | + { |
|
| 359 | + $params = $this->parseParams(false); |
|
| 360 | + |
|
| 361 | + // Reset the link - only include the tag. |
|
| 362 | + $link = $this->AbsoluteLink(); |
|
| 363 | + if (isset($params['tag'])) { |
|
| 364 | + $link = HTTP::setGetVar('tag', $params['tag'], $link, '&'); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + $this->redirect($link); |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + public function rss() |
|
| 371 | + { |
|
| 372 | + $rss = RSSFeed::create( |
|
| 373 | + $this->Updates()->sort('Created DESC')->limit(20), |
|
| 374 | + $this->Link('rss'), |
|
| 375 | + $this->getSubscriptionTitle() |
|
| 376 | + ); |
|
| 377 | + return $rss->outputToBrowser(); |
|
| 378 | + } |
|
| 379 | + |
|
| 380 | + public function atom() |
|
| 381 | + { |
|
| 382 | + $atom = CwpAtomFeed::create( |
|
| 383 | + $this->Updates()->sort('Created DESC')->limit(20), |
|
| 384 | + $this->Link('atom'), |
|
| 385 | + $this->getSubscriptionTitle() |
|
| 386 | + ); |
|
| 387 | + return $atom->outputToBrowser(); |
|
| 388 | + } |
|
| 389 | 389 | } |
@@ -6,11 +6,11 @@ |
||
| 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 | } |
@@ -66,7 +66,7 @@ |
||
| 66 | 66 | |
| 67 | 67 | public function getCMSFields() |
| 68 | 68 | { |
| 69 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 69 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
| 70 | 70 | // Main Content tab |
| 71 | 71 | $fields->addFieldToTab( |
| 72 | 72 | 'Root.Main', |
@@ -26,137 +26,137 @@ |
||
| 26 | 26 | */ |
| 27 | 27 | class BaseHomePage extends Page |
| 28 | 28 | { |
| 29 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/home.png'; |
|
| 30 | - |
|
| 31 | - private static $hide_ancestor = BaseHomePage::class; |
|
| 32 | - |
|
| 33 | - private static $singular_name = 'Home Page'; |
|
| 34 | - |
|
| 35 | - private static $plural_name = 'Home Pages'; |
|
| 36 | - |
|
| 37 | - private static $table_name = 'BaseHomePage'; |
|
| 38 | - |
|
| 39 | - private static $db = array( |
|
| 40 | - 'FeatureOneTitle' => 'Varchar(255)', |
|
| 41 | - 'FeatureOneCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')", |
|
| 42 | - 'FeatureOneContent' => 'HTMLText', |
|
| 43 | - 'FeatureOneButtonText' => 'Varchar(255)', |
|
| 44 | - 'FeatureTwoTitle' => 'Varchar(255)', |
|
| 45 | - 'FeatureTwoCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')", |
|
| 46 | - 'FeatureTwoContent' => 'HTMLText', |
|
| 47 | - 'FeatureTwoButtonText' => 'Varchar(255)' |
|
| 48 | - ); |
|
| 49 | - |
|
| 50 | - private static $has_one = array( |
|
| 51 | - 'LearnMorePage' => SiteTree::class, |
|
| 52 | - 'FeatureOneLink' => SiteTree::class, |
|
| 53 | - 'FeatureTwoLink' => SiteTree::class |
|
| 54 | - ); |
|
| 55 | - |
|
| 56 | - private static $has_many = array( |
|
| 57 | - 'Quicklinks' => 'Quicklink.Parent' |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - public function Quicklinks() |
|
| 61 | - { |
|
| 62 | - return $this->getComponents('Quicklinks')->sort('SortOrder'); |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - public function getCMSFields() |
|
| 66 | - { |
|
| 67 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 68 | - // Main Content tab |
|
| 69 | - $fields->addFieldToTab( |
|
| 70 | - 'Root.Main', |
|
| 71 | - TreeDropdownField::create( |
|
| 72 | - 'LearnMorePageID', |
|
| 73 | - _t(__CLASS__ . '.LearnMoreLink', 'Page to link the "Learn More" button to:'), |
|
| 74 | - SiteTree::class |
|
| 75 | - ), |
|
| 76 | - 'Metadata' |
|
| 77 | - ); |
|
| 78 | - |
|
| 79 | - $gridField = GridField::create( |
|
| 80 | - 'Quicklinks', |
|
| 81 | - 'Quicklinks', |
|
| 82 | - $this->Quicklinks(), |
|
| 83 | - GridFieldConfig_RelationEditor::create() |
|
| 84 | - ); |
|
| 85 | - $gridConfig = $gridField->getConfig(); |
|
| 86 | - $gridConfig->getComponentByType(GridFieldAddNewButton::class)->setButtonName( |
|
| 87 | - _t(__CLASS__ . '.AddNewButton', 'Add new') |
|
| 88 | - ); |
|
| 89 | - |
|
| 90 | - $injector = Injector::inst(); |
|
| 91 | - |
|
| 92 | - $gridConfig->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
|
| 93 | - $gridConfig->removeComponentsByType(GridFieldDeleteAction::class); |
|
| 94 | - $gridConfig->addComponent($injector->create(GridFieldDeleteAction::class)); |
|
| 95 | - $gridConfig->addComponent($injector->create(GridFieldSortableRows::class, 'SortOrder')); |
|
| 96 | - $gridField->setModelClass(Quicklink::class); |
|
| 97 | - |
|
| 98 | - $fields->addFieldToTab('Root.Quicklinks', $gridField); |
|
| 99 | - |
|
| 100 | - $fields->removeByName('Import'); |
|
| 101 | - |
|
| 102 | - $fields->addFieldToTab( |
|
| 103 | - 'Root.Features', |
|
| 104 | - ToggleCompositeField::create( |
|
| 105 | - 'FeatureOne', |
|
| 106 | - _t(__CLASS__ . '.FeatureOne', 'Feature One'), |
|
| 107 | - array( |
|
| 108 | - TextField::create('FeatureOneTitle', _t(__CLASS__ . '.Title', 'Title')), |
|
| 109 | - $dropdownField = DropdownField::create( |
|
| 110 | - 'FeatureOneCategory', |
|
| 111 | - _t(__CLASS__ . '.FeatureCategoryDropdown', 'Category icon'), |
|
| 112 | - singleton(BaseHomePage::class)->dbObject('FeatureOneCategory')->enumValues() |
|
| 113 | - ), |
|
| 114 | - HTMLEditorField::create( |
|
| 115 | - 'FeatureOneContent', |
|
| 116 | - _t(__CLASS__ . '.FeatureContentFieldLabel', 'Content') |
|
| 117 | - ), |
|
| 118 | - TextField::create( |
|
| 119 | - 'FeatureOneButtonText', |
|
| 120 | - _t(__CLASS__ . '.FeatureButtonText', 'Button text') |
|
| 121 | - ), |
|
| 122 | - TreeDropdownField::create( |
|
| 123 | - 'FeatureOneLinkID', |
|
| 124 | - _t(__CLASS__ . '.FeatureLink', 'Page to link to'), |
|
| 125 | - SiteTree::class |
|
| 126 | - )->setDescription(_t(__CLASS__ . '.ButtonTextRequired', 'Button text must be filled in')) |
|
| 127 | - ) |
|
| 128 | - )->setHeadingLevel(3) |
|
| 129 | - ); |
|
| 130 | - $dropdownField->setEmptyString('none'); |
|
| 131 | - |
|
| 132 | - $fields->addFieldToTab('Root.Features', ToggleCompositeField::create( |
|
| 133 | - 'FeatureTwo', |
|
| 134 | - _t(__CLASS__ . '.FeatureTwo', 'Feature Two'), |
|
| 135 | - array( |
|
| 136 | - TextField::create('FeatureTwoTitle', _t(__CLASS__ . '.Title', 'Title')), |
|
| 137 | - $dropdownField = DropdownField::create( |
|
| 138 | - 'FeatureTwoCategory', |
|
| 139 | - _t(__CLASS__ . '.FeatureCategoryDropdown', 'Category icon'), |
|
| 140 | - singleton(BaseHomePage::class)->dbObject('FeatureTwoCategory')->enumValues() |
|
| 141 | - ), |
|
| 142 | - HTMLEditorField::create( |
|
| 143 | - 'FeatureTwoContent', |
|
| 144 | - _t(__CLASS__ . '.FeatureContentFieldLabel', 'Content') |
|
| 145 | - ), |
|
| 146 | - TextField::create( |
|
| 147 | - 'FeatureTwoButtonText', |
|
| 148 | - _t(__CLASS__ . '.FeatureButtonText', 'Button text') |
|
| 149 | - ), |
|
| 150 | - TreeDropdownField::create( |
|
| 151 | - 'FeatureTwoLinkID', |
|
| 152 | - _t(__CLASS__ . '.FeatureLink', 'Page to link to'), |
|
| 153 | - SiteTree::class |
|
| 154 | - )->setDescription(_t(__CLASS__ . '.ButtonTextRequired', 'Button text must be filled in')) |
|
| 155 | - ) |
|
| 156 | - )->setHeadingLevel(3)); |
|
| 157 | - $dropdownField->setEmptyString('none'); |
|
| 158 | - }); |
|
| 159 | - |
|
| 160 | - return parent::getCMSFields(); |
|
| 161 | - } |
|
| 29 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/home.png'; |
|
| 30 | + |
|
| 31 | + private static $hide_ancestor = BaseHomePage::class; |
|
| 32 | + |
|
| 33 | + private static $singular_name = 'Home Page'; |
|
| 34 | + |
|
| 35 | + private static $plural_name = 'Home Pages'; |
|
| 36 | + |
|
| 37 | + private static $table_name = 'BaseHomePage'; |
|
| 38 | + |
|
| 39 | + private static $db = array( |
|
| 40 | + 'FeatureOneTitle' => 'Varchar(255)', |
|
| 41 | + 'FeatureOneCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')", |
|
| 42 | + 'FeatureOneContent' => 'HTMLText', |
|
| 43 | + 'FeatureOneButtonText' => 'Varchar(255)', |
|
| 44 | + 'FeatureTwoTitle' => 'Varchar(255)', |
|
| 45 | + 'FeatureTwoCategory' => "Enum('bell,comments,film,flag,globe,group,list,phone,rss,time,user','comments')", |
|
| 46 | + 'FeatureTwoContent' => 'HTMLText', |
|
| 47 | + 'FeatureTwoButtonText' => 'Varchar(255)' |
|
| 48 | + ); |
|
| 49 | + |
|
| 50 | + private static $has_one = array( |
|
| 51 | + 'LearnMorePage' => SiteTree::class, |
|
| 52 | + 'FeatureOneLink' => SiteTree::class, |
|
| 53 | + 'FeatureTwoLink' => SiteTree::class |
|
| 54 | + ); |
|
| 55 | + |
|
| 56 | + private static $has_many = array( |
|
| 57 | + 'Quicklinks' => 'Quicklink.Parent' |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + public function Quicklinks() |
|
| 61 | + { |
|
| 62 | + return $this->getComponents('Quicklinks')->sort('SortOrder'); |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + public function getCMSFields() |
|
| 66 | + { |
|
| 67 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 68 | + // Main Content tab |
|
| 69 | + $fields->addFieldToTab( |
|
| 70 | + 'Root.Main', |
|
| 71 | + TreeDropdownField::create( |
|
| 72 | + 'LearnMorePageID', |
|
| 73 | + _t(__CLASS__ . '.LearnMoreLink', 'Page to link the "Learn More" button to:'), |
|
| 74 | + SiteTree::class |
|
| 75 | + ), |
|
| 76 | + 'Metadata' |
|
| 77 | + ); |
|
| 78 | + |
|
| 79 | + $gridField = GridField::create( |
|
| 80 | + 'Quicklinks', |
|
| 81 | + 'Quicklinks', |
|
| 82 | + $this->Quicklinks(), |
|
| 83 | + GridFieldConfig_RelationEditor::create() |
|
| 84 | + ); |
|
| 85 | + $gridConfig = $gridField->getConfig(); |
|
| 86 | + $gridConfig->getComponentByType(GridFieldAddNewButton::class)->setButtonName( |
|
| 87 | + _t(__CLASS__ . '.AddNewButton', 'Add new') |
|
| 88 | + ); |
|
| 89 | + |
|
| 90 | + $injector = Injector::inst(); |
|
| 91 | + |
|
| 92 | + $gridConfig->removeComponentsByType(GridFieldAddExistingAutocompleter::class); |
|
| 93 | + $gridConfig->removeComponentsByType(GridFieldDeleteAction::class); |
|
| 94 | + $gridConfig->addComponent($injector->create(GridFieldDeleteAction::class)); |
|
| 95 | + $gridConfig->addComponent($injector->create(GridFieldSortableRows::class, 'SortOrder')); |
|
| 96 | + $gridField->setModelClass(Quicklink::class); |
|
| 97 | + |
|
| 98 | + $fields->addFieldToTab('Root.Quicklinks', $gridField); |
|
| 99 | + |
|
| 100 | + $fields->removeByName('Import'); |
|
| 101 | + |
|
| 102 | + $fields->addFieldToTab( |
|
| 103 | + 'Root.Features', |
|
| 104 | + ToggleCompositeField::create( |
|
| 105 | + 'FeatureOne', |
|
| 106 | + _t(__CLASS__ . '.FeatureOne', 'Feature One'), |
|
| 107 | + array( |
|
| 108 | + TextField::create('FeatureOneTitle', _t(__CLASS__ . '.Title', 'Title')), |
|
| 109 | + $dropdownField = DropdownField::create( |
|
| 110 | + 'FeatureOneCategory', |
|
| 111 | + _t(__CLASS__ . '.FeatureCategoryDropdown', 'Category icon'), |
|
| 112 | + singleton(BaseHomePage::class)->dbObject('FeatureOneCategory')->enumValues() |
|
| 113 | + ), |
|
| 114 | + HTMLEditorField::create( |
|
| 115 | + 'FeatureOneContent', |
|
| 116 | + _t(__CLASS__ . '.FeatureContentFieldLabel', 'Content') |
|
| 117 | + ), |
|
| 118 | + TextField::create( |
|
| 119 | + 'FeatureOneButtonText', |
|
| 120 | + _t(__CLASS__ . '.FeatureButtonText', 'Button text') |
|
| 121 | + ), |
|
| 122 | + TreeDropdownField::create( |
|
| 123 | + 'FeatureOneLinkID', |
|
| 124 | + _t(__CLASS__ . '.FeatureLink', 'Page to link to'), |
|
| 125 | + SiteTree::class |
|
| 126 | + )->setDescription(_t(__CLASS__ . '.ButtonTextRequired', 'Button text must be filled in')) |
|
| 127 | + ) |
|
| 128 | + )->setHeadingLevel(3) |
|
| 129 | + ); |
|
| 130 | + $dropdownField->setEmptyString('none'); |
|
| 131 | + |
|
| 132 | + $fields->addFieldToTab('Root.Features', ToggleCompositeField::create( |
|
| 133 | + 'FeatureTwo', |
|
| 134 | + _t(__CLASS__ . '.FeatureTwo', 'Feature Two'), |
|
| 135 | + array( |
|
| 136 | + TextField::create('FeatureTwoTitle', _t(__CLASS__ . '.Title', 'Title')), |
|
| 137 | + $dropdownField = DropdownField::create( |
|
| 138 | + 'FeatureTwoCategory', |
|
| 139 | + _t(__CLASS__ . '.FeatureCategoryDropdown', 'Category icon'), |
|
| 140 | + singleton(BaseHomePage::class)->dbObject('FeatureTwoCategory')->enumValues() |
|
| 141 | + ), |
|
| 142 | + HTMLEditorField::create( |
|
| 143 | + 'FeatureTwoContent', |
|
| 144 | + _t(__CLASS__ . '.FeatureContentFieldLabel', 'Content') |
|
| 145 | + ), |
|
| 146 | + TextField::create( |
|
| 147 | + 'FeatureTwoButtonText', |
|
| 148 | + _t(__CLASS__ . '.FeatureButtonText', 'Button text') |
|
| 149 | + ), |
|
| 150 | + TreeDropdownField::create( |
|
| 151 | + 'FeatureTwoLinkID', |
|
| 152 | + _t(__CLASS__ . '.FeatureLink', 'Page to link to'), |
|
| 153 | + SiteTree::class |
|
| 154 | + )->setDescription(_t(__CLASS__ . '.ButtonTextRequired', 'Button text must be filled in')) |
|
| 155 | + ) |
|
| 156 | + )->setHeadingLevel(3)); |
|
| 157 | + $dropdownField->setEmptyString('none'); |
|
| 158 | + }); |
|
| 159 | + |
|
| 160 | + return parent::getCMSFields(); |
|
| 161 | + } |
|
| 162 | 162 | } |
@@ -55,7 +55,7 @@ |
||
| 55 | 55 | |
| 56 | 56 | public function getCMSFields() |
| 57 | 57 | { |
| 58 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 58 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
| 59 | 59 | $fields->addFieldToTab( |
| 60 | 60 | 'Root.Main', |
| 61 | 61 | $dateTimeField = DatetimeField::create('Date', $this->fieldLabel('Date')), |
@@ -10,70 +10,70 @@ |
||
| 10 | 10 | |
| 11 | 11 | class DatedUpdatePage extends Page |
| 12 | 12 | { |
| 13 | - /** |
|
| 14 | - * Meant as an abstract base class. |
|
| 15 | - * |
|
| 16 | - * {@inheritDoc} |
|
| 17 | - */ |
|
| 18 | - private static $hide_ancestor = DatedUpdatePage::class; |
|
| 13 | + /** |
|
| 14 | + * Meant as an abstract base class. |
|
| 15 | + * |
|
| 16 | + * {@inheritDoc} |
|
| 17 | + */ |
|
| 18 | + private static $hide_ancestor = DatedUpdatePage::class; |
|
| 19 | 19 | |
| 20 | - private static $singular_name = 'Dated Update Page'; |
|
| 20 | + private static $singular_name = 'Dated Update Page'; |
|
| 21 | 21 | |
| 22 | - private static $plural_name = 'Dated Update Pages'; |
|
| 22 | + private static $plural_name = 'Dated Update Pages'; |
|
| 23 | 23 | |
| 24 | - private static $table_name = 'DatedUpdatePage'; |
|
| 24 | + private static $table_name = 'DatedUpdatePage'; |
|
| 25 | 25 | |
| 26 | - private static $defaults = [ |
|
| 27 | - 'ShowInMenus' => false, |
|
| 28 | - ]; |
|
| 26 | + private static $defaults = [ |
|
| 27 | + 'ShowInMenus' => false, |
|
| 28 | + ]; |
|
| 29 | 29 | |
| 30 | - private static $db = [ |
|
| 31 | - 'Abstract' => 'Text', |
|
| 32 | - 'Date' => 'Datetime', |
|
| 33 | - ]; |
|
| 30 | + private static $db = [ |
|
| 31 | + 'Abstract' => 'Text', |
|
| 32 | + 'Date' => 'Datetime', |
|
| 33 | + ]; |
|
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * Add the default for the Date being the current day. |
|
| 37 | - */ |
|
| 38 | - public function populateDefaults() |
|
| 39 | - { |
|
| 40 | - parent::populateDefaults(); |
|
| 35 | + /** |
|
| 36 | + * Add the default for the Date being the current day. |
|
| 37 | + */ |
|
| 38 | + public function populateDefaults() |
|
| 39 | + { |
|
| 40 | + parent::populateDefaults(); |
|
| 41 | 41 | |
| 42 | - if (!isset($this->Date) || $this->Date === null) { |
|
| 43 | - $this->Date = DBDatetime::now()->Format('y-MM-dd 09:00:00'); |
|
| 44 | - } |
|
| 45 | - } |
|
| 42 | + if (!isset($this->Date) || $this->Date === null) { |
|
| 43 | + $this->Date = DBDatetime::now()->Format('y-MM-dd 09:00:00'); |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - public function fieldLabels($includerelations = true) |
|
| 48 | - { |
|
| 49 | - $labels = parent::fieldLabels($includerelations); |
|
| 50 | - $labels['Date'] = _t(__CLASS__ . '.DateLabel', 'Date'); |
|
| 51 | - $labels['Abstract'] = _t(__CLASS__ . '.AbstractTextFieldLabel', 'Abstract'); |
|
| 47 | + public function fieldLabels($includerelations = true) |
|
| 48 | + { |
|
| 49 | + $labels = parent::fieldLabels($includerelations); |
|
| 50 | + $labels['Date'] = _t(__CLASS__ . '.DateLabel', 'Date'); |
|
| 51 | + $labels['Abstract'] = _t(__CLASS__ . '.AbstractTextFieldLabel', 'Abstract'); |
|
| 52 | 52 | |
| 53 | - return $labels; |
|
| 54 | - } |
|
| 53 | + return $labels; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - public function getCMSFields() |
|
| 57 | - { |
|
| 58 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 59 | - $fields->addFieldToTab( |
|
| 60 | - 'Root.Main', |
|
| 61 | - $dateTimeField = DatetimeField::create('Date', $this->fieldLabel('Date')), |
|
| 62 | - 'Content' |
|
| 63 | - ); |
|
| 56 | + public function getCMSFields() |
|
| 57 | + { |
|
| 58 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 59 | + $fields->addFieldToTab( |
|
| 60 | + 'Root.Main', |
|
| 61 | + $dateTimeField = DatetimeField::create('Date', $this->fieldLabel('Date')), |
|
| 62 | + 'Content' |
|
| 63 | + ); |
|
| 64 | 64 | |
| 65 | - $fields->addfieldToTab( |
|
| 66 | - 'Root.Main', |
|
| 67 | - $abstractField = TextareaField::create('Abstract', $this->fieldLabel('Abstract')), |
|
| 68 | - 'Content' |
|
| 69 | - ); |
|
| 70 | - $abstractField->setAttribute('maxlength', '160'); |
|
| 71 | - $abstractField->setRightTitle(_t( |
|
| 72 | - __CLASS__ . '.AbstractDesc', |
|
| 73 | - 'The abstract is used as a summary on the listing pages. It is limited to 160 characters.' |
|
| 74 | - )); |
|
| 75 | - $abstractField->setRows(6); |
|
| 76 | - }); |
|
| 77 | - return parent::getCMSFields(); |
|
| 78 | - } |
|
| 65 | + $fields->addfieldToTab( |
|
| 66 | + 'Root.Main', |
|
| 67 | + $abstractField = TextareaField::create('Abstract', $this->fieldLabel('Abstract')), |
|
| 68 | + 'Content' |
|
| 69 | + ); |
|
| 70 | + $abstractField->setAttribute('maxlength', '160'); |
|
| 71 | + $abstractField->setRightTitle(_t( |
|
| 72 | + __CLASS__ . '.AbstractDesc', |
|
| 73 | + 'The abstract is used as a summary on the listing pages. It is limited to 160 characters.' |
|
| 74 | + )); |
|
| 75 | + $abstractField->setRows(6); |
|
| 76 | + }); |
|
| 77 | + return parent::getCMSFields(); |
|
| 78 | + } |
|
| 79 | 79 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | |
| 185 | 185 | public function getCMSFields() |
| 186 | 186 | { |
| 187 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 187 | + $this->beforeUpdateCMSFields(function(FieldList $fields) { |
|
| 188 | 188 | // Related Pages |
| 189 | 189 | $components = GridFieldConfig_RelationEditor::create(); |
| 190 | 190 | $components->removeComponentsByType(GridFieldAddNewButton::class); |
@@ -292,11 +292,11 @@ discard block |
||
| 292 | 292 | 'Locale' => i18n::convert_rfc1766($loc), |
| 293 | 293 | 'LangName' => $nativeLangName, |
| 294 | 294 | 'Link' => $link, |
| 295 | - 'Current' => (Translatable::get_current_locale()==$loc) |
|
| 295 | + 'Current' => (Translatable::get_current_locale() == $loc) |
|
| 296 | 296 | ))); |
| 297 | 297 | } |
| 298 | 298 | |
| 299 | - if ($translations->count()>1) { |
|
| 299 | + if ($translations->count() > 1) { |
|
| 300 | 300 | return $translations; |
| 301 | 301 | } else { |
| 302 | 302 | return null; |
@@ -28,302 +28,302 @@ |
||
| 28 | 28 | |
| 29 | 29 | class BasePage extends SiteTree |
| 30 | 30 | { |
| 31 | - private static $icon = 'cwp/cwp:images/icons/sitetree_images/page.png'; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Hide this page type from the CMS. hide_ancestor is slightly misnamed, should really be just "hide" |
|
| 35 | - * |
|
| 36 | - * {@inheritDoc} |
|
| 37 | - */ |
|
| 38 | - private static $hide_ancestor = BasePage::class; |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @config |
|
| 42 | - * @var bool |
|
| 43 | - */ |
|
| 44 | - private static $pdf_export = false; |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Domain to generate PDF's from, DOES not include protocol |
|
| 48 | - * i.e. google.com not http://google.com |
|
| 49 | - * @config |
|
| 50 | - * @var string |
|
| 51 | - */ |
|
| 52 | - private static $pdf_base_url = ""; |
|
| 53 | - |
|
| 54 | - /** |
|
| 55 | - * Allow custom overriding of the path to the WKHTMLTOPDF binary, in cases |
|
| 56 | - * where multiple versions of the binary are available to choose from. This |
|
| 57 | - * should be the full path to the binary (e.g. /usr/local/bin/wkhtmltopdf) |
|
| 58 | - * @see BasePage_Controller::generatePDF(); |
|
| 59 | - * |
|
| 60 | - * @config |
|
| 61 | - * @var string|null |
|
| 62 | - */ |
|
| 63 | - private static $wkhtmltopdf_binary = null; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Where to store generated PDF files |
|
| 67 | - * |
|
| 68 | - * @config |
|
| 69 | - * @var string |
|
| 70 | - */ |
|
| 71 | - private static $generated_pdf_path = 'assets/_generated_pdfs'; |
|
| 72 | - |
|
| 73 | - private static $api_access = [ |
|
| 74 | - 'view' => [ |
|
| 75 | - 'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription', |
|
| 76 | - 'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID' |
|
| 77 | - ], |
|
| 78 | - 'edit' => [ |
|
| 79 | - 'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription', |
|
| 80 | - 'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID' |
|
| 81 | - ], |
|
| 82 | - ]; |
|
| 83 | - |
|
| 84 | - private static $table_name = 'BasePage'; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * @config |
|
| 88 | - * @var string |
|
| 89 | - */ |
|
| 90 | - private static $related_pages_title = 'Related pages'; |
|
| 91 | - |
|
| 92 | - private static $many_many = [ |
|
| 93 | - 'Terms' => TaxonomyTerm::class, |
|
| 94 | - 'RelatedPages' => BasePage::class, |
|
| 95 | - ]; |
|
| 96 | - |
|
| 97 | - private static $many_many_extraFields = [ |
|
| 98 | - 'RelatedPages' => [ |
|
| 99 | - 'SortOrder' => 'Int', |
|
| 100 | - ], |
|
| 101 | - ]; |
|
| 102 | - |
|
| 103 | - private static $plural_name = 'Base Pages'; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Get the footer holder. |
|
| 107 | - */ |
|
| 108 | - public function getFooter() |
|
| 109 | - { |
|
| 110 | - return FooterHolder::get_one(FooterHolder::class); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - /** |
|
| 114 | - * Return the full filename of the pdf file, including path & extension |
|
| 115 | - */ |
|
| 116 | - public function getPdfFilename() |
|
| 117 | - { |
|
| 118 | - $baseName = sprintf('%s-%s', $this->URLSegment, $this->ID); |
|
| 119 | - |
|
| 120 | - $folderPath = $this->config()->get('generated_pdf_path'); |
|
| 121 | - if ($folderPath[0] != '/') { |
|
| 122 | - $folderPath = BASE_PATH . '/' . $folderPath; |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return sprintf('%s/%s.pdf', $folderPath, $baseName); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - /** |
|
| 129 | - * Build pdf link for template. |
|
| 130 | - */ |
|
| 131 | - public function PdfLink() |
|
| 132 | - { |
|
| 133 | - if (!$this->config()->get('pdf_export')) { |
|
| 134 | - return false; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - $path = $this->getPdfFilename(); |
|
| 138 | - |
|
| 139 | - if ((Versioned::get_stage() === Versioned::LIVE) && file_exists($path)) { |
|
| 140 | - return Director::baseURL() . preg_replace('#^/#', '', Director::makeRelative($path)); |
|
| 141 | - } |
|
| 142 | - return $this->Link('downloadpdf'); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - public function RelatedPages() |
|
| 146 | - { |
|
| 147 | - return $this->getManyManyComponents('RelatedPages')->sort('SortOrder'); |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - public function RelatedPagesTitle() |
|
| 151 | - { |
|
| 152 | - return $this->config()->get('related_pages_title'); |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - /** |
|
| 156 | - * Remove linked pdf when publishing the page, |
|
| 157 | - * as it would be out of date. |
|
| 158 | - */ |
|
| 159 | - public function onAfterPublish() |
|
| 160 | - { |
|
| 161 | - $filepath = $this->getPdfFilename(); |
|
| 162 | - if (file_exists($filepath)) { |
|
| 163 | - unlink($filepath); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - /** |
|
| 168 | - * Remove linked pdf when unpublishing the page, |
|
| 169 | - * so it's no longer valid. |
|
| 170 | - * |
|
| 171 | - * @return boolean |
|
| 172 | - */ |
|
| 173 | - public function doUnpublish() |
|
| 174 | - { |
|
| 175 | - if (!parent::doUnpublish()) { |
|
| 176 | - return false; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - $filepath = $this->getPdfFilename(); |
|
| 180 | - if (file_exists($filepath)) { |
|
| 181 | - unlink($filepath); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return true; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - public function getCMSFields() |
|
| 188 | - { |
|
| 189 | - $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 190 | - // Related Pages |
|
| 191 | - $components = GridFieldConfig_RelationEditor::create(); |
|
| 192 | - $components->removeComponentsByType(GridFieldAddNewButton::class); |
|
| 193 | - $components->removeComponentsByType(GridFieldEditButton::class); |
|
| 194 | - $components->removeComponentsByType(GridFieldFilterHeader::class); |
|
| 195 | - $components->addComponent(new GridFieldSortableRows('SortOrder')); |
|
| 196 | - |
|
| 197 | - /** @var GridFieldDataColumns $dataColumns */ |
|
| 198 | - $dataColumns = $components->getComponentByType(GridFieldDataColumns::class); |
|
| 199 | - $dataColumns->setDisplayFields([ |
|
| 200 | - 'Title' => _t(__CLASS__ . '.ColumnTitle', 'Title'), |
|
| 201 | - 'ClassName' => _t(__CLASS__ . '.ColumnPageType', 'Page Type') |
|
| 202 | - ]); |
|
| 203 | - |
|
| 204 | - $fields->findOrMakeTab( |
|
| 205 | - 'Root.RelatedPages', |
|
| 206 | - _t(__CLASS__ . '.RelatedPages', 'Related pages') |
|
| 207 | - ); |
|
| 208 | - $fields->addFieldToTab( |
|
| 209 | - 'Root.RelatedPages', |
|
| 210 | - GridField::create( |
|
| 211 | - 'RelatedPages', |
|
| 212 | - _t(__CLASS__ . '.RelatedPages', 'Related pages'), |
|
| 213 | - $this->RelatedPages(), |
|
| 214 | - $components |
|
| 215 | - ) |
|
| 216 | - ); |
|
| 217 | - |
|
| 218 | - // Taxonomies - Unless they have their own 'Tags' field (such as in Blog, etc) |
|
| 219 | - $hasMany = $this->hasMany(); |
|
| 220 | - $manyMany = $this->manyMany(); |
|
| 221 | - if (!isset($hasMany['Tags']) && !isset($manyMany['Tags'])) { |
|
| 222 | - $components = GridFieldConfig_RelationEditor::create(); |
|
| 223 | - $components->removeComponentsByType(GridFieldAddNewButton::class); |
|
| 224 | - $components->removeComponentsByType(GridFieldEditButton::class); |
|
| 225 | - |
|
| 226 | - /** @var GridFieldAddExistingAutocompleter $autoCompleter */ |
|
| 227 | - $autoCompleter = $components->getComponentByType(GridFieldAddExistingAutocompleter::class); |
|
| 228 | - $autoCompleter->setResultsFormat('$Name ($TaxonomyName)'); |
|
| 229 | - |
|
| 230 | - /** @var GridFieldDataColumns $dataColumns */ |
|
| 231 | - $dataColumns = $components->getComponentByType(GridFieldDataColumns::class); |
|
| 232 | - $dataColumns->setDisplayFields([ |
|
| 233 | - 'Name' => _t(__CLASS__ . '.Term', 'Term'), |
|
| 234 | - 'TaxonomyName' => _t(__CLASS__ . '.Taxonomy', 'Taxonomy') |
|
| 235 | - ]); |
|
| 236 | - |
|
| 237 | - $fields->findOrMakeTab('Root.Tags', _t(__CLASS__ . '.TagsTabTitle', 'Tags')); |
|
| 238 | - $fields->addFieldToTab( |
|
| 239 | - 'Root.Tags', |
|
| 240 | - TreeMultiselectField::create( |
|
| 241 | - 'Terms', |
|
| 242 | - _t(__CLASS__ . '.Terms', 'Terms'), |
|
| 243 | - TaxonomyTerm::class |
|
| 244 | - )->setDescription(_t(__CLASS__ . '.TermsDescription', 'Click to search for additional terms')) |
|
| 245 | - ); |
|
| 246 | - } |
|
| 247 | - }); |
|
| 248 | - return parent::getCMSFields(); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - /** |
|
| 252 | - * Provides data for translation navigation. |
|
| 253 | - * Collects all site translations, marks the current one, and redirects |
|
| 254 | - * to the translated home page if a. there is a translated homepage and b. the |
|
| 255 | - * translation of the specific page is not available. |
|
| 256 | - * @todo re-implement with Fluent |
|
| 257 | - */ |
|
| 258 | - public function getAvailableTranslations() |
|
| 259 | - { |
|
| 260 | - if (!class_exists('Translatable')) { |
|
| 261 | - return false; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $translations = new ArrayList(); |
|
| 265 | - $globalTranslations = Translatable::get_existing_content_languages(); |
|
| 266 | - |
|
| 267 | - foreach ($globalTranslations as $loc => $langName) { |
|
| 268 | - // Find out the language name in native language. |
|
| 269 | - $nativeLangName = i18n::get_language_name($loc, true); |
|
| 270 | - if (!$nativeLangName) { |
|
| 271 | - $nativeLangName = i18n::get_language_name(i18n::get_lang_from_locale($loc), true); |
|
| 272 | - } |
|
| 273 | - if (!$nativeLangName) { |
|
| 274 | - // Fall back to the locale name. |
|
| 275 | - $nativeLangName = $langName; |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - // Eliminate the part in brackets (e.g. [mandarin]) |
|
| 279 | - $nativeLangName = preg_replace('/ *[\(\[].*$/', '', $nativeLangName); |
|
| 280 | - |
|
| 281 | - // Find out the link to the translated page. |
|
| 282 | - $link = null; |
|
| 283 | - $page = $this->getTranslation($loc); |
|
| 284 | - if ($page) { |
|
| 285 | - $link = $page->Link(); |
|
| 286 | - } |
|
| 287 | - if (!$link) { |
|
| 288 | - // Fall back to the home page |
|
| 289 | - $link = Translatable::get_homepage_link_by_locale($loc); |
|
| 290 | - } |
|
| 291 | - if (!$link) { |
|
| 292 | - continue; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - // Assemble the table for the switcher. |
|
| 296 | - $translations->push(new ArrayData(array( |
|
| 297 | - 'Locale' => i18n::convert_rfc1766($loc), |
|
| 298 | - 'LangName' => $nativeLangName, |
|
| 299 | - 'Link' => $link, |
|
| 300 | - 'Current' => (Translatable::get_current_locale()==$loc) |
|
| 301 | - ))); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if ($translations->count()>1) { |
|
| 305 | - return $translations; |
|
| 306 | - } else { |
|
| 307 | - return null; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - /** |
|
| 312 | - * Returns the native language name for the selected locale/language, empty string if Translatable is not available |
|
| 313 | - * |
|
| 314 | - * @return string |
|
| 315 | - * @todo re-implement with Fluent |
|
| 316 | - */ |
|
| 317 | - public function getSelectedLanguage() |
|
| 318 | - { |
|
| 319 | - if (!class_exists('Translatable')) { |
|
| 320 | - return ''; |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - $language = explode('_', Translatable::get_current_locale()); |
|
| 324 | - $languageCode = array_shift($language); |
|
| 325 | - $nativeName = i18n::get_language_name($languageCode, true); |
|
| 326 | - |
|
| 327 | - return $nativeName; |
|
| 328 | - } |
|
| 31 | + private static $icon = 'cwp/cwp:images/icons/sitetree_images/page.png'; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Hide this page type from the CMS. hide_ancestor is slightly misnamed, should really be just "hide" |
|
| 35 | + * |
|
| 36 | + * {@inheritDoc} |
|
| 37 | + */ |
|
| 38 | + private static $hide_ancestor = BasePage::class; |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @config |
|
| 42 | + * @var bool |
|
| 43 | + */ |
|
| 44 | + private static $pdf_export = false; |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Domain to generate PDF's from, DOES not include protocol |
|
| 48 | + * i.e. google.com not http://google.com |
|
| 49 | + * @config |
|
| 50 | + * @var string |
|
| 51 | + */ |
|
| 52 | + private static $pdf_base_url = ""; |
|
| 53 | + |
|
| 54 | + /** |
|
| 55 | + * Allow custom overriding of the path to the WKHTMLTOPDF binary, in cases |
|
| 56 | + * where multiple versions of the binary are available to choose from. This |
|
| 57 | + * should be the full path to the binary (e.g. /usr/local/bin/wkhtmltopdf) |
|
| 58 | + * @see BasePage_Controller::generatePDF(); |
|
| 59 | + * |
|
| 60 | + * @config |
|
| 61 | + * @var string|null |
|
| 62 | + */ |
|
| 63 | + private static $wkhtmltopdf_binary = null; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Where to store generated PDF files |
|
| 67 | + * |
|
| 68 | + * @config |
|
| 69 | + * @var string |
|
| 70 | + */ |
|
| 71 | + private static $generated_pdf_path = 'assets/_generated_pdfs'; |
|
| 72 | + |
|
| 73 | + private static $api_access = [ |
|
| 74 | + 'view' => [ |
|
| 75 | + 'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription', |
|
| 76 | + 'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID' |
|
| 77 | + ], |
|
| 78 | + 'edit' => [ |
|
| 79 | + 'Locale', 'URLSegment', 'Title', 'MenuTitle', 'Content', 'MetaDescription', |
|
| 80 | + 'ExtraMenu', 'Sort', 'Version', 'ParentID', 'ID' |
|
| 81 | + ], |
|
| 82 | + ]; |
|
| 83 | + |
|
| 84 | + private static $table_name = 'BasePage'; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * @config |
|
| 88 | + * @var string |
|
| 89 | + */ |
|
| 90 | + private static $related_pages_title = 'Related pages'; |
|
| 91 | + |
|
| 92 | + private static $many_many = [ |
|
| 93 | + 'Terms' => TaxonomyTerm::class, |
|
| 94 | + 'RelatedPages' => BasePage::class, |
|
| 95 | + ]; |
|
| 96 | + |
|
| 97 | + private static $many_many_extraFields = [ |
|
| 98 | + 'RelatedPages' => [ |
|
| 99 | + 'SortOrder' => 'Int', |
|
| 100 | + ], |
|
| 101 | + ]; |
|
| 102 | + |
|
| 103 | + private static $plural_name = 'Base Pages'; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Get the footer holder. |
|
| 107 | + */ |
|
| 108 | + public function getFooter() |
|
| 109 | + { |
|
| 110 | + return FooterHolder::get_one(FooterHolder::class); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + /** |
|
| 114 | + * Return the full filename of the pdf file, including path & extension |
|
| 115 | + */ |
|
| 116 | + public function getPdfFilename() |
|
| 117 | + { |
|
| 118 | + $baseName = sprintf('%s-%s', $this->URLSegment, $this->ID); |
|
| 119 | + |
|
| 120 | + $folderPath = $this->config()->get('generated_pdf_path'); |
|
| 121 | + if ($folderPath[0] != '/') { |
|
| 122 | + $folderPath = BASE_PATH . '/' . $folderPath; |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return sprintf('%s/%s.pdf', $folderPath, $baseName); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + /** |
|
| 129 | + * Build pdf link for template. |
|
| 130 | + */ |
|
| 131 | + public function PdfLink() |
|
| 132 | + { |
|
| 133 | + if (!$this->config()->get('pdf_export')) { |
|
| 134 | + return false; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + $path = $this->getPdfFilename(); |
|
| 138 | + |
|
| 139 | + if ((Versioned::get_stage() === Versioned::LIVE) && file_exists($path)) { |
|
| 140 | + return Director::baseURL() . preg_replace('#^/#', '', Director::makeRelative($path)); |
|
| 141 | + } |
|
| 142 | + return $this->Link('downloadpdf'); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + public function RelatedPages() |
|
| 146 | + { |
|
| 147 | + return $this->getManyManyComponents('RelatedPages')->sort('SortOrder'); |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + public function RelatedPagesTitle() |
|
| 151 | + { |
|
| 152 | + return $this->config()->get('related_pages_title'); |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + /** |
|
| 156 | + * Remove linked pdf when publishing the page, |
|
| 157 | + * as it would be out of date. |
|
| 158 | + */ |
|
| 159 | + public function onAfterPublish() |
|
| 160 | + { |
|
| 161 | + $filepath = $this->getPdfFilename(); |
|
| 162 | + if (file_exists($filepath)) { |
|
| 163 | + unlink($filepath); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + /** |
|
| 168 | + * Remove linked pdf when unpublishing the page, |
|
| 169 | + * so it's no longer valid. |
|
| 170 | + * |
|
| 171 | + * @return boolean |
|
| 172 | + */ |
|
| 173 | + public function doUnpublish() |
|
| 174 | + { |
|
| 175 | + if (!parent::doUnpublish()) { |
|
| 176 | + return false; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + $filepath = $this->getPdfFilename(); |
|
| 180 | + if (file_exists($filepath)) { |
|
| 181 | + unlink($filepath); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return true; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + public function getCMSFields() |
|
| 188 | + { |
|
| 189 | + $this->beforeUpdateCMSFields(function (FieldList $fields) { |
|
| 190 | + // Related Pages |
|
| 191 | + $components = GridFieldConfig_RelationEditor::create(); |
|
| 192 | + $components->removeComponentsByType(GridFieldAddNewButton::class); |
|
| 193 | + $components->removeComponentsByType(GridFieldEditButton::class); |
|
| 194 | + $components->removeComponentsByType(GridFieldFilterHeader::class); |
|
| 195 | + $components->addComponent(new GridFieldSortableRows('SortOrder')); |
|
| 196 | + |
|
| 197 | + /** @var GridFieldDataColumns $dataColumns */ |
|
| 198 | + $dataColumns = $components->getComponentByType(GridFieldDataColumns::class); |
|
| 199 | + $dataColumns->setDisplayFields([ |
|
| 200 | + 'Title' => _t(__CLASS__ . '.ColumnTitle', 'Title'), |
|
| 201 | + 'ClassName' => _t(__CLASS__ . '.ColumnPageType', 'Page Type') |
|
| 202 | + ]); |
|
| 203 | + |
|
| 204 | + $fields->findOrMakeTab( |
|
| 205 | + 'Root.RelatedPages', |
|
| 206 | + _t(__CLASS__ . '.RelatedPages', 'Related pages') |
|
| 207 | + ); |
|
| 208 | + $fields->addFieldToTab( |
|
| 209 | + 'Root.RelatedPages', |
|
| 210 | + GridField::create( |
|
| 211 | + 'RelatedPages', |
|
| 212 | + _t(__CLASS__ . '.RelatedPages', 'Related pages'), |
|
| 213 | + $this->RelatedPages(), |
|
| 214 | + $components |
|
| 215 | + ) |
|
| 216 | + ); |
|
| 217 | + |
|
| 218 | + // Taxonomies - Unless they have their own 'Tags' field (such as in Blog, etc) |
|
| 219 | + $hasMany = $this->hasMany(); |
|
| 220 | + $manyMany = $this->manyMany(); |
|
| 221 | + if (!isset($hasMany['Tags']) && !isset($manyMany['Tags'])) { |
|
| 222 | + $components = GridFieldConfig_RelationEditor::create(); |
|
| 223 | + $components->removeComponentsByType(GridFieldAddNewButton::class); |
|
| 224 | + $components->removeComponentsByType(GridFieldEditButton::class); |
|
| 225 | + |
|
| 226 | + /** @var GridFieldAddExistingAutocompleter $autoCompleter */ |
|
| 227 | + $autoCompleter = $components->getComponentByType(GridFieldAddExistingAutocompleter::class); |
|
| 228 | + $autoCompleter->setResultsFormat('$Name ($TaxonomyName)'); |
|
| 229 | + |
|
| 230 | + /** @var GridFieldDataColumns $dataColumns */ |
|
| 231 | + $dataColumns = $components->getComponentByType(GridFieldDataColumns::class); |
|
| 232 | + $dataColumns->setDisplayFields([ |
|
| 233 | + 'Name' => _t(__CLASS__ . '.Term', 'Term'), |
|
| 234 | + 'TaxonomyName' => _t(__CLASS__ . '.Taxonomy', 'Taxonomy') |
|
| 235 | + ]); |
|
| 236 | + |
|
| 237 | + $fields->findOrMakeTab('Root.Tags', _t(__CLASS__ . '.TagsTabTitle', 'Tags')); |
|
| 238 | + $fields->addFieldToTab( |
|
| 239 | + 'Root.Tags', |
|
| 240 | + TreeMultiselectField::create( |
|
| 241 | + 'Terms', |
|
| 242 | + _t(__CLASS__ . '.Terms', 'Terms'), |
|
| 243 | + TaxonomyTerm::class |
|
| 244 | + )->setDescription(_t(__CLASS__ . '.TermsDescription', 'Click to search for additional terms')) |
|
| 245 | + ); |
|
| 246 | + } |
|
| 247 | + }); |
|
| 248 | + return parent::getCMSFields(); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + /** |
|
| 252 | + * Provides data for translation navigation. |
|
| 253 | + * Collects all site translations, marks the current one, and redirects |
|
| 254 | + * to the translated home page if a. there is a translated homepage and b. the |
|
| 255 | + * translation of the specific page is not available. |
|
| 256 | + * @todo re-implement with Fluent |
|
| 257 | + */ |
|
| 258 | + public function getAvailableTranslations() |
|
| 259 | + { |
|
| 260 | + if (!class_exists('Translatable')) { |
|
| 261 | + return false; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $translations = new ArrayList(); |
|
| 265 | + $globalTranslations = Translatable::get_existing_content_languages(); |
|
| 266 | + |
|
| 267 | + foreach ($globalTranslations as $loc => $langName) { |
|
| 268 | + // Find out the language name in native language. |
|
| 269 | + $nativeLangName = i18n::get_language_name($loc, true); |
|
| 270 | + if (!$nativeLangName) { |
|
| 271 | + $nativeLangName = i18n::get_language_name(i18n::get_lang_from_locale($loc), true); |
|
| 272 | + } |
|
| 273 | + if (!$nativeLangName) { |
|
| 274 | + // Fall back to the locale name. |
|
| 275 | + $nativeLangName = $langName; |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + // Eliminate the part in brackets (e.g. [mandarin]) |
|
| 279 | + $nativeLangName = preg_replace('/ *[\(\[].*$/', '', $nativeLangName); |
|
| 280 | + |
|
| 281 | + // Find out the link to the translated page. |
|
| 282 | + $link = null; |
|
| 283 | + $page = $this->getTranslation($loc); |
|
| 284 | + if ($page) { |
|
| 285 | + $link = $page->Link(); |
|
| 286 | + } |
|
| 287 | + if (!$link) { |
|
| 288 | + // Fall back to the home page |
|
| 289 | + $link = Translatable::get_homepage_link_by_locale($loc); |
|
| 290 | + } |
|
| 291 | + if (!$link) { |
|
| 292 | + continue; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + // Assemble the table for the switcher. |
|
| 296 | + $translations->push(new ArrayData(array( |
|
| 297 | + 'Locale' => i18n::convert_rfc1766($loc), |
|
| 298 | + 'LangName' => $nativeLangName, |
|
| 299 | + 'Link' => $link, |
|
| 300 | + 'Current' => (Translatable::get_current_locale()==$loc) |
|
| 301 | + ))); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if ($translations->count()>1) { |
|
| 305 | + return $translations; |
|
| 306 | + } else { |
|
| 307 | + return null; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + /** |
|
| 312 | + * Returns the native language name for the selected locale/language, empty string if Translatable is not available |
|
| 313 | + * |
|
| 314 | + * @return string |
|
| 315 | + * @todo re-implement with Fluent |
|
| 316 | + */ |
|
| 317 | + public function getSelectedLanguage() |
|
| 318 | + { |
|
| 319 | + if (!class_exists('Translatable')) { |
|
| 320 | + return ''; |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + $language = explode('_', Translatable::get_current_locale()); |
|
| 324 | + $languageCode = array_shift($language); |
|
| 325 | + $nativeName = i18n::get_language_name($languageCode, true); |
|
| 326 | + |
|
| 327 | + return $nativeName; |
|
| 328 | + } |
|
| 329 | 329 | } |
@@ -6,20 +6,20 @@ |
||
| 6 | 6 | |
| 7 | 7 | class BaseHomePageController extends PageController |
| 8 | 8 | { |
| 9 | - public function getNewsPage() |
|
| 10 | - { |
|
| 11 | - return NewsHolder::get_one(NewsHolder::class); |
|
| 12 | - } |
|
| 9 | + public function getNewsPage() |
|
| 10 | + { |
|
| 11 | + return NewsHolder::get_one(NewsHolder::class); |
|
| 12 | + } |
|
| 13 | 13 | |
| 14 | - /** |
|
| 15 | - * @param int $amount The amount of items to provide. |
|
| 16 | - */ |
|
| 17 | - public function getNewsItems($amount = 2) |
|
| 18 | - { |
|
| 19 | - $newsHolder = $this->getNewsPage(); |
|
| 20 | - if ($newsHolder) { |
|
| 21 | - $controller = NewsHolderController::create($newsHolder); |
|
| 22 | - return $controller->Updates()->limit($amount); |
|
| 23 | - } |
|
| 24 | - } |
|
| 14 | + /** |
|
| 15 | + * @param int $amount The amount of items to provide. |
|
| 16 | + */ |
|
| 17 | + public function getNewsItems($amount = 2) |
|
| 18 | + { |
|
| 19 | + $newsHolder = $this->getNewsPage(); |
|
| 20 | + if ($newsHolder) { |
|
| 21 | + $controller = NewsHolderController::create($newsHolder); |
|
| 22 | + return $controller->Updates()->limit($amount); |
|
| 23 | + } |
|
| 24 | + } |
|
| 25 | 25 | } |
@@ -17,247 +17,247 @@ |
||
| 17 | 17 | |
| 18 | 18 | class DatedUpdateHolder extends Page |
| 19 | 19 | { |
| 20 | - /** |
|
| 21 | - * Meant as an abstract base class. |
|
| 22 | - * |
|
| 23 | - * {@inheritDoc} |
|
| 24 | - */ |
|
| 25 | - private static $hide_ancestor = DatedUpdateHolder::class; |
|
| 26 | - |
|
| 27 | - private static $update_name = 'Updates'; |
|
| 28 | - |
|
| 29 | - private static $update_class = DatedUpdatePage::class; |
|
| 30 | - |
|
| 31 | - private static $singular_name = 'Dated Update Holder'; |
|
| 32 | - |
|
| 33 | - private static $plural_name = 'Dated Update Holders'; |
|
| 34 | - |
|
| 35 | - private static $table_name = 'DatedUpdateHolder'; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * Find all distinct tags (TaxonomyTerms) associated with the DatedUpdatePages under this holder. |
|
| 39 | - */ |
|
| 40 | - public function UpdateTags() |
|
| 41 | - { |
|
| 42 | - $siteTree = DataObject::getSchema()->tableName(SiteTree::class); |
|
| 43 | - $taxonomy = DataObject::getSchema()->tableName(TaxonomyTerm::class); |
|
| 44 | - |
|
| 45 | - $tags = TaxonomyTerm::get() |
|
| 46 | - ->innerJoin('BasePage_Terms', sprintf('"%s"."ID"="BasePage_Terms"."TaxonomyTermID"', $taxonomy)) |
|
| 47 | - ->innerJoin( |
|
| 48 | - $siteTree, |
|
| 49 | - sprintf( |
|
| 50 | - '"%s"."ID" = "BasePage_Terms"."BasePageID" AND "%s"."ParentID" = \'%d\'', |
|
| 51 | - $siteTree, |
|
| 52 | - $siteTree, |
|
| 53 | - $this->ID |
|
| 54 | - ) |
|
| 55 | - ) |
|
| 56 | - ->sort('Name'); |
|
| 57 | - |
|
| 58 | - return $tags; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Wrapper to find all updates belonging to this holder, based on some filters. |
|
| 63 | - */ |
|
| 64 | - public function Updates($tagID = null, $dateFrom = null, $dateTo = null, $year = null, $monthNumber = null) |
|
| 65 | - { |
|
| 66 | - $className = Config::inst()->get($this->ClassName, 'update_class'); |
|
| 67 | - return static::AllUpdates($className, $this->ID, $tagID, $dateFrom, $dateTo, $year, $monthNumber); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - /** |
|
| 71 | - * Find all site's updates, based on some filters. |
|
| 72 | - * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
| 73 | - * |
|
| 74 | - * @param string $className The name of the class to fetch. |
|
| 75 | - * @param int|null $parentID The ID of the holder to extract the updates from. |
|
| 76 | - * @param int|null $tagID The ID of the tag to filter the updates by. |
|
| 77 | - * @param string|null $dateFrom The beginning of a date filter range. |
|
| 78 | - * @param string|null $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
| 79 | - * @param int|null $year Numeric value of the year to show. |
|
| 80 | - * @param int|null $monthNumber Numeric value of the month to show. |
|
| 81 | - * |
|
| 82 | - * @returns DataList | PaginatedList |
|
| 83 | - */ |
|
| 84 | - public static function AllUpdates( |
|
| 85 | - $className = DatedUpdatePage::class, |
|
| 86 | - $parentID = null, |
|
| 87 | - $tagID = null, |
|
| 88 | - $dateFrom = null, |
|
| 89 | - $dateTo = null, |
|
| 90 | - $year = null, |
|
| 91 | - $monthNumber = null |
|
| 92 | - ) { |
|
| 93 | - |
|
| 94 | - $items = $className::get(); |
|
| 95 | - $dbTableName = DataObject::getSchema()->tableForField($className, 'Date'); |
|
| 96 | - if (!$dbTableName) { |
|
| 97 | - $dbTableName = DatedUpdatePage::class; |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // Filter by parent holder. |
|
| 101 | - if (isset($parentID)) { |
|
| 102 | - $items = $items->filter(['ParentID'=>$parentID]); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // Filter down to a single tag. |
|
| 106 | - if (isset($tagID)) { |
|
| 107 | - $taxonomy = DataObject::getSchema()->tableName(TaxonomyTerm::class); |
|
| 108 | - $tableName = DataObject::getSchema()->tableName($className); |
|
| 109 | - |
|
| 110 | - $items = $items->innerJoin( |
|
| 111 | - 'BasePage_Terms', |
|
| 112 | - sprintf('"%s"."ID" = "BasePage_Terms"."BasePageID"', $tableName) |
|
| 113 | - )->innerJoin( |
|
| 114 | - $taxonomy, |
|
| 115 | - sprintf( |
|
| 116 | - '"BasePage_Terms"."TaxonomyTermID" = "%s"."ID" AND "TaxonomyTerm"."ID" = \'%d\'', |
|
| 117 | - $taxonomy, |
|
| 118 | - $tagID |
|
| 119 | - ) |
|
| 120 | - ); |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - // Filter by date |
|
| 124 | - if (isset($dateFrom)) { |
|
| 125 | - if (!isset($dateTo)) { |
|
| 126 | - $dateTo = $dateFrom; |
|
| 127 | - } |
|
| 128 | - |
|
| 129 | - $items = $items->where([ |
|
| 130 | - sprintf('"%s"."Date" >= \'%s\'', $dbTableName, Convert::raw2sql("$dateFrom 00:00:00")), |
|
| 131 | - sprintf('"%s"."Date" <= \'%s\'', $dbTableName, Convert::raw2sql("$dateTo 23:59:59")) |
|
| 132 | - ]); |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // Filter down to single month. |
|
| 136 | - if (isset($year) && isset($monthNumber)) { |
|
| 137 | - $year = (int)$year; |
|
| 138 | - $monthNumber = (int)$monthNumber; |
|
| 139 | - |
|
| 140 | - $beginDate = sprintf("%04d-%02d-01 00:00:00", $year, $monthNumber); |
|
| 141 | - $endDate = date('Y-m-d H:i:s', strtotime("{$beginDate} +1 month")); |
|
| 142 | - |
|
| 143 | - $items = $items->where(array( |
|
| 144 | - sprintf('"%s"."Date" >= \'%s\'', $dbTableName, Convert::raw2sql($beginDate)), |
|
| 145 | - sprintf('"%s"."Date" < \'%s\'', $dbTableName, Convert::raw2sql($endDate)) |
|
| 146 | - )); |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - // Unpaginated DataList. |
|
| 150 | - return $items; |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - /** |
|
| 154 | - * Produce an ArrayList of available months out of the updates contained in the DataList. |
|
| 155 | - * |
|
| 156 | - * Here is an example of the returned structure: |
|
| 157 | - * ArrayList: |
|
| 158 | - * ArrayData: |
|
| 159 | - * YearName => 2013 |
|
| 160 | - * Months => ArrayList: |
|
| 161 | - * MonthName => Jan |
|
| 162 | - * MonthNumber => 1 |
|
| 163 | - * MonthLink => (page URL)year=2012&month=1 |
|
| 164 | - * Active => true |
|
| 165 | - * ArrayData: |
|
| 166 | - * YearName => 2012 |
|
| 167 | - * Months => ArrayList: |
|
| 168 | - * ... |
|
| 169 | - * |
|
| 170 | - * @param DataList $updates DataList DataList to extract months from. |
|
| 171 | - * @param string $link Link used as abase to construct the MonthLink. |
|
| 172 | - * @param int $currentYear Currently selected year, for computing the link active state. |
|
| 173 | - * @param int $currentMonthNumber Currently selected month, for computing the link active state. |
|
| 174 | - * |
|
| 175 | - * @returns ArrayList |
|
| 176 | - */ |
|
| 177 | - public static function ExtractMonths( |
|
| 178 | - DataList $updates, |
|
| 179 | - $link = null, |
|
| 180 | - $currentYear = null, |
|
| 181 | - $currentMonthNumber = null |
|
| 182 | - ) { |
|
| 183 | - // Set the link to current URL in the same way the HTTP::setGetVar does it. |
|
| 184 | - if (!isset($link)) { |
|
| 185 | - $link = Director::makeRelative($_SERVER['REQUEST_URI']); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - $dates = $updates->dataQuery() |
|
| 189 | - ->groupby('YEAR("Date")') |
|
| 190 | - ->groupby('MONTH("Date")') |
|
| 191 | - ->query() |
|
| 192 | - ->setSelect([ |
|
| 193 | - 'Year' => 'YEAR("Date")', |
|
| 194 | - 'Month' => 'MONTH("Date")', |
|
| 195 | - ]) |
|
| 196 | - ->addWhere('"Date" IS NOT NULL') |
|
| 197 | - ->setOrderBy([ |
|
| 198 | - 'YEAR("Date")' => 'DESC', |
|
| 199 | - 'MONTH("Date")' => 'DESC', |
|
| 200 | - ]) |
|
| 201 | - ->execute(); |
|
| 202 | - |
|
| 203 | - $years = []; |
|
| 204 | - foreach ($dates as $date) { |
|
| 205 | - $monthNumber = $date['Month']; |
|
| 206 | - $year = $date['Year']; |
|
| 207 | - $dateObj = new DateTime(implode('-', [$year, $monthNumber, 1])); |
|
| 208 | - $monthName = $dateObj->Format('M'); |
|
| 209 | - |
|
| 210 | - // Set up the relevant year array, if not yet available. |
|
| 211 | - if (!isset($years[$year])) { |
|
| 212 | - $years[$year] = ['YearName'=>$year, 'Months' => []]; |
|
| 213 | - } |
|
| 214 | - |
|
| 215 | - // Check if the currently processed month is the one that is selected via GET params. |
|
| 216 | - $active = false; |
|
| 217 | - if (isset($year) && isset($monthNumber)) { |
|
| 218 | - $active = (((int)$currentYear)==$year && ((int)$currentMonthNumber)==$monthNumber); |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - // Build the link - keep the tag and date filter, but reset the pagination. |
|
| 222 | - if ($active) { |
|
| 223 | - // Allow clicking to deselect the month. |
|
| 224 | - $link = HTTP::setGetVar('month', null, $link, '&'); |
|
| 225 | - $link = HTTP::setGetVar('year', null, $link, '&'); |
|
| 226 | - } else { |
|
| 227 | - $link = HTTP::setGetVar('month', $monthNumber, $link, '&'); |
|
| 228 | - $link = HTTP::setGetVar('year', $year, $link, '&'); |
|
| 229 | - } |
|
| 230 | - $link = HTTP::setGetVar('start', null, $link, '&'); |
|
| 231 | - |
|
| 232 | - $years[$year]['Months'][$monthNumber] = array( |
|
| 233 | - 'MonthName'=>$monthName, |
|
| 234 | - 'MonthNumber'=>$monthNumber, |
|
| 235 | - 'MonthLink'=>$link, |
|
| 236 | - 'Active'=>$active |
|
| 237 | - ); |
|
| 238 | - } |
|
| 239 | - |
|
| 240 | - // ArrayList will not recursively walk through the supplied array, so manually build nested ArrayLists. |
|
| 241 | - foreach ($years as &$year) { |
|
| 242 | - $year['Months'] = new ArrayList($year['Months']); |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - // Reverse the list so the most recent years appear first. |
|
| 246 | - return new ArrayList($years); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - public function getDefaultRSSLink() |
|
| 250 | - { |
|
| 251 | - return $this->Link('rss'); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - public function getDefaultAtomLink() |
|
| 255 | - { |
|
| 256 | - return $this->Link('atom'); |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - public function getSubscriptionTitle() |
|
| 260 | - { |
|
| 261 | - return $this->Title; |
|
| 262 | - } |
|
| 20 | + /** |
|
| 21 | + * Meant as an abstract base class. |
|
| 22 | + * |
|
| 23 | + * {@inheritDoc} |
|
| 24 | + */ |
|
| 25 | + private static $hide_ancestor = DatedUpdateHolder::class; |
|
| 26 | + |
|
| 27 | + private static $update_name = 'Updates'; |
|
| 28 | + |
|
| 29 | + private static $update_class = DatedUpdatePage::class; |
|
| 30 | + |
|
| 31 | + private static $singular_name = 'Dated Update Holder'; |
|
| 32 | + |
|
| 33 | + private static $plural_name = 'Dated Update Holders'; |
|
| 34 | + |
|
| 35 | + private static $table_name = 'DatedUpdateHolder'; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * Find all distinct tags (TaxonomyTerms) associated with the DatedUpdatePages under this holder. |
|
| 39 | + */ |
|
| 40 | + public function UpdateTags() |
|
| 41 | + { |
|
| 42 | + $siteTree = DataObject::getSchema()->tableName(SiteTree::class); |
|
| 43 | + $taxonomy = DataObject::getSchema()->tableName(TaxonomyTerm::class); |
|
| 44 | + |
|
| 45 | + $tags = TaxonomyTerm::get() |
|
| 46 | + ->innerJoin('BasePage_Terms', sprintf('"%s"."ID"="BasePage_Terms"."TaxonomyTermID"', $taxonomy)) |
|
| 47 | + ->innerJoin( |
|
| 48 | + $siteTree, |
|
| 49 | + sprintf( |
|
| 50 | + '"%s"."ID" = "BasePage_Terms"."BasePageID" AND "%s"."ParentID" = \'%d\'', |
|
| 51 | + $siteTree, |
|
| 52 | + $siteTree, |
|
| 53 | + $this->ID |
|
| 54 | + ) |
|
| 55 | + ) |
|
| 56 | + ->sort('Name'); |
|
| 57 | + |
|
| 58 | + return $tags; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Wrapper to find all updates belonging to this holder, based on some filters. |
|
| 63 | + */ |
|
| 64 | + public function Updates($tagID = null, $dateFrom = null, $dateTo = null, $year = null, $monthNumber = null) |
|
| 65 | + { |
|
| 66 | + $className = Config::inst()->get($this->ClassName, 'update_class'); |
|
| 67 | + return static::AllUpdates($className, $this->ID, $tagID, $dateFrom, $dateTo, $year, $monthNumber); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + /** |
|
| 71 | + * Find all site's updates, based on some filters. |
|
| 72 | + * Omitting parameters will prevent relevant filters from being applied. The filters are ANDed together. |
|
| 73 | + * |
|
| 74 | + * @param string $className The name of the class to fetch. |
|
| 75 | + * @param int|null $parentID The ID of the holder to extract the updates from. |
|
| 76 | + * @param int|null $tagID The ID of the tag to filter the updates by. |
|
| 77 | + * @param string|null $dateFrom The beginning of a date filter range. |
|
| 78 | + * @param string|null $dateTo The end of the date filter range. If empty, only one day will be searched for. |
|
| 79 | + * @param int|null $year Numeric value of the year to show. |
|
| 80 | + * @param int|null $monthNumber Numeric value of the month to show. |
|
| 81 | + * |
|
| 82 | + * @returns DataList | PaginatedList |
|
| 83 | + */ |
|
| 84 | + public static function AllUpdates( |
|
| 85 | + $className = DatedUpdatePage::class, |
|
| 86 | + $parentID = null, |
|
| 87 | + $tagID = null, |
|
| 88 | + $dateFrom = null, |
|
| 89 | + $dateTo = null, |
|
| 90 | + $year = null, |
|
| 91 | + $monthNumber = null |
|
| 92 | + ) { |
|
| 93 | + |
|
| 94 | + $items = $className::get(); |
|
| 95 | + $dbTableName = DataObject::getSchema()->tableForField($className, 'Date'); |
|
| 96 | + if (!$dbTableName) { |
|
| 97 | + $dbTableName = DatedUpdatePage::class; |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // Filter by parent holder. |
|
| 101 | + if (isset($parentID)) { |
|
| 102 | + $items = $items->filter(['ParentID'=>$parentID]); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // Filter down to a single tag. |
|
| 106 | + if (isset($tagID)) { |
|
| 107 | + $taxonomy = DataObject::getSchema()->tableName(TaxonomyTerm::class); |
|
| 108 | + $tableName = DataObject::getSchema()->tableName($className); |
|
| 109 | + |
|
| 110 | + $items = $items->innerJoin( |
|
| 111 | + 'BasePage_Terms', |
|
| 112 | + sprintf('"%s"."ID" = "BasePage_Terms"."BasePageID"', $tableName) |
|
| 113 | + )->innerJoin( |
|
| 114 | + $taxonomy, |
|
| 115 | + sprintf( |
|
| 116 | + '"BasePage_Terms"."TaxonomyTermID" = "%s"."ID" AND "TaxonomyTerm"."ID" = \'%d\'', |
|
| 117 | + $taxonomy, |
|
| 118 | + $tagID |
|
| 119 | + ) |
|
| 120 | + ); |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + // Filter by date |
|
| 124 | + if (isset($dateFrom)) { |
|
| 125 | + if (!isset($dateTo)) { |
|
| 126 | + $dateTo = $dateFrom; |
|
| 127 | + } |
|
| 128 | + |
|
| 129 | + $items = $items->where([ |
|
| 130 | + sprintf('"%s"."Date" >= \'%s\'', $dbTableName, Convert::raw2sql("$dateFrom 00:00:00")), |
|
| 131 | + sprintf('"%s"."Date" <= \'%s\'', $dbTableName, Convert::raw2sql("$dateTo 23:59:59")) |
|
| 132 | + ]); |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // Filter down to single month. |
|
| 136 | + if (isset($year) && isset($monthNumber)) { |
|
| 137 | + $year = (int)$year; |
|
| 138 | + $monthNumber = (int)$monthNumber; |
|
| 139 | + |
|
| 140 | + $beginDate = sprintf("%04d-%02d-01 00:00:00", $year, $monthNumber); |
|
| 141 | + $endDate = date('Y-m-d H:i:s', strtotime("{$beginDate} +1 month")); |
|
| 142 | + |
|
| 143 | + $items = $items->where(array( |
|
| 144 | + sprintf('"%s"."Date" >= \'%s\'', $dbTableName, Convert::raw2sql($beginDate)), |
|
| 145 | + sprintf('"%s"."Date" < \'%s\'', $dbTableName, Convert::raw2sql($endDate)) |
|
| 146 | + )); |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + // Unpaginated DataList. |
|
| 150 | + return $items; |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + /** |
|
| 154 | + * Produce an ArrayList of available months out of the updates contained in the DataList. |
|
| 155 | + * |
|
| 156 | + * Here is an example of the returned structure: |
|
| 157 | + * ArrayList: |
|
| 158 | + * ArrayData: |
|
| 159 | + * YearName => 2013 |
|
| 160 | + * Months => ArrayList: |
|
| 161 | + * MonthName => Jan |
|
| 162 | + * MonthNumber => 1 |
|
| 163 | + * MonthLink => (page URL)year=2012&month=1 |
|
| 164 | + * Active => true |
|
| 165 | + * ArrayData: |
|
| 166 | + * YearName => 2012 |
|
| 167 | + * Months => ArrayList: |
|
| 168 | + * ... |
|
| 169 | + * |
|
| 170 | + * @param DataList $updates DataList DataList to extract months from. |
|
| 171 | + * @param string $link Link used as abase to construct the MonthLink. |
|
| 172 | + * @param int $currentYear Currently selected year, for computing the link active state. |
|
| 173 | + * @param int $currentMonthNumber Currently selected month, for computing the link active state. |
|
| 174 | + * |
|
| 175 | + * @returns ArrayList |
|
| 176 | + */ |
|
| 177 | + public static function ExtractMonths( |
|
| 178 | + DataList $updates, |
|
| 179 | + $link = null, |
|
| 180 | + $currentYear = null, |
|
| 181 | + $currentMonthNumber = null |
|
| 182 | + ) { |
|
| 183 | + // Set the link to current URL in the same way the HTTP::setGetVar does it. |
|
| 184 | + if (!isset($link)) { |
|
| 185 | + $link = Director::makeRelative($_SERVER['REQUEST_URI']); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + $dates = $updates->dataQuery() |
|
| 189 | + ->groupby('YEAR("Date")') |
|
| 190 | + ->groupby('MONTH("Date")') |
|
| 191 | + ->query() |
|
| 192 | + ->setSelect([ |
|
| 193 | + 'Year' => 'YEAR("Date")', |
|
| 194 | + 'Month' => 'MONTH("Date")', |
|
| 195 | + ]) |
|
| 196 | + ->addWhere('"Date" IS NOT NULL') |
|
| 197 | + ->setOrderBy([ |
|
| 198 | + 'YEAR("Date")' => 'DESC', |
|
| 199 | + 'MONTH("Date")' => 'DESC', |
|
| 200 | + ]) |
|
| 201 | + ->execute(); |
|
| 202 | + |
|
| 203 | + $years = []; |
|
| 204 | + foreach ($dates as $date) { |
|
| 205 | + $monthNumber = $date['Month']; |
|
| 206 | + $year = $date['Year']; |
|
| 207 | + $dateObj = new DateTime(implode('-', [$year, $monthNumber, 1])); |
|
| 208 | + $monthName = $dateObj->Format('M'); |
|
| 209 | + |
|
| 210 | + // Set up the relevant year array, if not yet available. |
|
| 211 | + if (!isset($years[$year])) { |
|
| 212 | + $years[$year] = ['YearName'=>$year, 'Months' => []]; |
|
| 213 | + } |
|
| 214 | + |
|
| 215 | + // Check if the currently processed month is the one that is selected via GET params. |
|
| 216 | + $active = false; |
|
| 217 | + if (isset($year) && isset($monthNumber)) { |
|
| 218 | + $active = (((int)$currentYear)==$year && ((int)$currentMonthNumber)==$monthNumber); |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + // Build the link - keep the tag and date filter, but reset the pagination. |
|
| 222 | + if ($active) { |
|
| 223 | + // Allow clicking to deselect the month. |
|
| 224 | + $link = HTTP::setGetVar('month', null, $link, '&'); |
|
| 225 | + $link = HTTP::setGetVar('year', null, $link, '&'); |
|
| 226 | + } else { |
|
| 227 | + $link = HTTP::setGetVar('month', $monthNumber, $link, '&'); |
|
| 228 | + $link = HTTP::setGetVar('year', $year, $link, '&'); |
|
| 229 | + } |
|
| 230 | + $link = HTTP::setGetVar('start', null, $link, '&'); |
|
| 231 | + |
|
| 232 | + $years[$year]['Months'][$monthNumber] = array( |
|
| 233 | + 'MonthName'=>$monthName, |
|
| 234 | + 'MonthNumber'=>$monthNumber, |
|
| 235 | + 'MonthLink'=>$link, |
|
| 236 | + 'Active'=>$active |
|
| 237 | + ); |
|
| 238 | + } |
|
| 239 | + |
|
| 240 | + // ArrayList will not recursively walk through the supplied array, so manually build nested ArrayLists. |
|
| 241 | + foreach ($years as &$year) { |
|
| 242 | + $year['Months'] = new ArrayList($year['Months']); |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + // Reverse the list so the most recent years appear first. |
|
| 246 | + return new ArrayList($years); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + public function getDefaultRSSLink() |
|
| 250 | + { |
|
| 251 | + return $this->Link('rss'); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + public function getDefaultAtomLink() |
|
| 255 | + { |
|
| 256 | + return $this->Link('atom'); |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + public function getSubscriptionTitle() |
|
| 260 | + { |
|
| 261 | + return $this->Title; |
|
| 262 | + } |
|
| 263 | 263 | } |
@@ -134,8 +134,8 @@ discard block |
||
| 134 | 134 | |
| 135 | 135 | // Filter down to single month. |
| 136 | 136 | if (isset($year) && isset($monthNumber)) { |
| 137 | - $year = (int)$year; |
|
| 138 | - $monthNumber = (int)$monthNumber; |
|
| 137 | + $year = (int) $year; |
|
| 138 | + $monthNumber = (int) $monthNumber; |
|
| 139 | 139 | |
| 140 | 140 | $beginDate = sprintf("%04d-%02d-01 00:00:00", $year, $monthNumber); |
| 141 | 141 | $endDate = date('Y-m-d H:i:s', strtotime("{$beginDate} +1 month")); |
@@ -215,7 +215,7 @@ discard block |
||
| 215 | 215 | // Check if the currently processed month is the one that is selected via GET params. |
| 216 | 216 | $active = false; |
| 217 | 217 | if (isset($year) && isset($monthNumber)) { |
| 218 | - $active = (((int)$currentYear)==$year && ((int)$currentMonthNumber)==$monthNumber); |
|
| 218 | + $active = (((int) $currentYear) == $year && ((int) $currentMonthNumber) == $monthNumber); |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | // Build the link - keep the tag and date filter, but reset the pagination. |