public function actionEdit() { $id = (int) Yii::$app->request->get('id'); $page = WikiPage::find()->contentContainer($this->contentContainer)->readable()->where(['wiki_page.id' => $id])->one(); if ($page === null) { $page = new WikiPage(); $page->content->setContainer($this->contentContainer); $page->content->visibility = Content::VISIBILITY_PRIVATE; $page->title = Yii::$app->request->get('title'); } if ($page->admin_only && !$page->canAdminister()) { throw new HttpException(403, 'Page not editable!'); } $revision = $page->createRevision(); if ($page->load(Yii::$app->request->post()) && $revision->load(Yii::$app->request->post())) { $page->content->container = $this->contentContainer; if ($page->validate()) { $page->save(); File::attachPrecreated($page, Yii::$app->request->post('fileUploaderHiddenGuidField')); $revision->wiki_page_id = $page->id; if ($revision->validate()) { $revision->save(); return $this->redirect($this->contentContainer->createUrl('view', array('title' => $page->title))); } } } return $this->render('edit', ['page' => $page, 'revision' => $revision, 'homePage' => $this->getHomePage(), 'contentContainer' => $this->contentContainer]); }
/** * Handles AJAX Post Request to submit new Comment */ public function actionPost() { $this->forcePostRequest(); if (Yii::$app->user->isGuest) { throw new HttpException(403, 'Guests can not comment.'); } if (!Yii::$app->getModule('comment')->canComment($this->parentContent->content)) { throw new HttpException(403, 'You are not allowed to comment.'); } $message = Yii::$app->request->post('message'); $files = Yii::$app->request->post('fileList'); if (trim($message) === '' && trim($files) === '') { // do not create empty comments return ''; } $comment = new Comment(); $comment->message = $message; $comment->object_model = $this->parentContent->className(); $comment->object_id = $this->parentContent->getPrimaryKey(); $comment->save(); \humhub\modules\file\models\File::attachPrecreated($comment, $files); // Reload comment to get populated created_at field $comment->refresh(); return $this->renderAjaxContent(\humhub\modules\comment\widgets\Comment::widget(['comment' => $comment, 'justEdited' => true])); }
public function actionEdit() { $this->adminOnly(); $page = ContainerPage::find()->contentContainer($this->contentContainer)->where(['custom_pages_container_page.id' => Yii::$app->request->get('id')])->one(); if ($page === null) { $page = new ContainerPage(); $page->content->container = $this->contentContainer; $page->type = (int) Yii::$app->request->get('type'); } if ($page->load(Yii::$app->request->post()) && $page->validate() && $page->save()) { \humhub\modules\file\models\File::attachPrecreated($page, Yii::$app->request->post('fileUploaderHiddenGuidField')); return $this->redirect($this->contentContainer->createUrl('list')); } return $this->render('edit', array('page' => $page)); }
public function actionEdit() { $page = Page::findOne(['id' => Yii::$app->request->get('id')]); if ($page === null) { $page = new Page(); $page->type = (int) Yii::$app->request->get('type'); } if ($page->load(Yii::$app->request->post()) && $page->validate() && $page->save()) { if ($page->type == Page::TYPE_MARKDOWN) { \humhub\modules\file\models\File::attachPrecreated($page, Yii::$app->request->post('fileUploaderHiddenGuidField')); } return $this->redirect(['index']); } return $this->render('edit', array('page' => $page)); }
/** * Handles AJAX Post Request to submit new Comment */ public function actionPost() { $this->forcePostRequest(); $message = Yii::$app->request->post('message'); if ($message != "" && !Yii::$app->user->isGuest) { $comment = new Comment(); $comment->message = $message; $comment->object_model = $this->parentContent->className(); $comment->object_id = $this->parentContent->getPrimaryKey(); $comment->save(); \humhub\modules\file\models\File::attachPrecreated($comment, Yii::$app->request->post('fileList')); // Reload comment to get populated created_at field $comment = Comment::findOne(['id' => $comment->id]); return $this->renderAjaxContent(\humhub\modules\comment\widgets\Comment::widget(['comment' => $comment, 'justEdited' => true])); } }
public function afterSave($insert, $changedAttributes) { // Loop over each eall entry and make sure its update_at / update_by // will also updated. (Sorting wall against update) foreach ($this->getWallEntries() as $wallEntry) { $wallEntry->save(); } if ($insert) { foreach ($this->notifyUsersOfNewContent as $user) { $this->getPolymorphicRelation()->follow($user->id); } $notification = new \humhub\modules\content\notifications\ContentCreated(); $notification->source = $this->getPolymorphicRelation(); $notification->originator = $this->user; $notification->sendBulk($this->notifyUsersOfNewContent); if (!$this->getPolymorphicRelation() instanceof \humhub\modules\activity\models\Activity) { $activity = new \humhub\modules\content\activities\ContentCreated(); $activity->source = $this->getPolymorphicRelation(); $activity->create(); } } \humhub\modules\file\models\File::attachPrecreated($this->getPolymorphicRelation(), $this->attachFileGuidsAfterSave); return parent::afterSave($insert, $changedAttributes); }
/** * Edits Entry Id */ public function actionEditEntry() { $messageEntryId = (int) Yii::$app->request->get('messageEntryId'); $entry = MessageEntry::findOne(['id' => $messageEntryId]); // Check if message entry exists and it´s by this user if ($entry == null || $entry->user_id != Yii::$app->user->id) { throw new HttpException(404, 'Could not find message entry!'); } if ($entry->load(Yii::$app->request->post()) && $entry->validate()) { // ? //$entry->content = $_POST['MessageEntry']['content']; $entry->save(); File::attachPrecreated($entry, Yii::$app->request->get('fileUploaderHiddenGuidField')); return $this->htmlRedirect(['index', 'id' => $entry->message->id]); } return $this->renderAjax('editEntry', array('entry' => $entry)); }