Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
sergey-galenko committed Nov 4, 2018
1 parent 659b857 commit 81fa925
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 1 deletion.
2 changes: 1 addition & 1 deletion module/Applications/view/applications/manage/detail.phtml
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
Expand Up @@ -427,6 +427,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/Core/View/Helper/ContactLink.php
@@ -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@address.net">Fancy Name</a>
*
* $this->contactLink($user->getInfo());
* // Outputs: <a href="mailto:email@address.net">email@address.net</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);
}
}
1 change: 1 addition & 0 deletions module/Core/src/autoload_classmap.php
Expand Up @@ -314,6 +314,7 @@
'Core\View\Helper\InsertFile\FileEvent' => __DIR__ . '/Core/View/Helper/InsertFile/FileEvent.php',
'Core\View\Helper\LanguageSwitcher' => __DIR__ . '/Core/View/Helper/LanguageSwitcher.php',
'Core\View\Helper\Link' => __DIR__ . '/Core/View/Helper/Link.php',
'Core\View\Helper\ContactLink' => __DIR__ . '/Core/View/Helper/ContactLink.php',
'Core\View\Helper\Params' => __DIR__ . '/Core/View/Helper/Params.php',
'Core\View\Helper\Period' => __DIR__ . '/Core/View/Helper/Period.php',
'Core\View\Helper\Proxy' => __DIR__ . '/Core/View/Helper/Proxy.php',
Expand Down

0 comments on commit 81fa925

Please sign in to comment.