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 Quiz Question containing a main question (in the "name" and "description" properties), with a set of Options,
 17:  * a Validation array with the correct pattern of Options, a Difficulty value, can be Tagged, can be linked to a Video,
 18:  * and contains links to all Results submitted by Students to this Question.
 19:  */
 20: class ClipitQuizQuestion extends UBItem {
 21:     /**
 22:      * @const string Elgg entity SUBTYPE for this class
 23:      */
 24:     const SUBTYPE = "ClipitQuizQuestion";
 25:     const REL_QUIZQUESTION_TAG = "ClipitQuizQuestion-ClipitTag";
 26:     const REL_QUIZQUESTION_QUIZRESULT = "ClipitQuizQuestion-ClipitQuizResult";
 27:     const REL_QUIZQUESTION_IMAGE = "ClipitQuizQuestion-ClipitFile";
 28:     const TYPE_TRUE_FALSE = "true_false";
 29:     const TYPE_SELECT_ONE = "select_one";
 30:     const TYPE_SELECT_MULTI = "select_multi";
 31:     const TYPE_NUMBER = "number";
 32: 
 33:     /**
 34:      * @var array Array of options to chose from as an answer to the question
 35:      */
 36:     public $option_array = array();
 37:     /**
 38:      * @var array Array for validation of the options
 39:      */
 40:     public $validation_array = array();
 41:     /**
 42:      * @var string Type of Question: single choice, multiple choice, select 2...
 43:      */
 44:     public $option_type = "";
 45:     /**
 46:      * @var array Array of Tags relevant to this question
 47:      */
 48:     public $tag_array = array();
 49:     /**
 50:      * @var array Array of Quiz Results which answer this Quiz Question
 51:      */
 52:     public $quiz_result_array = array();
 53:     /**
 54:      * @var string URL of ClipitVideo refered to by this question (optional)
 55:      */
 56:     public $video = "";
 57:     /**
 58:      * @var int ID of image file (ClipitFile) to show next to the Quiz Question (optional)
 59:      */
 60:     public $image = 0;
 61:     /**
 62:      * @var int Difficulty of the QuizQuestion, in an integer scale from 1 to 10.
 63:      */
 64:     public $difficulty = 0;
 65:     /**
 66:      * @var int Order in which this QuizQuestion will be displayed to students
 67:      */
 68:     public $order = 0;
 69: 
 70:     /**
 71:      * Loads object parameters stored in Elgg
 72:      *
 73:      * @param ElggEntity $elgg_entity Elgg Object to load parameters from.
 74:      */
 75:     protected function copy_from_elgg($elgg_entity) {
 76:         parent::copy_from_elgg($elgg_entity);
 77:         $this->tag_array = static::get_tags($this->id);
 78:         $this->quiz_result_array = static::get_quiz_results($this->id);
 79:         $this->option_array = (array)$elgg_entity->get("option_array");
 80:         $this->validation_array = (array)$elgg_entity->get("validation_array");
 81:         $this->option_type = (string)$elgg_entity->get("option_type");
 82:         $this->video = (string)$elgg_entity->get("video");
 83:         $this->image = static::get_image((int)$this->id);
 84:         $this->difficulty = (int)$elgg_entity->get("difficulty");
 85:         $this->order = (int)$elgg_entity->get("order");
 86:     }
 87: 
 88:     /**
 89:      * Copy $this object parameters into an Elgg entity.
 90:      *
 91:      * @param ElggEntity $elgg_entity Elgg object instance to save $this to
 92:      */
 93:     protected function copy_to_elgg($elgg_entity) {
 94:         parent::copy_to_elgg($elgg_entity);
 95:         $elgg_entity->set("option_array", (array)$this->option_array);
 96:         $elgg_entity->set("validation_array", (array)$this->validation_array);
 97:         $elgg_entity->set("option_type", (string)$this->option_type);
 98:         $video_metadata = ClipitVideo::video_url_parser($this->video);
 99:         $elgg_entity->set("video", (string)$video_metadata["url"]);
100:         $elgg_entity->set("difficulty", (int)$this->difficulty);
101:         $elgg_entity->set("order", (int)$this->order);
102:     }
103: 
104:     /**
105:     /**
106:      * Saves this instance to the system.
107:      * @param  bool $double_save if $double_save is true, this object is saved twice to ensure that all properties are updated properly. E.g. the time created property can only beset on ElggObjects during an update. Defaults to false!
108:      * @return bool|int Returns the Id of the saved instance, or false if error
109:      */
110:     protected function save($double_save=false) {
111:         parent::save($double_save);
112:         static::set_tags($this->id, $this->tag_array);
113:         static::set_quiz_results($this->id, $this->quiz_result_array);
114:         static::set_image($this->id, $this->image);
115:         return $this->id;
116:     }
117: 
118:     /**
119:      * Get all Questions from a Quiz ID
120:      *
121:      * @param int $quiz_id Quiz ID
122:      * @return static[] Quiz question array
123:      */
124:     static function get_from_quiz($quiz_id){
125:         $quiz_question_ids = ClipitQuiz::get_quiz_questions($quiz_id);
126:         return static::get_by_id($quiz_question_ids);
127:     }
128: 
129:     /**
130:      * Get the image ID (ClipitFile) linked to a Quiz Question
131:      *
132:      * @param int $id ID of the ClipitQuizQuestion
133:      * @return int|null ID of linked image file (ClipitFile)
134:      */
135:     static function get_image($id){
136:         $temp = UBCollection::get_items($id, static::REL_QUIZQUESTION_IMAGE);
137:         if(!empty($temp)){
138:             return (int)array_pop($temp);
139:         }
140:         return null;
141:     }
142: 
143:     /**
144:      * Set the image (ClipitFile) linked to a Quiz Question
145:      *
146:      * @param int $id ID of Quiz Question
147:      * @param int $image_id ID of image file (ClipitFile)
148:      * @return bool True if ok, False if error.
149:      */
150:     static function set_image($id, $image_id){
151:         return UBCollection::set_items($id, array($image_id), static::REL_QUIZQUESTION_IMAGE);
152:     }
153: 
154:     /**
155:      * Get Quiz Questions linked to a Video URL
156:      *
157:      * @param $video_url URL of video (optionally in Base64)
158:      * @return static[] Array of Quiz Questions
159:      */
160:     static function get_from_video($video_url){
161:         $base64_decode = base64_decode($video_url, true);
162:         if($base64_decode != false){
163:             $video_url = $base64_decode;
164:         }
165:         $video_metadata = ClipitVideo::video_url_parser($video_url);
166:         if($video_metadata == false){
167:             return array();
168:         }
169:         $video_url = $video_metadata["url"];
170:         $return_quiz_question_array = array();
171:         $quiz_array = ClipitQuiz::get_all(0, 0, "", true, true);
172:         foreach($quiz_array as $quiz_id){
173:             $quiz_question_array = static::get_from_quiz($quiz_id);
174:             foreach($quiz_question_array as $quiz_question){
175:                 if(strcmp($video_url, $quiz_question->video) === 0){
176:                     $return_quiz_question_array[] = $quiz_question;
177:                 }
178:             }
179:         }
180:         return $return_quiz_question_array;
181:     }
182: 
183:     static function evaluate_results($id){
184:         $quiz_results = static::get_quiz_results($id);
185:         foreach($quiz_results as $quiz_result){
186:             ClipitQuizResult::evaluate_result($quiz_result);
187:         }
188:         return true;
189:     }
190: 
191:     /**
192:      * @param int   $id
193:      * @param array $result_array
194:      *
195:      * @return bool
196:      */
197:     static function add_quiz_results($id, $result_array) {
198:         return UBCollection::add_items($id, $result_array, static::REL_QUIZQUESTION_QUIZRESULT, true);
199:     }
200: 
201:     /**
202:      * @param int   $id
203:      * @param array $result_array
204:      *
205:      * @return bool
206:      */
207:     static function set_quiz_results($id, $result_array) {
208:         return UBCollection::set_items($id, $result_array, static::REL_QUIZQUESTION_QUIZRESULT, true);
209:     }
210: 
211:     /**
212:      * @param $id
213:      * @param $result_array
214:      *
215:      * @return bool
216:      */
217:     static function remove_quiz_results($id, $result_array) {
218:         return UBCollection::remove_items($id, $result_array, static::REL_QUIZQUESTION_QUIZRESULT);
219:     }
220: 
221:     /**
222:      * Get all Quiz Results from a specified Quiz Question.
223:      *
224:      * @param int $id Id of Quiz Question to get Results form
225:      *
226:      * @return array|bool Array of Quiz Result IDs, or false if error
227:      */
228:     static function get_quiz_results($id) {
229:         return UBCollection::get_items($id, static::REL_QUIZQUESTION_QUIZRESULT);
230:     }
231: 
232:     /**
233:      * Add a list of Stumbling Block Tags to a Quiz Question.
234:      *
235:      * @param int   $id        Id of the Quiz Question
236:      * @param array $tag_array Array of Tags to add to the Quiz Question
237:      *
238:      * @return bool True if success, false if error
239:      */
240:     static function add_tags($id, $tag_array) {
241:         return UBCollection::add_items($id, $tag_array, static::REL_QUIZQUESTION_TAG);
242:     }
243: 
244:     /**
245:      * Set a list of Stumbling Block Tags to a Quiz Question.
246:      *
247:      * @param int   $id        Id of the Quiz Question
248:      * @param array $tag_array Array of Tags to set to the Quiz Question
249:      *
250:      * @return bool True if success, false if error
251:      */
252:     static function set_tags($id, $tag_array) {
253:         return UBCollection::set_items($id, $tag_array, static::REL_QUIZQUESTION_TAG);
254:     }
255: 
256:     /**
257:      * Remove a list of Stumbling Block Tags from a Quiz Question.
258:      *
259:      * @param int   $id        Id of the Quiz Question
260:      * @param array $tag_array Array of Tags to remove from the Quiz Question
261:      *
262:      * @return bool True if success, false if error
263:      */
264:     static function remove_tags($id, $tag_array) {
265:         return UBCollection::remove_items($id, $tag_array, static::REL_QUIZQUESTION_TAG);
266:     }
267: 
268:     /**
269:      * Get all Stumbling Block Tags for a Quiz Question.
270:      *
271:      * @param int $id Id from the Quiz Question to get Stumbling Block Tags from
272:      *
273:      * @return array|bool Returns an array of Tag IDs, or false if error
274:      */
275:     static function get_tags($id) {
276:         return UBCollection::get_items($id, static::REL_QUIZQUESTION_TAG);
277:     }
278: 
279:     static function set_type_true_false($id) {
280:         $prop_value_array = array();
281:         $prop_value_array["option_type"] = static::TYPE_TRUE_FALSE;
282:         return static::set_properties($id, $prop_value_array);
283:     }
284: 
285:     static function set_type_select_one($id) {
286:         $prop_value_array = array();
287:         $prop_value_array["option_type"] = static::TYPE_SELECT_ONE;
288:         return static::set_properties($id, $prop_value_array);
289:     }
290: 
291:     static function set_type_select_multi($id) {
292:         $prop_value_array = array();
293:         $prop_value_array["option_type"] = static::TYPE_SELECT_MULTI;
294:         return static::set_properties($id, $prop_value_array);
295:     }
296: 
297:     static function set_type_number($id) {
298:         $prop_value_array = array();
299:         $prop_value_array["option_type"] = static::TYPE_NUMBER;
300:         return static::set_properties($id, $prop_value_array);
301:     }
302: }
303: 
API documentation generated by ApiGen 2.8.0