/**
  * Global form rule.
  *
  * @param array $fields
  *   The input form values.
  *
  * @param $files
  * @param $self
  *
  * @return bool|array
  *   true if no errors, else array of errors
  */
 public static function formRule($fields, $files, $self)
 {
     $errors = array();
     if ($self->_id) {
         $contactName = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_ContactType', $self->_id, 'name');
     } else {
         $contactName = ucfirst(CRM_Utils_String::munge($fields['label']));
     }
     if (!CRM_Core_DAO::objectExists($contactName, 'CRM_Contact_DAO_ContactType', $self->_id)) {
         $errors['label'] = ts('This contact type name already exists in database. Contact type names must be unique.');
     }
     $reservedKeyWords = CRM_Core_SelectValues::customGroupExtends();
     //restrict "name" from being a reserved keyword when a new contact subtype is created
     if (!$self->_id && in_array($contactName, array_keys($reservedKeyWords))) {
         $errors['label'] = ts('Contact type names should not use reserved keywords.');
     }
     return empty($errors) ? TRUE : $errors;
 }
 /**
  * Browse all custom data groups.
  *
  * @param string $action   the action to be invoked
  *
  * @return void
  * @access public
  */
 function browse($action = NULL)
 {
     // get all custom groups sorted by weight
     $customGroup = array();
     $dao = new CRM_Core_DAO_CustomGroup();
     $dao->orderBy('weight, title');
     $dao->find();
     while ($dao->fetch()) {
         $customGroup[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $customGroup[$dao->id]);
         // form all action links
         $action = array_sum(array_keys($this->actionLinks()));
         // update enable/disable links depending on custom_group properties.
         if ($dao->is_active) {
             $action -= CRM_Core_Action::ENABLE;
         } else {
             $action -= CRM_Core_Action::DISABLE;
         }
         $customGroup[$dao->id]['order'] = $customGroup[$dao->id]['weight'];
         $customGroup[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action, array('id' => $dao->id));
     }
     $customGroupExtends = CRM_Core_SelectValues::customGroupExtends();
     foreach ($customGroup as $key => $array) {
         CRM_Core_DAO_CustomGroup::addDisplayEnums($customGroup[$key]);
         $customGroup[$key]['extends_display'] = $customGroupExtends[$customGroup[$key]['extends']];
     }
     //fix for Displaying subTypes
     $subTypes = array();
     $subTypes['Activity'] = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
     $subTypes['Contribution'] = CRM_Contribute_PseudoConstant::contributionType();
     $subTypes['Membership'] = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
     $subTypes['Event'] = CRM_Core_OptionGroup::values('event_type');
     $subTypes['Grant'] = CRM_Core_OptionGroup::values('grant_type');
     $subTypes['Campaign'] = CRM_Campaign_PseudoConstant::campaignType();
     $subTypes['Participant'] = array();
     $subTypes['ParticipantRole'] = CRM_Core_OptionGroup::values('participant_role');
     $subTypes['ParticipantEventName'] = CRM_Event_PseudoConstant::event();
     $subTypes['ParticipantEventType'] = CRM_Core_OptionGroup::values('event_type');
     $subTypes['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL);
     $subTypes['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL);
     $subTypes['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL);
     $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual');
     $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization');
     $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household');
     $allRelationshipType = array();
     $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
     $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
     //adding subtype specific relationships CRM-5256
     $relSubType = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($relSubType as $subType => $val) {
         $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], FALSE, 'label', TRUE, $subType);
         $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
     }
     $subTypes['Relationship'] = $allRelationshipType;
     $cSubTypes = CRM_Core_Component::contactSubTypes();
     $contactSubTypes = array();
     foreach ($cSubTypes as $key => $value) {
         $contactSubTypes[$key] = $key;
     }
     $subTypes['Contact'] = $contactSubTypes;
     CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($subTypes);
     foreach ($customGroup as $key => $values) {
         $subValue = CRM_Utils_Array::value('extends_entity_column_value', $customGroup[$key]);
         $subName = CRM_Utils_Array::value('extends_entity_column_id', $customGroup[$key]);
         $type = CRM_Utils_Array::value('extends', $customGroup[$key]);
         if ($subValue) {
             $subValue = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($subValue, 1, -1));
             $colValue = NULL;
             foreach ($subValue as $sub) {
                 if ($sub) {
                     if ($type == 'Participant') {
                         if ($subName == 1) {
                             $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantRole'][$sub] : $subTypes['ParticipantRole'][$sub];
                         } elseif ($subName == 2) {
                             $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventName'][$sub] : $subTypes['ParticipantEventName'][$sub];
                         } elseif ($subName == 3) {
                             $colValue = $colValue ? $colValue . ', ' . $subTypes['ParticipantEventType'][$sub] : $subTypes['ParticipantEventType'][$sub];
                         }
                     } elseif ($type == 'Relationship') {
                         $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_a_b'] : $subTypes[$type][$sub . '_a_b'];
                         if (isset($subTypes[$type][$sub . '_b_a'])) {
                             $colValue = $colValue ? $colValue . ', ' . $subTypes[$type][$sub . '_b_a'] : $subTypes[$type][$sub . '_b_a'];
                         }
                     } else {
                         $colValue = $colValue ? $colValue . (isset($subTypes[$type][$sub]) ? ', ' . $subTypes[$type][$sub] : '') : (isset($subTypes[$type][$sub]) ? $subTypes[$type][$sub] : '');
                     }
                 }
             }
             $customGroup[$key]["extends_entity_column_value"] = $colValue;
         } else {
             if (is_array(CRM_Utils_Array::value($type, $subTypes))) {
                 $customGroup[$key]["extends_entity_column_value"] = ts("Any");
             }
         }
     }
     $returnURL = CRM_Utils_System::url('civicrm/admin/custom/group', "reset=1&action=browse");
     CRM_Utils_Weight::addOrder($customGroup, 'CRM_Core_DAO_CustomGroup', 'id', $returnURL);
     $this->assign('rows', $customGroup);
 }
 /**
  * Take in an array of entityID, custom_ID
  * and gets the value from the appropriate table.
  *
  * To get the values of custom fields with IDs 13 and 43 for contact ID 1327, use:
  * $params = array( 'entityID' => 1327, 'custom_13' => 1, 'custom_43' => 1 );
  *
  * Entity Type will be inferred by the custom fields you request
  * Specify $params['entityType'] if you do not supply any custom fields to return
  * and entity type is other than Contact
  *
  * @array $params
  *
  * @param array $params
  *
  * @throws Exception
  * @return array
  */
 public static function &getValues(&$params)
 {
     if (empty($params)) {
         return NULL;
     }
     if (!isset($params['entityID']) || CRM_Utils_Type::escape($params['entityID'], 'Integer', FALSE) === NULL) {
         return CRM_Core_Error::createAPIError(ts('entityID needs to be set and of type Integer'));
     }
     // first collect all the ids. The format is:
     // custom_ID
     $fieldIDs = array();
     foreach ($params as $n => $v) {
         $key = $idx = NULL;
         if (substr($n, 0, 7) == 'custom_') {
             $idx = substr($n, 7);
             if (CRM_Utils_Type::escape($idx, 'Integer', FALSE) === NULL) {
                 return CRM_Core_Error::createAPIError(ts('field ID needs to be of type Integer for index %1', array(1 => $idx)));
             }
             $fieldIDs[] = (int) $idx;
         }
     }
     $default = array('Contact', 'Individual', 'Household', 'Organization');
     if (!($type = CRM_Utils_Array::value('entityType', $params)) || in_array($params['entityType'], $default)) {
         $type = NULL;
     } else {
         $entities = CRM_Core_SelectValues::customGroupExtends();
         if (!array_key_exists($type, $entities)) {
             if (in_array($type, $entities)) {
                 $type = $entities[$type];
                 if (in_array($type, $default)) {
                     $type = NULL;
                 }
             } else {
                 return CRM_Core_Error::createAPIError(ts('Invalid entity type') . ': "' . $type . '"');
             }
         }
     }
     $values = self::getEntityValues($params['entityID'], $type, $fieldIDs);
     if (empty($values)) {
         // note that this behaviour is undesirable from an API point of view - it should return an empty array
         // since this is also called by the merger code & not sure the consequences of changing
         // are just handling undoing this in the api layer. ie. converting the error back into a success
         $result = array('is_error' => 1, 'error_message' => 'No values found for the specified entity ID and custom field(s).');
         return $result;
     } else {
         $result = array('is_error' => 0, 'entityID' => $params['entityID']);
         foreach ($values as $id => $value) {
             $result["custom_{$id}"] = $value;
         }
         return $result;
     }
 }
