public function radio($fieldName, array $data, array $options, array $attributes = []) { $defaultAttributes = ['id' => 'Widget' . ucfirst($fieldName) . '-id', 'name' => $fieldName, 'label' => false]; if (count($data) > 0) { $attributes['value'] = $data[$fieldName]; } $attr = HuradFunctions::arraySliceAssoc($attributes, ['show-type', 'btn-class']); unset($attributes['show-type']); unset($attributes['btn-class']); $attributes = Hash::merge($defaultAttributes, $attributes); if ($attr['show-type'] == 'btn-group') { if (!isset($attr['btn-class'])) { $attr['btn-class'] = 'btn-default'; } $opt[] = '<div class="btn-group" data-toggle="buttons">'; foreach ($options as $value => $label) { if (isset($attributes['value']) && $value == $attributes['value']) { $active = ' active'; } else { $active = ''; } $opt[] = '<label class="btn ' . $attr['btn-class'] . $active . '">'; $opt[] = $this->Form->radio($fieldName, [$value => $label], $attributes); $opt[] = '</label>'; } $opt[] = '</div>'; } else { foreach ($options as $value => $label) { $opt[] = '<div class="radio">'; $opt[] = '<label>'; $opt[] = $this->Form->radio($fieldName, [$value => $label], $attributes); $opt[] = '</label>'; $opt[] = '</div>'; } } return implode('', $opt); }
/** * List all the authors of the blog, with several options available. * * @since 0.1.0 * * @param array $args The argument array. * * @return null|string The output, if echo is set to false. */ public function getListAuthors($args = array()) { $defaults = ['order_by' => 'username', 'order' => 'ASC', 'limit' => '', 'count' => false, 'exclude_admin' => true, 'show_fullname' => false, 'hide_empty' => false, 'style' => 'list', 'html' => true]; $args = Hash::merge($defaults, $args); $return = ''; $queryArgs = HuradFunctions::arraySliceAssoc($args, ['order_by', 'order', 'limit']); $authors = ClassRegistry::init('User')->getUsers($queryArgs); foreach ($authors as $author) { $author = ClassRegistry::init('User')->getUser($author['User']['id']); if ($args['exclude_admin'] && 'administrator' == $author['User']['role']) { continue; } $posts = ClassRegistry::init('Post')->countUserPosts($author['User']['id']); if (!$posts && $args['hide_empty']) { continue; } if ($args['show_fullname'] && isset($author['UserMeta']['first_name']) && isset($author['UserMeta']['last_name'])) { $name = "{$author['UserMeta']['first_name']} {$author['UserMeta']['last_name']}"; } else { $name = $author['UserMeta']['display_name']; } if (!$args['html']) { $return .= $name . ', '; continue; } if ('list' == $args['style']) { $return .= '<li>'; } $link = $this->Html->link($name, $this->getAuthorPostsUrl($author['User']['id']), ['title' => __("Posts by %s", $author['UserMeta']['display_name'])]); if ($args['count']) { $link .= ' (' . $posts . ')'; } $return .= $link; $return .= 'list' == $args['style'] ? '</li>' : ', '; } $return = rtrim($return, ', '); return $return; }