1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14:
15: 16: 17:
18: class ClipitExample extends UBItem {
19: 20: 21:
22: const SUBTYPE = "ClipitExample";
23: const REL_EXAMPLE_TAG = "ClipitExample-ClipitTag";
24: const REL_EXAMPLE_EXAMPLETYPE = "ClipitExample-ClipitExampleType";
25: const REL_EXAMPLE_STORYBOARD = "ClipitExample-ClipitStoryboard";
26: const REL_EXAMPLE_VIDEO = "ClipitExample-ClipitVideo";
27: const REL_EXAMPLE_FILE = "ClipitExample-ClipitFile";
28: public $tricky_topic = 0;
29: public $tag_array = array();
30: public $example_type_array = array();
31: public $country = "";
32: public $location = "";
33:
34: public $storyboard_array = array();
35: public $video_array = array();
36: public $file_array = array();
37:
38: 39: 40: 41: 42:
43: protected function copy_from_elgg($elgg_entity) {
44: parent::copy_from_elgg($elgg_entity);
45: $this->tricky_topic = (int)static::get_tricky_topic($this->id);
46: $this->tag_array = (array)static::get_tags($this->id);
47: $this->example_type_array = (array)static::get_example_types($this->id);
48: $this->country = (string)$elgg_entity->get("country");
49: $this->location = (string)$elgg_entity->get("location");
50: $this->video_array = static::get_videos($this->id);
51: $this->storyboard_array = static::get_storyboards($this->id);
52: $this->file_array = static::get_files($this->id);
53: }
54:
55: 56: 57: 58: 59:
60: protected function copy_to_elgg($elgg_entity) {
61: parent::copy_to_elgg($elgg_entity);
62: $elgg_entity->set("country", (string)$this->country);
63: $elgg_entity->set("location", (string)$this->location);
64: }
65:
66: protected function save($double_save=false) {
67: parent::save($double_save);
68: static::set_tricky_topic($this->id, (int)$this->tricky_topic);
69: static::set_tags($this->id, (array)$this->tag_array);
70: static::set_example_types($this->id, (array)$this->example_type_array);
71: static::set_videos($this->id, $this->video_array);
72: static::set_storyboards($this->id, $this->storyboard_array);
73: static::set_files($this->id, $this->file_array);
74: return $this->id;
75: }
76:
77: static function get_by_tags($tag_array){
78: $return_examples = array();
79: $example_array = static::get_all(0);
80: if(empty($example_array) || empty($tag_array)){
81: return $return_examples;
82: }
83: foreach($example_array as $example){
84: foreach($example->tag_array as $tag){
85: if(array_search($tag, $tag_array) !== false){
86: $return_examples[] = $example;
87: break;
88: }
89: }
90: }
91: return $return_examples;
92: }
93:
94: static function get_tricky_topic($id) {
95: $ret_array = UBCollection::get_items($id, ClipitTrickyTopic::REL_TRICKYTOPIC_EXAMPLE, true);
96: if(!empty($ret_array)){
97: return array_pop($ret_array);
98: }
99: return 0;
100: }
101:
102: static function set_tricky_topic($id, $tricky_topic_id) {
103: return ClipitTrickyTopic::add_examples($tricky_topic_id, array($id));
104: }
105:
106: static function get_from_tricky_topic($tricky_topic_id) {
107: return ClipitExample::get_by_id(ClipitTrickyTopic::get_examples($tricky_topic_id));
108: }
109:
110: 111: 112: 113: 114: 115: 116: 117:
118: static function add_tags($id, $tag_array) {
119: return UBCollection::add_items($id, $tag_array, static::REL_EXAMPLE_TAG);
120: }
121:
122: 123: 124: 125: 126: 127: 128: 129:
130: static function set_tags($id, $tag_array) {
131: return UBCollection::set_items($id, $tag_array, static::REL_EXAMPLE_TAG);
132: }
133:
134: 135: 136: 137: 138: 139: 140: 141:
142: static function remove_tags($id, $tag_array) {
143: return UBCollection::remove_items($id, $tag_array, static::REL_EXAMPLE_TAG);
144: }
145:
146: 147: 148: 149: 150: 151: 152:
153: static function get_tags($id) {
154: return UBCollection::get_items($id, static::REL_EXAMPLE_TAG);
155: }
156:
157: 158: 159: 160: 161: 162: 163: 164:
165: static function add_example_types($id, $example_type_array) {
166: return UBCollection::add_items($id, $example_type_array, static::REL_EXAMPLE_EXAMPLETYPE);
167: }
168:
169: 170: 171: 172: 173: 174: 175: 176:
177: static function set_example_types($id, $example_type_array) {
178: return UBCollection::set_items($id, $example_type_array, static::REL_EXAMPLE_EXAMPLETYPE);
179: }
180:
181: 182: 183: 184: 185: 186: 187: 188:
189: static function remove_example_types($id, $example_type_array) {
190: return UBCollection::remove_items($id, $example_type_array, static::REL_EXAMPLE_EXAMPLETYPE);
191: }
192:
193: 194: 195: 196: 197: 198: 199:
200: static function get_example_types($id) {
201: return UBCollection::get_items($id, static::REL_EXAMPLE_EXAMPLETYPE);
202: }
203:
204:
205: static function add_videos($id, $video_array) {
206: return UBCollection::add_items($id, $video_array, static::REL_EXAMPLE_VIDEO);
207: }
208:
209: static function set_videos($id, $video_array) {
210: return UBCollection::set_items($id, $video_array, static::REL_EXAMPLE_VIDEO);
211: }
212:
213: static function remove_videos($id, $video_array) {
214: return UBCollection::remove_items($id, $video_array, static::REL_EXAMPLE_VIDEO);
215: }
216:
217: static function get_videos($id) {
218: return UBCollection::get_items($id, static::REL_EXAMPLE_VIDEO);
219: }
220:
221:
222: static function add_storyboards($id, $storyboard_array) {
223: return UBCollection::add_items($id, $storyboard_array, static::REL_EXAMPLE_STORYBOARD);
224: }
225:
226: static function set_storyboards($id, $storyboard_array) {
227: return UBCollection::set_items($id, $storyboard_array, static::REL_EXAMPLE_STORYBOARD);
228: }
229:
230: static function remove_storyboards($id, $storyboard_array) {
231: return UBCollection::remove_items($id, $storyboard_array, static::REL_EXAMPLE_STORYBOARD);
232: }
233:
234: static function get_storyboards($id) {
235: return UBCollection::get_items($id, static::REL_EXAMPLE_STORYBOARD);
236: }
237:
238:
239: static function add_files($id, $file_array) {
240: return UBCollection::add_items($id, $file_array, static::REL_EXAMPLE_FILE);
241: }
242:
243: static function set_files($id, $file_array) {
244: return UBCollection::set_items($id, $file_array, static::REL_EXAMPLE_FILE);
245: }
246:
247: static function remove_files($id, $file_array) {
248: return UBCollection::remove_items($id, $file_array, static::REL_EXAMPLE_FILE);
249: }
250:
251: static function get_files($id) {
252: return UBCollection::get_items($id, static::REL_EXAMPLE_FILE);
253: }
254: }