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: 05/12/2014
  6:  * Time: 13:45
  7:  */
  8: 
  9: class ClipitExampleType extends UBItem{
 10:     /**
 11:      * @const string Elgg entity SUBTYPE for this class
 12:      */
 13:     const SUBTYPE = "ClipitExampleType";
 14: 
 15:     /*
 16:     Properties are disposed in arrays by language, in the following order:
 17:     [0 => en, 1 => es, 2 => de, 3 => pt]
 18:     To get the language index for a language code, use: get_language_index($lang_code);
 19:     E.g.: to get the Spanish translation of the Item's name: $item->item_name[get_language_index("es")]
 20:     */
 21:     public $reference = array();
 22:     public $item_name = array();
 23:     public $item_description = array();
 24:     public $category = array();
 25:     public $category_description = array();
 26: 
 27: 
 28:     /**
 29:      * Loads object parameters stored in Elgg
 30:      *
 31:      * @param ElggEntity $elgg_entity Elgg Object to load parameters from.
 32:      */
 33:     protected function copy_from_elgg($elgg_entity) {
 34:         parent::copy_from_elgg($elgg_entity);
 35:         $this->reference = (int)$elgg_entity->get("reference");
 36:         $this->item_name = (array)$elgg_entity->get("item_name");
 37:         $this->item_description = (array)$elgg_entity->get("item_description");
 38:         $this->category = (array)$elgg_entity->get("category");
 39:         $this->category_description = (array)$elgg_entity->get("category_description");
 40:     }
 41: 
 42:     /**
 43:      * Copy $this object parameters into an Elgg entity.
 44:      *
 45:      * @param ElggEntity $elgg_entity Elgg object instance to save $this to
 46:      */
 47:     protected function copy_to_elgg($elgg_entity) {
 48:         parent::copy_to_elgg($elgg_entity);
 49:         $elgg_entity->set("reference", (int)$this->reference);
 50:         $elgg_entity->set("item_name", (array)$this->item_name);
 51:         $elgg_entity->set("item_description", (array)$this->item_description);
 52:         $elgg_entity->set("category", (array)$this->category);
 53:         $elgg_entity->set("category_description", (array)$this->category_description);
 54:     }
 55: 
 56:     static function create($prop_value_array){
 57:         if(isset($prop_value_array["reference"])){
 58:             $item = static::get_by_reference((int)$prop_value_array["reference"]);
 59:             if(!empty($item)) {
 60:                 return static::set_properties($item->id, $prop_value_array);
 61:             }
 62:         }
 63:         return static::set_properties(null, $prop_value_array);
 64:     }
 65: 
 66:     static function set_properties($id, $prop_value_array){
 67:         if(!$item = new static($id)) {
 68:             return false;
 69:         }
 70: 
 71:         if(!isset($prop_value_array["language"])){
 72:             $lang_index = 0;
 73:         }else{
 74:             $lang_index = static::get_language_index($prop_value_array["language"]);
 75:             unset($prop_value_array["language"]);
 76:         }
 77:         $property_list = (array)static::list_properties();
 78:         foreach($prop_value_array as $prop => $value) {
 79:             if(!array_key_exists($prop, $property_list) && $prop != "language") {
 80:                 throw new InvalidParameterException("ERROR: One or more property names do not exist.");
 81:             }
 82:             if($prop == "id") {
 83:                 continue; // cannot set an item's ID or language.
 84:             }
 85:             // Check for multilanguage properties
 86:             if(array_search(
 87:                     $prop,
 88:                     array("item_name", "item_description", "category", "category_description"))
 89:                 !== false){
 90:                 $prop_array = (array)$item->$prop;
 91:                 $prop_array[$lang_index] = $value;
 92:                 $item->$prop = (array)$prop_array;
 93:             } else {
 94:                 $item->$prop = $value;
 95:             }
 96:         }
 97:         if (array_key_exists("time_created",$prop_value_array)) {
 98:             return $item->save(true);
 99:         } else {
100:             return $item->save(false);
101:         }
102:     }
103: 
104:     static function get_language_index($language){
105:         switch ((string)$language){
106:             case "en":
107:                 $lang_index = 0;
108:                 break;
109:             case "es":
110:                 $lang_index = 1;
111:                 break;
112:             case "de":
113:                 $lang_index = 2;
114:                 break;
115:             case "pt":
116:                 $lang_index = 3;
117:                 break;
118:             case "sv":
119:                 $lang_index = 4;
120:                 break;
121:             default:
122:                 $lang_index = 0;
123:         }
124:         return $lang_index;
125:     }
126: 
127:     /**
128:      * Gets all Items by category, or all items grouped by category if no category is specified.
129:      *
130:      * @param string $category
131:      * @param string $language
132:      *
133:      * @return static[] Array of Items for the specified category
134:      */
135:     static function get_from_category($category = null, $language = "en") {
136:         $performance_items = static::get_all();
137:         $category_array = array();
138:         $lang_index = static::get_language_index($language);
139:         if (empty($category)) {
140:             foreach ($performance_items as $performance_item) {
141:                 $category_array[$performance_item->category[$lang_index]][] = $performance_item;
142:             }
143:         } else {
144:             foreach ($performance_items as $performance_item) {
145:                 if ($performance_item->category[$lang_index] == $category) {
146:                     $category_array[] = $performance_item;
147:                 }
148:             }
149:         }
150:         return $category_array;
151:     }
152: 
153:     /**
154:      * @param $reference
155:      * @return static|null
156:      */
157:     static function get_by_reference($reference){
158:         $performance_items = static::get_all();
159:         foreach($performance_items as $item){
160:             if((int)$item->reference == (int)$reference) {
161:                 return $item;
162:             }
163:         }
164:         return null;
165:     }
166: }
API documentation generated by ApiGen 2.8.0