Example #1
0
 /**
  * Redirects to given HActiveRecordContent or HActiveRecordContentAddon
  */
 public function actionIndex()
 {
     $id = (int) Yii::$app->request->get('id', "");
     $content = Content::findOne(['id' => $id]);
     if ($content !== null) {
         return $this->redirect($content->getUrl());
     }
     throw new HttpException(404, Yii::t('ContentModule.controllers_PermaController', 'Could not find requested content!'));
 }
 public function disableContentContainer(\humhub\modules\content\components\ContentContainerActiveRecord $container)
 {
     $folders = Content::findAll(['object_model' => Folder::className(), 'space_id' => $container->id]);
     foreach ($folders as $key => $folderContent) {
         $folder = Folder::findOne(['id' => $folderContent->object_id]);
         $folder->delete();
     }
     $files = Content::findAll(['object_model' => File::className(), 'space_id' => $container->id]);
     foreach ($files as $key => $fileContent) {
         $file = File::findOne(['id' => $fileContent->object_id]);
         $file->delete();
     }
 }
 public function actionDeleteContent()
 {
     $this->forcePostRequest();
     $model = Yii::$app->request->get('model');
     $id = Yii::$app->request->get('id');
     $content = Content::get($model, $id);
     if ($content->content->canDelete()) {
         $content->delete();
     }
     if (!$content->content->space_id) {
         return $this->htmlRedirect(Url::to(['/reportcontent/admin']));
     } else {
         $space = Space::findOne(['id' => $content->content->space_id]);
         return $this->htmlRedirect($space->createUrl('/reportcontent/space-admin'));
     }
 }
Example #4
0
 /**
  * @inheritdoc
  */
 public function run()
 {
     $postCount = Content::find()->where(['object_model' => Post::className(), 'contentcontainer_id' => $this->space->contentContainerRecord->id])->count();
     return $this->render('header', array('space' => $this->space, 'postCount' => $postCount));
 }
Example #5
0
 /**
  * On rebuild of the search index, rebuild all user records
  *
  * @param type $event
  */
 public static function onSearchRebuild($event)
 {
     foreach (Content::find()->all() as $content) {
         $contentObject = $content->getPolymorphicRelation();
         if ($contentObject instanceof \humhub\modules\search\interfaces\Searchable) {
             Yii::$app->search->add($contentObject);
         }
     }
 }
 public function actionNotificationSwitch()
 {
     $this->forcePostRequest();
     $json = array();
     $json['success'] = false;
     // default
     $id = (int) Yii::$app->request->getParam('id', "");
     $className = Yii::$app->request->getParam('className', "");
     $switch = Yii::$app->request->getParam('switch', true);
     $object = Content::Get($className, $id);
     if ($object != null) {
         $object->follow(Yii::$app->user->id, $switch == 1 ? true : false);
         $json['success'] = true;
     }
     // returns JSON
     echo CJSON::encode($json);
     Yii::$app->end();
 }
 /**
  * Related Content model
  * 
  * @return \yii\db\ActiveQuery
  */
 public function getContent()
 {
     return $this->hasOne(Content::className(), ['object_id' => 'id'])->andWhere(['content.object_model' => self::className()]);
 }
 public function getContent()
 {
     return $this->hasOne(Content::className(), ['object_id' => 'object_id', 'object_model' => 'object_model']);
 }
Example #9
0
 public function getContent()
 {
     return $this->hasOne(Content::className(), ['id' => 'content_id']);
 }
 public function getBaseContent()
 {
     $query = $this->hasOne(\humhub\modules\content\models\Content::className(), ['object_id' => 'id']);
     $query->andWhere(['file.object_model' => self::className()]);
     return $query;
 }
 /**
  * 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]);
 }
 public function actionNotificationSwitch()
 {
     Yii::$app->response->format = 'json';
     $this->forcePostRequest();
     $json = array();
     $json['success'] = false;
     // default
     $content = Content::findOne(['id' => Yii::$app->request->get('id', "")]);
     if ($content !== null) {
         $switch = Yii::$app->request->get('switch', true) == 1 ? true : false;
         $obj = $content->getPolymorphicRelation();
         $obj->follow(Yii::$app->user->id, $switch);
         $json['success'] = true;
     }
     return $json;
 }
 public static function getIdFromPath($path, $contentContainer, $separator = '/')
 {
     $titles = array_reverse(explode($separator, $path));
     if (sizeof($titles) <= 0) {
         return null;
     }
     $folders = Folder::find()->contentContainer($contentContainer)->readable()->where(['title' => $titles[0]])->all();
     if (sizeof($folders) <= 0) {
         return null;
     }
     unset($titles[0]);
     foreach ($titles as $index => $title) {
         if (sizeof($folders) <= 0) {
             return null;
         }
     }
     $query = $this->hasOne(\humhub\modules\content\models\Content::className(), ['object_id' => 'id']);
     $query->andWhere(['file.object_model' => self::className()]);
 }
Example #14
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();
 }