2017-05-02 04:49:41 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* A document set is attached to Pages, and contains many DMSDocuments
|
|
|
|
*/
|
|
|
|
class DMSDocumentSet extends DataObject
|
|
|
|
{
|
|
|
|
private static $db = array(
|
|
|
|
'Title' => 'Varchar(255)'
|
|
|
|
);
|
|
|
|
|
|
|
|
private static $has_one = array(
|
|
|
|
'Page' => 'SiteTree'
|
|
|
|
);
|
|
|
|
|
|
|
|
private static $many_many = array(
|
|
|
|
'Documents' => 'DMSDocument'
|
|
|
|
);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Retrieve a list of the documents in this set. An extension hook is provided before the result is returned.
|
|
|
|
*
|
|
|
|
* You can attach an extension to this event:
|
|
|
|
*
|
|
|
|
* <code>
|
|
|
|
* public function updateDocuments($document)
|
|
|
|
* {
|
|
|
|
* // do something
|
|
|
|
* }
|
|
|
|
* </code>
|
|
|
|
*
|
|
|
|
* @return DataList
|
|
|
|
*/
|
|
|
|
public function getDocuments()
|
|
|
|
{
|
|
|
|
$documents = $this->Documents();
|
|
|
|
|
|
|
|
$this->extend('updateDocuments', $documents);
|
|
|
|
|
|
|
|
return $documents;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Put the "documents" list into the main tab instead of its own tab, and replace the default "Add Document" button
|
|
|
|
* with a customised button for DMS documents
|
|
|
|
*
|
|
|
|
* @return FieldList
|
|
|
|
*/
|
|
|
|
public function getCMSFields()
|
|
|
|
{
|
2017-05-09 00:13:13 +02:00
|
|
|
// PHP 5.3 only
|
|
|
|
$self = $this;
|
2017-05-02 04:49:41 +02:00
|
|
|
|
2017-05-09 00:13:13 +02:00
|
|
|
$this->beforeUpdateCMSFields(function (FieldList $fields) use ($self) {
|
|
|
|
// Don't put the GridField for documents in until the set has been created
|
|
|
|
if (!$self->isInDB()) {
|
|
|
|
$fields->addFieldToTab(
|
|
|
|
'Root.Main',
|
|
|
|
LiteralField::create(
|
|
|
|
'GridFieldNotice',
|
|
|
|
'<p class="message warning">' . _t(
|
|
|
|
'DMSDocumentSet.GRIDFIELD_NOTICE',
|
|
|
|
'Managing documents will be available once you have created this document set.'
|
|
|
|
) . '</p>'
|
|
|
|
),
|
|
|
|
'Title'
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
2017-05-02 04:49:41 +02:00
|
|
|
|
|
|
|
// Document listing
|
|
|
|
$gridFieldConfig = GridFieldConfig::create()
|
|
|
|
->addComponents(
|
|
|
|
new GridFieldToolbarHeader(),
|
|
|
|
new GridFieldFilterHeader(),
|
|
|
|
new GridFieldSortableHeader(),
|
|
|
|
// new GridFieldOrderableRows('DocumentSort'),
|
|
|
|
new GridFieldDataColumns(),
|
|
|
|
new GridFieldEditButton(),
|
2017-05-09 00:13:13 +02:00
|
|
|
// Special delete dialog to handle custom behaviour of unlinking and deleting
|
|
|
|
new DMSGridFieldDeleteAction(),
|
2017-05-02 04:49:41 +02:00
|
|
|
new GridFieldDetailForm()
|
|
|
|
);
|
|
|
|
|
|
|
|
if (class_exists('GridFieldPaginatorWithShowAll')) {
|
|
|
|
$paginatorComponent = new GridFieldPaginatorWithShowAll(15);
|
|
|
|
} else {
|
|
|
|
$paginatorComponent = new GridFieldPaginator(15);
|
|
|
|
}
|
|
|
|
$gridFieldConfig->addComponent($paginatorComponent);
|
|
|
|
|
|
|
|
if (class_exists('GridFieldSortableRows')) {
|
|
|
|
$sortableComponent = new GridFieldSortableRows('DocumentSort');
|
2017-05-09 00:13:13 +02:00
|
|
|
// setUsePagenation method removed from newer version of SortableGridField.
|
2017-05-02 04:49:41 +02:00
|
|
|
if (method_exists($sortableComponent, 'setUsePagination')) {
|
|
|
|
$sortableComponent->setUsePagination(false)->setForceRedraw(true);
|
|
|
|
}
|
|
|
|
$gridFieldConfig->addComponent($sortableComponent);
|
|
|
|
}
|
|
|
|
|
|
|
|
// 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'))
|
2017-05-09 00:13:13 +02:00
|
|
|
->setFieldCasting(array('LastChanged' => 'Datetime->Ago'))
|
2017-05-02 04:49:41 +02:00
|
|
|
->setFieldFormatting(
|
|
|
|
array(
|
|
|
|
'FilenameWithoutID' => '<a target=\'_blank\' class=\'file-url\' href=\'$Link\'>$FilenameWithoutID</a>'
|
|
|
|
)
|
|
|
|
);
|
|
|
|
|
2017-05-09 00:13:13 +02:00
|
|
|
// Override delete functionality with this class
|
2017-05-02 04:49:41 +02:00
|
|
|
$gridFieldConfig->getComponentByType('GridFieldDetailForm')
|
|
|
|
->setItemRequestClass('DMSGridFieldDetailForm_ItemRequest');
|
|
|
|
|
|
|
|
$gridField = GridField::create(
|
|
|
|
'Documents',
|
|
|
|
false,
|
2017-05-09 00:13:13 +02:00
|
|
|
$self->Documents(), //->Sort('DocumentSort'),
|
2017-05-02 04:49:41 +02:00
|
|
|
$gridFieldConfig
|
|
|
|
);
|
|
|
|
$gridField->addExtraClass('documents');
|
|
|
|
|
|
|
|
$gridFieldConfig->addComponent(
|
|
|
|
$addNewButton = new DMSGridFieldAddNewButton,
|
|
|
|
'GridFieldExportButton'
|
|
|
|
);
|
2017-05-09 00:13:13 +02:00
|
|
|
$addNewButton->setDocumentSetId($self->ID);
|
2017-05-02 04:49:41 +02:00
|
|
|
|
|
|
|
$fields->removeByName('Documents');
|
|
|
|
$fields->addFieldToTab('Root.Main', $gridField);
|
|
|
|
});
|
2017-05-09 00:13:13 +02:00
|
|
|
$this->addRequirements();
|
2017-05-02 04:49:41 +02:00
|
|
|
return parent::getCMSFields();
|
|
|
|
}
|
2017-05-09 00:13:13 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Add required CSS and Javascript requirements for managing documents
|
|
|
|
*
|
|
|
|
* @return $this
|
|
|
|
*/
|
|
|
|
protected function addRequirements()
|
|
|
|
{
|
|
|
|
// 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
|
|
|
|
Requirements::javascript(DMS_DIR . '/javascript/DocumentHtmlEditorFieldToolbar.js');
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
2017-05-02 04:49:41 +02:00
|
|
|
}
|