getSettings('period', 1);
}
public function getKey(): string
{
return 'mark';
}
/**
* Service can be in a pack
* @return bool
*/
public function isPackable(): bool
{
return true;
}
/**
* Get service expiration date or 0 - unlimited
* @return int
*/
public function getExpires(): int
{
if ($this->activationPack) {
$period = $this->activationSettings['mark_days'] ?? 1;
} else {
$period = $this->getPeriod();
}
if (empty($period)) {
return 0;
}
$exist = $this->getItemServiceData($this->getKey(), $this->itemID);
if (! empty($exist['expires'])) {
$expire = strtotime('+'.$period.' days', strtotime($exist['expires']));
} else {
$expire = strtotime('+'.$period.' days');
}
return $expire;
}
public function onActivateAfter()
{
do {
if (! $this->itemID) {
break;
}
$exist = $this->getItemServiceData($this->getKey(), $this->itemID);
if (empty($exist)) {
break;
}
$exist = $exist->toArray();
if (empty($exist['expires'])) {
break;
}
$expires = strtotime($exist['expires']);
$item = Listings::model()->itemData($this->itemID, ['publicated_to']);
if (strtotime($item['publicated_to']) < $expires) {
Listings::model()->itemSave($this->itemID, [
'publicated_to' => date('Y-m-d H:i:s', $expires)
]);
}
} while(false);
}
/**
* Returns service bill description
* @return string
*/
public function getBillDescription(): string
{
$item = $this->manager->getItemData($this->itemID, ['link', 'title']);
if (! $item) {
return '';
}
return $this->plugin()->lang('Highlighting the listing
[title]', [
'link' => $item['link'],
'title' => $item['title'],
]);
}
/**
* Admin settings form
* @param Form $form
* @return mixed|void
*/
public function onAdminSettings($form)
{
parent::onAdminSettings($form);
$form->to('settings');
$form->number('period', $this->plugin()->langAdmin('Service Validity Period'), 1)
->label($this->plugin()->langAdmin('days'))
->before('icon_b');
$form->endUnion();
$this->addAdminSettingsFormPrices($form);
}
/**
* Admin pack settings form
* @param Form $form
* @return void
*/
public function onAdminSettingsPackServices($form)
{
$form
->number('mark_days', '', 0)
->stretch('mini')
->htmlAfter(' ' . $this->plugin()->langAdmin('- amount of days'))
->together($this->getKey())
;
}
public function getInstallSettings(): array
{
# todo translate
return [
'title' => [
'en' => 'Mark',
'ru' => 'Выделение',
],
'description' => [
'ru' => 'Объявление выделяется желтым фоном на всё время размещения на сайте. ' . PHP_EOL .
'Выделение объявления — отличный способ сделать ваше объявление более ярким и заметным на фоне соседних.',
],
'description_view' => [
'ru' => '
Объявление выделяется желтым фоном на всё время размещения на сайте.
'. 'Выделение объявления — отличный способ сделать ваше объявление более ярким и заметным на фоне соседних.
', ], 'price' => 1, 'settings' => [ 'period' => 1, 'add_form' => 1, ], ]; } public function onInstall(array $opts = []) { $opts['icons'] = [ 'icon_b' => $this->plugin()->path('static/mark.svg'), 'icon_s' => $this->plugin()->path('static/mark.svg'), ]; return parent::onInstall($opts); } }