\Dewdrop\Admin\Component\Stock\UsersComponent

Admin user management component.

This component provides user management facilities within the Dewdrop admin environment for Silex.

Following is an example of how to register the component within your application's index.php facade script:

$zend = realpath(__DIR__ . '/../zend');

if (file_exists($zend)) {
    define('PROJECT_ROOT', $zend);
} else {
    define('PROJECT_ROOT', realpath(__DIR__ . '/../'));
}

require_once PROJECT_ROOT . '/vendor/autoload.php';

$silex = \Dewdrop\Pimple::getInstance();

$silex['auth']->init();

$silex['admin']->registerComponentsInPath();

$silex['admin']->registerComponent(new \Dewdrop\Admin\Component\Stock\Users\Component());

$silex->run();

If you wish to extend this class, you can write your own \Admin\Users\Component class in /admin/users/Component.php, and because the Dewdrop admin environment already scans the /admin directory for components, you do not need to register your custom component in your application's index.php facade script as shown in the above example.

Summary

Methods
Properties
Constants
__construct()
init()
preDispatch()
hasPimpleResource()
getPimpleResource()
getPimple()
getInflector()
getPaths()
getRequest()
getDb()
isActive()
getPermissions()
createPageObject()
url()
addToSubmenu()
addSubmenuDivider()
getSubmenuPages()
getName()
setEnv()
setTitle()
getTitle()
setBadgeContent()
getBadgeContent()
setIcon()
getIcon()
setMenuPosition()
getMenuPosition()
getPath()
setActivityLogHandler()
getActivityLogHandler()
getFullyQualifiedName()
getListingQueryParamsSessionName()
getPageFactories()
getCustomPageFactory()
addPageFactory()
onPageDispatch()
dispatchPage()
setShouldRenderLayout()
shouldRenderLayout()
getSlug()
getPrimaryModel()
getRowEditor()
getListing()
getFields()
getFieldGroupsFilter()
getVisibilityFilter()
setVisibilityFilter()
No public properties found
No constants found
checkRequiredProperties()
renderJsonResponse()
addPasswordFields()
$submenuPages
$name
$pimple
$shouldRenderLayout
$path
$env
$fieldGroupsFilter
$fields
$listing
$rowEditor
$visibilityFilter
N/A
executePageDispatchCallbacks()
$title
$icon
$menuPosition
$badgeContent
$active
$pageFactories
$customPageFactory
$pageDispatchCallbacks
$permissions
$activityLogHandler
N/A

Properties

$submenuPages

$submenuPages : array

An array of submenu pages that have been added by calling addToSubmenu().

These are actually tied in by registerMenuPage() after the admin_menu hook is triggered.

Type

array

$name

$name : string

The component name (as it would show up in the URL, for example).

Type

string

$pimple

$pimple : \Pimple

The Pimple object used to supply dependencies to the admin component.

Basically used as a service locator in this context, which makes testability a bit trickier in the context of the component class itself. However, it makes using component classes in other contexts (e.g. testing your page classes) much easier.

Type

\Pimple

$shouldRenderLayout

$shouldRenderLayout : boolean

