Commit f4edb764 authored by Nicolas Widart's avatar Nicolas Widart

Squashed 'Modules/User/' changes from d4e1225..f048f16

f048f16 Add an interface for the user entity. Implement it for sentinel
34d37c6 Merge pull request #16 from AsgardCms/fix-role-repo
2682d65 Fix the update method, unset the slug property for sentry.
b2371f1 Merge pull request #15 from AsgardCms/patch1
560da26 Adapting other files to the namespace change
e23ca89 Changing namespace for the user Entity
7f5dc4a Merge pull request #14 from AsgardCms/using-isset
adab07c Check for variables using isset

git-subtree-dir: Modules/User
git-subtree-split: f048f16a868474d4eca1c80c5ddfb27d451801e0
parent cf4bb7d7
<?php namespace Modules\User\Entities;
<?php namespace Modules\User\Entities\Sentinel;
use Cartalyst\Sentinel\Users\EloquentUser;
use Laracasts\Presenter\PresentableTrait;
use Modules\User\Entities\UserInterface;
class SentinelUser extends EloquentUser
class User extends EloquentUser implements UserInterface
{
use PresentableTrait;
......@@ -16,4 +17,9 @@ class SentinelUser extends EloquentUser
];
protected $presenter = 'Modules\User\Presenters\UserPresenter';
public function hasRole($roleId)
{
return $this->roles()->whereId($roleId)->count() >= 1;
}
}
<?php namespace Modules\User\Entities;
<?php namespace Modules\User\Entities\Sentry;
use Cartalyst\Sentry\Users\Eloquent\User;
use Cartalyst\Sentry\Users\Eloquent\User as SentryModel;
use Laracasts\Presenter\PresentableTrait;
use Modules\User\Entities\UserInterface;
class SentryUser extends User
class User extends SentryModel implements UserInterface
{
use PresentableTrait;
......@@ -21,4 +22,13 @@ class SentryUser extends User
{
return $this->belongsToMany(static::$groupModel, static::$userGroupsPivot, 'user_id');
}
/**
* Checks if a user belongs to the given Role ID
* @param int $roleId
* @return bool
*/
public function hasRole($roleId)
{
}
}
<?php namespace Modules\User\Entities;
interface UserInterface
{
/**
* Checks if a user belongs to the given Role ID
* @param int $roleId
* @return bool
*/
public function hasRole($roleId);
}
......@@ -8,7 +8,7 @@ use Modules\User\Repositories\UserRepository;
class SentinelUserRepository implements UserRepository
{
/**
* @var \Modules\User\Entities\SentinelUser
* @var \Modules\User\Entities\User\Sentinel
*/
protected $user;
/**
......
......@@ -20,6 +20,7 @@ class SentryRoleRepository implements RoleRepository
*/
public function create($data)
{
unset($data['slug']);
Sentry::createGroup($data);
}
......@@ -41,11 +42,10 @@ class SentryRoleRepository implements RoleRepository
*/
public function update($id, $data)
{
unset($data['slug']);
$role = Sentry::findGroupById($id);
$role->permissions($data);
$role->save();
$role->update($data);
}
/**
......
......@@ -34,7 +34,7 @@
</tr>
</thead>
<tbody>
<?php if ($roles->count() > 0): ?>
<?php if (isset($roles)): ?>
<?php foreach($roles as $role): ?>
<tr>
<td>
......@@ -73,7 +73,7 @@
</div>
</div>
<?php if ($roles->count() > 0): ?>
<?php if (isset($roles)): ?>
<?php foreach($roles as $role): ?>
<!-- Modal -->
<div class="modal fade" id="confirmation-{{ $role->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
......
......@@ -60,7 +60,7 @@
<label>{{ trans('user::users.tabs.roles') }}</label>
<select multiple="" class="form-control" name="roles[]">
<?php foreach($roles as $role): ?>
<option value="{{ $role->id }}" <?php echo $user->roles()->whereId($role->id)->count() >= 1 ? 'selected' : '' ?>>{{ $role->name }}</option>
<option value="{{ $role->id }}" <?php echo $user->hasRole($role->id) ? 'selected' : '' ?>>{{ $role->name }}</option>
<?php endforeach; ?>
</select>
</div>
......
......@@ -36,7 +36,7 @@
</tr>
</thead>
<tbody>
<?php if ($users->count() > 0): ?>
<?php if (isset($users)): ?>
<?php foreach($users as $user): ?>
<tr>
<td>
......@@ -89,7 +89,7 @@
</div>
</div>
<?php if ($users->count() > 0): ?>
<?php if (isset($users)): ?>
<?php foreach($users as $user): ?>
<!-- Modal -->
<div class="modal fade" id="confirmation-{{ $user->id }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment