/**
  * @inheritdoc
  */
 public function run()
 {
     if (\Yii::$app->user->isGuest) {
         return;
     }
     return $this->render('notificationSwitchLink', array('content' => $this->content->content, 'state' => $this->content->isFollowedByUser(\Yii::$app->user->id, true)));
 }
Exemplo n.º 2
0
 /**
  * Creates the given ContentActiveRecord based on given submitted form information.
  * 
  * - Automatically assigns ContentContainer
  * - Access Check
  * - User Notification / File Uploads
  * - Reloads Wall after successfull creation or returns error json
  * 
  * [See guide section](guide:dev-module-stream.md#CreateContentForm)
  * 
  * @param ContentActiveRecord $record
  * @return string json 
  */
 public static function create(ContentActiveRecord $record)
 {
     Yii::$app->response->format = 'json';
     // Set Content Container
     $contentContainer = null;
     $containerClass = Yii::$app->request->post('containerClass');
     $containerGuid = Yii::$app->request->post('containerGuid', "");
     if ($containerClass === User::className()) {
         $contentContainer = User::findOne(['guid' => $containerGuid]);
         $record->content->visibility = 1;
     } elseif ($containerClass === Space::className()) {
         $contentContainer = Space::findOne(['guid' => $containerGuid]);
         $record->content->visibility = Yii::$app->request->post('visibility');
     }
     $record->content->container = $contentContainer;
     // Handle Notify User Features of ContentFormWidget
     // ToDo: Check permissions of user guids
     $userGuids = Yii::$app->request->post('notifyUserInput');
     if ($userGuids != "") {
         foreach (explode(",", $userGuids) as $guid) {
             $user = User::findOne(['guid' => trim($guid)]);
             if ($user) {
                 $record->content->notifyUsersOfNewContent[] = $user;
             }
         }
     }
     // Store List of attached Files to add them after Save
     $record->content->attachFileGuidsAfterSave = Yii::$app->request->post('fileList');
     if ($record->validate() && $record->save()) {
         return array('wallEntryId' => $record->content->getFirstWallEntryId());
     }
     return array('errors' => $record->getErrors());
 }
Exemplo n.º 3
0
 public function beforeSave($insert)
 {
     if ($this->sort_order == "") {
         $this->sort_order = 0;
     }
     return parent::beforeSave($insert);
 }
 /**
  * Automatically loads the by content or content addon given by parameter.
  * className & id
  *
  * @return type
  */
 public function beforeAction($action)
 {
     $modelClass = Yii::$app->request->get('contentModel');
     $pk = (int) Yii::$app->request->get('contentId');
     // Fixme
     if ($modelClass == '') {
         $modelClass = Yii::$app->request->post('contentModel');
         $pk = (int) Yii::$app->request->post('contentId');
     }
     if ($modelClass == "" || $pk == "") {
         throw new HttpException(500, 'Model & ID parameter required!');
     }
     \humhub\libs\Helpers::CheckClassType($modelClass, array(ContentAddonActiveRecord::className(), ContentActiveRecord::className()));
     $target = $modelClass::findOne(['id' => $pk]);
     if ($target === null) {
         throw new HttpException(500, 'Could not find underlying content or content addon record!');
     }
     if ($target instanceof ContentAddonActiveRecord) {
         $this->parentContentAddon = $target;
         $this->parentContent = $target->getSource();
     } else {
         $this->parentContent = $target;
     }
     if (!$this->parentContent->content->canRead()) {
         throw new HttpException(403, 'Access denied!');
     }
     $this->contentModel = get_class($target);
     $this->contentId = $target->getPrimaryKey();
     return parent::beforeAction($action);
 }
 public function beforeSave($insert)
 {
     if ($this->parent_folder_id == "") {
         $this->parent_folder_id = 0;
     }
     return parent::beforeSave($insert);
 }
 public function afterDelete()
 {
     foreach ($this->links as $link) {
         $link->delete();
     }
     parent::afterDelete();
 }
Exemplo n.º 7
0
 /**
  * Before Save Addons
  *
  * @return type
  */
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     // Handle mentioned users
     \humhub\modules\user\models\Mentioning::parse($this, $this->message);
     return true;
 }
 public function afterFind()
 {
     if ($this->type == self::TYPE_IFRAME || $this->type == self::TYPE_LINK) {
         $this->url = $this->page_content;
     }
     return parent::afterFind();
 }
 public function afterDelete()
 {
     //delete events not included in ical file
     $to_delete = CalendarEntry::find()->where(["external_source_id" => $this->id])->all();
     foreach ($to_delete as $event) {
         $event->delete();
     }
     parent::afterDelete();
 }
