copyValues($params); return $caseTypeDAO->save(); } /** * Function to format / convert submitted array to xml for case type definition * * @param $params associated array of submitted values * * @return void * @static * @access public */ static function convertDefinitionToXML(&$params) { $xmlFile = '' . "\n\n\n"; $xmlFile .= "{$params['name']}\n"; if (!empty($params['definition']['activityTypes'])) { $xmlFile .= "\n"; foreach ($params['definition']['activityTypes'] as $values) { $xmlFile .= "\n"; foreach ($values as $key => $value) { $xmlFile .= "<{$key}>{$value}\n"; } $xmlFile .= "\n"; } $xmlFile .= "\n"; } if (!empty($params['definition']['activitySets'])) { $xmlFile .= "\n"; foreach ($params['definition']['activitySets'] as $k => $val) { $xmlFile .= "\n"; foreach ($val as $index => $setVal) { if ($index == 'activityTypes') { if (!empty($setVal)) { $xmlFile .= "\n"; foreach ($setVal as $values) { $xmlFile .= "\n"; foreach ($values as $key => $value) { $xmlFile .= "<{$key}>{$value}\n"; } $xmlFile .= "\n"; } $xmlFile .= "\n"; } } else { $xmlFile .= "<{$index}>{$setVal}\n"; } } $xmlFile .= "\n"; } $xmlFile .= "\n"; } if (!empty($params['definition']['caseRoles'])) { $xmlFile .= "\n"; foreach ($params['definition']['caseRoles'] as $values) { $xmlFile .= "\n"; foreach ($values as $key => $value) { $xmlFile .= "<{$key}>{$value}\n"; } $xmlFile .= "\n"; } $xmlFile .= "\n"; } $xmlFile .= ''; $params['definition'] = $xmlFile; } /** * Function to get the case definition either from db or read from xml file * * @param $caseType a single case-type record * * @return array the definition of the case-type, expressed as PHP array-tree * @static */ static function getCaseTypeDefinition($caseType) { $xml = CRM_Case_XMLRepository::singleton()->retrieve($caseType['name']); // build PHP array based on definition $definition = array(); // set activity types $activityTypes = json_decode(json_encode($xml->ActivityTypes), TRUE); $definition['activityTypes'] = $activityTypes['ActivityType']; // set activity sets $activitySets = json_decode(json_encode($xml->ActivitySets), TRUE); // hack to fix the case when we have only one activityset if (!empty($activitySets['ActivitySet']['name'])) { $temp = $activitySets['ActivitySet']; $activitySets['ActivitySet'] = array($temp); } foreach ($activitySets['ActivitySet'] as $key => $value) { foreach ($value as $k => $val) { if ( $k == 'ActivityTypes') { $definition['activitySets'][$key]['activityTypes'] = array_pop(array_values($val)); } else { $definition['activitySets'][$key][$k] = $val; } } } // set case roles $caseRoles = json_decode(json_encode($xml->CaseRoles), TRUE); $definition['caseRoles'] = $caseRoles['RelationshipType']; return $definition; } /** * Given the list of params in the params array, fetch the object * and store the values in the values array * * @param array $params input parameters to find object * @param array $values output values of the object * * @internal param array $ids the array that holds all the db ids * * @return CRM_Case_BAO_CaseType|null the found object or null * @access public * @static */ static function &getValues(&$params, &$values) { $caseType = new CRM_Case_BAO_CaseType(); $caseType->copyValues($params); if ($caseType->find(TRUE)) { CRM_Core_DAO::storeValues($caseType, $values); return $caseType; } return NULL; } /** * takes an associative array and creates a case type object * * @param array $params (reference ) an assoc array of name/value pairs * * @internal param array $ids the array that holds all the db ids * * @return object CRM_Case_BAO_CaseType object * @access public * @static */ static function &create(&$params) { $transaction = new CRM_Core_Transaction(); if (!empty($params['id'])) { CRM_Utils_Hook::pre('edit', 'CaseType', $params['id'], $params); } else { CRM_Utils_Hook::pre('create', 'CaseType', NULL, $params); } $caseType = self::add($params); if (is_a($caseType, 'CRM_Core_Error')) { $transaction->rollback(); return $caseType; } if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'CaseType', $caseType->id, $case); } else { CRM_Utils_Hook::post('create', 'CaseType', $caseType->id, $case); } $transaction->commit(); return $caseType; } /** * Takes a bunch of params that are needed to match certain criteria and * retrieves the relevant objects. We'll tweak this function to be more * full featured over a period of time. This is the inverse function of * create. It also stores all the retrieved values in the default array * * @param array $params (reference ) an assoc array of name/value pairs * @param array $defaults (reference ) an assoc array to hold the name / value pairs * in a hierarchical manner * * @internal param array $ids (reference) the array that holds all the db ids * * @return object CRM_Case_BAO_CaseType object * @access public * @static */ static function retrieve(&$params, &$defaults) { $caseType = CRM_Case_BAO_CaseType::getValues($params, $defaults); return $caseType; } /** * @param $caseTypeId * * @return mixed */ static function del($caseTypeId) { $caseType = new CRM_Case_DAO_CaseType(); $caseType->id = $caseTypeId; return $caseType->delete(); } }