| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Traits; |
| 3 |
|
| 4 |
trait UnPublishedNoticeTrait { |
| 5 |
use HasDocumentIdTrait; |
| 6 |
use EntityPropertiesTrait; |
| 7 |
|
| 8 |
/** |
| 9 |
* @var int|null |
| 10 |
*/ |
| 11 |
protected $showUnpublishedNotice = false; |
| 12 |
|
| 13 |
/** |
| 14 |
* Gets document ID |
| 15 |
* |
| 16 |
* @return int|null |
| 17 |
*/ |
| 18 |
public function showUnpublishedNotice() { |
| 19 |
return $this->showUnpublishedNotice; |
| 20 |
} |
| 21 |
|
| 22 |
/** |
| 23 |
* Enables or disables unpublished notice of document |
| 24 |
* |
| 25 |
* @param int $showUnpublishedNotice |
| 26 |
* |
| 27 |
* @return mixed |
| 28 |
*/ |
| 29 |
public function setUnpublishedNotice( $showUnpublishedNotice = false ) { |
| 30 |
$this->showUnpublishedNotice = $showUnpublishedNotice; |
| 31 |
return $this; |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Render unpublished changes notice |
| 36 |
* |
| 37 |
* @return string |
| 38 |
*/ |
| 39 |
public function getUnpublishedChangesNotice() { |
| 40 |
if( ! $this->showUnpublishedNotice() || ! $this->getDocumentID() ) { |
| 41 |
return ''; |
| 42 |
} |
| 43 |
$markup = ''; |
| 44 |
|
| 45 |
if ( $this->getEntityProperty('status') === 'draft' ) { |
| 46 |
$markup = \Depicter::view('admin/notices/slider-draft-notice')->with( 'view_args', [ |
| 47 |
'isPublishedBefore' => \Depicter::documentRepository()->isPublishedBefore( $this->getDocumentID() ), |
| 48 |
'editUrl' => \Depicter::editor()->getEditUrl( $this->getDocumentID() ) |
| 49 |
])->toString(); |
| 50 |
} |
| 51 |
|
| 52 |
return $markup; |
| 53 |
} |
| 54 |
} |
| 55 |
|