[Logicampus-cvs] logicampus/src/logicreate/lib/lob lc_lob.php, NONE, 1.1 lc_lob_class.php, NONE, 1.
Brought to you by:
trilexcom
Update of /cvsroot/logicampus/logicampus/src/logicreate/lib/lob In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv9622/lib/lob Added Files: lc_lob.php lc_lob_class.php lc_lob_class_test.php lc_lob_renderer.php lc_lob_test.php lc_lob_xml.php Log Message: Moving libraries into sub folders. --- NEW FILE: lc_lob_class_test.php --- <?php include_once(LIB_PATH.'PBDO/LobTest.php'); include_once(LIB_PATH.'PBDO/LobTestQst.php'); /** * Hold lob repo entries and lob test entries */ class Lc_Lob_ClassTest extends Lc_Lob_Class { var $type = 'test'; var $questionObjs = array(); var $mime = 'X-LMS/test'; function Lc_Lob_ClassTest($id = 0) { if ($id < 1) { $this->repoObj = new LobClassRepo(); $this->lobSub = new LobClassTest(); $this->lobMetaObj = new LobClassMetadata(); $this->lobMetaObj->createdOn = time(); } else { $this->repoObj = LobClassRepo::load($id); $tests = $this->repoObj->getLobClassTestsByLobClassRepoId(); $this->lobSub = $tests[0]; } } function addQuestion($qtext, $type = 'QUESTION_ESSAY', $choices = '', $answers = '') { $q = new LobTestQst(); $q->qstText = $qtext; if ( is_array($choices) ) { } $this->questionObjs[] = $q; } function getQuestionCount() { return count($this->questionObjs); } /** * Copy all the values of a specific sub Object to this lobSub */ function copySub(&$repoSub) { /* $this->lobSub->lobText = $repoSub->lobText; $this->lobSub->lobBinary = $repoSub->lobBinary; $this->lobSub->lobFilename = $repoSub->lobFilename; $this->lobSub->lobCaption = $repoSub->lobCaption; */ } /** * Skip the meta object for now */ function save() { if ($this->repoObj->lobGuid == '') { $guid = lcUuid(); $this->repoObj->set('lobGuid',$guid); } $this->repoObj->version++; $this->repoObj->save(); $ret = ($this->repoObj->getPrimaryKey() > 0); $this->lobSub->lobClassRepoId = $this->repoObj->getPrimaryKey(); $this->lobSub->save(); $this->lobMetaObj->updatedOn = time(); if ($this->lobMetaObj->isNew()) { //might be a brand new object $this->lobMetaObj->lobId = $this->repoObj->getPrimaryKey(); } return $this->lobMetaObj->save() && $ret; } //////////////// DEPRECATED //////////////// # Gradebook entry id # used for redirects back to the gradebook when modifying a user's score var $idClassGradebookEntries= ''; function load($id,$class_id) { if ( $class_id == '' ) { trigger_error('load with empty class id'); return false; } $array = AssessmentPeer::doSelect("class_id = $class_id and assessment_id = $id"); if (!is_array($array) ) { trigger_error('No permission to load assessment '.$id); return false; } return $array[0]; } function loadAll($class_id) { if ( $class_id == '' ) { trigger_error('Peer doSelect with empty key'); return false; } $array = AssessmentPeer::doSelect("class_id = $class_id"); return $array; } # boolean returns true if student can take the # test, false if they cannot # pass in the time stamp of when the user started taking the test # ($u->sessionvars['asmt_start_date'] for example function canTake($start) { $end = $this->dateUnavailable; $timeLimitSeconds = $this->minuteLimit * 60; $newEndingTime = $start + $timeLimitSeconds; $time = time(); /* echo '<br>'.$time. '= current time<br>'; echo $newEndingTime. '= ending time<br>'; */ if ( ($time > $newEndingTime) || ($time > $end) ) { return FALSE; } return TRUE; } function getAssessmentQuestions() { $array = AssessmentQuestionPeer::doSelect('assessment_id = \''.$this->getPrimaryKey().'\' order by question_sort'); $cc = count ($array); for($x=0; $x<$cc; ++$x) { $superObj = $array[$x]; switch($superObj->questionType) { case QUESTION_TRUEFALSE: $subObj = new AssessmentQuestionTrueFalse(); break; case QUESTION_MCHOICE: $subObj = new AssessmentQuestionMChoice(); break; case QUESTION_MANSWER: $subObj = new AssessmentQuestionMAnswer(); break; case QUESTION_MATCHING: $subObj = new AssessmentQuestionMatching(); break; case QUESTION_FILLINBLANK: $subObj = new AssessmentQuestionFill(); break; case QUESTION_ESSAY: $subObj = new AssessmentQuestionEssay(); break; default: trigger_error("Cannot find appropriate class for question. Question type was ".$superObj->questionType); } if( $superObj->assessmentQuestionId ) $subObj->_new = false; else $subObj->_new = true; $subObj->_modified = false; $subObj->assessmentQuestionId = $superObj->assessmentQuestionId; $subObj->assessmentId = $superObj->assessmentId; $subObj->questionType = $superObj->questionType; $subObj->questionSort = $superObj->questionSort; $subObj->questionDisplay = $superObj->questionDisplay; $subObj->questionText = $superObj->questionText; $subObj->questionPoints = $superObj->questionPoints; $subObj->questionChoices = $superObj->questionChoices; $subObj->fileHash = $superObj->fileHash; $subObjArray[] =$subObj; } return $subObjArray; } # $questions = array of question objects with answer object added on # $answers = array 0f answer objects # $u = user object # $grade = on / off to re-grade the assessment # If you want it to re-grade the assessment for you before sending out # the email, this does update the students grades for points_earned in the database function emailTeacher($questions, $stuUserObj, $logObj, $grade=0) { $u = $stuUserObj; $qstans .= "Student ID: ".$stuUserObj->username."\n"; $qstans .= "Name: ".$stuUserObj->profile->values['firstname']." ".$stuUserObj->profile->values['lastname']."\n"; $qstans .= "Assessment: Name ".$this->displayName."\n"; $qstans .= "Date Started: ".date('m-d-y h:i A', $u->sessionvars['asmt_date_start'])."\n"; $qstans .= "Date Stopped: ".date('m-d-y h:i A', $logObj->end_date)."\n\n"; $questionCount = count($questions); for ($i=0; $i<$questionCount; $i++) { $num = $i +1; $questionId = $questions[$i]->assessmentQuestionId; $qstans .= $num.".\n"; $qstans .= "Type of Question: ".$questions[$i]->questionDisplay."\nQuestion: ".$questions[$i]->questionText."\n"; $qstans .= "Points Assigned: ".$questions[$i]->answer->pointsEarned."\n"; if ($questions[$i]->questionType == QUESTION_MATCHING || $questions[$i]->questionType == QUESTION_MANSWER) { $answer = unserialize($questions[$i]->answer->assessmentAnswerValues); $qstans .= "Answers: \n"; for ($y=0;$y<$answerCount; $y++) { $ansnum = $y + 1; + //$qstans .= "\t $ansnum. ".$answer[$y]."\n"; + //trying out a fix for a bug where the teacher just + //gets the index of the correct answer + //MAK 11-03-04 + $qstans .= "\t $ansnum. ".$questions[$i]->questionChoices[$y]->label ." " .$answer[$y]."\n"; } } else { $qstans .= "Answer: ".$questions[$i]->answer->assessmentAnswerValues."\n\n"; } $total_points_earned += $questions[$i]->answer->pointsEarned; $total_possible_points += $questions[$i]->questionPoints; } $qstans .= "\n\nTotal Points Earned: ". $total_points_earned ." out of ". $total_possible_points; # Send email to teacher $db = DB::getHandle(); $sql = "select email from lcUsers where username='".$u->activeClassTaken->facultyId."'"; $db->queryOne($sql); $email = $db->record['email']; $subject = $this->displayName." completed by ".$u->profile->values['firstname']." ".$u->profile->values['lastname']; if ( mail($email, $subject, $qstans) ) { return TRUE; } return FALSE; } # Pulls in the last log entry for an assessment function getLastLogEntry($username) { include_once(LIB_PATH.'AssessmentLog.php'); $log = AssessmentLogPeer::doSelect("assessment_id='".$this->assessmentId."' AND id_student='".$username."' ORDER BY start_date DESC LIMIT 1"); return $log[0]; } # Loads answers onto questions object # And unserializes the matching and multiple answer questions for you automatcially function getQuestionsAndAnswers($studentId, $id_classes) { $questions = $this->getAssessmentQuestions(); $answers = AssessmentAnswerPeer::doSelect("assessment_id='".$this->assessmentId."' AND student_id='".$studentId."' AND id_classes='".$id_classes."'"); #debug($answers,1); $this->questionCount = count($questions); $answerCount = count($answers); for ($i=0; $i<$this->questionCount; $i++) { $num = $i +1; $questionId = $questions[$i]->assessmentQuestionId; for($x=0; $x<$answerCount; $x++) { if ($answers[$x]->assessmentQuestionId == $questionId) { #$questions[$i]->grade($answers[$x]); $questions[$i]->answer = $answers[$x]; # debug($questions[$i],1); if ($questions[$i]->questionType == QUESTION_MATCHING || $questions[$i]->questionType == QUESTION_MANSWER) { $questions[$i]->answer->assessmentAnswerValues = unserialize($questions[$i]->answer->assessmentAnswerValues); } else { $qstans .= "Answer: ".$questions[$i]->answer->assessmentAnswerValues."\n\n"; } } $this->pointsEarned += $questions[$i]->answer->pointsEarned; } $this->totalPoints += $questions[$i]->questionPoints; } return $questions; } # Loads the answers for a student for a given class and # update the gradebook score # Normally called in assessements/grade/event=updatePoints # MAK added 9/4/03 # always update gradebook scores in entries table to fix previous problem function updateGradebookScore($studentId, $id_classes) { $answer = AssessmentAnswerPeer::doSelect("student_id='$studentId' AND id_classes='$id_classes' AND assessment_id='".$this->assessmentId."'"); $count = count($answer); for ($i=0; $i<$count; $i++) { if ($answer[$i]->pointsGiven) { $totalPoints += $answer[$i]->pointsGiven; } else { $totalPoints += $answer[$i]->pointsEarned; } } $entry = $this->loadGradebookEntry($studentId); if (is_object($entry) ) { $entryId = $entry->getPrimaryKey(); $val = $this->loadGradebookVal($entryId, $studentId); if (is_object($val) ) { $val->score = $totalPoints; $val->save(); return $totalPoints; } else { # create val entry $val = new ClassGradebookVal(); $val->idClasses = $id_classes; $val->username = $studentId; $val->score = $totalPoints; $val->dateCreated = date('Y-m-d H:i:s'); $val->idClassGradebookEntries = $entryId; //__FIXME__ make comments field accept nulls // class_gradebook_val $val->save(); return $totalPoints; } } return $totalPoints; } function loadGradebookEntry($studentId) { include_once(LIB_PATH.'ClassGradebookEntries.php'); $entry = ClassGradebookEntriesPeer::doSelect("assessment_id='".$this->assessmentId."'"); $this->idClassGradebookEntries = $entry[0]->idClassGradebookEntries; return $entry[0]; } function loadGradebookVal($entryId, $studentId) { include_once(LIB_PATH.'ClassGradebookVal.php'); $val = ClassGradebookValPeer::doSelect("id_class_gradebook_entries='".$entryId."' AND username='".$studentId."'"); return $val[0]; } # Returns BOOL if the test has already been taken # or started by a student function isTaken() { include_once(LIB_PATH.'AssessmentLog.php'); $log = AssessmentLogPeer::doSelect("assessment_id='".$this->assessmentId."' AND id_classes='".$this->classId."'"); $count = count($log); if ($count) { return TRUE; } return FALSE; } } ?> --- NEW FILE: lc_lob_test.php --- <?php include_once(LIB_PATH.'PBDO/LobTest.php'); include_once(LIB_PATH.'PBDO/LobTestQst.php'); /** * Hold lob repo entries and lob test entries */ class Lc_Lob_Test extends Lc_Lob { var $type = 'test'; var $questionObjs = array(); var $mime = 'X-LMS/test'; function Lc_Lob_Test($id = 0) { if ($id < 1) { $this->repoObj = new LobRepoEntry(); $this->repoObj->lobMime = $this->mime; $this->repoObj->lobType = $this->type; $this->repoObj->lobSubType = $this->type; $this->lobSub = new LobTest(); $this->lobMetaObj = new LobMetadata(); $this->lobMetaObj->createdOn = time(); } else { $this->repoObj = LobRepoEntry::load($id); $tests = $this->repoObj->getLobTestsByLobRepoEntryId(); $this->lobSub = $tests[0]; } } function setTitle($t) { $this->repoObj->set('lobTitle', $t); } function setInstructions($i) { $this->repoObj->set('lobDescription', $i); } function setNotes($n) { $this->repoObj->set('lobNotes', $n); } function setQuestion($qidx, $qtext, $type = 'QUESTION_ESSAY', $choices = '', $answers = '') { $q = $this->_makeQuestion($qtext, $type, $choices, $answers); if ($qidx > -1) { $this->questionObjs[$qidx] = $q; } else { $this->questionObjs[] = $q; } } function addQuestion($qtext, $type = 'QUESTION_ESSAY', $choices = '', $answers = '') { $q = $this->_makeQuestion($qtext, $type, $choices, $answers); $this->questionObjs[] = $q; } function getQuestionCount() { return count($this->questionObjs); } function _makeQuestion($qtext, $type, $choices, $answers='') { $q = new LobTestQst(); $q->qstChoices = array(); $q->qstText = $qtext; $q->questionTypeId = constant($type); if ( is_array($choices) ) { } return $q; } /** * * @return bool successfully added the choice */ function addLabel($l, $correct, $qidx=-1) { if ($qidx == -1) { $qidx = $this->getQuestionCount()-1; } if ($qidx == -1) { return false; } $lidx = count($this->questionObjs[$qidx]->qstChoices); if ($lidx == -1) { $lidx = 0; } $this->questionObjs[$qidx]->qstChoices[$lidx]['label'] = $l; $this->questionObjs[$qidx]->qstChoices[$lidx]['correct'] = $correct; return true; } } ?> --- NEW FILE: lc_lob_class.php --- <?php include_once(LIB_PATH.'lob/lc_lob.php'); include_once(LIB_PATH.'PBDO/LobClassRepo.php'); include_once(LIB_PATH.'PBDO/LobClassContent.php'); include_once(LIB_PATH.'PBDO/LobClassActivity.php'); include_once(LIB_PATH.'PBDO/LobClassTest.php'); include_once(LIB_PATH.'PBDO/LobClassMetadata.php'); class Lc_Lob_Class extends Lc_Lob { var $repoObj; var $lobSub; var $lobMetaObj = null; var $type = 'unknown'; function Lc_Lob_Class($id=-1) { if ($id < 1) { $this->repoObj = new LobClassRepo(); $this->lobMetaObj = new LobMetadata(); $this->lobMetaObj->createdOn = time(); } else { $this->repoObj = LobClassRepo::load($id); $this->lobMetaObj = LobMetadata::load(array('lob_id'=>$id, 'lob_kind'=>$this->repoObj->lobType)); } } /** * Load a specific sub lob based on this type */ function loadSub() { switch($this->type) { case 'content': if ($this->repoObj->getPrimaryKey() > 0) { $results = $this->repoObj->getLobClassContentsByLobClassRepoId(); $this->lobSub = $results[0]; } else { $this->lobSub = new LobClassContent(); } break; case 'activity': if ($this->repoObj->getPrimaryKey() > 0) { $results = $this->repoObj->getLobClassActivitysByLobClassRepoId(); $this->lobSub = $results[0]; } else { $this->lobSub = new LobClassActivity(); } /* $results = $this->getLobActivitysByLobRepoEntryId(); if (! count($results) ) { trigger_error('learning object missing internal data.'); return null; } $subLob = $results[0]; include_once(LIB_PATH.'lc_lob_class.php'); $classLob = new Lc_Lob_ClassActivity(); trigger_error('un-implemented'); */ break; case 'test': if ($this->repoObj->getPrimaryKey() > 0) { $results = $this->repoObj->getLobClassTestsByLobClassRepoId(); $this->lobSub = $results[0]; } if (! is_object($this->lobSub)) { $this->lobSub = new LobClassTest(); } /* $results = $this->getLobTestsByLobRepoEntryId(); if (! count($results) ) { trigger_error('learning object missing internal data.'); return null; } $subLob = $results[0]; include_once(LIB_PATH.'lc_lob_class.php'); $classLob = new Lc_Lob_ClassTest(); trigger_error('un-implemented'); */ break; } } /** * Skip the meta object for now */ function save() { if ($this->repoObj->lobGuid == '') { $guid = lcUuid(); $this->repoObj->set('lobGuid',$guid); } $this->repoObj->version++; $this->repoObj->save(); $ret = ($this->repoObj->getPrimaryKey() > 0); $this->lobMetaObj->updatedOn = time(); if ($this->lobMetaObj->isNew()) { //might be a brand new object $this->lobMetaObj->lobId = $this->repoObj->getPrimaryKey(); } return $this->lobMetaObj->save() && $ret; } /** * Return the primary key */ function getRepoId() { return $this->repoObj->lobClassRepoId; } } class Lc_Lob_ClassContent extends Lc_Lob_Class { var $type = 'content'; function Lc_Lob_ClassContent($id=-1) { if ($id < 1) { $this->repoObj = new LobClassRepo(); $this->lobSub = new LobClassContent(); } else { $this->repoObj = LobClassRepo::load($id); $this->lobSub = LobClassContent::load($id); } } /** * Copy all the values of a specific sub Object to this lobSub */ function copySub(&$repoSub) { $this->lobSub->lobText = $repoSub->lobText; $this->lobSub->lobBinary = $repoSub->lobBinary; $this->lobSub->lobFilename = $repoSub->lobFilename; $this->lobSub->lobCaption = $repoSub->lobCaption; } /** * Skip the meta object for now */ function save() { if ($this->repoObj->lobGuid == '') { $guid = lcUuid(); $this->repoObj->set('lobGuid',$guid); } $this->repoObj->version++; $this->repoObj->save(); $ret = ($this->repoObj->getPrimaryKey() > 0); $this->lobSub->lobClassRepoId = $this->repoObj->getPrimaryKey(); $this->lobSub->save(); $this->lobMetaObj->updatedOn = time(); if ($this->lobMetaObj->isNew()) { //might be a brand new object $this->lobMetaObj->lobId = $this->repoObj->getPrimaryKey(); } return $this->lobMetaObj->save() && $ret; } } class Lc_Lob_ClassActivity extends Lc_Lob_Class { var $type = 'activity'; function Lc_Lob_ClassActivity($id=-1) { include_once(LIB_PATH.'PBDO/LobClassActivity.php'); if ($id < 1) { $this->repoObj = new LobClassRepo(); $this->lobSub = new LobClassActivity(); } else { $this->repoObj = LobClassRepo::load($id); $subs = LobClassActivityPeer::doSelect( 'lob_class_repo_id = '.$id); $this->lobSub = $subs[0]; } } /** * Copy all the values of a specific sub Object to this lobSub */ function copySub(&$repoSub) { $this->lobSub->responseTypeId = $repoSub->responseTypeId; /* $this->lobSub->instructions = $repoSub->lobDescription; $this->lobSub->lobFilename = $repoSub->lobFilename; $this->lobSub->lobCaption = $repoSub->lobCaption; */ } /** * Skip the meta object for now */ function save() { if ($this->repoObj->lobGuid == '') { $guid = lcUuid(); $this->repoObj->set('lobGuid',$guid); } $this->repoObj->version++; $this->repoObj->save(); $ret = ($this->repoObj->getPrimaryKey() > 0); $this->lobSub->lobClassRepoId = $this->repoObj->getPrimaryKey(); $this->lobSub->save(); $this->lobMetaObj->updatedOn = time(); if ($this->lobMetaObj->isNew()) { //might be a brand new object $this->lobMetaObj->lobId = $this->repoObj->getPrimaryKey(); } return $this->lobMetaObj->save() && $ret; } } ?> --- NEW FILE: lc_lob_xml.php --- <?php /** * Process Learning Object XML formats */ class Lc_Lob_Xml { } ?> --- NEW FILE: lc_lob_renderer.php --- <?php class LC_Lob_Renderer { function getMetadataForm() { $subject = array(); $subject[] = array( 'fieldName' => 'md_subj', 'displayName' => 'Subject', 'type' => 'text', ); $subdisc = array(); $subdisc[] = array( 'fieldName' => 'md_subdisc', 'displayName' => 'Sub-Discipline', 'type' => 'text', ); $author = array(); $author[] = array( 'fieldName' => 'md_author', 'displayName' => 'Author', 'type' => 'text', ); $copyright = array(); $copyright[] = array( 'fieldName' => 'md_copyright', 'displayName' => 'Copyright Year', 'type' => 'text', ); $license = array(); $license[] = array( 'fieldName' => 'md_license', 'displayName' => 'License', 'type' => 'text', ); return array($subject, $subdisc, $author, $copyright, $license); /* [1] => Array ( [0] => Array ( [pkey] => 2147483687 [formId] => 2147483654 [type] => text [fieldName] => txTitle [displayName] => Enter content title. [defaultValue] => [exp] => [validationType] => default [message] => [stripTags] => N [allowedTags] => [min] => 2 [max] => 255 [req] => Y [sort] => 1 [size] => 50 [maxlength] => 255 [selectOptions] => [checked] => [multiple] => [useValue] => [cols] => 0 [rows] => 0 [image] => [parentPkey] => 0 [rowStyle] => [groups] => Array ( [0] => reg ) [notgroups] => [row] => 1 [startYear] => [endYear] => [dateTimeBit] => [extra] => ) ) * */ } } ?> --- NEW FILE: lc_lob.php --- <?php include_once(LIB_PATH.'PBDO/LobRepoEntry.php'); include_once(LIB_PATH.'PBDO/LobMetadata.php'); include_once(LIB_PATH.'PBDO/LobContent.php'); //sub types include_once(LIB_PATH.'PBDO/LobTest.php'); include_once(LIB_PATH.'PBDO/LobActivity.php'); /** * Base class for all lob types (content, test, activity) */ class Lc_Lob { var $repoObj; var $lobSub = null; var $lobMetaObj; var $type = 'unknown'; function Lc_Lob($id=-1) { if ($id < 1) { $this->repoObj = new LobRepoEntry(); $this->lobMetaObj = new LobMetadata(); $this->lobMetaObj->createdOn = time(); } else { $this->repoObj = LobRepoEntry::load($id); $this->lobMetaObj = LobMetadata::load(array('lob_repo_entry_id'=>$id)); $this->type = $this->repoObj->lobType; } } function isImage() { return $this->repoObj->lobSubType == 'image'; } /** * Document style content, word processing files, audio, etc */ function isFile() { return $this->repoObj->lobSubType == 'document'; } /** * Acitivty/assignment style content. homework, upload a file, etc. */ function isActivity() { return $this->repoObj->lobType == 'activity'; } /** * Test/exam style content. */ function isTest() { return $this->repoObj->lobType == 'test'; } function isText() { return $this->repoObj->lobSubType == 'text'; } function get($key) { return $this->repoObj->{$key}; } function getMeta($key) { return $this->lobMetaObj->{$key}; } function set($key,$val) { $this->repoObj->set($key,$val); } function setMeta($key,$val) { $this->lobMetaObj->set($key,$val); } /** * Get version **/ function getVersion() { return $this->repoObj->lobVersion; } /** * Get Metadata **/ function getLicense() { return $this->lobMetaObj->license; } /** * Get Metadata **/ function getCopyright() { return $this->lobMetaObj->copyright; } /** * Get Metadata **/ function getSource() { return $this->lobMetaObj->source; } /** * Get Metadata **/ function getAuthor() { return $this->lobMetaObj->author; } /** * Get Metadata **/ function getSubject() { return $this->lobMetaObj->subject; } /** * Get Metadata **/ function getSubdiscipline() { return $this->lobMetaObj->subdisc; } /** * Get Metadata **/ function getEditedOn() { if ($this->lobMetaObj->updatedOn < 1) { return 'unknown'; } return date('M d \'y',$this->lobMetaObj->updatedOn); } /** * Get Metadata **/ function getCreatedOn() { if ($this->lobMetaObj->createdOn < 1) { return 'unknown'; } return date('M d \'y',$this->lobMetaObj->createdOn); } /** * Return the text to create a link to this object */ function getUrl() { return $this->repoObj->lobUrltitle; } /** * Return the type */ function getType() { return $this->repoObj->lobType; } /** * Return the sub type */ function getSubType() { return $this->repoObj->lobSubType; } /** * Return the primary key */ /* function getContentId() { return $this->repoObj->lobContentId; } */ /** * Return the primary key */ function getRepoId() { return $this->repoObj->lobRepoEntryId; } function updateAsFile($title, $subType = 'document') { $this->set('lobSubType',$subType); $this->set('lobTitle', $title); $n = $this->lobSub->lobFilename; $ext = substr ( $n, (strrpos($n, '.') - strlen($n) +1) ); $ext = strtolower($ext); $m = Lc_Lob_Util::getMimeForSubtype($subType,$ext); $this->set('lobMime', $m); } function updateAsText($title, $subType = 'text') { $this->set('lobSubType',$subType); $this->set('lobTitle', $title); } function makePublic() { $this->lobMetaObj->private = 0; } function makePrivate() { $this->lobMetaObj->private = 1; } function isPrivate() { if ($this->lobMetaObj->private ) { return 'yes'; } else { return 'no'; } } function updateMeta($vars) { $this->setMeta('lobKind','content'); $this->setMeta('author', $vars['md_author']); $this->setMeta('source', $vars['md_source']); $this->setMeta('copyright', $vars['md_copyright']); $this->setMeta('license', $vars['md_license']); $this->setMeta('subject', $vars['md_subj']); $this->setMeta('subdisc', $vars['md_subdisc']); } function save() { if ($this->repoObj->lobGuid == '') { $guid = lcUuid(); $this->repoObj->set('lobGuid',$guid); } if ($this->repoObj->lobType == '') { $this->repoObj->lobType = $this->type; } $this->repoObj->lobVersion++; $this->repoObj->save(); $ret = ($this->repoObj->getPrimaryKey() > 0); $this->lobSub->lobRepoEntryId = $this->repoObj->getPrimaryKey(); $this->lobSub->save(); $this->lobMetaObj->updatedOn = time(); $this->lobMetaObj->lobRepoEntryId = $this->repoObj->getPrimaryKey(); if ($this->lobMetaObj->isNew()) { //might be a brand new object $this->lobMetaObj->lobRepoEntryId = $this->repoObj->getPrimaryKey(); } $this->lobMetaObj->save(); $meta = ($this->lobMetaObj->getPrimaryKey() > 0); return $meta && $ret; } /** * Must be called by subclasses */ function &getRepoEntry() { return $this->repoObj; } function &getMetadata() { return $this->lobMetaObj; } /** * Make a copy or reference (link) of this lob in the * class_repo. */ function useInClass($classId = -1, $copyStyle = 'notify') { $subLob = null; $classRepo = null; $classMeta = null; if ($this->type == 'unknown') { return null; } $repo = $this->getRepoEntry(); $meta = $this->getMetadata(); switch($this->type) { case 'content': $results = $repo->getLobContentsByLobRepoEntryId(); if (! count($results) ) { trigger_error('learning object missing internal data.'); return null; } $subLob = $results[0]; include_once(LIB_PATH.'lc_lob_class.php'); $classLob = new Lc_Lob_ClassContent(); break; case 'activity': case 'interaction': $results = $repo->getLobActivitysByLobRepoEntryId(); if (! count($results) ) { trigger_error('learning object missing internal data.'); return null; } $subLob = $results[0]; include_once(LIB_PATH.'lc_lob_class.php'); $classLob = new Lc_Lob_ClassActivity(); break; case 'test': include_once(LIB_PATH.'lc_lob_test.php'); $results = $repo->getLobTestsByLobRepoEntryId(); if (! count($results) ) { trigger_error('learning object missing internal data.'); return null; } $subLob = $results[0]; include_once(LIB_PATH.'lc_lob_class.php'); include_once(LIB_PATH.'lc_lob_class_test.php'); $classLob = new Lc_Lob_ClassTest(); break; } //load or make a new class repository entry $classRepo = LobClassRepo::load( array ('lob_repo_entry_id'=> $repo->lobRepoEntryId) ); if (isset($classRepo)) { } else { $classRepo = new LobClassRepo(); $classRepo->type = $this->type; } //load or make a new class metadata entry $classMeta = LobClassMetadata::load( array ('lob_class_repo_id'=> $classRepo->lobClassRepoId) ); if (isset($classMeta)) { } else { $classMeta = new LobClassMetadata(); $classMeta->lobClassRepoId = $classRepo->lobClassRepoId; } $classLob->repoObj = $classRepo; $classLob->lobMetaObj = $classMeta; $classLob->loadSub(); //copy all values to classRepoEntry // $classLob->repoObj->classId = $classId; $classLob->repoObj->lobRepoEntryId = $repo->get('lobRepoEntryId'); $classLob->repoObj->lobGuid = $repo->get('lobGuid'); $classLob->repoObj->lobCopyStyle = $copyStyle; $classLob->repoObj->lobType = $repo->lobType; $classLob->repoObj->lobSubType = $repo->lobSubType; $classLob->repoObj->lobVersion = $repo->lobVersion; $classLob->repoObj->lobBytes = $repo->lobBytes; $classLob->repoObj->lobTitle = $repo->lobTitle; $classLob->repoObj->lobUrltitle = $repo->lobUrltitle; $classLob->repoObj->lobMime = $repo->lobMime; $classLob->repoObj->lobDescription = $repo->lobDescription; //copy all the values to lobClassMetadata // $classLob->lobMetaObj->subject = $meta->subject; $classLob->lobMetaObj->subdisc = $meta->subdisc; $classLob->lobMetaObj->author = $meta->author; $classLob->lobMetaObj->source = $meta->source; $classLob->lobMetaObj->copyright = $meta->copyright; $classLob->lobMetaObj->license = $meta->license; $classLob->lobMetaObj->userVersion = $meta->userVersion; $classLob->lobMetaObj->status = $meta->status; $classLob->lobMetaObj->updatedOn = $meta->updatedOn; $classLob->lobMetaObj->createdOn = $meta->createdOn; //update values of the sub object // $classLob->copySub($subLob); //save, get id // $classLob->save(); return $classLob; } } /** * Hold lob repo entries and lob content entries */ class Lc_Lob_Content extends Lc_Lob { var $type = 'content'; function Lc_Lob_Content($id = -1) { if ($id < 1) { $this->lobSub = new LobContent(); $this->repoObj = new LobRepoEntry(); $this->lobMetaObj = new LobMetadata(); $this->lobMetaObj->createdOn = time(); } else { $this->repoObj = LobRepoEntry::load($id); $content = $this->repoObj->getLobContentsByLobRepoEntryId(); $this->lobSub = $content[0]; $this->lobMetaObj = LobMetadata::load(array('lob_repo_entry_id'=>$id)); } } /** * Set the textual content */ function setTextContent(&$content) { $this->lobSub->lobText =& $content; $this->repoObj->lobSubType = 'text'; $this->repoObj->lobBytes = strlen($content); $this->lobSub->lobBinary = null; } /** * Set the textual content */ function setBinContent(&$binary) { $this->lobSub->lobBinary =& $binary; $this->repoObj->lobSubType = 'document'; $this->repoObj->lobBytes = strlen($binary); $this->lobSub->lobText = null; } /** * Set the textual content */ function setFile($filename, $filetitle = '') { if ($filetitle == '') { $filetitle = basename($filename); } $binary = file_get_contents($filename); $this->setBinContent($binary); $this->lobSub->lobFilename = $filetitle; } /** * Return the caption for this content, mostly for images */ function getCaption() { return $this->lobSub->lobCaption; } /** * Set the caption for this content, mostly for images */ function setCaption($cap) { $this->lobSub->lobCaption = $cap; } function getFilename() { return $this->lobSub->lobFilename; } /** * Return the text content contained in "lobSub" */ function getTextContent() { return $this->lobSub->lobText; } } /** * Hold lob repo entries and lob activity entries */ class Lc_Lob_Activity extends Lc_Lob { var $type = 'activity'; var $questionObjs = array(); var $mime = 'X-LMS/activity'; function Lc_Lob_Activity($id = -1) { if ($id < 1) { $this->repoObj = new LobRepoEntry(); $this->lobSub = new LobActivity(); $this->lobMetaObj = new LobMetadata(); $this->lobMetaObj->createdOn = time(); $this->repoObj->lobMime = $this->mime; } else { $this->repoObj = LobRepoEntry::load($id); $tests = $this->repoObj->getLobActivitysByLobRepoEntryId(); $this->lobSub = $tests[0]; $this->lobMetaObj = LobMetadata::load(array('lob_repo_entry_id'=>$id)); } } /** * Available response types are: * * 1 = upload file * 2 = text response * 3 = upload & text * 4 = forum post * 5 = None * 6 = audio */ function setResponseType($typeInt=5) { $this->lobSub->responseTypeId = $typeInt; } function getResponseTypeName($typeInt=-1) { if ($typeInt == -1) { $typeInt = $this->lobSub->responseTypeId; } switch ($typeInt) { case 1: return 'File Upload'; case 2: return 'Text Response'; case 3: return 'File Upload and Text Response'; case 4: return 'Forum Post'; case 5: return 'None'; case 6: return 'Audio Recording'; } } } /** * Handle static functions to reduce the size of Lc_Lob class */ class Lc_Lob_Util { /** * @static */ function getMimeIcon($mime) { switch ($mime) { case 'text/html': return 'html.png'; break; case 'application/pdf': return 'pdf.png'; break; case 'application/octet-stream': return 'document.png'; break; case 'X-LMS/assessment': case 'X-LMS/test': return 'quiz.png'; break; case 'X-LMS/assignment': case 'X-LMS/activity': case 'X-LMS/interaction': return 'activity.png'; break; case 'image/': case 'image/jpeg': case 'image/jpg': case 'image/gif': case 'image/bmp': case 'image/png': case 'image/mng': return 'image.png'; break; default: return 'document.png'; break; } } /** * @static */ function getSubTypeIcon($subType) { return Lc_Lob_Util::getMimeIcon( Lc_Lob_Util::getMimeForSubtype($subType)); } /** * Return an internet MIME for a specific sub-type. * Optional extension for generic sub-types like "open office" * * @static */ function getMimeForSubtype($subtype,$ext='') { if ($ext == 'jpeg' || $ext == 'pjpeg' || $ext == 'jpg') { $ext = 'jpeg'; } switch($subtype) { case 'text': return 'text/plain'; case 'wiki': return 'text/wiki'; case 'html': return 'text/html'; case 'image': return 'image/'.$ext; } if ($subtype == 'document' || $subtype == 'doc') { switch($ext) { case 'pdf': return 'application/pdf'; break; case 'sxw': return 'application/vnd.sun.xml.writer'; break; case 'sxc': return 'application/vnd.sun.xml.calc'; break; } } if ($subtype == 'audio') { switch($ext) { case 'mp3': return 'audio/mpeg'; break; } } return "application/octet-stream"; } /** * Make the text URL friendly by removing characters that would * have to be URL encoded to be valid. * * @static */ function createLinkText($name,$ext='') { $ext = strtolower($ext); $ret = str_replace('&', ' and ', $name); $ret = str_replace(' ', '_', $ret); $pattern = '/[\x{21}-\x{2C}]|[\x{2F}]|[\x{5B}-\x{5E}]|[\x{7E}]/'; $ret = preg_replace($pattern, '_', $ret); $ret = str_replace('___', '_', $ret); $ret = str_replace('__', '_', $ret); $ret = str_replace('__', '_', $ret); if ($ext != '' && $ext != 'html' && $ext != 'htm') { $ret .= '.'.$ext; } return $ret; } /** * Return a number of bytes as at least 0.00 kilobytes */ function formatBytes($intSize) { return sprintf('%0.2f', ($intSize/1000)). ' Kb'; } } ?> |