Whether the admin environment should wrap the page environment with the layout (i.e. admin shell chrome.

Type

boolean

$path

$path : string

The path to the component class.

Type

string

$env

$env : \Dewdrop\Admin\Env\EnvInterface

The admin environment. Used to do anything environment (i.e. WP or Silex) specific, like perform redirects.

Type

\Dewdrop\Admin\Env\EnvInterface

$title

$title : string

The title to display for this component in the admin navigation.

Type

string

$icon

$icon : string

The icon that should be used for this component's navigation link.

Type

string

$menuPosition

$menuPosition : integer

The position this item should take in the admin navigation menu.

To see the current menu positions, you can var_dump($_GLOBALS['menu']). Note that is you pick an already used menu position, you will essentially hide that item. For example, if you set your menu position to "5", which is the default value for "Posts", your component will show up there instead of "Posts", rather than just pushing "Posts" further down like you might expect. You can leave $menuPosition blank if you'd simply like your component to be appended to the end of the menu.

Type

integer

$badgeContent

$badgeContent : string

Content that should be displayed in a "badge" alongside this component's menu item.

Type

string

$active

$active : boolean

Whether this component is active (currently in charge of dispatching a page/response).

Type

boolean

$pageFactories

$pageFactories : array

The page factories registered with this component to provide page objects.

Type

array

$customPageFactory

$customPageFactory : \Dewdrop\Admin\PageFactory\Custom

A page factory to allow overriding of page classes that come from other factories.

Type

\Dewdrop\Admin\PageFactory\Custom

$pageDispatchCallbacks

$pageDispatchCallbacks : array

Callbacks registered with this component via onPageDispatch().

Type

array

Methods

__construct()

__construct(\Pimple  $pimple = null) 

Create a component instance using the DB adapter creating by the Wiring class.

Parameters

\Pimple $pimple

init()

init() : void

Initializations

preDispatch()

preDispatch() 

This method will be called before any admin page is dispatched.

hasPimpleResource()

hasPimpleResource(string  $name) : boolean

Check to see if the supplied resource is present in the component's Pimple or in the Dewdrop Pimple.

Parameters

string $name

Returns

boolean

getPimpleResource()

getPimpleResource(  $name) : mixed

Get the named Pimple resource from the component's local container or the Dewdrop container.

Parameters

$name

Returns

mixed

getPimple()

getPimple() : \Pimple

Get the Pimple container used by this component.

Returns

\Pimple

getInflector()

getInflector() : \Dewdrop\Inflector

Get a Inflector object.

Returns

\Dewdrop\Inflector

getPaths()

getPaths() : \Dewdrop\Paths

Get a Paths object.

Returns

\Dewdrop\Paths

getRequest()

getRequest() : \Dewdrop\Request

Get a Request object.

Returns

\Dewdrop\Request

getDb()

getDb() : \Dewdrop\Db\Adapter

Get the DB adapter associated with this component. This is used frequently by page classes to get access to the DB connection.

Returns

\Dewdrop\Db\Adapter

isActive()

isActive() : boolean

Check to see if this component is active.

Returns

boolean

getPermissions()

getPermissions() : \Dewdrop\Admin\Permissions

Get the Permissions object for this component.

Returns

\Dewdrop\Admin\Permissions

createPageObject()

createPageObject(string  $name) : \Dewdrop\Admin\Page\PageAbstract|false

Iterate over the page factories, attempting to create a page object for the supplied name. If no page factory can handle the page name, that's a 404.

Parameters

string $name

Throws

\Dewdrop\Exception

Returns

\Dewdrop\Admin\Page\PageAbstract|false

url()

url(string  $page, array  $params = array()) 

Request that the admin Env assemble a URL that will work to get to the specified page.

Parameters

string $page
array $params

addToSubmenu()

addToSubmenu(string  $title, string  $page, array  $params = array()) : \Dewdrop\Admin\Component\ComponentAbstract

Add a link to the submenu for this component.

Parameters

string $title
string $page
array $params

Returns

\Dewdrop\Admin\Component\ComponentAbstract

addSubmenuDivider()

addSubmenuDivider() : $this

Add a divider to the component's submenu.

Returns

$this

getSubmenuPages()

getSubmenuPages() : array

Get all sub-menu pages that have been added to this component.

Returns

array

getName()

getName() : string

Get the name of the component (i.e. the string that would represent it in the URL.

Returns

string

setEnv()

setEnv(\Dewdrop\Admin\Env\EnvInterface  $env) : $this

Allow overriding of the admin environment after instantiation.

Parameters

\Dewdrop\Admin\Env\EnvInterface $env

Returns

$this

setTitle()

setTitle(string  $title) : \Dewdrop\Admin\Component\ComponentAbstract

Set the title of this component as it should be displayed in the admin menu.

Parameters

string $title

Returns

\Dewdrop\Admin\Component\ComponentAbstract

getTitle()

getTitle() : string

Get the title of the component that would be displayed in the admin menu.

Returns

string

setBadgeContent()

setBadgeContent(string  $badgeContent) : $this

Set the badge content that should be displayed alongside this component's navigation.

Parameters

string $badgeContent

Returns

$this

getBadgeContent()

getBadgeContent() : string

Get the badge content assigned to this component.

Returns

string

setIcon()

setIcon(string  $icon) : \Dewdrop\Admin\Component\ComponentAbstract

Set the icon that should be used in this component's admin menu entry.

Parameters

string $icon

Returns

\Dewdrop\Admin\Component\ComponentAbstract

getIcon()

getIcon() : string

Get the icon that should be displayed for the component in the admin menu.

Returns

string

setMenuPosition()

setMenuPosition(integer  $menuPosition) : \Dewdrop\Admin\Component\ComponentAbstract

Set the position of the component's menu entry

Parameters

integer $menuPosition

Returns

\Dewdrop\Admin\Component\ComponentAbstract

getMenuPosition()

getMenuPosition() : integer

Get the position at which this component should be rendered in the admin shell nav menu.

Returns

integer

getPath()

getPath() : string

Get the path to this component's class.

Returns

string

getFullyQualifiedName()

getFullyQualifiedName() : string

Get a fully-qualified name for the component that can be used when referencing the component in externals systems like the DB.

Returns

string

getListingQueryParamsSessionName()

getListingQueryParamsSessionName() : string

Get an identifier that can be used when storing this component's listing query string parameters in the session. We store the params so that we can redirect while maintaining filter and pagination state.

Returns

string

getPageFactories()

getPageFactories() : array

Get all the page factories associated with this component.

Returns

array

getCustomPageFactory()

getCustomPageFactory() : \Dewdrop\Admin\PageFactory\Custom

Get the custom page factory for this component.

Returns

\Dewdrop\Admin\PageFactory\Custom

onPageDispatch()

onPageDispatch(  $pageName, callable  $callback) : $this

Register a callback to run when the page matching the supplied name is dispatched on this component. Your callback will receive the new page object as its first argument.

Parameters

$pageName
callable $callback

Returns

$this

dispatchPage()

dispatchPage(mixed  $page = null, \Dewdrop\Admin\Response  $response = null) : mixed

Dispatch the routed page, working through its init(), process() and render() methods.

Each abstract page class can specify whether the process() method should actually be run by implementing a shouldProcess() method. The page's init() method is guaranteed to always be called. If after calling render there is no output, the component will attempt to render the page's default view script automatically.

Parameters

mixed $page
\Dewdrop\Admin\Response $response

Returns

mixed

setShouldRenderLayout()

setShouldRenderLayout(boolean  $shouldRenderLayout) : $this

Set whether the admin environment should wrap the page's output with the layout (the admin shell chrome).

Parameters

boolean $shouldRenderLayout

Returns

$this

shouldRenderLayout()

shouldRenderLayout() : boolean

Check to see whether the page output should be wrapped by the layout.

Returns

boolean

getSlug()

getSlug() : string

Get WP slug for this component.

We use the component name, with namespace back slashes replaced with URL-friendly front slashes, as the slug.

Returns

string

getPrimaryModel()

getPrimaryModel() : \Dewdrop\Auth\Db\UsersTableGateway

Get the primary model that is used by this component. This model will be used to provide page and button titles. By default, its primary key will also be used to filter the listing when needed (e.g. when viewing a single item rather than the full listing).

Returns

\Dewdrop\Auth\Db\UsersTableGateway

getRowEditor()

getRowEditor() : \Dewdrop\Fields\RowEditor

Get the \Dewdrop\Fields\RowEditor object that will assist with the editing of items in this component.

Returns

\Dewdrop\Fields\RowEditor

getListing()

getListing() : \Dewdrop\Fields\Listing

Get a \Dewdrop\Fields\Listing object that allows the component to retrieve records for viewing. The Listing handles applying user sorts and filters.

Returns

\Dewdrop\Fields\Listing

getFields()

getFields() : \Dewdrop\Fields

Get the \Dewdrop\Fields object that defines what fields are available to this component, what capabilities that each have, and how they should interact with various \Dewdrop\Fields\Helper objects.

Returns

\Dewdrop\Fields

getFieldGroupsFilter()

getFieldGroupsFilter() : \Dewdrop\Fields\Filter\Groups

Get a \Dewdrop\Fields\Filter\Groups object to allow the user to sort and group their fields.

Returns

\Dewdrop\Fields\Filter\Groups

getVisibilityFilter()

getVisibilityFilter() : \Dewdrop\Fields\Filter\Visibility

Get a \Dewdrop\Fields\Filter\Visibility object that allows the user to select which fields should be visible on listings.

Returns

\Dewdrop\Fields\Filter\Visibility

checkRequiredProperties()

checkRequiredProperties() 

Make sure the title property was set in the component's init() method.

Throws

\Dewdrop\Exception

renderJsonResponse()

renderJsonResponse(array  $output) : void

Render the supplied output as a JSON response. This method is mostly in place to allow mocking (and thus dodging the exit statement) during testing.

Parameters

array $output

executePageDispatchCallbacks()

executePageDispatchCallbacks(\Dewdrop\Admin\Page\PageAbstract  $page) : $this

Run any page dispatch callbacks assigned to the provided page. We support both the WP and hyphen-separated versions of the page names in this method to make it easier to reuse page dispatch code across different environments.

Parameters

\Dewdrop\Admin\Page\PageAbstract $page

Returns

$this