Example #4
0
 /**
  * Store and return an array of all active custom fields.
  *
  * @param string      $customDataType      type of Custom Data
  * @param boolean     $showAll             If true returns all fields (includes disabled fields)
  * @param boolean     $inline              If true returns all inline fields (includes disabled fields)
  * @param int         $customDataSubType   Custom Data sub type value
  * @param int         $customDataSubName   Custom Data sub name value
  * @param boolean     $onlyParent          return only top level custom data, for eg, only Participant and ignore subname and subtype  
  *
  * @return array      $fields - an array of active custom fields.
  *
  * @access public
  * @static
  */
 public static function &getFields($customDataType = 'Individual', $showAll = false, $inline = false, $customDataSubType = null, $customDataSubName = null, $onlyParent = false)
 {
     $onlySubType = false;
     if ($customDataType && !is_array($customDataType)) {
         if (in_array($customDataType, CRM_Contact_BAO_ContactType::subTypes())) {
             // This is the case when getFieldsForImport() requires fields
             // limited strictly to a subtype.
             $customDataSubType = $customDataType;
             $customDataType = CRM_Contact_BAO_ContactType::getBasicType($customDataType);
             $onlySubType = true;
         }
         if (in_array($customDataType, array_keys(CRM_Core_SelectValues::customGroupExtends()))) {
             // this makes the method flexible to support retrieving fields
             // for multiple extends value.
             $customDataType = array($customDataType);
         }
     }
     if (is_array($customDataType)) {
         $cacheKey = implode('_', $customDataType);
     } else {
         $cacheKey = $customDataType;
     }
     $cacheKey .= $customDataSubType ? "{$customDataSubType}_" : "_0";
     $cacheKey .= $customDataSubName ? "{$customDataSubName}_" : "_0";
     $cacheKey .= $showAll ? "_1" : "_0";
     $cacheKey .= $inline ? "_1_" : "_0_";
     $cacheKey .= $onlyParent ? "_1_" : "_0_";
     $cacheKey .= $onlySubType ? "_1_" : "_0_";
     $cgTable = CRM_Core_DAO_CustomGroup::getTableName();
     // also get the permission stuff here
     require_once 'CRM/Core/Permission.php';
     $permissionClause = CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, "{$cgTable}.");
     // lets md5 permission clause and take first 8 characters
     $cacheKey .= substr(md5($permissionClause), 0, 8);
     if (strlen($cacheKey) > 40) {
         $cacheKey = md5($cacheKey);
     }
     if (!self::$_importFields || CRM_Utils_Array::value($cacheKey, self::$_importFields) === null) {
         if (!self::$_importFields) {
             self::$_importFields = array();
         }
         // check if we can retrieve from database cache
         require_once 'CRM/Core/BAO/Cache.php';
         $fields =& CRM_Core_BAO_Cache::getItem('contact fields', "custom importableFields {$cacheKey}");
         if ($fields === null) {
             $cfTable = self::getTableName();
             $extends = '';
             if (is_array($customDataType)) {
                 $value = null;
                 foreach ($customDataType as $dataType) {
                     if (in_array($dataType, array_keys(CRM_Core_SelectValues::customGroupExtends()))) {
                         if (in_array($dataType, array('Individual', 'Household', 'Organization'))) {
                             $val = "'" . CRM_Utils_Type::escape($dataType, 'String') . "', 'Contact' ";
                         } else {
                             $val = "'" . CRM_Utils_Type::escape($dataType, 'String') . "'";
                         }
                         $value = $value ? $value . ", {$val}" : $val;
                     }
                 }
                 if ($value) {
                     $extends = "AND   {$cgTable}.extends IN ( {$value} ) ";
                 }
             }
             if ($onlyParent) {
                 $extends .= " AND {$cgTable}.extends_entity_column_value IS NULL AND {$cgTable}.extends_entity_column_id IS NULL ";
             }
             $query = "SELECT {$cfTable}.id, {$cfTable}.label,\n                            {$cgTable}.title,\n                            {$cfTable}.data_type, {$cfTable}.html_type,\n                            {$cfTable}.options_per_line,\n                            {$cgTable}.extends, {$cfTable}.is_search_range,\n                            {$cgTable}.extends_entity_column_value,\n                            {$cgTable}.extends_entity_column_id,\n                            {$cfTable}.is_view,\n                            {$cfTable}.option_group_id,\n                            {$cfTable}.date_format,\n                            {$cfTable}.time_format,\n                            {$cgTable}.is_multiple\n                     FROM {$cfTable}\n                     INNER JOIN {$cgTable}\n                     ON {$cfTable}.custom_group_id = {$cgTable}.id\n                     WHERE ( 1 ) ";
             if (!$showAll) {
                 $query .= " AND {$cfTable}.is_active = 1 AND {$cgTable}.is_active = 1 ";
             }
             if ($inline) {
                 $query .= " AND {$cgTable}.style = 'Inline' ";
             }
             //get the custom fields for specific type in
             //combination with fields those support any type.
             if ($customDataSubType) {
                 $customDataSubType = CRM_Core_DAO::VALUE_SEPARATOR . $customDataSubType . CRM_Core_DAO::VALUE_SEPARATOR;
                 $query .= " AND ( {$cgTable}.extends_entity_column_value LIKE '%{$customDataSubType}%'";
                 if (!$onlySubType) {
                     $query .= " OR {$cgTable}.extends_entity_column_value IS NULL";
                 }
                 $query .= " )";
             }
             if ($customDataSubName) {
                 $query .= " AND ( {$cgTable}.extends_entity_column_id = {$customDataSubName} ) ";
             }
             // also get the permission stuff here
             require_once 'CRM/Core/Permission.php';
             $permissionClause = CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, "{$cgTable}.", true);
             $query .= " {$extends} AND {$permissionClause}\n                        ORDER BY {$cgTable}.weight, {$cgTable}.title,\n                                 {$cfTable}.weight, {$cfTable}.label";
             $dao =& CRM_Core_DAO::executeQuery($query);
             $fields = array();
             while ($dao->fetch() != null) {
                 $fields[$dao->id]['label'] = $dao->label;
                 $fields[$dao->id]['groupTitle'] = $dao->title;
                 $fields[$dao->id]['data_type'] = $dao->data_type;
                 $fields[$dao->id]['html_type'] = $dao->html_type;
                 $fields[$dao->id]['options_per_line'] = $dao->options_per_line;
                 $fields[$dao->id]['extends'] = $dao->extends;
                 $fields[$dao->id]['is_search_range'] = $dao->is_search_range;
                 $fields[$dao->id]['extends_entity_column_value'] = $dao->extends_entity_column_value;
                 $fields[$dao->id]['extends_entity_column_id'] = $dao->extends_entity_column_id;
                 $fields[$dao->id]['is_view'] = $dao->is_view;
                 $fields[$dao->id]['is_multiple'] = $dao->is_multiple;
                 $fields[$dao->id]['option_group_id'] = $dao->option_group_id;
                 $fields[$dao->id]['date_format'] = $dao->date_format;
                 $fields[$dao->id]['time_format'] = $dao->time_format;
             }
             CRM_Core_BAO_Cache::setItem($fields, 'contact fields', "custom importableFields {$cacheKey}");
         }
         self::$_importFields[$cacheKey] = $fields;
     }
     return self::$_importFields[$cacheKey];
 }
 /**
  * Store and return an array of all active custom fields.
  *
  * @param string $customDataType
  *   Type of Custom Data; empty is a synonym for "all contact data types".
  * @param bool $showAll
  *   If true returns all fields (includes disabled fields).
  * @param bool $inline
  *   If true returns all inline fields (includes disabled fields).
  * @param int $customDataSubType
  *   Custom Data sub type value.
  * @param int $customDataSubName
  *   Custom Data sub name value.
  * @param bool $onlyParent
  *   Return only top level custom data, for eg, only Participant and ignore subname and subtype.
  * @param bool $onlySubType
  *   Return only custom data for subtype.
  * @param bool $checkPermission
  *   If false, do not include permissioning clause.
  *
  * @return array
  *   an array of active custom fields.
  *
  */
 public static function &getFields($customDataType = 'Individual', $showAll = FALSE, $inline = FALSE, $customDataSubType = NULL, $customDataSubName = NULL, $onlyParent = FALSE, $onlySubType = FALSE, $checkPermission = TRUE)
 {
     if (empty($customDataType)) {
         $customDataType = array('Contact', 'Individual', 'Organization', 'Household');
     }
     if ($customDataType && !is_array($customDataType)) {
         if (in_array($customDataType, CRM_Contact_BAO_ContactType::subTypes())) {
             // This is the case when getFieldsForImport() requires fields
             // limited strictly to a subtype.
             $customDataSubType = $customDataType;
             $customDataType = CRM_Contact_BAO_ContactType::getBasicType($customDataType);
             $onlySubType = TRUE;
         }
         if (in_array($customDataType, array_keys(CRM_Core_SelectValues::customGroupExtends()))) {
             // this makes the method flexible to support retrieving fields
             // for multiple extends value.
             $customDataType = array($customDataType);
         }
     }
     $customDataSubType = CRM_Utils_Array::explodePadded($customDataSubType);
     if (is_array($customDataType)) {
         $cacheKey = implode('_', $customDataType);
     } else {
         $cacheKey = $customDataType;
     }
     $cacheKey .= !empty($customDataSubType) ? '_' . implode('_', $customDataSubType) : '_0';
     $cacheKey .= $customDataSubName ? "{$customDataSubName}_" : '_0';
     $cacheKey .= $showAll ? '_1' : '_0';
     $cacheKey .= $inline ? '_1_' : '_0_';
     $cacheKey .= $onlyParent ? '_1_' : '_0_';
     $cacheKey .= $onlySubType ? '_1_' : '_0_';
     $cacheKey .= $checkPermission ? '_1_' : '_0_';
     $cgTable = CRM_Core_DAO_CustomGroup::getTableName();
     // also get the permission stuff here
     if ($checkPermission) {
         $permissionClause = CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, "{$cgTable}.");
     } else {
         $permissionClause = '(1)';
     }
     // lets md5 permission clause and take first 8 characters
     $cacheKey .= substr(md5($permissionClause), 0, 8);
     if (strlen($cacheKey) > 40) {
         $cacheKey = md5($cacheKey);
     }
     if (!self::$_importFields || CRM_Utils_Array::value($cacheKey, self::$_importFields) === NULL) {
         if (!self::$_importFields) {
             self::$_importFields = array();
         }
         // check if we can retrieve from database cache
         $fields = CRM_Core_BAO_Cache::getItem('contact fields', "custom importableFields {$cacheKey}");
         if ($fields === NULL) {
             $cfTable = self::getTableName();
             $extends = '';
             if (is_array($customDataType)) {
                 $value = NULL;
                 foreach ($customDataType as $dataType) {
                     if (in_array($dataType, array_keys(CRM_Core_SelectValues::customGroupExtends()))) {
                         if (in_array($dataType, array('Individual', 'Household', 'Organization'))) {
                             $val = "'" . CRM_Utils_Type::escape($dataType, 'String') . "', 'Contact' ";
                         } else {
                             $val = "'" . CRM_Utils_Type::escape($dataType, 'String') . "'";
                         }
                         $value = $value ? $value . ", {$val}" : $val;
                     }
                 }
                 if ($value) {
                     $extends = "AND   {$cgTable}.extends IN ( {$value} ) ";
                 }
             }
             if (!empty($customDataType) && empty($extends)) {
                 // $customDataType specified a filter, but there is no corresponding SQL ($extends)
                 self::$_importFields[$cacheKey] = array();
                 return self::$_importFields[$cacheKey];
             }
             if ($onlyParent) {
                 $extends .= " AND {$cgTable}.extends_entity_column_value IS NULL AND {$cgTable}.extends_entity_column_id IS NULL ";
             }
             $query = "SELECT {$cfTable}.id, {$cfTable}.label,\n                            {$cgTable}.title,\n                            {$cfTable}.data_type,\n                            {$cfTable}.html_type,\n                            {$cfTable}.default_value,\n                            {$cfTable}.options_per_line, {$cfTable}.text_length,\n                            {$cfTable}.custom_group_id,\n                            {$cfTable}.is_required,\n                            {$cgTable}.extends, {$cfTable}.is_search_range,\n                            {$cgTable}.extends_entity_column_value,\n                            {$cgTable}.extends_entity_column_id,\n                            {$cfTable}.is_view,\n                            {$cfTable}.option_group_id,\n                            {$cfTable}.date_format,\n                            {$cfTable}.time_format,\n                            {$cgTable}.is_multiple,\n                            og.name as option_group_name\n                     FROM {$cfTable}\n                     INNER JOIN {$cgTable}\n                       ON {$cfTable}.custom_group_id = {$cgTable}.id\n                     LEFT JOIN civicrm_option_group og\n                       ON {$cfTable}.option_group_id = og.id\n                     WHERE ( 1 ) ";
             if (!$showAll) {
                 $query .= " AND {$cfTable}.is_active = 1 AND {$cgTable}.is_active = 1 ";
             }
             if ($inline) {
                 $query .= " AND {$cgTable}.style = 'Inline' ";
             }
             //get the custom fields for specific type in
             //combination with fields those support any type.
             if (!empty($customDataSubType)) {
                 $subtypeClause = array();
                 foreach ($customDataSubType as $subtype) {
                     $subtype = CRM_Core_DAO::VALUE_SEPARATOR . $subtype . CRM_Core_DAO::VALUE_SEPARATOR;
                     $subtypeClause[] = "{$cgTable}.extends_entity_column_value LIKE '%{$subtype}%'";
                 }
                 if (!$onlySubType) {
                     $subtypeClause[] = "{$cgTable}.extends_entity_column_value IS NULL";
                 }
                 $query .= " AND ( " . implode(' OR ', $subtypeClause) . " )";
             }
             if ($customDataSubName) {
                 $query .= " AND ( {$cgTable}.extends_entity_column_id = {$customDataSubName} ) ";
             }
             // also get the permission stuff here
             if ($checkPermission) {
                 $permissionClause = CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, "{$cgTable}.", TRUE);
             } else {
                 $permissionClause = '(1)';
             }
             $query .= " {$extends} AND {$permissionClause}\n                        ORDER BY {$cgTable}.weight, {$cgTable}.title,\n                                 {$cfTable}.weight, {$cfTable}.label";
             $dao = CRM_Core_DAO::executeQuery($query);
             $fields = array();
             while ($dao->fetch() != NULL) {
                 $fields[$dao->id]['label'] = $dao->label;
                 $fields[$dao->id]['groupTitle'] = $dao->title;
                 $fields[$dao->id]['data_type'] = $dao->data_type;
                 $fields[$dao->id]['html_type'] = $dao->html_type;
                 $fields[$dao->id]['default_value'] = $dao->default_value;
                 $fields[$dao->id]['text_length'] = $dao->text_length;
                 $fields[$dao->id]['options_per_line'] = $dao->options_per_line;
                 $fields[$dao->id]['custom_group_id'] = $dao->custom_group_id;
                 $fields[$dao->id]['extends'] = $dao->extends;
                 $fields[$dao->id]['is_search_range'] = $dao->is_search_range;
                 $fields[$dao->id]['extends_entity_column_value'] = $dao->extends_entity_column_value;
                 $fields[$dao->id]['extends_entity_column_id'] = $dao->extends_entity_column_id;
                 $fields[$dao->id]['is_view'] = $dao->is_view;
                 $fields[$dao->id]['is_multiple'] = $dao->is_multiple;
                 $fields[$dao->id]['option_group_id'] = $dao->option_group_id;
                 $fields[$dao->id]['date_format'] = $dao->date_format;
                 $fields[$dao->id]['time_format'] = $dao->time_format;
                 $fields[$dao->id]['is_required'] = $dao->is_required;
                 self::getOptionsForField($fields[$dao->id], $dao->option_group_name);
             }
             CRM_Core_BAO_Cache::setItem($fields, 'contact fields', "custom importableFields {$cacheKey}");
         }
         self::$_importFields[$cacheKey] = $fields;
     }
     return self::$_importFields[$cacheKey];
 }
