public function testCompareStartdateWithWeekday()
 {
     $att = array('consultant' => '1', 'paediatric' => '0', 'anaesthetist' => '0', 'general_anaesthetic' => '0', 'last_generate_date' => '1901-01-01 00:00:00', 'last_modified_user_id' => '1', 'last_modified_date' => '1901-01-01 00:00:00', 'created_user_id' => '1', 'created_date' => '1901-01-01 00:00:00', 'deleted' => 0, 'firm_id' => '', 'theatre_id' => '1', 'start_date' => '20 Mar 2014', 'end_date' => null, 'weekday' => '3', 'start_time' => '01:00', 'end_time' => '02:00', 'default_admission_time' => '', 'interval_id' => '2', 'week_selection' => null, 'id' => null);
     $this->operationSequence->attributes = $att;
     $this->operationSequence->save();
     $errors = $this->operationSequence->getErrors();
     $this->assertGreaterThan(0, count($errors));
     $this->assertTrue(array_key_exists('start_date', $errors));
     $this->assertGreaterThan(0, $errors['start_date']);
     $this->assertEquals($errors['start_date'][0], 'Start date and weekday must be on the same day of the week');
     $opSequence = new OphTrOperationbooking_Operation_Sequence();
     $att['start_date'] = '19 Mar 2014';
     $opSequence->attributes = $att;
     $opSequence->save();
     $errors = $opSequence->getErrors();
     $this->assertFalse(array_key_exists('start_date', $errors));
 }
 public function actionAddSequence()
 {
     $sequence = new OphTrOperationbooking_Operation_Sequence();
     $errors = array();
     if (!empty($_POST)) {
         $sequence->attributes = $_POST['OphTrOperationbooking_Operation_Sequence'];
         $weeks = 0;
         if ($_POST['OphTrOperationbooking_Operation_Sequence']['week_selection_week1']) {
             $weeks += 1;
         }
         if ($_POST['OphTrOperationbooking_Operation_Sequence']['week_selection_week2']) {
             $weeks += 2;
         }
         if ($_POST['OphTrOperationbooking_Operation_Sequence']['week_selection_week3']) {
             $weeks += 4;
         }
         if ($_POST['OphTrOperationbooking_Operation_Sequence']['week_selection_week4']) {
             $weeks += 8;
         }
         if ($_POST['OphTrOperationbooking_Operation_Sequence']['week_selection_week5']) {
             $weeks += 16;
         }
         $sequence->week_selection = $weeks;
         if (!$sequence->end_date) {
             $sequence->end_date = null;
         }
         if (!$sequence->week_selection) {
             $sequence->week_selection = null;
         }
         if (!$sequence->save()) {
             $errors = $sequence->getErrors();
         } else {
             if (empty($errors)) {
                 Audit::add('admin', 'create', $sequence->id, null, array('module' => 'OphTrOperationbooking', 'model' => 'OphTrOperationbooking_Operation_Sequence'));
                 $this->redirect(array('/OphTrOperationbooking/admin/viewSequences'));
             }
         }
     }
     $this->render('/admin/editsequence', array('sequence' => $sequence, 'errors' => $errors));
 }