1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115:
<?php
class FormFieldAuthorizationsSetter extends AbstractFormField
{
public function __construct($id, AuthorizationsSettings $value, array $field_options = array())
{
parent::__construct($id, '', $value, $field_options);
}
public function display()
{
$template = $this->get_template_to_use();
$this->assign_common_template_variables($template);
foreach ($this->get_value()->get_actions() as $action)
{
$template->assign_block_vars('actions', array(
'ID' => 'auth' . $action->get_bit(),
'HTML_ID' => $this->get_html_id() . 'auth' . $action->get_bit(),
'BIT' => $action->get_bit(),
'LABEL' => $action->get_label(),
'DESCRIPTION' => $action->get_description(),
'AUTH_FORM' => Authorizations::generate_select($action->get_bit(), $action->build_auth_array(), array(), $this->get_html_id() . $action->get_bit(), $this->is_disabled(), $this->is_disabled(), $action->get_disabled_ranks())
));
}
return $template;
}
protected function get_default_template()
{
return new FileTemplate('framework/builder/form/FormFieldAuthorizationsSetter.tpl');
}
public function retrieve_value()
{
$request = AppContext::get_request();
foreach ($this->get_value()->get_actions() as $action)
{
if ($request->has_parameter('groups_auth' . $this->get_html_id() . $action->get_bit()))
{
$roles_auths = self::get_action_auth($action, $request->get_array('groups_auth' . $this->get_html_id() . $action->get_bit(), array()));
$roles_auths = self::clean_groups_auths($roles_auths);
if ($request->has_parameter('members_auth' . $this->get_html_id() . $action->get_bit()))
{
$member_auths = self::get_action_auth($action, $request->get_array('members_auth' . $this->get_html_id() . $action->get_bit(), array()));
foreach (self::clean_members_auths($member_auths) as $member => $auth)
{
$roles_auths[$member] = $auth;
}
}
$roles = new RolesAuthorizations($roles_auths);
}
else
{
$roles = new RolesAuthorizations();
}
$action->set_roles_auths($roles);
}
}
private static function get_action_auth(ActionAuthorization $action, array $values)
{
$auth_array = array();
foreach ($values as $role_htlm_id)
{
$role = TextHelper::substr($role_htlm_id, TextHelper::strlen($action->get_bit()) - 1);
$auth_array[$role_htlm_id] = 1;
}
return $auth_array;
}
private static function clean_groups_auths(array $auths)
{
$g_auths = array();
foreach ($auths as $role => $auth)
{
if ($role[0] == 'r' || $role != '0')
{
$g_auths[$role] = $auth;
}
}
return $g_auths;
}
private static function clean_members_auths(array $auths)
{
$m_auths = array();
foreach ($auths as $member_id => $auth)
{
if ($member_id != 0)
{
$m_auths['m' . $member_id] = $auth;
}
}
return $m_auths;
}
}
?>