INFRA-132 - Change "else if" to "elseif"
[civicrm-core.git] / CRM / Utils / Wrapper.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
39de6fd5 4 | CiviCRM version 4.6 |
6a488035 5 +--------------------------------------------------------------------+
06b69b18 6 | Copyright CiviCRM LLC (c) 2004-2014 |
6a488035
TO
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
06b69b18 36 * @copyright CiviCRM LLC (c) 2004-2014
6a488035
TO
37 * $Id: $
38 *
39 */
40class CRM_Utils_Wrapper {
41
42 /**
43 * Simple Controller
44 *
45 * The controller which will handle the display and processing of this page.
46 *
6a488035
TO
47 */
48 protected $_controller;
49
50 /**
51 * Run.
52 *
53 * The heart of the callback processing is done by this method.
54 * forms are of different type and have different operations.
55 *
77855840
TO
56 * @param string formName name of the form processing this action
57 * @param string formLabel label for the above form
58 * @param int mode mode of operation.
59 * @param bool addSequence should we add a unique sequence number to the end of the key
60 * @param bool ignoreKey should we not set a qfKey for this controller (for standalone forms)
6a488035 61 *
355ba699 62 * @return void.
6001af1f 63 */
00be9182 64 public function run($formName, $formLabel = NULL, $arguments = NULL) {
6a488035
TO
65 if (is_array($arguments)) {
66 $mode = CRM_Utils_Array::value('mode', $arguments);
67 $imageUpload = (bool) CRM_Utils_Array::value('imageUpload', $arguments, FALSE);
68 $addSequence = (bool) CRM_Utils_Array::value('addSequence', $arguments, FALSE);
69 $attachUpload = (bool) CRM_Utils_Array::value('attachUpload', $arguments, FALSE);
70 $ignoreKey = (bool) CRM_Utils_Array::value('ignoreKey', $arguments, FALSE);
71 }
72 else {
73 $arguments = array();
74 $mode = NULL;
75 $addSequence = $ignoreKey = $imageUpload = $attachUpload = FALSE;
76 }
77
78 $this->_controller = new CRM_Core_Controller_Simple(
79 $formName,
80 $formLabel,
81 $mode,
82 $imageUpload,
83 $addSequence,
84 $ignoreKey,
85 $attachUpload
86 );
87
88 if (array_key_exists('urlToSession', $arguments)) {
89 if (is_array($arguments['urlToSession'])) {
90 foreach ($arguments['urlToSession'] as $params) {
91 $urlVar = CRM_Utils_Array::value('urlVar', $params);
92 $sessionVar = CRM_Utils_Array::value('sessionVar', $params);
93 $type = CRM_Utils_Array::value('type', $params);
94 $default = CRM_Utils_Array::value('default', $params);
95 $abort = CRM_Utils_Array::value('abort', $params, FALSE);
96
97 $value = NULL;
884605ca
DL
98 $value = CRM_Utils_Request::retrieve(
99 $urlVar,
6a488035
TO
100 $type,
101 $this->_controller,
102 $abort,
103 $default
104 );
105 $this->_controller->set($sessionVar, $value);
106 }
107 }
108 }
109
110 if (array_key_exists('setEmbedded', $arguments)) {
111 $this->_controller->setEmbedded(TRUE);
112 }
113
114 $this->_controller->process();
115 return $this->_controller->run();
116 }
117}