Example #1
0
 /**
  * Handles AJAX Post Request to submit new Comment
  */
 public function actionPost()
 {
     $this->forcePostRequest();
     $message = Yii::app()->request->getParam('message', "");
     $message = Yii::app()->input->stripClean(trim($message));
     if ($message != "" && !Yii::app()->user->isGuest) {
         $comment = new Comment();
         $comment->message = $message;
         $comment->object_model = get_class($this->parentContent);
         $comment->object_id = $this->parentContent->getPrimaryKey();
         $comment->save();
         File::attachPrecreated($comment, Yii::app()->request->getParam('fileList'));
         // Reload comment to get populated created_at field
         $comment = Comment::model()->findByPk($comment->id);
         $output = $this->widget('application.modules_core.comment.widgets.ShowCommentWidget', array('comment' => $comment, 'justEdited' => true), true);
         Yii::app()->clientScript->render($output);
         echo $output;
     }
 }
Example #2
0
 /**
  * Edits Entry Id
  */
 public function actionEditEntry()
 {
     $messageEntryId = (int) Yii::app()->request->getQuery('messageEntryId');
     $entry = MessageEntry::model()->findByPk($messageEntryId);
     // Check if message entry exists and it´s by this user
     if ($entry == null || $entry->user_id != Yii::app()->user->id) {
         throw new CHttpException(404, 'Could not find message entry!');
     }
     // Reply Form
     if (isset($_POST['MessageEntry'])) {
         $entry->content = $_POST['MessageEntry']['content'];
         if ($entry->validate()) {
             $entry->save();
             File::attachPrecreated($entry, Yii::app()->request->getParam('fileUploaderHiddenGuidField'));
             $this->htmlRedirect($this->createUrl('index', array('id' => $entry->message->id)));
         }
     }
     $this->renderPartial('editEntry', array('entry' => $entry), false, true);
 }
Example #3
0
 /**
  * Handles AJAX Post Request to submit new Comment
  */
 public function actionPost()
 {
     $this->forcePostRequest();
     $target = $this->loadTargetModel();
     $message = Yii::app()->request->getParam('message', "");
     $message = Yii::app()->input->stripClean(trim($message));
     if ($message != "") {
         $comment = new Comment();
         $comment->message = $message;
         $comment->object_model = get_class($target);
         $comment->object_id = $target->id;
         // Check if target has an attribute with space_id
         // When yes, take it
         // We need it for dashboard/getFrontEndInfo
         // To count workspace Items
         try {
             $comment->space_id = $target->content->space_id;
             $workspace = Space::model()->findByPk($comment->space_id);
             // Update Last viewed for Spaces
             if ($workspace != "") {
                 $membership = $workspace->getMembership(Yii::app()->user->id);
                 if ($membership != null) {
                     $membership->scenario = 'last_visit';
                     $membership->last_visit = new CDbExpression('NOW()');
                     $membership->save();
                 }
             }
         } catch (Exception $ex) {
         }
         $comment->save();
         File::attachPrecreated($comment, Yii::app()->request->getParam('fileList'));
     }
     return $this->actionShow();
 }
 public function actionEdit()
 {
     $id = (int) Yii::app()->request->getQuery('id');
     $homePage = WikiPage::model()->contentContainer($this->contentContainer)->findByAttributes(array('is_home' => 1));
     $page = WikiPage::model()->contentContainer($this->contentContainer)->findByAttributes(array('id' => $id));
     if ($page === null) {
         $page = new WikiPage();
         $page->content->setContainer($this->contentContainer);
         $page->content->visibility = Content::VISIBILITY_PRIVATE;
         $page->title = Yii::app()->request->getParam('title');
     }
     if ($page->admin_only && !$page->canAdminister()) {
         throw new CHttpException(403, 'Page not editable!');
     }
     $revision = $page->createRevision();
     if (isset($_POST['WikiPage']) && isset($_POST['WikiPageRevision'])) {
         $page->content->container = $this->contentContainer;
         $page->attributes = $_POST['WikiPage'];
         $revision->attributes = $_POST['WikiPageRevision'];
         if ($page->validate()) {
             $page->save();
             File::attachPrecreated($page, Yii::app()->request->getParam('fileUploaderHiddenGuidField'));
             $revision->wiki_page_id = $page->id;
             if ($revision->validate()) {
                 $revision->save();
                 $this->redirect($this->createContainerUrl('view', array('title' => $page->title)));
             }
         }
     }
     $this->render('edit', array('page' => $page, 'revision' => $revision, 'homePage' => $homePage));
 }
