1: <?php
2: 3: 4: 5: 6: 7:
8:
9: class ClipitRemoteSite extends UBItem{
10:
11: const REL_REMOTESITE_REMOTETRICKYTOPIC = "ClipitRemoteSite-ClipitRemoteTrickyTopic";
12: const REL_REMOTESITE_REMOTEVIDEO = "ClipitRemoteSite-ClipitRemoteVideo";
13: public $timezone = "";
14: public $tricky_topic_array = array();
15: public $video_array = array();
16:
17: static function create($prop_value_array){
18:
19: $prop_value_array["name"] = base64_decode($prop_value_array["name"]);
20: $prop_value_array["description"] = base64_decode($prop_value_array["description"]);
21: $prop_value_array["url"] = base64_decode($prop_value_array["url"]);
22: return parent::create($prop_value_array);
23: }
24:
25: protected function copy_from_elgg($elgg_entity) {
26: parent::copy_from_elgg($elgg_entity);
27: $this->timezone = (string)$elgg_entity->get("timezone");
28: $this->tricky_topic_array = (array)static::get_tricky_topics($this->id);
29: $this->video_array = (array)static::get_videos($this->id);
30: }
31:
32: 33: 34: 35: 36:
37: protected function copy_to_elgg($elgg_entity) {
38: parent::copy_to_elgg($elgg_entity);
39: $elgg_entity->set("timezone", (array)$this->timezone);
40: }
41:
42: 43: 44: 45: 46: 47:
48: protected function save($double_save = false) {
49: parent::save($double_save);
50: static::set_tricky_topics($this->id, $this->tricky_topic_array);
51: static::set_videos($this->id, $this->video_array);
52: return $this->id;
53: }
54:
55: 56: 57: 58: 59: 60: 61: 62: 63:
64: static function set_properties($id, $prop_value_array) {
65: $item = null;
66:
67: if(empty($id) && array_key_exists("url", $prop_value_array)){
68: $item = static::get_from_url($prop_value_array["url"]);
69: }
70: if(empty($item)){
71: if (!$item = new static($id)) {
72: return false;
73: }
74: }
75: $property_list = (array)static::list_properties();
76:
77: foreach ($prop_value_array as $prop => $value) {
78: if (!array_key_exists($prop, $property_list)) {
79: throw new InvalidParameterException("ERROR: One or more property names do not exist.");
80: }
81: if ($prop == "id") {
82: throw new InvalidParameterException("ERROR: Cannot modify 'id' of instance.");
83: }
84: $item->$prop = $value;
85: }
86: return $item->save();
87: }
88:
89: 90: 91: 92: 93:
94: static function get_from_url($url, $id_only = false){
95: if($decoded_url = base64_decode($url)){
96: $url = $decoded_url;
97: }
98: $remote_site_array = static::get_all();
99: foreach($remote_site_array as $remote_site){
100: if((string)$remote_site->url == $url){
101: return $id_only ? (int)$remote_site->id : $remote_site;
102: }
103: }
104: return null;
105: }
106:
107:
108: static function add_tricky_topics($id, $tricky_topic_array) {
109: return UBCollection::add_items($id, $tricky_topic_array, static::REL_REMOTESITE_REMOTETRICKYTOPIC);
110: }
111: static function set_tricky_topics($id, $tricky_topic_array) {
112: return UBCollection::set_items($id, $tricky_topic_array, static::REL_REMOTESITE_REMOTETRICKYTOPIC);
113: }
114: static function remove_tricky_topics($id, $tricky_topic_array) {
115: return UBCollection::remove_items($id, $tricky_topic_array, static::REL_REMOTESITE_REMOTETRICKYTOPIC);
116: }
117: static function get_tricky_topics($id) {
118: return UBCollection::get_items($id, static::REL_REMOTESITE_REMOTETRICKYTOPIC);
119: }
120:
121:
122: static function add_videos($id, $video_array) {
123: return UBCollection::add_items($id, $video_array, static::REL_REMOTESITE_REMOTEVIDEO);
124: }
125: static function set_videos($id, $video_array) {
126: return UBCollection::set_items($id, $video_array, static::REL_REMOTESITE_REMOTEVIDEO);
127: }
128: static function remove_videos($id, $video_array) {
129: return UBCollection::remove_items($id, $video_array, static::REL_REMOTESITE_REMOTEVIDEO);
130: }
131: static function get_videos($id) {
132: return UBCollection::get_items($id, static::REL_REMOTESITE_REMOTEVIDEO);
133: }
134:
135: }