Skip to content

Commit

Permalink
Merge pull request #499: Contact link viewhelper
Browse files Browse the repository at this point in the history
* pr-499:
  Issue #496
  • Loading branch information
TiSiE committed Nov 8, 2018
2 parents 5c149ce + 29ba0d6 commit 911e586
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 1 deletion.
2 changes: 1 addition & 1 deletion module/Applications/view/applications/manage/detail.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ endif;
<?php endif;?>
<tr>
<td><?php echo $this->translate('agent')?>:</td>
<td><?php echo $this->link($job->getUser()->getInfo()->getDisplayName())?></td>
<td><?php echo $this->contactLink($job->getUser()->getInfo())?></td>
</tr>
<?php
if ($job->hasMetaData('organizations:managers')): ?>
Expand Down
1 change: 1 addition & 0 deletions module/Core/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@
'salutation' => 'Core\View\Helper\Salutation',
'period' => 'Core\View\Helper\Period',
'link' => 'Core\View\Helper\Link',
'contactLink' => 'Core\View\Helper\ContactLink',
'languageSwitcher' => 'Core\View\Helper\LanguageSwitcher',
'rating' => 'Core\View\Helper\Rating',
'base64' => 'Core\View\Helper\Base64',
Expand Down
77 changes: 77 additions & 0 deletions module/Core/src/View/Helper/ContactLink.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
<?php
/**
* YAWIK
*
* @filesource
* @copyright (c) 2013 - 2016 Cross Solution (http://cross-solution.de)
* @license MIT
*/

/** Core view helpers */
namespace Core\View\Helper;

use Zend\View\Helper\AbstractHelper;
use Auth\Entity\Info;

/**
* This helper generates HTML email link markup from a user info entity.
*
* <code>
*
* $this->contactLink($user->getInfo());
* // Outputs: <a href="mailto:[email protected]">Fancy Name</a>
*
* $this->contactLink($user->getInfo());
* // Outputs: <a href="mailto:[email protected]">[email protected]</a>
*
* $this->contactLink($user->getInfo());
* // Outputs: Fancy Name
* </code>
*
*/
class ContactLink extends AbstractHelper
{

/**
* generates an email link from a user info entity
*
* @param \Auth\Entity\Info $userInfo
* @param array $attributes
* @return string
*/
public function __invoke(Info $userInfo, array $attributes = array())
{
$email = $userInfo->getEmail();
$displayName = $userInfo->getDisplayName(false);

if ($email) {
$label = $displayName
? $displayName
: $email;

$attributesStr = $attributes
? $this->createAttributesString($attributes)
: '';

return sprintf('<a %s href="mailto:%s">%s</a>', $attributesStr, $email, $label);
} else {
return $displayName
? $displayName
: '';
}
}

protected function createAttributesString(array $attributes)
{
$renderer = $this->getView();
$escape = $renderer->plugin('escapehtml');
$escapeAttr = $renderer->plugin('escapehtmlattr');
$attr = array();

foreach ($attributes as $name => $value) {
$attr[] = $escape($name) . (strlen($value) ? ('="' . $escapeAttr($value) . '"') : '');
}

return implode(' ', $attr);
}
}

0 comments on commit 911e586

Please sign in to comment.