/
Create.php
245 lines (217 loc) · 7.37 KB
/
Create.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
<?php
/**
* SocialEngine
*
* @category Application_Extensions
* @package Event
* @copyright Copyright 2006-2010 Webligo Developments
* @license http://www.socialengine.com/license/
* @version $Id: Create.php 9747 2012-07-26 02:08:08Z john $
* @author Sami
*/
/**
* @category Application_Extensions
* @package Event
* @copyright Copyright 2006-2010 Webligo Developments
* @license http://www.socialengine.com/license/
*/
class Event_Form_Create extends Engine_Form
{
protected $_parent_type;
protected $_parent_id;
public function setParent_type($value)
{
$this->_parent_type = $value;
}
public function setParent_id($value)
{
$this->_parent_id = $value;
}
public function init()
{
$user = Engine_Api::_()->user()->getViewer();
$this->setTitle('Create New Event')
->setAttrib('id', 'event_create_form')
->setMethod("POST")
->setAction(Zend_Controller_Front::getInstance()->getRouter()->assemble(array()));
// Title
$this->addElement('Text', 'title', array(
'label' => 'Event Name',
'allowEmpty' => false,
'required' => true,
'validators' => array(
array('NotEmpty', true),
array('StringLength', false, array(1, 64)),
),
'filters' => array(
'StripTags',
new Engine_Filter_Censor(),
),
));
$title = $this->getElement('title');
// Description
$this->addElement('Textarea', 'description', array(
'label' => 'Event Description',
'maxlength' => '10000',
'filters' => array(
'StripTags',
new Engine_Filter_Censor(),
new Engine_Filter_EnableLinks(),
new Engine_Filter_StringLength(array('max' => 10000)),
),
));
// Start time
$start = new Engine_Form_Element_CalendarDateTime('starttime');
$start->setLabel("Start Time");
$start->setAllowEmpty(false);
$this->addElement($start);
// End time
$end = new Engine_Form_Element_CalendarDateTime('endtime');
$end->setLabel("End Time");
$end->setAllowEmpty(false);
$this->addElement($end);
// Host
if ($this->_parent_type == 'user')
{
$this->addElement('Text', 'host', array(
'label' => 'Host',
'filters' => array(
new Engine_Filter_Censor(),
),
));
}
// Location
$this->addElement('Text', 'location', array(
'label' => 'Location',
'filters' => array(
new Engine_Filter_Censor(),
),
));
// Photo
$this->addElement('File', 'photo', array(
'label' => 'Main Photo'
));
$this->photo->addValidator('Extension', false, 'jpg,png,gif,jpeg');
// Category
$this->addElement('Select', 'category_id', array(
'label' => 'Event Category',
'multiOptions' => array(
'0' => ' '
),
));
// Search
$this->addElement('Checkbox', 'search', array(
'label' => 'People can search for this event',
'value' => True
));
// Approval
$this->addElement('Checkbox', 'approval', array(
'label' => 'People must be invited to RSVP for this event',
));
// Invite
$this->addElement('Checkbox', 'auth_invite', array(
'label' => 'Invited guests can invite other people as well',
'value' => True
));
// Privacy
$viewOptions = (array) Engine_Api::_()->authorization()->getAdapter('levels')->getAllowed('event', $user, 'auth_view');
$commentOptions = (array) Engine_Api::_()->authorization()->getAdapter('levels')->getAllowed('event', $user, 'auth_comment');
$photoOptions = (array) Engine_Api::_()->authorization()->getAdapter('levels')->getAllowed('event', $user, 'auth_photo');
if( $this->_parent_type == 'user' ) {
$availableLabels = array(
'everyone' => 'Everyone',
'registered' => 'All Registered Members',
'owner_network' => 'Friends and Networks',
'owner_member_member' => 'Friends of Friends',
'owner_member' => 'Friends Only',
'member' => 'Event Guests Only',
'owner' => 'Just Me'
);
$viewOptions = array_intersect_key($availableLabels, array_flip($viewOptions));
$commentOptions = array_intersect_key($availableLabels, array_flip($commentOptions));
$photoOptions = array_intersect_key($availableLabels, array_flip($photoOptions));
} else if( $this->_parent_type == 'group' ) {
$availableLabels = array(
'everyone' => 'Everyone',
'registered' => 'All Registered Members',
'parent_member' => 'Group Members',
'member' => 'Event Guests Only',
'owner' => 'Just Me',
);
$viewOptions = array_intersect_key($availableLabels, array_flip($viewOptions));
$commentOptions = array_intersect_key($availableLabels, array_flip($commentOptions));
$photoOptions = array_intersect_key($availableLabels, array_flip($photoOptions));
}
// View
if( !empty($viewOptions) && count($viewOptions) >= 1 ) {
// Make a hidden field
if(count($viewOptions) == 1) {
$this->addElement('hidden', 'auth_view', array('value' => key($viewOptions)));
// Make select box
} else {
$this->addElement('Select', 'auth_view', array(
'label' => 'Privacy',
'description' => 'Who may see this event?',
'multiOptions' => $viewOptions,
'value' => key($viewOptions),
));
$this->auth_view->getDecorator('Description')->setOption('placement', 'append');
}
}
// Comment
if( !empty($commentOptions) && count($commentOptions) >= 1 ) {
// Make a hidden field
if(count($commentOptions) == 1) {
$this->addElement('hidden', 'auth_comment', array('value' => key($commentOptions)));
// Make select box
} else {
$this->addElement('Select', 'auth_comment', array(
'label' => 'Comment Privacy',
'description' => 'Who may post comments on this event?',
'multiOptions' => $commentOptions,
'value' => key($commentOptions),
));
$this->auth_comment->getDecorator('Description')->setOption('placement', 'append');
}
}
// Photo
if( !empty($photoOptions) && count($photoOptions) >= 1 ) {
// Make a hidden field
if(count($photoOptions) == 1) {
$this->addElement('hidden', 'auth_photo', array('value' => key($photoOptions)));
// Make select box
} else {
$this->addElement('Select', 'auth_photo', array(
'label' => 'Photo Uploads',
'description' => 'Who may upload photos to this event?',
'multiOptions' => $photoOptions,
'value' => key($photoOptions)
));
$this->auth_photo->getDecorator('Description')->setOption('placement', 'append');
}
}
// Buttons
$this->addElement('Button', 'submit', array(
'label' => 'Save Changes',
'type' => 'submit',
'ignore' => true,
'decorators' => array(
'ViewHelper',
),
));
$this->addElement('Cancel', 'cancel', array(
'label' => 'cancel',
'link' => true,
'prependText' => ' or ',
'decorators' => array(
'ViewHelper',
),
));
$this->addDisplayGroup(array('submit', 'cancel'), 'buttons', array(
'decorators' => array(
'FormElements',
'DivDivDivWrapper',
),
));
}
}