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:  * A collection of Students contained inside an Activity. Also links to all Group Resources.
 17:  */
 18: class ClipitGroup extends UBItem {
 19:     /**
 20:      * @const string Elgg entity SUBTYPE for this class
 21:      */
 22:     const SUBTYPE = "ClipitGroup";
 23:     const REL_GROUP_USER = "ClipitGroup-ClipitUser";
 24:     const REL_GROUP_FILE = "ClipitGroup-ClipitFile";
 25:     const REL_GROUP_STORYBOARD = "ClipitGroup-ClipitStoryboard";
 26:     const REL_GROUP_VIDEO = "ClipitGroup-ClipitVideo";
 27:     const REL_GROUP_TAG = "ClipitGroup-ClipitTag";
 28:     public $user_array = array();
 29:     public $file_array = array();
 30:     public $storyboard_array = array();
 31:     public $video_array = array();
 32:     public $tag_array = array();
 33:     public $activity = 0;
 34: 
 35:     /**
 36:      * Loads object parameters stored in Elgg
 37:      *
 38:      * @param ElggEntity $elgg_entity Elgg Object to load parameters from.
 39:      */
 40:     protected function copy_from_elgg($elgg_entity) {
 41:         parent::copy_from_elgg($elgg_entity);
 42:         $this->user_array = static::get_users($this->id);
 43:         $this->file_array = static::get_files($this->id);
 44:         $this->storyboard_array = static::get_storyboards($this->id);
 45:         $this->video_array = static::get_videos($this->id);
 46:         $this->tag_array = static::get_tags($this->id);
 47:         $this->activity = static::get_activity($this->id);
 48:     }
 49: 
 50:     /**
 51:      * Saves this instance to the system.
 52:      * @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!
 53:      * @return bool|int Returns the Id of the saved instance, or false if error
 54:      */
 55:     protected function save($double_save=false) {
 56:         parent::save($double_save);
 57:         static::set_users($this->id, $this->user_array);
 58:         static::set_files($this->id, $this->file_array);
 59:         static::set_videos($this->id, $this->video_array);
 60:         static::set_storyboards($this->id, $this->storyboard_array);
 61:         static::set_tags($this->id, $this->tag_array);
 62:         if($this->activity != 0) {
 63:             ClipitActivity::add_groups($this->activity, array($this->id));
 64:         }
 65:         return $this->id;
 66:     }
 67: 
 68:     /**
 69:      * Returns the Group where a User is taking part in an Activity
 70:      *
 71:      * @param int $user_id     User ID
 72:      * @param int $activity_id Activity ID
 73:      *
 74:      * @return bool|int Returns the Group ID, or false if not found
 75:      */
 76:     static function get_from_user_activity($user_id, $activity_id) {
 77:         $user_groups = array_flip(ClipitUser::get_groups($user_id));
 78:         $activity_groups = array_flip(ClipitActivity::get_groups($activity_id));
 79:         $intersection = array_flip(array_intersect_key($user_groups, $activity_groups));
 80:         if(empty($intersection) || count($intersection) != 1) {
 81:             return false;
 82:         }
 83:         return (int)array_pop($intersection);
 84:     }
 85: 
 86:     /**
 87:      * Gets the Activity Id in which a Group takes part in.
 88:      *
 89:      * @param int $id Id from the Group.
 90:      *
 91:      * @return bool|int Returns an Activity Id.
 92:      */
 93:     static function get_activity($id) {
 94:         $temp_array = get_entity_relationships($id, true);
 95:         foreach($temp_array as $rel) {
 96:             if($rel->relationship == ClipitActivity::REL_ACTIVITY_GROUP) {
 97:                 $rel_array[] = $rel;
 98:             }
 99:         }
100:         if(!isset($rel_array) || count($rel_array) != 1) {
101:             return false;
102:         }
103:         return array_pop($rel_array)->guid_one;
104:     }
105: 
106:     /**
107:      * Add Users to a Group.
108:      *
109:      * @param int   $id         Id of the Group to add Users to.
110:      * @param array $user_array Array of User Ids to add to the Group.
111:      *
112:      * @return bool Returns true if added correctly, or false if error.
113:      */
114:     static function add_users($id, $user_array) {
115:         return UBCollection::add_items($id, $user_array, static::REL_GROUP_USER);
116:     }
117: 
118:     static function set_users($id, $user_array) {
119:         return UBCollection::set_items($id, $user_array, static::REL_GROUP_USER);
120:     }
121: 
122:     /**
123:      * Remove Users from a Group.
124:      *
125:      * @param int   $id         Id of the Group to remove Users from.
126:      * @param array $user_array Array of User Ids to remove from the Group.
127:      *
128:      * @return bool Returns true if removed correctly, or false if error.
129:      */
130:     static function remove_users($id, $user_array) {
131:         return UBCollection::remove_items($id, $user_array, static::REL_GROUP_USER);
132:     }
133: 
134:     /**
135:      * Get User Ids from a Group.
136:      *
137:      * @param int $id Id of the Group to get Users from.
138:      *
139:      * @return bool Returns array of User Ids, or false if error.
140:      */
141:     static function get_users($id) {
142:         return UBCollection::get_items($id, static::REL_GROUP_USER);
143:     }
144: 
145:     /**
146:      * Add Files to a Group.
147:      *
148:      * @param int   $id         Id of the Group to add Files to.
149:      * @param array $file_array Array of File Ids to add to the Group.
150:      *
151:      * @return bool Returns true if added correctly, or false if error.
152:      */
153:     static function add_files($id, $file_array) {
154:         return UBCollection::add_items($id, $file_array, static::REL_GROUP_FILE);
155:     }
156: 
157:     static function set_files($id, $file_array) {
158:         return UBCollection::set_items($id, $file_array, static::REL_GROUP_FILE);
159:     }
160: 
161:     /**
162:      * Remove Files from a Group.
163:      *
164:      * @param int   $id         Id of the Group to remove Files from.
165:      * @param array $file_array Array of File Ids to remove from the Group.
166:      *
167:      * @return bool Returns true if removed correctly, or false if error.
168:      */
169:     static function remove_files($id, $file_array) {
170:         return UBCollection::remove_items($id, $file_array, static::REL_GROUP_FILE);
171:     }
172: 
173:     /**
174:      * Get File Ids from a Group.
175:      *
176:      * @param int $id Id of the Group to get Files from.
177:      *
178:      * @return bool Returns array of User Ids, or false if error.
179:      */
180:     static function get_files($id) {
181:         return UBCollection::get_items($id, static::REL_GROUP_FILE);
182:     }
183: 
184:     /**
185:      * Add Storyboards to a Group.
186:      *
187:      * @param int   $id               Id of the Group to add Storyboards to.
188:      * @param array $storyboard_array Array of Storyboard Ids to add to the Group.
189:      *
190:      * @return bool Returns true if added correctly, or false if error.
191:      */
192:     static function add_storyboards($id, $storyboard_array) {
193:         return UBCollection::add_items($id, $storyboard_array, static::REL_GROUP_STORYBOARD);
194:     }
195: 
196:     static function set_storyboards($id, $storyboard_array) {
197:         return UBCollection::set_items($id, $storyboard_array, static::REL_GROUP_STORYBOARD);
198:     }
199: 
200:     static function remove_storyboards($id, $storyboard_array) {
201:         return UBCollection::remove_items($id, $storyboard_array, static::REL_GROUP_STORYBOARD);
202:     }
203: 
204:     static function get_storyboards($id) {
205:         return UBCollection::get_items($id, static::REL_GROUP_STORYBOARD);
206:     }
207: 
208:     /**
209:      * Add Videos to a Group.
210:      *
211:      * @param int   $id          Id of the Group to add Videos to.
212:      * @param array $video_array Array of Video Ids to add to the Group.
213:      *
214:      * @return bool Returns true if added correctly, or false if error.
215:      */
216:     static function add_videos($id, $video_array) {
217:         return UBCollection::add_items($id, $video_array, static::REL_GROUP_VIDEO);
218:     }
219: 
220:     static function set_videos($id, $video_array) {
221:         return UBCollection::set_items($id, $video_array, static::REL_GROUP_VIDEO);
222:     }
223: 
224:     /**
225:      * Remove Videos from a Group.
226:      *
227:      * @param int   $id          Id of the Group to remove Videos from.
228:      * @param array $video_array Array of Video Ids to remove from the Group.
229:      *
230:      * @return bool Returns true if removed correctly, or false if error.
231:      */
232:     static function remove_videos($id, $video_array) {
233:         return UBCollection::remove_items($id, $video_array, static::REL_GROUP_VIDEO);
234:     }
235: 
236:     /**
237:      * Get Video Ids from a Group.
238:      *
239:      * @param int $id Id of the Group to get Videos from.
240:      *
241:      * @return bool Returns array of Video Ids, or false if error.
242:      */
243:     static function get_videos($id) {
244:         return UBCollection::get_items($id, static::REL_GROUP_VIDEO);
245:     }
246: 
247:     /**
248:      * Add Tags for a Group to work on.
249:      *
250:      * @param int   $id          Id of the Group to add Tags to.
251:      * @param array $tag_array  Array of Tag Ids to add to the Group.
252:      *
253:      * @return bool Returns true if added correctly, or false if error.
254:      */
255:     static function add_tags($id, $tag_array) {
256:         return UBCollection::add_items($id, $tag_array, static::REL_GROUP_TAG);
257:     }
258: 
259:     static function set_tags($id, $tag_array) {
260:         return UBCollection::set_items($id, $tag_array, static::REL_GROUP_TAG);
261:     }
262: 
263:     static function remove_tags($id, $tag_array) {
264:         return UBCollection::remove_items($id, $tag_array, static::REL_GROUP_TAG);
265:     }
266: 
267:     static function get_tags($id) {
268:         return UBCollection::get_items($id, static::REL_GROUP_TAG);
269:     }
270: }
271: 
API documentation generated by ApiGen 2.8.0