Exemple #1
0
 function createGroup($group, $extends = null, $isMultiple = false)
 {
     if (empty($group)) {
         $group = array('title' => 'Test_Group', 'name' => 'test_group', 'extends' => $extends, 'style' => 'Inline', 'is_multiple' => $isMultiple, 'is_active' => 1);
     }
     require_once 'CRM/Core/BAO/CustomGroup.php';
     require_once 'CRM/Utils/String.php';
     $customGroupBAO =& new CRM_Core_BAO_CustomGroup();
     $customGroupBAO->copyValues($group);
     $customGroup = $customGroupBAO->save();
     $customGroup->table_name = "civicrm_value_" . strtolower(CRM_Utils_String::munge($group['title'], '_', 32));
     $customGroup->table_name = $customGroup->table_name . '_' . $customGroup->id;
     $customGroup = $customGroupBAO->save();
     $customTable = CRM_Core_BAO_CustomGroup::createTable($customGroup);
     return $customGroup;
 }
Exemple #2
0
 /**
  * @param $xml
  * @param $idMap
  */
 public function customGroups(&$xml, &$idMap)
 {
     foreach ($xml->CustomGroups as $customGroupsXML) {
         foreach ($customGroupsXML->CustomGroup as $customGroupXML) {
             $customGroup = new CRM_Core_DAO_CustomGroup();
             if (!$this->copyData($customGroup, $customGroupXML, TRUE, 'name')) {
                 $idMap['custom_group'][$customGroup->name] = $customGroup->id;
                 continue;
             }
             $saveAgain = FALSE;
             if (!isset($customGroup->table_name) || empty($customGroup->table_name)) {
                 // fix table name
                 $customGroup->table_name = "civicrm_value_" . strtolower(CRM_Utils_String::munge($customGroup->title, '_', 32)) . "_{$customGroup->id}";
                 $saveAgain = TRUE;
             }
             // fix extends stuff if it exists
             if (isset($customGroupXML->extends_entity_column_value_option_group) && isset($customGroupXML->extends_entity_column_value)) {
                 $valueIDs = array();
                 $optionValues = explode(",", $customGroupXML->extends_entity_column_value);
                 $optValues = implode("','", $optionValues);
                 if (trim($customGroup->extends) != 'Participant') {
                     if ($customGroup->extends == 'Relationship') {
                         foreach ($optionValues as $key => $value) {
                             $relTypeId = CRM_Core_DAO::getFieldValue('CRM_Contact_BAO_RelationshipType', $value, 'id', 'name_a_b');
                             $valueIDs[] = $relTypeId;
                         }
                     } elseif (in_array($customGroup->extends, array('Individual', 'Organization', 'Household'))) {
                         $valueIDs = $optionValues;
                     } else {
                         $sql = "\nSELECT     v.value\nFROM       civicrm_option_value v\nINNER JOIN civicrm_option_group g ON g.id = v.option_group_id\nWHERE      g.name = %1\nAND        v.name IN ('{$optValues}')\n";
                         $params = array(1 => array((string) $customGroupXML->extends_entity_column_value_option_group, 'String'));
                         $dao =& CRM_Core_DAO::executeQuery($sql, $params);
                         while ($dao->fetch()) {
                             $valueIDs[] = $dao->value;
                         }
                     }
                     if (!empty($valueIDs)) {
                         $customGroup->extends_entity_column_value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $valueIDs) . CRM_Core_DAO::VALUE_SEPARATOR;
                         unset($valueIDs);
                         // Note: No need to set extends_entity_column_id here.
                         $saveAgain = TRUE;
                     }
                 } else {
                     // when custom group extends 'Participant'
                     $sql = "\nSELECT     v.value\nFROM       civicrm_option_value v\nINNER JOIN civicrm_option_group g ON g.id = v.option_group_id\nWHERE      g.name = 'custom_data_type'\nAND        v.name = %1\n";
                     $params = array(1 => array((string) $customGroupXML->extends_entity_column_value_option_group, 'String'));
                     $valueID = (int) CRM_Core_DAO::singleValueQuery($sql, $params);
                     if ($valueID) {
                         $customGroup->extends_entity_column_id = $valueID;
                     }
                     $optionIDs = array();
                     switch ($valueID) {
                         case 1:
                             // ParticipantRole
                             $condition = "AND v.name IN ( '{$optValues}' )";
                             $optionIDs = CRM_Core_OptionGroup::values('participant_role', FALSE, FALSE, FALSE, $condition, 'name');
                             break;
                         case 2:
                             // ParticipantEventName
                             $condition = "( is_template IS NULL OR is_template != 1 ) AND title IN( '{$optValues}' )";
                             $optionIDs = CRM_Event_PseudoConstant::event(NULL, FALSE, $condition);
                             break;
                         case 3:
                             // ParticipantEventType
                             $condition = "AND v.name IN ( '{$optValues}' )";
                             $optionIDs = CRM_Core_OptionGroup::values('event_type', FALSE, FALSE, FALSE, $condition, 'name');
                             break;
                     }
                     if (is_array($optionIDs) && !empty($optionIDs)) {
                         $customGroup->extends_entity_column_value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($optionIDs)) . CRM_Core_DAO::VALUE_SEPARATOR;
                         $saveAgain = TRUE;
                     }
                 }
             }
             if ($saveAgain) {
                 $customGroup->save();
             }
             CRM_Core_BAO_CustomGroup::createTable($customGroup);
             $idMap['custom_group'][$customGroup->name] = $customGroup->id;
         }
     }
 }
