public function unitExport(EfrontUnit $unit)
 {
     $currentLesson = $this->getCurrentLesson();
     $unitExportFolder = $this->moduleBaseDir . "assets/";
     try {
         $dir = new EfrontDirectory($unitExportFolder);
         $dir->delete();
     } catch (Exception $e) {
     }
     $htmlExportFolder = $unitExportFolder . 'html/';
     $filesExportFolder = $unitExportFolder . 'html/files/';
     is_dir($filesExportFolder) or mkdir($filesExportFolder, 0755, true);
     //is_dir($htmlExportFolder)  OR mkdir($htmlExportFolder, 0755, true);
     $filelist = array();
     $unitFiles = $unit->getFiles(true);
     $units[] = $unit;
     $data = $unit['data'];
     foreach ($unitFiles as $file) {
         $filePath = str_replace($currentLesson->getDirectory(), "/", EfrontFile::encode($file['path']));
         //Added this line in case of a space in path(urlencode makes it + and rawurlencode convers also slashes ) (#2143)
         $data = str_replace("content/lessons/" . ($currentLesson->lesson['share_folder'] ? $currentLesson->lesson['share_folder'] : $currentLesson->lesson['id']) . str_replace(' ', '%20', $filePath), "files" . str_replace(' ', '%20', $filePath), $data);
         $data = str_replace("content/lessons/" . ($currentLesson->lesson['share_folder'] ? $currentLesson->lesson['share_folder'] : $currentLesson->lesson['id']) . $filePath, "files" . $filePath, $data);
         $data = str_replace("view_file.php?file=" . $file['id'], "files" . $filePath, $data);
     }
     $unitContent = $data;
     $unitFilename = $htmlExportFolder . $unit['name'] . ".html";
     file_put_contents(EfrontFile::encode($unitFilename), $unitContent);
     $filelist = array_merge($filelist, $unitFiles);
     foreach ($filelist as $file) {
         $filePath = str_replace($currentLesson->getDirectory(), "", $file['path']);
         if (!is_dir($filesExportFolder . dirname($filePath))) {
             mkdir($filesExportFolder . dirname($filePath), 0755, true);
         }
         $file->copy($filesExportFolder . $filePath);
     }
     $unitDirectory = new EfrontDirectory($unitExportFolder);
     if (eF_checkParameter($unit['name'], 'file')) {
         $filename = $unit['name'] . '.zip';
     } else {
         $filename = 'unit.zip';
     }
     $compressedFile = $unitDirectory->compress($filename, false);
     //$unitDirectory -> delete();
     return $compressedFile;
 }
