From d28a0eefa0a8305b7e2155644f61b9413a6263a5 Mon Sep 17 00:00:00 2001 From: Stig Lindqvist Date: Thu, 13 Feb 2014 14:07:39 +1300 Subject: [PATCH] Coding style guidelines --- code/ContentReviewEmails.php | 5 +- code/ContentReviewOwnerMigrationTask.php | 5 ++ code/PagesDueForReviewReport.php | 30 ++++++-- code/SiteTreeContentReview.php | 93 ++++++++++++++++-------- tests/ContentReviewTest.php | 17 +++-- 5 files changed, 106 insertions(+), 44 deletions(-) diff --git a/code/ContentReviewEmails.php b/code/ContentReviewEmails.php index 082bb6d..7bf9c45 100644 --- a/code/ContentReviewEmails.php +++ b/code/ContentReviewEmails.php @@ -8,6 +8,10 @@ */ class ContentReviewEmails extends BuildTask { + /** + * + * @param SS_HTTPRequest $request + */ public function run($request) { // Disable subsite filter (if installed) if (ClassInfo::exists('Subsite')) { @@ -38,7 +42,6 @@ class ContentReviewEmails extends BuildTask { "StageSiteLink" => Controller::join_links($page->Link(), "?stage=Stage"), "LiveSiteLink" => Controller::join_links($page->Link(), "?stage=Live"), )); - $email->send(); } } diff --git a/code/ContentReviewOwnerMigrationTask.php b/code/ContentReviewOwnerMigrationTask.php index 82177d5..bec0d8f 100644 --- a/code/ContentReviewOwnerMigrationTask.php +++ b/code/ContentReviewOwnerMigrationTask.php @@ -3,6 +3,11 @@ * Task which migrates the ContentReview Module's SiteTree->OwnerID column to a new column name */ class ContentReviewOwnerMigrationTask extends BuildTask { + + /** + * + * @param SS_HTTPRequest $request + */ public function run($request) { $results = DB::query('SHOW columns from "SiteTree" WHERE "field" = \'OwnerID\''); if ($results->numRecords() == 0) { diff --git a/code/PagesDueForReviewReport.php b/code/PagesDueForReviewReport.php index d8b2b20..aa72925 100644 --- a/code/PagesDueForReviewReport.php +++ b/code/PagesDueForReviewReport.php @@ -7,11 +7,20 @@ require_once 'Zend/Date.php'; * @package contentreview */ class PagesDueForReviewReport extends SS_Report { - function title() { + + /** + * + * @return string + */ + public function title() { return _t('PagesDueForReviewReport.TITLE', 'Pages due for review'); } - function parameterFields() { + /** + * + * @return \FieldList + */ + public function parameterFields() { $params = new FieldList(); // We need to be a bit fancier when subsites is enabled @@ -66,7 +75,11 @@ class PagesDueForReviewReport extends SS_Report { return $params; } - function columns() { + /** + * + * @return array + */ + public function columns() { $linkBase = singleton('CMSPageEditController')->Link('show') . '/'; $fields = array( 'Title' => array( @@ -98,11 +111,16 @@ class PagesDueForReviewReport extends SS_Report { return $fields; } - function sourceRecords($params, $sort, $limit) { + /** + * + * @param array $params + * @param string $sort + * @param array $limit + * @return DataList + */ + public function sourceRecords($params, $sort, $limit) { $records = SiteTree::get(); - $wheres = array(); - if(empty($params['ReviewDateBefore']) && empty($params['ReviewDateAfter'])) { // If there's no review dates set, default to all pages due for review now $reviewDate = new Zend_Date(SS_Datetime::now()->Format('U')); diff --git a/code/SiteTreeContentReview.php b/code/SiteTreeContentReview.php index eb1f48e..6a3a508 100644 --- a/code/SiteTreeContentReview.php +++ b/code/SiteTreeContentReview.php @@ -7,6 +7,10 @@ */ class SiteTreeContentReview extends DataExtension implements PermissionProvider { + /** + * + * @var array + */ private static $db = array( "ReviewPeriodDays" => "Int", "NextReviewDate" => "Date", @@ -15,53 +19,75 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider 'OwnerNames' => 'Varchar(255)' ); + /** + * + * @var array + */ private static $has_one = array( 'ContentReviewOwner' => 'Member', ); - function getOwnerName() { - if($this->owner->ContentReviewOwnerID && $this->owner->ContentReviewOwner()) return $this->owner->ContentReviewOwner()->FirstName . ' ' . $this->owner->ContentReviewOwner()->Surname; + /** + * + * @return string + */ + public function getOwnerName() { + if($this->owner->ContentReviewOwnerID && $this->owner->ContentReviewOwner()) { + return $this->owner->ContentReviewOwner()->FirstName . ' ' . $this->owner->ContentReviewOwner()->Surname; + } } - function getEditorName() { + /** + * + * @return string + */ + public function getEditorName() { if( $member = Member::currentUser() ) { return $member->FirstName .' '. $member->Surname; } return NULL; } + /** + * + * @param FieldList $fields + * @return void + */ public function updateCMSFields(FieldList $fields) { if(Permission::check("EDIT_CONTENT_REVIEW_FIELDS")) { - - $cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN")); - - $fields->addFieldsToTab("Root.Review", array( - new HeaderField(_t('SiteTreeCMSWorkflow.REVIEWHEADER', "Content review"), 2), - new DropdownField("ContentReviewOwnerID", _t("SiteTreeCMSWorkflow.PAGEOWNER", - "Page owner (will be responsible for reviews)"), $cmsUsers->map('ID', 'Title', '(no owner)')), - DateField::create( - "NextReviewDate", - _t("SiteTreeCMSWorkflow.NEXTREVIEWDATE", "Next review date (leave blank for no review)") - )->setConfig('showcalendar', true)->setConfig('dateformat', 'yyyy-MM-dd')->setConfig('datavalueformat', 'yyyy-MM-dd'), - new DropdownField("ReviewPeriodDays", _t("SiteTreeCMSWorkflow.REVIEWFREQUENCY", - "Review frequency (the review date will be set to this far in the future whenever the page is published.)"), array( - 0 => "No automatic review date", - 1 => "1 day", - 7 => "1 week", - 30 => "1 month", - 60 => "2 months", - 91 => "3 months", - 121 => "4 months", - 152 => "5 months", - 183 => "6 months", - 365 => "12 months", - )), - new TextareaField('ReviewNotes', 'Review Notes') - )); + return; } + $cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN")); + + $fields->addFieldsToTab("Root.Review", array( + new HeaderField(_t('SiteTreeCMSWorkflow.REVIEWHEADER', "Content review"), 2), + new DropdownField("ContentReviewOwnerID", _t("SiteTreeCMSWorkflow.PAGEOWNER", + "Page owner (will be responsible for reviews)"), $cmsUsers->map('ID', 'Title', '(no owner)')), + DateField::create( + "NextReviewDate", + _t("SiteTreeCMSWorkflow.NEXTREVIEWDATE", "Next review date (leave blank for no review)") + )->setConfig('showcalendar', true)->setConfig('dateformat', 'yyyy-MM-dd')->setConfig('datavalueformat', 'yyyy-MM-dd'), + new DropdownField("ReviewPeriodDays", _t("SiteTreeCMSWorkflow.REVIEWFREQUENCY", + "Review frequency (the review date will be set to this far in the future whenever the page is published.)"), array( + 0 => "No automatic review date", + 1 => "1 day", + 7 => "1 week", + 30 => "1 month", + 60 => "2 months", + 91 => "3 months", + 121 => "4 months", + 152 => "5 months", + 183 => "6 months", + 365 => "12 months", + )), + new TextareaField('ReviewNotes', 'Review Notes') + )); } - function onBeforeWrite() { + /** + * Set the review data from the review period, if set. + */ + public function onBeforeWrite() { if($this->owner->ReviewPeriodDays && !$this->owner->NextReviewDate) { $this->owner->NextReviewDate = date('Y-m-d', strtotime('+' . $this->owner->ReviewPeriodDays . ' days')); } @@ -69,7 +95,12 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider $this->owner->OwnerNames = $this->owner->getOwnerName(); } - function providePermissions() { + /** + * Provide permissions to the CMS + * + * @return array + */ + public function providePermissions() { return array( "EDIT_CONTENT_REVIEW_FIELDS" => array( 'name' => "Set content owners and review dates", diff --git a/tests/ContentReviewTest.php b/tests/ContentReviewTest.php index f8be5ca..1f90a79 100644 --- a/tests/ContentReviewTest.php +++ b/tests/ContentReviewTest.php @@ -1,9 +1,14 @@ objFromFixture('Member', 'editor'); $author = $this->objFromFixture('Member', 'author'); @@ -24,7 +29,7 @@ class ContentReviewTest extends FunctionalTest { $this->assertNull($fields->fieldByName('Root.Review')); } - function testContentReviewEmails() { + public function testContentReviewEmails() { SS_Datetime::set_mock_now('2010-02-14 12:00:00'); $task = new ContentReviewEmails(); @@ -35,7 +40,7 @@ class ContentReviewTest extends FunctionalTest { SS_Datetime::clear_mock_now(); } - function testAutomaticallySettingReviewDate() { + public function testAutomaticallySettingReviewDate() { $editor = $this->objFromFixture('Member', 'editor'); $this->logInAs($editor); @@ -46,7 +51,7 @@ class ContentReviewTest extends FunctionalTest { $this->assertEquals(date('Y-m-d', strtotime('now + 10 days')), $page->NextReviewDate); } - function testReportContent() { + public function testReportContent() { $editor = $this->objFromFixture('Member', 'editor'); $this->logInAs($editor); $report = new PagesDueForReviewReport(); @@ -78,7 +83,7 @@ class ContentReviewTest extends FunctionalTest { SS_Datetime::clear_mock_now(); } - function testOwnerName() { + public function testOwnerName() { $editor = $this->objFromFixture('Member', 'editor'); $this->logInAs($editor);