-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathacm_course.module
270 lines (259 loc) · 7.83 KB
/
acm_course.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
<?php
/**
*
* hook_menu()
*/
function acm_course_menu() {
$items = array();
$items['student/course_entity'] = array(
'title' => 'Course Entity',
'page callback' => 'acm_course_formget',
'access arguments' => array('administer acm_course'),
'type' => MENU_NORMAL_ITEM,
);
$items['student/course/list'] = array(
'title' => 'Course manage list',
'page callback' => 'course_list',
'access arguments' => array('administer acm_course'),
'type' => MENU_NORMAL_ITEM,
'file' => 'includes/acm_course.view.list.inc',
);
$items['student/course/%/view'] = array(
'title' => 'Course entity view',
'page callback' => 'view_courselist',
'page arguments' => array(2),
'access arguments' => array('administer acm_course'),
'type' => MENU_CALLBACK,
'file' => 'includes/acm_course.view.list.inc',
);
$items['student/course/update'] = array(
'title' => 'Course entity update',
'page callback' => 'acm_course_update',
'access arguments' => array('administer acm_course'),
'type' => MENU_CALLBACK,
'file' => 'includes/acm_course.view.list.inc'
);
return $items;
}
/*
*
*hook perm
*/
function acm_course_perm() {
return array('administer acm_course');
}
function acm_course_init() {
//drupal_add_css(drupal_get_path('module', 'acm_course') . '/css/acm_course.css');
//drupal_add_js(drupal_get_path('module', 'acm_course') . '/js/acm_course.js');
}
function acm_course_formget(){
return drupal_get_form('acm_course_form');
}
/*
*
* hook form()
*/
function acm_course_form($form_id) {
$form['title'] = array(
'#title' => t('Title'),
'#type' => 'textfield',
'#required' => TRUE,
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['exam_score'] = array(
'#title' => t('Exam Score'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['test_score'] = array(
'#title' => t('Test Score'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>' ,
);
$form['academic_departmentid'] = array(
'#title' => t('Academic Department Id'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['code'] = array(
'#title' => t('Code'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['description'] = array(
'#title' => t('Description'),
'#type' => 'textarea',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['creditpoint'] = array(
'#title' => t('Credit Point'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['prerequisitecodes'] = array(
'#title' => t('Prerequisite Codes'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['prerequisites'] = array(
'#title' => t('Prerequisite Course'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['level'] = array(
'#title' => t('Level'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['semester'] = array(
'#title' => t('Semester'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['session'] = array(
'#title' => t('Session'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['lecturerincharge'] = array(
'#title' => t('Lecturer in Charge'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['numberofcas'] = array(
'#title' => t('Number of CAS'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['caapprovalmethod'] = array(
'#title' => t('CA Approval Method'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['maxtestmark'] = array(
'#title' => t('Max Test Mark'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['maxexammark'] = array(
'#title' => t('Max Exam Mark'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['programme'] = array(
'#title' => t('Programme'),
'#type' => 'textfield',
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$options = array('Core'=>'Core','Elective'=>'Elective','Required'=>'Required');
$form['type'] = array(
'#title' => t('Type'),
'#type' => 'select',
'#options' => $options,
'#prefix' => '<div class="require-data">',
'#suffix' => '</div>',
);
$form['created'] = array(
'#title' => t('Created'),
'#type' => 'hidden',
'#default_value' => date("Y-m-d H:i:s"),
);
$form['updated'] = array(
'#title' => t('Updated'),
'#type' => 'hidden',
'#default_value' => date("Y-m-d H:i:s"),
);
$form['submit'] = array(
'#value' => 'Submit',
'#type' => 'submit',
'#submit' => array('acm_course_form_submit'),
'#prefix' => '<div class="member_submit" >',
'#suffix' => '</div>',
);
return $form;
}
function acm_course_form_validate($form, &$form_state){
/*if(empty($form_state['values']['title'])){
form_set_error('Title',t('Title is mandatory'));
}
if(empty($form_state['values']['exam_score'])){
form_set_error('Test score',t('Title is mandatory'));
}*/
}
function acm_course_form_submit($form, &$form_state){
$values = $form_state['values'];
$success = drupal_write_record('acm_course',$values);
$batch = array(
'title' => t('Adding Course Contents'),
'operations' => array(),
'finished' => '_acm_school_create_batch_course_content_finish', // Last function to call.
'init_message' => t('Initializing...'),
'progress_message' => t('Fixed @current out of @total.'),
'error_message' => t('Adding Course Contents encountered an error.'),
);
$batch['operations'][] = array('_acm_school_create_batch_course_content', array());
batch_set($batch);
}
function _acm_school_create_batch_course_content(&$context) {
$results = db_fetch_object(db_query("SELECT MAX(id) as id FROM {acm_course}"));
module_load_include('inc', 'node', 'node.pages');
$node = array('type' => 'course_content');
$node_form_state = array();
$node_form_state['values']['title'] = t('Course Introduction');
$node_form_state['values']['field_course_ref_id'][0]['value'] = $results->id;
$node_form_state['values']['op'] = t('Save');
drupal_execute('course_content_node_form', $node_form_state, (object)$node);
$nid = $node_form_state['nid'];
$node = node_load($nid);
$node->uid = 1;
node_save($node);
$node = array('type' => 'course_content');
$node_form_state = array();
$node_form_state['values']['title'] = t('Course Materials');
$node_form_state['values']['field_course_ref_id'][0]['value'] = $results->id;
$node_form_state['values']['op'] = t('Save');
drupal_execute('course_content_node_form', $node_form_state, (object)$node);
$nid = $node_form_state['nid'];
$node = node_load($nid);
$node->uid = 1;
node_save($node);
$node = array('type' => 'course_content');
$node_form_state = array();
$node_form_state['values']['title'] = t('Course Reference');
$node_form_state['values']['field_course_ref_id'][0]['value'] = $results->id;
$node_form_state['values']['op'] = t('Save');
drupal_execute('course_content_node_form', $node_form_state, (object)$node);
$nid = $node_form_state['nid'];
$node = node_load($nid);
$node->uid = 1;
node_save($node);
$context['finished'] = 1;
}
function _acm_school_create_batch_course_content_finish($success, $results, $operations) {
if ($success) {
drupal_goto('student/course/list');
$message = t('Course content has been created.');
}
else {
$message = t('Finished with error.');
}
drupal_set_message($message);
}