[ Index ]

PHP Cross Reference of Joomla 4.2.2 documentation

title

Body

[close]

/administrator/components/com_contact/src/Service/HTML/ -> Icon.php (source)

   1  <?php
   2  
   3  /**
   4   * @package     Joomla.Site
   5   * @subpackage  com_contact
   6   *
   7   * @copyright   (C) 2020 Open Source Matters, Inc. <https://www.joomla.org>
   8   * @license     GNU General Public License version 2 or later; see LICENSE.txt
   9   */
  10  
  11  namespace Joomla\Component\Contact\Administrator\Service\HTML;
  12  
  13  use Joomla\CMS\Application\CMSApplication;
  14  use Joomla\CMS\Factory;
  15  use Joomla\CMS\HTML\HTMLHelper;
  16  use Joomla\CMS\Language\Text;
  17  use Joomla\CMS\Layout\LayoutHelper;
  18  use Joomla\CMS\Router\Route;
  19  use Joomla\CMS\Uri\Uri;
  20  use Joomla\CMS\User\UserFactoryInterface;
  21  use Joomla\Component\Contact\Site\Helper\RouteHelper;
  22  use Joomla\Registry\Registry;
  23  
  24  // phpcs:disable PSR1.Files.SideEffects
  25  \defined('_JEXEC') or die;
  26  // phpcs:enable PSR1.Files.SideEffects
  27  
  28  /**
  29   * Content Component HTML Helper
  30   *
  31   * @since  4.0.0
  32   */
  33  class Icon
  34  {
  35      /**
  36       * The user factory
  37       *
  38       * @var    UserFactoryInterface
  39       *
  40       * @since  4.2.0
  41       */
  42      private $userFactory;
  43  
  44      /**
  45       * Service constructor
  46       *
  47       * @param   UserFactoryInterface  $userFactory  The userFactory
  48       *
  49       * @since   4.0.0
  50       */
  51      public function __construct(UserFactoryInterface $userFactory)
  52      {
  53          $this->userFactory = $userFactory;
  54      }
  55  
  56      /**
  57       * Method to generate a link to the create item page for the given category
  58       *
  59       * @param   object    $category  The category information
  60       * @param   Registry  $params    The item parameters
  61       * @param   array     $attribs   Optional attributes for the link
  62       *
  63       * @return  string  The HTML markup for the create item link
  64       *
  65       * @since  4.0.0
  66       */
  67      public function create($category, $params, $attribs = array())
  68      {
  69          $uri = Uri::getInstance();
  70  
  71          $url = 'index.php?option=com_contact&task=contact.add&return=' . base64_encode($uri) . '&id=0&catid=' . $category->id;
  72  
  73          $text = '';
  74  
  75          if ($params->get('show_icons')) {
  76              $text .= '<span class="icon-plus icon-fw" aria-hidden="true"></span>';
  77          }
  78  
  79          $text .= Text::_('COM_CONTACT_NEW_CONTACT');
  80  
  81          // Add the button classes to the attribs array
  82          if (isset($attribs['class'])) {
  83              $attribs['class'] .= ' btn btn-primary';
  84          } else {
  85              $attribs['class'] = 'btn btn-primary';
  86          }
  87  
  88          $button = HTMLHelper::_('link', Route::_($url), $text, $attribs);
  89  
  90          return $button;
  91      }
  92  
  93      /**
  94       * Display an edit icon for the contact.
  95       *
  96       * This icon will not display in a popup window, nor if the contact is trashed.
  97       * Edit access checks must be performed in the calling code.
  98       *
  99       * @param   object    $contact  The contact information
 100       * @param   Registry  $params   The item parameters
 101       * @param   array     $attribs  Optional attributes for the link
 102       * @param   boolean   $legacy   True to use legacy images, false to use icomoon based graphic
 103       *
 104       * @return  string   The HTML for the contact edit icon.
 105       *
 106       * @since   4.0.0
 107       */
 108      public function edit($contact, $params, $attribs = array(), $legacy = false)
 109      {
 110          $user = Factory::getUser();
 111          $uri  = Uri::getInstance();
 112  
 113          // Ignore if in a popup window.
 114          if ($params && $params->get('popup')) {
 115              return '';
 116          }
 117  
 118          // Ignore if the state is negative (trashed).
 119          if ($contact->published < 0) {
 120              return '';
 121          }
 122  
 123          // Show checked_out icon if the contact is checked out by a different user
 124          if (
 125              property_exists($contact, 'checked_out')
 126              && property_exists($contact, 'checked_out_time')
 127              && !is_null($contact->checked_out)
 128              && $contact->checked_out !== $user->get('id')
 129          ) {
 130              $checkoutUser = $this->userFactory->loadUserById($contact->checked_out);
 131              $date         = HTMLHelper::_('date', $contact->checked_out_time);
 132              $tooltip      = Text::sprintf('COM_CONTACT_CHECKED_OUT_BY', $checkoutUser->name)
 133                  . ' <br> ' . $date;
 134  
 135              $text = LayoutHelper::render('joomla.content.icons.edit_lock', array('contact' => $contact, 'tooltip' => $tooltip, 'legacy' => $legacy));
 136  
 137              $attribs['aria-describedby'] = 'editcontact-' . (int) $contact->id;
 138              $output = HTMLHelper::_('link', '#', $text, $attribs);
 139  
 140              return $output;
 141          }
 142  
 143          $contactUrl = RouteHelper::getContactRoute($contact->slug, $contact->catid, $contact->language);
 144          $url        = $contactUrl . '&task=contact.edit&id=' . $contact->id . '&return=' . base64_encode($uri);
 145  
 146          if ((int) $contact->published === 0) {
 147              $tooltip = Text::_('COM_CONTACT_EDIT_UNPUBLISHED_CONTACT');
 148          } else {
 149              $tooltip = Text::_('COM_CONTACT_EDIT_PUBLISHED_CONTACT');
 150          }
 151  
 152          $nowDate = strtotime(Factory::getDate());
 153          $icon    = $contact->published ? 'edit' : 'eye-slash';
 154  
 155          if (
 156              ($contact->publish_up !== null && strtotime($contact->publish_up) > $nowDate)
 157              || ($contact->publish_down !== null && strtotime($contact->publish_down) < $nowDate)
 158          ) {
 159              $icon = 'eye-slash';
 160          }
 161  
 162          $aria_described = 'editcontact-' . (int) $contact->id;
 163  
 164          $text = '<span class="icon-' . $icon . '" aria-hidden="true"></span>';
 165          $text .= Text::_('JGLOBAL_EDIT');
 166          $text .= '<div role="tooltip" id="' . $aria_described . '">' . $tooltip . '</div>';
 167  
 168          $attribs['aria-describedby'] = $aria_described;
 169          $output = HTMLHelper::_('link', Route::_($url), $text, $attribs);
 170  
 171          return $output;
 172      }
 173  }


Generated: Wed Sep 7 05:41:13 2022 Chilli.vc Blog - For Webmaster,Blog-Writer,System Admin and Domainer