/**
  * Get a list of Backbone-Form models
  *
  * @param array $entityTypes model names ("IndividualModel")
  * @return array; keys are model names ("IndividualModel") and values describe 'sections' and 'schema'
  * @see js/model/crm.core.js
  * @see js/model/crm.mappedcore.js
  */
 static function getSchema($entityTypes)
 {
     // FIXME: Depending on context (eg civicrm/profile/create vs search-columns), it may be appropriate to
     // pick importable or exportable fields
     $entityTypes = array_unique($entityTypes);
     $availableFields = NULL;
     foreach ($entityTypes as $entityType) {
         if (!$availableFields) {
             $availableFields = CRM_Core_BAO_UFField::getAvailableFieldsFlat();
             //dpm($availableFields);
         }
         switch ($entityType) {
             case 'IndividualModel':
                 $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Individual', ts('Individual'), $availableFields);
                 break;
             case 'ActivityModel':
                 $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Activity', ts('Activity'), $availableFields);
                 break;
             case 'ContributionModel':
                 $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Contribution', ts('Contribution'), $availableFields);
                 break;
             case 'MembershipModel':
                 $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Membership', ts('Membership'), $availableFields);
                 break;
             case 'ParticipantModel':
                 $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Participant', ts('Participant'), $availableFields);
                 break;
             default:
                 throw new CRM_Core_Exception("Unrecognized entity type: {$entityType}");
         }
     }
     return $civiSchema;
 }
Esempio n. 2
0
 /**
  * Get a list of Backbone-Form models
  *
  * @param array $entityTypes
  *   Model names ("IndividualModel").
  *
  * @throws CRM_Core_Exception
  * @return array; keys are model names ("IndividualModel") and values describe 'sections' and 'schema'
  * @see js/model/crm.core.js
  * @see js/model/crm.mappedcore.js
  */
 public static function getSchema($entityTypes)
 {
     // FIXME: Depending on context (eg civicrm/profile/create vs search-columns), it may be appropriate to
     // pick importable or exportable fields
     $entityTypes = array_unique($entityTypes);
     $availableFields = NULL;
     $civiSchema = array();
     foreach ($entityTypes as $entityType) {
         if (!$availableFields) {
             $availableFields = CRM_Core_BAO_UFField::getAvailableFieldsFlat();
         }
         switch ($entityType) {
             case 'IndividualModel':
                 $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Individual', ts('Individual'), $availableFields);
                 break;
             case 'OrganizationModel':
                 $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Organization', ts('Organization'), $availableFields);
                 break;
             case 'HouseholdModel':
                 $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Household', ts('Household'), $availableFields);
                 break;
             case 'ActivityModel':
                 $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Activity', ts('Activity'), $availableFields);
                 break;
             case 'ContributionModel':
                 $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Contribution', ts('Contribution'), $availableFields);
                 break;
             case 'MembershipModel':
                 $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Membership', ts('Membership'), $availableFields);
                 break;
             case 'ParticipantModel':
                 $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Participant', ts('Participant'), $availableFields);
                 break;
             case 'CaseModel':
                 $civiSchema[$entityType] = self::convertCiviModelToBackboneModel('Case', ts('Case'), $availableFields);
                 break;
             default:
                 throw new CRM_Core_Exception("Unrecognized entity type: {$entityType}");
         }
     }
     // Adding the oddball "formatting" field here because there's no other place to put it
     foreach (array('Individual', 'Organization', 'Household') as $type) {
         if (isset($civiSchema[$type . 'Model'])) {
             $civiSchema[$type . 'Model']['schema'] += array('formatting' => array('type' => 'Markup', 'title' => ts('Free HTML'), 'civiFieldType' => 'Formatting', 'section' => 'formatting'));
             $civiSchema[$type . 'Model']['sections'] += array('formatting' => array('title' => ts('Formatting'), 'is_addable' => FALSE));
         }
     }
     return $civiSchema;
 }
/**
 * Flush static caches in functions that might have stored available custom fields
 */
function _civicrm_api3_custom_field_flush_static_caches()
{
    civicrm_api('custom_field', 'getfields', array('version' => 3, 'cache_clear' => 1));
    CRM_Core_BAO_UFField::getAvailableFieldsFlat(TRUE);
}
Esempio n. 4
0
 /**
  * Determine whether the given field_name is valid.
  *
  * @param string $fieldName
  * @return bool
  */
 public static function isValidFieldName($fieldName)
 {
     $availableFields = CRM_Core_BAO_UFField::getAvailableFieldsFlat();
     return isset($availableFields[$fieldName]);
 }
