Beispiel #1
0
 function exportFilePdf()
 {
     while (ob_get_level()) {
         ob_end_clean();
     }
     header("Content-Encoding: None", true);
     require JPATH_COMPONENT . DS . 'helpers' . DS . 'fpdf.php';
     include_once JPATH_COMPONENT . DS . 'helpers' . DS . 'font' . DS . 'helvetica.php';
     $quiz_id = intval(JRequest::getVar("id", ""));
     //create a FPDF object
     $pdf = new FPDF();
     //set font for the entire document
     $pdf->SetFont('Arial', 'B', 20);
     $pdf->SetTextColor(50, 60, 100);
     //set up a page
     $pdf->AddPage();
     $pdf->SetDisplayMode(real, 'default');
     $pdf->SetXY(10, 5);
     $pdf->SetFontSize(8);
     $db = JFactory::getDBO();
     $sql = "select name from #__guru_quiz where id=" . $quiz_id;
     $db->setQuery($sql);
     $name = $db->loadColumn();
     $name = $name["0"];
     $pdf->Write(5, 'Student Quiz Result for ' . "'" . $name . "'");
     $pdf->SetXY(10, 15);
     $pdf->SetFontSize(8);
     $pdf->Cell(20, 10, 'Times', 1, 0, 'C', 0);
     $pdf->Cell(20, 10, 'Students', 1, 0, 'C', 0);
     $pdf->Cell(20, 10, 'Avg Score', 1, 0, 'C', 0);
     //display the title with a border around it
     $res = guruAdminModelguruQuiz::NbOfTimesandStudents($quiz_id);
     $z = 25;
     $scoresByUserId = array();
     $maxNoOfTimes = 0;
     for ($i = 0; $i < count($res); $i++) {
         $newElem = new stdClass();
         $newElem->user_id = $res[$i]["user_id"];
         $newElem->scores = explode(",", $res[$i]["score_by_user"]);
         if (count($newElem->scores) > $maxNoOfTimes) {
             $maxNoOfTimes = count($newElem->scores);
         }
         array_push($scoresByUserId, $newElem);
     }
     $newvect = array();
     for ($i = 0; $i < $maxNoOfTimes; $i++) {
         $newElem = new stdClass();
         $newElem->noOfTimes = $i + 1;
         $newElem->noOfStudents = 0;
         $newElem->sumScores = 0;
         for ($j = 0; $j < count($scoresByUserId); $j++) {
             if (count($scoresByUserId[$j]->scores) >= $i + 1) {
                 $newElem->noOfStudents += 1;
                 $newElem->sumScores += $scoresByUserId[$j]->scores[$i];
             }
         }
         $newElem->avgScore = $newElem->sumScores / $newElem->noOfStudents;
         array_push($newvect, $newElem);
     }
     for ($i = 0; $i < count($newvect); $i++) {
         if ($i + 1 == 1) {
             $nboftimes = $i + 1 . "st";
         } elseif ($i + 1 == 2) {
             $nboftimes = $i + 1 . "nd";
         } elseif ($i + 1 == 3) {
             $nboftimes = $i + 1 . "rd";
         } elseif ($i + 1 > 3) {
             $nboftimes = $i + 1 . "th";
         }
         $studtot = $newvect[$i]->noOfStudents;
         $avg = intval($newvect[$i]->avgScore * 100);
         $pdf->SetXY(10, $z);
         $pdf->SetFontSize(7);
         $pdf->Cell(20, 10, $nboftimes, 1, 0, 'C', 0);
         $pdf->Cell(20, 10, $studtot, 1, 0, 'C', 0);
         $pdf->Cell(20, 10, $avg, 1, 0, 'C', 0);
         $z += 10;
     }
     $t = $z + 10;
     $pdf->SetXY(10, $t);
     $pdf->SetFontSize(7);
     $pdf->Cell(25, 10, 'First Name', 'LRTB', '', 'L', 0);
     $pdf->Cell(25, 10, 'Last Name', 'LRTB', '', 'L', 0);
     $pdf->Cell(39, 10, 'Email', 'LRTB', '', 'L', 0);
     $pdf->Cell(15, 10, '#', 'LRTB', '', 'L', 0);
     $pdf->Cell(20, 10, 'Username', 'LRTB', '', 'L', 0);
     $pdf->Cell(20, 10, 'Date Taken', 'LRTB', '', 'L', 0);
     $pdf->Cell(20, 10, 'Score', 'LRTB', '', 'L', 0);
     $pdf->Ln();
     //-----------------------------------------
     $pid = JRequest::getVar("pid", 0, 'post', 'int');
     $db = JFactory::getDBO();
     $sql = "select u.id, u.username, u.email, c.firstname, c.lastname, tq.date_taken_quiz, tq.score_quiz, tq.`id` as tq_id  from #__guru_customer c, #__users u, #__guru_quiz_taken tq where c.id=u.id and c.id = tq.user_id and u.id IN (select  user_id from #__guru_quiz_taken where quiz_id=" . $quiz_id . ") and tq.quiz_id=" . $quiz_id . " order by c.id desc";
     $db->setQuery($sql);
     $tmp = $db->loadObjectList();
     $new_id = 0;
     $nr = 1;
     for ($i = 0; $i < count($tmp); $i++) {
         $firstname = $tmp[$i]->firstname;
         $lastname = $tmp[$i]->lastname;
         $username = $tmp[$i]->username;
         $email = $tmp[$i]->email;
         $date = date("d/n/Y ", strtotime($tmp[$i]->date_taken_quiz));
         $score = $tmp[$i]->score_quiz;
         $score = explode("|", $score);
         $score = intval($score[0] / $score[1] * 100);
         if ($tmp[$i]->id == $new_id) {
             $nr = $nr + 1;
         } else {
             $nr = 1;
         }
         if ($nr == 1) {
             $nr = $nr . "st";
         } elseif ($nr == 2) {
             $nr = $nr . "nd";
         } elseif ($nr == 3) {
             $nr = $nr . "rd";
         } elseif ($nr > 3) {
             $nr = $nr . "td";
         }
         $pdf->SetFontSize(7);
         $pdf->Cell(25, 10, $firstname, 'LRTB', '', 'L', 0);
         $pdf->Cell(25, 10, $lastname, 'LRTB', '', 'L', 0);
         $pdf->Cell(39, 10, $email, 'LRTB', '', 'L', 0);
         $pdf->Cell(15, 10, $nr, 'LRTB', '', 'L', 0);
         $pdf->Cell(20, 10, $username, 'LRTB', '', 'L', 0);
         $pdf->Cell(20, 10, $date, 'LRTB', '', 'L', 0);
         $pdf->Cell(20, 10, $score, 'LRTB', '', 'L', 0);
         $pdf->Ln();
         $new_id = $tmp[$i]->id;
     }
     //Output the document
     $pdf->Output('Scores.pdf', 'I');
 }
