Exemple #1
0
 /**
  * Retourne le module correspondant à l'exam donné.
  *
  * @param Exam $exam L'exam pour lequel on cherche le module.
  * @return Module
  */
 public static function findByExam($exam)
 {
     $examId = $exam->getId();
     $data = BaseSingleton::select('SELECT ' . 'module.id as id, module.bareme_id as bareme_id, ' . 'module.label as label, module.description as description, ' . 'module.date_creation as date_creation, module.number as number, ' . 'module.affiche as affiche, assignment.id as assignment_id, exam.id as exam_id ' . 'FROM module, exam, assignment ' . 'WHERE exam.module_id = module.id AND assignment.module_id = module.id ' . 'AND exam.id = ? ' . 'GROUP BY module.id', array('i', &$examId));
     $module = new Module();
     $module->hydrate($data[0]);
     return $module;
 }
 public function executeSubmitExam(sfWebRequest $request)
 {
     if ($request->isMethod(sfRequest::POST) && $request->hasParameter('security') && $request->hasParameter('year') && $request->hasParameter('descr')) {
         $files = $request->getFiles();
         $file = $files['file'];
         $descr = $request->getParameter('descr');
         if (isset($file) && strtoupper(substr($file['name'], -3, 3)) == 'PDF' && !helperFunctions::isMaliciousString($descr)) {
             if ($request->getParameter("security") != $_SESSION['securityImage']) {
                 echo "<input type='text' id='status' value='Security'/>";
                 exit;
             }
             $year = $request->getParameter("year") . $request->getParameter("term");
             // make directories if not exist
             if (!is_dir("exams/custom")) {
                 if (!mkdir("exams/custom")) {
                     echo "<input type='text' id='status' value='Moving'/>";
                     exit;
                 }
             }
             $tgt_path = "exams/custom/" . $year;
             if (!is_dir($tgt_path)) {
                 if (!mkdir($tgt_path)) {
                     echo "<input type='text' id='status' value='Moving'/>";
                     exit;
                 }
             }
             $fileName = time() . ".pdf";
             if (move_uploaded_file($file['tmp_name'], $tgt_path . "/" . $fileName)) {
                 // register in db
                 $conn = Propel::getConnection();
                 $exam = new Exam();
                 $exam->setCourseId($request->getParameter("course"));
                 $exam->setFilePath($tgt_path . "/" . $fileName);
                 $exam->setYear($year);
                 $exam->setType($request->getParameter("type"));
                 $exam->setDescr($descr);
                 $exam->save($conn);
                 // send notification email
                 $ip = $_SERVER['REMOTE_ADDR'];
                 $msg = "Submitted by " . $ip . " [id=" . $exam->getId() . "]";
                 helperFunctions::sendEmailNotice("Exam Submission", $msg);
                 echo "<input type='text' id='status' value='Success'/>";
             } else {
                 echo "<input type='text' id='status' value='Moving'/>";
             }
         } else {
             echo "<input type='text' id='status' value='PDF'/>";
         }
     }
     exit;
 }
 /**
  * Declares an association between this object and a Exam object.
  *
  * @param      Exam $v
  * @return     ExamComment The current object (for fluent API support)
  * @throws     PropelException
  */
 public function setExam(Exam $v = null)
 {
     if ($v === null) {
         $this->setExamId(NULL);
     } else {
         $this->setExamId($v->getId());
     }
     $this->aExam = $v;
     // Add binding for other direction of this n:n relationship.
     // If this object has already been added to the Exam object, it will not be re-added.
     if ($v !== null) {
         $v->addExamComment($this);
     }
     return $this;
 }
Exemple #4
0
 /**
  * Adds an object to the instance pool.
  *
  * Propel keeps cached copies of objects in an instance pool when they are retrieved
  * from the database.  In some cases -- especially when you override doSelect*()
  * methods in your stub classes -- you may need to explicitly add objects
  * to the cache in order to ensure that the same objects are always returned by doSelect*()
  * and retrieveByPK*() calls.
  *
  * @param      Exam $value A Exam object.
  * @param      string $key (optional) key to use for instance map (for performance boost if key was already calculated externally).
  */
 public static function addInstanceToPool(Exam $obj, $key = null)
 {
     if (Propel::isInstancePoolingEnabled()) {
         if ($key === null) {
             $key = (string) $obj->getId();
         }
         // if key === null
         self::$instances[$key] = $obj;
     }
 }
Exemple #5
0
 /**
  * Take the exam submission request and save it into database
  * @param sfWebRequest $request
  */
 public function executeSubmitExam(sfWebRequest $request)
 {
     //TODO: set up uniform display name for each exam/test uploaded so things don't get messy.
     //i.e. instead of letting the user choose the display name, we'll appropriate it
     //requested by David
     set_time_limit(0);
     if ($request->isMethod(sfRequest::POST) && $request->hasParameter('security') && $request->hasParameter('year') && $request->hasParameter('descr')) {
         $files = $request->getFiles();
         $file = $files['file'];
         $descr = $request->getParameter('descr');
         if (isset($file) && strtoupper(substr($file['name'], -3, 3)) == 'PDF' && !helperFunctions::isMaliciousString($descr)) {
             if ($request->getParameter("security") != $_SESSION['securityImage']) {
                 echo "<input type='text' id='status' value='Security'/>";
                 return sfView::NONE;
             }
             $year = $request->getParameter("year") . $request->getParameter("term");
             // make directories if not exist
             if (!is_dir("exams/custom")) {
                 if (!mkdir("exams/custom")) {
                     echo "<input type='text' id='status' value='Moving'/>";
                     return sfView::NONE;
                 }
             }
             $tgt_path = "exams/custom/" . $year;
             if (!is_dir($tgt_path)) {
                 if (!mkdir($tgt_path)) {
                     echo "<input type='text' id='status' value='Moving'/>";
                     return sfView::NONE;
                 }
             }
             // unique filename
             $courseId = $request->getParameter("course");
             $examType = $request->getParameter("type");
             $examTypeAbbr = HelperFunctions::getExamTypeAbbr($examType);
             $fileName = substr($courseId, 0, 6) . '_' . substr($year, 0, 4) . '_' . $examTypeAbbr . '_' . time() . ".pdf";
             if (move_uploaded_file($file['tmp_name'], $tgt_path . "/" . $fileName)) {
                 try {
                     // register in db
                     $conn = Propel::getConnection();
                     $exam = new Exam();
                     $exam->setCourseId($courseId);
                     $exam->setFilePath($tgt_path . "/" . $fileName);
                     $exam->setYear($year);
                     $exam->setType($examType);
                     $exam->setDescr($descr);
                     $exam->save($conn);
                     // send notification email
                     $ip = $_SERVER['REMOTE_ADDR'];
                     $msg = "A new exam on [title=" . $exam->getDescr() . "; course=" . $exam->getCourseId() . "; year=" . $exam->getYear() . "; id=" . $exam->getId() . "] has been submitted by " . $ip . " on " . date('Y-m-d H:i:s') . ".";
                     helperFunctions::sendEmailNotice("Exam Submission", $msg);
                     echo "<input type='text' id='status' value='Success'/>";
                 } catch (Exception $e) {
                     echo "<input type='text' id='status' value='Saving'/>";
                     // send error email
                     helperFunctions::sendEmailNotice("Exam Submission Error", $e->getMessage());
                 }
             } else {
                 echo "<input type='text' id='status' value='Moving'/>";
             }
         } else {
             echo "<input type='text' id='status' value='PDF'/>";
         }
         return sfView::NONE;
     } else {
         $this->forward404();
     }
 }