Example #5
0
 public function afterSave()
 {
     // 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 ($this->isNewRecord) {
         // If there are notifyUsers specified by populateByForm() make them follow this content
         foreach ($this->notifyUsersOfNewContent as $user) {
             $this->getUnderlyingObject()->follow($user->id);
             // Fire Notification to user
             $notification = new Notification();
             $notification->class = "ContentCreatedNotification";
             $notification->user_id = $user->id;
             if (get_class($this->container) == 'Space') {
                 $notification->space_id = $this->container->id;
             }
             $notification->source_object_model = $this->object_model;
             $notification->source_object_id = $this->object_id;
             $notification->target_object_model = $this->object_model;
             $notification->target_object_id = $this->object_id;
             $notification->save();
         }
     }
     File::attachPrecreated($this->getUnderlyingObject(), $this->attachFileGuidsAfterSave);
     return parent::afterSave();
 }
 /**
  * Action that renders the view to add a document.<br />
  * The request has to provide the id of the category the document should be created in, in the url parameter 'category_id'.<br />
  * @see views/library/editCategory.php
  * @throws CHttpException 404, if the logged in User misses the rights to access this view.
  */
 public function actionAddDocument()
 {
     $this->checkContainerAccess();
     $category_id = (int) Yii::app()->request->getQuery('category_id');
     $category = LibraryCategory::model()->findByAttributes(array('id' => $category_id));
     $publicCategory = $category->content->isPublic();
     $isCreated = false;
     $lastfile = '';
     // access level 0 may neither create nor edit
     if ($this->accessLevel == 0) {
         throw new CHttpException(404, Yii::t('LibraryModule.exception', 'You miss the rights to add documents!'));
     } else {
         $document = new LibraryDocument();
         $document->date = date('Y-m-d');
         if (LibraryCategory::model()->findByAttributes(array('id' => $category_id)) == null) {
             throw new CHttpException(404, Yii::t('LibraryModule.exception', 'The category you want to create your document in could not be found!'));
         }
         if ($this->accessLevel == 1 && $category->content->isPublic()) {
             throw new CHttpException(404, Yii::t('LibraryModule.exception', 'You miss the rights to add documents to public categories!'));
         }
         $document->category_id = $category_id;
         $isCreated = true;
     }
     // if form content is sent back, validate and save
     if (isset($_POST['LibraryDocument'])) {
         $_POST = Yii::app()->input->stripClean($_POST);
         $document->attributes = $_POST['LibraryDocument'];
         $document->content->container = $this->contentContainer;
         $document->content->visibility = $category->content->visibility;
         // Handle uploaded files. array_filter removes empty elements.
         $pre_files = array_filter(explode(",", Yii::app()->request->getParam('fileList')));
         $has_files = count($pre_files) > 0;
         $lastfile = array_pop($pre_files);
         // Validate and save item. At least one file needs to be attached.
         if ($document->validate()) {
             if (!$has_files) {
                 $document->addError('file', Yii::t('LibraryModule.base', 'You must upload a file.'));
             }
             if ($has_files && $document->validate()) {
                 $document->save();
                 // Attach the uploaded file. If multiple were uploaded, just attach the last one.
                 // TODO: Fix the ugly mess with multiple uploaded files.
                 File::attachPrecreated($document, $lastfile);
                 $this->redirect(Yii::app()->createUrl('library/library/showlibrary', array($this->guidParamName => $this->contentContainer->guid)));
             }
         }
     }
     // Render document edit form
     $this->render('editDocument', array($this->guidParamName => $this->contentContainer->guid, 'document' => $document, 'isCreated' => $isCreated));
 }