/** * Draw the widget */ public function run() { $files = array(); if ($this->object !== null) { if ($this->object->isNewRecord && $this->object->getRelation('content', false) !== null) { $files = File::findAll(['guid' => array_map('trim', explode(',', $this->object->content->attachFileGuidsAfterSave))]); } else { $files = File::getFilesOfObject($this->object); } } return $this->render('fileUploadList', array('uploaderId' => $this->uploaderId, 'files' => $files)); }
public function beforeSave($insert) { if ($this->thumbnail_link == "") { $this->thumbnail_link = ""; } return parent::beforeSave($insert); }
public function beforeDelete() { $notification = new \humhub\modules\tasks\notifications\Assigned(); $notification->source = $this->task; $notification->send($this->user); return parent::beforeDelete(); }
public function afterFind() { if ($this->type == self::TYPE_IFRAME || $this->type == self::TYPE_LINK) { $this->url = $this->content; } return parent::afterFind(); }
public function beforeSave($insert) { if ($this->isNewRecord) { // Updates the updated_at attribute $this->message->save(); } return parent::beforeSave($insert); }
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { if ($insert) { if ($this->group !== null && $this->group->space !== null) { $this->group->space->addMember($this->user->id); } } parent::afterSave($insert, $changedAttributes); }
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { $mentionedSource = $this->getPolymorphicRelation(); // Send mentioned notification $notification = new \humhub\modules\user\notifications\Mentioned(); $notification->source = $mentionedSource; if ($mentionedSource instanceof ContentActiveRecord) { $notification->originator = $mentionedSource->content->user; } elseif ($mentionedSource instanceof ContentAddonActiveRecord) { $notification->originator = $mentionedSource->user; } else { throw new \yii\base\Exception("Invalid polymorphic relation!"); } $notification->send($this->user); return parent::afterSave($insert, $changedAttributes); }
public function afterSave($insert, $changedAttributes) { $activity = null; if ($this->participation_state == self::PARTICIPATION_STATE_ACCEPTED) { $activity = new \humhub\modules\calendar\activities\ResponseAttend(); } elseif ($this->participation_state == self::PARTICIPATION_STATE_MAYBE) { $activity = new \humhub\modules\calendar\activities\ResponseMaybe(); } elseif ($this->participation_state == self::PARTICIPATION_STATE_DECLINED) { $activity = new \humhub\modules\calendar\activities\ResponseDeclined(); } else { throw new \yii\base\Exception("Invalid participation state!"); } $activity->source = $this->calendarEntry; $activity->originator = $this->user; $activity->create(); return parent::afterSave($insert, $changedAttributes); }
<?php use humhub\modules\notification\Module; use humhub\modules\notification\Events; use humhub\modules\user\models\User; use humhub\modules\space\models\Space; use humhub\commands\IntegrityController; use humhub\commands\CronController; use humhub\components\ActiveRecord; return ['id' => 'notification', 'class' => Module::className(), 'isCoreModule' => true, 'events' => array(array('class' => User::className(), 'event' => User::EVENT_BEFORE_DELETE, 'callback' => array(Events::className(), 'onUserDelete')), array('class' => Space::className(), 'event' => Space::EVENT_BEFORE_DELETE, 'callback' => array(Events::className(), 'onSpaceDelete')), array('class' => IntegrityController::className(), 'event' => IntegrityController::EVENT_ON_RUN, 'callback' => array(Events::className(), 'onIntegrityCheck')), array('class' => CronController::className(), 'event' => CronController::EVENT_ON_DAILY_RUN, 'callback' => array(Events::className(), 'onCronDailyRun')), array('class' => ActiveRecord::className(), 'event' => ActiveRecord::EVENT_BEFORE_DELETE, 'callback' => [Events::className(), 'onActiveRecordDelete']))];
/** * Deletes a message, including all dependencies. */ public function delete() { foreach (ServicesMessageEntry::findAll(array('message_id' => $this->id)) as $messageEntry) { $messageEntry->delete(); } foreach (ServicesUserMessage::findAll(array('message_id' => $this->id)) as $userMessage) { $userMessage->delete(); } parent::delete(); }
public function afterSave($insert, $changedAttributes) { // Set new uploaded file if ($this->uploadedFile !== null && $this->uploadedFile instanceof UploadedFile) { $newFilename = $this->getStoredFilePath(); if (is_uploaded_file($this->uploadedFile->tempName)) { move_uploaded_file($this->uploadedFile->tempName, $newFilename); @chmod($newFilename, 0744); } /** * For uploaded jpeg files convert them again - to handle special * exif attributes (e.g. orientation) */ if ($this->uploadedFile->type == 'image/jpeg') { ImageConverter::TransformToJpeg($newFilename, $newFilename); } } // Set file by given contents if ($this->newFileContent != null) { $newFilename = $this->getStoredFilePath(); file_put_contents($newFilename, $this->newFileContent); @chmod($newFilename, 0744); } return parent::afterSave($insert, $changedAttributes); }
<?php use humhub\modules\content\widgets\WallEntryAddons; use humhub\modules\space\widgets\Menu; use humhub\commands\CronController; use humhub\commands\IntegrityController; use modules\embeddedmedia\Events; use humhub\modules\user\models\User; use humhub\components\ActiveRecord; return ['id' => 'embeddedmedia', 'class' => 'modules\\embeddedmedia\\Module', 'namespace' => 'modules\\embeddedmedia', 'isCoreModule' => false, 'events' => array(array('class' => Menu::className(), 'event' => Menu::EVENT_INIT, 'callback' => array('modules\\embeddedmedia\\Events', 'onSpaceMenuInit')), array('class' => WallEntryAddons::className(), 'event' => WallEntryAddons::EVENT_INIT, 'callback' => array('modules\\embeddedmedia\\Events', 'onWallEntryAddonInit')), array('class' => CronController::className(), 'event' => CronController::EVENT_ON_DAILY_RUN, 'callback' => array('modules\\embeddedmedia\\Events', 'onCronDailyRun')), array('class' => IntegrityController::className(), 'event' => IntegrityController::EVENT_ON_RUN, 'callback' => array('modules\\embeddedmedia\\Events', 'onIntegrityCheck')), array('class' => ActiveRecord::className(), 'event' => \humhub\components\ActiveRecord::EVENT_BEFORE_DELETE, 'callback' => array('modules\\embeddedmedia\\Events', 'onBeforeActiveRecordDelete')), array('class' => User::className(), 'event' => User::EVENT_BEFORE_DELETE, 'callback' => array('modules\\embeddedmedia\\Events', 'onUserDelete')))]; ?> ), ]; ?>
/** * @inheritdoc */ public function afterDelete() { ContentContainer::deleteAll(['pk' => $this->getPrimaryKey(), 'class' => $this->className()]); parent::afterDelete(); }
<?php use humhub\modules\activity\Events; use humhub\components\ActiveRecord; use humhub\commands\IntegrityController; return ['id' => 'activity', 'class' => humhub\modules\activity\Module::className(), 'isCoreModule' => true, 'events' => [['class' => ActiveRecord::className(), 'event' => ActiveRecord::EVENT_BEFORE_DELETE, 'callback' => [Events::className(), 'onActiveRecordDelete']], ['class' => IntegrityController::className(), 'event' => IntegrityController::EVENT_ON_RUN, 'callback' => [Events::className(), 'onIntegrityCheck']]]];
public function beforeValidate() { if (!$this->container->canWrite($this->user_id)) { $this->addError('visibility', Yii::t('base', 'Insufficent permissions to create content!')); } return parent::beforeValidate(); }
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { if ($insert) { // Check if this is an request (friend has no entry in table) $state = self::getStateForUser($this->user, $this->friendUser); if ($state === self::STATE_REQUEST_SENT) { // Send Request Notification $notification = new \humhub\modules\friendship\notifications\Request(); $notification->originator = $this->user; $notification->source = $this; $notification->send($this->friendUser); } elseif ($state === self::STATE_FRIENDS) { // Remove request notification $notification = new \humhub\modules\friendship\notifications\Request(); $notification->originator = $this->friendUser; $notification->delete($this->user); // User approved friends request notification $notification = new \humhub\modules\friendship\notifications\RequestApproved(); $notification->originator = $this->user; $notification->source = $this; $notification->send($this->friendUser); } } return parent::afterSave($insert, $changedAttributes); }
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { WikiPageRevision::updateAll(['is_latest' => 0], 'wiki_page_id=:wikiPageId AND id!=:selfId', [':wikiPageId' => $this->wiki_page_id, ':selfId' => $this->id]); return parent::afterSave($insert, $changedAttributes); }
<?php use humhub\components\ActiveRecord; use humhub\commands\IntegrityController; use humhub\modules\like\Module; use humhub\modules\user\models\User; use humhub\modules\content\widgets\WallEntryLinks; return ['id' => 'like', 'class' => humhub\modules\like\Module::className(), 'isCoreModule' => true, 'events' => array(array('class' => User::className(), 'event' => User::EVENT_BEFORE_DELETE, 'callback' => array('humhub\\modules\\like\\Events', 'onUserDelete')), array('class' => ActiveRecord::className(), 'event' => ActiveRecord::EVENT_BEFORE_DELETE, 'callback' => array('humhub\\modules\\like\\Events', 'onActiveRecordDelete')), array('class' => IntegrityController::className(), 'event' => IntegrityController::EVENT_ON_RUN, 'callback' => array('humhub\\modules\\like\\Events', 'onIntegrityCheck')), array('class' => WallEntryLinks::className(), 'event' => WallEntryLinks::EVENT_INIT, 'callback' => array('humhub\\modules\\like\\Events', 'onWallEntryLinksInit')))];
public function beforeValidate() { if (!$this->container->canWrite($this->user_id) && $this->getPolymorphicRelation()->className() != Activity::className()) { $this->addError('visibility', Yii::t('base', 'Insufficent permissions to create content!')); } return parent::beforeValidate(); }
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { // Auto follow this content if ($this->className() != \humhub\modules\activity\models\Activity::className()) { $this->follow($this->content->created_by); } // Set polymorphic relation if ($insert) { $this->content->object_model = $this->className(); $this->content->object_id = $this->getPrimaryKey(); } // Always save content $this->content->save(); parent::afterSave($insert, $changedAttributes); if ($insert && $this->autoAddToWall && $this->wallEntryClass != "") { $this->content->addToWall(); } }
/** * After saving content addon, mark underlying content as updated. * * @return boolean */ public function afterSave($insert, $changedAttributes) { // Auto follow the content which this addon belongs to $this->content->getPolymorphicRelation()->follow($this->created_by); return parent::afterSave($insert, $changedAttributes); }
<?php use humhub\modules\content\widgets\WallEntryAddons; use humhub\commands\CronController; use humhub\commands\IntegrityController; use humhub\modules\file\Events; use humhub\modules\user\models\User; use humhub\components\ActiveRecord; return ['id' => 'file', 'class' => \humhub\modules\file\Module::className(), 'isCoreModule' => true, 'events' => array(array('class' => WallEntryAddons::className(), 'event' => WallEntryAddons::EVENT_INIT, 'callback' => array(Events::className(), 'onWallEntryAddonInit')), array('class' => CronController::className(), 'event' => CronController::EVENT_ON_DAILY_RUN, 'callback' => array(Events::className(), 'onCronDailyRun')), array('class' => IntegrityController::className(), 'event' => IntegrityController::EVENT_ON_RUN, 'callback' => array(Events::className(), 'onIntegrityCheck')), array('class' => ActiveRecord::className(), 'event' => \humhub\components\ActiveRecord::EVENT_BEFORE_DELETE, 'callback' => array(Events::className(), 'onBeforeActiveRecordDelete')), array('class' => User::className(), 'event' => User::EVENT_BEFORE_DELETE, 'callback' => array(Events::className(), 'onUserDelete')))];
/** * @inheritdoc */ public function afterSave($insert, $changedAttributes) { // Auto follow this content if ($this->className() != \humhub\modules\activity\models\Activity::className()) { $this->follow($this->content->user_id); } // Set polymorphic relation if ($insert) { $this->content->object_model = $this->className(); $this->content->object_id = $this->getPrimaryKey(); } // Always save content $this->content->save(); parent::afterSave($insert, $changedAttributes); if ($insert && $this->autoAddToWall && $this->wallEntryClass != "") { $this->content->addToWall(); } // When Space Content, update also last visit if ($this->content->space_id) { $membership = $this->content->space->getMembership(); if ($membership) { $membership->updateLastVisit(); } } }
/** * @inheritdoc */ public function afterDelete() { // Try delete the underlying object (Post, Question, Task, ...) $this->resetPolymorphicRelation(); if ($this->getPolymorphicRelation() !== null) { $this->getPolymorphicRelation()->delete(); } parent::afterDelete(); }
/** * After saving content addon, mark underlying content as updated. * * @return boolean */ public function afterSave($insert, $changedAttributes) { // Auto follow the content which this addon belongs to $this->content->getPolymorphicRelation()->follow($this->created_by); if ($this->updateContentStreamSort) { $this->getSource()->content->updateStreamSortTime(); } return parent::afterSave($insert, $changedAttributes); }
public function afterSave($insert, $changedAttributes) { // Set new uploaded file if ($this->uploadedFile !== null && $this->uploadedFile instanceof UploadedFile) { $newFilename = $this->getPath() . DIRECTORY_SEPARATOR . $this->getFilename(); if (is_uploaded_file($this->uploadedFile->tempName)) { move_uploaded_file($this->uploadedFile->tempName, $newFilename); @chmod($newFilename, 0744); } } // Set file by given contents if ($this->newFileContent != null) { $newFilename = $this->getPath() . DIRECTORY_SEPARATOR . $this->getFilename(); file_put_contents($newFilename, $this->newFileContent); @chmod($newFilename, 0744); } return parent::afterSave($insert, $changedAttributes); }