Skip to content

Commit

Permalink
Change calendar list view (both creator's and shared);
Browse files Browse the repository at this point in the history
Change calendar date view.
  • Loading branch information
dvaganov committed Jun 8, 2016
1 parent 8ae523b commit 44f6403
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 11 deletions.
32 changes: 31 additions & 1 deletion controllers/CalendarController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,36 @@ public function actionIndex()
]);
}

/**
* @return mixed
*/
public function actionMy()
{
$searchModel = new CalendarSearch();
$dataProvider = $searchModel->byOwner(\Yii::$app->user->id);

return $this->render('my', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}

/**
* @return mixed
*/
public function actionShared()
{
$searchModel = new CalendarSearch();
$access = Access::find()->whereGuest(\Yii::$app->user->id)->all();

$dataProvider = $searchModel->searchShared($access);

return $this->render('shared', [
'searchModel' => $searchModel,
'dataProvider' => $dataProvider,
]);
}

/**
* Displays a single Calendar model.
* @param int $id
Expand All @@ -62,7 +92,7 @@ public function actionView($id)
switch(Access::check($model)) {

case Access::ACCESS_OWNER:
$view = 'view';
$view = 'viewCreator';
break;

case Access::ACCESS_GUEST:
Expand Down
2 changes: 1 addition & 1 deletion models/search/CalendarSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public function search($params)
*/
public function byOwner($ownerID)
{
$query = Calendar::find()->whereOwner($ownerID);
$query = Calendar::find()->whereOwner($ownerID)->with('creator');
return new ActiveDataProvider(['query' => $query]);
}

Expand Down
9 changes: 9 additions & 0 deletions views/calendar/_calendarTemplate.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php
/***
* @var $model app\models\Calendar
*/
?>
<div style='padding: 40px; margin: 10px; display: inline-block; background: #f5f5f5; cursor: pointer;'
onclick='location.assign("/calendar/<?= $model->id ?>")'>
<?= $model->dateEvent ?> (<?= $model->creator->username ?>)
</div>
28 changes: 28 additions & 0 deletions views/calendar/my.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use yii\helpers\Html;
use yii\widgets\ListView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\search\CalendarSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Calendars');
//$this->params['breadcrumbs'][] = $this->title;
?>
<div class="calendar-index">
<h1><?= Html::encode($this->title) ?>: my events</h1>

<p>
<?= Html::a(Yii::t('app', 'Add event'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= ListView::widget([
'dataProvider' => $dataProvider,
'itemOptions' => ['class' => 'item'],
'itemView' => function ($model, $key, $index, $widget) {
return $this->render('_calendarTemplate', [
'model' => $model,
]);
},
]) ?>
</div>
28 changes: 28 additions & 0 deletions views/calendar/shared.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

use yii\helpers\Html;
use yii\widgets\ListView;

/* @var $this yii\web\View */
/* @var $searchModel app\models\search\CalendarSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('app', 'Calendars');
//$this->params['breadcrumbs'][] = $this->title;
?>
<div class="calendar-index">
<h1><?= Html::encode($this->title) ?>: shared events</h1>

<p>
<?= Html::a(Yii::t('app', 'Add event'), ['create'], ['class' => 'btn btn-success']) ?>
</p>
<?= ListView::widget([
'dataProvider' => $dataProvider,
'itemOptions' => ['class' => 'item'],
'itemView' => function ($model, $key, $index, $widget) {
return $this->render('_calendarTemplate', [
'model' => $model,
]);
},
]) ?>
</div>
14 changes: 10 additions & 4 deletions views/calendar/view.php → views/calendar/viewCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* @var $this yii\web\View */
/* @var $model app\models\Calendar */

$this->title = substr($model->text, 0, 10) . '...';
$this->title = $model->dateEvent;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Calendars'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
Expand All @@ -28,10 +28,16 @@
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'text:ntext',
'creatorID',
[
'attribute' => 'creatorName',
'format' => 'raw',
'value' => Html::a(
$model->creator->username,
['/calendar/my']
)
],
'dateEvent',
'text:ntext',
],
]) ?>

Expand Down
14 changes: 10 additions & 4 deletions views/calendar/viewGuest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/* @var $this yii\web\View */
/* @var $model app\models\Calendar */

$this->title = substr($model->text, 0, 10) . '...';
$this->title = $model->dateEvent;
$this->params['breadcrumbs'][] = ['label' => Yii::t('app', 'Calendars'), 'url' => ['index']];
$this->params['breadcrumbs'][] = $this->title;
?>
Expand All @@ -17,10 +17,16 @@
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'id',
'text:ntext',
'creatorID',
[
'attribute' => 'creatorName',
'format' => 'raw',
'value' => Html::a(
$model->creator->username,
['/calendar/shared']
)
],
'dateEvent',
'text:ntext',
],
]) ?>

Expand Down
3 changes: 2 additions & 1 deletion views/layouts/main.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'About', 'url' => ['/site/about']],
['label' => 'Contact', 'url' => ['/site/contact']],
['label' => 'Calendar', 'url' => ['/calendar/index']],
['label' => 'My Calendar', 'url' => ['/calendar/my']],
['label' => 'Shared Calendar', 'url' => ['/calendar/shared']],
['label' => 'Access ', 'url' => ['/access/index']],
Yii::$app->user->isGuest ? (
['label' => 'Login', 'url' => ['/site/login']]
Expand Down

0 comments on commit 44f6403

Please sign in to comment.