Exemplo n.º 10
0
 /**
  * Deletes a Poll including its dependencies.
  */
 public function beforeDelete()
 {
     foreach ($this->answers as $answer) {
         foreach ($answer->votes as $answerUser) {
             $answerUser->delete();
         }
         $answer->delete();
     }
     return parent::beforeDelete();
 }
Exemplo n.º 11
0
 /**
  * Loads Content Addon
  * We also validates that the content addon corresponds to the loaded content.
  *
  * @param string $className
  * @param int $pk
  */
 public function loadContentAddon($className, $pk)
 {
     if (!\humhub\libs\Helpers::CheckClassType($className, ContentAddonActiveRecord::className())) {
         throw new \yii\base\Exception("Given className is not a content addon model!");
     }
     $target = $className::findOne(['id' => $pk]);
     if ($target === null) {
         throw new HttpException(500, 'Could not find content addon record!');
     }
     if ($target->object_model != get_class($this->parentContent) && $target->object_id != $this->parentContent->getPrimaryKey()) {
         throw new HttpException(500, 'Content addon not belongs to given content record!');
     }
     $this->contentAddon = $target;
 }
 public function afterSave($insert, $changedAttributes)
 {
     parent::afterSave($insert, $changedAttributes);
     if ($insert) {
         // Creator automatically attends to this event
         $participant = new CalendarEntryParticipant();
         $participant->user_id = Yii::$app->user->id;
         $participant->calendar_entry_id = $this->id;
         $participant->participation_state = CalendarEntryParticipant::PARTICIPATION_STATE_ACCEPTED;
         $participant->save();
     }
     return;
 }
Exemplo n.º 13
0
<?php

use humhub\modules\search\engine\Search;
use humhub\modules\user\Events;
use humhub\commands\IntegrityController;
use humhub\modules\content\components\ContentAddonActiveRecord;
use humhub\modules\content\components\ContentActiveRecord;
use humhub\commands\CronController;
return ['id' => 'user', 'class' => \humhub\modules\user\Module::className(), 'isCoreModule' => true, 'urlManagerRules' => [['class' => 'humhub\\modules\\user\\components\\UrlRule']], 'events' => [['class' => Search::className(), 'event' => Search::EVENT_ON_REBUILD, 'callback' => array(Events::className(), 'onSearchRebuild')], ['class' => ContentActiveRecord::className(), 'event' => ContentActiveRecord::EVENT_BEFORE_DELETE, 'callback' => array(Events::className(), 'onContentDelete')], ['class' => ContentAddonActiveRecord::className(), 'event' => ContentAddonActiveRecord::EVENT_BEFORE_DELETE, 'callback' => array(Events::className(), 'onContentDelete')], ['class' => IntegrityController::className(), 'event' => IntegrityController::EVENT_ON_RUN, 'callback' => array(Events::className(), 'onIntegrityCheck')], ['class' => CronController::className(), 'event' => CronController::EVENT_ON_HOURLY_RUN, 'callback' => [Events::className(), 'onHourlyCron']]]];
Exemplo n.º 14
0
 /**
  * Creates the given ContentActiveRecord based on given submitted form information.
  *
  * - Automatically assigns ContentContainer
  * - Access Check
  * - User Notification / File Uploads
  * - Reloads Wall after successfull creation or returns error json
  *
  * [See guide section](guide:dev-module-stream.md#CreateContentForm)
  *
  * @param ContentActiveRecord $record
  * @return string json
  */
 public static function create(ContentActiveRecord $record, ContentContainerActiveRecord $contentContainer = null)
 {
     Yii::$app->response->format = 'json';
     $visibility = Yii::$app->request->post('visibility');
     if ($visibility == Content::VISIBILITY_PUBLIC && !$contentContainer->permissionManager->can(new \humhub\modules\content\permissions\CreatePublicContent())) {
         $visibility = Content::VISIBILITY_PRIVATE;
     }
     $record->content->visibility = $visibility;
     $record->content->container = $contentContainer;
     // Handle Notify User Features of ContentFormWidget
     // ToDo: Check permissions of user guids
     $userGuids = Yii::$app->request->post('notifyUserInput');
     if ($userGuids != "") {
         foreach (explode(",", $userGuids) as $guid) {
             $user = User::findOne(['guid' => trim($guid)]);
             if ($user) {
                 $record->content->notifyUsersOfNewContent[] = $user;
             }
         }
     }
     // Store List of attached Files to add them after Save
     $record->content->attachFileGuidsAfterSave = Yii::$app->request->post('fileList');
     if ($record->validate() && $record->save()) {
         return array('wallEntryId' => $record->content->getFirstWallEntryId());
     }
     return array('errors' => $record->getErrors());
 }
