CRM-20552 - Task for 'Add Relationship - to individual' is missing
authoryashodha <yashodha@cividesk.com>
Thu, 11 May 2017 04:11:30 +0000 (09:41 +0530)
committeryashodha <yashodha@cividesk.com>
Thu, 11 May 2017 04:11:30 +0000 (09:41 +0530)
CRM/Contact/Form/Task/AddToIndividual.php [new file with mode: 0644]
CRM/Contact/Task.php
templates/CRM/Contact/Form/Task/AddToIndividual.tpl [new file with mode: 0644]

diff --git a/CRM/Contact/Form/Task/AddToIndividual.php b/CRM/Contact/Form/Task/AddToIndividual.php
new file mode 100644 (file)
index 0000000..df8da26
--- /dev/null
@@ -0,0 +1,113 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | 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        |
+ +--------------------------------------------------------------------+
+ */
+
+/**
+ *
+ * @package CRM
+ * @copyright CiviCRM LLC (c) 2004-2017
+ */
+
+/**
+ * This class provides the functionality to add contact(s) to Individual.
+ */
+class CRM_Contact_Form_Task_AddToIndividual extends CRM_Contact_Form_Task_AddToParentClass {
+
+  /**
+   * Build the form object.
+   */
+  public function buildQuickForm() {
+    CRM_Utils_System::setTitle(ts('Add Contacts to Individual'));
+    $this->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();
+  }
+
+}
index 53cd22e32e512c556787fa40647c4705412ec1ac..fb77c32949a7f5f3793aae3026bf1c4168f53505 100644 (file)
@@ -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 (file)
index 0000000..dc32624
--- /dev/null
@@ -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        |
+ +--------------------------------------------------------------------+
+*}
+<div class="crm-block crm-form-block crm-contact-task-addtoindividual-form-block">
+  <div class="help">
+    {ts}Choose Relationship Type and Target Individual{/ts}
+  </div>
+    <table class="form-layout-compressed">
+        <tr><td></td><td>{include file="CRM/Contact/Form/Task.tpl"}</td></tr>
+            {if $action EQ 2} {* action = update *}
+                <tr><td><label>{$sort_name}</label></td></tr>
+            {else} {* action = add *}
+                <tr class="crm-contact-task-addtoindividual-form-block-relationship_type_id">
+                    <td>{$form.relationship_type_id.label}</td>
+                    <td>{$form.relationship_type_id.html}</td>
+                </tr>
+                <tr><td></td></tr>
+                <tr class="crm-contact-task-addtoindividual-form-block-name">
+                    <td>{$form.name.label}</td>
+                    <td>{$form.name.html}</td>
+                </tr>
+                <tr><td></td><td>{$form._qf_AddToIndividual_refresh.html}&nbsp;&nbsp;{$form._qf_AddToIndividual_cancel.html}</td></tr>
+     </table>
+         {if $searchDone } {* Search button clicked *}
+             {if $searchCount}
+                 {if $searchRows} {* we've got rows to display *}
+                     <fieldset><legend>{ts}Mark Target Contact(s) for this Relationship{/ts}</legend>
+                         <div class="description">
+                         {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}
+                         </div>
+                        {strip}
+                        <table>
+                        <tr class="columnheader">
+                        <td>&nbsp;</td>
+                        <td>{ts}Name{/ts}</td>
+                        <td>{ts}City{/ts}</td>
+                        <td>{ts}State{/ts}</td>
+                        <td>{ts}Email{/ts}</td>
+                        <td>{ts}Phone{/ts}</td>
+                        </tr>
+                        {foreach from=$searchRows item=row}
+                        <tr class="{cycle values="odd-row,even-row"}">
+                            <td>{$form.contact_check[$row.id].html}</td>
+                            <td>{$row.type} {$row.name}</td>
+                            <td>{$row.city}</td>
+                            <td>{$row.state}</td>
+                            <td>{$row.email}</td>
+                            <td>{$row.phone}</td>
+                        </tr>
+                        {/foreach}
+                        </table>
+                        {/strip}
+                        </fieldset>
+                    {else} {* too many results - we're only displaying 50 *}
+                        </div></fieldset>
+                        {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 *}
+                        </div></fieldset>
+                        {capture assign=infoTitle}{ts}No matching results for{/ts}{/capture}
+                        {capture assign=infoMessage}<ul><li>{ts 1=$form.name.value}Name like: %1{/ts}</li><li>{ts 1=$contact_type_display}Contact Type: %1{/ts}</li></ul>{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}
+                </div></fieldset>
+              {/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}
+            <div class="form-item">
+
+                    <div class="description">
+
+                    </div>
+               <div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl"}</div>
+            </div>
+  <div class="form-item">
+  {$form.status.label} {$form.status.html}
+  </div>
+
+
+            </div></fieldset>
+  {/if}