Exemplo n.º 1
0
 public static function addDynamicTokens(&$values)
 {
     if (!empty($values['issued_by'])) {
         // add created_by_display_name
         try {
             $creator = civicrm_api3('Contact', 'getsingle', array('id' => $values['issued_by']));
             $values['issued_by_display_name'] = $creator['display_name'];
         } catch (Exception $e) {
             CRM_Core_Error::debug_log_message('de.systopia.donrec - ' . print_r($e, 1));
         }
     }
     // add the legacy 'today' token
     if (!empty($values['issued_on'])) {
         $values['today'] = $values['issued_on'];
     }
     // add the monetary tokens: 'total', 'totaltext', 'totalmoney'
     if (isset($values['total_amount'])) {
         // format total_amount
         $values['total_amount'] = number_format((double) $values['total_amount'], 2, '.', '');
         $values['total'] = $values['total_amount'];
         $values['totaltext'] = CRM_Utils_DonrecHelper::convert_number_to_words($values['total_amount']);
         $values['totalmoney'] = CRM_Utils_Money::format($values['total_amount'], '');
     }
     // add financial type name
     $financialTypes = CRM_Contribute_PseudoConstant::financialType();
     if (is_array($values['lines'])) {
         foreach ($values['lines'] as $key => $line) {
             if (!empty($line['financial_type_id'])) {
                 $values['lines'][$key]['financial_type'] = $financialTypes[$line['financial_type_id']];
             }
         }
     }
     // sort contribution lines by receive date (#1497)
     $receive_dates = array();
     $sorted_lines = $values['lines'];
     foreach ($sorted_lines as $key => $line) {
         $sorted_lines[$key]['id'] = $key;
         $receive_dates[$key] = $line['receive_date'];
     }
     array_multisort($receive_dates, SORT_ASC, $sorted_lines);
     $values['lines'] = array();
     foreach ($sorted_lines as $key => $line) {
         $values['lines'][$line['id']] = $line;
     }
     // add legacy 'items'
     if (count($values['lines']) > 1) {
         $values['items'] = $values['lines'];
     }
     // add organisation address
     if (empty($values['organisation'])) {
         $domain = CRM_Core_BAO_Domain::getDomain();
         $values['organisation'] = self::lookupAddressTokens($domain->contact_id, 0, 0);
     }
     // ADD watermarks
     $profile = CRM_Donrec_Logic_Profile::getProfile($values['profile']);
     if ($values['status'] == 'ORIGINAL') {
         // nothing to to in this case..
     } elseif ($values['status'] == 'COPY') {
         $values['watermark'] = $profile->get('copy_text');
     } else {
         // in all other cases, it's INVALID/DRAFT:
         $values['watermark'] = $profile->get('draft_text');
     }
     // copy contributor values to addressee, if not set separately
     if (!isset($values['addressee']['display_name'])) {
         $values['addressee']['display_name'] = $values['contributor']['display_name'];
     }
     if (!isset($values['addressee']['addressee_display'])) {
         $values['addressee']['addressee_display'] = $values['contributor']['addressee_display'];
     }
     // add URL to view original file, if it exists
     if (!empty($values['original_file'])) {
         $values['view_url'] = CRM_Donrec_Logic_File::getPermanentURL($values['original_file'], $values['contributor']['id']);
     }
     // TODO: call Token hooks? Currently done by PDF generator
 }