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

  • ClipitExampleType
  • ClipitRemoteSite
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * Created by PhpStorm.
  4:  * User: pebs74
  5:  * Date: 11/11/2014
  6:  * Time: 13:09
  7:  */
  8: 
  9: class ClipitRemoteSite extends UBItem{
 10:     // REMOTE SCOPE
 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:         // Base64 decode some properties which can contain special characters
 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:      * Copy $this object parameters into an Elgg entity.
 34:      *
 35:      * @param ElggEntity $elgg_entity Elgg object instance to save $this to
 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:      * Saves Site parameters into Elgg
 44:      * @param bool $double_save if double_save is true, this object is saved twice to ensure that all properties are
 45:      * updated properly. E.g. the time_created property can only beset on ElggObjects during an update. Defaults to false!
 46:      * @return int Site ID
 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:      * Sets values to specified properties of a RemoteSite
 57:      *
 58:      * @param int $id Id of User to set property values
 59:      * @param array $prop_value_array Array of property=>value pairs to set into the RemoteSite
 60:      *
 61:      * @return int|bool Returns Id of User if correct, or false if error
 62:      * @throws InvalidParameterException
 63:      */
 64:     static function set_properties($id, $prop_value_array) {
 65:         $item = null;
 66:         // If no ID specified, try loading remote site from URL
 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:      * @param string $url
 91:      * @param bool $id_only
 92:      * @return static|null
 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:     // REMOTE TRICKY TOPICS
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:     // REMOTE VIDEOS
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: } 
API documentation generated by ApiGen 2.8.0