Exemple #3
0
 function customGroups(&$xml, &$idMap)
 {
     require_once 'CRM/Core/BAO/CustomGroup.php';
     require_once 'CRM/Utils/String.php';
     foreach ($xml->CustomGroups as $customGroupsXML) {
         foreach ($customGroupsXML->CustomGroup as $customGroupXML) {
             $customGroup = new CRM_Core_DAO_CustomGroup();
             if (!$this->copyData($customGroup, $customGroupXML, true, 'name')) {
                 $idMap['custom_group'][$customGroup->name] = $customGroup->id;
                 continue;
             }
             $saveAgain = false;
             if (!isset($customGroup->table_name) || empty($customGroup->table_name)) {
                 // fix table name
                 $customGroup->table_name = "civicrm_value_" . strtolower(CRM_Utils_String::munge($customGroup->title, '_', 32)) . "_{$customGroup->id}";
                 $saveAgain = true;
             }
             // fix extends stuff if it exists
             if (isset($customGroupXML->extends_entity_column_value_option_group) && isset($customGroupXML->extends_entity_column_value_option_value)) {
                 $optValues = explode(",", $customGroupXML->extends_entity_column_value_option_value);
                 $optValues = implode("','", $optValues);
                 if (trim($customGroup->extends) != 'Participant') {
                     $sql = "\nSELECT     v.value\nFROM       civicrm_option_value v\nINNER JOIN civicrm_option_group g ON g.id = v.option_group_id\nWHERE      g.name = %1\nAND        v.name IN (%2)\n";
                     $params = array(1 => array((string) $customGroupXML->extends_entity_column_value_option_group, 'String'), 2 => array((string) $optValues, 'String'));
                     $dao =& CRM_Core_DAO::executeQuery($sql, $params);
                     $valueIDs = array();
                     while ($dao->fetch()) {
                         $valueIDs[] = $dao->value;
                     }
                     if (!empty($valueIDs)) {
                         $customGroup->extends_entity_column_value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, $valueIDs) . CRM_Core_DAO::VALUE_SEPARATOR;
                         // Note: No need to set extends_entity_column_id here.
                         $saveAgain = true;
                     }
                 } else {
                     // when custom group extends 'Participant'
                     $sql = "\nSELECT     v.value\nFROM       civicrm_option_value v\nINNER JOIN civicrm_option_group g ON g.id = v.option_group_id\nWHERE      g.name = 'custom_data_type'\nAND        v.name = %1\n";
                     $params = array(1 => array((string) $customGroupXML->extends_entity_column_value_option_group, 'String'));
                     $valueID = (int) CRM_Core_DAO::singleValueQuery($sql, $params);
                     if ($valueID) {
                         $customGroup->extends_entity_column_id = $valueID;
                     }
                     $optionIDs = array();
                     switch ($valueID) {
                         case 1:
                             // ParticipantRole
                             require_once 'CRM/Core/OptionGroup.php';
                             $condition = "AND v.name IN ( '{$optValues}' )";
                             $optionIDs = CRM_Core_OptionGroup::values('participant_role', false, false, false, $condition, 'name');
                             break;
                         case 2:
                             // ParticipantEventName
                             require_once 'CRM/Event/PseudoConstant.php';
                             $condition = "( is_template IS NULL OR is_template != 1 ) AND title IN( '{$optValues}' )";
                             $optionIDs = CRM_Event_PseudoConstant::event(null, false, $condition);
                             break;
                         case 3:
                             // ParticipantEventType
                             require_once 'CRM/Core/OptionGroup.php';
                             $condition = "AND v.name IN ( '{$optValues}' )";
                             $optionIDs = CRM_Core_OptionGroup::values('event_type', false, false, false, $condition, 'name');
                             break;
                     }
                     if (is_array($optionIDs) && !empty($optionIDs)) {
                         $customGroup->extends_entity_column_value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($optionIDs)) . CRM_Core_DAO::VALUE_SEPARATOR;
                         $saveAgain = true;
                     }
                 }
             }
             if ($saveAgain) {
                 $customGroup->save();
             }
             CRM_Core_BAO_CustomGroup::createTable($customGroup);
             $idMap['custom_group'][$customGroup->name] = $customGroup->id;
         }
     }
 }
