X-Git-Url: https://vcs.fsf.org/?a=blobdiff_plain;f=CRM%2FProfile%2FPage%2FDynamic.php;h=2e05630f61b5ddaee03f2459146d37e04b54fa36;hb=33e1c468b8a2f15611ac8ed60a6777e198a232fe;hp=67f7edf0d508da8bf61ad99b64d6ea93efc51349;hpb=6217c68b76b3d14556bbace6fbfdd5264b92ab06;p=civicrm-core.git diff --git a/CRM/Profile/Page/Dynamic.php b/CRM/Profile/Page/Dynamic.php index 67f7edf0d5..2e05630f61 100644 --- a/CRM/Profile/Page/Dynamic.php +++ b/CRM/Profile/Page/Dynamic.php @@ -9,6 +9,8 @@ +--------------------------------------------------------------------+ */ +use Civi\Api4\Email; + /** * * @package CRM @@ -78,6 +80,13 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page { protected $_recordId = NULL; + /** + * Should the primary email be converted into a link, if emailabe. + * + * @var bool + */ + protected $isShowEmailTaskLink = FALSE; + /** * * fetch multirecord as well as non-multirecord fields @@ -97,15 +106,18 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page { * @param bool $skipPermission * @param null $profileIds * - * @return \CRM_Profile_Page_Dynamic + * @param bool $isShowEmailTaskLink + * + * @throws \CRM_Core_Exception */ - public function __construct($id, $gid, $restrict, $skipPermission = FALSE, $profileIds = NULL) { + public function __construct($id, $gid, $restrict, $skipPermission = FALSE, $profileIds = NULL, $isShowEmailTaskLink = FALSE) { parent::__construct(); $this->_id = $id; $this->_gid = $gid; $this->_restrict = $restrict; $this->_skipPermission = $skipPermission; + $this->isShowEmailTaskLink = $isShowEmailTaskLink; if (!array_key_exists('multiRecord', $_GET)) { $this->set('multiRecord', NULL); @@ -315,6 +327,11 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page { $labels[$index] = preg_replace('/\s+|\W+/', '_', $name); } + if ($this->isShowEmailTaskLink) { + foreach ($this->getEmailFields($fields) as $fieldName) { + $values[$fields[$fieldName]['title']] = $this->getLinkedEmail($values[$fields[$fieldName]['title']]); + } + } foreach ($values as $title => $value) { $profileFields[$labels[$title]] = [ 'label' => $title, @@ -416,4 +433,47 @@ class CRM_Profile_Page_Dynamic extends CRM_Core_Page { return $fileName ? $fileName : parent::overrideExtraTemplateFileName(); } + /** + * Get the email field as a task link, if not on hold or set to do_not_email. + * + * @param string $email + * + * @return string + * @throws \API_Exception + * @throws \Civi\API\Exception\UnauthorizedException + */ + protected function getLinkedEmail($email): string { + if (!$email) { + return ''; + } + $emailID = Email::get()->setOrderBy(['is_primary' => 'DESC'])->setWhere([['contact_id', '=', $this->_id], ['email', '=', $email], ['on_hold', '=', FALSE], ['contact_id.is_deceased', '=', FALSE], ['contact_id.is_deleted', '=', FALSE], ['contact_id.do_not_email', '=', FALSE]])->execute()->first()['id']; + if (!$emailID) { + return $email; + } + $emailPopupUrl = CRM_Utils_System::url('civicrm/activity/email/add', [ + 'action' => 'add', + 'reset' => '1', + 'email_id' => $emailID, + ], TRUE); + + return '' . $email . ''; + } + + /** + * Get the email fields from within the fields array. + * + * @param array $fields + */ + protected function getEmailFields(array $fields): array { + $emailFields = []; + foreach (array_keys($fields) as $fieldName) { + if (substr($fieldName, 0, 6) === 'email-' + && (is_numeric(substr($fieldName, 6)) || substr($fieldName, 6) === + 'Primary')) { + $emailFields[] = $fieldName; + } + } + return $emailFields; + } + }