SHARE
TWEET

Untitled

a guest Jun 18th, 2019 48 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. use yii\helpers\Html;
  4. use yii\grid\GridView;
  5. use yii\widgets\ActiveForm;
  6. use app\modules\system\daemon\models\DaemonName;
  7.  
  8. $this->title = 'Daemons';
  9. $this->params['breadcrumbs'][] = $this->title;
  10. ?>
  11. <div class="index">
  12.  
  13.   <h1><?= Html::encode($this->title) ?></h1>
  14.   <?php
  15.   $form = ActiveForm::begin([
  16.     'action' => ['refresh', 'return_url' => Yii::$app->request->url]
  17.   ]);
  18.   ?>
  19.   <?= GridView::widget([
  20.     'dataProvider' => $dataProvider,
  21.     'layout' => "{summary}\n{items}\n{pager}",
  22.     'columns' => [
  23.       DaemonName::$TYPE_NAME_FIELD,
  24.       DaemonName::$TRANSLATED_NAME_FIELD,
  25.       DaemonName::$PID_FIELD,
  26.       [
  27.         'label' => 'Staus',
  28.         'attribute' => DaemonName::$IS_ACTIVE_FIELD,
  29.         'format' => 'raw',
  30.         'value' => function ($data) {
  31.           /** @var $data DaemonName */
  32.           return $data->{DaemonName::$IS_ACTIVE_FIELD} ? '<div style="color:green">Is working</div>' : '<div style="color:red">Not working</div>';
  33.         }
  34.       ],
  35.       [
  36.         'label' => 'Actions',
  37.         'attribute' => 'enabled',
  38.         'format' => 'raw',
  39.         'value' => function ($data) {
  40.           /** @var $data DaemonName */
  41.           $buttons = [];
  42.           if ($data->{DaemonName::$IS_ACTIVE_FIELD} == 1) {
  43.             $buttons[] = Html::a(
  44.               'Stop',
  45.               ['execute', 'type_id' => $data->{DaemonName::$TYPE_ID_FIELD}, 'action' => 'stop', 'daemon' => $data->{DaemonName::$NAME_FIELD}, 'pid' => $data->{DaemonName::$PID_FIELD}, 'return_url' => Yii::$app->request->url],
  46.               [
  47.                 'class' => 'btn btn-success',
  48.                 'alt' => 'Stop',
  49.                 'title' => 'Stop',
  50.               ]);
  51.             $buttons[] = Html::a(
  52.               'Restart',
  53.               ['execute', 'type_id' => $data->{DaemonName::$TYPE_ID_FIELD}, 'action' => 'restart', 'daemon' => $data->{DaemonName::$NAME_FIELD}, 'pid' => $data->{DaemonName::$PID_FIELD}, 'return_url' => Yii::$app->request->url],
  54.               [
  55.                 'class' => 'btn btn-success',
  56.                 'alt' => 'Restart',
  57.                 'title' => 'Restart',
  58.               ]);
  59.           } else {
  60.             $buttons[] = Html::a(
  61.               'Run',
  62.               ['execute', 'type_id' => $data->{DaemonName::$TYPE_ID_FIELD}, 'action' => 'start', 'daemon' => $data->{DaemonName::$NAME_FIELD}, 'pid' => $data->{DaemonName::$PID_FIELD}, 'return_url' => Yii::$app->request->url],
  63.               [
  64.                 'class' => 'btn btn-success',
  65.                 'alt' => 'Run',
  66.                 'title' => 'Run',
  67.               ]);
  68.           }
  69.           return implode('&nbsp', $buttons);
  70.         }
  71.       ],
  72.     ],
  73.   ]); ?>
  74.   <?php
  75.   ActiveForm::end();
  76.   ?>
  77. </div>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top