diff --git a/controllers/CalendarController.php b/controllers/CalendarController.php
index 2b18b66..e7e7931 100644
--- a/controllers/CalendarController.php
+++ b/controllers/CalendarController.php
@@ -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
@@ -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:
diff --git a/models/search/CalendarSearch.php b/models/search/CalendarSearch.php
index 0095f99..0e41f32 100644
--- a/models/search/CalendarSearch.php
+++ b/models/search/CalendarSearch.php
@@ -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]);
}
diff --git a/views/calendar/_calendarTemplate.php b/views/calendar/_calendarTemplate.php
new file mode 100644
index 0000000..ad55b4b
--- /dev/null
+++ b/views/calendar/_calendarTemplate.php
@@ -0,0 +1,9 @@
+
+
+ = $model->dateEvent ?> (= $model->creator->username ?>)
+
diff --git a/views/calendar/my.php b/views/calendar/my.php
new file mode 100644
index 0000000..5e1521e
--- /dev/null
+++ b/views/calendar/my.php
@@ -0,0 +1,28 @@
+title = Yii::t('app', 'Calendars');
+//$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
= Html::encode($this->title) ?>: my events
+
+
+ = Html::a(Yii::t('app', 'Add event'), ['create'], ['class' => 'btn btn-success']) ?>
+
+ = ListView::widget([
+ 'dataProvider' => $dataProvider,
+ 'itemOptions' => ['class' => 'item'],
+ 'itemView' => function ($model, $key, $index, $widget) {
+ return $this->render('_calendarTemplate', [
+ 'model' => $model,
+ ]);
+ },
+ ]) ?>
+
diff --git a/views/calendar/shared.php b/views/calendar/shared.php
new file mode 100644
index 0000000..6414cd3
--- /dev/null
+++ b/views/calendar/shared.php
@@ -0,0 +1,28 @@
+title = Yii::t('app', 'Calendars');
+//$this->params['breadcrumbs'][] = $this->title;
+?>
+
+
= Html::encode($this->title) ?>: shared events
+
+
+ = Html::a(Yii::t('app', 'Add event'), ['create'], ['class' => 'btn btn-success']) ?>
+
+ = ListView::widget([
+ 'dataProvider' => $dataProvider,
+ 'itemOptions' => ['class' => 'item'],
+ 'itemView' => function ($model, $key, $index, $widget) {
+ return $this->render('_calendarTemplate', [
+ 'model' => $model,
+ ]);
+ },
+ ]) ?>
+
diff --git a/views/calendar/view.php b/views/calendar/viewCreator.php
similarity index 76%
rename from views/calendar/view.php
rename to views/calendar/viewCreator.php
index d055351..0caaf7d 100644
--- a/views/calendar/view.php
+++ b/views/calendar/viewCreator.php
@@ -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;
?>
@@ -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',
],
]) ?>
diff --git a/views/calendar/viewGuest.php b/views/calendar/viewGuest.php
index 152aecf..f9e5347 100644
--- a/views/calendar/viewGuest.php
+++ b/views/calendar/viewGuest.php
@@ -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;
?>
@@ -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',
],
]) ?>
diff --git a/views/layouts/main.php b/views/layouts/main.php
index 8753ce4..a319599 100755
--- a/views/layouts/main.php
+++ b/views/layouts/main.php
@@ -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']]