private function deleteReports() { // disable logging templates CRM_Core_DAO::executeQuery("\n UPDATE civicrm_option_value\n SET is_active = 0\n WHERE value IN ('" . implode("', '", $this->reports) . "')\n "); // delete report instances $domain_id = CRM_Core_Config::domainID(); foreach ($this->reports as $report) { $dao = new CRM_Report_DAO_ReportInstance(); $dao->domain_id = $domain_id; $dao->report_id = $report; $dao->delete(); } }
/** * Retrieve instance. * * @param array $params * @param array $defaults * * @return CRM_Report_DAO_ReportInstance|null */ public static function retrieve($params, &$defaults) { $instance = new CRM_Report_DAO_ReportInstance(); $instance->copyValues($params); if ($instance->find(TRUE)) { CRM_Core_DAO::storeValues($instance, $defaults); $instance->free(); return $instance; } return NULL; }
/** * @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); }
/** * 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; }
/** * Returns the list of fields that can be exported * * @param bool $prefix * * @return array */ static function &export($prefix = false) { if (!self::$_export) { self::$_export = array(); $fields = self::fields(); foreach ($fields as $name => $field) { if (CRM_Utils_Array::value('export', $field)) { if ($prefix) { self::$_export['report_instance'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }