Exemple #1
0
 /**
  * Evaluate the content of a single token.
  *
  * @param \Civi\Token\TokenRow $row
  *   The record for which we want token values.
  * @param string $field
  *   The name of the token field.
  * @param mixed $prefetch
  *   Any data that was returned by the prefetch().
  * @return mixed
  */
 public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefetch = NULL)
 {
     $actionSearchResult = $row->context['actionSearchResult'];
     if ($field == 'location') {
         $loc = array();
         $stateProvince = \CRM_Core_PseudoConstant::stateProvince();
         $loc['street_address'] = $actionSearchResult->street_address;
         $loc['city'] = $actionSearchResult->city;
         $loc['state_province'] = \CRM_Utils_Array::value($actionSearchResult->state_province_id, $stateProvince);
         $loc['postal_code'] = $actionSearchResult->postal_code;
         //$entityTokenParams[$tokenEntity][$field] = \CRM_Utils_Address::format($loc);
         $row->tokens($entity, $field, \CRM_Utils_Address::format($loc));
     } elseif ($field == 'info_url') {
         $row->tokens($entity, $field, \CRM_Utils_System::url('civicrm/event/info', 'reset=1&id=' . $actionSearchResult->event_id, TRUE, NULL, FALSE));
     } elseif ($field == 'registration_url') {
         $row->tokens($entity, $field, \CRM_Utils_System::url('civicrm/event/register', 'reset=1&id=' . $actionSearchResult->event_id, TRUE, NULL, FALSE));
     } elseif (in_array($field, array('start_date', 'end_date'))) {
         $row->tokens($entity, $field, \CRM_Utils_Date::customFormat($actionSearchResult->{$field}));
     } elseif ($field == 'balance') {
         if ($actionSearchResult->entityTable == 'civicrm_contact') {
             $balancePay = 'N/A';
         } elseif (!empty($actionSearchResult->entityID)) {
             $info = \CRM_Contribute_BAO_Contribution::getPaymentInfo($actionSearchResult->entityID, 'event');
             $balancePay = \CRM_Utils_Array::value('balance', $info);
             $balancePay = \CRM_Utils_Money::format($balancePay);
         }
         $row->tokens($entity, $field, $balancePay);
     } elseif ($field == 'fee_amount') {
         $row->tokens($entity, $field, \CRM_Utils_Money::format($actionSearchResult->{$field}));
     } elseif (isset($actionSearchResult->{$field})) {
         $row->tokens($entity, $field, $actionSearchResult->{$field});
     } else {
         $row->tokens($entity, $field, '');
     }
 }
Exemple #2
0
 /**
  * Evaluate the content of a single token.
  *
  * @param \Civi\Token\TokenRow $row
  *   The record for which we want token values.
  * @param string $entity
  * @param string $field
  *   The name of the token field.
  * @param mixed $prefetch
  *   Any data that was returned by the prefetch().
  *
  * @return mixed
  */
 public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefetch = NULL)
 {
     $actionSearchResult = $row->context['actionSearchResult'];
     if (in_array($field, array('start_date', 'end_date', 'join_date'))) {
         $row->tokens($entity, $field, \CRM_Utils_Date::customFormat($actionSearchResult->{$field}));
     } elseif (isset($actionSearchResult->{$field})) {
         $row->tokens($entity, $field, $actionSearchResult->{$field});
     } else {
         $row->tokens($entity, $field, '');
     }
 }
 /**
  * @param \Civi\Token\TokenRow $tokenRow
  * @param CRM_Core_DAO_ActionSchedule $schedule
  * @param int $toContactID
  * @return array
  *   List of error messages.
  */
 protected static function sendReminderEmail($tokenRow, $schedule, $toContactID)
 {
     $toEmail = CRM_Contact_BAO_Contact::getPrimaryEmail($toContactID);
     if (!$toEmail) {
         return array("email_missing" => "Couldn't find recipient's email address.");
     }
     $body_text = $tokenRow->render('body_text');
     $body_html = $tokenRow->render('body_html');
     if (!$schedule->body_text) {
         $body_text = CRM_Utils_String::htmlToText($body_html);
     }
     // set up the parameters for CRM_Utils_Mail::send
     $mailParams = array('groupName' => 'Scheduled Reminder Sender', 'from' => self::pickFromEmail($schedule), 'toName' => $tokenRow->context['contact']['display_name'], 'toEmail' => $toEmail, 'subject' => $tokenRow->render('subject'), 'entity' => 'action_schedule', 'entity_id' => $schedule->id);
     if (!$body_html || $tokenRow->context['contact']['preferred_mail_format'] == 'Text' || $tokenRow->context['contact']['preferred_mail_format'] == 'Both') {
         // render the & entities in text mode, so that the links work
         $mailParams['text'] = str_replace('&', '&', $body_text);
     }
     if ($body_html && ($tokenRow->context['contact']['preferred_mail_format'] == 'HTML' || $tokenRow->context['contact']['preferred_mail_format'] == 'Both')) {
         $mailParams['html'] = $body_html;
     }
     $result = CRM_Utils_Mail::send($mailParams);
     if (!$result || is_a($result, 'PEAR_Error')) {
         return array('email_fail' => 'Failed to send message');
     }
     return array();
 }
Exemple #4
0
 /**
  * Evaluate the content of a single token.
  *
  * @param \Civi\Token\TokenRow $row
  *   The record for which we want token values.
  * @param string $field
  *   The name of the token field.
  * @param mixed $prefetch
  *   Any data that was returned by the prefetch().
  * @return mixed
  */
 public function evaluateToken(\Civi\Token\TokenRow $row, $entity, $field, $prefetch = NULL)
 {
     $actionSearchResult = $row->context['actionSearchResult'];
     $fieldValue = isset($actionSearchResult->{"contrib_{$field}"}) ? $actionSearchResult->{"contrib_{$field}"} : NULL;
     $aliasTokens = $this->getAliasTokens();
     if (in_array($field, array('total_amount', 'fee_amount', 'net_amount'))) {
         return $row->format('text/plain')->tokens($entity, $field, \CRM_Utils_Money::format($fieldValue, $actionSearchResult->contrib_currency));
     } elseif (isset($aliasTokens[$field])) {
         $row->dbToken($entity, $field, 'CRM_Contribute_BAO_Contribution', $aliasTokens[$field], $fieldValue);
     } else {
         $row->dbToken($entity, $field, 'CRM_Contribute_BAO_Contribution', $field, $fieldValue);
     }
 }