Refactor phase2 for honoree block
authormonishdeb <monish.deb@webaccessglobal.com>
Fri, 4 Sep 2015 21:22:50 +0000 (02:52 +0530)
committermonishdeb <monish.deb@webaccessglobal.com>
Thu, 10 Sep 2015 08:24:30 +0000 (13:54 +0530)
CRM/Contact/Form/ProfileContact.php [deleted file]
CRM/Contribute/BAO/ContributionPage.php
CRM/Contribute/Form/Contribution/Confirm.php
CRM/Contribute/Form/Contribution/OnBehalfOf.php [new file with mode: 0644]
CRM/Contribute/Form/ContributionBase.php
CRM/Core/xml/Menu/Contact.xml
CRM/Core/xml/Menu/Misc.xml
CRM/Upgrade/Incremental/php/FourSeven.php
templates/CRM/Contribute/Form/Contribution/Main.tpl
templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl [moved from templates/CRM/Contact/Form/ProfileContact.tpl with 98% similarity]
templates/CRM/Contribute/Form/SoftCredit.tpl

diff --git a/CRM/Contact/Form/ProfileContact.php b/CRM/Contact/Form/ProfileContact.php
deleted file mode 100644 (file)
index 6bcebff..0000000
+++ /dev/null
@@ -1,120 +0,0 @@
-<?php
-/*
- +--------------------------------------------------------------------+
- | CiviCRM version 4.7                                                |
- +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2015                                |
- +--------------------------------------------------------------------+
- | 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-2015
- */
-class CRM_Contact_Form_ProfileContact extends CRM_Core_Form {
-
-  protected $_profileId;
-
-  protected $_prefix;
-
-  /**
-   * Set variables up before form is built.
-   *
-   * @param CRM_Core_Form $form
-   */
-  public function preProcess() {
-    parent::preProcess();
-
-    $this->_profileId = CRM_Utils_Request::retrieve('id', 'Positive', $this, NULL, FALSE, NULL, 'GET');
-    $this->_prefix = CRM_Utils_Request::retrieve('prefix', 'String', $this, NULL, FALSE, NULL, 'GET');
-
-    $this->assign('suppressForm', TRUE);
-    $this->assign('snippet', TRUE);
-    $this->controller->_generateQFKey = FALSE;
-  }
-
-  /**
-   * Build form for honoree contact / on behalf of organization.
-   *
-   * @param CRM_Core_Form $form
-   *
-   */
-  public function buildQuickForm() {
-    $contactID = $this->getContactID();
-
-    if ($this->_prefix == 'onbehalf') {
-      $this->assign('fieldSetTitle', ts('Organization Details'));
-      $this->assign('profileId', $this->_profileId);
-
-      if ($contactID) {
-        $employer = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID);
-
-        if (count($employer)) {
-          // Related org url - pass checksum if needed
-          $args = array('cid' => '');
-          if (!empty($_GET['cs'])) {
-            $args = array(
-              'uid' => $this->_contactID,
-              'cs' => $_GET['cs'],
-              'cid' => '',
-            );
-          }
-          $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
-          $this->assign('locDataURL', $locDataURL);
-        }
-        if (count($employer) > 0) {
-          $this->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $employer));
-
-          $orgOptions = array(
-            0 => ts('Select an existing organization'),
-            1 => ts('Enter a new organization'),
-          );
-          $this->addRadio('org_option', ts('options'), $orgOptions);
-          $this->setDefaults(array('org_option' => 0));
-        }
-      }
-
-      $profileFields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, CRM_Core_Action::VIEW, NULL,
-                       NULL, FALSE, NULL, FALSE, NULL,
-                       CRM_Core_Permission::CREATE, NULL
-      );
-      $this->assign('onBehalfOfFields', $profileFields);
-      $this->addElement('hidden', 'onbehalf_profile_id', $this->_profileId);
-
-      $fieldTypes = array('Contact', 'Organization');
-      $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
-      $fieldTypes = array_merge($fieldTypes, $contactSubType);
-
-      foreach ($profileFields as $name => $field) {
-        if (in_array($field['field_type'], $fieldTypes)) {
-          list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
-          if (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) {
-            $field['is_required'] = 1;
-          }
-
-          CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, NULL, FALSE, $this->_prefix, NULL, $this->_prefix);
-        }
-      }
-    }
-
-  }
-}
index f45d0ae761df8396ad029ce0d9f8207171883d93..9965edc37419edf6a61aa6bf150268993e4a3c1d 100644 (file)
@@ -789,7 +789,7 @@ LEFT JOIN  civicrm_premiums            ON ( civicrm_premiums.entity_id = civicrm
         'soft_credit_types',
         'multilingual' => array(
           'honor_block_title',
-          'honor_block_text'
+          'honor_block_text',
         ),
       ),
       'on_behalf' => array(
index 68c4dcc6f229914326f2d1208774f3f88fcda27e..21e393788d60c366447daee2f7adad90c44e3055 100644 (file)
@@ -232,7 +232,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
       $this->assign('pay_later_receipt', $this->_values['pay_later_receipt']);
     }
     // if onbehalf-of-organization
