/** * Function to return singleton object * * @return object $_singleton * @access public * @static */ public static function &singleton($contact_id) { if (self::$_singleton === NULL) { self::$_singleton = new CRM_Lidmaatschapwijziging_ConfigRegistratieOpleidingBelangstelling($contact_id); } return self::$_singleton; }
function postProcess() { $values = $this->exportValues(); $this->_configRegiOplBel = CRM_Lidmaatschapwijziging_ConfigRegistratieOpleidingBelangstelling::singleton($this->_contactId); // api create custom value try { $params = array('version' => 3, 'sequential' => 1, 'entity_id' => $this->_contactId); // for the custom values, the need to be like custom_35, and // other ajustments for checkboxes and advanced select $regiOplBelFields = $this->_configRegiOplBel->getRegiOplBelCustomFieldsByName(); $regiOplBelFieldsOptions = $this->_configRegiOplBel->getRegiOplBelCustomFieldsOptionValues(); foreach ($regiOplBelFields as $key => $field) { switch ($field['name']) { case 'Vliegschool': case 'Vooropleiding': case 'Overige_opleiding': $params['custom_' . $field['id']] = array(); // set it empty, if there is no values it will be empty, or else the field wound not be empty // if there is a value submitted, than the checkboxes with name exist and have a // value of 1, the 1 must be the value of the chekcbox (the same as the name of the option) if (isset($values[$field['name']]) and !empty($values[$field['name']])) { foreach ($values[$field['name']] as $option_name => $boolean) { $params['custom_' . $field['id']][$option_name] = $option_name; } } break; case 'Algemene_onderwerpen': case 'Commissies': case 'Groepscommissie': $params['custom_' . $field['id']] = array(); // set it empty, if there is no values it will be empty, or else the field wound not be empty // the advanced select have a array like [0 => label, 1 => label], and it // must be [name => name, name => name] if (isset($values[$field['name']]) and !empty($values[$field['name']])) { foreach ($values[$field['name']] as $key => $label) { // get the value from the option label foreach ($regiOplBelFieldsOptions[$field['name']] as $id => $option) { if ($label == $option['label']) { // if he found the correct option $params['custom_' . $field['id']][$option['value']] = $option['value']; } } } } break; default: if (isset($values[$field['name']])) { $params['custom_' . $field['id']] = $values[$field['name']]; } } } // set checkboxes // set if not exist if (!isset($values['is_permission_a_b'])) { $values['is_permission_a_b'] = '0'; } $result = civicrm_api('CustomValue', 'create', $params); // check no error if (isset($result['is_error']) and !$result['is_error']) { // if there is no error // set message $session = CRM_Core_Session::singleton(); $session->setStatus(ts('%1 is opgeslagen !', $this->_display_name), ts('Lidmaatschap Wijziging - Registratie Opleiding Belasngstelling'), 'success'); $session->setStatus(ts('Lidmaatschap wijziging van %1 is klaar !', $this->_display_name), ts('Lidmaatschap Wijziging - Klaar'), 'success'); // redirect user $url = CRM_Utils_System::url('civicrm/contact/view', 'reset=1&cid=' . $this->_contactId); CRM_Utils_System::redirect($url); } else { // if there is a error // set message $session = CRM_Core_Session::singleton(); $session->setStatus(sprintf(ts('%s is niet opgeslagen !'), $this->_display_name), ts('Lidmaatschap Wijziging - Registratie Opleiding Belasngstelling'), 'error'); // redirect user $url = CRM_Utils_System::url('civicrm/lidmaatschapwijziging/registratieopleidingbelangstelling', 'reset=1&cid=' . $this->_contactId); CRM_Utils_System::redirect($url); } } catch (CiviCRM_API3_Exception $ex) { throw new Exception('Could not create registratie opleiding belangstelling, ' . 'error from Api CustomValue create: ' . $ex->getMessage()); } //parent::postProcess(); }