Overview

Packages

  • ClipIt
    • clipit
      • api
    • urjc
      • backend
  • Elgg
    • Core
      • Access
      • Authentication
      • Cache
      • Caches
      • Core
      • DataMode
        • Site
      • DataModel
        • Annotations
        • Entities
        • Extender
        • File
        • Importable
        • Loggable
        • Notable
        • Object
        • User
      • DataStorage
      • Exception
      • Exceptions
        • Stub
      • FileStore
        • Disk
      • Groups
      • Helpers
      • HMAC
      • Memcache
      • Metadata
      • Navigation
      • ODD
      • Output
      • Plugins
        • Settings
      • Sessions
      • SocialModel
        • Friendable
        • Locatable
      • WebServicesAPI
      • Widgets
      • XML
      • XMLRPC
    • Exceptions
      • Stub
  • None
  • PHP

Classes

  • ClipitActivity
  • ClipitChat
  • ClipitComment
  • ClipitEvent
  • ClipitExample
  • ClipitFile
  • ClipitGroup
  • ClipitLA
  • ClipitLabel
  • ClipitPerformanceItem
  • ClipitPerformanceRating
  • ClipitPost
  • ClipitQuiz
  • ClipitQuizQuestion
  • ClipitQuizResult
  • ClipitRating
  • ClipitRemoteTrickyTopic
  • ClipitRemoteVideo
  • ClipitResource
  • ClipitSite
  • ClipitStoryboard
  • ClipitTag
  • ClipitTagRating
  • ClipitTask
  • ClipitTrickyTopic
  • ClipitUser
  • ClipitVideo
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * ClipIt - JuxtaLearn Web Space
  4:  * PHP version:     >= 5.2
  5:  * Creation date:   2013-10-10
  6:  * Last update:     $Date$
  7:  * @author          Pablo LlinĂ¡s Arnaiz <pebs74@gmail.com>, URJC JuxtaLearn Team
  8:  * @version         $Version$
  9:  * @link            http://www.juxtalearn.eu
 10:  * @license         GNU Affero General Public License v3
 11:  * @package         ClipIt
 12:  * @subpackage      clipit_api
 13:  */
 14: 
 15: /**
 16:  * Contains all elements required to carry out the JuxtaLearn learning method in which Student work in Groups around a
 17:  * selected Tricky Topic.
 18:  *
 19:  * It contains a list of enrolled/called Students, Groups (that actually participate in the activity), Tasks (set by the
 20:  * teacher/s), support Resources and student Publications.
 21:  *
 22:  * An Activity can have different statuses: "enroll" state, "active" state and "closed" state, marked by start and
 23:  * end dates which define the current status.
 24:  */
 25: class ClipitActivity extends UBItem {
 26:     /**
 27:      * @const string SUBTYPE Elgg entity SUBTYPE for this class
 28:      */
 29:     const SUBTYPE = "ClipitActivity";
 30:     // Relationship names
 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:     // Status values
 40:     const STATUS_ENROLL = "enroll";
 41:     const STATUS_ACTIVE = "active";
 42:     const STATUS_CLOSED = "closed";
 43:     // Grouping modes
 44:     const GROUP_MODE_TEACHER = "teacher";
 45:     const GROUP_MODE_SYSTEM = "system";
 46:     const GROUP_MODE_STUDENT = "student";
 47:     // Activity properties
 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:     // Activity contents
 56:     public $teacher_array = array();
 57:     public $student_array = array();
 58:     public $group_array = array();
 59:     public $task_array = array();
 60:     // Activity teacher resources
 61:     public $storyboard_array = array();
 62:     public $video_array = array();
 63:     public $file_array = array();
 64: 
 65:     /**
 66:      * Loads object parameters stored in Elgg
 67:      *
 68:      * @param ElggEntity $elgg_entity Elgg Object to load parameters from.
 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:      * Calculate the Activity Status depending on the current date, and the Start and End of the activity.
 90:      *
 91:      * @param int $start Activity Start timestamp
 92:      * @param int $end   Activity End timestamp
 93:      *
 94:      * @return string The status of the activity: STATUS_ENROLL, STATUS_ACTIVE or STATUS_CLOSED
 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:      * Copy $this object parameters into an Elgg entity.
110:      *
111:      * @param ElggEntity $elgg_entity Elgg object instance to save $this to
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:      * Saves this instance to the system.
128:      * @param  bool $double_save if $double_save is true, this object is saved twice to ensure that all properties are updated properly. E.g. the time created property can only beset on ElggObjects during an update. Defaults to false!
129:      * @return bool|int Returns the Id of the saved instance, or false if error
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:      * Returns a random hex color, from a predefined palette, to assign to an Activity
158:      * @return string Hex color.
159:      */
160:     protected function get_rand_color() {
161:         $color_array = array(
162:             "E7DF1A", // yellow
163:             "98BF0E", // light green
164:             "ED1E79", // pink
165:             "4174B5", // purple
166:             "EC7227", // orange
167:             "019B67", // dark green
168:             "E4391B", // red
169:             "14B8DD", // light blue
170:         );
171:         $pos = (int)rand(0, count($color_array)-1);
172:         return $color_array[$pos];
173:     }
174: 
175:     /** STATIC FUNCTIONS */
176:     /**
177:      * Get the Status for an Activity
178:      * @param int $id ID of Activity
179:      *
180:      * @return string Status
181:      * @throws InvalidParameterException
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:      * Returns the Activities where a User has been called in, or has joined.
189:      *
190:      * @param int  $user_id     ID of the User to get Activities from
191:      * @param bool $joined_only Only return Activities where the User has joined to a Group
192:      *
193:      * @return static[] Array of Activities
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:     // TEACHERS
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:     // STUDENTS
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:     // GROUPS
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:     // TASKS
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:     // TEACHER RESOURCE STORYBOARDS
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:     // TEACHER RESOURCE VIDEOS
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:     // TEACHER RESOURCE FILES
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:      * Gets all published Storyboards from the Tasks contained inside an Activity
335:      *
336:      * @param int $id Activity ID
337:      *
338:      * @return ClipitStoryboard[] Array of Storyboards
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:      * Gets all published Videos from the Tasks contained inside an Activity
351:      *
352:      * @param int $id Activity ID
353:      *
354:      * @return ClipitVideo[] Array of Videos
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: }
API documentation generated by ApiGen 2.8.0