public function setUp() { parent::setUp(); //create contact subtypes $params = array('label' => 'indivi_student', 'name' => 'indivi_student', 'parent_id' => 1, 'is_active' => 1); $result = CRM_Contact_BAO_ContactType::add($params); $this->student = $params['name']; $params = array('label' => 'indivi_parent', 'name' => 'indivi_parent', 'parent_id' => 1, 'is_active' => 1); $result = CRM_Contact_BAO_ContactType::add($params); $this->parent = $params['name']; $params = array('label' => 'org_sponsor', 'name' => 'org_sponsor', 'parent_id' => 3, 'is_active' => 1); $result = CRM_Contact_BAO_ContactType::add($params); $this->sponsor = $params['name']; //create contacts $params = array('first_name' => 'Anne', 'last_name' => 'Grant', 'contact_type' => 'Individual'); $this->individual = Contact::create($params); $params = array('first_name' => 'Bill', 'last_name' => 'Adams', 'contact_type' => 'Individual', 'contact_sub_type' => $this->student); $this->indivi_student = Contact::create($params); $params = array('first_name' => 'Alen', 'last_name' => 'Adams', 'contact_type' => 'Individual', 'contact_sub_type' => $this->parent); $this->indivi_parent = Contact::create($params); $params = array('organization_name' => 'Compumentor', 'contact_type' => 'Organization'); $this->organization = Contact::create($params); $params = array('organization_name' => 'Conservation Corp', 'contact_type' => 'Organization', 'contact_sub_type' => $this->sponsor); $this->organization_sponsor = Contact::create($params); }
function setUp() { parent::setUp(); $students = 'indivi_student' . substr(sha1(rand()), 0, 7); $params = array('label' => $students, 'name' => $students, 'parent_id' => 1, 'is_active' => 1); $result = CRM_Contact_BAO_ContactType::add($params); $this->student = $params['name']; $parents = 'indivi_parent' . substr(sha1(rand()), 0, 7); $params = array('label' => $parents, 'name' => $parents, 'parent_id' => 1, 'is_active' => 1); $result = CRM_Contact_BAO_ContactType::add($params); $this->parent = $params['name']; $orgs = 'org_sponsor' . substr(sha1(rand()), 0, 7); $params = array('label' => $orgs, 'name' => $orgs, 'parent_id' => 3, 'is_active' => 1); $result = CRM_Contact_BAO_ContactType::add($params); $this->sponsor = $params['name']; $this->indiviParams = array('first_name' => 'Anne', 'last_name' => 'Grant', 'contact_type' => 'Individual'); $this->individual = Contact::create($this->indiviParams); $this->indiviStudentParams = array('first_name' => 'Bill', 'last_name' => 'Adams', 'contact_type' => 'Individual', 'contact_sub_type' => $this->student); $this->indiviStudent = Contact::create($this->indiviStudentParams); $this->indiviParentParams = array('first_name' => 'Alen', 'last_name' => 'Adams', 'contact_type' => 'Individual', 'contact_sub_type' => $this->parent); $this->indiviParent = Contact::create($this->indiviParentParams); $this->organizationParams = array('organization_name' => 'Compumentor', 'contact_type' => 'Organization'); $this->organization = Contact::create($this->organizationParams); $this->orgSponsorParams = array('organization_name' => 'Conservation Corp', 'contact_type' => 'Organization', 'contact_sub_type' => $this->sponsor); $this->orgSponsor = Contact::create($this->orgSponsorParams); $this->householdParams = array('household_name' => "John Doe's home", 'contact_type' => 'Household'); $this->household = Contact::create($this->householdParams); }
/** * Implementation of hook_civicrm_install * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install */ function pcpteams_civicrm_install() { //create custom group from xml file // Create OptionGroup, OptionValues, RelationshipType, CustomGroup and CustomFields $extensionDir = dirname(__FILE__) . DIRECTORY_SEPARATOR; $customDataXMLFile = $extensionDir . '/xml/CustomGroupData.xml'; $import = new CRM_Utils_Migrate_Import(); $import->run($customDataXMLFile); //Create Contact Subtype $params = array('parent_id' => 3, 'is_active' => 1, 'is_reserved' => 0); foreach (array(CRM_Pcpteams_Constant::C_CONTACT_SUB_TYPE_TEAM, CRM_Pcpteams_Constant::C_CONTACTTYPE_IN_MEM, CRM_Pcpteams_Constant::C_CONTACTTYPE_IN_CELEB, CRM_Pcpteams_Constant::C_CONTACTTYPE_BRANCH, CRM_Pcpteams_Constant::C_CONTACTTYPE_PARTNER) as $subTypes) { if (!CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $subTypes, 'id', 'name')) { $params['name'] = $subTypes; $params['label'] = str_replace('_', ' ', $subTypes); CRM_Contact_BAO_ContactType::add($params); } } //set foreignkey $sql = "ALTER TABLE `civicrm_value_pcp_custom_set`\n MODIFY `team_pcp_id` int(10) unsigned DEFAULT NULL,\n ADD CONSTRAINT `FK_civicrm_value_pcp_custom_set_team_pcp_id` FOREIGN KEY (`team_pcp_id`) REFERENCES `civicrm_pcp` (`id`) ON DELETE SET NULL"; CRM_Core_DAO::executeQuery($sql); //set foreignkey for pcp_a_b and pcp_b_a on delete make null $alterSql = "ALTER TABLE `civicrm_value_pcp_relationship_set`\n MODIFY `pcp_a_b` int(10) unsigned DEFAULT NULL, MODIFY `pcp_b_a` int(10) unsigned DEFAULT NULL,\n ADD CONSTRAINT `FK_civicrm_value_pcp_relationship_set_pcp_a_b` FOREIGN KEY (`pcp_a_b`) REFERENCES `civicrm_pcp` (`id`) ON DELETE SET NULL,\n ADD CONSTRAINT `FK_civicrm_value_pcp_relationship_set_pcp_b_a` FOREIGN KEY (`pcp_b_a`) REFERENCES `civicrm_pcp` (`id`) ON DELETE SET NULL\n "; CRM_Core_DAO::executeQuery($alterSql); //invite team $messageHtmlSampleTeamInviteFile = $extensionDir . '/message_templates/msg_tpl_invite_members_to_team.tpl'; $messageHtml = file_get_contents($messageHtmlSampleTeamInviteFile); $message_params['invite_team'] = array('sequential' => 1, 'version' => 3, 'msg_title' => CRM_Pcpteams_Constant::C_MSG_TPL_INVITE_TEAM, 'msg_subject' => (string) '{$inviteeFirstName} you have been invited to join {$teamName} and support Leukaemia and Lymphoma Research', 'is_default' => 1, 'msg_html' => $messageHtml); //join team $messageHtmlSampleTeamInviteFile = $extensionDir . '/message_templates/msg_tpl_join_request_to_team.tpl'; $messageHtml = file_get_contents($messageHtmlSampleTeamInviteFile); $message_params['join_team'] = array('sequential' => 1, 'version' => 3, 'msg_title' => CRM_Pcpteams_Constant::C_MSG_TPL_JOIN_REQUEST, 'msg_subject' => (string) '{$userFirstName} {$userlastName} has requested to join Team {$teamName} please authorise', 'is_default' => 1, 'msg_html' => $messageHtml); //leave team $messageHtmlSampleTeamInviteFile = $extensionDir . '/message_templates/msg_tpl_leave_team.tpl'; $messageHtml = file_get_contents($messageHtmlSampleTeamInviteFile); $message_params['leave_team'] = array('sequential' => 1, 'version' => 3, 'msg_title' => CRM_Pcpteams_Constant::C_MSG_TPL_LEAVE_TEAM, 'msg_subject' => (string) '{$userFirstName} {$userLastName} has decided to leave Team {$teamName}', 'is_default' => 1, 'msg_html' => $messageHtml); //decline join request $messageHtmlSampleTeamInviteFile = $extensionDir . '/message_templates/msg_tpl_decline_request_to_team.tpl'; $messageHtml = file_get_contents($messageHtmlSampleTeamInviteFile); $message_params['decline_team'] = array('sequential' => 1, 'version' => 3, 'msg_title' => CRM_Pcpteams_Constant::C_MSG_TPL_JOIN_REQ_DECLINE_TEAM, 'msg_subject' => (string) '{$userFirstName} {$userLastName} your request to join {$teamName} has been turned down', 'is_default' => 1, 'msg_html' => $messageHtml); //approve join request $messageHtmlSampleTeamInviteFile = $extensionDir . '/message_templates/msg_tpl_approve_request_to_team.tpl'; $messageHtml = file_get_contents($messageHtmlSampleTeamInviteFile); $message_params['decline_team'] = array('sequential' => 1, 'version' => 3, 'msg_title' => CRM_Pcpteams_Constant::C_MSG_TPL_JOIN_REQ_APPROVE_TEAM, 'msg_subject' => (string) '{$userFirstName} {$userLastName} your request to join {$teamName} has been approved', 'is_default' => 1, 'msg_html' => $messageHtml); $ogId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', CRM_Pcpteams_Constant::C_OG_MSG_TPL_WORKFLOW, 'id', 'name'); foreach ($message_params as $key => $message_param) { $opValue = civicrm_api3('OptionValue', 'getsingle', array('version' => 3, 'option_group_id' => $ogId, 'name' => $message_param['msg_title'])); if ($opValue['id']) { $message_param['workflow_id'] = $opValue['id']; } $result = civicrm_api3('MessageTemplate', 'create', $message_param); } return _pcpteams_civix_civicrm_install(); }
public function setUp() { parent::setUp(); $params = array('label' => 'indiv_student', 'name' => 'indiv_student', 'parent_id' => 1, 'is_active' => 1); $result = CRM_Contact_BAO_ContactType::add($params); $this->student = $params['name']; $params = array('label' => 'indiv_parent', 'name' => 'indiv_parent', 'parent_id' => 1, 'is_active' => 1); $result = CRM_Contact_BAO_ContactType::add($params); $this->parent = $params['name']; $params = array('label' => 'org_sponsor', 'name' => 'org_sponsor', 'parent_id' => 3, 'is_active' => 1); $result = CRM_Contact_BAO_ContactType::add($params); $this->sponsor = $params['name']; $params = array('label' => 'org_team', 'name' => 'org_team', 'parent_id' => 3, 'is_active' => 1); $result = CRM_Contact_BAO_ContactType::add($params); $this->team = $params['name']; }
/** * Implementation of hook_civicrm_install * * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_install */ function hrjobcontract_civicrm_install() { $cType = CRM_Contact_BAO_ContactType::basicTypePairs(false, 'id'); $org_id = array_search('Organization', $cType); $sub_type_name = array('Health Insurance Provider', 'Life Insurance Provider'); $orgSubType = CRM_Contact_BAO_ContactType::subTypes('Organization', true); $orgSubType = CRM_Contact_BAO_ContactType::subTypeInfo('Organization'); $params['parent_id'] = $org_id; $params['is_active'] = 1; if ($org_id) { foreach ($sub_type_name as $sub_type_name) { $subTypeName = ucfirst(CRM_Utils_String::munge($sub_type_name)); $subID = array_key_exists($subTypeName, $orgSubType); if (!$subID) { $params['name'] = $subTypeName; $params['label'] = $sub_type_name; CRM_Contact_BAO_ContactType::add($params); } elseif ($subID && $orgSubType[$subTypeName]['is_active'] == 0) { CRM_Contact_BAO_ContactType::setIsActive($orgSubType[$subTypeName]['id'], 1); } } } // Add Job Contract top menu $jobContractNavigation = new CRM_Core_DAO_Navigation(); $jobContractNavigation->name = 'job_contracts'; $jobContractNavigationResult = $jobContractNavigation->find(); if (!$jobContractNavigationResult) { $contactsWeight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Contacts', 'weight', 'name'); $jobContractNavigation = new CRM_Core_DAO_Navigation(); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => ts('Job Contracts'), 'name' => 'job_contracts', 'url' => null, 'operator' => null, 'weight' => $contactsWeight + 1, 'is_active' => 1); $jobContractNavigation->copyValues($params); $jobContractNavigation->save(); $jobContractMenuTree = array(array('label' => ts('Import / Export'), 'name' => 'import_export_job_contracts')); foreach ($jobContractMenuTree as $key => $menuItems) { $menuItems['is_active'] = 1; $menuItems['parent_id'] = $jobContractNavigation->id; $menuItems['weight'] = $key; CRM_Core_BAO_Navigation::add($menuItems); } } return _hrjobcontract_civix_civicrm_install(); }
/** * Implementation of hook_civicrm_install */ function hrjob_civicrm_install() { $cType = CRM_Contact_BAO_ContactType::basicTypePairs(false, 'id'); $org_id = array_search('Organization', $cType); $sub_type_name = array('Health Insurance Provider', 'Life Insurance Provider'); $orgSubType = CRM_Contact_BAO_ContactType::subTypes('Organization', true); $orgSubType = CRM_Contact_BAO_ContactType::subTypeInfo('Organization'); $params['parent_id'] = $org_id; $params['is_active'] = 1; if ($org_id) { foreach ($sub_type_name as $sub_type_name) { $subTypeName = ucfirst(CRM_Utils_String::munge($sub_type_name)); $subID = array_key_exists($subTypeName, $orgSubType); if (!$subID) { $params['name'] = $subTypeName; $params['label'] = $sub_type_name; CRM_Contact_BAO_ContactType::add($params); } elseif ($subID && $orgSubType[$subTypeName]['is_active'] == 0) { CRM_Contact_BAO_ContactType::setIsActive($orgSubType[$subTypeName]['id'], 1); } } } //Add job import navigation menu $weight = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Import Contacts', 'weight', 'name'); $contactNavId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Contacts', 'id', 'name'); $administerNavId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Navigation', 'Dropdown Options', 'id', 'name'); $importJobNavigation = new CRM_Core_DAO_Navigation(); $params = array('domain_id' => CRM_Core_Config::domainID(), 'label' => ts('Import Jobs'), 'name' => 'jobImport', 'url' => null, 'parent_id' => $contactNavId, 'weight' => $weight + 1, 'permission' => 'access HRJobs', 'separator' => 1, 'is_active' => 1); $importJobNavigation->copyValues($params); $importJobNavigation->save(); $importJobMenuTree = array(array('label' => ts('Hours Types'), 'name' => 'hoursType', 'url' => 'civicrm/hour/editoption', 'permission' => 'administer CiviCRM', 'parent_id' => $administerNavId)); foreach ($importJobMenuTree as $key => $menuItems) { $menuItems['is_active'] = 1; CRM_Core_BAO_Navigation::add($menuItems); } CRM_Core_BAO_Navigation::resetNavigation(); return _hrjob_civix_civicrm_install(); }
/** * Test del() with valid data * success expected */ public function testDel() { $params = array('label' => 'indiviSubType', 'name' => 'indiviSubType', 'parent_id' => 1, 'is_active' => 1); $subtype = CRM_Contact_BAO_ContactType::add($params); $del = CRM_Contact_BAO_ContactType::del($subtype->id); $result = CRM_Contact_BAO_ContactType::subTypes(); $this->assertEquals($del, TRUE); $this->assertEquals(in_array($subtype->name, $result), TRUE); }
/** * Process the form submission. */ public function postProcess() { CRM_Utils_System::flushCache(); if ($this->_action & CRM_Core_Action::DELETE) { $isDelete = CRM_Contact_BAO_ContactType::del($this->_id); if ($isDelete) { CRM_Core_Session::setStatus(ts('Selected contact type has been deleted.'), ts('Record Deleted'), 'success'); } else { CRM_Core_Session::setStatus(ts("Selected contact type can not be deleted. Make sure contact type doesn't have any associated custom data or group."), ts('Sorry'), 'error'); } return; } // store the submitted values in an array $params = $this->exportValues(); if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; // Force Enabled = true for built-in contact types to fix problems caused by CRM-6471 (parent_id is NULL for these types) if (is_null($this->_parentId)) { $params['is_active'] = 1; } } if ($this->_action & CRM_Core_Action::ADD) { $params['name'] = ucfirst(CRM_Utils_String::munge($params['label'])); } $contactType = CRM_Contact_BAO_ContactType::add($params); CRM_Core_Session::setStatus(ts("The Contact Type '%1' has been saved.", array(1 => $contactType->label)), ts('Saved'), 'success'); }
function testContactUpdateSubtypeValid() { $params = array('label' => 'sub2_individual', 'name' => 'sub2_individual', 'parent_id' => 1, 'is_active' => 1); $getSubtype = CRM_Contact_BAO_ContactType::add($params); $subtype = $params['name']; // check for Type:Individual subype:sub_individual $contactParams = array('first_name' => 'Anne', 'last_name' => 'Grant', 'contact_type' => 'Individual', 'contact_sub_type' => $this->subTypeIndividual); $contact = $this->callAPISuccess('contact', 'create', $contactParams); // subype:sub2_individual $updateParams = array('id' => $contact['id'], 'first_name' => 'John', 'last_name' => 'Grant', 'contact_id' => $contact['id'], 'contact_type' => 'Individual', 'contact_sub_type' => $subtype); $updateContact = $this->callAPISuccess('contact', 'create', $updateParams); $this->assertEquals($updateContact['id'], $contact['id'], "In line " . __LINE__); $params = array('contact_id' => $contact['id']); $getContacts = $this->callAPISuccess('contact', 'get', $params); $result = $getContacts['values'][$contact['id']]; $this->assertEquals($result['first_name'], $updateParams['first_name'], "In line " . __LINE__); $this->assertEquals($result['last_name'], $updateParams['last_name'], "In line " . __LINE__); $this->assertEquals($result['contact_type'], $updateParams['contact_type'], "In line " . __LINE__); $this->assertEquals(end($result['contact_sub_type']), $updateParams['contact_sub_type'], "In line " . __LINE__); $this->callAPISuccess('contact', 'delete', $params); $params = array('label' => 'sub2_organization', 'name' => 'sub2_organization', 'parent_id' => 3, 'is_active' => 1); $getSubtype = CRM_Contact_BAO_ContactType::add($params); $subtype = $params['name']; // check for Type:Organization subype:sub_organization $contactParams = array('organization_name' => 'Compumentor', 'contact_type' => 'Organization', 'contact_sub_type' => $this->subTypeOrganization); $contact = $this->callAPISuccess('contact', 'create', $contactParams); // subype:sub2_organization $updateParams = array('organization_name' => 'Intel Arts', 'contact_id' => $contact['id'], 'contact_type' => 'Organization', 'contact_sub_type' => $subtype); $updateContact = $this->callAPISuccess('contact', 'create', $updateParams); $this->assertEquals($updateContact['id'], $contact['id'], "In line " . __LINE__); $params = array('contact_id' => $contact['id']); $getContacts = $this->callAPISuccess('contact', 'get', $params); $result = $getContacts['values'][$contact['id']]; $this->assertEquals($result['organization_name'], $updateParams['organization_name'], "In line " . __LINE__); $this->assertEquals($result['contact_type'], $updateParams['contact_type'], "In line " . __LINE__); $this->assertEquals(end($result['contact_sub_type']), $updateParams['contact_sub_type'], "In line " . __LINE__); $this->callAPISuccess('contact', 'delete', $params); }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $isDelete = CRM_Contact_BAO_ContactType::del($this->_id); if ($isDelete) { CRM_Core_Session::setStatus(ts('Selected contact type has been deleted.')); } else { CRM_Core_Session::setStatus(ts('Selected contact type can not be deleted. Make sure contact type doesn\'t have any associated custom data or group.')); } return; } // store the submitted values in an array $params = $this->exportValues(); if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; } if ($this->_action & CRM_Core_Action::ADD) { $params['name'] = ucfirst(CRM_Utils_String::munge($params['label'])); } $contactType = CRM_Contact_BAO_ContactType::add($params); CRM_Core_Session::setStatus(ts("The Contact Type '%1' has been saved.", array(1 => $contactType->label))); }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { $isDelete = CRM_Contact_BAO_ContactType::del($this->_id); if ($isDelete) { CRM_Core_Session::setStatus(ts('Selected Contact Type has been deleted.')); } else { CRM_Core_Session::setStatus(ts('Selected Contact Type can not be deleted.') . '<br/>' . ts('If you want to delete Contact Type ,first delete all custom data related to Type. ')); } return; } // store the submitted values in an array $params = $this->exportValues(); if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; } if ($this->_action & CRM_Core_Action::ADD) { $params['name'] = ucfirst(CRM_Utils_String::munge($params['label'])); } $contactType = CRM_Contact_BAO_ContactType::add($params); CRM_Core_Session::setStatus(ts("The Contact Type '%1' has been saved.", array(1 => $contactType->label))); }
public function upgrade_1108() { $this->ctx->log->info('Applying update 1108'); if (CRM_Core_DAO::checkFieldExists('civicrm_hrjob_health', 'provider') && CRM_Core_DAO::checkFieldExists('civicrm_hrjob_health', 'provider_life_insurance')) { $opt_grp_name = array('hrjob_health_provider' => array('name' => 'Health_Insurance_Provider', 'label' => ts('Health Insurance Provider'), 'column' => 'provider'), 'hrjob_life_provider' => array('name' => 'Life_Insurance_Provider', 'label' => ts('Life Insurance Provider'), 'column' => 'provider_life_insurance')); $org_id = array_search('Organization', CRM_Contact_BAO_ContactType::basicTypePairs(FALSE, 'id')); $orgSubType = CRM_Contact_BAO_ContactType::subTypeInfo('Organization'); foreach ($opt_grp_name as $oKey => $oValue) { $subID = array_key_exists($oValue['name'], $orgSubType); if (!$subID) { CRM_Contact_BAO_ContactType::add(array('parent_id' => $org_id, 'is_active' => 1, 'name' => $oValue['name'], 'label' => $oValue['label'])); } $options = CRM_Core_OptionGroup::values($oKey, TRUE, FALSE); foreach ($options as $orgKey => $orgValue) { $params = array('organization_name' => $orgValue, 'sort_name' => $orgValue, 'display_name' => $orgValue, 'legal_name' => $orgValue, 'contact_type' => 'Organization', 'contact_sub_type' => $oValue['name']); $result = civicrm_api3('contact', 'create', $params); if ($result['id']) { CRM_Core_DAO::executeQuery("UPDATE civicrm_hrjob_health SET {$oValue['column']} = {$result['id']} WHERE {$oValue['column']} LIKE '{$orgValue}'"); CRM_Core_DAO::executeQuery("UPDATE civicrm_hrjob_health SET {$oValue['column']} = NULL WHERE {$oValue['column']} = ''"); } } CRM_Core_OptionGroup::deleteAssoc($oKey); } CRM_Core_DAO::executeQuery("ALTER TABLE `civicrm_hrjob_health`\n MODIFY COLUMN `provider` int(10) unsigned DEFAULT NULL,\n MODIFY COLUMN `provider_life_insurance` int(10) unsigned DEFAULT NULL,\n ADD CONSTRAINT `FK_civicrm_hrjob_health_provider` FOREIGN KEY (`provider`) REFERENCES `civicrm_contact`(`id`) ON DELETE SET NULL,\n ADD CONSTRAINT `FK_civicrm_hrjob_health_provider_life_insurance` FOREIGN KEY (`provider_life_insurance`) REFERENCES `civicrm_contact`(`id`) ON DELETE SET NULL"); } return TRUE; }