Example #2
0
                 $options['custom'][$value['id']] = '<img style = "margin-left:30px" src = "images/16x16/theory.png" alt = "' . _CONVERTTOSCORMTEST . '" title = "' . _CONVERTTOSCORMCONTENT . '" onclick = "convertScorm(this, ' . $value['id'] . ')" class = "ajaxHandle"/>';
             }
         }
         $valid12Units[] = $value['id'];
     } else {
         if ($value['package_ID'] == $value['content_ID']) {
             //This is SCORM 2004 content's root (package) unit
             $options['custom'][$value['id']] = '<img style = "margin-left:30px" src = "images/16x16/refresh.png" alt = "' . _RESETSCORMDATA . '" title = "' . _RESETSCORMDATA . '" onclick = "resetScorm(this, ' . $value['id'] . ')" class = "ajaxHandle"/>';
             $valid2004Units[] = $value['id'];
         }
     }
 }
 try {
     //Set scorm content type through AJAX call
     if (isset($_GET['set_type']) && isset($_GET['id']) && in_array($_GET['id'], $valid12Units)) {
         $unit = new EfrontUnit($_GET['id']);
         $unit['ctg_type'] == 'scorm_test' ? $unit['ctg_type'] = 'scorm' : ($unit['ctg_type'] = 'scorm_test');
         $unit->persist();
         echo json_encode(array('id' => $unit['id'], 'ctg_type' => $unit['ctg_type']));
         exit;
     }
     if (isset($_GET['reset_scorm']) && isset($_GET['id']) && in_array($_GET['id'], $valid12Units)) {
         //eF_deleteTableData("scorm_data", "id=".$_GET['delete']);
         //$user = EfrontUserFactory::factory($scormData[0]['users_LOGIN']);
         //$user -> setSeenUnit($scormData[0]['content_ID'], $currentLesson, false);
     }
     //Reset scorm data
     if (isset($_GET['reset_scorm']) && isset($_GET['id']) && in_array($_GET['id'], $valid2004Units)) {
         if (isset($_GET['login']) && eF_checkParameter($_GET['login'], 'login')) {
             //EfrontContentTreeSCORM :: resetSCORMContentOrganization($currentLesson, $_GET['id'], $_GET['login']);
         } else {
                                    preg_match("/window.open\\(.*,/U", $currentUnit['data'], $matches);
                                    $scormValue = str_replace(array('window.open("', '",'), "", $matches[0]);
                                    $currentUnit['data'] = '<iframe height = "100%"  width = "100%" frameborder = "no" name = "scormFrameName" id = "scormFrameID" src = "' . $scormValue . '" onload = "if (window.eF_js_setCorrectIframeSize) {eF_js_setCorrectIframeSize();} else {setIframeSize = true;}"></iframe>';
                                } elseif ($_GET['value'] == 'popup' && strpos($currentUnit['data'], 'iframe') !== false) {
                                    preg_match("/src.*onload/U", $currentUnit['data'], $matches);
                                    $scormValue = str_replace(array('src = "', '" onload'), "", $matches[0]);
                                    $currentUnit['data'] = '
		                            	<div style = "text-align:center;height:300px">
			                            	<span>##CLICKTOSTARTUNIT##</span><br/>
			                        		<input type = "button" value = "##STARTUNIT##" class = "flatButton" onclick = \'window.open("' . $scormValue . '", "scormFrameName", "width=800,height=600,scrollbars=no,resizable=yes,status=yes,toolbar=no,location=no,menubar=no,top="+(parseInt(parseInt(screen.height)/2) - 300)+",left="+(parseInt(parseInt(screen.width)/2) - 400)+"")\' >
		                        		</div>';
                                }
                                $currentUnit->persist();
                            } else {
                                if ($_GET['option'] == 'popup_parameters') {
                                    $currentUnit = new EfrontUnit($key);
                                    preg_match("/\"scormFrameName\".*\"\\)'/U", $currentUnit['data'], $matches);
                                    $currentUnit['data'] = preg_replace("/\"scormFrameName\".*\"\\)'/U", '"scormFrameName", "' . $_GET['value'] . '")\'', $currentUnit['data']);
                                    $currentUnit->persist();
                                } else {
                                    if ($_GET['option'] == 'reentry_action') {
                                        $value['options'][$_GET['option']] = $_GET['value'];
                                        $value->persist();
                                    } else {
                                        if (isset($value['options'][$_GET['option']])) {
                                            $value['options'][$_GET['option']] = $_GET['value'];
                                            $value->persist();
                                        }
                                    }
                                }
                            }
 /**
  * Copy simple unit
  *
  * This function copies a unit (NOT its children) into the current content tree
  * <br/>Example:
  * <code>
  * $currentContent = new EfrontContentTree(5);           //Initialize content for lesson with id 5
  * $sourceUnit = new EfrontUnit(20);                     //Get the unit with id = 20
  * $currentContent -> copySimpleUnit($sourceUnit, false);   //Copy the source unit into the content tree (at its end)
  * </code>
  *
  * @param EfrontUnit $sourceUnit The unit object to be copied
  * @param mixed $targetUnit The id of the parent unit (or the parent EfrontUnit)in which the new unit will be copied, or false (the unit will be appended at the end)
  * @param mixed $previousUnit The id of the previous unit (or the unit itself) of the new unit, or false (the unit will be put to the end of the units)
  * @param boolean $copyFiles whether to copy files as well.
  * @param boolean $copyQuestions Whether to copy questions as well
  * @return EfrontUnit The newly created unit object
  * @since 3.5.0
  * @access public
  */
 public function copySimpleUnit($sourceUnit, $targetUnit = false, $previousUnit = false, $copyFiles = true, $copyQuestions = true)
 {
     if (!$sourceUnit instanceof EfrontUnit) {
         $sourceUnit = new EfrontUnit($sourceUnit);
     }
     $newUnit['name'] = $sourceUnit->offsetGet('name');
     $newUnit['ctg_type'] = $sourceUnit->offsetGet('ctg_type');
     $newUnit['data'] = $sourceUnit->offsetGet('data');
     $options = $sourceUnit->offsetGet('options');
     $newOptions['complete_unit_setting'] = $options['complete_unit_setting'];
     $newOptions['hide_navigation'] = $options['hide_navigation'];
     $newOptions['maximize_viewport'] = $options['maximize_viewport'];
     $newOptions['object_ids'] = $options['object_ids'];
     $newUnit['options'] = serialize($newOptions);
     $newUnit['lessons_ID'] = $this->lessonId;
     if ($targetUnit) {
         if ($targetUnit instanceof EfrontUnit) {
             $newUnit['parent_content_ID'] = $targetUnit->offsetGet('id');
         } else {
             if (eF_checkParameter($targetUnit, 'id')) {
                 $newUnit['parent_content_ID'] = $targetUnit;
             }
         }
         if ($previousUnit instanceof EfrontUnit) {
             $newUnit['previous_content_ID'] = $previousUnit->offsetGet('id');
         } else {
             if (eF_checkParameter($previousUnit, 'id')) {
                 $newUnit['previous_content_ID'] = $previousUnit;
             }
         }
         $unit = $this->insertNode($newUnit);
     } else {
         $unit = $this->appendUnit($newUnit);
     }
     if ($copyFiles) {
         $files = $unit->getFiles();
         $lesson = new EfrontLesson($this->lessonId);
         $data = $unit->offsetGet('data');
         foreach ($files as $file) {
             try {
                 $sourceFile = new EfrontFile($file);
                 $sourceFileOffset = preg_replace("#" . G_LESSONSPATH . "#", "", $sourceFile['directory']);
                 $position = strpos($sourceFileOffset, "/");
                 //check case that the file is in a subfolder of the lesson
                 if ($position !== false) {
                     $sourceLink = mb_substr($sourceFileOffset, $position + 1);
                     mkdir($lesson->getDirectory() . $sourceLink . '/', 0755, true);
                     $destinationPath = $lesson->getDirectory() . $sourceLink . '/' . basename($sourceFile['path']);
                     $copiedFile = $sourceFile->copy($destinationPath, false);
                 } else {
                     $destinationPath = $lesson->getDirectory() . basename($sourceFile['path']);
                     $copiedFile = $sourceFile->copy($destinationPath, false);
                 }
                 //@todo view_file.php?action=download&file=10410
                 //$data = str_replace("view_file.php?file=".$file, "view_file.php?file=".$copiedFile -> offsetGet('id'), $data);
                 //$data = str_replace("&file=".$file, "&file=".$copiedFile -> offsetGet('id'), $data);
                 //$data = str_replace("&amp;file=".$file, "&amp;file=".$copiedFile -> offsetGet('id'), $data);
                 $data = preg_replace('#view_file\\.php(.*)file=' . $file . '#', 'view_file.php${1}file=' . $copiedFile->offsetGet('id'), $data);
                 $folderId = $lesson->lesson['share_folder'] ? $lesson->lesson['share_folder'] : $lesson->lesson['id'];
                 $data = preg_replace("#(" . G_SERVERNAME . ")*content/lessons/" . $sourceUnit['lessons_ID'] . "/(.*)#", "content/lessons/" . $folderId . '/${2}', $data);
             } catch (EfrontFileException $e) {
                 if ($e->getCode() == EfrontFileException::FILE_ALREADY_EXISTS) {
                     $copiedFile = new EfrontFile($destinationPath);
                     //$data = str_replace("view_file.php?file=".$file, "view_file.php?file=".$copiedFile -> offsetGet('id'), $data);
                     //$data = str_replace("&file=".$file, "&file=".$copiedFile -> offsetGet('id'), $data);
                     //$data = str_replace("&amp;file=".$file, "&amp;file=".$copiedFile -> offsetGet('id'), $data);
                     $data = preg_replace('#view_file\\.php(.*)file=' . $file . '#', 'view_file.php${1}file=' . $copiedFile->offsetGet('id'), $data);
                     $folderId = $lesson->lesson['share_folder'] ? $lesson->lesson['share_folder'] : $lesson->lesson['id'];
                     $data = preg_replace("#(" . G_SERVERNAME . ")*content/lessons/" . $sourceUnit['lessons_ID'] . "/(.*)#", "content/lessons/" . $folderId . '/${2}', $data, -1, $count);
                 }
             }
             //this means that the file already exists
         }
         $unit->offsetSet('data', $data);
         if ($file && $unit['ctg_type'] == 'scorm' || $unit['ctg_type'] == 'scorm_test') {
             $d = new EfrontDirectory(dirname($file));
             $d->copy($lesson->getDirectory() . basename(dirname($file)), true);
         }
     }
     $unit->persist();
     // copying questions that belong to this unit
     if ($copyQuestions) {
         $questions = eF_getTableData("questions", "*", "content_ID=" . $sourceUnit->offsetGet('id'));
         if ($copyFiles) {
             $folderId = $lesson->lesson['share_folder'] ? $lesson->lesson['share_folder'] : $lesson->lesson['id'];
         }
         for ($k = 0; $k < sizeof($questions); $k++) {
             if ($copyFiles) {
                 $questions[$k]['text'] = replaceQuestionPaths($questions[$k]['text'], $questions[$k]['lessons_ID'], $folderId);
                 $questions[$k]['explanation'] = replaceQuestionPaths($questions[$k]['explanation'], $questions[$k]['lessons_ID'], $folderId);
             }
             $questions[$k]['content_ID'] = $unit->offsetGet('id');
             $questions[$k]['lessons_ID'] = $unit->offsetGet('lessons_ID');
             unset($questions[$k]['id']);
             eF_insertTableData("questions", $questions[$k]);
         }
     }
     return $unit;
 }
Example #5
0
 /**
  * This function analyzes the manifest. In order to perform faster, manifest entities are analyzed one-by-one (on the fly)
  * during parsing and not stored into memory
  * Algorithm:
  * 1. Detect organization elements. Each one will consist a separate units structure inside efront
  * 2. Dive inside an organization and detect item elements. Each <item> corresponds to a "unit" in efront
  *
  *
  *
  *
  * @param $manifest
  * @return unknown_type
  */
 public static function import2($lesson, $manifest)
 {
     //@todo: parse $lesson
     //foreach ($namespaces as $prefix => $ns) {
     //$xml->registerXPathNamespace($prefix, $ns);
     //}
     //pr($xml -> xpath("$dfn:organizations/$dfn:organization/$dfn:item/adlcp:timeLimitAction"));
     $xml = simplexml_load_file(G_SCORMPATH . 'imsmanifest.xml', 'SimpleXMLIterator');
     $namespaces = $xml->getNamespaces(true);
     if (isset($namespaces[""])) {
         //See notes for xpath() in php.net site
         $dfn = "default";
         $xml->registerXPathNamespace($dfn, $namespaces[""]);
         // register a prefix for that default namespace:
         //$xml -> organizations -> registerXPathNamespace($dfn, $namespaces[""]);  	// register a prefix for that default namespace:
     }
     /**
      * Manifest (1/1): may contain the following elements:
      * - metadata (1/1)
      * - organizations (1/1)
      * - resources (1/1)
      * - manifest
      * - imsss:sequencingCollection (0/1)
      * And the following attributes
      * - identifier (xs:ID, m): unique identifier
      * - version (xs:string, o): manifest version
      * - xml:base (xs:anyURI, o): provides a relative path offset for the content file(s) contained in the manifest
      */
     $manifest['identifier'] = (string) $xml->attributes()->identifier;
     $manifest['version'] = (string) $xml->attributes()->version;
     //@todo: handle 'xml:base'
     //$manifest['xml:base']	= (string)$xml -> attributes() -> xml:base;
     /**
      * Metadata: may contain the following elements:
      * - schema (1/1)
      * - schemaversion (1/1)
      * - {metadata} (0/1)
      */
     $metadata['schema'] = (string) $xml->metadata->schema;
     $metadata['schemaversion'] = (string) $xml->metadata->schemaversion;
     //@todo: handle metadata
     /*
      * Organizations: may contain the following elements:
      * - organization (1/M)
      * And the following attributes:
      * - default (xs:IDREF, m): The id of the default organization
      */
     $organizations['default'] = (string) $xml->organizations->attributes();
     //@todo: check that default is actually an existing organization
     /*
      * Organization: may contain the following elements:
      * - title (1/1)
      * - item (1/M)
      * - metadata (0/1)
      * - imsss:sequencing
      * And the following attributes:
      * - identifier (xs:ID, m): identifier (unique within the manifest)
      * - structure (xs:string, o): Describes the shape of the organization (default: hierarchical)
      * - adlseq:objectivesGlobalToSystem (xs:boolean, o): self-explanatory ;)
      */
     foreach ($xml->organizations->organization as $org) {
         $org->registerXPathNamespace($dfn, $namespaces[""]);
         // register a prefix for that default namespace:
         $id = (string) $org->attributes()->identifier;
         $org->attributes()->structure ? $organization[$id]['structure'] = $org->attributes()->structure : ($organization[$id]['structure'] = 'hierarchical');
         $organization[$id]['title'] = $org->attributes()->title;
         //@todo: the importing may be done below existing elements, take this into account when considering $previousContentId (its initial value may not be 0)
         $contentTree = new EfrontContentTree($lesson);
         $previousContent = $contentTree->getLastNode() or $previousContent = array('id' => 0);
         //Create the "holding" unit, an empty unit that will hold this organization's elements
         $previousContent = $parentContent = EfrontUnit::createUnit(array('name' => $organization[$id]['title'], 'parent_content_ID' => 0, 'previous_content_ID' => $previousContent['id'], 'lessons_ID' => $lesson));
         //Get contents of the organization
         foreach ($org as $key => $value) {
             /*
              * Item: may contain the following elements:
              * - title (1/1)
              * - item 0/M
              * - metadata 0/1
              * - adlcp: timeLimitAction 0/1
              * - adlcp: dataFromLMS 0/1
              * - adlcp: completionThreshold 0/1
              * - imsss:sequencing
              * - adlnav:presentation
              * And the following attributes:
              * - identifier (xs:ID, m): a unique identifier
              * - identifierref (xs:string, o): a reference to a resource
              * - isvisible (xs:boolean, o): whether this item is displayed when the structure of the package is displayed or rendered (Default true)
              * - parameters (xs:string, o): static parameters to be passed to the resource at launch time (max 1000 chars)
              */
             if ($key == 'item') {
                 $itemId = (string) $value->attributes()->identifier;
                 //pr($value -> attributes() -> identifier);
                 $item = array('identifier' => $itemId, 'identifierref' => (string) $value->attributes()->identifierref, 'isvisible' => (string) $value->attributes()->isvisible, 'parameters' => (string) $value->attributes()->parameters, 'title' => (string) $value->title, 'timeLimitAction' => (string) reset($org->xpath("{$dfn}:item[@identifier='{$itemId}']/adlcp:timeLimitAction")), 'dataFromLMS' => (string) reset($org->xpath("{$dfn}:item[@identifier='{$itemId}']/adlcp:dataFromLMS")), 'completionThreshold' => (string) reset($org->xpath("{$dfn}:item[@identifier='{$itemId}']/adlcp:completionThreshold")));
                 //@todo:<imsss:sequencing>, <adlnav:presentation>
                 //@todo: nested items
                 //@todo: metadata
                 $previousContent = EfrontUnit::createUnit(array('name' => $item['title'], 'parent_content_ID' => $parentContent['id'], 'previous_content_ID' => $previousContent['id'], 'lessons_ID' => $lesson));
                 $items[$itemId] = $item['identifierref'];
             }
         }
         //@todo: handle adlseq:objectivesGlobalToSystem
     }
     /*
      * Resources: may contain the following elements:
      * - resource (0/M)
      * And the following attributes:
      * - xml:base (xs:anyURI, o): provides a relative path offset for the content file(s)
      */
     $resources = $xml->resources;
     $resources->registerXPathNamespace($dfn, $namespaces[""]);
     // register a prefix for that default namespace:
     /*
      * Resource: may contain the following elements:
      * - metadata (0/1)
      * - file (0/M)
      * - dependency (0/M)
      * And the following attributes:
      * - identifier (xs:ID, m): a unique identifier
      * - type (xs:string, m): the type of the resource
      * - href (xs:string, o): the �entry point� or �launching point� of this resource
      * - xml:base (xs:anyURI, o): a relative path offset for the files contained in the manifest
      * - adlcp:scormType (xs:string, m): the type of SCORM resource ("sco" or "asset")
      */
     foreach ($resources->resource as $key => $value) {
         $resourceId = (string) $value->attributes()->identifier;
         $resource = array('identifier' => $resourceId, 'type' => (string) $value->attributes()->type, 'href' => (string) $value->attributes()->href, 'base' => (string) $value->attributes($namespaces['xml'])->base, 'scormType' => (string) $value->attributes($namespaces['adlcp'])->scormType);
         /**
          * File: may contain the following elements:
          * - metadata (0/1)
          * And the following attributes:
          * - href (xs:string, m): identifies the location of the file
          */
         foreach ($value->file as $f) {
             $file = array('href' => (string) $f->attributes()->href);
         }
         /**
          * Dependency: may contain the following elements:
          * <none>
          * And the following attributes:
          * - identifierref (xs:string, m): an identifier attribute of a resource
          */
         foreach ($value->dependency as $d) {
             $dependency = array('identifierref' => (string) $d->attributes()->identifierref);
         }
     }
     //@todo: sequencingCollection
     //pr($organization);
     //    	$result = $xml -> xpath("//$dfn:manifest/$dfn:organizations/$dfn:organization");
     /*
     $iterator = new SimpleXMLIterator($xml -> asXML());
     foreach (new RecursiveIteratorIterator($iterator, RecursiveIteratorIterator::SELF_FIRST) as $key => $value) {
     
     }
     */
     /*
              //$iterator = new SimpleXMLIterator($data);
              //$iterator = simplexml_load_string($data, 'SimpleXMLIterator');
     */
 }
Example #6
0
 /**
  * Function addUnit()
  *
  * This function is used to add a unit to the manifest file
  * <br/>Example:
  * <code>
  * $manifest = new EfrontManifest(32);    //32 is a lesson id
  * $unit = new EfrontUnit(10);      //10 is a content id
  * $manifest->addUnit($unit);
  * </code>
  *
  * @param EfrontUnit $unit The unit to be added
  * @since 1.0
  * @access public
  */
 public function addUnit($unit)
 {
     $this->units[$unit->offsetGet('id')] = $unit;
 }
Example #7
0
 /**
  * Get statistic information about scorm tests
  *
  * This returns statistic info for a scorm test
  * <br/>Example:
  * <code>
  * $tests = array(2, 4);
  * $info = EfrontStats :: getScomTestInfo($tests);                   //Get information for tests 2,4
  * </code>
  * @param mixed $tests Either an array of tests id or false (request information for all existing tests)
  * @return array the tests' statistic info
  * @since 3.5.0
  * @access public
  * @static
  */
 public static function getScormTestInfo($tests = false, $categories = false, $show_all = false)
 {
     $tests_info = array();
     if ($tests === false) {
         $tests = eF_getTableDataFlat("content", "id", "ctg_type='scorm_test'");
         $tests = $tests['id'];
     } else {
         if (!is_array($tests)) {
             $tests = array($tests);
         }
     }
     $lessonNames = eF_getTableDataFlat("lessons", "id,name");
     sizeof($lessonNames) > 0 ? $lessonNames = array_combine($lessonNames['id'], $lessonNames['name']) : ($lessonNames = array());
     $result = eF_getTableData("users", "name, surname, login");
     $users = array();
     foreach ($result as $user) {
         $users[$user['login']] = $user;
     }
     foreach ($tests as $id) {
         $testInfo = array();
         $unit = new EfrontUnit($id);
         $result = eF_getTableData("scorm_data", "*", "content_ID={$id} and (users_LOGIN is null or users_LOGIN='')");
         $testInfo['general']['content_ID'] = $id;
         $testInfo['general']['id'] = $id;
         $testInfo['general']['name'] = $unit->offsetGet('name');
         $testInfo['general']['scorm'] = 1;
         $testInfo['general']['lesson_name'] = $lessonNames[$unit->offsetGet('lessons_ID')];
         if ($result[0]['maxtimeallowed']) {
             $time_parts = explode(":", $result[0]['maxtimeallowed']);
             $testInfo['general']['duration'] = $time_parts[0] * 3600 + $time_parts[1] * 60 + $time_parts[2];
             $testInfo['general']['duration_str'] = eF_convertIntervalToTime($testInfo['general']['duration']);
         } else {
             $testInfo['general']['duration'] = '';
             $testInfo['general']['duration_str'] = eF_convertIntervalToTime($testInfo['general']['duration']);
         }
         // Create results score categories
         if ($categories) {
             $testInfo['score_categories'] = array();
             $step = 100 / $categories;
             for ($i = 0; $i < $categories; $i++) {
                 $testInfo['score_categories'][$i] = array("from" => $i * $step, "to" => ($i + 1) * $step, "count" => 0);
                 if ($i == $categories - 1) {
                     $testInfo['score_categories'][$i]["to"] = 100;
                 }
             }
         }
         $testInfo['done'] = array();
         $done_info = eF_getTableData("scorm_data d, users u", "d.users_LOGIN, u.name, u.surname, d.score, d.timestamp, d.lesson_status, d.masteryscore, d.minscore, d.maxscore", "d.lesson_status != 'incomplete' and d.users_LOGIN = u.LOGIN and d.content_ID = {$id}");
         foreach ($done_info as $done) {
             $done_test = array();
             $done_test['users_LOGIN'] = $done['users_LOGIN'];
             $done_test['name'] = $done['name'];
             $done_test['surname'] = $done['surname'];
             $done_test['timestamp'] = $done['timestamp'];
             $done_test['status'] = $done['lesson_status'];
             $done_test['mastery_score'] = $done['masteryscore'];
             if (is_numeric($done['minscore']) && is_numeric($done['maxscore'])) {
                 $done_test['score'] = 100 * $done['score'] / ($done['minscore'] + $done['maxscore']);
             } else {
                 $done_test['score'] = $done['score'];
             }
             //$done_test['score']         = $done['score'];
             $testInfo['done'][] = $done_test;
             if ($categories) {
                 $stat_cat = $done_test['score'] / $step;
                 $testInfo['score_categories'][$stat_cat >= $categories ? $categories - 1 : $stat_cat]["count"]++;
             }
         }
         if ($categories) {
             $doneTestsCount = sizeof($testInfo['done']);
             $sum_count = $doneTestsCount;
             // counts how many users have score equal or above each score_category
             if ($sum_count > 0) {
                 foreach ($testInfo['score_categories'] as $key => $score) {
                     $testInfo['score_categories'][$key]['percent'] = round(100 * ($testInfo['score_categories'][$key]['count'] / $doneTestsCount), 2);
                     $testInfo['score_categories'][$key]['sum_count'] = $sum_count;
                     $testInfo['score_categories'][$key]['sum_count_percent'] = round(100 * ($sum_count / $doneTestsCount), 2);
                     $sum_count -= $testInfo['score_categories'][$key]['count'];
                 }
             }
         }
         $tests_info[$id] = $testInfo;
     }
     return $tests_info;
 }
Example #8
0
 /**
  * Create test
  *
  * This function is used to create a new test.
  * In order to create the test, it firsts creates
  * a unit to hold it.
  * <br/>Example:
  * <code>
  * $contentFields = new array('name' => 'new unit');
  * $testFields    = new array('duration' => 100);
  * $test = EfrontTest :: createTest($contentFields, $testFields);
  * </code>
  *
  * @param mixed $content The content unit fields or an existing unitObject. If it's false, then the test will not be associated to a unit
  * @param array $test The test fields
  * @return EfrontTest the new test object
  * @since 3.5.0
  * @access public
  * @static
  */
 public static function createTest($content, $test)
 {
     if ($content === false) {
         $test['content_ID'] = 0;
     } elseif (!$content instanceof EfrontUnit) {
         $unit = EfrontUnit::createUnit($content);
         $test['content_ID'] = $unit['id'];
         $test['lessons_ID'] = $unit['lessons_ID'];
     } else {
         $unit = $content;
         $test['content_ID'] = $unit['id'];
         $test['lessons_ID'] = $unit['lessons_ID'];
     }
     unset($test['id']);
     if ($newId = eF_insertTableData("tests", $test)) {
         if ($test['lessons_ID'] != 0) {
             EfrontEvent::triggerEvent(array("type" => EfrontEvent::TEST_CREATION, "users_LOGIN" => $GLOBALS['currentUser']->user['login'], "lessons_ID" => $test['lessons_ID']));
         } else {
             // Special treatment for skillgap tests
             EfrontEvent::triggerEvent(array("type" => EfrontEvent::TEST_CREATION, "users_LOGIN" => $GLOBALS['currentUser']->user['login'], "lessons_ID" => 0, "lessons_name" => _SKILLGAPTESTS));
         }
         return new EfrontTest($newId);
     } else {
         return false;
     }
 }
Example #9
0
<?php

/**
 * 
 */
if (str_replace(DIRECTORY_SEPARATOR, "/", __FILE__) == $_SERVER['SCRIPT_FILENAME']) {
    exit;
}
$loadScripts[] = 'includes/metadata';
try {
    if ($_GET['unit']) {
        $currentUnit = new EfrontUnit($_GET['unit']);
        if (!$currentUnit['metadata']) {
            $defaultMetadata = array('title' => $currentUnit['name'], 'date' => date("Y/m/d", $currentUnit['timestamp']));
            $currentUnit['metadata'] = serialize($defaultMetadata);
            $currentUnit->persist();
        }
        $form = new HTML_QuickForm("empty_form", "post", null, null, null, true);
        try {
            $contentMetadata = unserialize($currentUnit['metadata']);
            $metadata = new DublinCoreMetadata($contentMetadata);
            $smarty->assign("T_CONTENT_METADATA_HTML", $metadata->toHTML($form));
            $smarty->assign("T_CURRENT_UNIT", $currentUnit);
        } catch (Exception $e) {
            handleNormalFlowExceptions($e);
        }
        if (isset($_POST['postAjaxRequest'])) {
            if (in_array($_POST['dc'], array_keys($metadata->metadataAttributes))) {
                if ($_POST['value']) {
                    $contentMetadata[$_POST['dc']] = htmlspecialchars(urldecode($_POST['value']));
                } else {
Example #10
0
        						   'show_answers_if_pass' => 1,
        						   'show_score'		  => 1,
                                   'maintain_history' => 5,
                                   'publish'          => 1,
        						   'keep_best'        => 0,
                                   'mastery_score'    => $_GET['ctg'] != 'feedback' ? 50 : 0,
                				   'redoable'	      => 1));
        */
    $form->setDefaults(array('action_on_submit' => 5, 'maintain_history' => 5, 'publish' => 1, 'keep_best' => 0, 'mastery_score' => $_GET['ctg'] != 'feedback' ? 50 : 0, 'redoable' => 1));
    if (isset($_GET['from_unit'])) {
        $form->setDefaults(array('parent_content' => $_GET['from_unit']));
    }
} else {
    if (isset($_GET['edit_test'])) {
        if (!$skillgap_tests) {
            $testUnit = new EfrontUnit($currentTest->test['content_ID']);
        }
        if ($_GET['ctg'] != 'feedback') {
            $form->addElement('submit', 'submit_test', _SAVETEST, 'class = "flatButton"');
            $form->addElement('submit', 'submit_test_new', _SAVEASNEWTEST, 'class = "flatButton"');
        } else {
            $form->addElement('submit', 'submit_test', _SAVE, 'class = "flatButton"');
        }
        $form->freeze('parent_content');
        $form->setDefaults($currentTest->options);
        if ($currentTest->options['redirect']) {
            $submitaction = 0;
        } elseif ($currentTest->options['show_answers_if_pass']) {
            $submitaction = 5;
        } elseif ($currentTest->options['answers']) {
            $submitaction = 4;
Example #11
0
     }
     $legalQuestions = eF_getTableDataFlat('questions', "id");
 }
 $legalQuestions = $legalQuestions['id'];
 //Lesson's questions
 /*
 	//If we asked to edit a test with its corresponding unit id, then find the equivalent test
 	if (isset($_GET['edit_test']) && in_array($_GET['edit'], $legalUnits)) {
 	    $currentTest = new EfrontTest($_GET['edit'], true);
 	    $_GET['edit_test'] = $currentTest -> test['id'];
 	}
 */
 $smarty->assign("T_SKILLGAP_TEST", $skillgap_tests);
 //If we asked to edit the test using the Unit id, then convert to Test id and assign to $_GET['edit_test']
 if (isset($_GET['edit']) && in_array($_GET['edit'], $legalUnits)) {
     $unit = new EfrontUnit($_GET['edit']);
     if ($unit->isTest()) {
         $test = new EfrontTest($_GET['edit'], true);
         $_GET['edit_test'] = $test->test['id'];
     }
 }
 if (isset($_GET['delete_test']) && in_array($_GET['delete_test'], $legalValues) && eF_checkParameter($_GET['delete_test'], 'id')) {
     try {
         if (!$_change_) {
             throw new EfrontUserException(_UNAUTHORIZEDACCESS, EfrontUserException::RESTRICTED_USER_TYPE);
         }
         $currentTest = new EfrontTest($_GET['delete_test']);
         $currentTest->delete();
     } catch (Exception $e) {
         header("HTTP/1.0 500 ");
         echo $e->getMessage() . ' (' . $e->getCode() . ')';