/**
  * PostProcess function.
  *
  * @param array $groupTree
  * @param array $params
  * @param bool $skipFile
  */
 public static function postProcess(&$groupTree, &$params, $skipFile = FALSE)
 {
     // Get the Custom form values and groupTree
     // first reset all checkbox and radio data
     foreach ($groupTree as $groupID => $group) {
         if ($groupID === 'info') {
             continue;
         }
         foreach ($group['fields'] as $field) {
             $fieldId = $field['id'];
             //added Multi-Select option in the below if-statement
             if ($field['html_type'] == 'CheckBox' || $field['html_type'] == 'Radio' || $field['html_type'] == 'AdvMulti-Select' || $field['html_type'] == 'Multi-Select') {
                 $groupTree[$groupID]['fields'][$fieldId]['customValue']['data'] = 'NULL';
             }
             $v = NULL;
             foreach ($params as $key => $val) {
                 if (preg_match('/^custom_(\\d+)_?(-?\\d+)?$/', $key, $match) && $match[1] == $field['id']) {
                     $v = $val;
                 }
             }
             if (!isset($groupTree[$groupID]['fields'][$fieldId]['customValue'])) {
                 // field exists in db so populate value from "form".
                 $groupTree[$groupID]['fields'][$fieldId]['customValue'] = array();
             }
             switch ($groupTree[$groupID]['fields'][$fieldId]['html_type']) {
                 //added for CheckBox
                 case 'CheckBox':
                     if (!empty($v)) {
                         $customValue = array_keys($v);
                         $groupTree[$groupID]['fields'][$fieldId]['customValue']['data'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $customValue) . CRM_Core_DAO::VALUE_SEPARATOR;
                     } else {
                         $groupTree[$groupID]['fields'][$fieldId]['customValue']['data'] = NULL;
                     }
                     break;
                     //added for Advanced Multi-Select
                 //added for Advanced Multi-Select
                 case 'AdvMulti-Select':
                     //added for Multi-Select
                 //added for Multi-Select
                 case 'Multi-Select':
                     if (!empty($v)) {
                         $groupTree[$groupID]['fields'][$fieldId]['customValue']['data'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $v) . CRM_Core_DAO::VALUE_SEPARATOR;
                     } else {
                         $groupTree[$groupID]['fields'][$fieldId]['customValue']['data'] = NULL;
                     }
                     break;
                 case 'Select Date':
                     $date = CRM_Utils_Date::processDate($v);
                     $groupTree[$groupID]['fields'][$fieldId]['customValue']['data'] = $date;
                     break;
                 case 'File':
                     if ($skipFile) {
                         continue;
                     }
                     //store the file in d/b
                     $entityId = explode('=', $groupTree['info']['where'][0]);
                     $fileParams = array('upload_date' => date('Ymdhis'));
                     if ($groupTree[$groupID]['fields'][$fieldId]['customValue']['fid']) {
                         $fileParams['id'] = $groupTree[$groupID]['fields'][$fieldId]['customValue']['fid'];
                     }
                     if (!empty($v)) {
                         $fileParams['uri'] = $v['name'];
                         $fileParams['mime_type'] = $v['type'];
                         CRM_Core_BAO_File::filePostProcess($v['name'], $groupTree[$groupID]['fields'][$fieldId]['customValue']['fid'], $groupTree[$groupID]['table_name'], trim($entityId[1]), FALSE, TRUE, $fileParams, 'custom_' . $fieldId, $v['type']);
                     }
                     $defaults = array();
                     $paramsFile = array('entity_table' => $groupTree[$groupID]['table_name'], 'entity_id' => $entityId[1]);
                     CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_EntityFile', $paramsFile, $defaults);
                     $groupTree[$groupID]['fields'][$fieldId]['customValue']['data'] = $defaults['file_id'];
                     break;
                 default:
                     $groupTree[$groupID]['fields'][$fieldId]['customValue']['data'] = $v;
                     break;
             }
         }
     }
 }
Exemple #2
0
/**
 * Attach a file to a given entity
 *
 * @param string   $name          filename
 * @param object   $entityID      id of the supported entity.
 * @param string   $entity_table   
 *
 * @access public
 */
function crm_add_file_by_entity($name, $entityID, $entityTable = 'civicrm_contact', $params)
{
    require_once 'CRM/Core/BAO/File.php';
    CRM_Core_BAO_File::filePostProcess($name, null, $entityTable, $entityID, null, false, $params);
}
 /**
  * Add the Message Templates.
  *
  * @param array $params
  *   Reference array contains the values submitted by the form.
  *
  *
  * @return object
  */
 public static function add(&$params)
 {
     $hook = empty($params['id']) ? 'create' : 'edit';
     CRM_Utils_Hook::pre($hook, 'MessageTemplate', CRM_Utils_Array::value('id', $params), $params);
     if (!empty($params['file_id']) && is_array($params['file_id']) && count($params['file_id'])) {
         $fileParams = $params['file_id'];
         unset($params['file_id']);
     }
     $messageTemplates = new CRM_Core_DAO_MessageTemplate();
     $messageTemplates->copyValues($params);
     $messageTemplates->save();
     if (!empty($fileParams)) {
         $params['file_id'] = $fileParams;
         CRM_Core_BAO_File::filePostProcess($params['file_id']['location'], NULL, 'civicrm_msg_template', $messageTemplates->id, NULL, TRUE, $params['file_id'], 'file_id', $params['file_id']['type']);
     }
     CRM_Utils_Hook::post($hook, 'MessageTemplate', $messageTemplates->id, $messageTemplates);
     return $messageTemplates;
 }
/**
 * Attach a file to a given entity
 *
 * @param string   $name          filename
 * @param object   $entityID      id of the supported entity.
 * @param string   $entity_table
 *
 * @access public
 */
function civicrm_file_by_entity_add($name, $entityID, $entityTable = 'civicrm_contact', $params)
{
    require_once 'CRM/Core/BAO/File.php';
    CRM_Core_BAO_File::filePostProcess($name, NULL, $entityTable, $entityID, NULL, FALSE, $params);
}