Пример #1
0
 /**
  * Handles AJAX Request for Comment Deletion.
  * Currently this is only allowed for the Comment Owner.
  */
 public function actionDelete()
 {
     $this->forcePostRequest();
     $this->loadContentAddon(Comment::className(), Yii::$app->request->get('id'));
     if ($this->contentAddon->canDelete()) {
         $this->contentAddon->delete();
     } else {
         throw new HttpException(500, Yii::t('CommentModule.controllers_CommentController', 'Insufficent permissions!'));
     }
 }
 /**
  * Load all posted files from the database and get an array of them.
  *
  * @param array $filesOrder
  *            orderBy array appended to the files query
  * @param array $foldersOrder
  *            currently unused
  * @return Ambigous <multitype:, multitype:\yii\db\ActiveRecord >
  */
 protected function getAllPostedFilesList($filesOrder = NULL, $foldersOrder = NULL)
 {
     // set ordering default
     if (!$filesOrder) {
         $filesOrder = ['file.updated_at' => SORT_DESC, 'file.title' => SORT_ASC];
     }
     // Get Posted Files
     $query = \humhub\modules\file\models\File::find();
     // join comments to the file if available
     $query->join('LEFT JOIN', 'comment', '(file.object_id=comment.id AND file.object_model=' . Yii::$app->db->quoteValue(Comment::className()) . ')');
     // join parent post of comment or file
     $query->join('LEFT JOIN', 'content', '(comment.object_model=content.object_model AND comment.object_id=content.object_id) OR (file.object_model=content.object_model AND file.object_id=content.object_id)');
     if (version_compare(Yii::$app->version, '1.1', 'lt')) {
         // select only the one for the given content container for Yii version < 1.1
         if ($this->contentContainer instanceof \humhub\modules\user\models\User) {
             $query->andWhere(['content.user_id' => $this->contentContainer->id]);
             $query->andWhere(['IS', 'content.space_id', new \yii\db\Expression('NULL')]);
         } else {
             $query->andWhere(['content.space_id' => $this->contentContainer->id]);
         }
     } else {
         // select only the one for the given content container for Yii version >= 1.1
         $query->andWhere(['content.contentcontainer_id' => $this->contentContainer->contentContainerRecord->id]);
     }
     // only accept Posts as the base content, so stuff from sumbmodules like files itsself or gallery will be excluded
     $query->andWhere(['or', ['=', 'comment.object_model', Post::className()], ['=', 'file.object_model', Post::className()]]);
     // Get Files from comments
     return ['postedFiles' => $query->orderBy($filesOrder)->all()];
 }
 public function up()
 {
     $this->renameClass('Comment', Comment::className());
 }
 /**
  * Action to list all posted files from the content container.
  * @return string
  */
 public function actionAllPostedFiles()
 {
     $items = $this->getAllPostedFiles();
     $content_file_wrapper = [];
     foreach ($items as $file) {
         $searchItem = $file;
         // if the item is connected to a Comment, we have to search for the corresponding Post
         if ($file->object_model === Comment::className()) {
             $searchItem = Comment::findOne(['id' => $file->object_id]);
         }
         $query = Content::find();
         $query->andWhere(['content.object_id' => $searchItem->object_id, 'content.object_model' => $searchItem->object_model]);
         $content_file_wrapper[] = ['file' => $file, 'content' => $query->one()];
     }
     return $this->render('allPostedFiles', ['contentContainer' => $this->contentContainer, 'items' => $content_file_wrapper]);
 }
Пример #5
0
 /**
  * Get the post the file is connected to.
  */
 public static function getBasePost($file = null)
 {
     if ($file === null) {
         return null;
     }
     $searchItem = $file;
     // if the item is connected to a Comment, we have to search for the corresponding Post
     if ($file->object_model === Comment::className()) {
         $searchItem = Comment::findOne(['id' => $file->object_id]);
     }
     $query = Content::find();
     $query->andWhere(['content.object_id' => $searchItem->object_id, 'content.object_model' => $searchItem->object_model]);
     return $query->one();
 }
Пример #6
0
 /**
  * Get the post the file is connected to.
  * @param File $basefile the file.
  */
 public static function getBasePost($file = null)
 {
     if ($file === null) {
         return null;
     }
     $searchItem = $file;
     // if the item is connected to a Comment, we have to search for the corresponding Post
     if ($file->object_model === Comment::className()) {
         $searchItem = Comment::findOne(['id' => $file->object_id]);
     }
     $return = Post::findOne(['id' => $searchItem->object_id]);
 }