Initial import of space_profiles module
This commit is contained in:
25
controllers/ProfileController.php
Normal file
25
controllers/ProfileController.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\modules\space_profiles\controllers;
|
||||
|
||||
use humhub\modules\content\components\ContentContainerController;
|
||||
use humhub\modules\space_profiles\models\SpaceProfile;
|
||||
|
||||
class ProfileController extends ContentContainerController
|
||||
{
|
||||
protected function getAccessRules()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function actionView()
|
||||
{
|
||||
$profile = SpaceProfile::findOne(['contentcontainer_id' => $this->contentContainer->contentcontainer_id]);
|
||||
|
||||
return $this->render('view', [
|
||||
'space' => $this->contentContainer,
|
||||
'profile' => $profile,
|
||||
'isPublicRoute' => false,
|
||||
]);
|
||||
}
|
||||
}
|
||||
43
controllers/PublicController.php
Normal file
43
controllers/PublicController.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\modules\space_profiles\controllers;
|
||||
|
||||
use humhub\components\Controller;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\space_profiles\helpers\ProfileAccess;
|
||||
use humhub\modules\space_profiles\models\SpaceProfile;
|
||||
use Yii;
|
||||
use yii\web\ForbiddenHttpException;
|
||||
use yii\web\NotFoundHttpException;
|
||||
|
||||
class PublicController extends Controller
|
||||
{
|
||||
public function actionView(string $slug)
|
||||
{
|
||||
$profile = SpaceProfile::findOne(['slug' => $slug]);
|
||||
if (!$profile instanceof SpaceProfile) {
|
||||
throw new NotFoundHttpException('Profile not found.');
|
||||
}
|
||||
|
||||
$space = Space::findOne(['contentcontainer_id' => $profile->contentcontainer_id]);
|
||||
if (!$space instanceof Space) {
|
||||
throw new NotFoundHttpException('Space not found.');
|
||||
}
|
||||
|
||||
if (!$space->moduleManager->isEnabled('space_profiles')) {
|
||||
throw new NotFoundHttpException('Profile not available.');
|
||||
}
|
||||
|
||||
if (!ProfileAccess::canView($space)) {
|
||||
throw new ForbiddenHttpException('You are not allowed to view this profile.');
|
||||
}
|
||||
|
||||
$this->view->title = Yii::t('SpaceProfilesModule.base', 'Rescue Profile') . ' - ' . $space->name;
|
||||
|
||||
return $this->render('view', [
|
||||
'space' => $space,
|
||||
'profile' => $profile,
|
||||
'isPublicRoute' => true,
|
||||
]);
|
||||
}
|
||||
}
|
||||
44
controllers/SettingsController.php
Normal file
44
controllers/SettingsController.php
Normal file
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
|
||||
namespace humhub\modules\space_profiles\controllers;
|
||||
|
||||
use humhub\modules\content\components\ContentContainerController;
|
||||
use humhub\modules\content\components\ContentContainerControllerAccess;
|
||||
use humhub\modules\rescue_foundation\widgets\RescueSettingsMenu;
|
||||
use humhub\modules\space\models\Space;
|
||||
use humhub\modules\space_profiles\models\forms\SpaceProfileForm;
|
||||
use Yii;
|
||||
use yii\web\UploadedFile;
|
||||
|
||||
class SettingsController extends ContentContainerController
|
||||
{
|
||||
protected function getAccessRules()
|
||||
{
|
||||
return [[ContentContainerControllerAccess::RULE_USER_GROUP_ONLY => [Space::USERGROUP_OWNER, Space::USERGROUP_ADMIN]]];
|
||||
}
|
||||
|
||||
public function actionIndex()
|
||||
{
|
||||
$model = new SpaceProfileForm(['contentContainer' => $this->contentContainer]);
|
||||
|
||||
if ($model->load(Yii::$app->request->post())) {
|
||||
$model->iconFile = UploadedFile::getInstance($model, 'iconFile');
|
||||
$model->backgroundImageFile = UploadedFile::getInstance($model, 'backgroundImageFile');
|
||||
|
||||
if ($model->save()) {
|
||||
$this->view->saved();
|
||||
return $this->refresh();
|
||||
}
|
||||
}
|
||||
|
||||
$subNav = null;
|
||||
if (class_exists(RescueSettingsMenu::class)) {
|
||||
$subNav = RescueSettingsMenu::widget(['space' => $this->contentContainer]);
|
||||
}
|
||||
|
||||
return $this->render('index', [
|
||||
'model' => $model,
|
||||
'subNav' => $subNav,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user