Thread: [Logicampus-cvs] logicampus/src/logicreate/services/classmgr classMaterial.lcp, NONE, 1.1
Brought to you by:
trilexcom
From: Mark K <har...@us...> - 2008-02-01 03:05:42
|
Update of /cvsroot/logicampus/logicampus/src/logicreate/services/classmgr In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv17944/src/logicreate/services/classmgr Added Files: classMaterial.lcp Log Message: Adding simple class materials service. --- NEW FILE: classMaterial.lcp --- <?php /** * */ include_once(LIB_PATH.'datagrid.php'); include_once(LIB_PATH."SiteForms.php"); include_once(LIB_PATH."classAssignmentObj.php"); include_once(LIB_PATH."ClassGradebookEntries.php"); include_once(LIB_PATH."ClassGradebook.php"); include_once(LIB_PATH."ClassGradebookVal.php"); include_once(LIB_PATH.'lc_lesson.php'); include_once(LIB_PATH.'lc_lesson_sequence.php'); include_once(LIB_PATH.'lc_lob.php'); include_once(LIB_PATH.'lc_lob_class.php'); class classMaterial extends FacultyService { var $presentor = 'htmlPresentation'; var $inactivelinks = array( 'Classroom Material' ); var $applinks = array(); var $sectionTitle = "Classroom Materials"; /** * show a list of available GBEs to insert this assignment into */ function showEntriesListRun(&$db,&$u,&$lc,&$t) { $lc->templateName = 'assignmentManage_pushtoGradebook'; // get assignment object $assignmentObj = classAssignmentObj::_getFromDB($lc->getvars['id_class_assignments'], 'id_class_assignments', 'id_classes='.$u->activeClassTaught->id_classes); // ok lets give a list, it's our view time viewing this //we don't want people pushing assignments into assessment entries... // grades will get all screwed up include_once(LIB_PATH.'ClassGradebookEntries.php'); $gradebook_entries_obj = ClassGradebookEntriesPeer::doSelect('id_classes='.$assignmentObj->id_classes. ' AND assessment_id = 0 AND assignment_id = 0 ORDER BY id_class_gradebook_categories ASC, title ASC'); if ( is_array($gradebook_entries_obj) ) { $t['table'] .= '<table border="0" align="center"><tr><th>Code / Entry Name</th><td> </td></tr>'; foreach($gradebook_entries_obj as $object) { $t['table'] .= '<tr><td><a href="'.modurl('assignmentManage/event=pushtoGradebook/id_class_assignments='.$assignmentObj->id_class_assignments.'/id_class_gradebook_entries='.$object->get('idClassGradebookEntries')).'">'; $t['table'] .= '['.$object->get('gradebookCode').'] '. $object->get('title').'</td>'; $t['table'] .= '<td><- click the entry to publish there</td></tr>'; } $t['table'] .= '</table>'; } } /** * do the actual pushing */ function pushtoGradebookRun(&$db,&$u,&$lc,&$t) { include_once(LIB_PATH.'ClassGradebookVal.php'); include_once(LIB_PATH.'ClassGradebookEntries.php'); // get assignment object $assignmentObj = classAssignmentObj::_getFromDB($lc->getvars['id_class_assignments'], 'id_class_assignments', 'id_classes='.$u->activeClassTaught->id_classes); $t['assignmentObj'] = $assignmentObj; $entryObj = ClassGradebookEntries::load( array('id_class_gradebook_entries'=>$lc->getvars['id_class_gradebook_entries'], 'id_classes'=>$u->activeClassTaught->id_classes, 'assignment_id'=>'0','assessment_id'=>'0') ); //if this was loaded, but has no assignment id, set the id and save it if ( is_object($entryObj) && (!$entryObj->assignmentId || !$entryObj->dateDue || !$entryObj->assessmentId) ) { $entryObj->assignmentId = $assignmentObj->id_class_assignments; $entryObj->dateDue = $assignmentObj->dueDate; $entryObj->save(); } else { //they clicked a link with an id that they don't own $this->presentor = 'errorMessage'; $t['message'] = "You don't own the gradebook entry #".$lc->getvars['id_class_gradebook_entries']." or it is already attached to another assignment or assessment."; $t['details'] = "Go back and select another gradebook entry. If you think you've gotten this message in error, contact the helpdesk."; $t['details'] .= "<br/>Assignment ID = ".$entryObj->assignmentId." - Assessment ID = ".$entryObj->assessmentId; return; } //need both assignment and entry permission to update if ($assignmentObj->id_classes && $entryObj->idClassGradebookEntries) { // __FIXME__ try to get a GBE, if there's one that relates via GBE's assignment_id field, then // go in this next block // pushing if ((int)$lc->getvars['id_class_gradebook_entries'] > 0) { $lc->getvars['id_class_gradebook_entries'] = (int)$lc->getvars['id_class_gradebook_entries']; // making it an int // lets add user's grades to the VAL of this entry //__FIXME__ not really a fix me but a notice // all inactive students will still have grades pushed to the gradebook // is this okay? should be because they can't get access to the GB anyway // getting class list w/ grades $sql = ' SELECT A.*, B.id_classes FROM class_assignments_grades as A INNER JOIN class_assignments as B ON A.id_class_assignments = B.id_class_assignments WHERE A.id_class_assignments='.$assignmentObj->id_class_assignments.' '; $db->query($sql); $db3 = DB::getHandle(); while ($db->nextRecord()) { // doing a swap off.. remove one, then readd it $sql = ' DELETE FROM class_gradebook_val WHERE ( id_class_gradebook_entries='.$lc->getvars['id_class_gradebook_entries'].' AND id_classes='.$assignmentObj->id_classes.' AND username=\''.$db->record['id_student'].'\') '; $db3->query($sql); $gradebook_val_obj = new ClassGradebookVal(); $gradebook_val_obj->set('username', $db->record['id_student']); $gradebook_val_obj->set('score', $db->record['grade']); $gradebook_val_obj->set('comments', $db->record['comments']); $gradebook_val_obj->set('idClasses', $db->record['id_classes']); $gradebook_val_obj->set('idClassGradebookEntries', $lc->getvars['id_class_gradebook_entries']); $gradebook_val_obj->save(); // I can't stop someone from entering these in multiple times right now //echo 'I am updating: '. $db->record['id_student']. '<br>'; } $this->run($db, $u, $lc, $t); return; } } else { $this->presentor = 'errorMessage'; $t['message'] = 'We are sorry to report that we could not locate the class this assignment belongs to, please try again!'; $t['details'] = 'You may not be the owner of this assignment or gradebook entry.'; return; } } /** * must push to class_gradebook_vals if there is a GBE associated with this */ function gradeStudentRun(&$db,&$u,&$lc,&$t) { $lc->getvars['id_class_assignments'] = (int)$lc->getvars['id_class_assignments']; $lc->getvars['student'] = trim($lc->getvars['student']); $lc->getvars['student'] = addslashes(stripslashes( $lc->getvars['student'])); $username = addslashes(stripslashes( $lc->getvars['student'])); $db->query('SELECT pkey from lcUsers where username="'.$lc->getvars['student'].'"'); $db->nextRecord(); $db->freeResult(); $studentId = $db->record['pkey']; $activityId = intval($lc->postvars['seqId']); $db->query('SELECT A.class_lesson_sequence_id FROM class_lesson_sequence A WHERE A.class_lesson_sequence_id = '.$activityId.' AND A.class_id = '.$u->activeClassTaught->id_classes); if (! $db->nextRecord() ) { $this->presentor = 'errorMessage'; $t['message'] = "You don't have permission to alter grades for this assignment"; $t['details'] = $lc->getvars['seqId'] . " is not an assignment ID that is owned by you or your current class."; return; } //__FIXME__ do one more security check on the student via 2 tables // not really usefull, someone wants to grade a student for a class that it's not in... // won't affect anything // this is a good query to find duplicates, just gotta make sure the student and assigment // belong to this current teacher! $sql = ' SELECT id_class_assignments_grades, grade, comments FROM class_assignments_grades WHERE (id_class_assignments='.$activityId.' AND id_student=\''.$username.'\') '; if ($lc->postvars['submit'] == 'Update') { //need to do explicit next record to get duplicate grades $db->query($sql); $db->nextRecord(); //this next block is in here for data cleanup, you can remove next semester // MAK 10-02-2003 if ( $db->getNumRows() > 1 ) { $db->query('DELETE FROM class_assignments_grades WHERE (id_class_assignments='.$activityId.' AND id_student=\''.$username.'\')'); $db->record['id_class_assignments_grades'] = 0; } if ((int)$db->record['id_class_assignments_grades'] > 0) { $sql = ' UPDATE class_assignments_grades SET grade='. number_format($lc->postvars['grade'], 2). ' , comments=\''. str_replace("'", '\'\'', stripslashes($lc->postvars['teachercomments'])). '\' WHERE id_class_assignments_grades='.$db->record['id_class_assignments_grades']; $db->query($sql); } else { $sql = ' INSERT INTO class_assignments_grades SET id_class_assignments='.(int)$lc->postvars['seqId'].', comments=\''. str_replace("'", '\'\'', stripslashes($lc->postvars['teachercomments'])). '\', grade='. number_format($lc->postvars['grade'], 2). ', id_student=\''.$username.'\' '; $db->query($sql); } //assignment_grades has been updated, let's find an associated GBE, if there is one we will push a new GBV $entryObj = ClassGradebookEntries::load( array('class_lesson_sequence_id'=>$activityId, 'id_classes'=>$u->activeClassTaught->id_classes) ); if ( is_object($entryObj) ) { $gbvObj = ClassGradebookVal::load( array('id_class_gradebook_entries'=>$entryObj->idClassGradebookEntries, 'student_id'=>$studentId) ); if (!is_object($gbvObj) ) { $gbvObj = new ClassGradebookVal(); $gbvObj->set('idClassGradebookEntries',$entryObj->idClassGradebookEntries); $gbvObj->set('idClasses',$u->activeClassTaught->id_classes); $gbvObj->set('studentId',$studentId); } $gbvObj->set('comments',$lc->postvars['teachercomments']); $gbvObj->set('score',$lc->postvars['grade']); $gbvObj->save(); } } $this->presentor = 'redirectPresentation'; $t['url'] = appurl('classmgr/assignmentManage/event=viewAssignment/id='.$activityId); return; } /** * Show a list of material in a datagrid * * Input data: * Output data: list of courses */ function run(&$db,&$u,&$lc,&$t) { $class_id = $u->activeClassTaught->id_classes; $datagrid = new DataGrid($this->module,$this->serviceName); $datagrid->sql = ' SELECT A.lob_title, C.title, A.lob_class_repo_id, B.class_lesson_sequence_id FROM class_lesson_sequence AS B LEFT JOIN lob_class_repo AS A ON A.lob_class_repo_id = B.lob_class_repo_id LEFT JOIN class_lessons AS C ON B.lesson_id = C.id_class_lessons WHERE A.class_id = '.$u->activeClassTaught->id_classes.' AND A.lob_type = "content" ORDER BY B.due_offset ASC'; $datagrid->countsql = ' SELECT count(*) as totalcount FROM class_lesson_sequence AS B LEFT JOIN lob_class_repo AS A ON A.lob_class_repo_id = B.lob_class_repo_id LEFT JOIN class_lessons AS C ON B.lesson_id = C.id_class_lessons WHERE A.class_id = '.$u->activeClassTaught->id_classes.' AND A.lob_type = "content"'; $datagrid->ignore = array('lob_class_repo_id', 'lob_guid', 'class_lesson_sequence_id'); $datagrid->headers = array( 'lob_title' => 'Content', 'title' => 'Lesson', 'links' => ' ' ); $datagrid->setCellWidth('links', '10%'); $datagrid->getRows(); $datagrid->class = 'datagrid'; //put all items with no due date at the end $datagrid->orderby = 'noDueDate ASC, dueDate'; if ( $lc->getvars['dgorder'] == 'title' ) { $datagrid->orderby = 'title'; } //show the one to many relationship of lessons in one column // using LessonRenderer // also, correct the checkbox selection state with a one to // many lookup /* $sql = "SELECT A.lob_class_repo_id, A.lesson_id, B.title FROM class_lesson_sequence AS A LEFT JOIN class_lessons AS B ON A.lesson_id = B.id_class_lessons WHERE B.id_classes = ".$class_id." ORDER BY B.title"; $db->query($sql); global $classmgr_itemsToTitles; $classmgr_itemsToTitles = array(); while ($db->nextRecord()) { $classmgr_itemsToTitles[$db->record['lob_class_repo_id']][] = $db->record['title']; } */ //collapse the double array into one string //Also, N'JECT data into the datagrid's internal memory so that it // becomes exposed to the internal column eval() statements foreach($classmgr_itemsToTitles as $k=>$v) { $classmgr_itemsToTitles[$k] = implode(" <br/>", $v); } // $datagrid->postpendCallbackColumn('DG_classmgr_injectLessonTitles', 'lesson_titles'); // $datagrid->postpendCallbackColumn('DG_classmgr_assignmentActions', 'links'); $t['table'] = $datagrid->toHTML(); $this->inactivelinks[] = 'List Activities'; $lc->templateName='assignmentManage_main'; } function viewAssignmentRun(&$db,&$u,&$lc,&$t) { include_once(LIB_PATH.'ClassGradebookEntries.php'); //load the assignment $classSeqId = intval($lc->getvars['id']); $classId = $u->activeClassTaught->id_classes; //get the lesson ID from the class_lesson_sequence object $seqItem = ClassLessonSequence::load( intval($lc->getvars['id']) ); $t['sequenceId'] = intval($lc->getvars['id']); $lessonId = $seqItem->lessonId; $lessonSequence = new LC_LessonSequence($lessonId,$classId); $lessonSequence->loadItems(); $lesson = new LC_Lesson($lessonId); $t['lessonTitle'] = $lesson->getTitle(); $activityLob = $lessonSequence->fetchObject($classSeqId); $t['startDate'] = $lessonSequence->getStartDate($lesson,$classSeqId); $t['dueDate'] = $lessonSequence->getDueDate($lesson,$classSeqId); $t['activity'] = $activityLob; // mgk 4/17/05 // per davidw/markk if (!facultyOnlyAuth($lc,$u)) { $lc->templateName = "assignmentManage_viewAssignment_observer"; return; } // load up a GBE to see if it has a gradebook entry, if not we need to instruct the teacher to // publish one last time, then it will save the relationship $entryObj = ClassGradebookEntries::load( array('class_lesson_sequence_id'=>$classSeqId) ); if ( is_object($entryObj) ) { $t['entryCode'] = $entryObj->gradebookCode; $t['entryLinked'] = true; } else { $t['entryCode'] = '<i>Not linked to a gradebook entry yet</i>'; $t['entryLinked'] = false; } // first view is listing all students in a particular assignment w/ assignment information to show $lc->templateName='assignmentManage_viewAssignment_one'; // give me a class list $sql = ' SELECT A.student_id, C.firstname, C.lastname, C.username FROM class_enrollment AS A INNER JOIN lcUsers AS B ON A.student_id = B.pkey INNER JOIN profile AS C ON B.username = C.username WHERE A.class_id='.$u->activeClassTaught->id_classes.' AND A.active=1 ORDER BY C.lastname ASC '; $db->query($sql); while ($db->nextRecord()) { $a_student_list[$db->record['student_id']] = $db->record; // $a_student_list[] = $db->record; } // I hate to do this but damn... This is soooooo inefficent.. but how often is something going to use this? foreach($a_student_list as $k=>$student) { // getting grade //don't need this, i added it to the join up above $sql = ' SELECT A.* FROM class_assignments_grades as A LEFT JOIN lcUsers AS B on B.username = A.id_student WHERE B.pkey=\''.$student['student_id'].'\' AND A.id_class_assignments='.$classSeqId.' '; $db->queryOne($sql); //*/ $a_student_list[$k]['grade'] = $db->record['grade']; $sql = 'SELECT COUNT(id_class_assignments) as completed, dateTurnin FROM class_assignments_turnin AS A LEFT JOIN lcUsers AS B on B.username = A.id_student WHERE id_class_assignments = '.$classSeqId.' AND B.pkey=\''.$student['student_id'].'\' GROUP BY id_class_assignments'; $db->queryOne($sql); $a_student_list[$k]['datecompleted'] = (($db->record['dateTurnin'] != null) ? date('F j Y g:i a',strtotime($db->record['dateTurnin'])) : ''); $a_student_list[$k]['completed'] = $db->record['completed']; ++$c; } $t['student_list'] = $a_student_list; //debug($t['student_list']); // get a class list and status applied to assignment // grab assign // connect assign to class // connect classs_section with classid (sectionNubmer=sectionNumber to class_section // then class_section.studentid to profile for names // get assignment text $db2 = DB::getHandle(); $db2->RESULT_TYPE = MYSQL_ASSOC; /* $sql = 'SELECT a.assign_text FROM class_assignments_turnin as a INNER JOIN class_assignments AS b ON a.id_class_assignments = b.id_class_assignments WHERE assign_type=0 AND b.id_classes='. $u->activeClassTaught->id_classes. ' AND a.id_class_assignments='. $lc->getvars['id_class_assignments'].' AND a.id_student=\''. $lc->getvars['student'].'\''; $db2->queryOne($sql); //debug($db2->record); $t['turnin'] = $db2->record; */ } function viewSubmitRun(&$db,&$u,&$lc,&$t) { include_once(LIB_PATH.'ClassGradebookEntries.php'); //load the assignment $classSeqId = intval($lc->getvars['id']); $classId = $u->activeClassTaught->id_classes; //get the lesson ID from the class_lesson_sequence object $seqItem = ClassLessonSequence::load( intval($lc->getvars['id']) ); $t['sequenceId'] = intval($lc->getvars['id']); $lessonId = $seqItem->lessonId; $lessonSequence = new LC_LessonSequence($lessonId,$classId); $lessonSequence->loadItems(); $lesson = new LC_Lesson($lessonId); $t['lessonTitle'] = $lesson->getTitle(); $activityLob = $lessonSequence->fetchObject($classSeqId); $t['startDate'] = $lessonSequence->getStartDate($lesson,$classSeqId); $t['dueDate'] = $lessonSequence->getDueDate($lesson,$classSeqId); $t['activity'] = $activityLob; // load up a GBE to see if it has a gradebook entry, if not we need to instruct the teacher to // publish one last time, then it will save the relationship $entryObj = ClassGradebookEntries::load( array('class_lesson_sequence_id'=>$classSeqId) ); if ( is_object($entryObj) ) { $t['entryCode'] = $entryObj->gradebookCode; $t['entryLinked'] = true; } else { $t['entryCode'] = '<i>Not linked to a gradebook entry yet</i>'; $t['entryLinked'] = false; } $lc->templateName = 'assignmentManage_viewSubmit'; $t['id_class_assignments'] = $lc->getvars['id_class_assignments']; $t['student'] = $lc->getvars['student']; // find student information (verification kinda thing, plus.. i need there info!) $sql = ' SELECT id_class_assignments_grades, grade, comments FROM class_assignments_grades WHERE (id_class_assignments='.(int)$lc->getvars['id_class_assignments'].' AND id_student=\''.$lc->getvars['student'].'\') '; $db->query($sql); $db->nextRecord(); //cleanup bad data, assume two duplicate records, combine highest score // with longest comment. Should fix the data problems that we have if ( $db->getNumRows() > 1){ $record1 = $db->record; $db->nextRecord(); $record2 = $db->record; if ( strlen($record1['coments']) > strlen($record2['comments']) ) { $db->record['comments'] = $record1['comments']; } else { $db->record['comments'] = $record2['comments']; } if ( $record1['grade'] > $record2['grade'] ) { $db->record['grade'] = $record1['grade']; } else { $db->record['grade'] = $record2['grade']; } } // original code before this data fixing patch $t['student_grade_info'] = $db->record; // get current attachments for this assignment for this student (FILES ONLY) $studentId = addslashes($lc->getvars['student']); $t['studentId'] = $studentId; $t['attachments'] = $this->getAssignmentsByType($t['activity']->lobSub->responseTypeId, $studentId, $u->activeClassTaught->id_classes, $t['sequenceId'] ); $t['audioFiles'] = $this->getAssignmentsByType(6, $studentId, $u->activeClassTaught->id_classes, $t['sequenceId'] ); if (count($t['audioFiles']) > 0 ) { $t['hasAudio'] = true; $t['audioData'] = base64_encode(file_get_contents(CONTENT_PATH.'uploads/'.$audioFiles[0]['assign_file_name'])); } } function getFileRun($db,&$u,&$lc,&$t) { $sql = ' SELECT class_assignments_turnin.id_class_assignments_turnin, class_assignments_turnin.assign_file_name, class_assignments_turnin.assign_file_size, class_assignments_turnin.assign_file_mime, class_assignments_turnin.dateTurnin, class_assignments_turnin.assign_file_blob FROM class_assignments_turnin INNER JOIN class_lesson_sequence AS B ON class_assignments_turnin.id_class_assignments=B.class_lesson_sequence_id WHERE 1=1 AND class_assignments_turnin.id_class_assignments_turnin='.(int)$lc->getvars['turnin'].' AND id_student=\''. $lc->getvars['student'].'\' AND (assign_type=1 OR assign_type=6) AND B.class_id='. $u->activeClassTaught->id_classes. ' AND class_assignments_turnin.id_class_assignments='. $lc->getvars['id'].' '; $db->RESULT_TYPE = MYSQL_ASSOC; $db->queryOne($sql); ob_end_clean(); header("Cache-control: private"); header("Content-type: ".trim($db->record['assign_file_mime'])); header("Content-Disposition: attachment; filename=".trim($lc->getvars['student'].'_'.$u->activeClassTaught->courseFamilyNumber.'_'.$db->record['assign_file_name'])); $data = $db->record['assign_file_blob']; /* if ( strlen($db->record['assign_file_blob']) > 80) { $data = base64_decode($db->record['assign_file_blob']); } else { $data = implode("",file(CONTENT_PATH."/uploads/".$db->record['assign_file_blob'])); } */ header("Content-length: ".strlen($data)); echo $data; exit(); } function getAssignmentsByType($typeId,$username,$classId,$assignmentId) { $db = DB::getHandle(); $sql = ' SELECT class_assignments_turnin.id_class_assignments_turnin, class_assignments_turnin.assign_file_name, class_assignments_turnin.assign_file_size, class_assignments_turnin.assign_file_mime, class_assignments_turnin.dateTurnin FROM class_assignments_turnin INNER JOIN class_lesson_sequence AS B ON class_assignments_turnin.id_class_assignments=B.class_lesson_sequence_id WHERE id_student=\''. $username.'\' AND assign_type='.$typeId.' AND B.class_id='. $classId. ' AND class_assignments_turnin.id_class_assignments='. $assignmentId.' '; $db->RESULT_TYPE = MYSQL_ASSOC; $db->query($sql); $ret = array(); while ($db->nextRecord()) { $ret[] = $db->record; } return $ret; } } /** * works with datagrid to generate data for column 'Lesson Titles' */ /* function DG_classmgr_injectLessonTitles($row, &$ret) { global $classmgr_itemsToTitles; $ret = $classmgr_itemsToTitles[$row['lob_class_repo_id']]; } */ /** * works with datagrid to generate data for column action links */ function DG_classmgr_assignmentActions($row, &$ret) { $ret = ' <ul style="margin:0px;padding-left:15px"> <li><a href="'.appurl("classmgr/assignmentManage/event=viewAssignment/id=".$row['class_lesson_sequence_id']."/").'">Grade</a></li> <li><a href="'.appurl("classmgr/assignmentManage/event=deleteAssignment/id=".$row['id_class_assignments']."/").'" onclick="if (confirm(\'Are you SURE you want to delete this assignment?\')) { return true; } else { return false; }">Delete</a></li> </ul>'; } ?> |