Skip to content

Commit

Permalink
move company html to template
Browse files Browse the repository at this point in the history
  • Loading branch information
0m3r committed Dec 21, 2021
1 parent 6418770 commit d8d833b
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 46 deletions.
60 changes: 19 additions & 41 deletions Block/TestimonialsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,40 +152,27 @@ public function getProfileImageUrl($testimonial)
}

/**
* @param \Swissup\Testimonials\Model\Data $testimonial
* @return string
*/
public function getContactsHtml($testimonial)
public function getEmailIconUrl()
{
$result = '';
if ($this->configHelper->showUserEmail()) {
$email = $this->escapeHtml($testimonial->getEmail());
if ($email) {
$icon = $this->getViewFileUrl(self::EMAIL_ICON);
$title = __('Email');
$result .= "<a title='$title' href='$email' target='_blank'><img src='$icon' /></a>";
}
}

if ($this->configHelper->isFacebookEnabled()) {
$facebook = $this->escapeUrl($testimonial->getFacebook());
if ($facebook) {
$fbIcon = $this->getViewFileUrl(self::FACEBOOK_ICON);
$fbTitle = __('Facebook');
$result .= "<a title='$fbTitle' href='$facebook' target='_blank'><img src='$fbIcon' /></a>";
}
}
return $this->getViewFileUrl(self::EMAIL_ICON);
}

if ($this->configHelper->isTwitterEnabled()) {
$twitter = $this->escapeUrl($testimonial->getTwitter());
if ($twitter) {
$twtrIcon = $this->getViewFileUrl(self::TWITTER_ICON);
$twtrTitle = __('Twitter');
$result .= "<a title='$twtrTitle' href='$twitter' target='_blank'><img src='$twtrIcon' /></a>";
}
}
/**
* @return string
*/
public function getFacebookIconUrl()
{
return $this->getViewFileUrl(self::FACEBOOK_ICON);
}

return $result;
/**
* @return string
*/
public function getTwitterIconUrl()
{
return $this->getViewFileUrl(self::TWITTER_ICON);
}

/**
Expand All @@ -199,19 +186,10 @@ public function getRatingPercent($testimonial)
}

/**
* @param \Swissup\Testimonials\Model\Data $testimonial
* @return string|bool
* @return \Swissup\Testimonials\Helper\Config
*/
public function getCompanyHtml($testimonial)
public function getConfigHelper()
{
$company = $this->escapeHtml($testimonial->getCompany());
if (!$this->configHelper->isCompanyEnabled() || !$company) return false;

$website = $this->escapeUrl($testimonial->getWebsite());
if ($website && $this->configHelper->isWebsiteEnabled()) {
$company = "<a href='$website' target='_blank'>$company</a>";
}

return $company;
return $this->configHelper;
}
}
44 changes: 39 additions & 5 deletions view/frontend/templates/list.phtml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php /** @var $block \Swissup\Testimonials\Block\TestimonialsList */ ?>
<?php $testimonials = $block->getTestimonials(); ?>
<?php $testimonials = $block->getTestimonials();
$configHelper = $block->getConfigHelper();
?>
<?php if (!$block->getIsAjax()): ?>
<div class="testimonials-list">
<div class="testimonials" data-mage-init='{"Swissup_Testimonials/js/list":{"loadAction":"<?= $block->escapeUrl($block->getLoadAction()) ?>"}}'>
Expand Down Expand Up @@ -38,11 +40,43 @@
<img src="<?= $block->getProfileImageUrl($testimonial) ?>" alt="Profile image" />
<div class="author">
<h5><?= $block->escapeHtml($testimonial->getName()) ?></h5>
<?php if ($companyHtml = $block->getCompanyHtml($testimonial)): ?>
<p><?= $companyHtml ?></p>
<?php
$company = $testimonial->getCompany();
$isCompanyEnabled = $configHelper->isCompanyEnabled() && $company;
$website = $testimonial->getWebsite();
$isWebsiteEnabled = $configHelper->isWebsiteEnabled() && $website;
if ($isCompanyEnabled && $isWebsiteEnabled): ?>
<p>
<a href="<?= $block->escapeUrl($website) ?>" target='_blank'>
<?= $block->escapeHtml($company) ?>
</a>
</p>
<?php endif; ?>
<?php if ($contacts = $block->getContactsHtml($testimonial)): ?>
<p class="contacts-info"><?= $contacts ?></p>
<?php
$email = $testimonial->getEmail();
$isShowUserEmail = $configHelper->showUserEmail() && $email;
$facebook = $testimonial->getFacebook();
$isFacebookEnabled = $configHelper->isFacebookEnabled() && $facebook;
$twitter = $testimonial->getTwitter();
$isTwitterEnabled = $configHelper->isTwitterEnabled() && $twitter;
if ($isShowUserEmail || $isFacebookEnabled || $isTwitterEnabled): ?>
<p class="contacts-info">
<?php if ($isShowUserEmail): ?>
<a title="<?= $block->escapeHtml(__('Email')) ?>" href="mailto:<?= $block->escapeHtml($email) ?>" target="_blank">
<img src="<?= $block->getEmailIconUrl() ?>" />
</a>
<?php endif; ?>
<?php if ($isFacebookEnabled): ?>
<a title="<?= $block->escapeHtml(__('Facebook')) ?>" href="<?= $block->escapeUrl($facebook) ?>" target="_blank">
<img src="<?= $block->getFacebookIconUrl() ?>" />
</a>
<?php endif; ?>
<?php if ($isTwitterEnabled): ?>
<a title="<?= $block->escapeHtml(__('Twitter')) ?>" href="<?= $block->escapeUrl($twitter) ?>" target="_blank">
<img src="<?= $block->getTwitterIconUrl() ?>" />
</a>
<?php endif; ?>
</p>
<?php endif; ?>
</div>
</div>
Expand Down
1 change: 1 addition & 0 deletions view/frontend/templates/widgets/slider.phtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php
/* @var $block \Swissup\Testimonials\Block\Widgets\Slider */
$testimonials = $block->getTestimonials();
if (!count($testimonials)) {
return;
Expand Down

0 comments on commit d8d833b

Please sign in to comment.