Coding style guidelines

This commit is contained in:
Stig Lindqvist 2014-02-13 14:07:39 +13:00
parent 90db01d259
commit d28a0eefa0
5 changed files with 106 additions and 44 deletions

View File

@ -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();
}
}

View File

@ -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) {

View File

@ -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'));

View File

@ -7,6 +7,10 @@
*/
class SiteTreeContentReview extends DataExtension implements PermissionProvider {
/**
*
* @var array
*/
private static $db = array(
"ReviewPeriodDays" => "Int",
"NextReviewDate" => "Date",
@ -15,24 +19,44 @@ 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")) {
return;
}
$cmsUsers = Permission::get_members_by_permission(array("CMS_ACCESS_CMSMain", "ADMIN"));
$fields->addFieldsToTab("Root.Review", array(
@ -59,9 +83,11 @@ class SiteTreeContentReview extends DataExtension implements PermissionProvider
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",

View File

@ -1,9 +1,14 @@
<?php
class ContentReviewTest extends FunctionalTest {
static $fixture_file = 'contentreview/tests/ContentReviewTest.yml';
function testPermissions() {
/**
*
* @var string
*/
public static $fixture_file = 'contentreview/tests/ContentReviewTest.yml';
public function testPermissions() {
$editor = $this->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);