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: /**
 16:  * A Tag (Stumbling Block) identifier which is linked from one or more Tricky Topics, and which can be added
 17:  * as metadata to Items or Resources.
 18:  */
 19: class ClipitTag extends UBItem {
 20:     /**
 21:      * @const string Elgg entity SUBTYPE for this class
 22:      */
 23:     const SUBTYPE = "ClipitTag";
 24: 
 25:     public $ontologylink = "";
 26: 
 27:     /**
 28:      * Create a new instance of this class, and assign values to its properties.
 29:      *
 30:      * @param array $prop_value_array Array of [property]=>value pairs to set into the new instance
 31:      *
 32:      * @return int|bool Returns instance Id if correct, or false if error
 33:      */
 34:     static function create($prop_value_array) {
 35:         if(!isset($prop_value_array["name"])){
 36:             return null;
 37:         }
 38:         $id_array = static::get_from_search($prop_value_array["name"], true, true);
 39:         if(!empty($id_array)){
 40:             return array_pop($id_array)->id;
 41:         }
 42:         return static::set_properties(null, $prop_value_array);
 43:     }
 44: 
 45:     static function get_tricky_topics($id) {
 46:         return UBCollection::get_items($id, ClipitTrickyTopic::REL_TRICKYTOPIC_TAG, true);
 47:     }
 48: 
 49:     protected function copy_from_elgg($elgg_entity)
 50:     {
 51:         parent::copy_from_elgg($elgg_entity);
 52:         $this->ontologylink = (string)$elgg_entity->get("ontologylink");
 53:     }
 54: 
 55:     protected function copy_to_elgg($elgg_entity)
 56:     {
 57:         parent::copy_to_elgg($elgg_entity);
 58:         if (!empty($this->ontologylink)) {
 59:             $elgg_entity->set("ontologylink", (string)$this->ontologylink);
 60:         } else {
 61:             $elgg_entity->set("ontologylink", "<http://www.juxtalearn.org/Stumbling_Block/".str_replace(" ","_",$this->name).">");
 62:         }
 63:     }
 64:     public function save(){
 65:         return parent::save();
 66:     }
 67: 
 68:     /**
 69:      * Get all objects which match a $search_string
 70:      *
 71:      * @param string $search_string String for searching matching objects
 72:      * @param bool   $name_only     Whether to look only in the name property, default false.
 73:      * @param bool   $strict        Whether to match the $search_string exactly, including case, or only partially.
 74:      * @param int    $offset        The offset of the returned array
 75:      * @param int    $limit         The limit of the returned array
 76:      *
 77:      * @return static[] Returns an array of matched objects
 78:      */
 79:     static function get_from_search($search_string, $name_only = true, $strict = false, $limit = 0, $offset = 0) {
 80:         $search_result = array();
 81:         if(!$strict) {
 82:             $search_string = strtolower($search_string);
 83:             // get the full array of entities
 84:             $elgg_object_array = elgg_get_entities_from_metadata(
 85:                 array('type' => static::TYPE, 'subtype' => static::SUBTYPE, 'limit' => 0, 'metadata_name_value_pairs' => array( name => 'name', value => $search_string.'%', 'operand' => 'LIKE', 'case_sensitive' => FALSE ))
 86:             );
 87:             $search_result = array();
 88:             foreach($elgg_object_array as $elgg_object) {
 89:                 // search for string in name
 90:                 if(strpos(strtolower($elgg_object->name), $search_string) !== false) {
 91:                     $search_result[(int)$elgg_object->guid] = new static((int)$elgg_object->guid, $elgg_object);
 92:                     continue;
 93:                 }
 94:                 // if not in name, search in description
 95:                 if($name_only === false) {
 96:                     if(strpos(strtolower($elgg_object->description), $search_string) !== false) {
 97:                         $search_result[(int)$elgg_object->guid] = new static((int)$elgg_object->guid, $elgg_object);
 98:                     }
 99:                 }
100:             }
101:         } else { // $strict == true
102:             // directly retrieve entities with name = $search_string
103:             $elgg_object_array = elgg_get_entities_from_metadata(
104:                 array(
105:                     'type' => static::TYPE, 'subtype' => static::SUBTYPE, 'metadata_names' => array("name"),
106:                     'metadata_values' => array($search_string), 'limit' => 0
107:                 )
108:             );
109:             if(!empty($elgg_object_array)) {
110:                 foreach($elgg_object_array as $elgg_object) {
111:                     $search_result[(int)$elgg_object->guid] = new static((int)$elgg_object->guid, $elgg_object);
112:                 }
113:             }
114:         }
115:         usort($search_result, function($a,$b){
116:             $length1 = strlen($a->name);
117:             $length2 = strlen($b->name);
118:             return ($length1 < $length2) ? -1 : (($length1 > $length2) ? 1 : 0);
119:         });
120:         if(empty($limit)){
121:             return array_slice($search_result, (int)$offset, count($search_result), true);
122:         } else {
123:             return array_slice($search_result, (int)$offset, (int)$limit, true);
124:         }
125:         //return $search_result;
126:     }
127: 
128: }
API documentation generated by ApiGen 2.8.0