Update version numbers to 4.4 and lint php
[civicrm-core.git] / CRM / Custom / Form / Preview.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
232624b1 4 | CiviCRM version 4.4 |
6a488035
TO
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
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 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36/**
37 * This class generates form components for previewing custom data
38 *
39 * It delegates the work to lower level subclasses and integrates the changes
40 * back in. It also uses a lot of functionality with the CRM API's, so any change
41 * made here could potentially affect the API etc. Be careful, be aware, use unit tests.
42 *
43 */
44class CRM_Custom_Form_Preview extends CRM_Core_Form {
45
46 /**
47 * the group tree data
48 *
49 * @var array
50 */
51 protected $_groupTree;
52
53 /**
54 * pre processing work done here.
55 *
56 * gets session variables for group or field id
57 *
58 * @param null
59 *
60 * @return void
61 * @access public
8ef12e64 62 */
6a488035
TO
63 function preProcess() {
64 // get the controller vars
65 $this->_groupId = $this->get('groupId');
66 $this->_fieldId = $this->get('fieldId');
67 if ($this->_fieldId) {
68 // field preview
69 $defaults = array();
70 $params = array('id' => $this->_fieldId);
71 $fieldDAO = new CRM_Core_DAO_CustomField();
72 CRM_Core_DAO::commonRetrieve('CRM_Core_DAO_CustomField', $params, $defaults);
73
74 if (CRM_Utils_Array::value('is_view', $defaults)) {
75 CRM_Core_Error::statusBounce(ts('This field is view only so it will not display on edit form.'));
76 }
77 elseif (CRM_Utils_Array::value('is_active', $defaults) == 0) {
78 CRM_Core_Error::statusBounce(ts('This field is inactive so it will not display on edit form.'));
79 }
80
81 $groupTree = array();
82 $groupTree[$this->_groupId]['id'] = 0;
83 $groupTree[$this->_groupId]['fields'] = array();
84 $groupTree[$this->_groupId]['fields'][$this->_fieldId] = $defaults;
85 $this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, 1, $this);
86 $this->assign('preview_type', 'field');
87 }
88 else {
89 $groupTree = CRM_Core_BAO_CustomGroup::getGroupDetail($this->_groupId);
90 $this->_groupTree = CRM_Core_BAO_CustomGroup::formatGroupTree($groupTree, TRUE, $this);
91 $this->assign('preview_type', 'group');
92 }
93 }
94
95 /**
96 * Set the default form values
97 *
98 * @param null
99 *
100 * @return array the default array reference
101 * @access protected
102 */
103 function setDefaultValues() {
104 $defaults = array();
105
106 CRM_Core_BAO_CustomGroup::setDefaults($this->_groupTree, $defaults, FALSE, FALSE);
107
108 return $defaults;
109 }
110
111 /**
112 * Function to actually build the form
113 *
114 * @param null
115 *
116 * @return void
117 * @access public
118 */
119 public function buildQuickForm() {
120 if (is_array($this->_groupTree[$this->_groupId])) {
121 foreach ($this->_groupTree[$this->_groupId]['fields'] as & $field) {
122 //add the form elements
123 CRM_Core_BAO_CustomField::addQuickFormElement($this, $field['element_name'], $field['id'], FALSE, CRM_Utils_Array::value('is_required', $field));
124 }
125
126 $this->assign('groupTree', $this->_groupTree);
127 }
128 $this->addButtons(array(
129 array(
130 'type' => 'cancel',
131 'name' => ts('Done with Preview'),
132 'isDefault' => TRUE,
133 ),
134 )
135 );
136 }
137}
138