| 1 |
<?php |
| 2 |
namespace Depicter\Document\Models\Traits; |
| 3 |
|
| 4 |
use Averta\Core\Utility\JSON; |
| 5 |
use Exception; |
| 6 |
|
| 7 |
trait DocumentAdminNoticeTrait { |
| 8 |
use HasDocumentIdTrait; |
| 9 |
use EntityPropertiesTrait; |
| 10 |
|
| 11 |
/** |
| 12 |
* @var int|null |
| 13 |
*/ |
| 14 |
protected $showAdminNotice = false; |
| 15 |
|
| 16 |
/** |
| 17 |
* Gets document ID |
| 18 |
* |
| 19 |
* @return int|null |
| 20 |
*/ |
| 21 |
public function showAdminNotice() { |
| 22 |
return $this->showAdminNotice; |
| 23 |
} |
| 24 |
|
| 25 |
/** |
| 26 |
* Enables or disables unpublished notice of document |
| 27 |
* |
| 28 |
* @param int $showAdminNotice |
| 29 |
* |
| 30 |
* @return mixed |
| 31 |
*/ |
| 32 |
public function setShowAdminNotice( $showAdminNotice = false ) { |
| 33 |
$this->showAdminNotice = $showAdminNotice; |
| 34 |
return $this; |
| 35 |
} |
| 36 |
|
| 37 |
/** |
| 38 |
* Render unpublished changes notice |
| 39 |
* |
| 40 |
* @return string |
| 41 |
*/ |
| 42 |
public function getUnpublishedChangesNotice() { |
| 43 |
if( ! $this->showAdminNotice() || ! $this->getDocumentID() ) { |
| 44 |
return ''; |
| 45 |
} |
| 46 |
$markup = ''; |
| 47 |
|
| 48 |
if ( $this->getEntityProperty('status') === 'draft' ) { |
| 49 |
$markup = \Depicter::view('admin/notices/slider-draft-notice')->with( 'view_args', [ |
| 50 |
'isPublishedBefore' => \Depicter::documentRepository()->isPublishedBefore( $this->getDocumentID() ), |
| 51 |
'editUrl' => \Depicter::editor()->getEditUrl( $this->getDocumentID() ) |
| 52 |
])->toString(); |
| 53 |
} |
| 54 |
|
| 55 |
$rule = \Depicter::metaRepository()->get( $this->getDocumentID(), 'rules', '' ); |
| 56 |
if ( JSON::isJson( $rule ) ) { |
| 57 |
$rule = JSON::decode( $rule ); |
| 58 |
if ( !empty( $rule->visibilitySchedule ) && !empty( $rule->visibilitySchedule->enable ) ) { |
| 59 |
$visibilityTime = $rule->visibilitySchedule; |
| 60 |
if ( !empty( $visibilityTime->start ) && ! \Depicter::schedule()->isDatePassed( $visibilityTime->start ) ) { |
| 61 |
$markup = \Depicter::view('admin/notices/slider-schedule-notice')->with( 'view_args', [ |
| 62 |
'editUrl' => \Depicter::editor()->getEditUrl( $this->getDocumentID() ) |
| 63 |
])->toString(); |
| 64 |
} else if ( !empty( $visibilityTime->end ) && \Depicter::schedule()->isDatePassed( $visibilityTime->end ) ) { |
| 65 |
$markup = \Depicter::view('admin/notices/slider-schedule-notice')->with( 'view_args', [ |
| 66 |
'editUrl' => \Depicter::editor()->getEditUrl( $this->getDocumentID() ) |
| 67 |
])->toString(); |
| 68 |
} |
| 69 |
} |
| 70 |
} |
| 71 |
|
| 72 |
return $markup; |
| 73 |
} |
| 74 |
|
| 75 |
/** |
| 76 |
* Render expired subscription notice |
| 77 |
* |
| 78 |
* @return string |
| 79 |
*/ |
| 80 |
public function getExpiredSubscriptionNotice() { |
| 81 |
if( ! $this->showAdminNotice() || ! $this->getDocumentID() ) { |
| 82 |
return ''; |
| 83 |
} |
| 84 |
|
| 85 |
if ( ! \Depicter::auth()->isSubscriptionExpired() ) { |
| 86 |
return ''; |
| 87 |
} |
| 88 |
|
| 89 |
try{ |
| 90 |
// skip admin notice display for popup and notification bars |
| 91 |
if ( in_array( \Depicter::documentRepository()->findOne( $this->getDocumentID() )->getProperty('type'), ['popup', 'banner-bar', 'notification-bar'] ) ) { |
| 92 |
return ''; |
| 93 |
} |
| 94 |
}catch( \Exception $e ){ |
| 95 |
return ''; |
| 96 |
} |
| 97 |
|
| 98 |
$subscription_id = \Depicter::options()->get('subscription_id' , ''); |
| 99 |
return \Depicter::view('admin/notices/subscription-expire-notice')->with( 'view_args',[ |
| 100 |
'subscription_id' => $subscription_id |
| 101 |
])->toString(); |
| 102 |
} |
| 103 |
} |
| 104 |
|