Example #6
0
 /**
  * Build the form object.
  *
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $this->applyFilter('__ALL__', 'trim');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup');
     //title
     $this->add('text', 'title', ts('Set Name'), $attributes['title'], TRUE);
     //Fix for code alignment, CRM-3058
     $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
     $this->assign('contactTypes', json_encode($contactTypes));
     $sel1 = array("" => ts("- select -")) + CRM_Core_SelectValues::customGroupExtends();
     $sel2 = array();
     $activityType = CRM_Core_PseudoConstant::activityType(FALSE, TRUE, FALSE, 'label', TRUE);
     $eventType = CRM_Core_OptionGroup::values('event_type');
     $grantType = CRM_Core_OptionGroup::values('grant_type');
     $campaignTypes = CRM_Campaign_PseudoConstant::campaignType();
     $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypes(FALSE);
     $participantRole = CRM_Core_OptionGroup::values('participant_role');
     $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Individual');
     $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Organization');
     $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, 'null', NULL, 'Household');
     ksort($sel1);
     asort($activityType);
     asort($eventType);
     asort($grantType);
     asort($membershipType);
     asort($participantRole);
     $allRelationshipType = array();
     $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
     $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
     //adding subtype specific relationships CRM-5256
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $subType => $val) {
         $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(NULL, NULL, NULL, $val['parent'], FALSE, 'label', TRUE, $subType);
         $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
     }
     $sel2['Event'] = $eventType;
     $sel2['Grant'] = $grantType;
     $sel2['Activity'] = $activityType;
     $sel2['Campaign'] = $campaignTypes;
     $sel2['Membership'] = $membershipType;
     $sel2['ParticipantRole'] = $participantRole;
     $sel2['ParticipantEventName'] = CRM_Event_PseudoConstant::event(NULL, FALSE, "( is_template IS NULL OR is_template != 1 )");
     $sel2['ParticipantEventType'] = $eventType;
     $sel2['Contribution'] = CRM_Contribute_PseudoConstant::financialType();
     $sel2['Relationship'] = $allRelationshipType;
     $sel2['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', FALSE, NULL);
     $sel2['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', FALSE, NULL);
     $sel2['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', FALSE, NULL);
     CRM_Core_BAO_CustomGroup::getExtendedObjectTypes($sel2);
     foreach ($sel2 as $main => $sub) {
         if (!empty($sel2[$main])) {
             if ($main == 'Relationship') {
                 $relName = self::getFormattedList($sel2[$main]);
                 $sel2[$main] = array('' => ts("- Any -")) + $relName;
             } else {
                 $sel2[$main] = array('' => ts("- Any -")) + $sel2[$main];
             }
         }
     }
     $cSubTypes = CRM_Core_Component::contactSubTypes();
     if (!empty($cSubTypes)) {
         $contactSubTypes = array();
         foreach ($cSubTypes as $key => $value) {
             $contactSubTypes[$key] = $key;
         }
         $sel2['Contact'] = array("" => "- Any -") + $contactSubTypes;
     } else {
         if (!isset($this->_id)) {
             $formName = 'document.forms.' . $this->_name;
             $js = "<script type='text/javascript'>\n";
             $js .= "{$formName}['extends_1'].style.display = 'none';\n";
             $js .= "</script>";
             $this->assign('initHideBlocks', $js);
         }
     }
     $sel =& $this->add('hierselect', 'extends', ts('Used For'), array('name' => 'extends[0]', 'style' => 'vertical-align: top;'), TRUE);
     $sel->setOptions(array($sel1, $sel2));
     if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) {
         // make second selector a multi-select -
         $sel->_elements[1]->setMultiple(TRUE);
         $sel->_elements[1]->setSize(5);
     }
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $subName = CRM_Utils_Array::value('extends_entity_column_id', $this->_defaults);
         if ($this->_defaults['extends'] == 'Participant') {
             if ($subName == 1) {
                 $this->_defaults['extends'] = 'ParticipantRole';
             } elseif ($subName == 2) {
                 $this->_defaults['extends'] = 'ParticipantEventName';
             } elseif ($subName == 3) {
                 $this->_defaults['extends'] = 'ParticipantEventType';
             }
         }
         //allow to edit settings if custom set is empty CRM-5258
         $this->_isGroupEmpty = CRM_Core_BAO_CustomGroup::isGroupEmpty($this->_id);
         if (!$this->_isGroupEmpty) {
             if (!empty($this->_subtypes)) {
                 // we want to allow adding / updating subtypes for this case,
                 // and therefore freeze the first selector only.
                 $sel->_elements[0]->freeze();
             } else {
                 // freeze both the selectors
                 $sel->freeze();
             }
         }
         $this->assign('isCustomGroupEmpty', $this->_isGroupEmpty);
         $this->assign('gid', $this->_id);
     }
     $this->assign('defaultSubtypes', json_encode($this->_subtypes));
     // help text
     $this->add('wysiwyg', 'help_pre', ts('Pre-form Help'), $attributes['help_pre']);
     $this->add('wysiwyg', 'help_post', ts('Post-form Help'), $attributes['help_post']);
     // weight
     $this->add('text', 'weight', ts('Order'), $attributes['weight'], TRUE);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     // display style
     $this->add('select', 'style', ts('Display Style'), CRM_Core_SelectValues::customGroupStyle());
     // is this set collapsed or expanded ?
     $this->addElement('checkbox', 'collapse_display', ts('Collapse this set on initial display'));
     // is this set collapsed or expanded ? in advanced search
     $this->addElement('checkbox', 'collapse_adv_display', ts('Collapse this set in Advanced Search'));
     // is this set active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Custom Data Set active?'));
     // does this set have multiple record?
     $multiple = $this->addElement('checkbox', 'is_multiple', ts('Does this Custom Field Set allow multiple records?'), NULL);
     // $min_multiple = $this->add('text', 'min_multiple', ts('Minimum number of multiple records'), $attributes['min_multiple'] );
     // $this->addRule('min_multiple', ts('is a numeric field') , 'numeric');
     $max_multiple = $this->add('text', 'max_multiple', ts('Maximum number of multiple records'), $attributes['max_multiple']);
     $this->addRule('max_multiple', ts('is a numeric field'), 'numeric');
     //allow to edit settings if custom set is empty CRM-5258
     $this->assign('isGroupEmpty', $this->_isGroupEmpty);
     if (!$this->_isGroupEmpty) {
         $multiple->freeze();
         //$min_multiple->freeze();
         $max_multiple->freeze();
     }
     $this->assign('showStyle', FALSE);
     $this->assign('showMultiple', FALSE);
     $buttons = array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')));
     if (!$this->_isGroupEmpty && !empty($this->_subtypes)) {
         $buttons[0]['class'] = 'crm-warnDataLoss';
     }
     $this->addButtons($buttons);
     // TODO: Is this condition ever true? Can this code be removed?
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'"));
     }
 }
Example #7
0
 /**
  * Browse all custom data groups.
  * 
  * @param string $action   the action to be invoked
  * 
  * @return void
  * @access public
  */
 function browse($action = null)
 {
     // get all custom groups sorted by weight
     $customGroup = array();
     $dao =& new CRM_Core_DAO_CustomGroup();
     // set the domain_id parameter
     $config =& CRM_Core_Config::singleton();
     $dao->domain_id = $config->domainID();
     $dao->orderBy('weight, title');
     $dao->find();
     while ($dao->fetch()) {
         $customGroup[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $customGroup[$dao->id]);
         // form all action links
         $action = array_sum(array_keys($this->actionLinks()));
         // update enable/disable links depending on custom_group properties.
         if ($dao->is_active) {
             $action -= CRM_CORE_ACTION_ENABLE;
         } else {
             $action -= CRM_CORE_ACTION_DISABLE;
         }
         $customGroup[$dao->id]['action'] = CRM_Core_Action::formLink(CRM_Custom_Page_Group::actionLinks(), $action, array('id' => $dao->id));
     }
     $customGroupExtends = CRM_Core_SelectValues::customGroupExtends();
     foreach ($customGroup as $key => $array) {
         CRM_Core_DAO_CustomGroup::addDisplayEnums($customGroup[$key]);
         $customGroup[$key]['extends_display'] = $customGroupExtends[$customGroup[$key]['extends']];
     }
     $this->assign('rows', $customGroup);
 }
