attributes['subtype'] = 'dmtest'; $this->attributes['access_id'] = ACCESS_PUBLIC; $this->achieved = serialize(array()); $this->failed = serialize(array()); $this->pending = serialize(array()); $this->available = serialize(array()); $this->complete_sections = serialize(array()); } /** * Returns DigiMinaCompetencyModel GUID * * @return mixed */ public function getModel() { return $this->model; } /** * Returns DigiMinaCompetencyModel object * * @return mixed */ public function getModelEntity() { return get_entity($this->model); } /** * Returns current test state * * @return string */ public function getState() { return $this->state; } /** * Returns if test is finished * * @return bool */ public function isFinished() { if ($this->getState() == 'finished') { return true; } return false; } /** * Returns if test is ongoing * * @return bool */ public function isOngoing() { if ($this->getState() == 'ongoing') { return true; } return false; } /** * Returns PerformanceLevel GUID if any * * @return string */ public function getCurrentLevel() { return $this->current_level; } /** * Returns Competency GUID if aany * * @return string */ public function getCurrentCompetency() { return $this->current_competency; } /** * Returns SubCompetency if any * * @return string */ public function getCurrentSubCompetency() { return $this->current_subcompetency; } /** * Returns Item if any * * @return string */ public function getCurrentItem() { return $this->current_item; } /** * Checks if next level allows automatic testing * * @return bool */ public function isNextLevelAutomatedTesting() { $level = get_entity($this->getCurrentLevel()); if ($level instanceof DigiMinaPerformanceLevel) { if ((int)$level->level == 5) { return false; } $options = array( 'type' => 'object', 'subtype' => 'dmperformancelevel', 'limit' => 1, 'container_guid' => $this->getModel(), 'metadata_name_value_pairs' => array('name' => 'level', 'value' => ((int)$level->level + 1)) ); $next_level = elgg_get_entities_from_metadata($options); if (!(is_array($next_level) || sizeof($next_level))) { return false; } $next_level = $next_level[0]; $items = $next_level->getItems(); if (is_array($items) && sizeof($items)>1) { return true; } elseif (is_array($items) && sizeof($items)>0) { $item = $itms[0]; if ($item->detectAutomatedTesting()) { return true; } } } return false; } /** * Returns an array with GUID identifiers of achieved levels. * * @return array */ public function getAchieved() { $achieved = unserialize($this->achieved); if (!$achieved) { $achieved = array(); } elseif (!is_array($achieved)) { $achieved = array($achieved); } return $achieved; } /** * Add level GUID identifier to achieved. * * @param mixed $guid DigiMinaPerformanceLevel GUID (may be either int or array) * @return void */ public function addAchieved($guid) { $achieved = $this->getAchieved(); if (!is_array($guid)) { $guid = array($guid); } foreach ($guid as $single_guid) { if (!in_array($single_guid, $achieved)) { $achieved[] = $single_guid; } } $this->achieved = serialize($achieved); } /** * Check if level GUID identifier is in achieved. * * @param int $guid DigiMinaPerformanceLevel GUID * @return bool */ public function isAchieved($guid) { if (in_array($guid, $this->getAchieved())) { return true; } return false; } /** * Returns an array with GUID identifiers of failed levels. * * @return array */ public function getFailed() { $failed = unserialize($this->failed); if (!$failed) { $failed = array(); } elseif (!is_array($failed)) { $failed = array($failed); } return $failed; } /** * Add level GUID identifier to failed. * * @param mixed $guid DigiMinaPerformanceLevel GUID (may be either int or array) * @return void */ public function addFailed($guid) { $failed = $this->getFailed(); if (!is_array($guid)) { $guid = array($guid); } foreach ($guid as $single_guid) { if (!in_array($single_guid, $failed)) { $failed[] = $single_guid; } } $this->failed = serialize($failed); } /** * Returns an array with GUID identifiers of pending levels. * * @return array */ public function getPending() { $pending = unserialize($this->pending); if (!$pending) { $pending = array(); } elseif (!is_array($pending)) { $pending = array($pending); } return $pending; } /** * Add level GUID identifier to pending. * * @param mixed $guid DigiMinaPerformanceLevel GUID (may be either int or array) * @return void */ public function addPending($guid) { $pending = $this->getPending(); if (!is_array($guid)) { $guid = array($guid); } foreach ($guid as $single_guid) { if (!in_array($single_guid, $pending)) { $pending[] = $single_guid; } } $this->pending = serialize($pending); } /** * Remove level GUID identifier from pending. * * @param mixed $guid DigiMinaPerformanceLevel GUID (may be either int or array) * @return void */ public function removePending($guid) { $pending = $this->getPending(); if (!is_array($guid)) { $guid = array($guid); } foreach ($guid as $single_guid) { if (in_array($single_guid, $pending)) { $key = array_search($single_guid, $pending); unset($pending[$key]); } } // Normalize keys $pending = array_values($pending); $this->pending = serialize($pending); } /** * Returns an array with GUID identifiers of available levels. * * @return array */ public function getAvailable() { $available = unserialize($this->available); if (!$available) { $available = array(); } elseif (!is_array($available)) { $available = array($available); } return $available; } /** * Add level GUID identifier to available array. * * @param mixed $guid DigiMinaPerformanceLevel GUID (may be either int or array) * @return void */ public function addAvailable($guid) { $available = $this->getAvailable(); if (!is_array($guid)) { $guid = array($guid); } foreach ($guid as $single_guid) { if (!in_array($single_guid, $available)) { $available[] = $single_guid; } } $this->available = serialize($available); } /** * Remove level GUID identifier from available. * * @param mixed $guid DigiMinaPerformanceLevel GUID (may be either int or array) * @return void */ public function removeAvailable($guid) { $available = $this->getAvailable(); if (!is_array($guid)) { $guid = array($guid); } foreach ($guid as $single_guid) { if (in_array($single_guid, $available)) { $key = array_search($single_guid, $available); unset($available[$key]); } } // Normalize keys $available = array_values($available); $this->available = serialize($available); } /** * Checks if level is pending * * @param int $guid DigiMinaPerformanceLevel GUID * @return bool */ public function isPendingLevel($guid) { $pending = $this->getPending(); return in_array($guid, $pending); } /** * Determine if level GUID is is achieved or failed. * * @param int $guid DigiMinaPerformanceLevel GUID * @return bool */ public function haveBeenToLevel($guid) { if (in_array($guid, $this->getAchieved()) || in_array($guid, $this->getFailed()) || in_array($guid, $this->getPending())) { return true; } return false; } /** * Returns an array with GUID identifiers of complete competencies. * A section can have pending peer-review elements, this only means that user has played through the Competency and can not start with that again. * This is used to disable Competencies on the choice page. * * @return array */ public function getCompleteSections() { $complete_sections = unserialize($this->complete_sections); if (!$complete_sections) { $complete_sections = array(); } elseif (!is_array($complete_sections)) { $complete_sections = array($complete_sections); } return $complete_sections; } /** * Add competency GUID identifier to completed. * * @param int $guid DigiMinaPerformanceLevel GUID * @return void */ public function addCompleteSection($guid) { $complete_sections = $this->getCompleteSections(); if (!in_array($guid, $complete_sections)) { $complete_sections[] = $guid; $this->complete_sections = serialize($complete_sections); } } /** * Determine if a user has already played through the section. * This section can not be started again. * Peer-review cases should be handled in a different manner. * * @param int $guid DigiMinaCompetency GUID * @return bool */ public function isCompleteSection($guid) { if (in_array($guid, $this->getCompleteSections())) { return true; } return false; } /** * Teretmines if test is complete. * Currently that would require that all levels would be added to achieved or failed. * * @return bool */ public function isComplete() { $model = $this->getModelEntity(); // Please note that level count is cacheable. // Local metadata level_count will be used after the count is done for the first time if ($this->level_count) { $level_count = $this->level_count; } else { $level_count = $model->getPerformanceLevelCount(); $this->level_count = $level_count; } // Number of levels should not be 0, this is wrong if ($level_count == 0) { return false; } if ($level_count == (count($this->getAchieved()) + count($this->getFailed()))) { return true; } return false; } /** * Returns completeness percentage * * return int */ function getCompletenessPercent() { $model = $this->getModelEntity(); $level_count = $model->getPerformanceLevelCount(); $af_count = (count($this->getAchieved()) + count($this->getFailed())); if (!($level_count || $af_count)) { return 0; } return ($af_count/$level_count)*100; } /** * Returns state for a level (used in a diagram view) * * @param int $guid Level GUID * @return string */ function getLevelState($guid) { if ($this->isOngoing()) { if (in_array($guid, $this->getAchieved())) { return 'achieved'; } elseif (in_array($guid, $this->getFailed())) { return 'failed'; } elseif (in_array($guid, $this->getPending())) { return 'pending'; } } else { if (in_array($guid, $this->getAchieved())) { return 'achieved'; } } return 'missing'; } /** * Decides if a section needs reviewer or not (DigiMnaCompetency is a section). * * @param int $guid Competency GUID * @return bool */ function isSectionReviewNeeded($guid) { $all_levels = array(); $pending = $this->getPending(); $competency = get_entity($guid); $subcompetencies = $competency->getSubCompetencies(0); foreach ($subcompetencies as $subcompetency) { $levels = $subcompetency->getPerformanceLevels(0); foreach ($levels as $level) { $all_levels[] = $level->getGUID(); } } if (array_intersect($pending, $all_levels)) { return true; } return false; } }