FOF30\Form\Field\User::getRepeatable PHP Метод

getRepeatable() публичный Метод

Get the rendering of this field type for a repeatable (grid) display, e.g. in a view listing many item (typically a "browse" task)
С версии: 2.0
public getRepeatable ( ) : string
Результат string The field HTML
    public function getRepeatable()
    {
        static $userCache = array();
        if (isset($this->element['legacy'])) {
            return $this->getInput();
        }
        // Initialise
        $show_username = !$this->element['show_username'] == 'false';
        $show_email = !$this->element['show_email'] == 'false';
        $show_name = !$this->element['show_name'] == 'false';
        $show_id = !$this->element['show_id'] == 'false';
        $show_avatar = !$this->element['show_avatar'] == 'false';
        $show_link = $this->element['show_link'] == 'true';
        $link_url = $this->element['link_url'] ? $this->element['link_url'] : null;
        $avatar_method = 'gravatar';
        $avatar_size = $this->element['avatar_size'] ? $this->element['avatar_size'] : 64;
        $class = '';
        // Get the user record
        $key = is_numeric($this->value) ? $this->value : 'empty';
        $key = $key == 0 ? 'zero' : $key;
        if (!array_key_exists($key, $userCache)) {
            $userCache[$key] = $this->form->getContainer()->platform->getUser($this->value);
        }
        $user = $userCache[$key];
        // Get the field parameters
        if ($this->class) {
            $class = ' class="' . $this->class . '"';
        }
        if ($this->element['avatar_method']) {
            $avatar_method = strtolower($this->element['avatar_method']);
        }
        if (!$link_url && $this->form->getContainer()->platform->isBackend()) {
            $link_url = 'index.php?option=com_users&task=user.edit&id=[USER:ID]';
        } elseif (!$link_url) {
            // If no link is defined in the front-end, we can't create a
            // default link. Therefore, show no link.
            $show_link = false;
        }
        // Post-process the link URL
        if ($show_link) {
            $replacements = array('[USER:ID]' => $user->id, '[USER:USERNAME]' => $user->username, '[USER:EMAIL]' => $user->email, '[USER:NAME]' => $user->name);
            foreach ($replacements as $key => $value) {
                $link_url = str_replace($key, $value, $link_url);
            }
            $link_url = $this->parseFieldTags($link_url);
        }
        // Get the avatar image, if necessary
        $avatar_url = '';
        if ($show_avatar) {
            if ($avatar_method == 'plugin') {
                // Use the user plugins to get an avatar
                $this->form->getContainer()->platform->importPlugin('user');
                $jResponse = $this->form->getContainer()->platform->runPlugins('onUserAvatar', array($user, $avatar_size));
                if (!empty($jResponse)) {
                    foreach ($jResponse as $response) {
                        if ($response) {
                            $avatar_url = $response;
                        }
                    }
                }
                if (empty($avatar_url)) {
                    $show_avatar = false;
                }
            } else {
                // Fall back to the Gravatar method
                $md5 = md5($user->email);
                if ($this->form->getContainer()->platform->isCli()) {
                    $scheme = 'http';
                } else {
                    $scheme = \JUri::getInstance()->getScheme();
                }
                if ($scheme == 'http') {
                    $avatar_url = 'http://www.gravatar.com/avatar/' . $md5 . '.jpg?s=' . $avatar_size . '&d=mm';
                } else {
                    $avatar_url = 'https://secure.gravatar.com/avatar/' . $md5 . '.jpg?s=' . $avatar_size . '&d=mm';
                }
            }
        }
        // Generate the HTML
        $html = '<div id="' . $this->id . '" ' . $class . '>';
        if ($show_avatar) {
            $html .= '<img src="' . $avatar_url . '" align="left" class="fof-usersfield-avatar" />';
        }
        if ($show_link) {
            $html .= '<a href="' . $link_url . '">';
        }
        if ($show_username) {
            $html .= '<span class="fof-usersfield-username">' . $user->username . '</span>';
        }
        if ($show_id) {
            $html .= '<span class="fof-usersfield-id">' . $user->id . '</span>';
        }
        if ($show_name) {
            $html .= '<span class="fof-usersfield-name">' . $user->name . '</span>';
        }
        if ($show_email) {
            $html .= '<span class="fof-usersfield-email">' . $user->email . '</span>';
        }
        if ($show_link) {
            $html .= '</a>';
        }
        $html .= '</div>';
        return $html;
    }