From 6b5f37d3f8687ba4f845f784e78f9ab463bebd1a Mon Sep 17 00:00:00 2001 From: yashodha Date: Thu, 11 May 2017 09:41:30 +0530 Subject: [PATCH] CRM-20552 - Task for 'Add Relationship - to individual' is missing --- CRM/Contact/Form/Task/AddToIndividual.php | 113 ++++++++++++++++++ CRM/Contact/Task.php | 13 +- .../CRM/Contact/Form/Task/AddToIndividual.tpl | 108 +++++++++++++++++ 3 files changed, 233 insertions(+), 1 deletion(-) create mode 100644 CRM/Contact/Form/Task/AddToIndividual.php create mode 100644 templates/CRM/Contact/Form/Task/AddToIndividual.tpl diff --git a/CRM/Contact/Form/Task/AddToIndividual.php b/CRM/Contact/Form/Task/AddToIndividual.php new file mode 100644 index 0000000000..df8da26684 --- /dev/null +++ b/CRM/Contact/Form/Task/AddToIndividual.php @@ -0,0 +1,113 @@ +addElement('text', 'name', ts('Find Target Individual')); + + $this->add('select', + 'relationship_type_id', + ts('Relationship Type'), + array( + '' => ts('- select -'), + ) + + CRM_Contact_BAO_Relationship::getRelationType("Individual"), TRUE + ); + + $searchRows = $this->get('searchRows'); + $searchCount = $this->get('searchCount'); + if ($searchRows) { + $checkBoxes = array(); + $chekFlag = 0; + foreach ($searchRows as $id => $row) { + if (!$chekFlag) { + $chekFlag = $id; + } + + $checkBoxes[$id] = $this->createElement('radio', NULL, NULL, NULL, $id); + } + + $this->addGroup($checkBoxes, 'contact_check'); + if ($chekFlag) { + $checkBoxes[$chekFlag]->setChecked(TRUE); + } + $this->assign('searchRows', $searchRows); + } + + $this->assign('searchCount', $searchCount); + $this->assign('searchDone', $this->get('searchDone')); + $this->assign('contact_type_display', ts('Individual')); + $this->addElement('submit', $this->getButtonName('refresh'), ts('Search'), array('class' => 'crm-form-submit')); + $this->addElement('submit', $this->getButtonName('cancel'), ts('Cancel'), array('class' => 'crm-form-submit')); + $this->addButtons(array( + array( + 'type' => 'next', + 'name' => ts('Add to Individual'), + 'isDefault' => TRUE, + ), + array( + 'type' => 'cancel', + 'name' => ts('Cancel'), + ), + ) + ); + } + + /** + * Process the form after the input has been submitted and validated. + */ + public function postProcess() { + // store the submitted values in an array + $this->params = $this->controller->exportValues($this->_name); + + $this->set('searchDone', 0); + if (!empty($_POST['_qf_AddToIndividual_refresh'])) { + $searchParams['contact_type'] = 'Individual'; + $searchParams['rel_contact'] = $this->params['name']; + $this->search($this, $searchParams); + $this->set('searchDone', 1); + return; + } + + $this->addRelationships(); + } + +} diff --git a/CRM/Contact/Task.php b/CRM/Contact/Task.php index 53cd22e32e..fb77c32949 100644 --- a/CRM/Contact/Task.php +++ b/CRM/Contact/Task.php @@ -60,7 +60,8 @@ class CRM_Contact_Task { EMAIL_UNHOLD = 22, RESTORE = 23, DELETE_PERMANENTLY = 24, - COMMUNICATION_PREFS = 25; + COMMUNICATION_PREFS = 25, + INDIVIDUAL_CONTACTS = 26; /** * The task array @@ -180,6 +181,16 @@ class CRM_Contact_Task { ); } + if (CRM_Contact_BAO_ContactType::isActive('Individual')) { + $label = CRM_Contact_BAO_ContactType::getLabel('individual'); + self::$_tasks[self::INDIVIDUAL_CONTACTS] = array( + 'title' => ts('Add relationship - to %1', + array(1 => $label) + ), + 'class' => 'CRM_Contact_Form_Task_AddToIndividual', + ); + } + if (CRM_Contact_BAO_ContactType::isActive('Household')) { $label = CRM_Contact_BAO_ContactType::getLabel('household'); self::$_tasks[self::HOUSEHOLD_CONTACTS] = array( diff --git a/templates/CRM/Contact/Form/Task/AddToIndividual.tpl b/templates/CRM/Contact/Form/Task/AddToIndividual.tpl new file mode 100644 index 0000000000..dc32624b5e --- /dev/null +++ b/templates/CRM/Contact/Form/Task/AddToIndividual.tpl @@ -0,0 +1,108 @@ +{* + +--------------------------------------------------------------------+ + | CiviCRM version 4.7 | + +--------------------------------------------------------------------+ + | Copyright CiviCRM LLC (c) 2004-2017 | + +--------------------------------------------------------------------+ + | This file is a part of CiviCRM. | + | | + | CiviCRM is free software; you can copy, modify, and distribute it | + | under the terms of the GNU affero General Public License | + | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | + | | + | CiviCRM is distributed in the hope that it will be useful, but | + | WITHOUT ANY WARRANTY; without even the implied warranty of | + | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | + | See the GNU Affero General Public License for more details. | + | | + | You should have received a copy of the GNU Affero General Public | + | License and the CiviCRM Licensing Exception along | + | with this program; if not, contact CiviCRM LLC | + | at info[AT]civicrm[DOT]org. If you have questions about the | + | GNU Affero General Public License or the licensing of CiviCRM, | + | see the CiviCRM license FAQ at http://civicrm.org/licensing | + +--------------------------------------------------------------------+ +*} +
+
+ {ts}Choose Relationship Type and Target Individual{/ts} +
+ + + {if $action EQ 2} {* action = update *} + + {else} {* action = add *} + + + + + + + + + + +
{include file="CRM/Contact/Form/Task.tpl"}
{$form.relationship_type_id.label}{$form.relationship_type_id.html}
{$form.name.label}{$form.name.html}
{$form._qf_AddToIndividual_refresh.html}  {$form._qf_AddToIndividual_cancel.html}
+ {if $searchDone } {* Search button clicked *} + {if $searchCount} + {if $searchRows} {* we've got rows to display *} +
{ts}Mark Target Contact(s) for this Relationship{/ts} +
+ {ts}Mark the target contact(s) for this relationship if it appears below. Otherwise you may modify the search name above and click Search again.{/ts} +
+ {strip} + + + + + + + + + + {foreach from=$searchRows item=row} + + + + + + + + + {/foreach} +
 {ts}Name{/ts}{ts}City{/ts}{ts}State{/ts}{ts}Email{/ts}{ts}Phone{/ts}
{$form.contact_check[$row.id].html}{$row.type} {$row.name}{$row.city}{$row.state}{$row.email}{$row.phone}
+ {/strip} +
+ {else} {* too many results - we're only displaying 50 *} +
+ {capture assign=infoTitle}{ts}Too many matching results{/ts}{/capture} + {capture assign=infoMessage}{ts}Please narrow your search by entering a more complete target contact name.{/ts}{/capture} + {include file="CRM/common/info.tpl"} + {/if} + {else} {* no valid matches for name + contact_type *} + + {capture assign=infoTitle}{ts}No matching results for{/ts}{/capture} + {capture assign=infoMessage}{ts}Check your spelling, or try fewer letters for the target contact name.{/ts}{/capture} + {include file="CRM/common/info.tpl"} + {/if} {* end if searchCount *} + {else} + + {/if} {* end if searchDone *} + {/if} {* end action = add *} + + {* Only show buttons if action=update, OR if we have $contacts (results)*} + {if $searchRows OR $action EQ 2} +
+ +
+ +
+
{include file="CRM/common/formButtons.tpl"}
+
+
+ {$form.status.label} {$form.status.html} +
+ + + + {/if} -- 2.25.1