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

  • ClipitActivity
  • ClipitChat
  • ClipitComment
  • ClipitEvent
  • ClipitExample
  • ClipitFile
  • ClipitGroup
  • ClipitLA
  • ClipitLabel
  • ClipitPerformanceItem
  • ClipitPerformanceRating
  • ClipitPost
  • ClipitQuiz
  • ClipitQuizQuestion
  • ClipitQuizResult
  • ClipitRating
  • ClipitRemoteTrickyTopic
  • ClipitRemoteVideo
  • ClipitResource
  • ClipitSite
  • ClipitStoryboard
  • ClipitTag
  • ClipitTagRating
  • ClipitTask
  • ClipitTrickyTopic
  • ClipitUser
  • ClipitVideo
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /**
  3:  * ClipIt - JuxtaLearn Web Space
  4:  * PHP version:     >= 5.2
  5:  * Creation date:   2013-10-10
  6:  * Last update:     $Date$
  7:  * @author          Pablo LlinĂ¡s Arnaiz <pebs74@gmail.com>, URJC JuxtaLearn Team
  8:  * @version         $Version$
  9:  * @link            http://www.juxtalearn.eu
 10:  * @license         GNU Affero General Public License v3
 11:  * @package         ClipIt
 12:  * @subpackage      clipit_api
 13:  */
 14: /**
 15:  * An class which holds properties for Remote Tricky Topics.
 16:  */
 17: class ClipitRemoteTrickyTopic extends UBItem {
 18:     const SUBTYPE = "ClipitRemoteTrickyTopic";
 19:     const REL_REMOTETRICKYTOPIC_TAG = "ClipitRemoteTrickyTopic-ClipitTag";
 20:     public $remote_id;
 21:     public $remote_site = 0;
 22:     public $tag_array = "";
 23:     /**
 24:      * Loads object parameters stored in Elgg
 25:      *
 26:      * @param ElggEntity $elgg_entity Elgg Object to load parameters from.
 27:      */
 28:     protected function copy_from_elgg($elgg_entity) {
 29:         parent::copy_from_elgg($elgg_entity);
 30:         $this->remote_id = (int)$elgg_entity->get("remote_id");
 31:         $this->remote_site = (int)$elgg_entity->get("remote_site");
 32:         $this->tag_array = (array)static::get_tags($this->id);
 33:     }
 34:     /**
 35:      * Copy $this object parameters into an Elgg entity.
 36:      *
 37:      * @param ElggEntity $elgg_entity Elgg object instance to save $this to
 38:      */
 39:     protected function copy_to_elgg($elgg_entity) {
 40:         parent::copy_to_elgg($elgg_entity);
 41:         $elgg_entity->set("remote_id", (int)$this->remote_id);
 42:         $elgg_entity->set("remote_site", (int)$this->remote_site);
 43:         static::set_tags((int)$this->id, (array)$this->tag_array);
 44:     }
 45:     static function create($prop_value_array){
 46:         // convert "remote_site" from string to local ID
 47:         $remote_site_url = base64_decode($prop_value_array["remote_site"]);
 48:         $remote_site_id = ClipitRemoteSite::get_from_url($remote_site_url, true);
 49:         $prop_value_array["remote_site"] = $remote_site_id;
 50:         // Base64 decode some properties which can contain special characters
 51:         $prop_value_array["name"] = base64_decode($prop_value_array["name"]);
 52:         $prop_value_array["description"] = base64_decode($prop_value_array["description"]);
 53:         // convert tag_array from array of names to array of local IDs
 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_tricky_topics($remote_site_url, array($id));
 62:         return $id;
 63:     }
 64: 
 65:     /**
 66:      * Adds Tags to a Tricky Topic, referenced by Id.
 67:      *
 68:      * @param int   $id        Id from the Tricky Topic to add Tags to
 69:      * @param array $tag_array Array of Tag Ids to be added to the Tricky Topic
 70:      *
 71:      * @return bool Returns true if success, false if error
 72:      */
 73:     static function add_tags($id, $tag_array) {
 74:         return UBCollection::add_items($id, $tag_array, static::REL_REMOTETRICKYTOPIC_TAG);
 75:     }
 76:     /**
 77:      * Sets Tags to a Tricky Topic, referenced by Id.
 78:      *
 79:      * @param int   $id        Id from the Tricky Topic to set Tags to
 80:      * @param array $tag_array Array of Tag Ids to be set to the Tricky Topic
 81:      *
 82:      * @return bool Returns true if success, false if error
 83:      */
 84:     static function set_tags($id, $tag_array) {
 85:         return UBCollection::set_items($id, $tag_array, static::REL_REMOTETRICKYTOPIC_TAG);
 86:     }
 87:     /**
 88:      * Remove Tags from a Tricky Topic.
 89:      *
 90:      * @param int   $id        Id from Tricky Topic to remove Tags from
 91:      * @param array $tag_array Array of Tag Ids to remove from Tricky Topic
 92:      *
 93:      * @return bool Returns true if success, false if error
 94:      */
 95:     static function remove_tags($id, $tag_array) {
 96:         return UBCollection::remove_items($id, $tag_array, static::REL_REMOTETRICKYTOPIC_TAG);
 97:     }
 98:     /**
 99:      * Get all Tags from a Tricky Topic
100:      *
101:      * @param int $id Id of the Tricky Topic to get Tags from
102:      *
103:      * @return array|bool Returns an array of Tag IDs, or false if error
104:      */
105:     static function get_tags($id) {
106:         return UBCollection::get_items($id, static::REL_REMOTETRICKYTOPIC_TAG);
107:     }
108: 
109:     // FOR REST API CALLS (remote_site comes as an URL)
110:     /**
111:      * @param string $remote_site
112:      * @param int[] $remote_id_array
113:      * @return array
114:      */
115:     static function get_by_remote_id($remote_site, $remote_id_array){
116:         $remote_site_id = ClipitRemoteSite::get_from_url(base64_decode($remote_site), true);
117:         $tricky_topic_array = static::get_all();
118:         $return_array = array();
119:         foreach($tricky_topic_array as $tricky_topic){
120:             if($tricky_topic->remote_site == $remote_site_id
121:                 && array_search($tricky_topic->remote_id,  $remote_id_array) !== false){
122:                 $return_array[] = $tricky_topic;
123:             }
124:         }
125:         return $return_array;
126:     }
127:     /**
128:      * @param string $remote_site
129:      * @param int[] $remote_id_array
130:      * @return bool
131:      */
132:     static function delete_by_remote_id($remote_site, $remote_id_array){
133:         $remote_site_id = ClipitRemoteSite::get_from_url(base64_decode($remote_site), true);
134:         $tricky_topic_array = static::get_by_remote_id($remote_site_id, $remote_id_array);
135:         $delete_array = array();
136:         foreach($tricky_topic_array as $tricky_topic){
137:             $delete_array[] = $tricky_topic->id;
138:         }
139:         static::delete_by_id($delete_array);
140:         return true;
141:     }
142:     /**
143:      * @param string $remote_site
144:      * @param bool $remote_ids_only Only return remote IDs
145:      * @return array
146:      */
147:     static function get_from_site($remote_site, $remote_ids_only = false){
148:         $remote_site_id = ClipitRemoteSite::get_from_url(base64_decode($remote_site), true);
149:         $tricky_topic_array = static::get_all();
150:         $return_array = array();
151:         foreach($tricky_topic_array as $tricky_topic){
152:             if((int)$tricky_topic->remote_site == $remote_site_id) {
153:                 if($remote_ids_only) {
154:                     $return_array[] = $tricky_topic->remote_id;
155:                 } else{
156:                     $return_array[] = $tricky_topic;
157:                 }
158:             }
159:         }
160:         return $return_array;
161:     }
162:     /**
163:      * @param string $remote_site
164:      * @return bool
165:      */
166:     static function delete_all_from_site($remote_site){
167:         $remote_site_id = ClipitRemoteSite::get_from_url(base64_decode($remote_site), true);
168:         $tricky_topic_array = static::get_from_site($remote_site_id);
169:         $delete_array = array();
170:         foreach($tricky_topic_array as $tricky_topic){
171:             if((int)$tricky_topic->remote_site == $remote_site_id){
172:                 $delete_array[] = $tricky_topic->id;
173:             }
174:         }
175:         return static::delete_by_id($delete_array);
176:     }
177: 
178: }
API documentation generated by ApiGen 2.8.0