本文整理汇总了PHP中Role::validate方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::validate方法的具体用法?PHP Role::validate怎么用?PHP Role::validate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Role
的用法示例。
在下文中一共展示了Role::validate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: doValidate
/**
* This function performs the validation work for complex object models.
*
* In addition to checking the current object, all related objects will
* also be validated. If all pass then <code>true</code> is returned; otherwise
* an aggreagated array of ValidationFailed objects will be returned.
*
* @param array $columns Array of column names to validate.
* @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
*/
protected function doValidate($columns = null)
{
if (!$this->alreadyInValidation) {
$this->alreadyInValidation = true;
$retval = null;
$failureMap = array();
// We call the validate method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aRole !== null) {
if (!$this->aRole->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aRole->getValidationFailures());
}
}
if ($this->aEmployee !== null) {
if (!$this->aEmployee->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aEmployee->getValidationFailures());
}
}
if (($retval = UserPeer::doValidate($this, $columns)) !== true) {
$failureMap = array_merge($failureMap, $retval);
}
$this->alreadyInValidation = false;
}
return !empty($failureMap) ? $failureMap : true;
}
示例2: testAddingUserToRole
public function testAddingUserToRole()
{
Yii::app()->user->userModel = User::getByUsername('super');
$role = new Role();
$role->name = 'myRole';
$role->validate();
$saved = $role->save();
$this->assertTrue($saved);
$benny = User::getByUsername('benny');
//Add the role to benny
$benny->role = $role;
$saved = $benny->save();
$this->assertTrue($saved);
$roleId = $role->id;
unset($role);
$role = Role::getById($roleId);
$this->assertEquals(1, $role->users->count());
$this->assertTrue($role->users[0]->isSame($benny));
//Now try adding billy to the role but from the other side, from the role side.
$billy = User::getByUsername('billy');
$role->users->add($billy);
$saved = $role->save();
$this->assertTrue($saved);
$billy->forget();
//need to forget billy otherwise it won't pick up the change. i tried unset(), test fails
$billy = User::getByUsername('billy');
$this->assertTrue($billy->role->id > 0);
$this->assertTrue($billy->role->isSame($role));
}
示例3: testGetRole
public function testGetRole()
{
$super = User::getByUsername('super');
Yii::app()->user->userModel = $super;
$authenticationData = $this->login();
$headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
$role = new Role();
$role->name = 'myRole';
$role->validate();
$saved = $role->save();
$this->assertTrue($saved);
$roles = Role::getAll();
$compareData = $this->getModelToApiDataUtilData($roles[0]);
$response = $this->createApiCallWithRelativeUrl('read/' . $compareData['id'], 'GET', $headers);
$response = json_decode($response, true);
$this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
$this->assertEquals($compareData, $response['data']);
}
示例4: createRoles
public static function createRoles()
{
foreach (self::$parentToChildRoleNames as $parentRoleName => $childRoleName) {
if ($childRoleName !== null) {
$childRole = new Role();
$childRole->name = $childRoleName;
$childRole->validate();
$saved = $childRole->save();
assert('$saved');
}
try {
$parentRole = Role::getByName($parentRoleName);
} catch (NotFoundException $e) {
$parentRole = new Role();
}
$parentRole->name = $parentRoleName;
if ($childRoleName !== null) {
$parentRole->roles->add($childRole);
}
$saved = $parentRole->save();
assert('$saved');
$parentRole->forget();
if ($childRoleName !== null) {
$childRole->forget();
}
}
foreach (self::$usernamesToUserInfo as $username => $userInfo) {
$roleName = $userInfo[2];
if ($roleName !== null) {
assert('is_string($roleName)');
$role = Role::getByName($roleName);
$user = User::getByUsername($username);
$role->users->add($user);
$saved = $role->save();
assert('$saved');
$user->forget();
//do this so that if you retrieve the $user, $user->role will be known.
}
}
}
示例5: doValidate
/**
* This function performs the validation work for complex object models.
*
* In addition to checking the current object, all related objects will
* also be validated. If all pass then <code>true</code> is returned; otherwise
* an aggreagated array of ValidationFailed objects will be returned.
*
* @param array $columns Array of column names to validate.
* @return mixed <code>true</code> if all validations pass; array of <code>ValidationFailed</code> objets otherwise.
*/
protected function doValidate($columns = null)
{
if (!$this->alreadyInValidation) {
$this->alreadyInValidation = true;
$retval = null;
$failureMap = array();
// We call the validate method on the following object(s) if they
// were passed to this object by their coresponding set
// method. This object relates to these object(s) by a
// foreign key reference.
if ($this->aDepartment !== null) {
if (!$this->aDepartment->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aDepartment->getValidationFailures());
}
}
if ($this->aDesignation !== null) {
if (!$this->aDesignation->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aDesignation->getValidationFailures());
}
}
if ($this->aRole !== null) {
if (!$this->aRole->validate($columns)) {
$failureMap = array_merge($failureMap, $this->aRole->getValidationFailures());
}
}
if (($retval = EmployeePeer::doValidate($this, $columns)) !== true) {
$failureMap = array_merge($failureMap, $retval);
}
if ($this->collDutyRostersRelatedByEmployeeId !== null) {
foreach ($this->collDutyRostersRelatedByEmployeeId as $referrerFK) {
if (!$referrerFK->validate($columns)) {
$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
}
}
}
if ($this->collDutyRostersRelatedBySubstituteId !== null) {
foreach ($this->collDutyRostersRelatedBySubstituteId as $referrerFK) {
if (!$referrerFK->validate($columns)) {
$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
}
}
}
if ($this->collUsers !== null) {
foreach ($this->collUsers as $referrerFK) {
if (!$referrerFK->validate($columns)) {
$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
}
}
}
if ($this->collVisitsRelatedByDoctorId !== null) {
foreach ($this->collVisitsRelatedByDoctorId as $referrerFK) {
if (!$referrerFK->validate($columns)) {
$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
}
}
}
if ($this->collVisitsRelatedByWardDocId !== null) {
foreach ($this->collVisitsRelatedByWardDocId as $referrerFK) {
if (!$referrerFK->validate($columns)) {
$failureMap = array_merge($failureMap, $referrerFK->getValidationFailures());
}
}
}
$this->alreadyInValidation = false;
}
return !empty($failureMap) ? $failureMap : true;
}