$encoded=htmlentities($options['label'],ENT_QUOTES);
$html.="<option selected=selected value=''>$encoded</option>";
}
- foreach ($selectors as $selector) {
- $display=htmlentities($selector['display'],ENT_QUOTES);
- $value=$selector['value'];
- $html .= "<option value='$value'";
- if ($selector['selected']) $html .= " selected=selected";
- if ($selector['disabled']) $html .= " disabled=disabled";
- $html .= ">$display</option>\n";
+ if ($selectors) {
+ foreach ($selectors as $selector) {
+ $display=htmlentities($selector['display'],ENT_QUOTES);
+ $value=$selector['value'];
+ $html .= "<option value='$value'";
+ if ($selector['selected']) $html .= " selected=selected";
+ if ($selector['disabled']) $html .= " disabled=disabled";
+ $html .= ">$display</option>\n";
+ }
}
$html .= "</select>";
return $html;
// helper function to handle role-oriented selectors
// because GetRoles does not correctly support filters, it's really painful to do this
- static public function role_selectors($api,$role_ids=NULL,$current=NULL) {
+ static public function role_selectors($roles,$current_id=NULL) {
function role_selector ($role) { return array('display'=>$role['name'],"value"=>$role['role_id']); }
- function role_id ($role) { return $role['role_id']; }
-
- $all_roles=$api->GetRoles();
- if ( ! $role_ids)
- $role_ids=array_map("role_id",$all_roles);
-
$selectors=array();
// preserve input order
- foreach ($role_ids as $role_id) {
- foreach ($all_roles as $all_role) {
- if ($all_role['role_id'] == $role_id) {
- $selector=role_selector($all_role);
- if ($role_id == $current)
+ if ( ! $roles) {
+ drupal_set_message('WARNING: empty roles in role_selectors');
+ } else {
+ foreach ($roles as $role) {
+ $selector=role_selector($role);
+ if ($role['role_id'] == $current_id)
$selector['selected']=true;
- $selectors []= $selector;
- }
+ $selectors []= $selector;
}
}
return $selectors;
}
- static public function role_selectors_excluding ($api,$exclude_role_ids=NULL,$current=NULL) {
- if ( ! $exclude_role_ids ) $exclude_role_ids = array();
- $all_roles=$api->GetRoles();
- $role_ids = array();
- foreach ($all_roles as $role) {
- if ( ! in_array ($role['role_id'],$exclude_role_ids)) {
- $role_ids [] = $role['role_id'];
- }
- }
- return PlekitForm::role_selectors($api,$role_ids,$current);
- }
}
// a form with a single button