Exemplo n.º 15
0
 public function afterFind()
 {
     foreach ($this->assignedUsers as $user) {
         $this->assignedUserGuids .= $user->guid . ",";
     }
     return parent::afterFind();
 }
Exemplo n.º 16
0
<?php

use humhub\modules\content\Events;
use humhub\commands\CronController;
use humhub\commands\IntegrityController;
use humhub\modules\content\widgets\WallEntryControls;
use humhub\modules\content\widgets\WallEntryAddons;
use humhub\modules\user\models\User;
use humhub\modules\space\models\Space;
use humhub\modules\search\engine\Search;
use humhub\modules\content\components\ContentActiveRecord;
return ['id' => 'content', 'class' => \humhub\modules\content\Module::className(), 'isCoreModule' => true, 'events' => array(['class' => IntegrityController::className(), 'event' => IntegrityController::EVENT_ON_RUN, 'callback' => array(Events::className(), 'onIntegrityCheck')], ['class' => WallEntryControls::className(), 'event' => WallEntryControls::EVENT_INIT, 'callback' => array(Events::className(), 'onWallEntryControlsInit')], ['class' => WallEntryAddons::className(), 'event' => WallEntryAddons::EVENT_INIT, 'callback' => array(Events::className(), 'onWallEntryAddonInit')], ['class' => CronController::className(), 'event' => CronController::EVENT_ON_HOURLY_RUN, 'callback' => [Events::className(), 'onCronRun']], ['class' => CronController::className(), 'event' => CronController::EVENT_ON_DAILY_RUN, 'callback' => [Events::className(), 'onCronRun']], ['class' => User::className(), 'event' => User::EVENT_BEFORE_DELETE, 'callback' => [Events::className(), 'onUserDelete']], ['class' => Space::className(), 'event' => User::EVENT_BEFORE_DELETE, 'callback' => [Events::className(), 'onSpaceDelete']], ['class' => Search::className(), 'event' => Search::EVENT_ON_REBUILD, 'callback' => [Events::className(), 'onSearchRebuild']], ['class' => ContentActiveRecord::className(), 'event' => ContentActiveRecord::EVENT_AFTER_INSERT, 'callback' => [Events::className(), 'onContentActiveRecordSave']], ['class' => ContentActiveRecord::className(), 'event' => ContentActiveRecord::EVENT_AFTER_UPDATE, 'callback' => [Events::className(), 'onContentActiveRecordSave']], ['class' => ContentActiveRecord::className(), 'event' => ContentActiveRecord::EVENT_AFTER_DELETE, 'callback' => [Events::className(), 'onContentActiveRecordDelete']])];
Exemplo n.º 17
0
 /**
  * @inheritdoc
  */
 public function behaviors()
 {
     return [['class' => \humhub\components\behaviors\PolymorphicRelation::className(), 'mustBeInstanceOf' => [ContentActiveRecord::className(), ContentContainerActiveRecord::className(), ContentAddonActiveRecord::className()]]];
 }
 public function beforeDelete()
 {
     foreach ($this->revisions as $revision) {
         $revision->delete();
     }
     return parent::beforeDelete();
 }
Exemplo n.º 19
0
 public function behaviors()
 {
     return [['class' => \humhub\components\behaviors\PolymorphicRelation::className(), 'mustBeInstanceOf' => array(ContentActiveRecord::className())], ['class' => \humhub\components\behaviors\GUID::className()]];
 }
Exemplo n.º 20
0
<?php

use humhub\modules\comment\Events;
use humhub\modules\user\models\User;
use humhub\modules\content\components\ContentActiveRecord;
use humhub\commands\IntegrityController;
use humhub\modules\content\widgets\WallEntryAddons;
use humhub\modules\content\widgets\WallEntryLinks;
return ['id' => 'comment', 'class' => \humhub\modules\comment\Module::className(), 'isCoreModule' => true, 'events' => array(array('class' => User::className(), 'event' => User::EVENT_BEFORE_DELETE, 'callback' => array(Events::className(), 'onUserDelete')), array('class' => ContentActiveRecord::className(), 'event' => ContentActiveRecord::EVENT_BEFORE_DELETE, 'callback' => array(Events::className(), 'onContentDelete')), array('class' => IntegrityController::className(), 'event' => IntegrityController::EVENT_ON_RUN, 'callback' => array(Events::className(), 'onIntegrityCheck')), array('class' => WallEntryLinks::className(), 'event' => WallEntryLinks::EVENT_INIT, 'callback' => array(Events::className(), 'onWallEntryLinksInit')), array('class' => WallEntryAddons::className(), 'event' => WallEntryAddons::EVENT_INIT, 'callback' => array(Events::className(), 'onWallEntryAddonInit')))];