コード例 #1
0
ファイル: Layout.php プロジェクト: cornernote/yii2-dashboard
 /**
  * @inheritdoc
  */
 public function afterValidate()
 {
     if (!$this->dashboard->validate()) {
         $this->addError(null);
     }
     parent::afterValidate();
 }
コード例 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Dashboard::find();
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['sort' => SORT_ASC]]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'enabled' => $this->enabled, 'sort' => $this->sort]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'layout_class', $this->layout_class]);
     return $dataProvider;
 }
コード例 #3
0
ファイル: index.php プロジェクト: cornernote/yii2-dashboard
/**
 * @var yii\web\View $this
 * @var yii\data\ActiveDataProvider $dataProvider
 * @var cornernote\dashboard\models\Dashboard $model
 * @var cornernote\dashboard\models\search\DashboardSearch $searchModel
 */
$this->title = Yii::t('dashboard', 'Dashboards');
$this->params['breadcrumbs'][] = $this->title;
?>

<div class="dashboard-index">

    <div class="clearfix">
        <p class="pull-left">
            <?php 
echo Html::a('<span class="fa fa-plus"></span> ' . Yii::t('dashboard', 'Create') . ' ' . Yii::t('dashboard', 'Dashboard'), ['create', 'Dashboard' => ['enabled' => 1, 'sort' => 0]], ['class' => 'btn btn-success']);
?>
        </p>
    </div>

    <?php 
$items = [];
foreach (Dashboard::find()->orderBySort()->all() as $dashboard) {
    $dashboardDisplay = implode(' ', [Html::a('<i class="glyphicon glyphicon-eye-open"></i>', ['dashboard/view', 'id' => $dashboard->id], ['data-toggle' => 'tooltip', 'title' => Yii::t('dashboard', 'View Dashboard')]), Html::a('<i class="glyphicon glyphicon-pencil"></i>', ['dashboard/update', 'id' => $dashboard->id], ['data-toggle' => 'tooltip', 'title' => Yii::t('dashboard', 'Update Dashboard')]), Html::a('<i class="glyphicon glyphicon-trash"></i>', ['dashboard/delete', 'id' => $dashboard->id], ['data-confirm' => Yii::t('dashboard', 'Are you sure to delete this dashboard?'), 'data-method' => 'post', 'data-toggle' => 'tooltip', 'title' => Yii::t('dashboard', 'Delete Dashboard')]), '&nbsp;&nbsp;' . Html::tag('span', $dashboard->name, ['style' => !$dashboard->enabled ? 'text-decoration:line-through' : ''])]);
    $items[] = ['options' => ['id' => 'dashboard-' . $dashboard->id, 'class' => 'dashboard'], 'content' => $dashboardDisplay];
}
echo Sortable::widget(['id' => 'dashboard-sortable', 'items' => $items, 'pluginEvents' => ['sortupdate' => 'dashboardSort']]);
$this->registerJs('var dashboardSortUrl = "' . Url::to(['dashboard/sort']) . '"', View::POS_END);
?>

</div>
コード例 #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getDashboard()
 {
     return $this->hasOne(Dashboard::className(), ['id' => 'dashboard_id']);
 }
コード例 #5
0
 /**
  * Finds the Dashboard model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Dashboard the loaded model
  * @throws HttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Dashboard::findOne($id)) !== null) {
         return $model;
     }
     throw new HttpException(404, 'The requested page does not exist.');
 }