Example #1
0
 /**
  * This function sets the default values for the form. Note that in edit/view mode
  * the default values are retrieved from the database
  * 
  * @access public
  * @return None
  */
 function setDefaultValues()
 {
     $defaults = array();
     $params = array();
     if ($this->_action & CRM_CORE_ACTION_ADD) {
         // set group and tag defaults if any
         if ($this->_gid) {
             $defaults['group'][$this->_gid] = 1;
         }
         if ($this->_tid) {
             $defaults['tag'][$this->_tid] = 1;
         }
         if (CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS >= 1) {
             // set the is_primary location for the first location
             $defaults['location'] = array();
             $locationTypeKeys = array_filter(array_keys(CRM_Core_PseudoConstant::locationType()), 'is_int');
             sort($locationTypeKeys);
             // also set the location types for each location block
             for ($i = 0; $i < CRM_CONTACT_FORM_EDIT_LOCATION_BLOCKS; $i++) {
                 $defaults['location'][$i + 1] = array();
                 //$defaults['location'][$i+1]['location_type_id'] = $locationTypeKeys[$i];
                 if ($i == 0) {
                     $defaultLocation =& new CRM_Core_BAO_LocationType();
                     $locationType = $defaultLocation->getDefault();
                     $defaults['location'][$i + 1]['location_type_id'] = $locationType->id;
                 } else {
                     $defaults['location'][$i + 1]['location_type_id'] = $locationTypeKeys[$i];
                 }
                 $defaults['location'][$i + 1]['address'] = array();
                 $config =& CRM_Core_Config::singleton();
                 $countryIsoCodes =& CRM_Core_PseudoConstant::countryIsoCode();
                 $defaultCountryId = array_search($config->defaultContactCountry, $countryIsoCodes);
                 $defaults['location'][$i + 1]['address']['country_id'] = $defaultCountryId;
             }
             $defaults['location'][1]['is_primary'] = true;
         }
     } else {
         // this is update mode
         // get values from contact table
         $params['id'] = $params['contact_id'] = $this->_contactId;
         $ids = array();
         $contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults, $ids);
         $this->set('ids', $ids);
         $this->assign('contactId', $this->_contactId);
         // also set contact_type, since this is used in showHide routines
         // to decide whether to display certain blocks (demographics)
         $this->_contactType = CRM_Utils_Array::value('contact_type', $defaults);
         // set the group and tag ids
         CRM_Contact_Form_GroupTag::setDefaults($this->_contactId, $defaults, CRM_CONTACT_FORM_GROUPTAG_ALL);
     }
     // use most recently posted values if any to display show hide blocks
     $params = $this->controller->exportValues($this->_name);
     if (!empty($params)) {
         $this->setShowHide($params, true);
     } else {
         $this->setShowHide($defaults, false);
     }
     // do we need inactive options ?
     if ($this->_action & (CRM_CORE_ACTION_VIEW | CRM_CORE_ACTION_BROWSE)) {
         $inactiveNeeded = true;
         $viewMode = true;
     } else {
         $viewMode = false;
         $inactiveNeeded = false;
     }
     CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, $viewMode, $inactiveNeeded);
     return $defaults;
 }
Example #2
0
 /**
  * This functions sets the default values for a contact and is invoked by the inherited classes
  *
  * @access protected 
  * @return array the default array reference 
  */
 function &setContactValues()
 {
     $defaults = array();
     if ($this->_contact) {
         foreach ($this->_fields as $name => $field) {
             $objName = $field['name'];
             if ($objName == 'state_province') {
                 $states =& CRM_Core_PseudoConstant::stateProvince();
                 if ($this->_contact->state_province) {
                     $defaults[$name] = array_search($this->_contact->state_province, $states);
                 }
             } else {
                 if ($objName == 'country') {
                     $country =& CRM_Core_PseudoConstant::country();
                     if ($this->_contact->country) {
                         $defaults[$name] = array_search($this->_contact->country, $country);
                     }
                 } else {
                     if ($objName == 'gender') {
                         if ($this->_contact->gender_id) {
                             $defaults[$name] = $this->_contact->gender_id;
                         }
                     } else {
                         if ($objName == 'group') {
                             CRM_Contact_Form_GroupTag::setDefaults($this->_id, $defaults, CRM_CONTACT_FORM_GROUPTAG_GROUP);
                         } else {
                             if ($objName == 'tag') {
                                 CRM_Contact_Form_GroupTag::setDefaults($this->_id, $defaults, CRM_CONTACT_FORM_GROUPTAG_TAG);
                             } else {
                                 if ($cfID = CRM_Core_BAO_CustomField::getKeyID($objName)) {
                                     CRM_Core_BAO_CustomField::setProfileDefaults($cfID, $name, $defaults, $this->_id, $this->_mode);
                                 } else {
                                     $defaults[$name] = $this->_contact->{$objName};
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
     return $defaults;
 }