1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13:
14: 15: 16:
17: class ClipitRemoteVideo extends UBItem {
18: const SUBTYPE = "ClipitRemoteVideo";
19: public $remote_id;
20: public $remote_site = 0;
21: public $tag_array = array();
22: 23: 24: 25: 26:
27: protected function copy_from_elgg($elgg_entity) {
28: parent::copy_from_elgg($elgg_entity);
29: $this->remote_id = (int)$elgg_entity->get("remote_id");
30: $this->remote_site = (int)$elgg_entity->get("remote_site");
31: $this->tag_array = (array)$elgg_entity->get("tag_array");
32: }
33: 34: 35: 36: 37:
38: protected function copy_to_elgg($elgg_entity) {
39: parent::copy_to_elgg($elgg_entity);
40: $elgg_entity->set("remote_id", (int)$this->remote_id);
41: $elgg_entity->set("remote_site", (int)$this->remote_site);
42: $elgg_entity->set("tag_array", (array)$this->tag_array);
43: }
44: static function create($prop_value_array){
45:
46: $remote_site_url = base64_decode($prop_value_array["remote_site"]);
47: $remote_site_id = ClipitRemoteSite::get_from_url($remote_site_url, true);
48: $prop_value_array["remote_site"] = $remote_site_id;
49:
50: $prop_value_array["name"] = base64_decode($prop_value_array["name"]);
51: $prop_value_array["description"] = base64_decode($prop_value_array["description"]);
52: $prop_value_array["url"] = base64_decode($prop_value_array["url"]);
53:
54: $tag_name_array = json_decode(base64_decode($prop_value_array["tag_array"]));
55: $tag_array = array();
56: foreach($tag_name_array as $tag_name){
57: $tag_array[] = (int)ClipitTag::create(array("name" => $tag_name));
58: }
59: $prop_value_array["tag_array"] = (array)$tag_array;
60: $id = parent::create($prop_value_array);
61: ClipitRemoteSite::add_videos($remote_site_id, array($id));
62: return $id;
63: }
64: static function get_by_tags($tag_array){
65: $video_array = static::get_all();
66: $return_array = array();
67: foreach($video_array as $video){
68: $intersection = array_intersect($video->tag_array, $tag_array);
69: if(!empty($intersection)){
70: $return_array[] = $video;
71: }
72: }
73: return $return_array;
74: }
75:
76: static function get_by_remote_id($remote_site, $remote_id_array){
77: $remote_site_id = ClipitRemoteSite::get_from_url(base64_decode($remote_site), true);
78: $remote_videos = ClipitRemoteVideo::get_all();
79: $remote_video_array = array();
80: foreach($remote_videos as $remote_video){
81: if($remote_video->remote_site == $remote_site_id && array_search($remote_video->remote_id, $remote_id_array) !== false){
82: $remote_video_array[] = $remote_video;
83: }
84: }
85: return $remote_video_array;
86: }
87: static function delete_by_remote_id($remote_site, $remote_id_array){
88: $remote_site_id = ClipitRemoteSite::get_from_url(base64_decode($remote_site), true);
89: $remote_video_array = static::get_by_remote_id($remote_site_id, $remote_id_array);
90: $remote_video_id_array = array();
91: foreach($remote_video_array as $video){
92: $remote_video_id_array[] = $video->id;
93: }
94: static::delete_by_id($remote_video_id_array);
95: return true;
96: }
97: static function get_from_site($remote_site, $remote_ids_only = false){
98: $remote_site_id = ClipitRemoteSite::get_from_url(base64_decode($remote_site), true);
99: $video_array = static::get_all();
100: $return_array = array();
101: foreach($video_array as $video){
102: if((int)$video->remote_site == $remote_site_id) {
103: if($remote_ids_only) {
104: $return_array[] = $video->remote_id;
105: } else{
106: $return_array[] = $video;
107: }
108: }
109: }
110: return $return_array;
111: }
112: static function delete_from_site($remote_site){
113: $remote_site_id = ClipitRemoteSite::get_from_url(base64_decode($remote_site), true);
114: $video_array = static::get_all();
115: $delete_array = array();
116: foreach($video_array as $video){
117: if((int)$video->remote_site == $remote_site_id){
118: $delete_array[] = $video->id;
119: }
120: }
121: return static::delete_by_id($delete_array);
122: }
123: }