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:  * Represents each human user interacting directly or indirectly with the ClipIt.
 17:  */
 18: class ClipitUser extends UBUser {
 19:     /**
 20:      * @const string Elgg entity SUBTYPE for this class
 21:      */
 22:     const SUBTYPE = "ClipitUser";
 23:     /**
 24:      * @const Role name for Students
 25:      */
 26:     const ROLE_STUDENT = "student";
 27:     /**
 28:      * @const Role name for Teachers
 29:      */
 30:     const ROLE_TEACHER = "teacher";
 31:     /**
 32:      * @const Role name for Administrators
 33:      */
 34:     const ROLE_ADMIN = "admin";
 35:     /**
 36:      * @const Default cookie token duration in minutes
 37:      */
 38:     const COOKIE_TOKEN_DURATION = 60;
 39: 
 40:     /**
 41:      * Saves this instance into the system.
 42:      * @return bool|int Returns id of saved instance, or false if error.
 43:      */
 44:     protected function save() {
 45:         // If no role set, use "student" as default
 46:         if(array_search($this->role, array(static::ROLE_STUDENT, static::ROLE_TEACHER, static::ROLE_ADMIN)) === false){
 47:             $this->role = static::ROLE_STUDENT;
 48:         }
 49:         $id = parent::save();
 50:         switch(strtolower($this->role)) {
 51:             case static::ROLE_STUDENT:
 52:                 remove_user_admin($this->id);
 53:                 break;
 54:             case static::ROLE_TEACHER:
 55:                 make_user_admin($this->id);
 56:                 break;
 57:             case static::ROLE_ADMIN:
 58:                 make_user_admin($this->id);
 59:                 break;
 60:         }
 61:         return $id;
 62:     }
 63: 
 64:     static function login($login, $password, $persistent = false) {
 65:         if(!parent::login($login, $password, $persistent)) {
 66:             return false;
 67:         }
 68:         //static::create_cookies($login, $password);
 69:         return true;
 70:     }
 71: 
 72:     static function logout() {
 73:         return parent::logout();
 74:     }
 75: 
 76:     /**
 77:      * Get all Group Ids in which a user is member of.
 78:      *
 79:      * @param int $user_id Id of the user to get groups from.
 80:      *
 81:      * @return array Returns an array of Group IDs the user is member of.
 82:      */
 83:     static function get_groups($user_id) {
 84:         return UBCollection::get_items($user_id, ClipitGroup::REL_GROUP_USER, true);
 85:     }
 86: 
 87:     /**
 88:      * Get all Activity Ids in which a Student is member of, or a Teacher is in charge of.
 89:      *
 90:      * @param int  $user_id     Id of the user to get activities from.
 91:      * @param bool $joined_only Only returnes Activities where a Student user has joined to a group.
 92:      *
 93:      * @return array Returns an array of Activity IDs the user is member of.
 94:      */
 95:     static function get_activities($user_id, $joined_only = false) {
 96:         $prop_value_array = static::get_properties($user_id, array("role"));
 97:         $user_role = $prop_value_array["role"];
 98:         switch($user_role) {
 99:             case static::ROLE_STUDENT:
100:                 if((bool)$joined_only) {
101:                     $group_ids = static::get_groups($user_id);
102:                     if(empty($group_ids)) {
103:                         return null;
104:                     }
105:                     foreach($group_ids as $group_id) {
106:                         $activity_array[] = ClipitGroup::get_activity($group_id);
107:                     }
108:                     if(!isset($activity_array)) {
109:                         return null;
110:                     }
111:                     return $activity_array;
112:                 } else {
113:                     return UBCollection::get_items($user_id, ClipitActivity::REL_ACTIVITY_STUDENT, true);
114:                 }
115:             case static::ROLE_TEACHER:
116:                 return UBCollection::get_items($user_id, ClipitActivity::REL_ACTIVITY_TEACHER, true);
117:         }
118:         return null;
119:     }
120: 
121:     /**
122:      * Sets a User role to Student.
123:      *
124:      * @param int $user_id User Id.
125:      *
126:      * @return int Returns the User Id if set correctly.
127:      */
128:     static function set_role_student($user_id) {
129:         $prop_value_array["role"] = static::ROLE_STUDENT;
130:         return static::set_properties($user_id, $prop_value_array);
131:     }
132: 
133:     /**
134:      * Sets a User role to Teacher.
135:      *
136:      * @param int $user_id User Id.
137:      *
138:      * @return int Returns the User Id if set correctly.
139:      */
140:     static function set_role_teacher($user_id) {
141:         $prop_value_array["role"] = static::ROLE_TEACHER;
142:         return static::set_properties($user_id, $prop_value_array);
143:     }
144: 
145:     /**
146:      * Sets a User role to Admin.
147:      *
148:      * @param int $user_id User Id.
149:      *
150:      * @return int Returns the User Id if set correctly.
151:      */
152:     static function set_role_admin($user_id) {
153:         $prop_value_array["role"] = static::ROLE_ADMIN;
154:         return static::set_properties($user_id, $prop_value_array);
155:     }
156: }
API documentation generated by ApiGen 2.8.0