コード例 #1
0
ファイル: NoteController.php プロジェクト: Sywooch/notes
 public function actionView($id)
 {
     $note = Note::find()->where(['id' => $id])->with('comments')->with('user')->one();
     if (!$note) {
         throw new NotFoundHttpException();
     }
     if (Yii::$app->user->can('viewNote', ['note' => $note])) {
         $query = Note::find()->with('user');
         $previousNote = $query->where(['<=', 'created_at', $note->created_at])->andWhere(['<', 'id', $note->id])->andWhere(['visibility' => Note::VIS_PUBLIC_LISTED])->orderBy('created_at DESC, id DESC')->one();
         $nextNote = $query->where(['>=', 'created_at', $note->created_at])->andWhere(['>', 'id', $note->id])->andWhere(['visibility' => Note::VIS_PUBLIC_LISTED])->orderBy('created_at ASC, id ASC')->one();
         $comment = new Comment();
         if ($comment->load(Yii::$app->request->post()) && $comment->validate()) {
             $parentId = Yii::$app->request->post('parentId');
             if ($parentId !== null && CommentClosure::find()->where(['child_id' => $parentId])->max('depth') >= Yii::$app->params['maxCommentsDepth']) {
                 throw new ForbiddenHttpException();
             }
             $comment->user_id = Yii::$app->user->getId();
             $comment->note_id = $note->id;
             $comment->save(false);
             CommentClosure::insertComment($comment->id, $parentId);
             return $this->refresh();
         }
         return $this->render('view', ['note' => $note, 'previousNote' => $previousNote, 'nextNote' => $nextNote, 'comment' => $comment]);
     } else {
         throw new ForbiddenHttpException();
     }
 }
コード例 #2
0
ファイル: NoteSearch.php プロジェクト: Sywooch/notes
 public function search($params, $whereParams = null)
 {
     $query = Note::find()->joinWith(User::tableName());
     $isAdminPanel = $this->getScenario() === 'admin';
     if ($whereParams) {
         $query->where($whereParams);
     }
     if ($this->load($params) && $this->validate()) {
         $query->andFilterWhere(['like', 'note.name', $this->name])->andFilterWhere(['like', 'user.name', $this['user.name']]);
         if ($isAdminPanel) {
             $query->andFilterWhere(['note.id' => $this->id])->andFilterWhere(['visibility' => $this->visibility]);
             if (preg_match('/[\\d]{2}-[\\d]{2}-[\\d]{4}/', $this->created_at)) {
                 $query->andFilterWhere(['AND', ['>', 'note.created_at', \DateTime::createFromFormat('d-m-Y H:i:s', $this->created_at . ' 00:00:00')->getTimestamp()], ['<', 'note.created_at', \DateTime::createFromFormat('d-m-Y H:i:s', $this->created_at . ' 23:59:59')->getTimestamp()]]);
             }
         } else {
             $query->andFilterWhere(['like', 'description', $this->description]);
         }
     }
     $noteSortAttributes = ['name' => ['asc' => ['note.name' => SORT_ASC], 'desc' => ['note.name' => SORT_DESC], 'label' => $this->getAttributeLabel('name')], 'created_at' => ['default' => SORT_DESC, 'label' => $this->getAttributeLabel('created_at')]];
     if ($isAdminPanel) {
         array_push($noteSortAttributes, 'id', 'user.name', 'visibility');
     } else {
         $noteSortAttributes['description'] = ['label' => $this->getAttributeLabel('description')];
     }
     $noteProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['attributes' => $noteSortAttributes, 'defaultOrder' => ['created_at' => SORT_DESC]], 'pagination' => ['pageSize' => $isAdminPanel ? 10 : 9, 'defaultPageSize' => $isAdminPanel ? 10 : 9]]);
     return $noteProvider;
 }
コード例 #3
0
ファイル: NoteController.php プロジェクト: mops1k/yiimine
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Note::find()->where(['user_id' => \Yii::$app->user->id])->orderBy('id DESC')]);
     $model = new Note();
     if ($model->load(\Yii::$app->request->post()) && $model->save()) {
         return $this->refresh();
     }
     return $this->render('index', ['dataProvider' => $dataProvider, 'model' => $model]);
 }
コード例 #4
0
ファイル: NotesWidget.php プロジェクト: hoangngk/adminpanel
 public function run()
 {
     $disViewMore = false;
     $notes = Note::find()->where(['type_area' => $this->type_area, 'belong_to' => $this->belong_to])->orderBy('id DESC');
     if (count($notes->all()) <= 5) {
         $notes = $notes->all();
         $disViewMore = true;
     } else {
         $notes = $notes->limit(5)->all();
     }
     return $this->render('notes/index', ['type_area' => $this->type_area, 'belong_to' => $this->belong_to, 'disViewMore' => $disViewMore, 'notes' => $notes]);
 }
コード例 #5
0
ファイル: NoteSearch.php プロジェクト: hscstudio/psiaga
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Note::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'title', $this->title])->andFilterWhere(['like', 'content', $this->content]);
     return $dataProvider;
 }
コード例 #6
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Note::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $query->joinWith(['access']);
     $dataProvider->sort->attributes['access'] = ['asc' => ['evrnt_access.user_id' => SORT_ASC], 'desc' => ['evrnt_access.user_id' => SORT_DESC]];
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['evrnt_note.id' => $this->id, 'evrnt_note.creator' => $this->creator, 'evrnt_note.date_create' => $this->date_create, 'evrnt_access.user_id' => $this->access['user_id']]);
     $query->andFilterWhere(['like', 'evrnt_note.text', $this->text]);
     return $dataProvider;
 }
コード例 #7
0
ファイル: NoteController.php プロジェクト: Sywooch/noteapp
 /**
  * Deletes single note from persistent storage
  * @return Array ( deleted => true|false )
  */
 public function actionDeleteNote()
 {
     # Accept only POST requests
     if (!Yii::$app->request->getIsPost()) {
         throw new NoteControllerInvalidCallException('Invalid call... ' . __METHOD__ . ' takes in only POST requests.');
     }
     $this->_setJsonResponse();
     $data = Json::decode(Yii::$app->request->getPost('note'));
     $note = Note::find($data['id']);
     # If note by given ID is not stored in persistent storage we can safely return true...
     $status = true;
     if (!is_null($note)) {
         $status = $note->delete();
     }
     return array('deleted' => $status);
 }
コード例 #8
0
ファイル: SiteController.php プロジェクト: Sywooch/notes
 public function actionHome($viewType = null)
 {
     if ($viewType) {
         Yii::$app->response->cookies->add(new Cookie(['name' => 'viewType', 'value' => $viewType]));
     } else {
         if ($cookie = Yii::$app->request->cookies->get('viewType')) {
             $viewType = $cookie->value;
         } else {
             $viewType = 'panel';
             Yii::$app->response->cookies->add(new Cookie(['name' => 'viewType', 'value' => $viewType]));
         }
     }
     $query = Note::find();
     $noteSearch = new NoteSearch();
     $noteSearch->setScenario('own');
     $noteProvider = $noteSearch->search(Yii::$app->request->queryParams, ['user_id' => Yii::$app->user->identity->id]);
     $curDate = getdate();
     $beginOfCurDay = \DateTime::createFromFormat('Y-n-j H:i:s', $curDate['year'] . '-' . $curDate['mon'] . '-' . $curDate['mday'] . ' 00:00:00')->getTimestamp();
     $beginOfCurMonth = \DateTime::createFromFormat('Y-n-j H:i:s', $curDate['year'] . '-' . $curDate['mon'] . '-1 00:00:00')->getTimestamp();
     return $this->render('/notes', ['cur' => 'own', 'viewType' => $viewType, 'notes' => $noteProvider->getModels(), 'pagination' => $noteProvider->pagination, 'sort' => $noteProvider->sort, 'noteSearch' => $noteSearch, 'notesCountDay' => $query->where(['>=', 'created_at', $beginOfCurDay])->andWhere(['user_id' => Yii::$app->user->identity->id])->count(), 'notesCountMonth' => $query->where(['>=', 'created_at', $beginOfCurMonth])->andWhere(['user_id' => Yii::$app->user->identity->id])->count()]);
 }
コード例 #9
0
 public function actionIndex()
 {
     $notes = Note::find()->all();
     return $this->render('list', ['notes' => $notes]);
 }
コード例 #10
0
 /**
  * Find Note by given id
  *
  * @param int $id
  *
  * @return \Illuminate\Support\Collection|null|static|Note
  */
 public function findNoteById($id)
 {
     return Note::find($id);
 }
コード例 #11
0
ファイル: _list.php プロジェクト: hoangngk/adminpanel
<?php

use app\models\Note;
?>
<ul class="media-list">
    <?php 
// by default value of disViewMore is false
$disViewMore = false;
$allNotes = Note::find()->where(['type_area' => $type_area, 'belong_to' => $belong_to])->orderBy('id DESC')->all();
if (count($allNotes) <= count($notes)) {
    $disViewMore = true;
}
if (!empty($notes)) {
    foreach ($notes as $key => $note) {
        ?>
                <li class="media clearfix">
                    <a href="page_ready_user_profile.php" class="pull-left">
                        <img src="/web/upload/avatar/<?php 
        echo $note->user->avatar;
        ?>
" width="64" height="64" alt="Avatar" class="img-circle">
                    </a>
                    <div class="media-body">
                        <span class="text-muted text-right pull-right link-hover">
                            <small>
                                <?php 
        if (strtotime($note->updated_at) > 0) {
            ?>
                                <em><?php 
            echo $note->timeAgo(strtotime($note->updated_at));
            ?>
コード例 #12
0
ファイル: ObjectHelper.php プロジェクト: app-dev-ru/lingnote
 public static function getUserObjects($userID)
 {
     $notes = Note::find()->join('inner join', 'object o', 'o.id = note.id')->where('user_id = :user')->params([':user' => $userID])->all();
     return $notes;
 }
コード例 #13
0
 /**
  * Lists all Note models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Note::find()]);
     $notes = Note::find()->join('INNER JOIN', 'object o', 'o.id = note.id')->where(['o.user_id' => Yii::$app->user->id])->all();
     return $this->render('index', ['models' => $notes]);
 }
コード例 #14
0
 public function actionList()
 {
     $notes = Note::find()->where(['user_id' => Yii::$app->user->identity->getId()])->orderBy($this->getOrderParam())->all();
     return $this->render('list', ['notes' => $notes]);
 }
コード例 #15
0
 /**
  * Deletes an existing Note model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel($id)->delete();
     // get 5 latest notes
     $notes = Note::find()->where(['belong_to' => $this->data_post['belong_to'], 'type_area' => $this->data_post['type_area']])->orderBy('id DESC')->limit(5)->all();
     // merge returned data
     $res_data = array_merge($this->data_post, ['notes' => $notes, 'disViewMore' => false]);
     return ['errors' => '', 'data' => $this->renderPartial('@widget/views/notes/_list', $res_data)];
 }