-
Notifications
You must be signed in to change notification settings - Fork 2
Accounts and user management
OTF allows for centralized management of users, no matter how they log into the system. Users are accessed via the Ot_Model_DbTable_Account model, which extends Zend_Db_Table and stores content in tbl_account
.
An account object contains all the information about an account that is housed in tbl_account
. However, [helper methods](Helpful Methods) also glue certain other pieces of information together that can be helpful to the developer.
Gives a list of role objects that the user is assigned to.
Because OTF is written as a generic framework, there are cases where additional information is needed to be attached to an account. That information is needed to make programmatic decisions in other parts of an application and should always be there in some capacity. For example, if you needed to know the gender of every user who created an account, you would need a way to track that.
Account attributes allow a developer to define a variable in the bootstrap that will be attached to each account retrieved. Account Attribute Vars are classes that extend Ot_Var_Abstract
.
Example initialization in your bootstrap.php file
The following example will create a select box, with the ID of gender
and make it required.
public function _initAccountAttributeVars() {
$accountVars = array();
$accountVars[] = new Ot_Var_Type_Select('gender', 'Gender', 'Your gender', '', array('male','female'), true);
$aar = new Ot_Account_Attribute_Register();
$aar->registerVars($accountVars);
}
Once you have registered this account variable, the select box from above will be available on the pages that reference accounts, and it will become part of the account object under the accountAttributes
notation.
Custom fields can be defined through the interface to also accompany information about an account. This content should be only used as a display mechanism. If your application will rely on an attribute, use an Account Attribute, not a Custom Field
An account object can be a simple Zend_Db_Table_Row object if accessed via find() or fetch() methods. However, it may be beneficial to access some of the other account-specific data from the Ot_Account model
Ot_Model_DbTable_Account::getByAccountId($accountId)
This method will return a complete account object based on the account ID passed.
Ot_Model_DbTable_Account::getByUsername($username, $realm)
Each user/realm combination is unique. It may be possible to have usernames that overlap, but the username/realm key is unique. This will lookup by that unique key and return a complete account object.
It may become necessary to add information to an accounts details page. For example, you may want to add all the conferences a user has attended or all the computers that they have access to. Instead of creating an entirely separate page with this information, you can add a tab to the account details page that lists this information.
The tab will reference a module, controller and action that is external to the account details view, allowing you to add this tab without changing core OTF code. You will want to register the tab in the bootstrap file like this:
public function _initAccountProfilePages() {
$accountPages = array();
$accountPages[] = new Ot_Account_Profile_Page('test', 'This Is A Test', 'default', 'index', 'test', array('mytest' => 'value'));
$apr = new Ot_Account_Profile_Register();
$apr->registerPages($accountPages);
}
This will register a tab called "This Is A Test" and will reference the test action in the index controller of the default module. The final argument is used to pass additional view variables.