BUGFIX: fixing expire/embargo on date functionality

This commit is contained in:
Julian Seidenberg 2012-08-14 11:35:41 +12:00
parent a858c1f66c
commit 2dbd0d89c1
2 changed files with 23 additions and 14 deletions

View File

@ -267,10 +267,12 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
* @return bool True or False depending on whether this document is embargoed
*/
function isEmbargoed() {
if (is_object($this->EmbargoedUntilDate)) $this->EmbargoedUntilDate = $this->EmbargoedUntilDate->Value;
$embargoed = false;
if ($this->EmbargoedForever) $embargoed = true;
elseif ($this->EmbargoedUntilPublished) $embargoed = true;
elseif (!empty($this->EmbargoedUntilDate) && SS_Datetime::now()->Value < $this->EmbargoedUntilDate->Value) $embargoed = true;
elseif (!empty($this->EmbargoedUntilDate) && SS_Datetime::now()->Value < $this->EmbargoedUntilDate) $embargoed = true;
return $embargoed;
}
@ -302,8 +304,10 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
* @return bool True or False depending on whether this document is expired
*/
function isExpired() {
if (is_object($this->ExpireAtDate)) $this->ExpireAtDate = $this->ExpireAtDate->Value;
$expired = false;
if (!empty($this->ExpireAtDate) && SS_Datetime::now()->Value >= $this->ExpireAtDate->Value) $expired = true;
if (!empty($this->ExpireAtDate) && SS_Datetime::now()->Value >= $this->ExpireAtDate) $expired = true;
return $expired;
}
@ -523,13 +527,13 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
elseif (!empty($this->EmbargoedUntilDate)) $embargoValue = 3;
$embargo = new OptionsetField('Embargo','Embargo',array('None','Hide document until page is published','Hide document forever','Hide until set date'),$embargoValue);
$embargoDatetime = DatetimeField::create('EmbargoedUntilDate','');
$embargoDatetime->getDateField()->setConfig('showcalendar', true);
$embargoDatetime->getDateField()->setConfig('showcalendar', true)->setConfig('dateformat', 'yyyy-MM-dd')->setConfig('datavalueformat', 'yyyy-MM-dd');
$expiryValue = 0;
if (!empty($this->ExpireAtDate)) $expiryValue = 1;
$expiry = new OptionsetField('Expiry','Expiry',array('None','Set document to expire on'),$expiryValue);
$expiryDatetime = DatetimeField::create('ExpireAtDate','');
$expiryDatetime->getDateField()->setConfig('showcalendar', true);;
$expiryDatetime->getDateField()->setConfig('showcalendar', true)->setConfig('dateformat', 'yyyy-MM-dd')->setConfig('datavalueformat', 'yyyy-MM-dd');
// This adds all the actions details into a group.
// Embargo, History, etc to go in here
@ -552,15 +556,20 @@ class DMSDocument extends DataObject implements DMSDocumentInterface {
function onBeforeWrite() {
parent::onBeforeWrite();
//set the embargo options from the OptionSetField created in the getCMSFields method
//do not write after clearing the embargo (write happens automatically)
$this->clearEmbargo(false); //clear all previous settings and re-apply them on save
if ($this->Embargo == 1) $this->embargoUntilPublished(false);
if ($this->Embargo == 2) $this->embargoForever(false);
if ($this->Embargo == 3) $this->embargoUntilDate($this->EmbargoDatetime, false);
if (isset($this->Embargo)) {
//set the embargo options from the OptionSetField created in the getCMSFields method
//do not write after clearing the embargo (write happens automatically)
if ($this->Embargo != 3) $this->clearEmbargo(false); //clear all previous settings and re-apply them on save
$this->clearExpiry(false); //clear all previous settings and re-apply them on save
if ($this->Expire == 1) $this->expireAtDate($this->ExpiryDatetime, false);
if ($this->Embargo == 1) $this->embargoUntilPublished(false);
if ($this->Embargo == 2) $this->embargoForever(false);
if ($this->Embargo == 3) $this->embargoUntilDate($this->EmbargoedUntilDate, false);
}
if (isset($this->Expire)) {
if ($this->Expire == 1) $this->expireAtDate($this->ExpireAtDate, false);
else $this->clearExpiry(false); //clear all previous settings
}
}
/**

View File

@ -46,7 +46,7 @@
$('#Form_ItemEditForm_Embargo input').entwine({
onchange: function() {
//selected the date options
if (this.attr('value') == 3) {
if (this.attr('value') === '3') {
$('.embargoDatetime').show();
} else {
$('.embargoDatetime').hide();
@ -57,7 +57,7 @@
$('#Form_ItemEditForm_Expiry input').entwine({
onchange: function() {
//selected the date options
if (this.attr('value') == 1) {
if (this.attr('value') === '1') {
$('.expiryDatetime').show();
} else {
$('.expiryDatetime').hide();