diff --git a/CRM/Contact/DAO/Relationship.php b/CRM/Contact/DAO/Relationship.php index 740d0a752548..a04739f0d58a 100644 --- a/CRM/Contact/DAO/Relationship.php +++ b/CRM/Contact/DAO/Relationship.php @@ -6,7 +6,7 @@ * * Generated from xml/schema/CRM/Contact/Relationship.xml * DO NOT EDIT. Generated by CRM_Core_CodeGen - * (GenCodeChecksum:49381da59affbf165a4c9ce87c9a68ec) + * (GenCodeChecksum:ce5f84e10ef36ac340837227265123a4) */ /** @@ -203,6 +203,7 @@ public static function &fields() { 'localizable' => 0, 'html' => [ 'type' => 'Select Date', + 'formatType' => 'activityDate', ], ], 'end_date' => [ @@ -216,6 +217,7 @@ public static function &fields() { 'localizable' => 0, 'html' => [ 'type' => 'Select Date', + 'formatType' => 'activityDate', ], ], 'is_active' => [ diff --git a/CRM/Contact/Form/Relationship.php b/CRM/Contact/Form/Relationship.php index 73aae1120140..186620dbec1f 100644 --- a/CRM/Contact/Form/Relationship.php +++ b/CRM/Contact/Form/Relationship.php @@ -212,18 +212,13 @@ public function preProcess() { * Set default values for the form. */ public function setDefaultValues() { - $defaults = array(); if ($this->_action & CRM_Core_Action::UPDATE) { if (!empty($this->_values)) { $defaults['relationship_type_id'] = $this->_rtypeId; - if (!empty($this->_values['start_date'])) { - list($defaults['start_date']) = CRM_Utils_Date::setDateDefaults($this->_values['start_date']); - } - if (!empty($this->_values['end_date'])) { - list($defaults['end_date']) = CRM_Utils_Date::setDateDefaults($this->_values['end_date']); - } + $defaults['start_date'] = CRM_Utils_Array::value('start_date', $this->_values); + $defaults['end_date'] = CRM_Utils_Array::value('end_date', $this->_values); $defaults['description'] = CRM_Utils_Array::value('description', $this->_values); $defaults['is_active'] = CRM_Utils_Array::value('is_active', $this->_values); @@ -271,7 +266,6 @@ public function setDefaultValues() { * Add the rules for form. */ public function addRules() { - if (!($this->_action & CRM_Core_Action::DELETE)) { $this->addFormRule(array('CRM_Contact_Form_Relationship', 'dateRule')); } @@ -335,8 +329,8 @@ public function buildQuickForm() { $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('start_date', array('label' => ts('Start Date')), FALSE, FALSE); + $this->addField('end_date', array('label' => ts('End Date')), FALSE, FALSE); $this->addField('is_active', array('label' => ts('Enabled?'), 'type' => 'advcheckbox')); @@ -373,9 +367,11 @@ public function buildQuickForm() { /** * This function is called when the form is submitted and also from unit test. + * * @param array $params * * @return array + * @throws \CRM_Core_Exception */ public function submit($params) { switch ($this->getAction()) { @@ -425,7 +421,6 @@ public function postProcess() { '#tab_contribute' => CRM_Contact_BAO_Contact::getCountComponent('contribution', $this->_contactId), ), ); - } /** @@ -442,9 +437,7 @@ public static function dateRule($params) { // check start and end date if (!empty($params['start_date']) && !empty($params['end_date'])) { - $start_date = CRM_Utils_Date::format(CRM_Utils_Array::value('start_date', $params)); - $end_date = CRM_Utils_Date::format(CRM_Utils_Array::value('end_date', $params)); - if ($start_date && $end_date && (int ) $end_date < (int ) $start_date) { + if ($params['end_date'] < $params['start_date']) { $errors['end_date'] = ts('The relationship end date cannot be prior to the start date.'); } } @@ -494,6 +487,7 @@ protected function setMessage($outcome) { /** * @param $relationshipList + * * @return array */ public static function getRelationshipTypeMetadata($relationshipList) { @@ -539,11 +533,10 @@ private function deleteAction($id) { * @param array $params * * @return array + * @throws \CRM_Core_Exception */ private function updateAction($params) { - $params = $this->preparePostProcessParameters($params); - $params = $params[0]; - + list($params, $_) = $this->preparePostProcessParameters($params); try { civicrm_api3('relationship', 'create', $params); } @@ -561,6 +554,7 @@ private function updateAction($params) { * @param array $params * * @return array + * @throws \CRM_Core_Exception */ private function createAction($params) { list($params, $primaryContactLetter) = $this->preparePostProcessParameters($params); @@ -595,12 +589,6 @@ private function preparePostProcessParameters($values) { else { $params['id'] = $this->_relationshipId; $params['contact_id_' . $b] = $params['related_contact_id']; - - foreach (array('start_date', 'end_date') as $dateParam) { - if (!empty($params[$dateParam])) { - $params[$dateParam] = CRM_Utils_Date::processDate($params[$dateParam]); - } - } } // If this is a b_a relationship these form elements are flipped @@ -615,6 +603,8 @@ private function preparePostProcessParameters($values) { * * @param array $relationshipIds * @param string $note + * + * @throws \CiviCRM_API3_Exception */ private function saveRelationshipNotes($relationshipIds, $note) { foreach ($relationshipIds as $id) { diff --git a/templates/CRM/Contact/Form/Relationship.tpl b/templates/CRM/Contact/Form/Relationship.tpl index 23239b69a4ee..4ead58e922d2 100644 --- a/templates/CRM/Contact/Form/Relationship.tpl +++ b/templates/CRM/Contact/Form/Relationship.tpl @@ -101,8 +101,7 @@ {$form.start_date.label} - {include file="CRM/common/jcalendar.tpl" elementName=start_date}{$form.end_date.label} {include file="CRM/common/jcalendar.tpl" elementName=end_date}
- {ts}If this relationship has start and/or end dates, specify them here.{/ts} + {$form.start_date.html} {$form.end_date.label} {$form.end_date.html}
{ts}If this relationship has start and/or end dates, specify them here.{/ts} {$form.description.label} diff --git a/xml/schema/Contact/Relationship.xml b/xml/schema/Contact/Relationship.xml index 03f2a6de2069..ea4daaa03f4d 100644 --- a/xml/schema/Contact/Relationship.xml +++ b/xml/schema/Contact/Relationship.xml @@ -78,6 +78,7 @@ 1.1 Select Date + activityDate @@ -88,6 +89,7 @@ 1.1 Select Date + activityDate