Permalink
Browse files

FEATURE: Users can select to file by year, year/month, year/month/day…

…. Existing holders will still use year/month/day, until the user changes the setting
  • Loading branch information...
1 parent acda46b commit d35a8b66eb471868e1fc9d6c200d046a885d5010 @nyeholt committed Oct 2, 2011
Showing with 40 additions and 4 deletions.
  1. +6 −0 CHANGELOG
  2. +1 −1 VERSION
  3. +1 −1 code/pages/NewsArticle.php
  4. +32 −2 code/pages/NewsHolder.php
View
@@ -1,3 +1,9 @@
+
+2011-10-03 v1.1.0
+-----------------
+
+* Allow users to select whether to file by year, year/month, or year/month/day
+
2011-07-26 v1.0.0
-----------------
View
@@ -1 +1 @@
-1.0.0
+1.1.0
@@ -75,7 +75,7 @@ public function onBeforeWrite() {
$newlyCreated = $section->ID == $parent->ID;
$changedPublishDate = $this->isChanged('OriginalPublishedDate', 2);
- if (($changedPublishDate || $newlyCreated) && $section->AutoFiling) {
+ if (($changedPublishDate || $newlyCreated) && ($section->AutoFiling || $section->FilingMode)) {
if (!$this->Created) {
$this->Created = date('Y-m-d H:i:s');
}
View
@@ -11,12 +11,16 @@ class NewsHolder extends Page {
public static $db = array(
'AutoFiling' => 'Boolean', // whether articles created in this holder
// automatically file into subfolders
+ 'FilingMode' => 'Varchar', // Date, Month, Year
'FileBy' => "Enum('Published,Created','Created')",
'PrimaryNewsSection' => 'Boolean', // whether this holder should be regarded as a primary
// news section (some are secondary and merely categorisation tools)
);
- public static $defaults = array('AutoFiling' => false, 'PrimaryNewsSection' => true);
+ public static $defaults = array(
+ 'AutoFiling' => false,
+ 'PrimaryNewsSection' => true
+ );
public static $icon = 'news/images/newsholder';
@@ -47,11 +51,29 @@ class NewsHolder extends Page {
*/
public function getCMSFields() {
$fields = parent::getCMSFields();
- $fields->addFieldToTab('Root.Content.Main', new CheckboxField('AutoFiling', _t('NewsHolder.AUTO_FOLDER', 'Automatically file contained Articles'), true), 'Content');
+// $fields->addFieldToTab('Root.Content.Main', new CheckboxField('AutoFiling', _t('NewsHolder.AUTO_FOLDER', 'Automatically file contained Articles'), true), 'Content');
+
+ $modes = array(
+ '' => 'No filing',
+ 'day' => '/Year/Month/Day',
+ 'month' => '/Year/Month',
+ 'year' => '/Year'
+ );
+ $fields->addFieldToTab('Root.Content.Main', new DropdownField('FilingMode', _t('NewsHolder.FILING_MODE', 'File into'), $modes), 'Content');
$fields->addFieldToTab('Root.Content.Main', new DropdownField('FileBy', _t('NewsHolder.FILE_BY', 'File by'), array('Published' => 'Published', 'Created' => 'Created')), 'Content');
$fields->addFieldToTab('Root.Content.Main', new CheckboxField('PrimaryNewsSection', _t('NewsHolder.PRIMARY_SECTION', 'Is this a primary news section?'), true), 'Content');
return $fields;
}
+
+ public function onBeforeWrite() {
+ parent::onBeforeWrite();
+
+ // set the filing mode, now that it's being obsolete
+ if ($this->AutoFiling && !$this->FilingMode) {
+ $this->FilingMode = 'day';
+ $this->AutoFiling = false;
+ }
+ }
/**
* Returns a list of articles within this news holder.
@@ -140,10 +162,18 @@ public function getPartitionedHolderForArticle($article) {
throw new Exception("Failed retrieving folder");
}
+ if ($this->FilingMode == 'year') {
+ return $yearFolder;
+ }
+
$monthFolder = $yearFolder->dateFolder($month);
if (!$monthFolder) {
throw new Exception("Failed retrieving folder");
}
+
+ if ($this->FilingMode == 'month') {
+ return $monthFolder;
+ }
$dayFolder = $monthFolder->dateFolder($day);
if (!$dayFolder) {

0 comments on commit d35a8b6

Please sign in to comment.