for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
/**
* Created for IG Monitoring.
* User: jakim <[email protected]>
* Date: 02.02.2018
*/
namespace app\modules\admin\widgets\favorites;
use app\models\Favorite;
use app\modules\admin\widgets\AjaxButton;
use Yii;
use yii\base\Widget;
use yii\helpers\Url;
class ProfileButton extends Widget
{
public $model;
public $addLabel = '<span class="fa fa-star text-yellow"></span> Add to favorites';
public $removeLabel = '<span class="fa fa-star-o text-yellow"></span> Remove from favorites';
public function run()
$url = Url::to(['/admin/account/dashboard', 'id' => $this->model->id]);
$model = Favorite::findOne([
'user_id' => Yii::$app->user->id,
'url' => $url,
]);
return AjaxButton::widget([
'confirm' => isset($model),
'text' => $model ? $this->removeLabel : $this->addLabel,
$model
yii\db\ActiveRecord
true
'url' => $model ? ['favorite/delete', 'id' => $model->id] : ['favorite/create'],
'data' => [
'label' => $this->model->usernamePrefixed,
],
'options' => [
'class' => 'btn btn-block btn-default btn-sm',
'style' => 'zoom-out',
}