Esempio n. 5
0
 /**
  * When omitting a GID, return a list of all fields.
  */
 public function testGetAvailableFlat()
 {
     $fields = CRM_Core_BAO_UFField::getAvailableFieldsFlat();
     // Make sure that each entity appears with at least one field
     $this->assertEquals('Contact', $fields['do_not_sms']['field_type']);
     $this->assertEquals('Contact', $fields['city']['field_type']);
     $this->assertEquals('Individual', $fields['first_name']['field_type']);
     $this->assertEquals('Individual', $fields['birth_date']['field_type']);
     $this->assertEquals('Organization', $fields['organization_name']['field_type']);
     $this->assertEquals('Organization', $fields['legal_name']['field_type']);
     $this->assertEquals('Contribution', $fields['amount_level']['field_type']);
     $this->assertEquals('Contribution', $fields['cancel_reason']['field_type']);
     $this->assertEquals('Participant', $fields['participant_note']['field_type']);
     $this->assertEquals('Participant', $fields['participant_role']['field_type']);
     $this->assertEquals('Membership', $fields['join_date']['field_type']);
     $this->assertEquals('Membership', $fields['membership_end_date']['field_type']);
     $this->assertEquals('Activity', $fields['activity_date_time']['field_type']);
     $this->assertEquals('Activity', $fields['activity_subject']['field_type']);
     // Make sure that some of the blacklisted fields don't appear
     $this->assertFalse(isset($fields['is_pay_later']));
     $this->assertFalse(isset($fields['participant_role_id']));
     $this->assertFalse(isset($fields['membership_type_id']));
 }
/**
 * Create the custom fields used to record subject and body
 *
 */
function petitionemail_create_custom_fields()
{
    $group = 'petitionemail';
    $key = 'petitionemail_custom_message_fields';
    $ret = CRM_Core_BAO_Setting::getItem($group, $key);
    if (!empty($ret)) {
        // Ensure it exists
        $sql = "SELECT id FROM civicrm_custom_group WHERE id = %0";
        $dao = CRM_Core_DAO::executeQuery($sql, array(0 => array($ret, 'Integer')));
        $dao->fetch();
        if ($dao->N == 1) {
            return $ret;
        }
        // Delete this variable - probably the user deleted the profile not knowing
        // what it was used for.
        $sql = "DELETE FROM civicrm_setting WHERE group_name = %0 AND name = %1";
        $params = array(0 => array($group, 'String'), 1 => array($key, 'String'));
        CRM_Core_DAO::executeQuery($sql, $params);
    }
    // Get the value of the petition activity id so our custom group
    // will only extend Activities of type Petition.
    $sql = "SELECT v.value FROM civicrm_option_group g JOIN \n    civicrm_option_value v ON g.id = v.option_group_id WHERE g.name = 'activity_type'\n    AND v.name = 'petition'";
    $dao = CRM_Core_DAO::executeQuery($sql);
    $dao->fetch();
    if ($dao->N > 0) {
        $activity_type_id = $dao->value;
        $params = array('version' => 3, 'name' => 'PetitionEmailMessageFields', 'title' => 'Petition Email Message Fields', 'extends' => 'Activity', 'extends_entity_column_value' => array($activity_type_id), 'style' => 'Inline', 'collapse_display' => 1, 'is_active' => 1, 'api.custom_field.create' => array(array('custom_group_id' => '$value.id', 'label' => 'Custom Message', 'name' => 'Petition_Email_Custom_Message', 'data_type' => 'Memo', 'html_type' => 'TextArea', 'is_required' => 0, 'is_searchable' => 0, 'is_active' => 1), array('custom_group_id' => '$value.id', 'label' => 'Custom Subject', 'name' => 'Petition_Email_Custom_Subject', 'data_type' => 'String', 'html_type' => 'Text', 'is_required' => 0, 'is_searchable' => 0, 'is_active' => 1)));
        try {
            $results = civicrm_api3('CustomGroup', 'create', $params);
        } catch (CiviCRM_API3_Exception $e) {
            $session = CRM_Core_Session::singleton();
            $session->setStatus(ts("Error creating the petition custom fields."));
            $session->setStatus($e->getMessage());
            return FALSE;
        }
        $values = array_pop($results['values']);
        $id = $values['id'];
        CRM_Core_BAO_Setting::setItem($id, $group, $key);
        // Start complex process for clearing the cache of available fields.
        // We need to clear the cache so that when we create a profile that
        // depends on these fields, we won't get an error that it's an invalid field.
        // First clear the static array of exportableFields which is used to determine
        // if a field is valid when being used in a profile.
        CRM_Activity_BAO_Activity::$_exportableFields = NULL;
        // Next clear the cache so we don't pull from an already populated cache.
        CRM_Utils_System::flushCache();
        // Lastly, we have to call the function that is called to validate fields,
        // but specifying that we want to force the re-fecthing of fields to unset
        // yet another static variable.
        CRM_Core_BAO_UFField::getAvailableFieldsFlat(TRUE);
        return $id;
    }
    return FALSE;
}