/** * Build the form object. */ public function buildQuickForm() { if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } // Select list $relationshipList = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactId, $this->_rtype, $this->_relationshipId); // Metadata needed on clientside $contactTypes = CRM_Contact_BAO_ContactType::contactTypeInfo(TRUE); $jsData = array(); // Get just what we need to keep the dom small $whatWeWant = array_flip(array('contact_type_a', 'contact_type_b', 'contact_sub_type_a', 'contact_sub_type_b')); foreach ($this->_allRelationshipNames as $id => $vals) { if ($vals['name_a_b'] === 'Employee of') { $this->assign('employmentRelationship', $id); } if (isset($relationshipList["{$id}_a_b"]) || isset($relationshipList["{$id}_b_a"])) { $jsData[$id] = array_filter(array_intersect_key($this->_allRelationshipNames[$id], $whatWeWant)); // Add user-friendly placeholder foreach (array('a', 'b') as $x) { $type = !empty($jsData[$id]["contact_sub_type_{$x}"]) ? $jsData[$id]["contact_sub_type_{$x}"] : CRM_Utils_Array::value("contact_type_{$x}", $jsData[$id]); $jsData[$id]["placeholder_{$x}"] = $type ? ts('- select %1 -', array(strtolower($contactTypes[$type]['label']))) : ts('- select contact -'); } } } $this->assign('relationshipData', $jsData); $this->addField('relationship_type_id', array('options' => array('' => ts('- select -')) + $relationshipList, 'class' => 'huge', 'placeholder' => '- select -'), TRUE); $label = $this->_action & CRM_Core_Action::ADD ? ts('Contact(s)') : ts('Contact'); $contactField = $this->addField('related_contact_id', array('label' => $label, 'name' => 'contact_id_b', 'multiple' => TRUE, 'create' => TRUE), TRUE); // This field cannot be updated if ($this->_action & CRM_Core_Action::UPDATE) { $contactField->freeze(); } $this->add('advcheckbox', 'is_current_employer', $this->_contactType == 'Organization' ? ts('Current Employee') : ts('Current Employer')); $this->addField('start_date', array('label' => ts('Start Date'), 'formatType' => 'searchDate')); $this->addField('end_date', array('label' => ts('End Date'), 'formatType' => 'searchDate')); $this->addField('is_active', array('label' => ts('Enabled?'))); $this->addField('is_permission_a_b'); $this->addField('is_permission_b_a'); $this->addField('description', array('label' => ts('Description'))); CRM_Contact_Form_Edit_Notes::buildQuickForm($this); if ($this->_action & CRM_Core_Action::VIEW) { $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done')))); } else { // make this form an upload since we don't know if the custom data injected dynamically is of type file etc. $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save Relationship'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); } }
/** * Function to build the form * * @return None * @access public */ public function buildQuickForm() { if ($this->_cdType) { return CRM_Custom_Form_CustomData::buildQuickForm($this); } $relTypeID = explode('_', $this->_rtypeId, 3); if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'isDefault' => true), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } $callAjax = $this->get('callAjax'); $searchRows = null; if (!$callAjax) { $searchRows = $this->get('searchRows'); } else { $this->addElement('hidden', 'store_contacts', '', array('id' => 'store_contacts')); $sourceUrl = 'snippet=4&relType=' . $this->get('relType'); $sourceUrl .= '&relContact=' . $this->get('relContact'); $sourceUrl .= '&cid=' . $this->_contactId; $this->assign('searchCount', true); // To handle employee of and employer of if (!empty($this->_relationshipTypeId) && !empty($this->_rtype)) { $sourceUrl .= '&typeName=' . $this->_allRelationshipNames[$this->_relationshipTypeId]["name_{$this->_rtype}"]; } $this->assign('sourceUrl', CRM_Utils_System::url('civicrm/ajax/relationshipcontacts', $sourceUrl, false, null, false)); } $this->assign('callAjax', $callAjax); $this->_callAjax = $callAjax; $this->addElement('select', 'relationship_type_id', ts('Relationship Type'), array('' => ts('- select -')) + CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactId, $this->_rtype, $this->_relationshipId, null, false, 'label')); // add a ajax facility for searching contacts $dataUrl = CRM_Utils_System::url("civicrm/ajax/search", "reset=1", true, null, false); $this->assign('dataUrl', $dataUrl); $this->add('text', 'rel_contact', ts('Find Target Contact')); $this->add('hidden', "rel_contact_id"); $this->addDate('start_date', ts('Start Date'), false, array('formatType' => 'searchDate')); $this->addDate('end_date', ts('End Date'), false, array('formatType' => 'searchDate')); $this->addElement('advcheckbox', 'is_active', ts('Enabled?'), null, 'setChecked()'); $this->addElement('checkbox', 'is_permission_a_b', ts('Permission for contact a to view and update information for contact b'), null); $this->addElement('checkbox', 'is_permission_b_a', ts('permission for contact b to view and update information for contact a'), null); $this->add('text', 'description', ts('Description'), CRM_Core_DAO::getAttribute('CRM_Contact_DAO_Relationship', 'description')); CRM_Contact_Form_Edit_Notes::buildQuickForm($this); $searchCount = $this->get('searchCount'); $duplicateRelationship = $this->get('duplicateRelationship'); $searchDone = $this->get('searchDone'); $isEmployeeOf = $isEmployerOf = false; if (!empty($this->_relationshipTypeId) && !empty($this->_rtype)) { if ($this->_allRelationshipNames[$this->_relationshipTypeId]["name_{$this->_rtype}"] == 'Employee of') { $isEmployeeOf = true; } else { if ($this->_allRelationshipNames[$this->_relationshipTypeId]["name_{$this->_rtype}"] == 'Employer of') { $isEmployerOf = true; } } } $employers = $checkBoxes = $employees = array(); if ($searchRows) { foreach ($searchRows as $id => $row) { $checkBoxes[$id] = $this->createElement('checkbox', $id, null, ''); if ($isEmployeeOf) { $employers[$id] = $this->createElement('radio', null, $id, null, $id); } else { if ($isEmployerOf) { $employees[$id] = $this->createElement('checkbox', $id, null, ''); } } } $this->addGroup($checkBoxes, 'contact_check'); $this->assign('searchRows', $searchRows); } if ($isEmployeeOf) { $this->assign('isEmployeeOf', $isEmployeeOf); if (!$callAjax) { $this->addGroup($employers, 'employee_of'); } } else { if ($isEmployerOf) { $this->assign('isEmployerOf', $isEmployerOf); if (!$callAjax) { $this->addGroup($employees, 'employer_of'); } } } if ($callAjax && ($isEmployeeOf || $isEmployerOf)) { $this->addElement('hidden', 'store_employers', '', array('id' => 'store_employers')); } if ($this->_action & CRM_Core_Action::UPDATE) { $this->addElement('checkbox', 'is_current_employer'); } $this->assign('duplicateRelationship', $duplicateRelationship); $this->assign('searchCount', $searchCount); $this->assign('searchDone', $searchDone); if ($this->get('contact_type')) { require_once 'CRM/Contact/BAO/ContactType.php'; $typeLabel = CRM_Contact_BAO_ContactType::getLabel($this->get('contact_type')); $this->assign('contact_type', $this->get('contact_type')); $this->assign('contact_type_display', $typeLabel); } if ($searchDone) { $searchBtn = ts('Search Again'); } else { $searchBtn = ts('Search'); } $this->addElement('submit', $this->getButtonName('refresh'), $searchBtn, array('class' => 'form-submit', 'id' => 'search-button')); $this->addElement('submit', $this->getButtonName('refresh', 'save'), 'Quick Save', array('class' => 'form-submit', 'id' => 'quick-save')); $this->addElement('submit', $this->getButtonName('cancel'), ts('Cancel'), array('class' => 'form-submit')); $this->addElement('submit', $this->getButtonName('refresh', 'savedetails'), 'Save Relationship', array('class' => 'form-submit hiddenElement', 'id' => 'details-save')); $this->addElement('checkbox', 'add_current_employer', ts('Current Employer'), null); $this->addElement('checkbox', 'add_current_employee', ts('Current Employee'), null); //need to assign custom data type and subtype to the template $this->assign('customDataType', 'Relationship'); $this->assign('customDataSubType', $this->_relationshipTypeId); $this->assign('entityID', $this->_relationshipId); // make this form an upload since we dont know if the custom data injected dynamically // is of type file etc $uploadNames = $this->get( // 'uploadNames' ); $buttonParams = array('type' => 'upload', 'name' => ts('Save Relationship'), 'isDefault' => true); if ($callAjax) { $buttonParams['js'] = array('onclick' => ' submitAjaxData();'); } $this->addButtons(array($buttonParams, array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * Build the form object. */ public function buildQuickForm() { if ($this->_action & CRM_Core_Action::DELETE) { $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); return; } // Select list $relationshipList = CRM_Contact_BAO_Relationship::getContactRelationshipType($this->_contactId, $this->_rtype, $this->_relationshipId); // Metadata needed on clientside $this->assign('relationshipData', self::getRelationshipTypeMetadata($relationshipList)); foreach ($this->_allRelationshipNames as $id => $vals) { if ($vals['name_a_b'] === 'Employee of') { $this->assign('employmentRelationship', $id); break; } } $this->addField('relationship_type_id', array('options' => array('' => ts('- select -')) + $relationshipList, 'class' => 'huge', 'placeholder' => '- select -'), TRUE); $label = $this->_action & CRM_Core_Action::ADD ? ts('Contact(s)') : ts('Contact'); $contactField = $this->addField('related_contact_id', array('label' => $label, 'name' => 'contact_id_b', 'multiple' => TRUE, 'create' => TRUE), TRUE); // This field cannot be updated if ($this->_action & CRM_Core_Action::UPDATE) { $contactField->freeze(); } $this->add('advcheckbox', 'is_current_employer', $this->_contactType == 'Organization' ? ts('Current Employee') : ts('Current Employer')); $this->addField('start_date', array('label' => ts('Start Date'), 'formatType' => 'searchDate')); $this->addField('end_date', array('label' => ts('End Date'), 'formatType' => 'searchDate')); $this->addField('is_active', array('label' => ts('Enabled?'), 'type' => 'advcheckbox')); $this->addField('is_permission_a_b'); $this->addField('is_permission_b_a'); $this->addField('description', array('label' => ts('Description'))); CRM_Contact_Form_Edit_Notes::buildQuickForm($this); if ($this->_action & CRM_Core_Action::VIEW) { $this->addButtons(array(array('type' => 'cancel', 'name' => ts('Done')))); } else { // make this form an upload since we don't know if the custom data injected dynamically is of type file etc. $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save Relationship'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); } }