コード例 #1
0
 /**
  * Replace contribution_type to financial_type in table.
  * civicrm_saved_search and Structure civicrm_report_instance
  */
 public function replaceContributionTypeId(CRM_Queue_TaskContext $ctx, $query, $table)
 {
     $dao = CRM_Core_DAO::executeQuery($query);
     while ($dao->fetch()) {
         $formValues = unserialize($dao->form_values);
         foreach (array('contribution_type_id_op', 'contribution_type_id_value', 'contribution_type_id') as $value) {
             if (array_key_exists($value, $formValues)) {
                 $key = preg_replace('/contribution/', 'financial', $value);
                 $formValues[$key] = $formValues[$value];
                 unset($formValues[$value]);
             }
         }
         if ($table != 'savedSearch') {
             foreach (array('fields', 'group_bys') as $value) {
                 if (array_key_exists($value, $formValues)) {
                     if (array_key_exists('contribution_type_id', $formValues[$value])) {
                         $formValues[$value]['financial_type_id'] = $formValues[$value]['contribution_type_id'];
                         unset($formValues[$value]['contribution_type_id']);
                     } elseif (array_key_exists('contribution_type', $formValues[$value])) {
                         $formValues[$value]['financial_type'] = $formValues[$value]['contribution_type'];
                         unset($formValues[$value]['contribution_type']);
                     }
                 }
             }
             if (array_key_exists('order_bys', $formValues)) {
                 foreach ($formValues['order_bys'] as $key => $values) {
                     if (preg_grep('/contribution_type/', $values)) {
                         $formValues['order_bys'][$key]['column'] = preg_replace('/contribution_type/', 'financial_type', $values['column']);
                     }
                 }
             }
         }
         if ($table == 'savedSearch') {
             $saveDao = new CRM_Contact_DAO_SavedSearch();
         } else {
             $saveDao = new CRM_Report_DAO_ReportInstance();
         }
         $saveDao->id = $dao->id;
         if ($table == 'savedSearch') {
             if (array_key_exists('mapper', $formValues)) {
                 foreach ($formValues['mapper'] as $key => $values) {
                     foreach ($values as $k => $v) {
                         if (preg_grep('/contribution_/', $v)) {
                             $formValues['mapper'][$key][$k] = preg_replace('/contribution_type/', 'financial_type', $v);
                         }
                     }
                 }
             }
             foreach (array('select_tables', 'where_tables') as $value) {
                 if (preg_match('/contribution_type/', $dao->{$value})) {
                     $tempValue = unserialize($dao->{$value});
                     if (array_key_exists('civicrm_contribution_type', $tempValue)) {
                         $tempValue['civicrm_financial_type'] = $tempValue['civicrm_contribution_type'];
                         unset($tempValue['civicrm_contribution_type']);
                     }
                     $saveDao->{$value} = serialize($tempValue);
                 }
             }
             if (preg_match('/contribution_type/', $dao->where_clause)) {
                 $saveDao->where_clause = preg_replace('/contribution_type/', 'financial_type', $dao->where_clause);
             }
         }
         $saveDao->form_values = serialize($formValues);
         $saveDao->save();
     }
     return TRUE;
 }
