From 39ce206b55a82d890809eca393d8bdadf76b9934 Mon Sep 17 00:00:00 2001 From: Robbie Averill Date: Mon, 1 May 2017 15:54:48 +1200 Subject: [PATCH] FIX Updates for coding standards, move second classes in files to their own files, fix comments --- _config.php | 7 +- code/DMS.php | 51 +++- code/DMSShortcodeHandler.php | 10 +- code/cms/DMSDocumentAddController.php | 38 ++- code/cms/DMSDocumentAddExistingField.php | 14 +- code/cms/DMSGridFieldDeleteAction.php | 51 +++- code/cms/DMSUploadField.php | 89 ++---- code/cms/DMSUploadField_ItemHandler.php | 39 +++ code/cms/DocumentHtmlEditorFieldToolbar.php | 3 - code/extensions/DMSSiteTreeExtension.php | 25 +- code/interface/DMSDocumentInterface.php | 27 +- code/interface/DMSInterface.php | 9 +- code/model/DMSDocument.php | 276 ++++++------------- code/model/DMSDocument_Controller.php | 165 +++++++++++ code/model/DMSDocument_versions.php | 9 +- code/model/DMSTag.php | 2 - javascript/DMSDocumentAddExistingField.js | 44 +-- javascript/DMSDocumentCMSFields.js | 24 +- javascript/DMSGridField.js | 28 +- javascript/DocumentHtmlEditorFieldToolbar.js | 36 ++- tests/DMSDocumentControllerTest.php | 59 ++-- tests/DMSDocumentTest.php | 16 +- tests/DMSEmbargoTest.php | 14 +- tests/DMSShortcodeTest.php | 4 +- tests/DMSTagTest.php | 1 + tests/DMSTest.php | 67 +++-- tests/DMSVersioningTest.php | 27 +- tests/ShortCodeRelationFinderTest.php | 11 +- 28 files changed, 686 insertions(+), 460 deletions(-) create mode 100644 code/cms/DMSUploadField_ItemHandler.php create mode 100644 code/model/DMSDocument_Controller.php diff --git a/_config.php b/_config.php index b56df74..6d59e6c 100644 --- a/_config.php +++ b/_config.php @@ -8,12 +8,15 @@ DMSDocumentAddController::add_allowed_extensions(); //add an array of additional define('DMS_DIR', 'dms'); -if (!file_exists(BASE_PATH . DIRECTORY_SEPARATOR . DMS_DIR)) user_error("DMS directory named incorrectly. Please install the DMS module into a folder named: ".DMS_DIR); +if (!file_exists(BASE_PATH . DIRECTORY_SEPARATOR . DMS_DIR)) { + user_error("DMS directory named incorrectly. Please install the DMS module into a folder named: ".DMS_DIR); +} CMSMenu::remove_menu_item('DMSDocumentAddController'); ShortcodeParser::get('default')->register( - 'dms_document_link', array('DMSShortcodeHandler', 'handle') + 'dms_document_link', + array('DMSShortcodeHandler', 'handle') ); if ($config->get('DMSDocument_versions', 'enable_versions')) { diff --git a/code/DMS.php b/code/DMS.php index 9c8e14d..6746716 100644 --- a/code/DMS.php +++ b/code/DMS.php @@ -1,11 +1,20 @@ write(); @@ -74,7 +96,14 @@ class DMS implements DMSInterface /** * * Returns a number of Document objects based on the a search by tags. You can search by category alone, - * by tag value alone, or by both. I.e: getByTag("fruits",null); getByTag(null,"banana"); getByTag("fruits","banana") + * by tag value alone, or by both. I.e: + * + * + * getByTag("fruits", null); + * getByTag(null, "banana"); + * getByTag("fruits", "banana"); + * + * * @param null $category The metadata category to search for * @param null $value The metadata value to search for * @param bool $showEmbargoed Boolean that specifies if embargoed documents should be included in results diff --git a/code/DMSShortcodeHandler.php b/code/DMSShortcodeHandler.php index c1dac54..0af1773 100644 --- a/code/DMSShortcodeHandler.php +++ b/code/DMSShortcodeHandler.php @@ -10,7 +10,11 @@ class DMSShortcodeHandler { public static function handle( - $arguments, $content, ShortcodeParser $parser, $tag, array $extra = array() + $arguments, + $content, + ShortcodeParser $parser, + $tag, + array $extra = array() ) { if (!empty($arguments['id'])) { $document = DMSDocument::get()->byID($arguments['id']); @@ -18,7 +22,9 @@ class DMSShortcodeHandler if ($document && !$document->isHidden()) { if ($content) { return sprintf( - '%s', $document->Link(), $parser->parse($content) + '%s', + $document->Link(), + $parser->parse($content) ); } else { if (isset($extra['element'])) { diff --git a/code/cms/DMSDocumentAddController.php b/code/cms/DMSDocumentAddController.php index 475fbb1..899886c 100644 --- a/code/cms/DMSDocumentAddController.php +++ b/code/cms/DMSDocumentAddController.php @@ -3,7 +3,6 @@ /** * @package dms */ - class DMSDocumentAddController extends LeftAndMain { @@ -51,7 +50,8 @@ class DMSDocumentAddController extends LeftAndMain if ($id && is_numeric($id) && $id > 0) { return Versioned::get_by_stage('SiteTree', 'Stage', sprintf( - 'ID = %s', (int) $id + 'ID = %s', + (int) $id ))->first(); } else { // ID is either '0' or 'root' @@ -89,7 +89,9 @@ class DMSDocumentAddController extends LeftAndMain $uploadField->setTemplate('AssetUploadField'); $uploadField->setRecord($page); - $uploadField->getValidator()->setAllowedExtensions(array_filter(array_merge(Config::inst()->get('File', 'allowed_extensions'), self::$allowed_extensions))); + $uploadField->getValidator()->setAllowedExtensions( + array_filter(array_merge(Config::inst()->get('File', 'allowed_extensions'), self::$allowed_extensions)) + ); $exts = $uploadField->getValidator()->getAllowedExtensions(); asort($exts); @@ -105,8 +107,10 @@ class DMSDocumentAddController extends LeftAndMain $this, 'getEditForm', new FieldList( - new TabSet('Main', - new Tab('From your computer', + new TabSet( + 'Main', + new Tab( + 'From your computer', new HiddenField('ID', false, $page->ID), $uploadField, new LiteralField( @@ -118,7 +122,8 @@ class DMSDocumentAddController extends LeftAndMain ) ) ), - new Tab('From the CMS', + new Tab( + 'From the CMS', $addExistingField ) ) @@ -168,10 +173,10 @@ class DMSDocumentAddController extends LeftAndMain 'Title' => 'Add Document', 'Link' => $this->Link() ))); - + return $items; } - + public function Backlink() { $pageID = $this->currentPageID(); @@ -183,7 +188,9 @@ class DMSDocumentAddController extends LeftAndMain $term = (isset($_GET['term'])) ? $_GET['term'] : ''; $term_sql = Convert::raw2sql($term); $data = DMSDocument::get() - ->where("(\"ID\" LIKE '%".$term_sql."%' OR \"Filename\" LIKE '%".$term_sql."%' OR \"Title\" LIKE '%".$term_sql."%')") + ->where( + "(\"ID\" LIKE '%".$term_sql."%' OR \"Filename\" LIKE '%".$term_sql."%' OR \"Title\" LIKE '%".$term_sql."%')" + ) ->sort('ID ASC') ->limit(20); @@ -208,15 +215,17 @@ class DMSDocumentAddController extends LeftAndMain $document = DataObject::get_by_id('DMSDocument', (int) $_GET['documentID']); $document->addPage($page); - $buttonText = ''; + $buttonText = ''; // Collect all output data. $return = array( 'id' => $document->ID, 'name' => $document->getTitle(), 'thumbnail_url' => $document->Icon($document->getExtension()), - 'edit_url' => $this->getEditForm()->Fields()->fieldByName('Main.From your computer.AssetUploadField')->getItemHandler($document->ID)->EditLink(), + 'edit_url' => $this->getEditForm()->Fields()->fieldByName('Main.From your computer.AssetUploadField') + ->getItemHandler($document->ID)->EditLink(), 'size' => $document->getFileSizeFormatted(), 'buttons' => $buttonText, 'showeditform' => true @@ -249,8 +258,9 @@ class DMSDocumentAddController extends LeftAndMain return $list; } - - return sprintf('

