Merge pull request #3212 from acs-ferreira/array-pass

Arrays on findOne() methods
This commit is contained in:
buddh4 2018-07-13 15:42:38 +02:00 committed by GitHub
commit 75f4398f3b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 29 additions and 25 deletions

View File

@ -71,13 +71,13 @@ class AddGroupMemberForm extends Model
{
$group = $this->getGroup();
if($group == null) {
if ($group == null) {
throw new HttpException(404, Yii::t('AdminModule.models_form_AddGroupMemberForm', 'Group not found!'));
}
foreach ($this->userGuids as $userGuid) {
$user = User::findIdentityByAccessToken($userGuid);
if($user != null) {
if ($user != null) {
$group->addUser($user);
}
}
@ -87,6 +87,6 @@ class AddGroupMemberForm extends Model
public function getGroup()
{
return Group::findOne($this->groupId);
return Group::findOne(['id' => $this->groupId]);
}
}

View File

@ -3,14 +3,16 @@
namespace humhub\modules\admin\models\forms;
use Yii;
use humhub\modules\user\models\User;
use humhub\modules\user\models\Group;
use humhub\modules\admin\permissions\ManageGroups;
/**
* Description of UserEditForm
*
* @author buddha
*/
class UserEditForm extends \humhub\modules\user\models\User
class UserEditForm extends User
{
/**
* GroupId selection array of the form.
@ -63,10 +65,10 @@ class UserEditForm extends \humhub\modules\user\models\User
*/
public function afterSave($insert, $changedAttributes)
{
if(Yii::$app->user->can(new \humhub\modules\admin\permissions\ManageGroups())) {
if (Yii::$app->user->can(new ManageGroups())) {
//Check old group selection and remove non selected groups
foreach($this->currentGroups as $userGroup) {
if(!$this->isInGroupSelection($userGroup)) {
foreach ($this->currentGroups as $userGroup) {
if (!$this->isInGroupSelection($userGroup)) {
$this->getGroupUsers()->where(['group_id' => $userGroup->id])->one()->delete();
}
}
@ -76,7 +78,7 @@ class UserEditForm extends \humhub\modules\user\models\User
//Add all new selectedGroups to the given user
foreach ($this->groupSelection as $groupId) {
if (!$this->isCurrentlyMemberOf($groupId)) {
Group::findOne($groupId)->addUser($this);
Group::findOne(['id' => $groupId])->addUser($this);
}
}
}
@ -122,7 +124,7 @@ class UserEditForm extends \humhub\modules\user\models\User
public static function getGroupItems($groups = null)
{
if($groups == null) {
$groups = \humhub\modules\user\models\Group::find()->all();
$groups = Group::find()->all();
}
$result = [];

View File

@ -8,6 +8,7 @@
namespace humhub\modules\admin\models\forms;
use yii\base\Model;
use humhub\modules\user\models\Group;
/**
@ -15,7 +16,7 @@ use humhub\modules\user\models\Group;
*
* @author buddha
*/
class UserGroupForm extends \yii\base\Model
class UserGroupForm extends Model
{
/**
@ -81,8 +82,8 @@ class UserGroupForm extends \yii\base\Model
public function save()
{
//Check old group selection and remove non selected groups
foreach($this->currentGroups as $userGroup) {
if(!$this->isInGroupSelection($userGroup)) {
foreach ($this->currentGroups as $userGroup) {
if (!$this->isInGroupSelection($userGroup)) {
$this->user->getGroupUsers()->where(['group_id' => $userGroup->id])->one()->delete();
}
}
@ -90,7 +91,7 @@ class UserGroupForm extends \yii\base\Model
//Add all selectedGroups to the given user
foreach ($this->groupSelection as $groupId) {
if (!$this->isCurrentlyMemberOf($groupId)) {
Group::findOne($groupId)->addUser($this->user);
Group::findOne(['id' => $groupId])->addUser($this->user);
}
}

View File

@ -8,12 +8,11 @@
namespace humhub\modules\topic\controllers;
use humhub\widgets\ModalClose;
use Yii;
use humhub\modules\content\components\ContentContainerController;
use humhub\modules\topic\models\Topic;
use humhub\modules\topic\permissions\ManageTopics;
use Yii;
use yii\data\ActiveDataProvider;
use yii\web\HttpException;
@ -31,11 +30,11 @@ class ManageController extends ContentContainerController
{
$model = new Topic($this->contentContainer);
if($model->load(Yii::$app->request->post()) && $model->save()) {
if ($model->load(Yii::$app->request->post()) && $model->save()) {
$this->view->saved();
}
if($model->hasErrors()) {
if ($model->hasErrors()) {
$this->view->error($model->getFirstError('name'));
}
@ -60,8 +59,8 @@ class ManageController extends ContentContainerController
{
$this->forcePostRequest();
$topic = Topic::findOne($id);
if($topic) {
$topic = Topic::findOne(['id' => $id]);
if ($topic) {
$topic->delete();
return ['success' => true, 'message' => Yii::t('TopicModule.base', 'Topic has been deleted!')];
}
@ -71,13 +70,13 @@ class ManageController extends ContentContainerController
public function actionEdit($id)
{
$topic = Topic::findOne($id);
$topic = Topic::findOne(['id' => $id]);
if(!$topic) {
if (!$topic) {
throw new HttpException(404);
}
if($topic->load(Yii::$app->request->post()) && $topic->save()) {
if ($topic->load(Yii::$app->request->post()) && $topic->save()) {
return ModalClose::widget([
'saved' => true,
'reload' => true

View File

@ -242,7 +242,7 @@ class User extends ContentContainerActiveRecord implements IdentityInterface, Se
public static function findIdentity($id)
{
return static::findOne($id);
return static::findOne(['id' => $id]);
}
public static function findIdentityByAccessToken($token, $type = null)
@ -541,12 +541,14 @@ class User extends ContentContainerActiveRecord implements IdentityInterface, Se
$format = Yii::$app->settings->get('displayNameFormat');
if ($this->profile !== null && $format == '{profile.firstname} {profile.lastname}')
if ($this->profile !== null && $format == '{profile.firstname} {profile.lastname}') {
$name = $this->profile->firstname . ' ' . $this->profile->lastname;
}
// Return always username as fallback
if ($name == '' || $name == ' ')
if ($name == '' || $name == ' ') {
return $this->username;
}
return $name;
}