コード例 #2
0
 /**
  * Takes an associative array and creates an instance object.
  *
  * the function extract all the params it needs to initialize the create a
  * instance object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array $params
  *   (reference ) an assoc array of name/value pairs.
  *
  * @return CRM_Report_DAO_ReportInstance
  */
 public static function add(&$params)
 {
     $instance = new CRM_Report_DAO_ReportInstance();
     if (empty($params)) {
         return NULL;
     }
     $instanceID = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('instance_id', $params));
     // convert roles array to string
     if (isset($params['grouprole']) && is_array($params['grouprole'])) {
         $grouprole_array = array();
         foreach ($params['grouprole'] as $key => $value) {
             $grouprole_array[$value] = $value;
         }
         $params['grouprole'] = implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($grouprole_array));
     }
     if (!$instanceID || !isset($params['id'])) {
         $params['is_reserved'] = CRM_Utils_Array::value('is_reserved', $params, FALSE);
         $params['domain_id'] = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID());
         // CRM-17256 set created_id on report creation.
         $params['created_id'] = isset($params['created_id']) ? $params['created_id'] : CRM_Core_Session::getLoggedInContactID();
     }
     if ($instanceID) {
         CRM_Utils_Hook::pre('edit', 'ReportInstance', $instanceID, $params);
     } else {
         CRM_Utils_Hook::pre('create', 'ReportInstance', NULL, $params);
     }
     $instance = new CRM_Report_DAO_ReportInstance();
     $instance->copyValues($params);
     if (CRM_Core_Config::singleton()->userFramework == 'Joomla') {
         $instance->permission = 'null';
     }
     // explicitly set to null if params value is empty
     if (!$instanceID && empty($params['grouprole'])) {
         $instance->grouprole = 'null';
     }
     if ($instanceID) {
         $instance->id = $instanceID;
     }
     if (!$instanceID) {
         if ($reportID = CRM_Utils_Array::value('report_id', $params)) {
             $instance->report_id = $reportID;
         } elseif ($instanceID) {
             $instance->report_id = CRM_Report_Utils_Report::getValueFromUrl($instanceID);
         } else {
             // just take it from current url
             $instance->report_id = CRM_Report_Utils_Report::getValueFromUrl();
         }
     }
     $instance->save();
     if ($instanceID) {
         CRM_Utils_Hook::pre('edit', 'ReportInstance', $instance->id, $instance);
     } else {
         CRM_Utils_Hook::pre('create', 'ReportInstance', $instance->id, $instance);
     }
     return $instance;
 }
コード例 #3
0
ファイル: ThreeFour.php プロジェクト: kidaa30/yes
 /**
  * @param $rev
  */
 public function upgrade_3_4_6($rev)
 {
     $modifiedReportIds = array('event/summary', 'activity', 'Mailing/bounce', 'Mailing/clicks', 'Mailing/opened');
     $instances = CRM_Core_DAO::executeQuery("SELECT id, form_values, report_id FROM civicrm_report_instance WHERE report_id IN ('" . implode("','", $modifiedReportIds) . "')");
     while ($instances->fetch()) {
         $formValues = unserialize($instances->form_values);
         switch ($instances->report_id) {
             case 'event/summary':
                 $eventDates = array('event_start_date_from', 'event_start_date_to', 'event_end_date_from', 'event_end_date_to');
                 foreach ($eventDates as $date) {
                     if (isset($formValues[$date]) && $formValues[$date] == ' ') {
                         $formValues[$date] = '';
                     }
                 }
                 break;
             case 'activity':
                 if (isset($formValues['group_bys'])) {
                     if (is_array($formValues['group_bys'])) {
                         $orderBy = array();
                         $count = 0;
                         foreach ($formValues['group_bys'] as $col => $isSet) {
                             if (!$isSet) {
                                 continue;
                             }
                             $orderBy[++$count] = array('column' => $col, 'order' => 'ASC');
                         }
                         if (!empty($orderBy)) {
                             $formValues['order_bys'] = $orderBy;
                         }
                     }
                     unset($formValues['group_bys']);
                 }
                 break;
             case 'Mailing/bounce':
             case 'Mailing/clicks':
             case 'Mailing/opened':
                 $formValues['fields']['mailing_name'] = 1;
                 break;
         }
         // save updated instance criteria
         $dao = new CRM_Report_DAO_ReportInstance();
         $dao->id = $instances->id;
         $dao->form_values = serialize($formValues);
         $dao->save();
         $dao->free();
     }
     $bulkEmailActivityType = CRM_Core_DAO::singleValueQuery("\nSELECT v.id\nFROM   civicrm_option_value v,\n       civicrm_option_group g\nWHERE  v.option_group_id = g.id\n  AND  g.name      = %1\n  AND  g.is_active = 1\n  AND  v.name      = %2", array(1 => array('activity_type', 'String'), 2 => array('Bulk Email', 'String')));
     // CRM-8852, reset contact field cache
     CRM_Core_BAO_Cache::deleteGroup('contact fields');
     $upgrade = new CRM_Upgrade_Form();
     $upgrade->assign('bulkEmailActivityType', $bulkEmailActivityType);
     $upgrade->processSQL($rev);
 }