%s

', + + return sprintf( + '

%s

', _t('DMSDocumentAddController.NODOCUMENTS', 'There are no documents attached to the selected page.') ); } diff --git a/code/cms/DMSDocumentAddExistingField.php b/code/cms/DMSDocumentAddExistingField.php index 1ed3f94..7e45953 100644 --- a/code/cms/DMSDocumentAddExistingField.php +++ b/code/cms/DMSDocumentAddExistingField.php @@ -2,7 +2,6 @@ class DMSDocumentAddExistingField extends CompositeField { - public $useFieldContext = true; public function __construct($name, $title = null) @@ -10,7 +9,15 @@ class DMSDocumentAddExistingField extends CompositeField $this->name = $name; $this->title = ($title === null) ? $name : $title; - parent::__construct(new TreeDropdownField('PageSelector', 'Add from another page', 'SiteTree', 'ID', 'TitleWithNumberOfDocuments')); + parent::__construct( + new TreeDropdownField( + 'PageSelector', + 'Add from another page', + 'SiteTree', + 'ID', + 'TitleWithNumberOfDocuments' + ) + ); } /** @@ -23,7 +30,8 @@ class DMSDocumentAddExistingField extends CompositeField return $this; } /** - * Get the record to use as "Parent" for uploaded Files (eg a Page with a has_one to File) If none is set, it will use Form->getRecord() or Form->Controller()->data() + * Get the record to use as "Parent" for uploaded Files (eg a Page with a has_one to File) If none is set, it + * will use Form->getRecord() or Form->Controller()->data() * @return DataObject */ public function getRecord() diff --git a/code/cms/DMSGridFieldDeleteAction.php b/code/cms/DMSGridFieldDeleteAction.php index 00c5c68..35e6f4c 100644 --- a/code/cms/DMSGridFieldDeleteAction.php +++ b/code/cms/DMSGridFieldDeleteAction.php @@ -13,7 +13,9 @@ * @package dms * @subpackage cms */ -class DMSGridFieldDeleteAction extends GridFieldDeleteAction implements GridField_ColumnProvider, GridField_ActionProvider +class DMSGridFieldDeleteAction extends GridFieldDeleteAction implements + GridField_ColumnProvider, + GridField_ActionProvider { /** @@ -26,35 +28,52 @@ class DMSGridFieldDeleteAction extends GridFieldDeleteAction implements GridFiel public function getColumnContent($gridField, $record, $columnName) { if ($this->removeRelation) { - $field = GridField_FormAction::create($gridField, 'UnlinkRelation'.$record->ID, false, "unlinkrelation", array('RecordID' => $record->ID)) + $field = GridField_FormAction::create( + $gridField, + 'UnlinkRelation' . $record->ID, + false, + "unlinkrelation", + array('RecordID' => $record->ID) + ) ->addExtraClass('gridfield-button-unlink') ->setAttribute('title', _t('GridAction.UnlinkRelation', "Unlink")) ->setAttribute('data-icon', 'chain--minus'); } else { if (!$record->canDelete()) { - return; + return ''; } - $field = GridField_FormAction::create($gridField, 'DeleteRecord'.$record->ID, false, "deleterecord", array('RecordID' => $record->ID)) + + $field = GridField_FormAction::create( + $gridField, + 'DeleteRecord' . $record->ID, + false, + "deleterecord", + array('RecordID' => $record->ID) + ) ->addExtraClass('gridfield-button-delete') ->setAttribute('title', _t('GridAction.Delete', "Delete")) ->setAttribute('data-icon', 'cross-circle') ->setDescription(_t('GridAction.DELETE_DESCRIPTION', 'Delete')); } - //add a class to the field to if it is the last gridfield in the list + // Add a class to the field to if it is the last gridfield in the list $numberOfRelations = $record->Pages()->Count(); - $field->addExtraClass('dms-delete') //add a new class for custom JS to handle the delete action - ->setAttribute('data-pages-count', $numberOfRelations) //add the number of pages attached to this field as a data-attribute - ->removeExtraClass('gridfield-button-delete'); //remove the base gridfield behaviour + $field + // Add a new class for custom JS to handle the delete action + ->addExtraClass('dms-delete') + // Add the number of pages attached to this field as a data-attribute + ->setAttribute('data-pages-count', $numberOfRelations) + // Remove the base gridfield behaviour + ->removeExtraClass('gridfield-button-delete'); - //set a class telling JS what kind of warning to display when clicking the delete button + // Set a class telling JS what kind of warning to display when clicking the delete button if ($numberOfRelations > 1) { $field->addExtraClass('dms-delete-link-only'); } else { $field->addExtraClass('dms-delete-last-warning'); } - //set a class to show if the document is hidden + // Set a class to show if the document is hidden if ($record->isHidden()) { $field->addExtraClass('dms-document-hidden'); } @@ -70,6 +89,7 @@ class DMSGridFieldDeleteAction extends GridFieldDeleteAction implements GridFiel * @param mixed $arguments * @param array $data - form data * @return void + * @throws ValidationException If the current user doesn't have permission to delete the record */ public function handleAction(GridField $gridField, $actionName, $arguments, $data) { @@ -79,7 +99,10 @@ class DMSGridFieldDeleteAction extends GridFieldDeleteAction implements GridFiel return; } if ($actionName == 'deleterecord' && !$item->canDelete()) { - throw new ValidationException(_t('GridFieldAction_Delete.DeletePermissionsFailure', "No delete permissions"), 0); + throw new ValidationException( + _t('GridFieldAction_Delete.DeletePermissionsFailure', "No delete permissions"), + 0 + ); } $delete = false; @@ -87,10 +110,12 @@ class DMSGridFieldDeleteAction extends GridFieldDeleteAction implements GridFiel $delete = true; } - $gridField->getList()->remove($item); //remove the relation + // Remove the relation + $gridField->getList()->remove($item); if ($delete) { + // Delete the document $item->delete(); - } //delete the DMSDocument + } } } } diff --git a/code/cms/DMSUploadField.php b/code/cms/DMSUploadField.php index 6ca3f7e..4468cc5 100644 --- a/code/cms/DMSUploadField.php +++ b/code/cms/DMSUploadField.php @@ -74,7 +74,7 @@ class DMSUploadField extends UploadField /** * Action to handle upload of a single file - * + * * @param SS_HTTPRequest $request * @return string json */ @@ -93,7 +93,7 @@ class DMSUploadField extends UploadField $name = $this->getName(); $tmpfile = $request->postVar($name); $record = $this->getRecord(); - + // Check if the file has been uploaded into the temporary storage. if (!$tmpfile) { $return = array('error' => _t('UploadField.FIELDNOTSET', 'File information not found')); @@ -161,7 +161,7 @@ class DMSUploadField extends UploadField // CUSTOM Attach the file to the related record. $document = $this->attachFile($file); - + // Collect all output data. $return = array_merge($return, array( 'id' => $document->ID, @@ -199,7 +199,7 @@ class DMSUploadField extends UploadField // Replace the download template with a new one only when access the upload field through a GridField. // Needs to be enabled through setConfig('downloadTemplateName', 'ss-dmsuploadfield-downloadtemplate'); Requirements::javascript('dms/javascript/DMSUploadField_downloadtemplate.js'); - + // In the add dialog, add the addtemplate into the set of file that load. Requirements::javascript('dms/javascript/DMSUploadField_addtemplate.js'); @@ -214,7 +214,7 @@ class DMSUploadField extends UploadField { return DMSUploadField_ItemHandler::create($this, $itemID); } - + /** * FieldList $fields for the EditForm @@ -223,24 +223,26 @@ class DMSUploadField extends UploadField * @param File $file File context to generate fields for * @return FieldList List of form fields */ - public function getDMSFileEditFields($file) - { + public function getDMSFileEditFields($file) + { // Empty actions, generate default - if(empty($this->fileEditFields)) { + if (empty($this->fileEditFields)) { $fields = $file->getCMSFields(); // Only display main tab, to avoid overly complex interface - if($fields->hasTabSet() && ($mainTab = $fields->findOrMakeTab('Root.Main'))) { + if ($fields->hasTabSet() && ($mainTab = $fields->findOrMakeTab('Root.Main'))) { $fields = $mainTab->Fields(); } return $fields; } // Fields instance - if ($this->fileEditFields instanceof FieldList) return $this->fileEditFields; + if ($this->fileEditFields instanceof FieldList) { + return $this->fileEditFields; + } // Method to call on the given file - if($file->hasMethod($this->fileEditFields)) { + if ($file->hasMethod($this->fileEditFields)) { return $file->{$this->fileEditFields}(); } @@ -254,21 +256,23 @@ class DMSUploadField extends UploadField * @param File $file File context to generate form actions for * @return FieldList Field list containing FormAction */ - public function getDMSFileEditActions($file) - { + public function getDMSFileEditActions($file) + { // Empty actions, generate default - if(empty($this->fileEditActions)) { + if (empty($this->fileEditActions)) { $actions = new FieldList($saveAction = new FormAction('doEdit', _t('UploadField.DOEDIT', 'Save'))); $saveAction->addExtraClass('ss-ui-action-constructive icon-accept'); return $actions; } // Actions instance - if ($this->fileEditActions instanceof FieldList) return $this->fileEditActions; + if ($this->fileEditActions instanceof FieldList) { + return $this->fileEditActions; + } // Method to call on the given file - if($file->hasMethod($this->fileEditActions)) { + if ($file->hasMethod($this->fileEditActions)) { return $file->{$this->fileEditActions}(); } @@ -282,58 +286,23 @@ class DMSUploadField extends UploadField * @param File $file File context to generate validator from * @return Validator Validator object */ - public function getDMSFileEditValidator($file) - { + public function getDMSFileEditValidator($file) + { // Empty validator - if(empty($this->fileEditValidator)) return null; + if (empty($this->fileEditValidator)) { + return null; + } // Validator instance - if($this->fileEditValidator instanceof Validator) return $this->fileEditValidator; + if ($this->fileEditValidator instanceof Validator) { + return $this->fileEditValidator; + } // Method to call on the given file - if($file->hasMethod($this->fileEditValidator)) { + if ($file->hasMethod($this->fileEditValidator)) { return $file->{$this->fileEditValidator}(); } user_error("Invalid value for UploadField::fileEditValidator", E_USER_ERROR); - } -} - -class DMSUploadField_ItemHandler extends UploadField_ItemHandler -{ - - private static $allowed_actions = array( - 'delete', - 'edit', - 'EditForm', - ); - - public function getItem() - { - return DataObject::get_by_id('DMSDocument', $this->itemID); } - - /** - * @return Form - */ - public function EditForm() { - $file = $this->getItem(); - - // Get form components - $fields = $this->parent->getDMSFileEditFields($file); - $actions = $this->parent->getDMSFileEditActions($file); - $validator = $this->parent->getDMSFileEditValidator($file); - $form = new Form( - $this, - __FUNCTION__, - $fields, - $actions, - $validator - ); - $form->loadDataFrom($file); - $form->addExtraClass('small'); - - return $form; - } - } diff --git a/code/cms/DMSUploadField_ItemHandler.php b/code/cms/DMSUploadField_ItemHandler.php new file mode 100644 index 0000000..b698c92 --- /dev/null +++ b/code/cms/DMSUploadField_ItemHandler.php @@ -0,0 +1,39 @@ +itemID); + } + + /** + * @return Form + */ + public function EditForm() + { + $file = $this->getItem(); + + // Get form components + $fields = $this->parent->getDMSFileEditFields($file); + $actions = $this->parent->getDMSFileEditActions($file); + $validator = $this->parent->getDMSFileEditValidator($file); + $form = new Form( + $this, + __FUNCTION__, + $fields, + $actions, + $validator + ); + $form->loadDataFrom($file); + $form->addExtraClass('small'); + + return $form; + } +} diff --git a/code/cms/DocumentHtmlEditorFieldToolbar.php b/code/cms/DocumentHtmlEditorFieldToolbar.php index c879c4c..b1318cf 100644 --- a/code/cms/DocumentHtmlEditorFieldToolbar.php +++ b/code/cms/DocumentHtmlEditorFieldToolbar.php @@ -2,11 +2,8 @@ /** * Extends the original toolbar with document picking capability - modified lines are commented. */ - - class DocumentHtmlEditorFieldToolbar extends Extension { - public function updateLinkForm(Form $form) { $linkType = null; diff --git a/code/extensions/DMSSiteTreeExtension.php b/code/extensions/DMSSiteTreeExtension.php index 439adbc..9e7e653 100644 --- a/code/extensions/DMSSiteTreeExtension.php +++ b/code/extensions/DMSSiteTreeExtension.php @@ -33,7 +33,8 @@ class DMSSiteTreeExtension extends DataExtension /** * Only show the documents tab on the list of pages set here. Any pages set in the no_documents_tab array will - * still not be shown. If this isn't called, or if it is called with an empty array, all pages will get Document tabs. + * still not be shown. If this isn't called, or if it is called with an empty array, all pages will get + * Document tabs. * @static * @param $array Array of page types to show the Documents tab on */ @@ -51,7 +52,7 @@ class DMSSiteTreeExtension extends DataExtension public function updateCMSFields(FieldList $fields) { - //prevent certain pages from having a Document tab in the CMS + // Prevent certain pages from having a Document tab in the CMS if (in_array($this->owner->ClassName, self::$noDocumentsList)) { return; } @@ -59,11 +60,12 @@ class DMSSiteTreeExtension extends DataExtension return; } - //javascript to customize the grid field for the DMS document (overriding entwine in FRAMEWORK_DIR.'/javascript/GridField.js' + // Javascript to customize the grid field for the DMS document (overriding entwine + // in FRAMEWORK_DIR.'/javascript/GridField.js' Requirements::javascript(DMS_DIR.'/javascript/DMSGridField.js'); Requirements::css(DMS_DIR.'/css/DMSMainCMS.css'); - //javascript for the link editor pop-up in TinyMCE + // Javascript for the link editor pop-up in TinyMCE Requirements::javascript(DMS_DIR."/javascript/DocumentHtmlEditorFieldToolbar.js"); // Document listing @@ -97,12 +99,18 @@ class DMSSiteTreeExtension extends DataExtension // HACK: Create a singleton of DMSDocument to ensure extensions are applied before we try to get display fields. singleton('DMSDocument'); - $gridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields(Config::inst()->get('DMSDocument', 'display_fields')) + $gridFieldConfig->getComponentByType('GridFieldDataColumns') + ->setDisplayFields(Config::inst()->get('DMSDocument', 'display_fields')) ->setFieldCasting(array('LastChanged'=>"Datetime->Ago")) - ->setFieldFormatting(array('FilenameWithoutID'=>'$FilenameWithoutID')); + ->setFieldFormatting( + array( + 'FilenameWithoutID'=>'$FilenameWithoutID' + ) + ); //override delete functionality with this class - $gridFieldConfig->getComponentByType('GridFieldDetailForm')->setItemRequestClass('DMSGridFieldDetailForm_ItemRequest'); + $gridFieldConfig->getComponentByType('GridFieldDetailForm') + ->setItemRequestClass('DMSGridFieldDetailForm_ItemRequest'); $gridField = GridField::create( 'Documents', @@ -115,7 +123,8 @@ class DMSSiteTreeExtension extends DataExtension $uploadBtn = new LiteralField( 'UploadButton', sprintf( - '%s', + '%s', Controller::join_links(singleton('DMSDocumentAddController')->Link(), '?ID=' . $this->owner->ID), "Add Documents" ) diff --git a/code/interface/DMSDocumentInterface.php b/code/interface/DMSDocumentInterface.php index 9331b6f..9df20f1 100644 --- a/code/interface/DMSDocumentInterface.php +++ b/code/interface/DMSDocumentInterface.php @@ -1,17 +1,16 @@ apple. * Can could be implemented as a key/value store table (although it is more like category/value, because the * same category can occur multiple times) @@ -106,12 +109,12 @@ interface DMSDocumentInterface * @return String */ public function getLink(); - + /** * Return the extension of the file associated with the document */ public function getExtension(); - + /** * Returns the size of the file type in an appropriate format. * diff --git a/code/interface/DMSInterface.php b/code/interface/DMSInterface.php index 79702fc..719c8df 100644 --- a/code/interface/DMSInterface.php +++ b/code/interface/DMSInterface.php @@ -10,7 +10,6 @@ */ interface DMSInterface { - /** * Factory method that returns an instance of the DMS. This could be any class that implements the DMSInterface. * @static @@ -31,7 +30,13 @@ interface DMSInterface /** * * Returns a number of Document objects based on the a search by tags. You can search by category alone, - * by tag value alone, or by both. I.e: getByTag("fruits",null); getByTag(null,"banana"); getByTag("fruits","banana") + * by tag value alone, or by both. I.e: + * + * + * getByTag("fruits", null); + * getByTag(null, "banana"); + * getByTag("fruits", "banana"); + * * @abstract * @param null $category The metadata category to search for * @param null $value The metadata value to search for diff --git a/code/model/DMSDocument.php b/code/model/DMSDocument.php index b47e573..ead12bb 100644 --- a/code/model/DMSDocument.php +++ b/code/model/DMSDocument.php @@ -5,14 +5,14 @@ */ class DMSDocument extends DataObject implements DMSDocumentInterface { - private static $db = array( "Filename" => "Varchar(255)", // eg. 3469~2011-energysaving-report.pdf "Folder" => "Varchar(255)", // eg. 0 "Title" => 'Varchar(1024)', // eg. "Energy Saving Report for Year 2011, New Zealand LandCorp" "Description" => 'Text', "ViewCount" => 'Int', - "LastChanged" => 'SS_DateTime', //when this document's file was created or last replaced (small changes like updating title don't count) + // When this document's file was created or last replaced (small changes like updating title don't count) + "LastChanged" => 'SS_DateTime', "EmbargoedIndefinitely" => 'Boolean(false)', "EmbargoedUntilPublished" => 'Boolean(false)', @@ -169,7 +169,10 @@ class DMSDocument extends DataObject implements DMSDocumentInterface { $this->Pages()->add($pageObject); - DB::query("UPDATE \"DMSDocument_Pages\" SET \"DocumentSort\"=\"DocumentSort\"+1 WHERE \"SiteTreeID\" = $pageObject->ID"); + DB::query( + "UPDATE \"DMSDocument_Pages\" SET \"DocumentSort\"=\"DocumentSort\"+1" + . " WHERE \"SiteTreeID\" = $pageObject->ID" + ); return $this; } @@ -926,8 +929,7 @@ class DMSDocument extends DataObject implements DMSDocumentInterface $defaultDownloadBehaviour = Config::inst()->get('DMSDocument', 'default_download_behaviour'); if (!isset($downloadBehaviorSource[$defaultDownloadBehaviour])) { user_error('Default download behaviour "' . $defaultDownloadBehaviour . '" not supported.', E_USER_WARNING); - } - else { + } else { $downloadBehaviorSource[$defaultDownloadBehaviour] .= ' (' . _t('DMSDocument.DEFAULT', 'default') . ')'; } @@ -938,7 +940,10 @@ class DMSDocument extends DataObject implements DMSDocumentInterface $downloadBehaviorSource, $defaultDownloadBehaviour ) - ->setDescription('How the visitor will view this file. Open in browser allows files to be opened in a new tab.') + ->setDescription( + 'How the visitor will view this file. Open in browser ' + . 'allows files to be opened in a new tab.' + ) ); //create upload field to replace document @@ -990,9 +995,15 @@ class DMSDocument extends DataObject implements DMSDocumentInterface new GridFieldDataColumns(), new GridFieldPaginator(30) ); - $versionsGridFieldConfig->getComponentByType('GridFieldDataColumns')->setDisplayFields(Config::inst()->get('DMSDocument_versions', 'display_fields')) - ->setFieldCasting(array('LastChanged'=>"Datetime->Ago")) - ->setFieldFormatting(array('FilenameWithoutID'=>'$FilenameWithoutID')); + $versionsGridFieldConfig->getComponentByType('GridFieldDataColumns') + ->setDisplayFields(Config::inst()->get('DMSDocument_versions', 'display_fields')) + ->setFieldCasting(array('LastChanged'=>"Datetime->Ago")) + ->setFieldFormatting( + array( + 'FilenameWithoutID' => '' + . '$FilenameWithoutID' + ) + ); $versionsGrid = GridField::create( 'Versions', @@ -1004,7 +1015,8 @@ class DMSDocument extends DataObject implements DMSDocumentInterface //$extraFields = $versionsGrid->addExtraClass('find-versions'); } - $fields->add(new LiteralField('BottomTaskSelection', + $fields->add(new LiteralField( + 'BottomTaskSelection', '