コード例 #1
0
 public function testSubjectsCanBeRetrievedWhenReopeningTheRegistrationEvenThoughNoSubjectsWasSavedInitally()
 {
     $course1 = new VIH_Model_Course();
     $course1->navn = 'Course 1';
     $period1 = new VIH_Model_Course_Period();
     $period1->name = 'Period 1';
     $period1->Course = $course1;
     $period1->save();
     $group1 = new VIH_Model_Course_SubjectGroup();
     $group1->name = 'SubjectGroup 1';
     $group1->Period = $period1;
     $subject1 = new VIH_Model_Subject();
     $subject1->identifier = 'Subject 1';
     $subject2 = new VIH_Model_Subject();
     $subject2->identifier = 'Subject 2';
     $group1->Subjects[] = $subject1;
     $group1->Subjects[] = $subject2;
     $group1->save();
     $group1->Subjects[] = $subject1;
     $group1->Subjects[] = $subject2;
     $group1->save();
     $course1->SubjectGroups[] = $group1;
     $course1->save();
     // saved without Subjects
     try {
         $registrar = new VIH_Model_Course_Registration();
         $registrar->Course = $course1;
         // $registrar->Subjects; // if this is uncommented the test will pass
         $registrar->save();
     } catch (Doctrine_Record_Exception $e) {
         $this->fail($e->getMessage());
     }
     $reopend = Doctrine_Core::getTable('VIH_Model_Course_Registration')->findOneById($registrar->id);
     try {
         $reopend->Subjects[] = $subject1;
     } catch (Doctrine_Record_Exception $e) {
         $this->fail($e->getMessage());
     }
     $reopend->save();
     try {
         $subject = $reopend->Subjects[0];
         $this->assertTrue(is_object($subject));
         $this->assertEqual('VIH_Model_Subject', get_class($reopend->Subjects[0]));
     } catch (Doctrine_Record_Exception $e) {
         $this->fail($e->getMessage());
     }
 }
コード例 #2
0
ファイル: Create.php プロジェクト: vih/intranet.vih.dk
 function postForm()
 {
     if (!$this->validate()) {
         return $this->render();
     }
     $values = $this->body();
     $course = Doctrine::getTable('VIH_Model_Course')->findOneById($this->context->getLangtKursusId());
     $period = new VIH_Model_Course_Period();
     $period->Course = $course;
     $period->name = $values['name'];
     $period->description = $values['description'];
     $period->date_start = $values['date_start'];
     $period->date_end = $values['date_end'];
     try {
         $period->save();
     } catch (Exception $e) {
         throw $e;
     }
     return new k_SeeOther($this->context->url());
 }