-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtbs_department.module
309 lines (289 loc) · 9.06 KB
/
tbs_department.module
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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
<?php
/**
* Implements hook_entity_info().
*/
function tbs_department_entity_info() {
$return['department'] = array(
'label' => t('Department'),
'controller class' => 'DeparmentController',
'base table' => 'tbs_department',
'revision table' => 'tbs_department_revision',
'uri callback' => 'department_uri',
'fieldable' => TRUE,
'entity keys' => array(
'id' => 'dep_id',
'revision' => 'dep_vid',
'bundle' => 'dep_type',
'label' => 'dep_name',
),
'bundle keys' => array(
'bundle' => 'dep_type',
),
'static cache' => TRUE,
'bundles' => array(),
'view modes' => array(
'full' => array(
'label' => t('Full Content'),
'custom settings' => FALSE,
),
'teaser' => array(
'label' => t('Teaser'),
'custom settings' => FALSE,
),
),
);
foreach (department_types() as $type => $info){
$return['department']['bundles'][$type] = array(
'label' => $info->name,
'admin' => array(
'path' => 'admin/structure/department/manage/%department_type',
'real path' => 'admin/structure/department/manage/' . str_replace('_', '-', $type),
'bundle argument' => 4,
'access arguments' => array('administer departments'),
),
);
}
return $return;
}
/**
* Entity uri callback.
*/
function department_uri($department){
return array(
'path' => 'department/' . $department->dep_id,
);
}
/**
* Get a list of all department types available.
*
*/
function department_types() {
$types = &drupal_static(__FUNCTION__);
if(empty($types)) {
$types['accra'] = (object)array(
'dep_type' => 'accra',
'name' => t('Accra Departments'),
'description' => t('Departments located in Accra.')
);
$types['ahafo'] = (object)array(
'dep_type' => 'ahafo',
'name' => t('Ahafo Departments'),
'description' => t('Departments located in Ahafo.')
);
$types['achim'] = (object)array(
'dep_type' => 'achim',
'name' => t('Achim Departments'),
'description' => t('Departments located in Achim.')
);
}
return $types;
}
/**
* Implements hook_field_extra_fields().
*/
function tbs_department_field_extra_fields(){
$extra = array();
foreach(department_types() as $type){
$extra['department'][$type->dep_type] = array(
'form'=> array(
'title' => array(
'label' => t('Title'),
'description' => t('The name of the department'),
'weight' => -5,
),
),
'diaplay' => array(
'title' => array(
'label' => t('Title'),
'description' => t('The name of the department'),
'weight' => -5,
),
),
);
}
return $extra;
}
/**
* Implements hook_permission()
*/
function tbs_department_permission() {
return array(
'administer departments' => array(
'title' => t('Administer Departments'),
),
'create departmants' => array(
'title' => t('Create Departments'),
),
'update departments' => array(
'title' => t('Update Departments'),
),
'view departments' => array(
'title' => t('View Departments'),
),
'delete departments' => array(
'title' => t('Delete Departments'),
),
);
}
/**
* Implementation of hook_menu()
*/
function tbs_department_menu(){
$items['admin/structure/department'] = array(
'title' => 'Manage Departments',
'description' => 'Manage Departments',
'page callback' => 'department_overview_types',
'access arguments' => array('administer departments'),
'file' => 'includes/department.admin.inc',
);
$items['admin/structure/department/manage/%department_type'] = array(
'title' => 'View department types',
'title callback' => 'department_type_page_title',
'title arguments' => array(4),
'page callback' => 'department_information',
'page arguments' => array(4),
'access arguments' => array('administer departments'),
'file' => 'includes/department.admin.inc',
);
$items['admin/structure/department/manage/%deparment_type/view']= array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
);
$items['department/add'] = array(
'title' => 'Add new department',
'page callback' => 'department_add_page',
'access arguments' => array('create departments'),
'weight' => 1,
'menu_name' => 'management',
'file' => 'includes/department.pages.inc',
);
foreach(department_types() as $type){
$type_url_str = str_replace('_','-', $type->dep_type);
$items['department/add/' . $type_url_str] = array(
'title' => $type->name,
'title callback' => 'check_plain',
'page callback' => 'department_add',
'page arguments' => array(2),
'access arguments' => array('create departments'),
'description' => $type->description,
'file' => 'includes/department.pages.inc',
);
}
$items['department/%department'] = array(
'title callback' => 'department_page_title',
'title arguments' => array(1),
'page callback' => 'department_page_view',
'page arguments' => array(1),
'access arguments' => array('view departments'),
'type' => MENU_CALLBACK,
'file' => 'includes/department.pages.inc',
);
$items['department/%department/view'] = array(
'title' => 'View',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['department/%department/edit'] = array(
'title' => 'Edit',
'page callback' => 'department_page_edit',
'page arguments' => array(1),
'access arguments' => array('update departments'),
'weight' => 0,
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_PAGE | MENU_CONTEXT_INLINE,
'file' => 'includes/department.pages.inc',
);
$items['department/%department/delete'] = array(
'title' => 'Delete',
'page callback' => 'drupal_get_form',
'page arguments' => array('department_delete_confirm', 1),
'access arguments' => array('delete departments'),
'weight' => 1,
'type' => MENU_LOCAL_TASK,
'context' => MENU_CONTEXT_INLINE,
'file' => 'includes/department.pages.inc',
);
$items['department/recent'] = array(
'title' => 'Recently added departments',
'page callback' => 'department_page_list_recent',
'access arguments' => array('view departments'),
'file' => 'includes/department.pages.inc',
);
return $items;
}
/**
* Sets the page title based on the specified department
*
* The department object
*/
function department_page_title($department){
return $department->dep_name;
}
/**
* Implements hook_form().
*
* All departments forms share the same form handler.
*/
function tbs_department_forms(){
$forms = array();
if($types = department_types()) {
foreach(array_keys($types) as $type){
$forms[$type. '_department_form']['callback'] = 'department_form';
}
}
return $forms;
}
/**
* Menu title Callback
*/
function department_type_page_title($type) {
return t('Manage @type', array('@type' => $type->name));
}
/**
* Get an individual department type definition object.
*/
function department_type_load($type) {
$types = department_types();
$type = str_replace('-','_', $type);
return isset($types[$type]) ? $types[$type] : FALSE;
}
/**
* Load departments from the database.
*/
function department_load_multiple($aids = array(), $conditions = array(), $reset = False){
return entity_load('department', $aids, $conditions, $reset);
}
/**
* Department Load
*/
function department_load($dep_id = NULL, $dep_vid = NULL, $reset = FALSE) {
$dep_ids = (isset($dep_id) ? array($dep_id) : array());
$conditions = (isset($dep_vid) ? array('dep_vid' => $dep_vid) : array());
$department = department_load_multiple($dep_ids, $conditions, $reset);
return $department ? reset($department) : FALSE;
}
/**
* Department Save
*/
function department_save($department){
return entity_get_controller('department')->save($department);
}
/**
* Department New
*/
function department_new($type = '') {
return entity_get_controller('department')->create($type);
}
/**
* Department Delete
*
*/
function department_delete($dep_id) {
return department_delete_multiple(array($dep_id));
}
/**
* Deletes multiple
*/
function department_delete_multiple($dep_id) {
return entity_get_controller('department')->delete($dep_id);
}