1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17:
18: class ClipitGroup extends UBItem {
19: 20: 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: 37: 38: 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: 52: 53: 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: 70: 71: 72: 73: 74: 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: 88: 89: 90: 91: 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: 108: 109: 110: 111: 112: 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: 124: 125: 126: 127: 128: 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: 136: 137: 138: 139: 140:
141: static function get_users($id) {
142: return UBCollection::get_items($id, static::REL_GROUP_USER);
143: }
144:
145: 146: 147: 148: 149: 150: 151: 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: 163: 164: 165: 166: 167: 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: 175: 176: 177: 178: 179:
180: static function get_files($id) {
181: return UBCollection::get_items($id, static::REL_GROUP_FILE);
182: }
183:
184: 185: 186: 187: 188: 189: 190: 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: 210: 211: 212: 213: 214: 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: 226: 227: 228: 229: 230: 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: 238: 239: 240: 241: 242:
243: static function get_videos($id) {
244: return UBCollection::get_items($id, static::REL_GROUP_VIDEO);
245: }
246:
247: 248: 249: 250: 251: 252: 253: 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: