本文整理汇总了PHP中Roles::hydrate方法的典型用法代码示例。如果您正苦于以下问题:PHP Roles::hydrate方法的具体用法?PHP Roles::hydrate怎么用?PHP Roles::hydrate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Roles
的用法示例。
在下文中一共展示了Roles::hydrate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _save
/**
* @param \Roles $role
* @param $error
* @return bool|\Roles
* @throws \Exception
*/
protected function _save(\Roles $role, &$error)
{
$current_status = $role->getStatus();
$data = $this->post('role', 'ARRAY', []);
$role->hydrate($data);
if (!isset($data['admin_access'])) {
$role->setAdminAccess(0);
}
$parentId = $this->post('role_parent', 'INT', 0);
if ($parentId == 0) {
$parent = \Roles::retrieveRoot();
} else {
$parent = \Roles::retrieveById($parentId);
if (!$parent) {
$error['parent'] = array(t('Role parent not found with id:' . $parentId));
return false;
}
}
$is_new = $role->isNew();
$role->beginTransaction();
try {
if ($is_new) {
//always save
$role->setParentId($parent->getId());
$role->setStatus($parent->getStatus());
$role->insertAsLastChildOf($parent);
//dispatch event
$this->dispatch('onCreateNewRole', new CMSBackendEvent($this, ['role' => $role]));
} else {
$currentParent = $role->getParent();
if ($parent->getId() == $role->getId()) {
//something fucked
$error['parent'] = t('Could not move to child of itself!');
}
if ($currentParent->getId() != $parent->getId()) {
//move tree
$role->moveToLastChildOf($parent);
$role->setParentId($parent->getId());
$role->setStatus($parent->getStatus());
if (!$role->save()) {
//save information first
$this->dispatch('onUpdateRole', new CMSBackendEvent($this, ['role' => $role]));
if (!$role->isValid()) {
$failures = $role->getValidationFailures();
foreach ($failures as $failure) {
$error[$failure->getColumn()] = $failure->getMessage();
}
}
}
} else {
//simply save information
if ($role->save()) {
//dispatch event update
$this->dispatch('onUpdateRole', new CMSBackendEvent($this, ['role' => $role]));
} else {
if (!$role->isValid()) {
$failures = $role->getValidationFailures();
foreach ($failures as $failure) {
$error[$failure->getColumn()] = $failure->getMessage();
}
}
}
if (!empty($error)) {
$role->rollBack();
return false;
}
}
//end simply save information
if ($current_status != $role->getStatus() && $role->getStatus() == \Roles::STATUS_INACTIVE) {
//change status to INACTIVE
$role->changeDescendantsStatus(\Roles::STATUS_INACTIVE);
}
}
if ($role->isValid()) {
$role->commit();
return $role;
}
$role->rollBack();
} catch (\Exception $e) {
$role->rollBack();
throw $e;
}
$failures = $role->getValidationFailures();
foreach ($failures as $failure) {
$error[$failure->getColumn()] = $failure->getMessage();
}
return false;
}