Example #8
0
 /**
  * Function to actually build the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 public function buildQuickForm()
 {
     $this->applyFilter('__ALL__', 'trim');
     $attributes = CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup');
     //title
     $this->add('text', 'title', ts('Group Name'), $attributes['title'], true);
     $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_DAO_CustomGroup', $this->_id, 'title'));
     //Fix for code alignment, CRM-3058
     require_once "CRM/Contribute/PseudoConstant.php";
     require_once "CRM/Member/BAO/MembershipType.php";
     require_once 'CRM/Event/PseudoConstant.php';
     require_once "CRM/Contact/BAO/Relationship.php";
     require_once 'CRM/Core/OptionGroup.php';
     require_once 'CRM/Contact/BAO/ContactType.php';
     $contactTypes = array('Contact', 'Individual', 'Household', 'Organization');
     $this->assign('contactTypes', json_encode($contactTypes));
     $sel1 = array("" => "- select -") + CRM_Core_SelectValues::customGroupExtends();
     $sel2 = array();
     $activityType = CRM_Core_PseudoConstant::activityType(false, true);
     $eventType = CRM_Core_OptionGroup::values('event_type');
     $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypes(false);
     $participantRole = CRM_Core_OptionGroup::values('participant_role');
     $relTypeInd = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Individual');
     $relTypeOrg = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Organization');
     $relTypeHou = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, 'null', null, 'Household');
     ksort($sel1);
     asort($activityType);
     asort($eventType);
     asort($membershipType);
     asort($participantRole);
     $allRelationshipType = array();
     $allRelationshipType = array_merge($relTypeInd, $relTypeOrg);
     $allRelationshipType = array_merge($allRelationshipType, $relTypeHou);
     //adding subtype specific relationships CRM-5256
     $subTypes = CRM_Contact_BAO_ContactType::subTypeInfo();
     foreach ($subTypes as $subType => $val) {
         $subTypeRelationshipTypes = CRM_Contact_BAO_Relationship::getContactRelationshipType(null, null, null, $val['parent'], false, 'label', true, $subType);
         $allRelationshipType = array_merge($allRelationshipType, $subTypeRelationshipTypes);
     }
     $sel2['Event'] = $eventType;
     $sel2['Activity'] = $activityType;
     $sel2['Membership'] = $membershipType;
     $sel2['ParticipantRole'] = $participantRole;
     $sel2['ParticipantEventName'] = CRM_Event_PseudoConstant::event(null, false, "( is_template IS NULL OR is_template != 1 )");
     $sel2['ParticipantEventType'] = $eventType;
     $sel2['Contribution'] = CRM_Contribute_PseudoConstant::contributionType();
     $sel2['Relationship'] = $allRelationshipType;
     $sel2['Individual'] = CRM_Contact_BAO_ContactType::subTypePairs('Individual', false, null);
     $sel2['Household'] = CRM_Contact_BAO_ContactType::subTypePairs('Household', false, null);
     $sel2['Organization'] = CRM_Contact_BAO_ContactType::subTypePairs('Organization', false, null);
     foreach ($sel2 as $main => $sub) {
         if (!empty($sel2[$main])) {
             $sel2[$main] = array('' => ts("- Any -")) + $sel2[$main];
         }
     }
     require_once "CRM/Core/Component.php";
     $cSubTypes = CRM_Core_Component::contactSubTypes();
     if (!empty($cSubTypes)) {
         $contactSubTypes = array();
         foreach ($cSubTypes as $key => $value) {
             $contactSubTypes[$key] = $key;
         }
         $sel2['Contact'] = array("" => "-- Any --") + $contactSubTypes;
     } else {
         if (!isset($this->_id)) {
             $formName = 'document.forms.' . $this->_name;
             $js = "<script type='text/javascript'>\n";
             $js .= "{$formName}['extends[1]'].style.display = 'none';\n";
             $js .= "</script>";
             $this->assign('initHideBlocks', $js);
         }
     }
     $sel =& $this->add('hierselect', 'extends', ts('Used For'), array('onClick' => 'showHideStyle();', 'name' => 'extends[0]', 'style' => 'vertical-align: top;'), true);
     $sel->setOptions(array($sel1, $sel2));
     if (is_a($sel->_elements[1], 'HTML_QuickForm_select')) {
         // make second selector a multi-select -
         $sel->_elements[1]->setMultiple(true);
         $sel->_elements[1]->setSize(5);
     }
     if ($this->_action == CRM_Core_Action::UPDATE) {
         //allow to edit settings if custom group is empty CRM-5258
         $this->_isGroupEmpty = CRM_Core_BAO_CustomGroup::isGroupEmpty($this->_id);
         if (!$this->_isGroupEmpty) {
             if (!empty($this->_subtypes) && count(array_intersect($this->_subtypes, $sel2[$this->_defaults['extends']])) < count($sel2[$this->_defaults['extends']])) {
                 // we want to allow adding subtypes for this case,
                 // and therefore freeze the first selector only.
                 $sel->_elements[0]->freeze();
             } else {
                 // freeze both the selectors
                 $sel->freeze();
             }
         }
         $this->assign('gid', $this->_id);
     }
     // help text
     $this->addWysiwyg('help_pre', ts('Pre-form Help'), $attributes['help_pre']);
     $this->addWysiwyg('help_post', ts('Post-form Help'), $attributes['help_post']);
     // weight
     $this->add('text', 'weight', ts('Order'), $attributes['weight'], true);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     // display style
     $this->add('select', 'style', ts('Display Style'), CRM_Core_SelectValues::customGroupStyle());
     // is this group collapsed or expanded ?
     $this->addElement('checkbox', 'collapse_display', ts('Collapse this group on initial display'));
     // is this group collapsed or expanded ? in advanced search
     $this->addElement('checkbox', 'collapse_adv_display', ts('Collapse this group in Advanced Search'));
     // is this group active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Custom Data Group active?'));
     // does this group have multiple record?
     $multiple = $this->addElement('checkbox', 'is_multiple', ts('Does this Custom Data Group allow multiple records?'), null, array('onclick' => "showRange();"));
     // $min_multiple = $this->add('text', 'min_multiple', ts('Minimum number of multiple records'), $attributes['min_multiple'] );
     // $this->addRule('min_multiple', ts('is a numeric field') , 'numeric');
     $max_multiple = $this->add('text', 'max_multiple', ts('Maximum number of multiple records'), $attributes['max_multiple']);
     $this->addRule('max_multiple', ts('is a numeric field'), 'numeric');
     //allow to edit settings if custom group is empty CRM-5258
     $this->assign('isGroupEmpty', $this->_isGroupEmpty);
     if (!$this->_isGroupEmpty) {
         $multiple->freeze();
         //$min_multiple->freeze();
         $max_multiple->freeze();
     }
     $this->assign('showStyle', false);
     $this->assign('showMultiple', false);
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // views are implemented as frozen form
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'"));
     }
 }
Example #9
0
 /**
  * Function to actually build the form
  * 
  * @param null
  * 
  * @return void
  * @access public
  */
 function buildQuickForm()
 {
     $this->applyFilter('__ALL__', 'trim');
     // title
     $this->add('text', 'title', ts('Group Name'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup', 'title'), true);
     $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Core_DAO_CustomGroup', $this->_id, 'title'));
     // which entity is this custom data group for ?
     // for update action only allowed if there are no custom values present for this group.
     $extendsElement = $this->add('select', 'extends', ts('Used For'), CRM_Core_SelectValues::customGroupExtends());
     if ($this->_action == CRM_CORE_ACTION_UPDATE) {
         $extendsElement->freeze();
         $this->assign('gid', $this->_id);
     }
     // help text
     $this->add('textarea', 'help_pre', ts('Pre-form Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup', 'help_pre'));
     $this->add('textarea', 'help_post', ts('Post-form Help'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup', 'help_post'));
     // weight
     $this->add('text', 'weight', ts('Weight'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_CustomGroup', 'weight'), true);
     $this->addRule('weight', ts(' is a numeric field'), 'numeric');
     // display style
     $this->add('select', 'style', ts('Display Style'), CRM_Core_SelectValues::customGroupStyle());
     // is this group collapsed or expanded ?
     $this->addElement('checkbox', 'collapse_display', ts('Collapse this group on initial display'));
     // is this group active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Custom Data Group active?'));
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // views are implemented as frozen form
     if ($this->_action & CRM_CORE_ACTION_VIEW) {
         $this->freeze();
         $this->addElement('button', 'done', ts('Done'), array('onClick' => "location.href='civicrm/admin/custom/group?reset=1&action=browse'"));
     }
 }