-    if (!empty($this->_params['onbehalf_profile_id'])) {
+    if (!empty($this->_params['onbehalf_profile_id']) && !empty($this->_params['onbehalf']['organization_name'])) {
       // CRM-15182
       $this->_params['organization_id'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $this->_params['onbehalf']['organization_name'], 'id', 'display_name');
 
@@ -465,7 +465,7 @@ class CRM_Contribute_Form_Contribution_Confirm extends CRM_Contribute_Form_Contr
     $this->buildCustom($this->_values['custom_pre_id'], 'customPre', TRUE);
     $this->buildCustom($this->_values['custom_post_id'], 'customPost', TRUE);
 
-    if (!empty($params['onbehalf_profile_id'])) {
+    if (!empty($params['onbehalf'])) {
 
       $fieldTypes = array('Contact', 'Organization');
       $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
diff --git a/CRM/Contribute/Form/Contribution/OnBehalfOf.php b/CRM/Contribute/Form/Contribution/OnBehalfOf.php
new file mode 100644 (file)
index 0000000..22ae17d
--- /dev/null
@@ -0,0 +1,110 @@
+<?php
+/*
+ +--------------------------------------------------------------------+
+ | CiviCRM version 4.7                                                |
+ +--------------------------------------------------------------------+
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
+ +--------------------------------------------------------------------+
+ | 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-2015
+ */
+class CRM_Contribute_Form_Contribution_OnBehalfOf extends CRM_Core_Form {
+
+  protected $_profileId;
+
+  /**
+   * Set variables up before form is built.
+   */
+  public function preProcess() {
+    parent::preProcess();
+
+    $this->_profileId = CRM_Utils_Request::retrieve('id', 'Positive', $this, NULL, FALSE, NULL, 'GET');
+
+    $this->assign('suppressForm', TRUE);
+    $this->assign('snippet', TRUE);
+    $this->controller->_generateQFKey = FALSE;
+  }
+
+  /**
+   * Build form for honoree contact / on behalf of organization.
+   */
+  public function buildQuickForm() {
+    $contactID = $this->getContactID();
+
+    $this->assign('fieldSetTitle', ts('Organization Details'));
+    $this->assign('profileId', $this->_profileId);
+
+    if ($contactID) {
+      $employer = CRM_Contact_BAO_Relationship::getPermissionedEmployer($contactID);
+
+      if (count($employer)) {
+        // Related org url - pass checksum if needed
+        $args = array('cid' => '');
+        if (!empty($_GET['cs'])) {
+          $args = array(
+            'uid' => $this->_contactID,
+            'cs' => $_GET['cs'],
+            'cid' => '',
+          );
+        }
+        $locDataURL = CRM_Utils_System::url('civicrm/ajax/permlocation', $args, FALSE, NULL, FALSE);
+        $this->assign('locDataURL', $locDataURL);
+      }
+      if (count($employer) > 0) {
+        $this->add('select', 'onbehalfof_id', '', CRM_Utils_Array::collect('name', $employer));
+
+        $orgOptions = array(
+          0 => ts('Select an existing organization'),
+          1 => ts('Enter a new organization'),
+        );
+        $this->addRadio('org_option', ts('options'), $orgOptions);
+        $this->setDefaults(array('org_option' => 0));
+      }
+    }
+
+    $profileFields = CRM_Core_BAO_UFGroup::getFields($this->_profileId, FALSE, CRM_Core_Action::VIEW, NULL,
+                     NULL, FALSE, NULL, FALSE, NULL,
+                     CRM_Core_Permission::CREATE, NULL
+    );
+    $this->assign('onBehalfOfFields', $profileFields);
+    $this->addElement('hidden', 'onbehalf_profile_id', $this->_profileId);
+
+    $fieldTypes = array('Contact', 'Organization');
+    $contactSubType = CRM_Contact_BAO_ContactType::subTypes('Organization');
+    $fieldTypes = array_merge($fieldTypes, $contactSubType);
+
+    foreach ($profileFields as $name => $field) {
+      if (in_array($field['field_type'], $fieldTypes)) {
+        list($prefixName, $index) = CRM_Utils_System::explode('-', $name, 2);
+        if (in_array($prefixName, array('organization_name', 'email')) && empty($field['is_required'])) {
+          $field['is_required'] = 1;
+        }
+
+        CRM_Core_BAO_UFGroup::buildProfile($this, $field, NULL, NULL, FALSE, 'onbehalf', NULL, 'onbehalf');
+      }
+    }
+  }
+
+}
index 1d48059ae2ec5a5f1ca5c414d7b7f192ddcecb1f..ca3412bfdee48ab96199b878b54468c3c417d473 100644 (file)
@@ -539,7 +539,7 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
 
     $this->assign('address', CRM_Utils_Address::format($addressFields));
 
-    if (!empty($this->_params['onbehalf_profile_id'])) {
+    if (!empty($this->_params['onbehalf_profile_id']) && !empty($this->_params['onbehalf'])) {
       $this->assign('onBehalfName', $this->_params['organization_name']);
       $locTypeId = array_keys($this->_params['onbehalf_location']['email']);
       $this->assign('onBehalfEmail', $this->_params['onbehalf_location']['email'][$locTypeId[0]]['email']);
@@ -732,6 +732,8 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
         continue;
       }
 
+      $params = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoin->module_data, TRUE, $module);
+
       if ($module == 'soft_credit') {
         $form->_honoreeProfileId = $ufJoin->uf_group_id;
         $form->_honor_block_is_active = $ufJoin->is_active;
@@ -753,11 +755,43 @@ class CRM_Contribute_Form_ContributionBase extends CRM_Core_Form {
           CRM_Core_Error::fatal(ts('This contribution page has been configured for contribution on behalf of honoree and the required fields of the selected honoree profile are disabled or doesn\'t exist.'));
         }
 
-        //build soft-credit section
-        CRM_Contribute_Form_SoftCredit::buildQuickForm($form);
+        $form->assign('honor_block_is_active', $form->_honor_block_is_active);
+
+        foreach (array('honor_block_title', 'honor_block_text') as $name) {
+          $form->assign($name, $params[$name]);
+        }
+
+        $softCreditTypes = CRM_Core_OptionGroup::values("soft_credit_type", FALSE);
+
+        // radio button for Honor Type
+        foreach ($params['soft_credit_types'] as $value) {
+          $honorTypes[$value] = $form->createElement('radio', NULL, NULL, $softCreditTypes[$value], $value);
+        }
+        $form->addGroup($honorTypes, 'soft_credit_type_id', NULL)->setAttribute('allowClear', TRUE);
+
+        $prefix = 'honor';
+        $honoreeProfileFields = CRM_Core_BAO_UFGroup::getFields($form->_honoreeProfileId, FALSE, NULL,
+                                NULL, NULL,
+                                FALSE, NULL,
+                                TRUE, NULL,
+                                CRM_Core_Permission::CREATE
+        );
+        $form->addElement('hidden', 'honoree_profile_id', $form->_honoreeProfileId);
+        $form->assign('honoreeProfileFields', $honoreeProfileFields);
+
+        // add the form elements
+        foreach ($honoreeProfileFields as $name => $field) {
+          // If soft credit type is not chosen then make omit requiredness from honoree profile fields
+          if (count($form->_submitValues) &&
+            empty($form->_submitValues['soft_credit_type_id']) &&
+            !empty($field['is_required'])
+          ) {
+            $field['is_required'] = FALSE;
+          }
+            CRM_Core_BAO_UFGroup::buildProfile($form, $field, CRM_Profile_Form::MODE_CREATE, NULL, FALSE, FALSE, NULL, $prefix);
+        }
       }
       else {
-        $params = CRM_Contribute_BAO_ContributionPage::formatModuleData($ufJoin->module_data, TRUE, 'on_behalf');
         $form->_values = array_merge($params, $form->_values);
 
         $onBehalfProfileId = $ufJoin->uf_group_id;
index 58987ab3720f34575ed4e65249f97ae060d332e1..7f1ac88b2a4110640171edbd880689b1a2b25bfc 100644 (file)
      <page_callback>CRM_Contact_Page_AJAX::flipDupePairs</page_callback>
      <access_arguments>merge duplicate contacts</access_arguments>
 </item>
-<item>
-    <path>civicrm/profileContact/form</path>
-    <access_callback>1</access_callback>
-    <page_callback>CRM_Contact_Form_ProfileContact</page_callback>
-    <is_public>true</is_public>
-    <weight>0</weight>
-</item>
 <item>
   <path>civicrm/activity/sms/add</path>
   <path_arguments>action=add</path_arguments>
index aec5f169d76761ffd267d98a9280c32f1117bbd2..3fde326200d0d06d69ac4cd8239e5a8335256337 100644 (file)
     <access_arguments>access CiviCRM</access_arguments>
     <title>Insert CiviCRM Content</title>
   </item>
+  <item>
+    <path>civicrm/onbehalf/form</path>
+    <access_callback>1</access_callback>
+    <page_callback>CRM_Contribute_Form_Contribution_OnBehalfOf</page_callback>
+    <is_public>true</is_public>
+    <weight>0</weight>
+  </item>
 </menu>
index 710854ac16909ca9202b48652771c19b43bcf6c5..71fcc7f9a9453c4053356324b9cdcf65fbd82131 100644 (file)
@@ -199,4 +199,5 @@ FROM `civicrm_dashboard_contact` WHERE 1 GROUP BY contact_id";
 
     return TRUE;
   }
+
 }
index 90e280be2ed00dd09f23d26cdb69cbf3a8e90dff..440d3a05d9d94faf146fbd9e8db69a24696182b0 100644 (file)
     <div class="clear"></div>
   </div>
 
-  {include file="CRM/Contact/Form/ProfileContact.tpl"}
+  {include file="CRM/Contribute/Form/Contribution/OnBehalfOf.tpl"}
 
   {* User account registration option. Displays if enabled for one of the profiles on this page. *}
   {include file="CRM/common/CMSUser.tpl"}
   {include file="CRM/Contribute/Form/Contribution/PremiumBlock.tpl" context="makeContribution"}
 
   {if $honor_block_is_active}
-  <fieldset class="crm-group honor_block-group">
-    {include file="CRM/Contribute/Form/SoftCredit.tpl"}
-    <div id="honorType" class="honoree-name-email-section">
-      {include file="CRM/UF/Form/Block.tpl" fields=$honoreeProfileFields mode=8 prefix='honor'}
-    </div>
-  </fieldset>
+    <fieldset class="crm-group honor_block-group">
+      {crmRegion name="contribution-soft-credit-block"}
+        <legend>{$honor_block_title}</legend>
+        <div class="crm-section honor_block_text-section">
+          {$honor_block_text}
+        </div>
+        {if $form.soft_credit_type_id.html}
+          <div class="crm-section {$form.soft_credit_type_id.name}-section">
+            <div class="content" >
+              {$form.soft_credit_type_id.html}
+              <div class="description">{ts}Select an option to reveal honoree information fields.{/ts}</div>
+            </div>
+          </div>
+        {/if}
+      {/crmRegion}
+      <div id="honorType" class="honoree-name-email-section">
+        {include file="CRM/UF/Form/Block.tpl" fields=$honoreeProfileFields mode=8 prefix='honor'}
+      </div>
+    </fieldset>
   {/if}
 
   <div class="crm-group custom_pre_profile-group">
similarity index 98%
rename from templates/CRM/Contact/Form/ProfileContact.tpl
rename to templates/CRM/Contribute/Form/Contribution/OnBehalfOf.tpl
index 723e422231910d4d29a103e7e8ddc4c7c8f4dd78..0319981834ad2abed715820deec270dc6ad8fb95 100644 (file)
       }
       {/literal}{if $onBehalfprofileId}
         {capture assign='onBehalfprofileId'}id={$onBehalfprofileId}&{/capture};
-        var dataUrl = "{crmURL p='civicrm/profileContact/form' h=0 q="`$onBehalfprofileId`prefix=onbehalf"}";
+        var dataUrl = "{crmURL p='civicrm/onbehalf/form' h=0 q="`$onBehalfprofileId`prefix=onbehalf"}";
       {/if}{literal}
       if (typeof dataUrl != 'undefined') {CRM.loadPage(dataUrl, {target: '#on-behalf-block'})};
     }
index 7b8e7ab3df4f36e1774549b9585ac1451f4155f2..a71f886c2af41f419a784a4cf31b1a4d16d40318 100644 (file)
  +--------------------------------------------------------------------+
 *}
 {* template for adding form elements for soft credit form*}
-{if $honor_block_is_active}
-  {crmRegion name="contribution-soft-credit-block"}
-    <legend>{$honor_block_title}</legend>
-    <div class="crm-section honor_block_text-section">
-      {$honor_block_text}
-    </div>
-    {if $form.soft_credit_type_id.html}
-      <div class="crm-section {$form.soft_credit_type_id.name}-section">
-        <div class="content" >
-          {$form.soft_credit_type_id.html}
-          <div class="description">{ts}Select an option to reveal honoree information fields.{/ts}</div>
-        </div>
-      </div>
-    {/if}
-  {/crmRegion}
-{else}
 <table class="form-layout-compressed crm-soft-credit-block">
   {section name='i' start=1 loop=$rowCount}
     {assign var='rowNumber' value=$smarty.section.i.index}
@@ -63,7 +47,7 @@
     </td>
   </tr>
 </table>
-{/if}
+
 {literal}
 <script type="text/javascript">
   CRM.$(function($) {