/** * Creates a new option group with the passed in values. * @TODO: Should update the group if it already exists intelligently, so multi-lingual is * not messed up. Currently deletes the old group * * @param string $groupName * The name of the option group - make sure there is no conflict. * @param array $values * The associative array that has information on the option values. * the keys of this array are: * string 'title' (required) * string 'value' (required) * string 'name' (optional) * string 'description' (optional) * int 'weight' (optional) - the order in which the value are displayed * bool 'is_default' (optional) - is this the default one to display when rendered in form * bool 'is_active' (optional) - should this element be rendered * @param int $defaultID * (reference) - the option value ID of the default element (if set) is returned else 'null'. * @param null $groupTitle * The optional label of the option group else set to group name. * * * @return int * the option group ID */ public static function createAssoc($groupName, &$values, &$defaultID, $groupTitle = NULL) { self::deleteAssoc($groupName); if (!empty($values)) { $group = new CRM_Core_DAO_OptionGroup(); $group->name = $groupName; $group->title = empty($groupTitle) ? $groupName : $groupTitle; $group->is_reserved = 1; $group->is_active = 1; $group->save(); foreach ($values as $v) { $value = new CRM_Core_DAO_OptionValue(); $value->option_group_id = $group->id; $value->label = $v['label']; $value->value = $v['value']; $value->name = CRM_Utils_Array::value('name', $v); $value->description = CRM_Utils_Array::value('description', $v); $value->weight = CRM_Utils_Array::value('weight', $v); $value->is_default = CRM_Utils_Array::value('is_default', $v); $value->is_active = CRM_Utils_Array::value('is_active', $v); $value->save(); if ($value->is_default) { $defaultID = $value->id; } } } else { return $defaultID = 'null'; } return $group->id; }
/** * function to get the complete information for one or more events * * @param date $start get events with start date >= this date * @param integer $type get events on the a specific event type (by event_type_id) * @param integer $eventId return a single event - by event id * @param date $end also get events with end date >= this date * * @return array $all array of all the events that are searched * @static * @access public */ static function &getCompleteInfo($start = null, $type = null, $eventId = null, $end = null) { // if start and end date are NOT passed, return all events with start_date OR end_date >= today CRM-5133 if ($start) { // get events with start_date >= requested start $startDate = CRM_Utils_Type::escape($start, 'Date'); } else { // get events with start date >= today $startDate = date("Ymd"); } if ($end) { // also get events with end_date >= requested end $endDate = CRM_Utils_Type::escape($end, 'Date'); } else { // OR also get events with end date >= today $endDate = date("Ymd"); } $dateCondition = "AND (civicrm_event.start_date >= {$startDate} OR civicrm_event.end_date >= {$endDate})"; if ($type) { $typeCondition = " AND civicrm_event.event_type_id = " . CRM_Utils_Type::escape($type, 'Integer'); } // Get the Id of Option Group for Event Types require_once 'CRM/Core/DAO/OptionGroup.php'; $optionGroupDAO = new CRM_Core_DAO_OptionGroup(); $optionGroupDAO->name = 'event_type'; $optionGroupId = null; if ($optionGroupDAO->find(true)) { $optionGroupId = $optionGroupDAO->id; } $query = "\nSELECT\n civicrm_event.id as event_id, \n civicrm_email.email as email, \n civicrm_event.title as title, \n civicrm_event.summary as summary, \n civicrm_event.start_date as start, \n civicrm_event.end_date as end, \n civicrm_event.description as description, \n civicrm_event.is_show_location as is_show_location, \n civicrm_event.is_online_registration as is_online_registration,\n civicrm_event.registration_link_text as registration_link_text,\n civicrm_event.registration_start_date as registration_start_date,\n civicrm_event.registration_end_date as registration_end_date,\n civicrm_option_value.label as event_type, \n civicrm_address.name as address_name, \n civicrm_address.street_address as street_address, \n civicrm_address.supplemental_address_1 as supplemental_address_1, \n civicrm_address.supplemental_address_2 as supplemental_address_2, \n civicrm_address.city as city, \n civicrm_address.postal_code as postal_code, \n civicrm_address.postal_code_suffix as postal_code_suffix, \n civicrm_state_province.abbreviation as state, \n civicrm_country.name AS country\nFROM civicrm_event\nLEFT JOIN civicrm_loc_block ON civicrm_event.loc_block_id = civicrm_loc_block.id\nLEFT JOIN civicrm_address ON civicrm_loc_block.address_id = civicrm_address.id\nLEFT JOIN civicrm_state_province ON civicrm_address.state_province_id = civicrm_state_province.id\nLEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id\nLEFT JOIN civicrm_email ON civicrm_loc_block.email_id = civicrm_email.id\nLEFT JOIN civicrm_option_value ON (\n civicrm_event.event_type_id = civicrm_option_value.value AND\n civicrm_option_value.option_group_id = %1 )\nWHERE civicrm_event.is_active = 1 \n AND civicrm_event.is_public = 1\n AND (is_template = 0 OR is_template IS NULL)\n {$dateCondition}"; if (isset($typeCondition)) { $query .= $typeCondition; } if (isset($eventId)) { $query .= " AND civicrm_event.id ={$eventId} "; } $query .= " ORDER BY civicrm_event.start_date ASC"; $params = array(1 => array($optionGroupId, 'Integer')); $dao =& CRM_Core_DAO::executeQuery($query, $params); $all = array(); $config = CRM_Core_Config::singleton(); $baseURL = parse_url($config->userFrameworkBaseURL); $url = "@" . $baseURL['host']; if (CRM_Utils_Array::value('path', $baseURL)) { $url .= substr($baseURL['path'], 0, -1); } // check 'view event info' permission $permissions = CRM_Core_Permission::event(CRM_Core_Permission::VIEW); require_once 'CRM/Utils/String.php'; while ($dao->fetch()) { if (in_array($dao->event_id, $permissions)) { $info = array(); $info['uid'] = "CiviCRM_EventID_{$dao->event_id}_" . md5($config->userFrameworkBaseURL) . $url; $info['title'] = $dao->title; $info['event_id'] = $dao->event_id; $info['summary'] = $dao->summary; $info['description'] = $dao->description; $info['start_date'] = $dao->start; $info['end_date'] = $dao->end; $info['contact_email'] = $dao->email; $info['event_type'] = $dao->event_type; $info['is_show_location'] = $dao->is_show_location; $info['is_online_registration'] = $dao->is_online_registration; $info['registration_link_text'] = $dao->registration_link_text; $info['registration_start_date'] = $dao->registration_start_date; $info['registration_end_date'] = $dao->registration_end_date; $address = ''; $addrFields = array('address_name' => $dao->address_name, 'street_address' => $dao->street_address, 'supplemental_address_1' => $dao->supplemental_address_1, 'supplemental_address_2' => $dao->supplemental_address_2, 'city' => $dao->city, 'state_province' => $dao->state, 'postal_code' => $dao->postal_code, 'postal_code_suffix' => $dao->postal_code_suffix, 'country' => $dao->country, 'county' => null); require_once 'CRM/Utils/Address.php'; CRM_Utils_String::append($address, ', ', CRM_Utils_Address::format($addrFields)); $info['location'] = $address; $info['url'] = CRM_Utils_System::url('civicrm/event/info', 'reset=1&id=' . $dao->event_id, true, null, false); $all[] = $info; } } return $all; }
/** * Get the values of all option values given an option group Name as a key => value pair * Use above cached function to make it super efficient * * @param string $optionGroupName * The option group name for which we want the values from. * * @return array * an associative array of label, value pairs */ public static function getOptionValuesAssocArrayFromName($optionGroupName) { $dao = new CRM_Core_DAO_OptionGroup(); $dao->name = $optionGroupName; $dao->selectAdd(); $dao->selectAdd('id'); $dao->find(TRUE); $optionValues = self::getOptionValuesArray($dao->id); $options = array(); foreach ($optionValues as $id => $value) { $options[$value['value']] = $value['label']; } return $options; }
/** * returns the list of fields that can be exported * * @access public * return array */ 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['option_group'] =& $fields[$name]; } else { self::$_export[$name] =& $fields[$name]; } } } } return self::$_export; }
/** * function to get the complete information for one or more events * * @param date $start get events with start date >= this date * @param integer $type get events on the a specific event type (by event_type_id) * @param integer $eventId return a single event - by event id * @param date $end also get events with end date >= this date * @param boolean $onlyPublic include public events only, default TRUE * * @return array $all array of all the events that are searched * @static * @access public */ static function &getCompleteInfo($start = NULL, $type = NULL, $eventId = NULL, $end = NULL, $onlyPublic = TRUE) { $publicCondition = NULL; if ($onlyPublic) { $publicCondition = " AND civicrm_event.is_public = 1"; } $dateCondition = ''; // if start and end date are NOT passed, return all events with start_date OR end_date >= today CRM-5133 if ($start) { // get events with start_date >= requested start $startDate = CRM_Utils_Type::escape($start, 'Date'); $dateCondition .= " AND ( civicrm_event.start_date >= {$startDate} )"; } if ($end) { // also get events with end_date <= requested end $endDate = CRM_Utils_Type::escape($end, 'Date'); $dateCondition .= " AND ( civicrm_event.end_date <= '{$endDate}' ) "; } // CRM-9421 and CRM-8620 Default mode for ical/rss feeds. No start or end filter passed. // Need to exclude old events with only start date // and not exclude events in progress (start <= today and end >= today). DGG if (empty($start) && empty($end)) { // get events with end date >= today, not sure of this logic // but keeping this for backward compatibility as per issue CRM-5133 $today = date("Y-m-d G:i:s"); $dateCondition .= " AND ( civicrm_event.end_date >= '{$today}' OR civicrm_event.start_date >= '{$today}' ) "; } if ($type) { $typeCondition = " AND civicrm_event.event_type_id = " . CRM_Utils_Type::escape($type, 'Integer'); } // Get the Id of Option Group for Event Types $optionGroupDAO = new CRM_Core_DAO_OptionGroup(); $optionGroupDAO->name = 'event_type'; $optionGroupId = NULL; if ($optionGroupDAO->find(TRUE)) { $optionGroupId = $optionGroupDAO->id; } $query = "\nSELECT\n civicrm_event.id as event_id,\n civicrm_email.email as email,\n civicrm_event.title as title,\n civicrm_event.summary as summary,\n civicrm_event.start_date as start,\n civicrm_event.end_date as end,\n civicrm_event.description as description,\n civicrm_event.is_show_location as is_show_location,\n civicrm_event.is_online_registration as is_online_registration,\n civicrm_event.registration_link_text as registration_link_text,\n civicrm_event.registration_start_date as registration_start_date,\n civicrm_event.registration_end_date as registration_end_date,\n civicrm_option_value.label as event_type,\n civicrm_address.name as address_name,\n civicrm_address.street_address as street_address,\n civicrm_address.supplemental_address_1 as supplemental_address_1,\n civicrm_address.supplemental_address_2 as supplemental_address_2,\n civicrm_address.city as city,\n civicrm_address.postal_code as postal_code,\n civicrm_address.postal_code_suffix as postal_code_suffix,\n civicrm_state_province.abbreviation as state,\n civicrm_country.name AS country\nFROM civicrm_event\nLEFT JOIN civicrm_loc_block ON civicrm_event.loc_block_id = civicrm_loc_block.id\nLEFT JOIN civicrm_address ON civicrm_loc_block.address_id = civicrm_address.id\nLEFT JOIN civicrm_state_province ON civicrm_address.state_province_id = civicrm_state_province.id\nLEFT JOIN civicrm_country ON civicrm_address.country_id = civicrm_country.id\nLEFT JOIN civicrm_email ON civicrm_loc_block.email_id = civicrm_email.id\nLEFT JOIN civicrm_option_value ON (\n civicrm_event.event_type_id = civicrm_option_value.value AND\n civicrm_option_value.option_group_id = %1 )\nWHERE civicrm_event.is_active = 1\n AND (is_template = 0 OR is_template IS NULL)\n {$publicCondition}\n {$dateCondition}"; if (isset($typeCondition)) { $query .= $typeCondition; } if (isset($eventId)) { $query .= " AND civicrm_event.id ={$eventId} "; } $query .= " ORDER BY civicrm_event.start_date ASC"; $params = array(1 => array($optionGroupId, 'Integer')); $dao = CRM_Core_DAO::executeQuery($query, $params); $all = array(); $config = CRM_Core_Config::singleton(); $baseURL = parse_url($config->userFrameworkBaseURL); $url = "@" . $baseURL['host']; if (!empty($baseURL['path'])) { $url .= substr($baseURL['path'], 0, -1); } // check 'view event info' permission //@todo - per CRM-14626 we have resolved that 'view event info' means 'view ALL event info' // and passing in the specific permission here will short-circuit the evaluation of permission to // see specific events (doesn't seem relevant to this call // however, since this function is accessed only by a convoluted call from a joomla block function // it seems safer not to touch here. Suggestion is that CRM_Core_Permission::check(array or relevant permissions) would // be clearer & safer here $permissions = CRM_Core_Permission::event(CRM_Core_Permission::VIEW); // check if we're in shopping cart mode for events $enable_cart = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::EVENT_PREFERENCES_NAME, 'enable_cart'); if ($enable_cart) { } while ($dao->fetch()) { if (!empty($permissions) && in_array($dao->event_id, $permissions)) { $info = array(); $info['uid'] = "CiviCRM_EventID_{$dao->event_id}_" . md5($config->userFrameworkBaseURL) . $url; $info['title'] = $dao->title; $info['event_id'] = $dao->event_id; $info['summary'] = $dao->summary; $info['description'] = $dao->description; $info['start_date'] = $dao->start; $info['end_date'] = $dao->end; $info['contact_email'] = $dao->email; $info['event_type'] = $dao->event_type; $info['is_show_location'] = $dao->is_show_location; $info['is_online_registration'] = $dao->is_online_registration; $info['registration_link_text'] = $dao->registration_link_text; $info['registration_start_date'] = $dao->registration_start_date; $info['registration_end_date'] = $dao->registration_end_date; $address = ''; $addrFields = array('address_name' => $dao->address_name, 'street_address' => $dao->street_address, 'supplemental_address_1' => $dao->supplemental_address_1, 'supplemental_address_2' => $dao->supplemental_address_2, 'city' => $dao->city, 'state_province' => $dao->state, 'postal_code' => $dao->postal_code, 'postal_code_suffix' => $dao->postal_code_suffix, 'country' => $dao->country, 'county' => NULL); CRM_Utils_String::append($address, ', ', CRM_Utils_Address::format($addrFields)); $info['location'] = $address; $info['url'] = CRM_Utils_System::url('civicrm/event/info', 'reset=1&id=' . $dao->event_id, TRUE, NULL, FALSE); if ($enable_cart) { $reg = CRM_Event_Cart_BAO_EventInCart::get_registration_link($dao->event_id); $info['registration_link'] = CRM_Utils_System::url($reg['path'], $reg['query'], TRUE); $info['registration_link_text'] = $reg['label']; } $all[] = $info; } } return $all; }
function upgrade_3_3_beta1($rev) { $upgrade = new CRM_Upgrade_Form(); $upgrade->processSQL($rev); // CRM-6902 // Add column price_field_value_id in civicrm_line_item. // Do not drop option_group_id column now since we need it to // update line items. $updateLineItem1 = "ALTER TABLE civicrm_line_item ADD COLUMN price_field_value_id int(10) unsigned default NULL;"; CRM_Core_DAO::executeQuery($updateLineItem1); $priceFieldDAO = new CRM_Price_DAO_Field(); $priceFieldDAO->find(); $ids = array(); while ($priceFieldDAO->fetch()) { $opGroupDAO = new CRM_Core_DAO_OptionGroup(); $opGroupDAO->name = 'civicrm_price_field.amount.' . $priceFieldDAO->id; if (!$opGroupDAO->find(TRUE)) { $opGroupDAO->free(); continue; } $opValueDAO = new CRM_Core_DAO_OptionValue(); $opValueDAO->option_group_id = $opGroupDAO->id; $opValueDAO->find(); while ($opValueDAO->fetch()) { // FIX ME: not migrating description(?), there will // be a field description for each option. $fieldValue = array('price_field_id' => $priceFieldDAO->id, 'label' => $opValueDAO->label, 'name' => CRM_Utils_String::munge($opValueDAO->label, '_', 64), 'amount' => $opValueDAO->name, 'weight' => $opValueDAO->weight, 'is_default' => $opValueDAO->is_default, 'is_active' => $opValueDAO->is_active); if ($priceFieldDAO->count) { // Migrate Participant Counts on option level. // count of each option will be the same // as earlier field count. $fieldValue['count'] = $priceFieldDAO->count; } $fieldValueDAO = CRM_Price_BAO_FieldValue::add($fieldValue, $ids); $lineItemDAO = new CRM_Price_DAO_LineItem(); $lineItemDAO->option_group_id = $opGroupDAO->id; $lineItemDAO->label = $opValueDAO->label; $lineItemDAO->unit_price = $opValueDAO->name; $labelFound = $priceFound = FALSE; // check with label and amount if (!$lineItemDAO->find(TRUE)) { $lineItemDAO->free(); $lineItemDAO = new CRM_Price_DAO_LineItem(); $lineItemDAO->option_group_id = $opGroupDAO->id; $lineItemDAO->label = $opValueDAO->label; // check with label only if ($lineItemDAO->find(TRUE)) { $labelFound = TRUE; } } else { $labelFound = TRUE; $priceFound = TRUE; } $lineItemDAO->free(); // update civicrm_line_item for price_field_value_id. // Used query to avoid line by line update. if ($labelFound || $priceFound) { $lineItemParams = array(1 => array($fieldValueDAO->id, 'Integer'), 2 => array($opValueDAO->label, 'String')); $updateLineItems = "UPDATE civicrm_line_item SET price_field_value_id = %1 WHERE label = %2"; if ($priceFound) { $lineItemParams[3] = array($opValueDAO->name, 'Float'); $updateLineItems .= " AND unit_price = %3"; } CRM_Core_DAO::executeQuery($updateLineItems, $lineItemParams); } } $opGroupDAO->delete(); $opValueDAO->free(); $opGroupDAO->free(); } $priceFieldDAO->free(); // Now drop option_group_id column from civicrm_line_item $updateLineItem2 = "ALTER TABLE civicrm_line_item DROP option_group_id,\n ADD CONSTRAINT `FK_civicrm_price_field_value_id` FOREIGN KEY (price_field_value_id) REFERENCES civicrm_price_field_value(id) ON DELETE SET NULL;"; CRM_Core_DAO::executeQuery($updateLineItem2, array(), TRUE, NULL, FALSE, FALSE); $updatePriceField = "ALTER TABLE civicrm_price_field DROP count"; CRM_Core_DAO::executeQuery($updatePriceField, array(), TRUE, NULL, FALSE, FALSE); // as the table 'civicrm_price_field' is localised and column 'count' is dropped // after the views are rebuild, we need to rebuild views to avoid invalid refrence of table. if ($upgrade->multilingual) { CRM_Core_I18n_Schema::rebuildMultilingualSchema($upgrade->locales, $rev); } }
function buildEventReport($eventIDs) { $this->assign('events', $eventIDs); $eventID = implode(',', $eventIDs); $participantStatus = CRM_Event_PseudoConstant::participantStatus(NULL, "is_counted = 1"); $participantRole = CRM_Event_PseudoConstant::participantRole(); $paymentInstruments = CRM_Contribute_PseudoConstant::paymentInstrument(); $rows = $eventSummary = $roleRows = $statusRows = $instrumentRows = $count = array(); $optionGroupDAO = new CRM_Core_DAO_OptionGroup(); $optionGroupDAO->name = 'event_type'; $optionGroupId = NULL; if ($optionGroupDAO->find(TRUE)) { $optionGroupId = $optionGroupDAO->id; } //show the income of active participant status (Counted = filter = 1) $activeParticipantStatusIDArray = $activeParticipantStatusLabelArray = array(); foreach ($participantStatus as $id => $label) { $activeParticipantStatusIDArray[] = $id; $activeParticipantStatusLabelArray[] = $label; } $activeParticipantStatus = implode(',', $activeParticipantStatusIDArray); $activeparticipnatStutusLabel = implode(', ', $activeParticipantStatusLabelArray); $activeParticipantClause = " AND civicrm_participant.status_id IN ( {$activeParticipantStatus} ) "; $sql = "\n SELECT civicrm_event.id as event_id,\n civicrm_event.title as event_title,\n civicrm_event.max_participants as max_participants, \n civicrm_event.start_date as start_date,\n civicrm_event.end_date as end_date, \n civicrm_option_value.label as event_type, \n SUM(civicrm_participant.fee_amount) as total,\n COUNT(civicrm_participant.id) as participant\n\n FROM civicrm_event\n LEFT JOIN civicrm_option_value \n ON ( civicrm_event.event_type_id = civicrm_option_value.value AND\n civicrm_option_value.option_group_id = {$optionGroupId} )\n LEFT JOIN civicrm_participant ON ( civicrm_event.id = civicrm_participant.event_id \n {$activeParticipantClause} AND civicrm_participant.is_test = 0 )\n\n WHERE civicrm_event.id IN( {$eventID}) \n \n GROUP BY civicrm_event.id\n "; $eventDAO = CRM_Core_DAO::executeQuery($sql); while ($eventDAO->fetch()) { $eventSummary[$eventDAO->event_id]['Title'] = $eventDAO->event_title; $eventSummary[$eventDAO->event_id]['Max Participants'] = $eventDAO->max_participants; $eventSummary[$eventDAO->event_id]['Start Date'] = CRM_Utils_Date::customFormat($eventDAO->start_date); $eventSummary[$eventDAO->event_id]['End Date'] = CRM_Utils_Date::customFormat($eventDAO->end_date); $eventSummary[$eventDAO->event_id]['Event Type'] = $eventDAO->event_type; $eventSummary[$eventDAO->event_id]['Event Income'] = CRM_Utils_Money::format($eventDAO->total); $eventSummary[$eventDAO->event_id]['Registered Participant'] = "{$eventDAO->participant} ({$activeparticipnatStutusLabel})"; } $this->assign_by_ref('summary', $eventSummary); //Total Participant Registerd for the Event $pariticipantCount = "\n SELECT COUNT(civicrm_participant.id ) as count, civicrm_participant.event_id as event_id\n\n FROM civicrm_participant\n\n WHERE civicrm_participant.event_id IN( {$eventID}) AND \n civicrm_participant.is_test = 0 \n {$activeParticipantClause}\n GROUP BY civicrm_participant.event_id\n "; $counteDAO = CRM_Core_DAO::executeQuery($pariticipantCount); while ($counteDAO->fetch()) { $count[$counteDAO->event_id] = $counteDAO->count; } //Count the Participant by Role ID for Event $role = "\n SELECT civicrm_participant.role_id as ROLEID, \n COUNT( civicrm_participant.id ) as participant, \n SUM(civicrm_participant.fee_amount) as amount,\n civicrm_participant.event_id as event_id\n\n FROM civicrm_participant\n\n WHERE civicrm_participant.event_id IN ( {$eventID}) AND\n civicrm_participant.is_test = 0 \n {$activeParticipantClause}\n GROUP BY civicrm_participant.role_id, civicrm_participant.event_id\n "; $roleDAO = CRM_Core_DAO::executeQuery($role); while ($roleDAO->fetch()) { // fix for multiple role, CRM-6507 $roles = explode(CRM_Core_DAO::VALUE_SEPARATOR, $roleDAO->ROLEID); foreach ($roles as $roleId) { if (!isset($roleRows[$roleDAO->event_id][$participantRole[$roleId]])) { $roleRows[$roleDAO->event_id][$participantRole[$roleId]]['total'] = 0; $roleRows[$roleDAO->event_id][$participantRole[$roleId]]['round'] = 0; $roleRows[$roleDAO->event_id][$participantRole[$roleId]]['amount'] = 0; } $roleRows[$roleDAO->event_id][$participantRole[$roleId]]['total'] += $roleDAO->participant; $roleRows[$roleDAO->event_id][$participantRole[$roleId]]['amount'] += $roleDAO->amount; } } foreach ($roleRows as $eventId => $roleInfo) { foreach ($participantRole as $roleName) { if (isset($roleInfo[$roleName])) { $roleRows[$eventId][$roleName]['round'] = round($roleRows[$eventId][$roleName]['total'] / $count[$eventId] * 100, 2); } } } $rows['Role'] = $roleRows; //Count the Participant by status ID for Event $status = "\n SELECT civicrm_participant.status_id as STATUSID, \n COUNT( civicrm_participant.id ) as participant, \n SUM(civicrm_participant.fee_amount) as amount,\n civicrm_participant.event_id as event_id\n\n FROM civicrm_participant\n\n WHERE civicrm_participant.event_id IN ({$eventID}) AND\n civicrm_participant.is_test = 0 \n {$activeParticipantClause}\n GROUP BY civicrm_participant.status_id, civicrm_participant.event_id\n "; $statusDAO = CRM_Core_DAO::executeQuery($status); while ($statusDAO->fetch()) { $statusRows[$statusDAO->event_id][$participantStatus[$statusDAO->STATUSID]]['total'] = $statusDAO->participant; $statusRows[$statusDAO->event_id][$participantStatus[$statusDAO->STATUSID]]['round'] = round($statusDAO->participant / $count[$statusDAO->event_id] * 100, 2); $statusRows[$statusDAO->event_id][$participantStatus[$statusDAO->STATUSID]]['amount'] = $statusDAO->amount; } $rows['Status'] = $statusRows; //Count the Participant by payment instrument ID for Event //e.g. Credit Card, Check,Cash etc $paymentInstrument = "\n SELECT c.payment_instrument_id as INSTRUMENT, \n COUNT( c.id ) as participant, \n SUM(civicrm_participant.fee_amount) as amount,\n civicrm_participant.event_id as event_id\n\n FROM civicrm_participant\n LEFT JOIN civicrm_participant_payment pp ON(pp.participant_id = civicrm_participant.id )\n LEFT JOIN civicrm_contribution c ON ( pp.contribution_id = c.id)\n\n WHERE civicrm_participant.event_id IN ( {$eventID}) AND\n civicrm_participant.is_test = 0\n {$activeParticipantClause}\n GROUP BY c.payment_instrument_id, civicrm_participant.event_id\n "; $instrumentDAO = CRM_Core_DAO::executeQuery($paymentInstrument); while ($instrumentDAO->fetch()) { //allow only if instrument is present in contribution table if ($instrumentDAO->INSTRUMENT) { $instrumentRows[$instrumentDAO->event_id][$paymentInstruments[$instrumentDAO->INSTRUMENT]]['total'] = $instrumentDAO->participant; $instrumentRows[$instrumentDAO->event_id][$paymentInstruments[$instrumentDAO->INSTRUMENT]]['round'] = round($instrumentDAO->participant / $count[$instrumentDAO->event_id] * 100, 2); $instrumentRows[$instrumentDAO->event_id][$paymentInstruments[$instrumentDAO->INSTRUMENT]]['amount'] = $instrumentDAO->amount; } } $rows['Payment Method'] = $instrumentRows; $this->assign_by_ref('rows', $rows); if (!$this->_setVariable) { $this->_params['id_value'] = NULL; } $this->assign('statistics', $this->statistics($eventIDs)); }
/** * Function to get title of the option group * * @param int $optionGroupId Id of the Option Group. * * @return String title * * @access public * @static */ static function getTitle($optionGroupId) { $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->id = $optionGroupId; $optionGroup->find(TRUE); return $optionGroup->name; }
/** * Takes an associative array and creates a custom field object. * * This function is invoked from within the web form layer and also from the api layer * * @param array $params * (reference) an assoc array of name/value pairs. * * @return CRM_Core_DAO_CustomField */ public static function create(&$params) { $origParams = array_merge(array(), $params); if (!isset($params['id'])) { if (!isset($params['column_name'])) { // if add mode & column_name not present, calculate it. $params['column_name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 32)); } if (!isset($params['name'])) { $params['name'] = CRM_Utils_String::munge($params['label'], '_', 64); } } else { $params['column_name'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'column_name'); } $columnName = $params['column_name']; $indexExist = FALSE; //as during create if field is_searchable we had created index. if (!empty($params['id'])) { $indexExist = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable'); } switch (CRM_Utils_Array::value('html_type', $params)) { case 'Select Date': if (empty($params['date_format'])) { $config = CRM_Core_Config::singleton(); $params['date_format'] = $config->dateInputFormat; } break; case 'CheckBox': case 'AdvMulti-Select': case 'Multi-Select': if (isset($params['default_checkbox_option'])) { $tempArray = array_keys($params['default_checkbox_option']); $defaultArray = array(); foreach ($tempArray as $k => $v) { if ($params['option_value'][$v]) { $defaultArray[] = $params['option_value'][$v]; } } if (!empty($defaultArray)) { // also add the separator before and after the value per new convention (CRM-1604) $params['default_value'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $defaultArray) . CRM_Core_DAO::VALUE_SEPARATOR; } } else { if (!empty($params['default_option']) && isset($params['option_value'][$params['default_option']])) { $params['default_value'] = $params['option_value'][$params['default_option']]; } } break; } $transaction = new CRM_Core_Transaction(); // create any option group & values if required if ($params['html_type'] != 'Text' && in_array($params['data_type'], array('String', 'Int', 'Float', 'Money'))) { $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['custom_group_id'], 'table_name'); //CRM-16659: if option_value then create an option group for this custom field. if ($params['option_type'] == 1 && (empty($params['option_group_id']) || !empty($params['option_value']))) { // first create an option group for this custom group $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->name = "{$columnName}_" . date('YmdHis'); $optionGroup->title = $params['label']; $optionGroup->is_active = 1; $optionGroup->save(); $params['option_group_id'] = $optionGroup->id; if (!empty($params['option_value']) && is_array($params['option_value'])) { foreach ($params['option_value'] as $k => $v) { if (strlen(trim($v))) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $optionGroup->id; $optionValue->label = $params['option_label'][$k]; $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]); switch ($params['data_type']) { case 'Money': $optionValue->value = CRM_Utils_Rule::cleanMoney($v); break; case 'Int': $optionValue->value = intval($v); break; case 'Float': $optionValue->value = floatval($v); break; default: $optionValue->value = trim($v); } $optionValue->weight = $params['option_weight'][$k]; $optionValue->is_active = CRM_Utils_Array::value($k, $params['option_status'], FALSE); $optionValue->save(); } } } } } // check for orphan option groups if (!empty($params['option_group_id'])) { if (!empty($params['id'])) { self::fixOptionGroups($params['id'], $params['option_group_id']); } // if we do not have a default value // retrieve it from one of the other custom fields which use this option group if (empty($params['default_value'])) { //don't insert only value separator as default value, CRM-4579 $defaultValue = self::getOptionGroupDefault($params['option_group_id'], $params['html_type']); if (!CRM_Utils_System::isNull(explode(CRM_Core_DAO::VALUE_SEPARATOR, $defaultValue))) { $params['default_value'] = $defaultValue; } } } // since we need to save option group id :) if (!isset($params['attributes']) && strtolower($params['html_type']) == 'textarea') { $params['attributes'] = 'rows=4, cols=60'; } $customField = new CRM_Core_DAO_CustomField(); $customField->copyValues($params); $customField->is_required = CRM_Utils_Array::value('is_required', $params, FALSE); $customField->is_searchable = CRM_Utils_Array::value('is_searchable', $params, FALSE); $customField->in_selector = CRM_Utils_Array::value('in_selector', $params, FALSE); $customField->is_search_range = CRM_Utils_Array::value('is_search_range', $params, FALSE); //CRM-15792 - Custom field gets disabled if is_active not set $customField->is_active = CRM_Utils_Array::value('is_active', $params, TRUE); $customField->is_view = CRM_Utils_Array::value('is_view', $params, FALSE); $customField->save(); // make sure all values are present in the object for further processing $customField->find(TRUE); $triggerRebuild = CRM_Utils_Array::value('triggerRebuild', $params, TRUE); //create/drop the index when we toggle the is_searchable flag if (!empty($params['id'])) { self::createField($customField, 'modify', $indexExist, $triggerRebuild); } else { if (!isset($origParams['column_name'])) { $columnName .= "_{$customField->id}"; $params['column_name'] = $columnName; } $customField->column_name = $columnName; $customField->save(); // make sure all values are present in the object $customField->find(TRUE); $indexExist = FALSE; self::createField($customField, 'add', $indexExist, $triggerRebuild); } // complete transaction $transaction->commit(); CRM_Utils_System::flushCache(); return $customField; }
/** * Process the form. */ public function postProcess() { // store the submitted values in an array $status = ''; $params = $this->controller->exportValues($this->_name); $params['id'] = $this->_surveyId; $updateResultSet = FALSE; $resultSetOptGrpId = NULL; if (CRM_Utils_Array::value('option_type', $params) == 2 && !empty($params['option_group_id'])) { $updateResultSet = TRUE; $resultSetOptGrpId = $params['option_group_id']; } $recontactInterval = array(); if ($updateResultSet) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $resultSetOptGrpId; $optionValue->delete(); $params['result_id'] = $resultSetOptGrpId; } else { $opGroupName = 'civicrm_survey_' . rand(10, 1000) . '_' . date('YmdHis'); $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->name = $opGroupName; $optionGroup->title = $this->_values['title'] . ' Result Set'; $optionGroup->is_active = 1; $optionGroup->save(); $params['result_id'] = $optionGroup->id; } foreach ($params['option_value'] as $k => $v) { if (strlen(trim($v))) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $params['result_id']; $optionValue->label = $params['option_label'][$k]; $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]); $optionValue->value = trim($v); $optionValue->weight = $params['option_weight'][$k]; $optionValue->is_active = 1; if (!empty($params['default_option']) && $params['default_option'] == $k) { $optionValue->is_default = 1; } $optionValue->save(); // using is_numeric since 0 is a valid value for option_interval if (is_numeric($params['option_interval'][$k])) { $recontactInterval[$optionValue->label] = $params['option_interval'][$k]; } } } $params['recontact_interval'] = serialize($recontactInterval); $survey = CRM_Campaign_BAO_Survey::create($params); // create report if required. if (!$this->_reportId && $survey->id && !empty($params['create_report'])) { $activityStatus = CRM_Core_PseudoConstant::activityStatus('name'); $activityStatus = array_flip($activityStatus); $this->_params = array('name' => "survey_{$survey->id}", 'title' => $params['report_title'] ? $params['report_title'] : $this->_values['title'], 'status_id_op' => 'eq', 'status_id_value' => $activityStatus['Scheduled'], 'survey_id_value' => array($survey->id), 'description' => ts('Detailed report for canvassing, phone-banking, walk lists or other surveys.')); //Default value of order by $this->_params['order_bys'] = array(1 => array('column' => 'sort_name', 'order' => 'ASC')); // for WalkList or default $displayFields = array('id', 'sort_name', 'result', 'street_number', 'street_name', 'street_unit', 'survey_response'); if (CRM_Core_OptionGroup::getValue('activity_type', 'WalkList') == $this->_values['activity_type_id']) { $this->_params['order_bys'] = array(1 => array('column' => 'street_name', 'order' => 'ASC'), 2 => array('column' => 'street_number_odd_even', 'order' => 'ASC'), 3 => array('column' => 'street_number', 'order' => 'ASC'), 4 => array('column' => 'sort_name', 'order' => 'ASC')); } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'PhoneBank') == $this->_values['activity_type_id']) { array_push($displayFields, 'phone'); } elseif (CRM_Core_OptionGroup::getValue('activity_type', 'Survey') == $this->_values['activity_type_id'] || CRM_Core_OptionGroup::getValue('activity_type', 'Canvass') == $this->_values['activity_type_id']) { array_push($displayFields, 'phone', 'city', 'state_province_id', 'postal_code', 'email'); } foreach ($displayFields as $key) { $this->_params['fields'][$key] = 1; } $this->_createNew = TRUE; $this->_id = CRM_Report_Utils_Report::getInstanceIDForValue('survey/detail'); CRM_Report_Form_Instance::postProcess($this, FALSE); $query = "SELECT MAX(id) FROM civicrm_report_instance WHERE name = %1"; $reportID = CRM_Core_DAO::singleValueQuery($query, array(1 => array("survey_{$survey->id}", 'String'))); if ($reportID) { $url = CRM_Utils_System::url("civicrm/report/instance/{$reportID}", 'reset=1'); $status = ts("A Survey Detail Report <a href='%1'>%2</a> has been created.", array(1 => $url, 2 => $this->_params['title'])); } } if ($status) { // reset status as we don't want status set by Instance::postProcess $session = CRM_Core_Session::singleton(); $session->getStatus(TRUE); // set new status CRM_Core_Session::setStatus($status, ts('Saved'), 'success'); } parent::endPostProcess(); }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); $session = CRM_Core_Session::singleton(); $params['last_modified_id'] = $session->get('userID'); $params['last_modified_date'] = date('YmdHis'); require_once 'CRM/Core/BAO/OptionValue.php'; require_once 'CRM/Core/BAO/OptionGroup.php'; $updateResultSet = false; if (CRM_Utils_Array::value('option_type', $params) == 2 && CRM_Utils_Array::value('option_group_id', $params)) { if ($params['option_group_id'] == CRM_Utils_Array::value('result_id', $this->_values)) { $updateResultSet = true; } } if ($this->_surveyId) { if ($this->_action & CRM_Core_Action::DELETE) { CRM_Campaign_BAO_Survey::del($this->_surveyId); CRM_Core_Session::setStatus(ts(' Survey has been deleted.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey')); return; } $params['id'] = $this->_surveyId; } else { $params['created_id'] = $session->get('userID'); $params['created_date'] = date('YmdHis'); } $params['is_active'] = CRM_Utils_Array::value('is_active', $params, 0); $params['is_default'] = CRM_Utils_Array::value('is_default', $params, 0); $recontactInterval = array(); if ($updateResultSet) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $this->_values['result_id']; $optionValue->delete(); $params['result_id'] = $this->_values['result_id']; } else { $opGroupName = 'civicrm_survey_' . rand(10, 1000) . '_' . date('YmdHis'); $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->name = $opGroupName; $optionGroup->label = $params['title'] . ' Response Set'; $optionGroup->is_active = 1; $optionGroup->save(); $params['result_id'] = $optionGroup->id; } foreach ($params['option_value'] as $k => $v) { if (strlen(trim($v))) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $params['result_id']; $optionValue->label = $params['option_label'][$k]; $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]); $optionValue->value = trim($v); $optionValue->weight = $params['option_weight'][$k]; $optionValue->is_active = 1; if (CRM_Utils_Array::value('default_option', $params) && $params['default_option'] == $k) { $optionValue->is_default = 1; } $optionValue->save(); if (CRM_Utils_Array::value($k, $params['option_interval'])) { $recontactInterval[$optionValue->label] = $params['option_interval'][$k]; } } } $params['recontact_interval'] = serialize($recontactInterval); $surveyId = CRM_Campaign_BAO_Survey::create($params); if (CRM_Utils_Array::value('result_id', $this->_values) && !$updateResultSet) { $query = "SELECT COUNT(*) FROM civicrm_survey WHERE result_id = %1"; $countSurvey = CRM_Core_DAO::singleValueQuery($query, array(1 => array($this->_values['result_id'], 'Integer'))); // delete option group if no any survey is using it. if (!($countSurvey >= 1)) { CRM_Core_BAO_OptionGroup::del($this->_values['result_id']); } } require_once 'CRM/Core/BAO/UFJoin.php'; // also update the ProfileModule tables $ufJoinParams = array('is_active' => 1, 'module' => 'CiviCampaign', 'entity_table' => 'civicrm_survey', 'entity_id' => $surveyId->id); // first delete all past entries if ($this->_surveyId) { CRM_Core_BAO_UFJoin::deleteAll($ufJoinParams); } if (CRM_Utils_Array::value('profile_id', $params)) { $ufJoinParams['weight'] = 1; $ufJoinParams['uf_group_id'] = $params['profile_id']; CRM_Core_BAO_UFJoin::create($ufJoinParams); } if (!is_a($surveyId, 'CRM_Core_Error')) { CRM_Core_Session::setStatus(ts('Survey %1 has been saved.', array(1 => $params['title']))); } if ($this->_context == 'dialog') { $returnArray = array('returnSuccess' => true); echo json_encode($returnArray); CRM_Utils_System::civiExit(); } $buttonName = $this->controller->getButtonName(); if ($buttonName == $this->getButtonName('next', 'new')) { CRM_Core_Session::setStatus(ts(' You can add another Survey.')); $session->replaceUserContext(CRM_Utils_System::url('civicrm/survey/add', 'reset=1&action=add')); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/campaign', 'reset=1&subPage=survey')); } }
/** * Find a price_set_id associatied with the given option value or field ID * @param array $params (reference) an assoc array of name/value pairs * array may contain either option id or * price field id * * @return price set id on success, null otherwise * @static * @access public */ public static function getSetId(&$params) { $fid = null; require_once 'CRM/Utils/Array.php'; if ($oid = CRM_Utils_Array::value('oid', $params)) { require_once 'CRM/Core/DAO/OptionGroup.php'; $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->id = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionValue', $oid, 'option_group_id'); if ($optionGroup->find(true)) { $groupName = explode(".", $optionGroup->name); $fid = $groupName[2]; } } else { $fid = CRM_Utils_Array::value('fid', $params); } if (isset($fid)) { return CRM_Core_DAO::getFieldValue('CRM_Price_DAO_Field', $fid, 'price_set_id'); } return null; }
/** * takes an associative array and creates a custom field object * * This function is invoked from within the web form layer and also from the api layer * * @param array $params (reference) an assoc array of name/value pairs * * @return object CRM_Core_DAO_CustomField object * @access public * @static */ static function create(&$params) { if (!isset($params['id']) && !isset($params['column_name'])) { // if add mode & column_name not present, calculate it. require_once 'CRM/Utils/String.php'; $params['column_name'] = strtolower(CRM_Utils_String::munge($params['label'], '_', 32)); $params['name'] = CRM_Utils_String::munge($params['label'], '_', 64); } else { if (isset($params['id'])) { $params['column_name'] = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'column_name'); } } $indexExist = false; //as during create if field is_searchable we had created index. if (CRM_Utils_Array::value('id', $params)) { $indexExist = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $params['id'], 'is_searchable'); } if (($params['html_type'] == 'CheckBox' || $params['html_type'] == 'AdvMulti-Select' || $params['html_type'] == 'Multi-Select') && isset($params['default_checkbox_option'])) { $tempArray = array_keys($params['default_checkbox_option']); $defaultArray = array(); foreach ($tempArray as $k => $v) { if ($params['option_value'][$v]) { $defaultArray[] = $params['option_value'][$v]; } } if (!empty($defaultArray)) { // also add the seperator before and after the value per new conventio (CRM-1604) $params['default_value'] = CRM_Core_BAO_CustomOption::VALUE_SEPERATOR . implode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $defaultArray) . CRM_Core_BAO_CustomOption::VALUE_SEPERATOR; } } else { if (CRM_Utils_Array::value('default_option', $params) && isset($params['option_value'][$params['default_option']])) { $params['default_value'] = $params['option_value'][$params['default_option']]; } } require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); // create any option group & values if required if ($params['html_type'] != 'Text' && in_array($params['data_type'], array('String', 'Int', 'Float', 'Money')) && !empty($params['option_value']) && is_array($params['option_value'])) { $tableName = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $params['custom_group_id'], 'table_name'); if ($params['option_type'] == 1) { // first create an option group for this custom group require_once 'CRM/Core/BAO/OptionGroup.php'; $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->name = "{$params['column_name']}_" . date('YmdHis'); $optionGroup->label = $params['label']; $optionGroup->is_active = 1; $optionGroup->save(); $params['option_group_id'] = $optionGroup->id; require_once 'CRM/Core/BAO/OptionValue.php'; require_once 'CRM/Utils/String.php'; foreach ($params['option_value'] as $k => $v) { if (strlen(trim($v))) { $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->option_group_id = $optionGroup->id; $optionValue->label = $params['option_label'][$k]; $optionValue->name = CRM_Utils_String::titleToVar($params['option_label'][$k]); switch ($params['data_type']) { case 'Money': require_once 'CRM/Utils/Rule.php'; $optionValue->value = number_format(CRM_Utils_Rule::cleanMoney($v), 2); break; case 'Int': $optionValue->value = intval($v); break; case 'Float': $optionValue->value = floatval($v); break; default: $optionValue->value = trim($v); } $optionValue->weight = $params['option_weight'][$k]; $optionValue->is_active = CRM_Utils_Array::value($k, $params['option_status'], false); $optionValue->save(); } } } } // check for orphan option groups if (CRM_Utils_Array::value('option_group_id', $params)) { if (CRM_Utils_Array::value('id', $params)) { self::fixOptionGroups($params['id'], $params['option_group_id']); } // if we dont have a default value // retrive it from one of the other custom fields which use this option group if (!CRM_Utils_Array::value('default_value', $params)) { //don't insert only value separator as default value, CRM-4579 $defaultValue = self::getOptionGroupDefault($params['option_group_id'], $params['html_type']); if (!CRM_Utils_System::isNull(explode(CRM_Core_BAO_CustomOption::VALUE_SEPERATOR, $defaultValue))) { $params['default_value'] = $defaultValue; } } } // since we need to save option group id :) if (!isset($params['attributes']) && strtolower($params['html_type']) == 'textarea') { $params['attributes'] = 'rows=4, cols=60'; } $customField = new CRM_Core_DAO_CustomField(); $customField->copyValues($params); $customField->is_required = CRM_Utils_Array::value('is_required', $params, false); $customField->is_searchable = CRM_Utils_Array::value('is_searchable', $params, false); $customField->is_search_range = CRM_Utils_Array::value('is_search_range', $params, false); $customField->is_active = CRM_Utils_Array::value('is_active', $params, false); $customField->is_view = CRM_Utils_Array::value('is_view', $params, false); $customField->save(); // make sure all values are present in the object for further processing $customField->find(true); //create/drop the index when we toggle the is_searchable flag if (CRM_Utils_Array::value('id', $params)) { self::createField($customField, 'modify', $indexExist); } else { $customField->column_name .= "_{$customField->id}"; $customField->save(); // make sure all values are present in the object $customField->find(true); self::createField($customField, 'add'); } // complete transaction $transaction->commit(); // reset the cache require_once 'CRM/Core/BAO/Cache.php'; CRM_Core_BAO_Cache::deleteGroup('contact fields'); // reset various static arrays used here require_once 'CRM/Contact/BAO/Contact.php'; CRM_Contact_BAO_Contact::$_importableFields = CRM_Contact_BAO_Contact::$_exportableFields = self::$_importFields = null; return $customField; }
/** * Get DataType for a specified option Group * * @param int $optionGroupId * Id of the Option Group. * * @return string|null * Data Type */ public static function getDataType($optionGroupId) { $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->id = $optionGroupId; $optionGroup->find(TRUE); return $optionGroup->data_type; }
/** * updates contacts affected by the option value passed. * * @param Integer $optionValueId the option value id. * @param int $action the action describing whether prefix/suffix was UPDATED or DELETED * * @return void */ static function updateRecords(&$optionValueId, $action) { //finding group name $optionValue = new CRM_Core_DAO_OptionValue(); $optionValue->id = $optionValueId; $optionValue->find(TRUE); $optionGroup = new CRM_Core_DAO_OptionGroup(); $optionGroup->id = $optionValue->option_group_id; $optionGroup->find(TRUE); // group name $gName = $optionGroup->name; // value $value = $optionValue->value; // get the proper group name & affected field name $individuals = array('gender' => 'gender_id', 'individual_prefix' => 'prefix_id', 'individual_suffix' => 'suffix_id'); $contributions = array('payment_instrument' => 'payment_instrument_id'); $activities = array('activity_type' => 'activity_type_id'); $participant = array('participant_role' => 'role_id'); $eventType = array('event_type' => 'event_type_id'); $aclRole = array('acl_role' => 'acl_role_id'); $all = array_merge($individuals, $contributions, $activities, $participant, $eventType, $aclRole); $fieldName = ''; foreach ($all as $name => $id) { if ($gName == $name) { $fieldName = $id; } } if ($fieldName == '') { return TRUE; } if (array_key_exists($gName, $individuals)) { $contactDAO = new CRM_Contact_DAO_Contact(); $contactDAO->{$fieldName} = $value; $contactDAO->find(); while ($contactDAO->fetch()) { if ($action == CRM_Core_Action::DELETE) { $contact = new CRM_Contact_DAO_Contact(); $contact->id = $contactDAO->id; $contact->find(TRUE); // make sure dates doesn't get reset $contact->birth_date = CRM_Utils_Date::isoToMysql($contact->birth_date); $contact->deceased_date = CRM_Utils_Date::isoToMysql($contact->deceased_date); $contact->{$fieldName} = 'NULL'; $contact->save(); } } return TRUE; } if (array_key_exists($gName, $contributions)) { $contribution = new CRM_Contribute_DAO_Contribution(); $contribution->{$fieldName} = $value; $contribution->find(); while ($contribution->fetch()) { if ($action == CRM_Core_Action::DELETE) { $contribution->{$fieldName} = 'NULL'; $contribution->save(); } } return TRUE; } if (array_key_exists($gName, $activities)) { $activity = new CRM_Activity_DAO_Activity(); $activity->{$fieldName} = $value; $activity->find(); while ($activity->fetch()) { $activity->delete(); } return TRUE; } //delete participant role, type and event type option value if (array_key_exists($gName, $participant)) { $participantValue = new CRM_Event_DAO_Participant(); $participantValue->{$fieldName} = $value; if ($participantValue->find(TRUE)) { return FALSE; } return TRUE; } //delete event type option value if (array_key_exists($gName, $eventType)) { $event = new CRM_Event_DAO_Event(); $event->{$fieldName} = $value; if ($event->find(TRUE)) { return FALSE; } return TRUE; } //delete acl_role option value if (array_key_exists($gName, $aclRole)) { $entityRole = new CRM_ACL_DAO_EntityRole(); $entityRole->{$fieldName} = $value; $aclDAO = new CRM_ACL_DAO_ACL(); $aclDAO->entity_id = $value; if ($entityRole->find(TRUE) || $aclDAO->find(TRUE)) { return FALSE; } return TRUE; } }
/** * class constructor */ function __construct() { parent::__construct(); }