Пример #1
0
 /**
  * Creates a receipt without receipt-items using the generic tokens
  * @param $tokens             tokens coming from SnapshotReceipt->getAllTokens
  * @return Receipt object if successfull, FALSE otherwise.
  */
 public static function _createReceiptFromTokens($tokens)
 {
     // initialize custom field map
     self::getCustomFields();
     $fields = self::$_custom_fields;
     $custom_group_id = self::$_custom_group_id;
     $table = "civicrm_value_donation_receipt_{$custom_group_id}";
     // build SET-SQL
     $sql_set = "`entity_id`={$tokens['contact_id']}";
     foreach ($fields as $key => $field) {
         $value = null;
         if (0 === strpos($key, 'shipping')) {
             $token_key = substr($key, strlen('shipping_'));
             $value = $tokens['addressee'][$token_key];
         } elseif ($tokens[$key]) {
             $value = $tokens[$key];
         } elseif ($tokens['contributor'][$key]) {
             $value = $tokens['contributor'][$key];
         }
         if (!is_null($value)) {
             $value = CRM_Utils_DonrecHelper::escapeString($value);
             $sql_set .= ", `{$field}`='{$value}'";
         }
     }
     // build query
     $query = "INSERT INTO `{$table}` SET {$sql_set}";
     // run the query
     return CRM_Core_DAO::executeQuery($query);
 }
Пример #2
0
 /**
  * Creates a new receipt item
  * @param array of parameters
  * @return TRUE or FALSE if there was an error //TODO
  */
 public static function create($params)
 {
     self::getCustomFields();
     $fields = self::$_custom_fields;
     $group_id = self::$_custom_group_id;
     $table = "civicrm_value_donation_receipt_item_{$group_id}";
     $params['contribution_hash'] = self::calculateChecksum($params);
     // build set-string
     $set_str = "`entity_id`={$params['contribution_id']}";
     foreach ($fields as $key => $field) {
         if (!is_null($params[$key])) {
             $value = CRM_Utils_DonrecHelper::escapeString($params[$key]);
             $set_str .= ", `{$field}`='{$value}'";
         }
     }
     // build query
     $query = "INSERT INTO `{$table}` SET {$set_str}";
     // run query
     $result = CRM_Core_DAO::executeQuery($query);
     return $result;
 }
Пример #3
0
 /**
  * This is a workaround for the problem that using the translated title right away makes the
  * table names change.
  *
  * FIXME: we should not be working with static table names
  */
 public static function translateCustomGroups()
 {
     try {
         // TRANSLATE zwb_donation_receipt title
         $custom_group_receipt = civicrm_api3('CustomGroup', 'getsingle', array('name' => 'zwb_donation_receipt'));
         // since the API is not reliable here, we do this via SQL
         $new_title = CRM_Utils_DonrecHelper::escapeString(ts('Donation Receipt', array('domain' => 'de.systopia.donrec')));
         $custom_group_receipt_id = (int) $custom_group_receipt['id'];
         CRM_Core_DAO::executeQuery("UPDATE `civicrm_custom_group` SET title='{$new_title}' WHERE id={$custom_group_receipt_id};");
         // TRANSLATE zwb_donation_receipt_item title
         $custom_group_receipt_item = civicrm_api3('CustomGroup', 'getsingle', array('name' => 'zwb_donation_receipt_item'));
         // since the API is not reliable here, we do this via SQL
         $new_title = CRM_Utils_DonrecHelper::escapeString(ts('Donation Receipt Item', array('domain' => 'de.systopia.donrec')));
         $custom_group_receipt_item_id = (int) $custom_group_receipt_item['id'];
         CRM_Core_DAO::executeQuery("UPDATE `civicrm_custom_group` SET title='{$new_title}' WHERE id={$custom_group_receipt_item_id};");
     } catch (Exception $e) {
         CRM_Core_Error::debug_log_message('de.systopia.donrec - Error translating custom groups: ' . $e->getMessage());
     }
 }