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 5-star Rating on a Performance Items applied to a Resource, submitted by a user as evaluation feedback.
 17:  */
 18: class ClipitPerformanceRating extends UBItem {
 19:     /**
 20:      * @const string Elgg entity SUBTYPE for this class
 21:      */
 22:     const SUBTYPE = "ClipitPerformanceRating";
 23:     public $performance_item = 0;
 24:     public $star_rating = 0;
 25: 
 26:     /**
 27:      * Loads object parameters stored in Elgg
 28:      *
 29:      * @param ElggEntity $elgg_entity Elgg Object to load parameters from.
 30:      */
 31:     protected function copy_from_elgg($elgg_entity) {
 32:         parent::copy_from_elgg($elgg_entity);
 33:         $this->performance_item = (int)$elgg_entity->get("performance_item");
 34:         $this->star_rating = (int)$elgg_entity->get("star_rating");
 35:     }
 36: 
 37:     /**
 38:      * Copy $this object parameters into an Elgg entity.
 39:      *
 40:      * @param ElggEntity $elgg_entity Elgg object instance to save $this to
 41:      */
 42:     protected function copy_to_elgg($elgg_entity) {
 43:         parent::copy_to_elgg($elgg_entity);
 44:         $elgg_entity->set("performance_item", (int)$this->performance_item);
 45:         $elgg_entity->set("star_rating", (int)$this->star_rating);
 46:     }
 47: 
 48:     static function get_by_item($item_array) {
 49:         $performance_rating_array = array();
 50:         foreach($item_array as $item_id) {
 51:             $elgg_objects = elgg_get_entities_from_metadata(
 52:                 array(
 53:                     'type' => static::TYPE, 'subtype' => static::SUBTYPE, 'metadata_names' => array("performance_item"),
 54:                     'metadata_values' => array($item_id), 'limit' => 0
 55:                 )
 56:             );
 57:             if(!empty($elgg_objects)) {
 58:                 $temp_array = array();
 59:                 foreach($elgg_objects as $elgg_object) {
 60:                     $temp_array[] = new static($elgg_object->guid, $elgg_object);
 61:                 }
 62:                 $performance_rating_array[$item_id] = $temp_array;
 63:             } else {
 64:                 $performance_rating_array[$item_id] = null;
 65:             }
 66:         }
 67:         return $performance_rating_array;
 68:     }
 69: 
 70:     /**
 71:      * Get the average Performance Rating for a Target
 72:      *
 73:      * @param int $target_id IF of Target with Performance Ratings
 74:      * @return float|null The Average Performance star rating [0.0 - 5.0]
 75:      * @throws InvalidParameterException
 76:      */
 77:     static function get_average_rating_for_target($target_id) {
 78:         $rating_array = ClipitRating::get_by_target(array($target_id));
 79:         $rating_array = $rating_array[$target_id];
 80:         $average_rating = 0;
 81:         $count = 0;
 82:         if(!empty($rating_array)) {
 83:             foreach($rating_array as $rating) {
 84:                 foreach($rating->performance_rating_array as $performance_rating_id) {
 85:                     $prop_value_array = static::get_properties($performance_rating_id, array("star_rating"));
 86:                     $average_rating += (int)$prop_value_array["star_rating"];
 87:                     $count ++;
 88:                 }
 89:             }
 90:         }
 91:         if(!empty($count)) {
 92:             return $average_rating = $average_rating / $count;
 93:         } else {
 94:             return null;
 95:         }
 96:     }
 97: 
 98:     /**
 99:      * Get the average Performance Rating of each Performance Item for a Target
100:      *
101:      * @param int $target_id ID of Target with Performance Ratings
102:      * @return array Array of [(int)performance_item_id] => (float[0.0 - 5.0])item_average_rating
103:      * @throws InvalidParameterException
104:      */
105:     static function get_item_average_rating_for_target($target_id) {
106:         $rating_array = ClipitRating::get_by_target(array($target_id));
107:         $rating_array = $rating_array[$target_id];
108:         $average_rating = array();
109:         $count = array();
110:         if(!empty($rating_array)) {
111:             foreach($rating_array as $rating) {
112:                 foreach($rating->performance_rating_array as $performance_rating_id) {
113:                     $prop_value_array = static::get_properties($performance_rating_id, array("performance_item", "star_rating"));
114:                     $performance_item = $prop_value_array["performance_item"];
115:                     $star_rating = $prop_value_array["star_rating"];
116:                     if(!isset($average_rating[$performance_item])){
117:                         $average_rating[$performance_item] = (int)$star_rating;
118:                         $count[$performance_item] = 1;
119:                     } else{
120:                         $average_rating[$performance_item] += (int)$star_rating;
121:                         $count[$performance_item]++;
122:                     }
123:                 }
124:             }
125:             if(!empty($count)) {
126:                 foreach($count as $performance_item => $total) {
127:                     $average_rating[$performance_item] = $average_rating[$performance_item] / $total;
128:                 }
129:             }
130:         }
131:         return $average_rating;
132:     }
133: 
134:     static function get_average_user_rating_for_target($user_id, $target_id) {
135:         $rating = ClipitRating::get_user_rating_for_target($user_id, $target_id);
136:         $average_rating = 0;
137:         $count = 0;
138:         if(!empty($rating)) {
139:             foreach ($rating->performance_rating_array as $performance_rating_id) {
140:                 $prop_value_array = static::get_properties($performance_rating_id, array("star_rating"));
141:                 $average_rating += (int)$prop_value_array["star_rating"];
142:                 $count++;
143:             }
144:         }
145:         if(!empty($count)) {
146:             return $average_rating = $average_rating / $count;
147:         } else {
148:             return null;
149:         }
150:     }
151: }
API documentation generated by ApiGen 2.8.0