Exemplo n.º 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, '');
     }
 }
Exemplo n.º 2
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 (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, '');
     }
 }