| 1 | <?php |
| 2 | /* |
| 3 | +--------------------------------------------------------------------+ |
| 4 | | CiviCRM version 4.5 | |
| 5 | +--------------------------------------------------------------------+ |
| 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
| 7 | +--------------------------------------------------------------------+ |
| 8 | | This file is a part of CiviCRM. | |
| 9 | | | |
| 10 | | CiviCRM is free software; you can copy, modify, and distribute it | |
| 11 | | under the terms of the GNU Affero General Public License | |
| 12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | |
| 13 | | | |
| 14 | | CiviCRM is distributed in the hope that it will be useful, but | |
| 15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | |
| 17 | | See the GNU Affero General Public License for more details. | |
| 18 | | | |
| 19 | | You should have received a copy of the GNU Affero General Public | |
| 20 | | License and the CiviCRM Licensing Exception along | |
| 21 | | with this program; if not, contact CiviCRM LLC | |
| 22 | | at info[AT]civicrm[DOT]org. If you have questions about the | |
| 23 | | GNU Affero General Public License or the licensing of CiviCRM, | |
| 24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | |
| 25 | +--------------------------------------------------------------------+ |
| 26 | */ |
| 27 | |
| 28 | /** |
| 29 | * The Contact Wrapper is a wrapper class which is called by |
| 30 | * contact.module after it parses the menu path. |
| 31 | * |
| 32 | * The key elements of the wrapper are the controller and the |
| 33 | * run method as explained below. |
| 34 | * |
| 35 | * @package CRM |
| 36 | * @copyright CiviCRM LLC (c) 2004-2014 |
| 37 | * $Id: $ |
| 38 | * |
| 39 | */ |
| 40 | class CRM_Utils_Wrapper { |
| 41 | |
| 42 | /** |
| 43 | * Simple Controller |
| 44 | * |
| 45 | * The controller which will handle the display and processing of this page. |
| 46 | * |
| 47 | * @access protected |
| 48 | */ |
| 49 | protected $_controller; |
| 50 | |
| 51 | /** |
| 52 | * Run. |
| 53 | * |
| 54 | * The heart of the callback processing is done by this method. |
| 55 | * forms are of different type and have different operations. |
| 56 | * |
| 57 | * @param string formName name of the form processing this action |
| 58 | * @param string formLabel label for the above form |
| 59 | * @param int mode mode of operation. |
| 60 | * @param boolean addSequence should we add a unique sequence number to the end of the key |
| 61 | * @param boolean ignoreKey should we not set a qfKey for this controller (for standalone forms) |
| 62 | * |
| 63 | * @return void. |
| 64 | * @access public |
| 65 | */ |
| 66 | function run($formName, $formLabel = NULL, $arguments = NULL) { |
| 67 | if (is_array($arguments)) { |
| 68 | $mode = CRM_Utils_Array::value('mode', $arguments); |
| 69 | $imageUpload = (bool) CRM_Utils_Array::value('imageUpload', $arguments, FALSE); |
| 70 | $addSequence = (bool) CRM_Utils_Array::value('addSequence', $arguments, FALSE); |
| 71 | $attachUpload = (bool) CRM_Utils_Array::value('attachUpload', $arguments, FALSE); |
| 72 | $ignoreKey = (bool) CRM_Utils_Array::value('ignoreKey', $arguments, FALSE); |
| 73 | } |
| 74 | else { |
| 75 | $arguments = array(); |
| 76 | $mode = NULL; |
| 77 | $addSequence = $ignoreKey = $imageUpload = $attachUpload = FALSE; |
| 78 | } |
| 79 | |
| 80 | $this->_controller = new CRM_Core_Controller_Simple( |
| 81 | $formName, |
| 82 | $formLabel, |
| 83 | $mode, |
| 84 | $imageUpload, |
| 85 | $addSequence, |
| 86 | $ignoreKey, |
| 87 | $attachUpload |
| 88 | ); |
| 89 | |
| 90 | if (array_key_exists('urlToSession', $arguments)) { |
| 91 | if (is_array($arguments['urlToSession'])) { |
| 92 | foreach ($arguments['urlToSession'] as $params) { |
| 93 | $urlVar = CRM_Utils_Array::value('urlVar', $params); |
| 94 | $sessionVar = CRM_Utils_Array::value('sessionVar', $params); |
| 95 | $type = CRM_Utils_Array::value('type', $params); |
| 96 | $default = CRM_Utils_Array::value('default', $params); |
| 97 | $abort = CRM_Utils_Array::value('abort', $params, FALSE); |
| 98 | |
| 99 | $value = NULL; |
| 100 | $value = CRM_Utils_Request::retrieve( |
| 101 | $urlVar, |
| 102 | $type, |
| 103 | $this->_controller, |
| 104 | $abort, |
| 105 | $default |
| 106 | ); |
| 107 | $this->_controller->set($sessionVar, $value); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | if (array_key_exists('setEmbedded', $arguments)) { |
| 113 | $this->_controller->setEmbedded(TRUE); |
| 114 | } |
| 115 | |
| 116 | $this->_controller->process(); |
| 117 | return $this->_controller->run(); |
| 118 | } |
| 119 | } |
| 120 | |