1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17: 18: 19: 20: 21: 22: 23: 24:
25: class ClipitActivity extends UBItem {
26: 27: 28:
29: const SUBTYPE = "ClipitActivity";
30:
31: const REL_ACTIVITY_TRICKYTOPIC = "ClipitActivity-ClipitTrickyTopic";
32: const REL_ACTIVITY_TEACHER = "ClipitActivity-teacher";
33: const REL_ACTIVITY_STUDENT = "ClipitActivity-student";
34: const REL_ACTIVITY_GROUP = "ClipitActivity-ClipitGroup";
35: const REL_ACTIVITY_TASK = "ClipitActivity-ClipitTask";
36: const REL_ACTIVITY_STORYBOARD = "ClipitActivity-ClipitStoryboard";
37: const REL_ACTIVITY_VIDEO = "ClipitActivity-ClipitVideo";
38: const REL_ACTIVITY_FILE = "ClipitActivity-ClipitFile";
39:
40: const STATUS_ENROLL = "enroll";
41: const STATUS_ACTIVE = "active";
42: const STATUS_CLOSED = "closed";
43:
44: const GROUP_MODE_TEACHER = "teacher";
45: const GROUP_MODE_SYSTEM = "system";
46: const GROUP_MODE_STUDENT = "student";
47:
48: public $color = "";
49: public $status = "";
50: public $tricky_topic = 0;
51: public $start = 0;
52: public $end = 0;
53: public $group_mode = "";
54: public $max_group_size = 0;
55:
56: public $teacher_array = array();
57: public $student_array = array();
58: public $group_array = array();
59: public $task_array = array();
60:
61: public $storyboard_array = array();
62: public $video_array = array();
63: public $file_array = array();
64:
65: 66: 67: 68: 69:
70: protected function copy_from_elgg($elgg_entity) {
71: parent::copy_from_elgg($elgg_entity);
72: $this->color = (string)$elgg_entity->get("color");
73: $this->tricky_topic = (int)static::get_tricky_topic($this->id);
74: $this->start = (int)$elgg_entity->get("start");
75: $this->end = (int)$elgg_entity->get("end");
76: $this->group_mode = (string)$elgg_entity->get("group_mode");
77: $this->max_group_size = (int)$elgg_entity->get("max_group_size");
78: $this->status = (string)static::calc_status($this->start, $this->end);
79: $this->teacher_array = static::get_teachers($this->id);
80: $this->student_array = static::get_students($this->id);
81: $this->group_array = static::get_groups($this->id);
82: $this->task_array = static::get_tasks($this->id);
83: $this->storyboard_array = static::get_storyboards($this->id);
84: $this->video_array = static::get_videos($this->id);
85: $this->file_array = static::get_files($this->id);
86: }
87:
88: 89: 90: 91: 92: 93: 94: 95:
96: private function calc_status($start, $end) {
97: $date = new DateTime();
98: $now = (int)$date->getTimestamp();
99: if($now < $start) {
100: return static::STATUS_ENROLL;
101: } elseif($now >= $start && $now <= $end) {
102: return static::STATUS_ACTIVE;
103: } else {
104: return static::STATUS_CLOSED;
105: }
106: }
107:
108: 109: 110: 111: 112:
113: protected function copy_to_elgg($elgg_entity) {
114: parent::copy_to_elgg($elgg_entity);
115: if(!empty($this->color)) {
116: $elgg_entity->set("color", (string)$this->color);
117: } else {
118: $elgg_entity->set("color", $this->get_rand_color());
119: }
120: $elgg_entity->set("start", (int)$this->start);
121: $elgg_entity->set("end", (int)$this->end);
122: $elgg_entity->set("group_mode", (string)$this->group_mode);
123: $elgg_entity->set("max_group_size", (int)$this->max_group_size);
124: }
125:
126: 127: 128: 129: 130:
131: protected function save($double_save=false) {
132: parent::save($double_save);
133: static::set_tricky_topic($this->id, (int)$this->tricky_topic);
134: static::set_teachers($this->id, $this->teacher_array);
135: static::set_students($this->id, $this->student_array);
136: static::set_groups($this->id, $this->group_array);
137: static::set_tasks($this->id, $this->task_array);
138: static::set_storyboards($this->id, $this->storyboard_array);
139: static::set_videos($this->id, $this->video_array);
140: static::set_files($this->id, $this->file_array);
141: return $this->id;
142: }
143:
144: static function get_tricky_topic($id) {
145: $ret_array = UBCollection::get_items($id, static::REL_ACTIVITY_TRICKYTOPIC);
146: if(!empty($ret_array)){
147: return array_pop($ret_array);
148: }
149: return 0;
150: }
151:
152: static function set_tricky_topic($id, $tricky_topic) {
153: return UBCollection::set_items($id, array($tricky_topic), static::REL_ACTIVITY_TRICKYTOPIC);
154: }
155:
156: 157: 158: 159:
160: protected function get_rand_color() {
161: $color_array = array(
162: "E7DF1A",
163: "98BF0E",
164: "ED1E79",
165: "4174B5",
166: "EC7227",
167: "019B67",
168: "E4391B",
169: "14B8DD",
170: );
171: $pos = (int)rand(0, count($color_array)-1);
172: return $color_array[$pos];
173: }
174:
175:
176: 177: 178: 179: 180: 181: 182:
183: public function get_status($id){
184: $prop_value_array = static::get_properties($id, array("status"));
185: return $prop_value_array["status"];
186: }
187: 188: 189: 190: 191: 192: 193: 194:
195: static function get_from_user($user_id, $joined_only = false) {
196: $activity_id_array = ClipitUser::get_activities($user_id, $joined_only);
197: $activity_array = array();
198: foreach($activity_id_array as $activity_id) {
199: $activity_array[$activity_id] = new static($activity_id);
200: }
201: return $activity_array;
202: }
203:
204: static function get_from_tricky_topic($tricky_topic_id) {
205: $id_array = UBCollection::get_items($tricky_topic_id, static::REL_ACTIVITY_TRICKYTOPIC, true);
206: $activity_array = array();
207: foreach($id_array as $activity_id) {
208: $activity_array[] = new static($activity_id);
209: }
210: return $activity_array;
211: }
212:
213:
214: static function add_teachers($id, $teacher_array) {
215: return UBCollection::add_items($id, $teacher_array, static::REL_ACTIVITY_TEACHER);
216: }
217:
218: static function set_teachers($id, $teacher_array) {
219: return UBCollection::set_items($id, $teacher_array, static::REL_ACTIVITY_TEACHER);
220: }
221:
222: static function remove_teachers($id, $teacher_array) {
223: return UBCollection::remove_items($id, $teacher_array, static::REL_ACTIVITY_TEACHER);
224: }
225:
226: static function get_teachers($id) {
227: return UBCollection::get_items($id, static::REL_ACTIVITY_TEACHER);
228: }
229:
230:
231: static function add_students($id, $user_array) {
232: return UBCollection::add_items($id, $user_array, static::REL_ACTIVITY_STUDENT);
233: }
234:
235: static function set_students($id, $user_array) {
236: return UBCollection::set_items($id, $user_array, static::REL_ACTIVITY_STUDENT);
237: }
238:
239: static function remove_students($id, $user_array) {
240: return UBCollection::remove_items($id, $user_array, static::REL_ACTIVITY_STUDENT);
241: }
242:
243: static function get_students($id) {
244: return UBCollection::get_items($id, static::REL_ACTIVITY_STUDENT);
245: }
246:
247:
248: static function add_groups($id, $group_array) {
249: return UBCollection::add_items($id, $group_array, static::REL_ACTIVITY_GROUP, true);
250: }
251:
252: static function set_groups($id, $group_array) {
253: return UBCollection::set_items($id, $group_array, static::REL_ACTIVITY_GROUP, true);
254: }
255:
256: static function remove_groups($id, $group_array) {
257: return UBCollection::remove_items($id, $group_array, static::REL_ACTIVITY_GROUP);
258: }
259:
260: static function get_groups($id) {
261: return UBCollection::get_items($id, static::REL_ACTIVITY_GROUP);
262: }
263:
264:
265: static function add_tasks($id, $task_array) {
266: return UBCollection::add_items($id, $task_array, static::REL_ACTIVITY_TASK, true);
267: }
268:
269: static function set_tasks($id, $task_array) {
270: return UBCollection::set_items($id, $task_array, static::REL_ACTIVITY_TASK, true);
271: }
272:
273: static function remove_tasks($id, $task_array) {
274: return UBCollection::remove_items($id, $task_array, static::REL_ACTIVITY_TASK);
275: }
276:
277: static function get_tasks($id) {
278: return UBCollection::get_items($id, static::REL_ACTIVITY_TASK);
279: }
280:
281:
282:
283: static function add_storyboards($id, $storyboard_array) {
284: return UBCollection::add_items($id, $storyboard_array, static::REL_ACTIVITY_STORYBOARD);
285: }
286:
287: static function set_storyboards($id, $storyboard_array) {
288: return UBCollection::set_items($id, $storyboard_array, static::REL_ACTIVITY_STORYBOARD);
289: }
290:
291: static function remove_storyboards($id, $storyboard_array) {
292: return UBCollection::remove_items($id, $storyboard_array, static::REL_ACTIVITY_STORYBOARD);
293: }
294:
295: static function get_storyboards($id) {
296: return UBCollection::get_items($id, static::REL_ACTIVITY_STORYBOARD);
297: }
298:
299:
300: static function add_videos($id, $video_array) {
301: return UBCollection::add_items($id, $video_array, static::REL_ACTIVITY_VIDEO);
302: }
303:
304: static function set_videos($id, $video_array) {
305: return UBCollection::set_items($id, $video_array, static::REL_ACTIVITY_VIDEO);
306: }
307:
308: static function remove_videos($id, $video_array) {
309: return UBCollection::remove_items($id, $video_array, static::REL_ACTIVITY_VIDEO);
310: }
311:
312: static function get_videos($id) {
313: return UBCollection::get_items($id, static::REL_ACTIVITY_VIDEO);
314: }
315:
316:
317: static function add_files($id, $file_array) {
318: return UBCollection::add_items($id, $file_array, static::REL_ACTIVITY_FILE);
319: }
320:
321: static function set_files($id, $file_array) {
322: return UBCollection::set_items($id, $file_array, static::REL_ACTIVITY_FILE);
323: }
324:
325: static function remove_files($id, $file_array) {
326: return UBCollection::remove_items($id, $file_array, static::REL_ACTIVITY_FILE);
327: }
328:
329: static function get_files($id) {
330: return UBCollection::get_items($id, static::REL_ACTIVITY_FILE);
331: }
332:
333: 334: 335: 336: 337: 338: 339:
340: static function get_published_storyboards($id) {
341: $tasks = static::get_tasks($id);
342: $storyboard_array = array();
343: foreach($tasks as $task_id) {
344: $storyboard_array = array_merge($storyboard_array, ClipitTask::get_storyboards($task_id));
345: }
346: return $storyboard_array;
347: }
348:
349: 350: 351: 352: 353: 354: 355:
356: static function get_published_videos($id) {
357: $tasks = static::get_tasks($id);
358: $video_array = array();
359: foreach($tasks as $task_id) {
360: $video_array = array_merge($video_array, ClipitTask::get_videos($task_id));
361: }
362: return $video_array;
363: }
364: }