Minor code cleanups

This commit is contained in:
Lucas Bartholemy 2018-05-06 21:40:45 +02:00
parent c5f697e571
commit f3a6056977
7 changed files with 57 additions and 33 deletions

View File

@ -26,6 +26,9 @@ class ListController extends Controller
/**
* Returns an list of all friends of a user
*
* @throws HttpException
* @throws \Exception
*/
public function actionPopup()
{

View File

@ -9,11 +9,10 @@
namespace humhub\modules\friendship\controllers;
use yii\data\ActiveDataProvider;
use humhub\modules\user\components\BaseAccountController;
use humhub\modules\friendship\models\Friendship;
use humhub\modules\friendship\models\SettingsForm;
use humhub\modules\user\components\BaseAccountController;
use yii\data\ActiveDataProvider;
/**
@ -39,8 +38,8 @@ class ManageController extends BaseAccountController
]);
return $this->render('list', [
'user' => $this->getUser(),
'dataProvider' => $dataProvider
'user' => $this->getUser(),
'dataProvider' => $dataProvider
]);
}
@ -54,8 +53,8 @@ class ManageController extends BaseAccountController
]);
return $this->render('requests', [
'user' => $this->getUser(),
'dataProvider' => $dataProvider
'user' => $this->getUser(),
'dataProvider' => $dataProvider
]);
}
@ -69,8 +68,8 @@ class ManageController extends BaseAccountController
]);
return $this->render('sent-requests', [
'user' => $this->getUser(),
'dataProvider' => $dataProvider
'user' => $this->getUser(),
'dataProvider' => $dataProvider
]);
}

View File

@ -8,22 +8,39 @@
namespace humhub\modules\friendship\controllers;
use Yii;
use yii\web\HttpException;
use humhub\modules\user\models\User;
use humhub\components\Controller;
use humhub\modules\friendship\models\Friendship;
use humhub\modules\friendship\Module;
use humhub\modules\user\models\User;
use Yii;
use yii\web\HttpException;
/**
* Membership Handling Controller
*
* @property Module $module
* @author luke
*/
class RequestController extends Controller
{
/**
* @inheritdoc
* @throws HttpException
*/
public function beforeAction($action)
{
if (!$this->module->getIsEnabled()) {
throw new HttpException(404, 'Friendship system is not enabled!');
}
return parent::beforeAction($action);
}
/**
* Adds or Approves Friendship Request
* @throws HttpException
*/
public function actionAdd()
{
@ -42,6 +59,7 @@ class RequestController extends Controller
/**
* Declines or Deletes Friendship
* @throws HttpException
*/
public function actionDelete()
{

View File

@ -151,9 +151,9 @@ class Friendship extends \humhub\components\ActiveRecord
* Returns a query for friends of a user
*
* @return \yii\db\ActiveQuery
* @param type $user
* @param User $user
*/
public static function getFriendsQuery($user)
public static function getFriendsQuery(User $user)
{
$query = User::find();
@ -172,9 +172,9 @@ class Friendship extends \humhub\components\ActiveRecord
* Returns a query for sent and not approved friend requests of an user
*
* @return \yii\db\ActiveQuery
* @param type $user
* @param User $user
*/
public static function getSentRequestsQuery($user)
public static function getSentRequestsQuery(User $user)
{
$query = User::find();

View File

@ -8,9 +8,9 @@
namespace humhub\modules\notification\controllers;
use Yii;
use humhub\components\Controller;
use humhub\modules\notification\models\Notification;
use Yii;
/**
* ListController
@ -41,7 +41,7 @@ class ListController extends Controller
$notifications = Notification::loadMore(Yii::$app->request->get('from', 0));
$lastEntryId = 0;
$output = "";
foreach ($notifications as $notification) {
try {
@ -49,8 +49,8 @@ class ListController extends Controller
$lastEntryId = $notification->id;
$notification->desktop_notified = 1;
$notification->update();
} catch(\Exception $e) {
Yii::error($e);
} catch (\Exception $e) {
Yii::error('Could not display notification: ' . $notification->id . '(' . $e . ')');
}
}
@ -68,7 +68,7 @@ class ListController extends Controller
public function actionMarkAsSeen()
{
$this->forcePostRequest();
Yii::$app->response->format = 'json';
$count = Notification::updateAll(['seen' => 1], ['user_id' => Yii::$app->user->id]);
@ -80,7 +80,7 @@ class ListController extends Controller
/**
* Returns new notifications
*
*
* @deprecated since version 1.2
*/
public function actionGetUpdateJson()
@ -102,10 +102,10 @@ class ListController extends Controller
$update['newNotifications'] = Notification::findUnseen()->count();
$unnotified = Notification::findUnnotifiedInFrontend()->all();
$update['notifications'] = [];
foreach ($unnotified as $notification) {
if(Yii::$app->getModule('notification')->settings->user()->getInherit('enable_html5_desktop_notifications', true)) {
if (Yii::$app->getModule('notification')->settings->user()->getInherit('enable_html5_desktop_notifications', true)) {
$update['notifications'][] = $notification->getBaseModel()->text();
}
$notification->desktop_notified = 1;

View File

@ -9,6 +9,7 @@
namespace humhub\modules\user\models;
use humhub\components\ActiveRecord;
use humhub\libs\Helpers;
use humhub\modules\user\models\fieldtype\BaseType;
use Yii;
use yii\db\ActiveQuery;
@ -139,6 +140,7 @@ class ProfileField extends ActiveRecord
* Returns the ProfileFieldType Class for this Profile Field
*
* @return BaseType
* @throws \yii\base\Exception
*/
public function getFieldType()
{
@ -146,7 +148,7 @@ class ProfileField extends ActiveRecord
if ($this->_fieldType != null)
return $this->_fieldType;
if ($this->field_type_class != "" && \humhub\libs\Helpers::CheckClassType($this->field_type_class, fieldtype\BaseType::className())) {
if ($this->field_type_class != "" && Helpers::CheckClassType($this->field_type_class, fieldtype\BaseType::className())) {
$type = $this->field_type_class;
$this->_fieldType = new $type;
$this->_fieldType->setProfileField($this);
@ -158,7 +160,7 @@ class ProfileField extends ActiveRecord
/**
* Returns The Form Definition to edit the ProfileField Model.
*
* @return Array CForm Definition
* @return array CForm Definition
*/
public function getFormDefinition()
{
@ -250,7 +252,6 @@ class ProfileField extends ActiveRecord
$this->internal_name = trim($this->internal_name);
if (!$this->isNewRecord) {
// Dont allow changes of internal_name - Maybe not the best way to check it.
$currentProfileField = ProfileField::findOne(['id' => $this->id]);
if ($this->internal_name != $currentProfileField->internal_name) {

View File

@ -24,22 +24,25 @@ class LayoutAddons extends BaseStack
*/
public function init()
{
if(!Yii::$app->request->isPjax) {
if (!Yii::$app->request->isPjax) {
$this->addWidget(GlobalModal::class);
$this->addWidget(GlobalConfirmModal::class);
if(Yii::$app->params['installed']) {
if (Yii::$app->params['installed']) {
$this->addWidget(\humhub\modules\tour\widgets\Tour::class);
$this->addWidget(\humhub\modules\admin\widgets\TrackingWidget::class);
}
$this->addWidget(LoaderWidget::class, ['show' => false, 'id' => "humhub-ui-loader-default"]);
$this->addWidget(StatusBar::class);
$this->addWidget(BlueimpGallery::class);
$this->addWidget(MarkdownFieldModals::class);
if (Yii::$app->params['installed']) {
$this->addWidget(BlueimpGallery::class);
$this->addWidget(MarkdownFieldModals::class);
if (Yii::$app->params['enablePjax']) {
$this->addWidget(Pjax::class);
}
if (Yii::$app->params['enablePjax']) {
$this->addWidget(Pjax::class);
}
}
parent::init();