\Ceo\Core\ManagersUserManager

User manager provides a standard API to user model management

Managers provide a service layer in front of models. Managers implement domain specific logic, checks and initialization that would normally live in multiple controllers.

Summary

Methods
Properties
Constants
save()
getPaginator()
restDelete()
restCreate()
restUpdate()
find()
findFirst()
findFirstById()
findFirstByUuid()
getForm()
create()
update()
appendRoles()
replaceRoles()
delete()
restGet()
No public properties found
No constants found
No protected methods found
No protected properties found
N/A
No private methods found
No private properties found
N/A

Methods

save()

save(object  $obj) : object

Save handler, because DRY

Parameters

object $obj

Model to be saved

Throws

\Ceo\Core\Managers\Exception

Json encoded string of validation errors

Returns

object —

Model

getPaginator()

getPaginator(integer  $page = 1, integer  $limit = 50) : \Ceo\Core\Managers\Ceo\Core\ModelHelpers\Paginator

Helps paginate models using the query bulder. Bit more complicated than the native array method, but works better for larger data sets

Because it's based on Phalcon's QueryBuilder, it supports a fluent filtering interface:

    $manager = $this->foo_manager;
    $items = $manager->getPaginator(1, 20)
        ->orderBy('created_at desc')
        ->where('name = :name:', array('name' => $name))
        ->andWhere('type = :type:', array('type' => $type))
        ->paginate();

    echo json_encode($items);

Parameters

integer $page

Current page

integer $limit

Per page limit

Returns

\Ceo\Core\Managers\Ceo\Core\ModelHelpers\Paginator

restDelete()

restDelete(\Ceo\Core\Managers\number  $id) : boolean

Delete an object with rest

Parameters

\Ceo\Core\Managers\number $id

Returns

boolean

restCreate()

restCreate(array  $data) 

Create a new object

Parameters

array $data

restUpdate()

restUpdate(integer  $id, array  $data) 

Update an existing object

Parameters

integer $id
array $data

find()

find(mixed  $parameters = null) : mixed

Find users

Parameters

mixed $parameters

Returns

mixed

findFirst()

findFirst(mixed  $params = null) : mixed

Find first based on params

Parameters

mixed $params

Returns

mixed

findFirstById()

findFirstById(mixed  $params = null) : mixed

Find first user by ID

Parameters

mixed $params

Returns

mixed

findFirstByUuid()

findFirstByUuid(  $params = null) : mixed

Find first by UUID

Parameters

$params

Returns

mixed

getForm()

getForm(mixed  $entity = null, array  $options = null) : object

Build and return standard editing form

Parameters

mixed $entity

Entity to prepopulate

array $options

Form options

Returns

object —

Ceo\Core\Forms\UserForm

create()

create(array  $data) : object

Create new user with given dataset

Accepts an array of user data, including:

  • name
  • email
  • (plain text) password
  • array of ACL group names

Example:

    $userData = [
        'name' => 'Test Testerson',
        'email' => 'test@example',
        'password' => 'thisisasecret',
        'roles' => ['Administrators']
    ];
    $userManager = $DI->get('user_manager');
    $userManager->create($userData);

Parameters

array $data

Initial data for user

Throws

\Ceo\Core\Managers\Exception

Will throw json encoded list of validation or other errors

Returns

object —

Newly created user

update()

update(integer  $id, array  $data) : \Ceo\Core\Managers\UserModel

Update user

Parameters

integer $id

ID

array $data

data

Returns

\Ceo\Core\Managers\UserModel

appendRoles()

appendRoles(integer  $id, array  $newRoles) : \Ceo\Core\Managers\UserModel

Append ACL roles to existing user

    echo $user->roles->count(); // 1
    $user = $manager->appendRoles(1, ['Administrator']);
    echo $user->roles->count(); // 2

Parameters

integer $id

user ID

array $newRoles

New role names

Returns

\Ceo\Core\Managers\UserModel

replaceRoles()

replaceRoles(integer  $id,   $newRoles) : \Ceo\Core\Managers\UserModel

Replace user roles with new roles <pre> echo $user->roles->count(); // 1 $user = $manager->replaceRoles(1, ['Administrator']); echo $user->roles->count(); // 1 </pre>

Parameters

integer $id

user ID

$newRoles

Returns

\Ceo\Core\Managers\UserModel

delete()

delete(  $id) 

Parameters

$id

restGet()

restGet(array  $params = null, array  $options = null,   $page = 1,   $limit = 10) 

Parameters

array $params
array $options
$page
$limit