public function addDefaultModels()
 {
     $module = Yii::$app->getModule('comment');
     foreach ($module->defaultModels as $modelClass) {
         if (class_exists($modelClass)) {
             $model = new CommentModel(['scenario' => 'admin-create', 'name' => $modelClass, 'status_id' => CommentModel::STATUS_ENABLED]);
             if ($model->save()) {
                 echo 'Comment model class ' . $modelClass . ' added' . PHP_EOL;
             }
         }
     }
 }
 /**
  * Finds the CommentModel model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CommentModel the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CommentModel::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * Comments list page.
  */
 public function actionIndex()
 {
     $searchModel = new CommentSearch();
     $dataProvider = $searchModel->search(Yii::$app->request->get());
     $statusArray = Comment::statusLabels();
     $modelArray = CommentModel::getModelArray();
     return $this->render('index', ['dataProvider' => $dataProvider, 'searchModel' => $searchModel, 'statusArray' => $statusArray, 'modelArray' => $modelArray]);
 }
 /**
  * Find model by ID.
  *
  * @param integer|array $id Comment ID
  * @return null|CommentModel
  * @throws NotFoundHttpException
  */
 protected function findModel($id)
 {
     /** @var CommentModel $model */
     $commentModelClass = CommentModel::className();
     if (($model = $commentModelClass::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException(Yii::t('app', 'The requested page does not exist.'));
     }
 }
Beispiel #5
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $class = $this->model;
     /** @var CommentModel $classModel */
     $classModel = CommentModel::findIdentity($class::className());
     if ($classModel) {
         $model = new Comment(['scenario' => 'create']);
         $model->model_id = $this->model->id;
         // NewsPost->id, Page->id
         $model->model_class = $classModel->id;
         // crc32(NewsPost::class), crc32(Page::class)
         $models = Comment::getTree($model->model_id, $model->model_class);
         return $this->render('index', ['models' => $models, 'model' => $model, 'route' => $this->route]);
     }
     return '';
 }
Beispiel #6
0
 /**
  * Executes the widget.
  * @return string the result of widget execution to be outputted.
  */
 public function run()
 {
     /* @var $module Module */
     $module = Module::$name;
     //Get comment model class from `comment` Module
     $commentModelClass = CommentModel::className();
     //Get entity from widget and hash it.
     $entity = $this->model;
     $entityId = $entity->{$this->entityIdAttribute};
     $entity = hash('crc32', $entity::className());
     //Get comment tree by entity and entityId
     $comments = $commentModelClass::getTree($entity, $entityId, $this->maxLevel);
     //Create comment model
     $commentModel = Yii::createObject($commentModelClass);
     //Encrypt entity and entityId values
     $encryptedEntity = Yii::$app->getSecurity()->encryptByKey(Json::encode(['entity' => $entity, 'entityId' => $entityId]), $module);
     return $this->render('index', ['comments' => $comments, 'commentModel' => $commentModel, 'maxLevel' => $this->maxLevel, 'encryptedEntity' => $encryptedEntity, 'pjaxContainerId' => $this->pjaxContainerId]);
 }
Beispiel #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getModel()
 {
     /** @var ActiveRecord $class */
     $class = CommentModel::find()->where(['id' => $this->model_class])->asArray()->one();
     $model = $class->name;
     return $this->hasOne($model::className(), ['id' => 'model_id']);
 }
Beispiel #8
0
 public function getArticleCommentCount()
 {
     return $this->hasMany(CommentModel::className(), ['entityId' => 'id'])->count();
 }
Beispiel #9
0
    echo Html::a('Новый пользователь?', ['/user/secure/signup']);
    ?>
<br/>
            </div>
        </div>
    </div>
<?php 
} else {
    ?>
    <div class="panels panel-default">
        <div class="panel-body">
            <?php 
    $profile = Profile::findOne(['user_id' => Yii::$app->user->identity->getId()]);
    ?>
            <?php 
    $comment = CommentModel::find()->where(['createdBy' => Yii::$app->user->identity->getId()])->andWhere(['status' => 1])->count();
    ?>
            <div class="row">
                <div class="col-xs-4"><?php 
    echo $profile->getAvatarImg();
    ?>
<br/></div>
                <div class="col-xs-8">
                    <i class="fa fa-user"></i> <?php 
    echo $profile->name;
    ?>
<br/>
                    <i class="fa fa-comments"></i> <?php 
    echo $comment;
    ?>
                </div>
 /**
  * Find model by ID.
  *
  * @param integer|array $id Model ID
  *
  * @return CommentModel Model
  *
  * @throws HttpException 404 error if model not found
  */
 protected function findModel($id)
 {
     if (is_array($id)) {
         /** @var CommentModel $model */
         $model = CommentModel::findAll($id);
     } else {
         /** @var CommentModel $model */
         $model = CommentModel::findOne($id);
     }
     if ($model !== null) {
         return $model;
     } else {
         throw new HttpException(404);
     }
 }
 /**
  * Returns the validation rules for attributes.
  * @return array validation rules
  */
 public function rules()
 {
     return ArrayHelper::merge([[['id', 'createdBy', 'content', 'status'], 'safe']], parent::rules());
 }
 public function actionDelete($id)
 {
     //comment
     $commentUser = CommentModel::find()->where(['createdBy' => $id])->all();
     if ($commentUser) {
         $commentUser->deleteAll();
     }
     $this->findModel($id)->delete();
     return $this->redirect(['index']);
 }