Beispiel #2
0
            	<tr>
                	<td style="font-weight:bold;"><?php 
echo JText::_("GURU_TIMES_T");
?>
</td>
                    <td style="font-weight:bold;"><?php 
echo JText::_("GURU_COU_STUDENTS");
?>
</td>
                    <td style="font-weight:bold;"><?php 
echo JText::_("GURU_AVG_SCORE");
?>
</td>
                </tr>
                <?php 
$res = guruAdminModelguruQuiz::NbOfTimesandStudents($quiz_id);
$scoresByUserId = array();
$maxNoOfTimes = 0;
for ($i = 0; $i < count($res); $i++) {
    $newElem = new stdClass();
    $newElem->user_id = $res[$i]["user_id"];
    $newElem->scores = explode(",", $res[$i]["score_by_user"]);
    if (count($newElem->scores) > $maxNoOfTimes) {
        $maxNoOfTimes = count($newElem->scores);
    }
    array_push($scoresByUserId, $newElem);
}
$newvect = array();
for ($i = 0; $i < $maxNoOfTimes; $i++) {
    $newElem = new stdClass();
    $newElem->noOfTimes = $i + 1;
            	<tr>
                	<td style="font-weight:bold;"><?php 
echo JText::_("GURU_TIMES_T");
?>
</td>
                    <td style="font-weight:bold;"><?php 
echo JText::_("GURU_COU_STUDENTS");
?>
</td>
                    <td style="font-weight:bold;"><?php 
echo JText::_("GURU_AVG_SCORE");
?>
</td>
                </tr>
                <?php 
$res = $model_quizz->NbOfTimesandStudents($quiz_id);
$scoresByUserId = array();
$maxNoOfTimes = 0;
for ($i = 0; $i < count($res); $i++) {
    $newElem = new stdClass();
    $newElem->user_id = $res[$i]["user_id"];
    $newElem->scores = explode(",", $res[$i]["score_by_user"]);
    if (count($newElem->scores) > $maxNoOfTimes) {
        $maxNoOfTimes = count($newElem->scores);
    }
    array_push($scoresByUserId, $newElem);
}
$newvect = array();
for ($i = 0; $i < $maxNoOfTimes; $i++) {
    $newElem = new stdClass();
    $newElem->noOfTimes = $i + 1;