/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new DeliveryDate();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['DeliveryDate'])) {
         $model->attributes = $_POST['DeliveryDate'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 2
0
 /**
  * Generate new delivery dates and boxes for each date
  */
 public function actionCreateFutureDeliveryDatesAndBoxes()
 {
     $weeksInAdvance = SnapUtil::config('boxomatic/autoCreateDeliveryDates');
     $latestDate = DeliveryDate::getLastEnteredDate();
     if ($latestDate) {
         $latestDate = strtotime($latestDate->date);
     } else {
         $latestDate = time();
     }
     $targetDate = strtotime('+' . $weeksInAdvance . ' weeks');
     $BoxSizes = BoxSize::model()->findAll();
     while ($latestDate <= $targetDate) {
         //			$dateStr = date('j-n-Y',$latestDate);
         //			$parts = explode('-',$dateStr);
         //			mktime(0,0,0,$parts[1],$parts[0],$parts[2]);
         foreach (SnapUtil::config('boxomatic/deliveryDateLocations') as $day => $locationIds) {
             if (!empty($locationIds)) {
                 $latestDate = strtotime('next ' . $day, $latestDate);
                 //var_dump(date('l, d-m-Y',$latestDate));
                 //$latestDateStr=date('Y-m-d',$latestDate);
                 //$latestDate=strtotime($latestDateStr . ' +1 week');
                 $newDateStr = date('Y-m-d', $latestDate);
                 $DeliveryDate = new DeliveryDate();
                 $DeliveryDate->date = $newDateStr;
                 $DeliveryDate->Locations = $locationIds;
                 $DeliveryDate->save();
                 foreach ($BoxSizes as $BoxSize) {
                     $Box = new Box();
                     $Box->size_id = $BoxSize->id;
                     $Box->box_price = $BoxSize->box_size_price;
                     $Box->delivery_date_id = $DeliveryDate->id;
                     $Box->save();
                 }
                 echo '<p>Created new delivery_date: ' . $DeliveryDate->date . '</p>';
             }
         }
     }
     echo '<p><strong>Finished.</strong></p>';
     Yii::app()->end();
 }