Exemple #4
0
 /**
  * Function to test createTable()
  */
 function testCreateTable()
 {
     $customGrouptitle = 'My Custom Group';
     $groupParams = array('title' => $customGrouptitle, 'name' => 'my_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'is_active' => 1);
     require_once 'CRM/Core/BAO/CustomGroup.php';
     $customGroupBAO =& new CRM_Core_BAO_CustomGroup();
     $customGroupBAO->copyValues($groupParams);
     $customGroup = $customGroupBAO->save();
     $tableName = 'civicrm_value_test_group_' . $customGroup->id;
     $customGroup->table_name = $tableName;
     $customGroup = $customGroupBAO->save();
     $customTable = CRM_Core_BAO_CustomGroup::createTable($customGroup);
     $customGroupId = $customGroup->id;
     //check db for custom group.
     $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id', 'Database check for custom group record.');
     //check for custom group table name
     $this->assertDBCompareValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'table_name', 'id', $tableName, 'Database check for custom group table name.');
     //check for group title
     $this->assertEquals($customGrouptitle, $dbCustomGroupTitle);
     //cleanup DB by deleting customGroup
     Custom::deleteGroup($customGroup);
 }
Exemple #5
0
 /**
  *  Test civicrm_activity_get() with a good activity ID which
  *  has associated custom data
  */
 function testActivityGetGoodIDCustom()
 {
     //  Insert rows in civicrm_activity creating activities 4 and
     //  13
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
     $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_XMLDataSet(dirname(__FILE__) . '/dataset/activity_4_13.xml'));
     //  Insert rows in civicrm_custom_group and civicrm_custom_field
     //  creating Activity Custom to extend activity type 5
     $op = new PHPUnit_Extensions_Database_Operation_Insert();
     $op->execute($this->_dbconn, new PHPUnit_Extensions_Database_DataSet_FlatXMLDataSet(dirname(__FILE__) . '/dataset/custom_group_activity_type_5.xml'));
     //  Drop and create table civicrm_value_activity_custom_9
     $query = 'DROP TABLE IF EXISTS civicrm_value_activity_custom_9';
     AllTests::$utils->do_query($query);
     $group = new CRM_Core_DAO_CustomGroup();
     $group->extends = "Activity";
     $group->table_name = 'civicrm_value_activity_custom_9';
     $group->is_multiple = 0;
     $group->is_active = 1;
     CRM_Core_BAO_CustomGroup::createTable($group);
     //  Add column activity_custom_11 to the custom table
     $customField =& new CRM_Core_DAO_CustomField();
     $customField->column_name = 'activity_custom_11';
     $customField->custom_group_id = 9;
     $customField->is_required = 0;
     $customField->is_active = 1;
     $customField->data_type = 'String';
     $customField->text_length = 255;
     CRM_Core_BAO_CustomField::createField($customField, 'add');
     //  Insert a test value into the new table
     $query = "INSERT INTO civicrm_value_activity_custom_9" . "( entity_id, activity_custom_11 )" . " VALUES ( 4,  'bite my test data' )";
     AllTests::$utils->do_query($query);
     //  Retrieve the test value
     $params = array('activity_id' => 4, 'activity_type_id' => 5);
     $result = civicrm_activity_get($params, true);
     $this->assertEquals(0, $result['is_error'], "Error message: " . $result['error_message']);
     $this->assertEquals(4, $result['result']['id'], 'In line ' . __LINE__);
     $this->assertEquals(17, $result['result']['source_contact_id'], 'In line ' . __LINE__);
     $this->assertEquals(5, $result['result']['activity_type_id'], 'In line ' . __LINE__);
     $this->assertEquals('test activity type id', $result['result']['subject'], 'In line ' . __LINE__);
     $this->assertEquals('bite my test data', $result['result']['custom_11_1'], 'In line ' . __LINE__);
 }
 /**
  * Test createTable()
  */
 public function testCreateTable()
 {
     $groupParams = array('title' => 'My Custom Group', 'name' => 'my_custom_group', 'style' => 'Tab', 'extends' => 'Individual', 'is_active' => 1, 'version' => 3);
     $customGroupBAO = new CRM_Core_BAO_CustomGroup();
     $customGroupBAO->copyValues($groupParams);
     $customGroup = $customGroupBAO->save();
     $tableName = 'civicrm_value_test_group_' . $customGroup->id;
     $customGroup->table_name = $tableName;
     $customGroup = $customGroupBAO->save();
     CRM_Core_BAO_CustomGroup::createTable($customGroup);
     $customGroupId = $customGroup->id;
     //check db for custom group.
     $dbCustomGroupTitle = $this->assertDBNotNull('CRM_Core_DAO_CustomGroup', $customGroupId, 'title', 'id', 'Database check for custom group record.');
     //check for custom group table name
     $this->assertDBCompareValue('CRM_Core_DAO_CustomGroup', $customGroupId, 'table_name', 'id', $tableName, 'Database check for custom group table name.');
     $this->customGroupDelete($customGroup->id);
 }
Exemple #7
0
 function customGroups(&$xml, &$idMap)
 {
     require_once 'CRM/Core/BAO/CustomGroup.php';
     require_once 'CRM/Utils/String.php';
     foreach ($xml->CustomGroups as $customGroupsXML) {
         foreach ($customGroupsXML->CustomGroup as $customGroupXML) {
             $customGroup = new CRM_Core_DAO_CustomGroup();
             $this->copyData($customGroup, $customGroupXML, true);
             // fix table name
             $customGroup->table_name = "civicrm_value_" . strtolower(CRM_Utils_String::munge($customGroup->title, '_', 32)) . "_{$customGroup->id}";
             $customGroup->save();
             CRM_Core_BAO_CustomGroup::createTable($customGroup);
             $idMap['custom_group'][$customGroup->title] = $customGroup->id;
         }
     }
 }