public function testCaseType() { CRM_Core_PseudoConstant::flush(); $caseTypes = CRM_Case_PseudoConstant::caseType(); $expectedTypes = array(1 => 'Housing Support', 2 => 'Adult Day Care Referral'); $this->assertEquals($expectedTypes, $caseTypes); }
/** * Class constructor. */ public function __construct() { // don’t display the ‘Add these Contacts to Group’ button $this->_add2groupSupported = FALSE; $dsn = defined('CIVICRM_LOGGING_DSN') ? DB::parseDSN(CIVICRM_LOGGING_DSN) : DB::parseDSN(CIVICRM_DSN); $this->loggingDB = $dsn['database']; // used for redirect back to contact summary $this->cid = CRM_Utils_Request::retrieve('cid', 'Integer', CRM_Core_DAO::$_nullObject); $activityContacts = CRM_Core_OptionGroup::values('activity_contacts', FALSE, FALSE, FALSE, NULL, 'name'); $sourceID = CRM_Utils_Array::key('Activity Source', $activityContacts); $assigneeID = CRM_Utils_Array::key('Activity Assignees', $activityContacts); $targetID = CRM_Utils_Array::key('Activity Targets', $activityContacts); $this->_logTables = array('log_civicrm_contact' => array('fk' => 'id'), 'log_civicrm_email' => array('fk' => 'contact_id', 'log_type' => 'Contact'), 'log_civicrm_phone' => array('fk' => 'contact_id', 'log_type' => 'Contact'), 'log_civicrm_address' => array('fk' => 'contact_id', 'log_type' => 'Contact'), 'log_civicrm_note' => array('fk' => 'entity_id', 'entity_table' => TRUE, 'bracket_info' => array('table' => 'log_civicrm_note', 'column' => 'subject')), 'log_civicrm_note_comment' => array('fk' => 'entity_id', 'table_name' => 'log_civicrm_note', 'joins' => array('table' => 'log_civicrm_note', 'join' => "entity_log_civireport.entity_id = fk_table.id AND entity_log_civireport.entity_table = 'civicrm_note'"), 'entity_table' => TRUE, 'bracket_info' => array('table' => 'log_civicrm_note', 'column' => 'subject')), 'log_civicrm_group_contact' => array('fk' => 'contact_id', 'bracket_info' => array('entity_column' => 'group_id', 'table' => 'log_civicrm_group', 'column' => 'title'), 'action_column' => 'status', 'log_type' => 'Group'), 'log_civicrm_entity_tag' => array('fk' => 'entity_id', 'bracket_info' => array('entity_column' => 'tag_id', 'table' => 'log_civicrm_tag', 'column' => 'name'), 'entity_table' => TRUE), 'log_civicrm_relationship' => array('fk' => 'contact_id_a', 'bracket_info' => array('entity_column' => 'relationship_type_id', 'table' => 'log_civicrm_relationship_type', 'column' => 'label_a_b')), 'log_civicrm_activity_for_target' => array('fk' => 'contact_id', 'table_name' => 'log_civicrm_activity', 'joins' => array('table' => 'log_civicrm_activity_contact', 'join' => "(entity_log_civireport.id = fk_table.activity_id AND fk_table.record_type_id = {$targetID})"), 'bracket_info' => array('entity_column' => 'activity_type_id', 'options' => CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE)), 'log_type' => 'Activity'), 'log_civicrm_activity_for_assignee' => array('fk' => 'contact_id', 'table_name' => 'log_civicrm_activity', 'joins' => array('table' => 'log_civicrm_activity_contact', 'join' => "entity_log_civireport.id = fk_table.activity_id AND fk_table.record_type_id = {$assigneeID}"), 'bracket_info' => array('entity_column' => 'activity_type_id', 'options' => CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE)), 'log_type' => 'Activity'), 'log_civicrm_activity_for_source' => array('fk' => 'contact_id', 'table_name' => 'log_civicrm_activity', 'joins' => array('table' => 'log_civicrm_activity_contact', 'join' => "entity_log_civireport.id = fk_table.activity_id AND fk_table.record_type_id = {$sourceID}"), 'bracket_info' => array('entity_column' => 'activity_type_id', 'options' => CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE)), 'log_type' => 'Activity'), 'log_civicrm_case' => array('fk' => 'contact_id', 'joins' => array('table' => 'log_civicrm_case_contact', 'join' => 'entity_log_civireport.id = fk_table.case_id'), 'bracket_info' => array('entity_column' => 'case_type_id', 'options' => CRM_Case_PseudoConstant::caseType('title', FALSE)))); $logging = new CRM_Logging_Schema(); // build _logTables for contact custom tables $customTables = $logging->entityCustomDataLogTables('Contact'); foreach ($customTables as $table) { $this->_logTables[$table] = array('fk' => 'entity_id', 'log_type' => 'Contact'); } // build _logTables for address custom tables $customTables = $logging->entityCustomDataLogTables('Address'); foreach ($customTables as $table) { $this->_logTables[$table] = array('fk' => 'contact_id', 'joins' => array('table' => 'log_civicrm_address', 'join' => 'entity_log_civireport.entity_id = fk_table.id'), 'log_type' => 'Contact'); } // Allow log tables to be extended via report hooks. CRM_Report_BAO_Hook::singleton()->alterLogTables($this, $this->_logTables); parent::__construct(); }
public function setUp() { parent::setUp(); // create a logged in USER since the code references it for source_contact_id $this->createLoggedInUser(); $caseTypes = CRM_Case_PseudoConstant::caseType(); self::mocktest($caseTypes); }
/** * Constructor method */ function __construct() { $this->_caseTypes = CRM_Case_PseudoConstant::caseType(); $this->_caseStatus = CRM_Case_PseudoConstant::caseStatus(); $this->setUserSelectList(); $this->_deletedLabels = array('' => ts('- select -'), 0 => ts('No'), 1 => ts('Yes')); $this->_columns = array('pum_main' => array('fields' => array('case_id' => array('no_display' => TRUE, 'required' => TRUE), 'customer_name' => array('name' => 'customer_name', 'title' => ts('Client'), 'required' => TRUE), 'customer_id' => array('name' => 'customer_id', 'no_display' => TRUE, 'required' => TRUE), 'country_name' => array('name' => 'country_name', 'title' => ts('Country'), 'default' => TRUE), 'representative' => array('name' => 'representative', 'title' => ts('Representative'), 'default' => TRUE), 'representative_id' => array('name' => 'representative_id', 'no_display' => TRUE, 'required' => TRUE), 'case_type' => array('name' => 'case_type_id', 'title' => ts('Case Type'), 'default' => TRUE), 'case_status' => array('name' => 'case_status_id', 'title' => ts('Case Status'), 'default' => TRUE), 'expert' => array('name' => 'expert', 'title' => ts('Expert'), 'default' => TRUE), 'expert_id' => array('name' => 'expert_id', 'no_display' => TRUE, 'required' => TRUE), 'start_date' => array('name' => 'start_date', 'title' => ts('Activity Start Date'), 'default' => TRUE), 'end_date' => array('name' => 'end_date', 'title' => ts('Activity End Date'), 'default' => TRUE), 'ma_expert_approval' => array('name' => 'ma_expert_approval', 'title' => ts('Expert approves Main. Act'), 'default' => TRUE), 'pq_approved_sc' => array('name' => 'pq_approved_sc', 'title' => ts('PQ approved by SC'), 'default' => TRUE), 'pq_approved_cc' => array('name' => 'pq_approved_cc', 'title' => ts('PQ approved by CC'), 'default' => TRUE), 'cust_approves_expert' => array('name' => 'cust_approves_expert', 'title' => ts('Customer approves Expert'), 'default' => TRUE), 'briefing_date' => array('name' => 'briefing_date', 'title' => ts('Briefing Date'), 'default' => TRUE), 'briefing_status' => array('name' => 'briefing_status', 'title' => ts('Briefing Status'), 'default' => TRUE)), 'filters' => array('user_id' => array('title' => ts('Main Activities for User'), 'default' => 0, 'pseudofield' => 1, 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => $this->_userSelectList), 'case_type_id' => array('title' => ts('Case Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->_caseTypes), 'case_status_id' => array('title' => ts('Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->_caseStatus)), 'order_bys' => array('start_date' => array('title' => ts('Activity Start Date'), 'name' => 'start_date', 'default' => 1))), 'case_status_weight' => array('dao' => 'CRM_Core_DAO_OptionValue', 'fields' => array('case_status_label' => array('name' => 'label', 'no_display' => TRUE, 'required' => TRUE), 'weight' => array('no_display' => TRUE, 'required' => TRUE)), 'order_bys' => array('case_status_label' => array('title' => ts('Case Status'), 'name' => 'label', 'default' => 1)))); parent::__construct(); }
/** */ public function __construct() { $this->case_types = CRM_Case_PseudoConstant::caseType(); $this->case_statuses = CRM_Core_OptionGroup::values('case_status'); $rels = CRM_Core_PseudoConstant::relationshipType(); foreach ($rels as $relid => $v) { $this->rel_types[$relid] = $v['label_b_a']; } $this->deleted_labels = array('' => ts('- select -'), 0 => ts('No'), 1 => ts('Yes')); $this->_columns = array('civicrm_c2' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('client_name' => array('name' => 'sort_name', 'title' => ts('Client'), 'required' => TRUE), 'id' => array('no_display' => TRUE, 'required' => TRUE))), 'civicrm_case' => array('dao' => 'CRM_Case_DAO_Case', 'fields' => array('id' => array('title' => ts('Case ID'), 'required' => TRUE), 'subject' => array('title' => ts('Case Subject'), 'default' => TRUE), 'status_id' => array('title' => ts('Status'), 'default' => TRUE), 'case_type_id' => array('title' => ts('Case Type'), 'default' => TRUE), 'start_date' => array('title' => ts('Start Date'), 'default' => TRUE, 'type' => CRM_Utils_Type::T_DATE), 'end_date' => array('title' => ts('End Date'), 'default' => TRUE, 'type' => CRM_Utils_Type::T_DATE), 'duration' => array('title' => ts('Duration (Days)'), 'default' => FALSE), 'is_deleted' => array('title' => ts('Deleted?'), 'default' => FALSE, 'type' => CRM_Utils_Type::T_INT)), 'filters' => array('start_date' => array('title' => ts('Start Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'end_date' => array('title' => ts('End Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'case_type_id' => array('title' => ts('Case Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Case_BAO_Case::buildOptions('case_type_id', 'search')), 'status_id' => array('title' => ts('Status'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Case_BAO_Case::buildOptions('status_id', 'search')), 'is_deleted' => array('title' => ts('Deleted?'), 'type' => CRM_Report_Form::OP_INT, 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => $this->deleted_labels, 'default' => 0))), 'civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('sort_name' => array('title' => ts('Staff Member'), 'default' => TRUE)), 'filters' => array('sort_name' => array('title' => ts('Staff Member')))), 'civicrm_relationship' => array('dao' => 'CRM_Contact_DAO_Relationship', 'filters' => array('relationship_type_id' => array('title' => ts('Staff Relationship'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->rel_types))), 'civicrm_relationship_type' => array('dao' => 'CRM_Contact_DAO_RelationshipType', 'fields' => array('label_b_a' => array('title' => ts('Relationship'), 'default' => TRUE))), 'civicrm_case_contact' => array('dao' => 'CRM_Case_DAO_CaseContact')); parent::__construct(); }
function __construct() { $this->case_statuses = CRM_Case_PseudoConstant::caseStatus(); $this->case_types = CRM_Case_PseudoConstant::caseType(); $rels = CRM_Core_PseudoConstant::relationshipType(); foreach ($rels as $relid => $v) { $this->rel_types[$relid] = $v['label_b_a']; } $this->_columns = array('civicrm_case' => array('dao' => 'CRM_Case_DAO_Case', 'fields' => array('id' => array('title' => ts('Case ID'), 'no_display' => true, 'required' => true), 'subject' => array('title' => ts('Subject'), 'required' => true), 'start_date' => array('title' => ts('Start Date')), 'end_date' => array('title' => ts('End Date')), 'status_id' => array('title' => ts('Case Status')), 'case_type_id' => array('title' => ts('Case Type'))), 'filters' => array('start_date' => array('title' => ts('Start Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'end_date' => array('title' => ts('End Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'status_id' => array('title' => ts('Case Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->case_statuses), 'case_type_id' => array('title' => ts('Case Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->case_types))), 'civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('display_name' => array('title' => ts('Client Name'), 'required' => true), 'id' => array('no_display' => true, 'required' => true)), 'filters' => array('display_name' => array('title' => ts('Client Name')))), 'civicrm_relationship' => array('dao' => 'CRM_Contact_DAO_Relationship', 'fields' => array('relationship_type_id' => array('title' => ts('Case Role'))), 'filters' => array('relationship_type_id' => array('title' => ts('Case Role'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->rel_types))), 'civicrm_relationship_type' => array('dao' => 'CRM_Contact_DAO_RelationshipType'), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => true)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => true)), 'grouping' => 'contact-fields'), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'fields' => array('street_address' => null, 'state_province_id' => array('title' => ts('State/Province')), 'country_id' => array('title' => ts('Country'))), 'grouping' => 'contact-fields', 'filters' => array('country_id' => array('title' => ts('Country'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::country()), 'state_province_id' => array('title' => ts('State/Province'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::stateProvince()))), 'civicrm_worldregion' => array('dao' => 'CRM_Core_DAO_Worldregion', 'filters' => array('worldregion_id' => array('name' => 'id', 'title' => ts('WorldRegion'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::worldRegion()))), 'civicrm_country' => array('dao' => 'CRM_Core_DAO_Country'), 'civicrm_activity' => array('dao' => 'CRM_Activity_DAO_Activity', 'fields' => array('activity_subject' => array('name' => 'subject', 'title' => ts('Activity Subject'), 'no_display' => true)), 'filters' => array('activity_date_time' => array('title' => ts('Last Action Date'), 'operatorType' => CRM_Report_Form::OP_DATE))), 'civicrm_case_contact' => array('dao' => 'CRM_Case_DAO_CaseContact')); $this->_options = array('my_cases' => array('title' => ts('My Cases'), 'type' => 'checkbox')); parent::__construct(); }
/** * */ function __construct() { $this->case_statuses = CRM_Case_PseudoConstant::caseStatus(); $this->case_types = CRM_Case_PseudoConstant::caseType(); $rels = CRM_Core_PseudoConstant::relationshipType(); foreach ($rels as $relid => $v) { $this->rel_types[$relid] = $v['label_b_a']; } $this->deleted_labels = array('' => ts('- select -'), 0 => ts('No'), 1 => ts('Yes')); $this->caseActivityTypes = array(); foreach (CRM_Case_PseudoConstant::caseActivityType() as $typeDetail) { $this->caseActivityTypes[$typeDetail['id']] = $typeDetail['label']; } $this->_columns = array('civicrm_case' => array('dao' => 'CRM_Case_DAO_Case', 'fields' => array('id' => array('title' => ts('Case ID'), 'no_display' => TRUE, 'required' => TRUE), 'subject' => array('title' => ts('Subject'), 'required' => TRUE), 'start_date' => array('title' => ts('Start Date'), 'type' => CRM_Utils_Type::T_DATE), 'end_date' => array('title' => ts('End Date'), 'type' => CRM_Utils_Type::T_DATE), 'status_id' => array('title' => ts('Case Status')), 'case_type_id' => array('title' => ts('Case Type')), 'is_deleted' => array('title' => ts('Deleted?'), 'default' => FALSE, 'type' => CRM_Utils_Type::T_INT)), 'filters' => array('start_date' => array('title' => ts('Start Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'end_date' => array('title' => ts('End Date'), 'operatorType' => CRM_Report_Form::OP_DATE, 'type' => CRM_Utils_Type::T_DATE), 'status_id' => array('title' => ts('Case Status'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->case_statuses), 'case_type_id' => array('title' => ts('Case Type'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->case_types), 'is_deleted' => array('title' => ts('Deleted?'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_SELECT, 'options' => $this->deleted_labels, 'default' => 0))), 'civicrm_contact' => array('dao' => 'CRM_Contact_DAO_Contact', 'fields' => array('client_sort_name' => array('name' => 'sort_name', 'title' => ts('Client Name'), 'required' => TRUE), 'id' => array('no_display' => TRUE, 'required' => TRUE)), 'filters' => array('sort_name' => array('title' => ts('Client Name')))), 'civicrm_relationship' => array('dao' => 'CRM_Contact_DAO_Relationship', 'fields' => array('case_role' => array('name' => 'relationship_type_id', 'title' => ts('Case Role(s)'))), 'filters' => array('case_role' => array('name' => 'relationship_type_id', 'title' => ts('Case Role(s)'), 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => $this->rel_types))), 'civicrm_email' => array('dao' => 'CRM_Core_DAO_Email', 'fields' => array('email' => array('title' => ts('Email'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_phone' => array('dao' => 'CRM_Core_DAO_Phone', 'fields' => array('phone' => array('title' => ts('Phone'), 'no_repeat' => TRUE)), 'grouping' => 'contact-fields'), 'civicrm_address' => array('dao' => 'CRM_Core_DAO_Address', 'fields' => array('street_address' => NULL, 'state_province_id' => array('title' => ts('State/Province')), 'country_id' => array('title' => ts('Country'))), 'grouping' => 'contact-fields', 'filters' => array('country_id' => array('title' => ts('Country'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::country()), 'state_province_id' => array('title' => ts('State/Province'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::stateProvince()))), 'civicrm_worldregion' => array('dao' => 'CRM_Core_DAO_Worldregion', 'filters' => array('worldregion_id' => array('name' => 'id', 'title' => ts('WorldRegion'), 'type' => CRM_Utils_Type::T_INT, 'operatorType' => CRM_Report_Form::OP_MULTISELECT, 'options' => CRM_Core_PseudoConstant::worldRegion()))), 'civicrm_country' => array('dao' => 'CRM_Core_DAO_Country'), 'civicrm_activity_last' => array('dao' => 'CRM_Activity_DAO_Activity', 'filters' => array('last_activity_date_time' => array('name' => 'activity_date_time', 'title' => ts('Last Action Date'), 'operatorType' => CRM_Report_Form::OP_DATE)), 'alias' => 'civireport_activity_last'), 'civicrm_activity_last_completed' => array('dao' => 'CRM_Activity_DAO_Activity', 'fields' => array('last_completed_activity_subject' => array('name' => 'subject', 'title' => ts('Subject of the last completed activity in the case')), 'last_completed_activity_type' => array('name' => 'activity_type_id', 'title' => ts('Activity type of the last completed activity'))))); $this->_options = array('my_cases' => array('title' => ts('My Cases'), 'type' => 'checkbox')); parent::__construct(); }
/** * Implementation of hook_civicrm_uninstall */ function hrcaseutils_civicrm_uninstall() { //delete all activity type CRM_Core_DAO::executeQuery("DELETE FROM civicrm_option_value WHERE name IN ('Interview Prospect', 'Background_Check', 'ID badge')"); $caseTypes = CRM_Case_PseudoConstant::caseType('name', FALSE); $value = array_search('Hrdata', $caseTypes); //Delete cases and related contact of type Hrdata on uninstall if ($value) { $caseDAO = new CRM_Case_DAO_Case(); $caseDAO->case_type_id = $value; $caseDAO->find(); while ($caseDAO->fetch()) { CRM_Case_BAO_Case::deleteCase($caseDAO->id); } } return _hrcaseutils_civix_civicrm_uninstall(); }
/** * Internal function to format create params for processing. * * @param array $params */ function _civicrm_api3_case_format_params(&$params) { // figure out case type id from case type and vice-versa $caseTypes = CRM_Case_PseudoConstant::caseType('name', FALSE); if (empty($params['case_type_id'])) { $params['case_type_id'] = array_search($params['case_type'], $caseTypes); // DEPRECATED: lookup by label for backward compatibility if (!$params['case_type_id']) { $caseTypeLabels = CRM_Case_PseudoConstant::caseType('title', FALSE); $params['case_type_id'] = array_search($params['case_type'], $caseTypeLabels); $params['case_type'] = $caseTypes[$params['case_type_id']]; } } elseif (empty($params['case_type'])) { $params['case_type'] = $caseTypes[$params['case_type_id']]; } }
function addVacancies($cid) { //sample data for HRRecruitment table $grpParams['name'] = 'vacancy_status'; $optionValues = $vacancyPermissionContactIds = array(); $caseStatuses = CRM_Core_OptionGroup::values('case_status', FALSE, FALSE, FALSE, " AND grouping = 'Vacancy'"); $vacancyStatuses = CRM_Core_OptionGroup::values('vacancy_status'); //Filterout Rejected and Cancelled status while creating vacancy foreach (array('Cancelled', 'Rejected') as $status) { $key = array_search($status, $vacancyStatuses); unset($vacancyStatuses[$key]); } $totalcount = 6; $setNewVacancy = FALSE; $templatePosition = array(); $randomVacancies = $this->randomVacancy(); for ($i = 1; $i <= $totalcount; $i++) { $jobCount = mt_rand(0, 2); $position = $randomVacancies[$jobCount]['position']; $vacanciesValues = array('salary' => $randomVacancies[$jobCount]['salary'], 'position' => $position, 'description' => $this->randomItem('vacancydescription'), 'benefits' => $randomVacancies[$jobCount]['benefits'], 'requirements' => $randomVacancies[$jobCount]['requirements'], 'location' => $this->randomItem('location'), 'is_template' => mt_rand(0, 1), 'status_id' => array_rand($vacancyStatuses, 1), 'start_date' => $this->randomDate('20130701', '20140101', 'YmdHis'), 'end_date' => $this->randomDate('20140102', '20151231', 'YmdHis'), 'created_id' => $cid, 'created_date' => $this->randomDate()); if ($vacanciesValues['is_template'] == 1) { unset($vacanciesValues['status_id']); if (array_key_exists($position, $templatePosition)) { //always create distict template continue; } $templatePosition[$position] = NULL; } else { $setNewVacancy = TRUE; } //ensure that atleast there is one vacancy not all template if (!$setNewVacancy && $i == $totalcount) { $totalcount++; } $hrVacancies[] = $this->insertVacancyData('CRM_HRRecruitment_DAO_HRVacancy', $vacanciesValues); } //There are 6 sample Vacancies created, next is to create Entities - VacancyStage, VacancyPermission, Cases foreach ($hrVacancies as $key => $hrVacanciesObj) { $selectedCaseStatuses = array(); $lastSelectedCaseStatus = NULL; $randCaseStatus = $caseStatuses; //Igonre Apply and Hired statuses while removing random status $ignoreCaseStatus = array(array_search('Apply', $randCaseStatus), array_search('Hired', $randCaseStatus)); for ($i = 1; $i <= mt_rand(1, 6); $i++) { $randomValue = array_rand($randCaseStatus, 1); if (in_array($randomValue, $ignoreCaseStatus)) { continue; } unset($randCaseStatus[$randomValue]); } $count = 1; foreach ($randCaseStatus as $caseStatus => $dontCare) { $vacancyStagesValues = array('case_status_id' => $caseStatus, 'vacancy_id' => $hrVacanciesObj->id, 'weight' => $count); $count++; $this->insertVacancyData('CRM_HRRecruitment_DAO_HRVacancyStage', $vacancyStagesValues); } //sample data for HRPermission table $vacancyPermissionContactIds[$hrVacanciesObj->id][] = $hrVacanciesObj->created_id; for ($i = 1; $i <= mt_rand(1, 4); $i++) { $vacancyPermissionValues = array('contact_id' => $this->randomContact(), 'vacancy_id' => $hrVacanciesObj->id, 'permission' => $this->randomItem('permission')); if ($vacancyPermissionValues['permission'] == 'manage Applicants' || $vacancyPermissionValues['permission'] == 'administer Vacancy') { $vacancyPermissionContactIds[$hrVacanciesObj->id][] = $vacancyPermissionValues['contact_id']; } $this->insertVacancyData('CRM_HRRecruitment_DAO_HRVacancyPermission', $vacancyPermissionValues); } foreach (array('application_profile', 'evaluation_profile') as $profileName) { $ufgID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', $profileName, 'id', 'name'); $vacancyUFJoinValues = array('module' => 'Vacancy', 'entity_id' => $hrVacanciesObj->id, 'entity_table' => 'civicrm_hrvacancy', 'uf_group_id' => $ufgID, 'module_data' => $profileName); $this->insertVacancyData('CRM_Core_DAO_UFJoin', $vacancyUFJoinValues); $caseTypes = CRM_Case_PseudoConstant::caseType('name', 1, 'AND filter = 1'); if (!$hrVacanciesObj->is_template) { for ($i = 1; $i <= mt_rand(1, 4); $i++) { $applicantID = $this->randomContact(); $caseParams['case_type_id'] = CRM_Utils_Array::key('Application', $caseTypes); $caseParams['start_date'] = $this->randomDate($hrVacanciesObj->start_date, $hrVacanciesObj->end_date); $caseParams['status_id'] = array_rand($randCaseStatus, 1); $caseObj = CRM_Case_BAO_Case::create($caseParams); $contactParams = array('case_id' => $caseObj->id, 'contact_id' => $applicantID); CRM_Case_BAO_Case::addCaseToContact($contactParams); $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $xmlProcessorParams = array('clientID' => $applicantID, 'creatorID' => $cid, 'standardTimeline' => 1, 'activityTypeName' => 'Open Case', 'caseID' => $caseObj->id, 'activity_date_time' => $caseParams['start_date']); $xmlProcessor->run('Application', $xmlProcessorParams); $aTypes = $xmlProcessor->get('Application', 'ActivityTypes'); $aTypes = array_rand(array_flip($aTypes), mt_rand(2, 5)); foreach ($aTypes as $aType) { if (in_array($aType, array('Open Case', 'Assign Case Role', 'Link Cases'))) { continue; } $index = array_rand($vacancyPermissionContactIds[$hrVacanciesObj->id], 1); $aParam = array('source_contact_id' => $vacancyPermissionContactIds[$hrVacanciesObj->id][$index], 'activity_date_time' => $this->randomDate($hrVacanciesObj->start_date, $hrVacanciesObj->end_date, 'YmdHis'), 'activity_type_id' => $aType, 'status_id' => CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name')); if ($aType == 'Change Case Status') { $aParam['last_status'] = $caseStatuses[$caseObj->status_id]; $caseObj->status_id = array_rand($caseStatuses, 1); $caseObj->save(); $aParam['new_status'] = $caseStatuses[$caseObj->status_id]; } $this->addActivityParamByType($aType, $aParam); $result = civicrm_api3('Activity', 'create', $aParam); $caseActivityParams = array('case_id' => $caseObj->id, 'activity_id' => $result['id']); CRM_Case_BAO_Case::processCaseActivity($caseActivityParams); } $cgID = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', 'application_case', 'id', 'name'); $result = civicrm_api3('CustomField', 'get', array('custom_group_id' => $cgID, 'name' => 'vacancy_id')); civicrm_api3('custom_value', 'create', array("custom_{$result['id']}" => $hrVacanciesObj->id, 'entity_id' => $caseObj->id)); } } } } }
/** * Function to process the form * * @access public * * @return None */ public function postProcess() { $tx = new CRM_Core_Transaction(); // check if dedupe button, if so return. $buttonName = $this->controller->getButtonName(); if (isset($this->_dedupeButtonName) && $buttonName == $this->_dedupeButtonName) { return; } if ($this->_action & CRM_Core_Action::DELETE) { $statusMsg = NULL; $caseDelete = CRM_Case_BAO_Case::deleteCase($this->_caseId, TRUE); if ($caseDelete) { $statusMsg = ts('The selected case has been moved to the Trash. You can view and / or restore deleted cases by checking the "Deleted Cases" option under Find Cases.<br />'); } CRM_Core_Session::setStatus($statusMsg); return; } if ($this->_action & CRM_Core_Action::RENEW) { $statusMsg = NULL; $caseRestore = CRM_Case_BAO_Case::restoreCase($this->_caseId); if ($caseRestore) { $statusMsg = ts('The selected case has been restored.<br />'); } CRM_Core_Session::setStatus($statusMsg); return; } // store the submitted values in an array $params = $this->controller->exportValues($this->_name); $params['now'] = date("Ymd"); // 1. call begin post process if ($this->_activityTypeFile) { eval("CRM_Case_Form_Activity_{$this->_activityTypeFile}" . "::beginPostProcess( \$this, \$params );"); } if (CRM_Utils_Array::value('hidden_custom', $params) && !isset($params['custom'])) { $customFields = array(); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, NULL, 'Case'); } // 2. create/edit case if (CRM_Utils_Array::value('case_type_id', $params)) { $caseType = CRM_Case_PseudoConstant::caseType('name'); $params['case_type'] = $caseType[$params['case_type_id']]; $params['subject'] = $params['activity_subject']; $params['case_type_id'] = CRM_Core_DAO::VALUE_SEPARATOR . $params['case_type_id'] . CRM_Core_DAO::VALUE_SEPARATOR; } $caseObj = CRM_Case_BAO_Case::create($params); $params['case_id'] = $caseObj->id; // unset any ids, custom data unset($params['id'], $params['custom']); // add tags if exists $tagParams = array(); if (!empty($params['tag'])) { $tagParams = array(); foreach ($params['tag'] as $tag) { $tagParams[$tag] = 1; } } CRM_Core_BAO_EntityTag::create($tagParams, 'civicrm_case', $caseObj->id); //save free tags if (isset($params['case_taglist']) && !empty($params['case_taglist'])) { CRM_Core_Form_Tag::postProcess($params['case_taglist'], $caseObj->id, 'civicrm_case', $this); } // user context $url = CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseObj->id}"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); // 3. format activity custom data if (CRM_Utils_Array::value('hidden_custom', $params)) { $customFields = CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, $this->_activityTypeId); $customFields = CRM_Utils_Array::crmArrayMerge($customFields, CRM_Core_BAO_CustomField::getFields('Activity', FALSE, FALSE, NULL, NULL, TRUE)); $params['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, $this->_activityId, 'Activity'); } // 4. call end post process if ($this->_activityTypeFile) { eval("CRM_Case_Form_Activity_{$this->_activityTypeFile}" . "::endPostProcess( \$this, \$params );"); } // 5. auto populate activites // 6. set status CRM_Core_Session::setStatus("{$params['statusMsg']}"); }
/** * Function to process the form * * @access public * * @return None */ static function endPostProcess(&$form, &$params, $activity) { if (!$form->_caseId) { // always expecting a change, so case-id is a must. return; } $caseTypes = CRM_Case_PseudoConstant::caseType('name'); $allCaseTypes = CRM_Case_PseudoConstant::caseType('label', FALSE); if (CRM_Utils_Array::value($params['case_type_id'], $caseTypes)) { $caseType = $caseTypes[$params['case_type_id']]; } if (!$form->_currentlyViewedContactId || !$form->_currentUserId || !$params['case_type_id'] || !$caseType) { CRM_Core_Error::fatal('Required parameter missing for ChangeCaseType - end post processing'); } $params['status_id'] = CRM_Core_OptionGroup::getValue('activity_status', 'Completed', 'name'); $activity->status_id = $params['status_id']; $params['priority_id'] = CRM_Core_OptionGroup::getValue('priority', 'Normal', 'name'); $activity->priority_id = $params['priority_id']; if ($activity->subject == 'null') { $activity->subject = ts('Case type changed from %1 to %2', array(1 => CRM_Utils_Array::value($form->_defaults['case_type_id'], $allCaseTypes), 2 => CRM_Utils_Array::value($params['case_type_id'], $allCaseTypes))); $activity->save(); } // 1. initiate xml processor $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $xmlProcessorParams = array('clientID' => $form->_currentlyViewedContactId, 'creatorID' => $form->_currentUserId, 'standardTimeline' => 1, 'activityTypeName' => 'Change Case Type', 'activity_date_time' => CRM_Utils_Array::value('reset_date_time', $params), 'caseID' => $form->_caseId, 'resetTimeline' => CRM_Utils_Array::value('is_reset_timeline', $params)); $xmlProcessor->run($caseType, $xmlProcessorParams); // status msg $params['statusMsg'] = ts('Case Type changed successfully.'); }
/** * Run some sanity checks. * * This could become a hook so that CiviCRM can run both built-in * configuration & sanity checks, and modules/extensions can add * their own checks. * * We might even expose the results of these checks on the Wordpress * plugin status page or the Drupal admin/reports/status path. * * @return array * Array of messages * @link https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_requirements */ public function checkAll() { $checks = array(); $checks[] = new CRM_Utils_Check_Security(); $checks[] = new CRM_Utils_Check_Env(); $compInfo = CRM_Core_Component::getEnabledComponents(); foreach ($compInfo as $compObj) { switch ($compObj->info['name']) { case 'CiviCase': $checks[] = new CRM_Utils_Check_Case(CRM_Case_XMLRepository::singleton(), CRM_Case_PseudoConstant::caseType('name')); break; default: } } $messages = array(); foreach ($checks as $check) { $messages = array_merge($messages, $check->checkAll()); } CRM_Utils_Hook::check($messages); return $messages; }
/** * @param CRM_Case_XMLRepository $xmlRepo * @param array <string> $caseTypeNames */ public function __construct() { $this->caseTypeNames = CRM_Case_PseudoConstant::caseType('name'); $this->xmlRepo = CRM_Case_XMLRepository::singleton(); }
/** * Build the form object. * * @return void */ public function preProcess() { $this->_caseId = CRM_Utils_Request::retrieve('id', 'Positive', $this); $this->_currentlyViewedContactId = CRM_Utils_Request::retrieve('cid', 'Positive', $this); if ($this->_action & CRM_Core_Action::ADD && !$this->_currentlyViewedContactId) { // check for add contacts permissions if (!CRM_Core_Permission::check('add contacts')) { CRM_Utils_System::permissionDenied(); return; } } //CRM-4418 if (!CRM_Core_Permission::checkActionPermission('CiviCase', $this->_action)) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); } if ($this->_action & CRM_Core_Action::DELETE || $this->_action & CRM_Core_Action::RENEW) { return TRUE; } if (!$this->_caseId) { $caseAttributes = array('case_type' => CRM_Case_PseudoConstant::caseType(), 'case_status' => CRM_Case_PseudoConstant::caseStatus(), 'encounter_medium' => CRM_Case_PseudoConstant::encounterMedium()); foreach ($caseAttributes as $key => $values) { if (empty($values)) { CRM_Core_Error::fatal(ts('You do not have any active %1', array(1 => str_replace('_', ' ', $key)))); break; } } } if ($this->_action & CRM_Core_Action::ADD) { $this->_activityTypeId = CRM_Core_OptionGroup::getValue('activity_type', 'Open Case', 'name'); if (!$this->_activityTypeId) { CRM_Core_Error::fatal(ts('The Open Case activity type is missing or disabled. Please have your site administrator check Administer > Option Lists > Activity Types for the CiviCase component.')); } } //check for case permissions. if (!CRM_Case_BAO_Case::accessCiviCase()) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } if ($this->_action & CRM_Core_Action::ADD && (!CRM_Core_Permission::check('access all cases and activities') && !CRM_Core_Permission::check('add cases'))) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } if ($this->_activityTypeFile = CRM_Activity_BAO_Activity::getFileForActivityTypeId($this->_activityTypeId, 'Case')) { $this->assign('activityTypeFile', $this->_activityTypeFile); } $details = CRM_Case_PseudoConstant::caseActivityType(FALSE); CRM_Utils_System::setTitle($details[$this->_activityTypeId]['label']); $this->assign('activityType', $details[$this->_activityTypeId]['label']); $this->assign('activityTypeDescription', $details[$this->_activityTypeId]['description']); if (isset($this->_currentlyViewedContactId)) { $contact = new CRM_Contact_DAO_Contact(); $contact->id = $this->_currentlyViewedContactId; if (!$contact->find(TRUE)) { CRM_Core_Error::statusBounce(ts('Client contact does not exist: %1', array(1 => $this->_currentlyViewedContactId))); } $this->assign('clientName', $contact->display_name); } $session = CRM_Core_Session::singleton(); $this->_currentUserId = $session->get('userID'); //when custom data is included in this page CRM_Custom_Form_CustomData::preProcess($this, NULL, $this->_activityTypeId, 1, 'Activity'); $className = "CRM_Case_Form_Activity_{$this->_activityTypeFile}"; $className::preProcess($this); $activityGroupTree = $this->_groupTree; // for case custom fields to populate with defaults if (!empty($_POST['hidden_custom'])) { CRM_Custom_Form_CustomData::preProcess($this); CRM_Custom_Form_CustomData::buildQuickForm($this); } // so that grouptree is not populated with case fields, since the grouptree is used // for populating activity custom fields. $this->_groupTree = $activityGroupTree; }
/** * @throws \CiviCRM_API3_Exception */ public function caseDetails() { $caseId = CRM_Utils_Type::escape($_GET['caseId'], 'Positive'); $case = civicrm_api3('Case', 'getsingle', array('id' => $caseId, 'check_permissions' => TRUE, 'return' => array('subject', 'case_type_id', 'status_id', 'start_date', 'end_date'))); $caseStatuses = CRM_Case_PseudoConstant::caseStatus(); $caseTypes = CRM_Case_PseudoConstant::caseType('title', FALSE); $caseDetails = "<table><tr><td>" . ts('Case Subject') . "</td><td>{$case['subject']}</td></tr>\n <tr><td>" . ts('Case Type') . "</td><td>{$caseTypes[$case['case_type_id']]}</td></tr>\n <tr><td>" . ts('Case Status') . "</td><td>{$caseStatuses[$case['status_id']]}</td></tr>\n <tr><td>" . ts('Case Start Date') . "</td><td>" . CRM_Utils_Date::customFormat($case['start_date']) . "</td></tr>\n <tr><td>" . ts('Case End Date') . "</td><td></td></tr>" . CRM_Utils_Date::customFormat($case['end_date']) . "</table>"; if (CRM_Utils_Array::value('snippet', $_GET) == 'json') { CRM_Core_Page_AJAX::returnJsonResponse($caseDetails); } echo $caseDetails; CRM_Utils_System::civiExit(); }
/** * Run all system checks. * * This functon is wrapped by the System.check api. * * Calls hook_civicrm_check() for extensions to add or modify messages. * @link http://wiki.civicrm.org/confluence/display/CRMDOC/hook_civicrm_check * * @param bool $max * Whether to return just the maximum non-hushed severity * * @return array * Array of CRM_Utils_Check_Message objects */ public static function checkAll($max = FALSE) { $checks = array(); $checks[] = new CRM_Utils_Check_Security(); $checks[] = new CRM_Utils_Check_Env(); $compInfo = CRM_Core_Component::getEnabledComponents(); foreach ($compInfo as $compObj) { switch ($compObj->info['name']) { case 'CiviCase': $checks[] = new CRM_Utils_Check_Case(CRM_Case_XMLRepository::singleton(), CRM_Case_PseudoConstant::caseType('name')); break; default: } } $messages = array(); foreach ($checks as $check) { $messages = array_merge($messages, $check->checkAll()); } CRM_Utils_Hook::check($messages); uasort($messages, array(__CLASS__, 'severitySort')); $maxSeverity = 1; foreach ($messages as $message) { if (!$message->isVisible()) { continue; } $maxSeverity = max(1, $message->getLevel()); break; } Civi::settings()->set('systemStatusCheckResult', $maxSeverity); return $max ? $maxSeverity : $messages; }
/** * Function to process the form * * @access public * @return None */ public function endPostProcess(&$form, &$params) { if (!$form->_caseId) { // always expecting a change, so case-id is a must. return; } $caseTypes = CRM_Case_PseudoConstant::caseType('name'); if (CRM_Utils_Array::value($params['case_type_id'], $caseTypes)) { $caseType = $caseTypes[$params['case_type_id']]; } if (!$form->_currentlyViewedContactId || !$form->_currentUserId || !$params['case_type_id'] || !$caseType) { CRM_Core_Error::fatal('Required parameter missing for ChangeCaseType - end post processing'); } // 1. initiate xml processor $xmlProcessor = new CRM_Case_XMLProcessor_Process(); $xmlProcessorParams = array('clientID' => $form->_currentlyViewedContactId, 'creatorID' => $form->_currentUserId, 'standardTimeline' => 1, 'activityTypeName' => 'Change Case Type', 'activity_date_time' => CRM_Utils_Array::value('reset_date_time', $params), 'caseID' => $form->_caseId, 'resetTimeline' => CRM_Utils_Array::value('is_reset_timeline', $params)); $xmlProcessor->run($caseType, $xmlProcessorParams); // status msg $params['statusMsg'] = ts('Case Type changed successfully.'); }
static function buildQuickForm(&$form) { if ($form->_context == 'caseActivity') { return; } if ($form->_context == 'standalone') { CRM_Contact_Form_NewContact::buildQuickForm($form); } $caseType = array('' => '-select-') + CRM_Case_PseudoConstant::caseType(); $element = $form->add('select', 'case_type_id', ts('Case Type'), $caseType, TRUE, array('onchange' => "CRM.buildCustomData( 'Case', this.value );")); if ($form->_caseTypeId) { $element->freeze(); } $caseStatus = CRM_Case_PseudoConstant::caseStatus(); $form->add('select', 'status_id', ts('Case Status'), $caseStatus, TRUE); $form->add('text', 'duration', ts('Duration'), array('size' => 4, 'maxlength' => 8)); $form->addRule('duration', ts('Please enter the duration as number of minutes (integers only).'), 'positiveInteger'); if ($form->_currentlyViewedContactId) { list($displayName) = CRM_Contact_BAO_Contact::getDisplayAndImage($form->_currentlyViewedContactId); $form->assign('clientName', $displayName); } $form->addDate('start_date', ts('Case Start Date'), TRUE, array('formatType' => 'activityDateTime')); $form->add('select', 'medium_id', ts('Medium'), CRM_Case_PseudoConstant::encounterMedium(), TRUE); // calling this field activity_location to prevent conflict with contact location fields $form->add('text', 'activity_location', ts('Location'), CRM_Core_DAO::getAttribute('CRM_Activity_DAO_Activity', 'location')); $form->addWysiwyg('activity_details', ts('Details'), array('rows' => 4, 'cols' => 60), FALSE); $form->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'upload', 'name' => ts('Save and New'), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * add all the elements shared between case search and advanaced search * * @access public * @return void * @static */ static function buildSearchForm(&$form) { $config = CRM_Core_Config::singleton(); //validate case configuration. require_once 'CRM/Case/BAO/Case.php'; $configured = CRM_Case_BAO_Case::isCaseConfigured(); $form->assign('notConfigured', !$configured['configured']); require_once "CRM/Case/PseudoConstant.php"; $caseTypes = CRM_Case_PseudoConstant::caseType('label', false); foreach ($caseTypes as $id => $Name) { $form->addElement('checkbox', "case_type_id[{$id}]", null, $Name); } $statuses = CRM_Case_PseudoConstant::caseStatus('label', false); $form->add('select', 'case_status_id', ts('Case Status'), array('' => ts('- any status -')) + $statuses); $form->assign('validCiviCase', true); //give options when all cases are accessible. $accessAllCases = false; if (CRM_Core_Permission::check('access all cases and activities')) { $accessAllCases = true; $caseOwner = array(1 => ts('Search All Cases'), 2 => ts('Only My Cases')); $form->addRadio('case_owner', ts('Cases'), $caseOwner); } $form->assign('accessAllCases', $accessAllCases); require_once 'CRM/Core/BAO/Tag.php'; $caseTags = CRM_Core_BAO_Tag::getTagsUsedFor(array('civicrm_case')); if ($caseTags) { foreach ($caseTags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "case_tags[{$tagID}]", null, $tagName); } } require_once "CRM/Core/Permission.php"; if (CRM_Core_Permission::check('administer CiviCRM')) { $form->addElement('checkbox', 'case_deleted', ts('Deleted Cases')); } }
/** * @return array<string> symbolic names of case-types */ public function getAllCaseTypes() { if ($this->allCaseTypes === NULL) { $this->allCaseTypes = CRM_Case_PseudoConstant::caseType("name"); } return $this->allCaseTypes; }
/** * Internal function to format create params for processing */ function _civicrm_api3_case_format_params(&$params) { if (!array_key_exists('creator_id', $params)) { $session = CRM_Core_Session::singleton(); $params['creator_id'] = $session->get('userID'); } if (empty($params['start_date'])) { $params['start_date'] = date('YmdHis'); } // figure out case type id from case type and vice-versa $caseTypes = CRM_Case_PseudoConstant::caseType('label', FALSE); if (empty($params['case_type_id'])) { $params['case_type_id'] = array_search($params['case_type'], $caseTypes); } elseif (empty($params['case_type'])) { $params['case_type'] = $caseTypes[$params['case_type_id']]; } // format input with value separators $sep = CRM_Core_DAO::VALUE_SEPARATOR; $params['case_type_id'] = $sep . implode($sep, (array) $params['case_type_id']) . $sep; }
/** * @param $groupType * * @return array */ public static function extractGroupTypes($groupType) { $returnGroupTypes = array(); if (!$groupType) { return $returnGroupTypes; } $groupTypeParts = explode(CRM_Core_DAO::VALUE_SEPARATOR, $groupType); foreach (explode(',', $groupTypeParts[0]) as $type) { $returnGroupTypes[$type] = $type; } if (!empty($groupTypeParts[1])) { foreach (explode(',', $groupTypeParts[1]) as $typeValue) { $groupTypeValues = $valueLabels = array(); $valueParts = explode(':', $typeValue); $typeName = NULL; switch ($valueParts[0]) { case 'ContributionType': $typeName = 'Contribution'; $valueLabels = CRM_Contribute_PseudoConstant::financialType(); break; case 'ParticipantRole': $typeName = 'Participant'; $valueLabels = CRM_Event_PseudoConstant::participantRole(); break; case 'ParticipantEventName': $typeName = 'Participant'; $valueLabels = CRM_Event_PseudoConstant::event(); break; case 'ParticipantEventType': $typeName = 'Participant'; $valueLabels = CRM_Event_PseudoConstant::eventType(); break; case 'MembershipType': $typeName = 'Membership'; $valueLabels = CRM_Member_PseudoConstant::membershipType(); break; case 'ActivityType': $typeName = 'Activity'; $valueLabels = CRM_Core_PseudoConstant::ActivityType(TRUE, TRUE, FALSE, 'label', TRUE); break; case 'CaseType': $typeName = 'Case'; $valueLabels = CRM_Case_PseudoConstant::caseType(); break; } foreach ($valueParts as $val) { if (CRM_Utils_Rule::integer($val)) { $groupTypeValues[$val] = CRM_Utils_Array::value($val, $valueLabels); } } if (!is_array($returnGroupTypes[$typeName])) { $returnGroupTypes[$typeName] = array(); } $returnGroupTypes[$typeName][$valueParts[0]] = $groupTypeValues; } } return $returnGroupTypes; }
/** * @param $table * * @return array */ public function titlesAndValuesForTable($table) { // static caches for subsequent calls with the same $table static $titles = array(); static $values = array(); // FIXME: split off the table → DAO mapping to a GenCode-generated class static $daos = array('civicrm_address' => 'CRM_Core_DAO_Address', 'civicrm_contact' => 'CRM_Contact_DAO_Contact', 'civicrm_email' => 'CRM_Core_DAO_Email', 'civicrm_im' => 'CRM_Core_DAO_IM', 'civicrm_openid' => 'CRM_Core_DAO_OpenID', 'civicrm_phone' => 'CRM_Core_DAO_Phone', 'civicrm_website' => 'CRM_Core_DAO_Website', 'civicrm_contribution' => 'CRM_Contribute_DAO_Contribution', 'civicrm_note' => 'CRM_Core_DAO_Note', 'civicrm_relationship' => 'CRM_Contact_DAO_Relationship', 'civicrm_activity' => 'CRM_Activity_DAO_Activity', 'civicrm_case' => 'CRM_Case_DAO_Case'); if (!isset($titles[$table]) or !isset($values[$table])) { if (in_array($table, array_keys($daos))) { // FIXME: these should be populated with pseudo constants as they // were at the time of logging rather than their current values // FIXME: Use *_BAO:buildOptions() method rather than pseudoconstants & fetch programmatically $values[$table] = array('contribution_page_id' => CRM_Contribute_PseudoConstant::contributionPage(), 'contribution_status_id' => CRM_Contribute_PseudoConstant::contributionStatus(), 'financial_type_id' => CRM_Contribute_PseudoConstant::financialType(), 'country_id' => CRM_Core_PseudoConstant::country(), 'gender_id' => CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id'), 'location_type_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Address', 'location_type_id'), 'payment_instrument_id' => CRM_Contribute_PseudoConstant::paymentInstrument(), 'phone_type_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Phone', 'phone_type_id'), 'preferred_communication_method' => CRM_Contact_BAO_Contact::buildOptions('preferred_communication_method'), 'preferred_language' => CRM_Contact_BAO_Contact::buildOptions('preferred_language'), 'prefix_id' => CRM_Contact_BAO_Contact::buildOptions('prefix_id'), 'provider_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_IM', 'provider_id'), 'state_province_id' => CRM_Core_PseudoConstant::stateProvince(), 'suffix_id' => CRM_Contact_BAO_Contact::buildOptions('suffix_id'), 'website_type_id' => CRM_Core_PseudoConstant::get('CRM_Core_DAO_Website', 'website_type_id'), 'activity_type_id' => CRM_Core_PseudoConstant::activityType(TRUE, TRUE, FALSE, 'label', TRUE), 'case_type_id' => CRM_Case_PseudoConstant::caseType('title', FALSE), 'priority_id' => CRM_Core_PseudoConstant::get('CRM_Activity_DAO_Activity', 'priority_id')); // for columns that appear in more than 1 table switch ($table) { case 'civicrm_case': $values[$table]['status_id'] = CRM_Case_PseudoConstant::caseStatus('label', FALSE); break; case 'civicrm_activity': $values[$table]['status_id'] = CRM_Core_PseudoConstant::activityStatus(); break; } $dao = new $daos[$table](); foreach ($dao->fields() as $field) { $titles[$table][$field['name']] = CRM_Utils_Array::value('title', $field); if ($field['type'] == CRM_Utils_Type::T_BOOLEAN) { $values[$table][$field['name']] = array('0' => ts('false'), '1' => ts('true')); } } } elseif (substr($table, 0, 14) == 'civicrm_value_') { list($titles[$table], $values[$table]) = $this->titlesAndValuesForCustomDataTable($table); } else { $titles[$table] = $values[$table] = array(); } } return array($titles[$table], $values[$table]); }
public function upgrade_1300() { $this->ctx->log->info('Applying update 1300'); $sql = "Update civicrm_case_type SET is_active = 0 where name IN ('AdultDayCareReferral', 'HousingSupport', 'adult_day_care_referral', 'housing_support')"; CRM_Core_DAO::executeQuery($sql); $values = NULL; $caseTypes = CRM_Case_PseudoConstant::caseType('name', FALSE); foreach (array('Exiting', 'Joining', 'Probation', 'Hrdata') as $caseName) { if ($caseID = array_search($caseName, $caseTypes)) { $values .= " WHEN '{$caseName}' THEN '{$caseID}'"; } } if ($values) { $query = "UPDATE civicrm_managed\n SET entity_id = CASE name\n {$values}\n END, entity_type = 'caseType' WHERE name IN ('Exiting', 'Joining', 'Probation', 'Hrdata');"; CRM_Core_DAO::executeQuery($query); CRM_Core_BAO_Navigation::resetNavigation(); } return TRUE; }
/** * add all the elements shared between case search and advanaced search * * @access public * @return void * @static */ static function buildSearchForm(&$form) { $config =& CRM_Core_Config::singleton(); require_once "CRM/Case/PseudoConstant.php"; $caseTypes = CRM_Case_PseudoConstant::caseType(); if (empty($caseTypes)) { $form->assign('notConfigured', 1); } foreach ($caseTypes as $id => $Name) { $form->addElement('checkbox', "case_type_id[{$id}]", null, $Name); } $statuses = CRM_Case_PseudoConstant::caseStatus(); $form->add('select', 'case_status_id', ts('Case Status'), array('' => ts('- any status -')) + $statuses); $form->assign('validCiviCase', true); $caseOwner = array(ts('My Cases'), ts('All Cases')); $form->addRadio('case_owner', ts('Cases'), $caseOwner); $form->setDefaults(array('case_owner' => 1)); require_once "CRM/Core/Permission.php"; if (CRM_Core_Permission::check('administer CiviCRM')) { $form->addElement('checkbox', 'case_deleted', ts('Deleted Cases')); } }
/** * Function to check case configuration. * * @param null $contactId * * @return array $configured */ static function isCaseConfigured($contactId = NULL) { $configured = array_fill_keys(array('configured', 'allowToAddNewCase', 'redirectToCaseAdmin'), FALSE); //lets check for case configured. $allCasesCount = CRM_Case_BAO_Case::caseCount(NULL, FALSE); $configured['configured'] = $allCasesCount ? TRUE : FALSE; if (!$configured['configured']) { //do check for case type and case status. $caseTypes = CRM_Case_PseudoConstant::caseType('title', FALSE); if (!empty($caseTypes)) { $configured['configured'] = TRUE; if (!$configured['configured']) { $caseStatuses = CRM_Case_PseudoConstant::caseStatus('label', FALSE); if (!empty($caseStatuses)) { $configured['configured'] = TRUE; } } } } if ($configured['configured']) { //do check for active case type and case status. $caseTypes = CRM_Case_PseudoConstant::caseType(); if (!empty($caseTypes)) { $caseStatuses = CRM_Case_PseudoConstant::caseStatus(); if (!empty($caseStatuses)) { $configured['allowToAddNewCase'] = TRUE; } } //do we need to redirect user to case admin. if (!$configured['allowToAddNewCase'] && $contactId) { //check for current contact case count. $currentContatCasesCount = CRM_Case_BAO_Case::caseCount($contactId); //redirect user to case admin page. if (!$currentContatCasesCount) { $configured['redirectToCaseAdmin'] = TRUE; } } } return $configured; }
/** * Add all the elements shared between case search and advanaced search. * * * @param CRM_Core_Form $form * * @return void */ public static function buildSearchForm(&$form) { $config = CRM_Core_Config::singleton(); //validate case configuration. $configured = CRM_Case_BAO_Case::isCaseConfigured(); $form->assign('notConfigured', !$configured['configured']); $form->add('select', 'case_type_id', ts('Case Type'), CRM_Case_PseudoConstant::caseType('title', FALSE), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple')); $form->add('select', 'case_status_id', ts('Case Status'), CRM_Case_PseudoConstant::caseStatus('label', FALSE), FALSE, array('class' => 'crm-select2', 'multiple' => 'multiple')); CRM_Core_Form_Date::buildDateRange($form, 'case_from', 1, '_start_date_low', '_start_date_high', ts('From'), FALSE); CRM_Core_Form_Date::buildDateRange($form, 'case_to', 1, '_end_date_low', '_end_date_high', ts('From'), FALSE); $form->assign('validCiviCase', TRUE); //give options when all cases are accessible. $accessAllCases = FALSE; if (CRM_Core_Permission::check('access all cases and activities')) { $accessAllCases = TRUE; $caseOwner = array(1 => ts('Search All Cases'), 2 => ts('Only My Cases')); $form->addRadio('case_owner', ts('Cases'), $caseOwner); } $form->assign('accessAllCases', $accessAllCases); $caseTags = CRM_Core_BAO_Tag::getTags('civicrm_case'); if ($caseTags) { foreach ($caseTags as $tagID => $tagName) { $form->_tagElement =& $form->addElement('checkbox', "case_tags[{$tagID}]", NULL, $tagName); } } $parentNames = CRM_Core_BAO_Tag::getTagSet('civicrm_case'); CRM_Core_Form_Tag::buildQuickForm($form, $parentNames, 'civicrm_case', NULL, TRUE, FALSE); if (CRM_Core_Permission::check('administer CiviCRM')) { $form->addElement('checkbox', 'case_deleted', ts('Deleted Cases')); } // add all the custom searchable fields $extends = array('Case'); $groupDetails = CRM_Core_BAO_CustomGroup::getGroupDetail(NULL, TRUE, $extends); if ($groupDetails) { $form->assign('caseGroupTree', $groupDetails); foreach ($groupDetails as $group) { foreach ($group['fields'] as $field) { $fieldId = $field['id']; $elementName = 'custom_' . $fieldId; CRM_Core_BAO_CustomField::addQuickFormElement($form, $elementName, $fieldId, FALSE, FALSE, TRUE); } } } $form->setDefaults(array('case_owner' => 1)); }
/** * Build the form object. * * @return void */ public function preProcess() { $caseIds = CRM_Utils_Request::retrieve('caseid', 'String', $this); $this->_caseId = explode(',', $caseIds); $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this); if (!$this->_context) { $this->_context = 'caseActivity'; } $this->_crmDir = 'Case'; $this->assign('context', $this->_context); $result = parent::preProcess(); $scheduleStatusId = CRM_Core_OptionGroup::getValue('activity_status', 'Scheduled', 'name'); $this->assign('scheduleStatusId', $scheduleStatusId); if (!$this->_caseId && $this->_activityId) { $this->_caseId = CRM_Core_DAO::getFieldValue('CRM_Case_DAO_CaseActivity', $this->_activityId, 'case_id', 'activity_id'); } if ($this->_caseId) { $this->assign('caseId', $this->_caseId); $this->assign('countId', count($this->_caseId)); $this->assign('caseID', CRM_Utils_Array::first($this->_caseId)); } if (!$this->_caseId || !$this->_activityId && !$this->_activityTypeId) { CRM_Core_Error::fatal('required params missing.'); } //check for case activity access. if (!CRM_Case_BAO_Case::accessCiviCase()) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } //validate case id. if ($this->_caseId && !CRM_Core_Permission::check('access all cases and activities')) { $session = CRM_Core_Session::singleton(); $allCases = CRM_Case_BAO_Case::getCases(TRUE, $session->get('userID'), 'any'); if (!array_key_exists($this->_caseId, $allCases)) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } } //validate case activity id. if ($this->_activityId && $this->_action & CRM_Core_Action::UPDATE) { $valid = CRM_Case_BAO_Case::checkPermission($this->_activityId, 'edit', $this->_activityTypeId); if (!$valid) { CRM_Core_Error::fatal(ts('You are not authorized to access this page.')); } } foreach ($this->_caseId as $casePos => $caseId) { $this->_caseType[$casePos] = CRM_Case_BAO_Case::getCaseType($caseId, 'name'); } $this->assign('caseType', $this->_caseType); $xmlProcessorProcess = new CRM_Case_XMLProcessor_Process(); $isMultiClient = $xmlProcessorProcess->getAllowMultipleCaseClients(); $this->assign('multiClient', $isMultiClient); foreach ($this->_caseId as $casePos => $caseId) { $clients[] = CRM_Case_BAO_Case::getContactNames($caseId); } $this->assign('client_names', $clients); $caseIds = implode(',', $this->_caseId); // set context for pushUserContext and for statusBounce if ($this->_context == 'fulltext') { if ($this->_action == CRM_Core_Action::UPDATE || $this->_action == CRM_Core_Action::DELETE) { $url = CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1&context={$this->_context}"); } else { $url = CRM_Utils_System::url('civicrm/contact/search/custom', 'force=1'); } } else { $url = CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1"); } if (!$this->_activityId) { $caseTypes = CRM_Case_PseudoConstant::caseType(); if (empty($caseTypes) && $this->_activityTypeName == 'Change Case Type' && !$this->_caseId) { $url = CRM_Utils_System::url('civicrm/contact/view/case', "reset=1&action=view&cid={$this->_currentlyViewedContactId}&id={$caseIds}&show=1"); $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); CRM_Core_Error::statusBounce(ts("You do not have any active Case Types")); } // check if activity count is within the limit $xmlProcessor = new CRM_Case_XMLProcessor_Process(); foreach ($this->_caseId as $casePos => $caseId) { $caseType = $this->_caseType[$casePos]; $activityInst = $xmlProcessor->getMaxInstance($caseType); // If not bounce back and also provide activity edit link if (isset($activityInst[$this->_activityTypeName])) { $activityCount = CRM_Case_BAO_Case::getCaseActivityCount($caseId, $this->_activityTypeId); if ($activityCount >= $activityInst[$this->_activityTypeName]) { if ($activityInst[$this->_activityTypeName] == 1) { $atArray = array('activity_type_id' => $this->_activityTypeId); $activities = CRM_Case_BAO_Case::getCaseActivity($caseId, $atArray, $this->_currentUserId); $activities = array_keys($activities); $activities = $activities[0]; $editUrl = CRM_Utils_System::url('civicrm/case/activity', "reset=1&cid={$this->_currentlyViewedContactId}&caseid={$caseId}&action=update&id={$activities}"); } CRM_Core_Error::statusBounce(ts("You can not add another '%1' activity to this case. %2", array(1 => $this->_activityTypeName, 2 => ts("Do you want to <a %1>edit the existing activity</a>?", array(1 => "href='{$editUrl}'")))), $url); } } } } $session = CRM_Core_Session::singleton(); $session->pushUserContext($url); }
/** * Run some sanity checks. * * This could become a hook so that CiviCRM can run both built-in * configuration & sanity checks, and modules/extensions can add * their own checks. * * We might even expose the results of these checks on the Wordpress * plugin status page or the Drupal admin/reports/status path. * * @return array * Array of messages * @link https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_requirements */ public function checkAll($showHushed = FALSE) { $checks = array(); $checks[] = new CRM_Utils_Check_Security(); $checks[] = new CRM_Utils_Check_Env(); $compInfo = CRM_Core_Component::getEnabledComponents(); foreach ($compInfo as $compObj) { switch ($compObj->info['name']) { case 'CiviCase': $checks[] = new CRM_Utils_Check_Case(CRM_Case_XMLRepository::singleton(), CRM_Case_PseudoConstant::caseType('name')); break; default: } } $messages = array(); foreach ($checks as $check) { $messages = array_merge($messages, $check->checkAll()); } CRM_Utils_Hook::check($messages); if (!$showHushed) { foreach ($messages as $key => $message) { $hush = self::checkHushSnooze($message); if ($hush) { unset($messages[$key]); } } } uasort($messages, array(__CLASS__, 'severitySort')); return $messages; }