<?php
/*
+--------------------------------------------------------------------+
- | CiviCRM version 4.3 |
+ | CiviCRM version 4.4 |
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC (c) 2004-2013 |
+--------------------------------------------------------------------+
$this->fetch('mappingField', 'CRM_Core_DAO_MappingField');
}
+ /**
+ * @param array $customGroupIds list of custom groups to export
+ * @return void
+ */
+ function buildCustomGroups($customGroupIds) {
+ $customGroupIdsSql = implode(',', array_filter($customGroupIds, 'is_numeric'));
+ if (empty($customGroupIdsSql)) {
+ return;
+ }
+
+ $sql = "
+ SELECT distinct(g.id), g.*
+ FROM civicrm_option_group g,
+ civicrm_custom_field f,
+ civicrm_custom_group cg
+ WHERE f.option_group_id = g.id
+ AND f.custom_group_id = cg.id
+ AND cg.id in ($customGroupIdsSql)
+ ";
+ $this->fetch('optionGroup', 'CRM_Core_DAO_OptionGroup', $sql);
+
+ $sql = "
+ SELECT distinct(v.id), v.*, g.name as prefix
+ FROM civicrm_option_value v,
+ civicrm_option_group g,
+ civicrm_custom_field f,
+ civicrm_custom_group cg
+ WHERE v.option_group_id = g.id
+ AND f.option_group_id = g.id
+ AND f.custom_group_id = cg.id
+ AND cg.id in ($customGroupIdsSql)
+ ";
+
+ $this->fetch('optionValue', 'CRM_Core_DAO_OptionValue', $sql);
+
+ $sql = "
+ SELECT cg.*
+ FROM civicrm_custom_group cg
+ WHERE cg.id in ($customGroupIdsSql)
+
+ ";
+ $this->fetch('customGroup', 'CRM_Core_DAO_CustomGroup', $sql);
+
+ $sql = "
+ SELECT f.*
+ FROM civicrm_custom_field f,
+ civicrm_custom_group cg
+ WHERE f.custom_group_id = cg.id
+ AND cg.id in ($customGroupIdsSql)
+ ";
+ $this->fetch('customField', 'CRM_Core_DAO_CustomField', $sql);
+ }
+
+ /**
+ * @param array $ufGroupIds list of custom groups to export
+ * @return void
+ */
+ function buildUFGroups($ufGroupIds) {
+ $ufGroupIdsSql = implode(',', array_filter($ufGroupIds, 'is_numeric'));
+ if (empty($ufGroupIdsSql)) {
+ return;
+ }
+
+ $sql = "
+ SELECT cg.*
+ FROM civicrm_uf_group cg
+ WHERE cg.id IN ($ufGroupIdsSql)
+
+ ";
+ $this->fetch('profileGroup', 'CRM_Core_DAO_UFGroup', $sql);
+
+ $sql = "
+ SELECT f.*
+ FROM civicrm_uf_field f,
+ civicrm_uf_group cg
+ WHERE f.uf_group_id = cg.id
+ AND cg.id IN ($ufGroupIdsSql)
+ ";
+ $this->fetch('profileField', 'CRM_Core_DAO_UFField', $sql);
+
+ $sql = "
+ SELECT *
+ FROM civicrm_uf_join
+ WHERE entity_table IS NULL
+ AND entity_id IS NULL
+ AND uf_group_id IN ($ufGroupIdsSql)
+ ";
+ $this->fetch('profileJoin', 'CRM_Core_DAO_UFJoin', $sql);
+ }
+
/**
* Render the in-memory representation as XML
*
$result = array();
foreach (array_keys($this->_xml) as $key) {
if (!empty($this->_xml[$key]['data'])) {
- $result[ $this->_xml[$key]['name'] ] = $this->_xml[$key]['data'];
+ $result[ $this->_xml[$key]['name'] ] = array_values($this->_xml[$key]['data']);
}
}
return $result;
}
while ($dao->fetch()) {
- $this->_xml[$groupName]['data'][] = $this->exportDAO($this->_xml[$groupName]['name'], $dao, $mappedFields);
+ $this->_xml[$groupName]['data'][$dao->id] = $this->exportDAO($this->_xml[$groupName]['name'], $dao, $mappedFields);
if ($idNameFields) {
// index the id/name fields so that we can translate from FK ids to FK names
if (isset($idNameFields[2])) {
if (isset($object->$name) && $object->$name !== NULL) {
// hack for extends_entity_column_value
if ($name == 'extends_entity_column_value') {
- if ($object->extends == 'Event' ||
- $object->extends == 'Activity' ||
- $object->extends == 'Relationship'
- ) {
+ if (in_array($object->extends, array('Event', 'Activity', 'Relationship', 'Individual', 'Organization', 'Household'))) {
if ($object->extends == 'Event') {
$key = 'event_type';
}
elseif ($object->extends == 'Relationship') {
$key = 'relationship_type';
}
- $keyValues['extends_entity_column_value_option_group'] = $key;
+ elseif($object->extends == 'Case') {
+ $key = 'case_type';
+ }
$types = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($object->$name, 1, -1));
$values = array();
- foreach ($types as $type) {
- $values[] = $this->_xml['optionValue']['idNameMap']["$key.{$type}"];
+ if (in_array($object->extends, array('Individual', 'Organization', 'Household'))) {
+ $key = 'contact_type';
+ $values = $types;
}
+ else {
+ foreach ($types as $type) {
+ if (in_array($key, array('activity_type', 'event_type'))) {
+ $ogID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', $key, 'id', 'name');
+ $ovParams = array('option_group_id' => $ogID, 'value' => $type);
+ CRM_Core_BAO_OptionValue::retrieve($ovParams, $oValue);
+ $values[] = $oValue['name'];
+ }
+ else {
+ $relTypeName = CRM_Core_DAO::getFieldValue('CRM_Contact_BAO_RelationshipType', $type, 'name_a_b', 'id');
+ $values[] = $relTypeName;
+ }
+ }
+ }
+ $keyValues['extends_entity_column_value_option_group'] = $key;
$value = implode(',', $values);
- $keyValues['extends_entity_column_value_option_value'] = $value;
+ $object->extends_entity_column_value = $value;
}
else {
echo "This extension: {$object->extends} is not yet handled";