Created
April 16, 2019 17:28
-
-
Save Atmden/a11f462afb73126be44560dc59381ccb to your computer and use it in GitHub Desktop.
Comments.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Admin\Sections; | |
use SleepingOwl\Admin\Contracts\Display\DisplayInterface; | |
use SleepingOwl\Admin\Contracts\Form\FormInterface; | |
use SleepingOwl\Admin\Contracts\Initializable; | |
use SleepingOwl\Admin\Section; | |
use AdminColumn; | |
use AdminDisplay; | |
use AdminForm; | |
use AdminFormElement; | |
use AdminColumnEditable; | |
use SleepingOwl\Admin\Form\Buttons\SaveAndClose; | |
use SleepingOwl\Admin\Form\Buttons\Cancel; | |
/** | |
* Class Comments | |
* | |
* @property \App\Models\Comment $model | |
* | |
* @see http://sleepingowladmin.ru/docs/model_configuration_section | |
*/ | |
class Comments extends Section implements Initializable | |
{ | |
/** | |
* @see http://sleepingowladmin.ru/docs/model_configuration#ограничение-прав-доступа | |
* | |
* @var bool | |
*/ | |
protected $checkAccess = false; | |
/** | |
* @var string | |
*/ | |
protected $title = 'Комментарии к статьям'; | |
protected $icon = 'fa fa-file-text-o'; | |
public function isCreatable() | |
{ | |
return false;// TODO: Change the autogenerated stub | |
} | |
/** | |
* @var string | |
*/ | |
protected $alias; | |
/** | |
* @return DisplayInterface | |
*/ | |
public function onDisplay() | |
{ | |
$display = AdminDisplay::table() | |
->setHtmlAttribute('class', 'table-primary') | |
->setColumns([ | |
AdminColumn::link('name', 'Имя'), | |
AdminColumn::link('phone', 'Телефон'), | |
AdminColumn::link('article.title', 'Статья'), | |
AdminColumn::custom('Ссылка', function ($model) { | |
return '<a href="' . route('article', [$model->article_id]) . '">Просмотреть статью</a>'; | |
}), | |
AdminColumnEditable::checkbox('online')->setLabel('Показывать на сайте'), | |
AdminColumn::datetime('created_at')->setLabel('Дата создания'), | |
])->paginate(20); | |
return $display; | |
} | |
/** | |
* @param int $id | |
* | |
* @return FormInterface | |
*/ | |
public function onEdit($id) | |
{ | |
$form = AdminForm::panel()->addBody( | |
AdminFormElement::checkbox('online', 'Показывать на сайте'), | |
AdminFormElement::text('name', 'Имя отправителя')->required(), | |
AdminFormElement::text('phone', 'Телефон'), | |
AdminFormElement::textarea('comment', 'Комментарий')->required(), | |
AdminColumn::custom('Ссылка', function ($model) { | |
return '<a href="' . route('article', [$model->article_id]) . '">Просмотреть статью</a>'; | |
}) | |
); | |
$form->getButtons()->setButtons([ | |
'save' => new SaveAndClose(), | |
'cancel' => (new Cancel())->setText('Отмена'), | |
]); | |
return $form; | |
} | |
/** | |
* @return FormInterface | |
*/ | |
public function onCreate() | |
{ | |
return $this->onEdit(null); | |
} | |
/** | |
* @return void | |
*/ | |
public function onDelete($id) | |
{ | |
// remove if unused | |
} | |
/** | |
* @return void | |
*/ | |
public function onRestore($id) | |
{ | |
// remove if unused | |
} | |
/** | |
* Initialize class. | |
*/ | |
public function initialize() | |
{ | |
$this->addToNavigation(14); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment