Exemplo n.º 1
0
 public function createHoliday()
 {
     $holiday = new Holiday();
     $holiday->name = Input::get('name');
     $holiday->date = Input::get('date');
     $holiday->save();
     return Redirect::back()->with('message', array('type' => 'success', 'text' => 'Created Holiday!'));
 }
Exemplo n.º 2
0
 public static function createHoliday($data)
 {
     $organization = Organization::getUserOrganization();
     $holiday = new Holiday();
     $holiday->name = array_get($data, 'name');
     $holiday->date = array_get($data, 'date');
     $holiday->organization()->associate($organization);
     $holiday->save();
 }
Exemplo n.º 3
0
 /**
  * Add and Update Holiday
  * @param Holiday $holiday
  * @return boolean
  */
 public function saveHoliday(Holiday $holiday)
 {
     try {
         $holiday->save();
         return $holiday;
     } catch (Exception $e) {
         throw new DaoException($e->getMessage());
     }
 }
Exemplo n.º 4
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make($data = Input::all(), Holiday::$rules);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $holidays = new Holiday();
     $holidays->holidays_name = Input::get('holidays_name');
     $holidays->holidays_date = Input::get('holidays_date');
     $holidays->save();
     return Redirect::route('holidays.index');
 }
Exemplo n.º 5
0
 /**
  * Implementation for 'POST' method for Rest API
  *
  * @param  mixed $hldUid Primary key
  *
  * @return array $result Returns array within multiple records or a single record depending if
  *                       a single selection was requested passing id(s) as param
  */
 protected function post($hldUid, $hldDate, $hldDescription)
 {
     try {
         $result = array();
         $obj = new Holiday();
         $obj->setHldUid($hldUid);
         $obj->setHldDate($hldDate);
         $obj->setHldDescription($hldDescription);
         $obj->save();
     } catch (Exception $e) {
         throw new RestException(412, $e->getMessage());
     }
 }
Exemplo n.º 6
0
 public function actionCreate()
 {
     $model = new Holiday('insert');
     $semester = Semesters::model()->actual();
     if (Yii::app()->request->isPostRequest) {
         $holiday = Yii::app()->request->getParam('Holiday');
         $model->setAttributes($holiday);
         if ($model->save()) {
             Yii::app()->user->setFlash('success', 'Выходной успешно создан');
             $this->redirect(['index']);
         }
     }
     $this->render('form', ['model' => $model, 'semester' => $semester]);
 }
Exemplo n.º 7
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Holiday();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Holiday'])) {
         $model->attributes = $_POST['Holiday'];
         if ($model->save()) {
             $this->addCronJob($model->start_date_timestamp);
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Exemplo n.º 8
0
 /**
  * Performs the work of inserting or updating the row in the database.
  *
  * If the object is new, it inserts it; otherwise an update is performed.
  * All related objects are also updated in this method.
  *
  * @param PropelPDO $con
  * @return int             The number of rows affected by this insert/update and any referring fk objects' save() operations.
  * @throws PropelException
  * @see        save()
  */
 protected function doSave(PropelPDO $con)
 {
     $affectedRows = 0;
     // initialize var to track total num of affected rows
     if (!$this->alreadyInSave) {
         $this->alreadyInSave = true;
         // We call the save method on the following object(s) if they
         // were passed to this object by their coresponding set
         // method.  This object relates to these object(s) by a
         // foreign key reference.
         if ($this->aDomain !== null) {
             if ($this->aDomain->isModified() || $this->aDomain->isNew()) {
                 $affectedRows += $this->aDomain->save($con);
             }
             $this->setDomain($this->aDomain);
         }
         if ($this->aHoliday !== null) {
             if ($this->aHoliday->isModified() || $this->aHoliday->isNew()) {
                 $affectedRows += $this->aHoliday->save($con);
             }
             $this->setHoliday($this->aHoliday);
         }
         if ($this->isNew() || $this->isModified()) {
             // persist changes
             if ($this->isNew()) {
                 $this->doInsert($con);
             } else {
                 $this->doUpdate($con);
             }
             $affectedRows += 1;
             $this->resetModified();
         }
         $this->alreadyInSave = false;
     }
     return $affectedRows;
 }
Exemplo n.º 9
0
 /**
  * Generate the holidays from the holidays file for the given year and locale.
  * 
  * @param string $year
  * @param string $locale
  * @throws Exception 
  */
 public function generateHolidays($year, $locale = 'en')
 {
     $this->deleteHolidays($year, $locale);
     // Load the holidays file for the given $locale
     if (is_file(\GO::config()->root_path . 'language/holidays/' . $locale . '.php')) {
         require \GO::config()->root_path . 'language/holidays/' . $locale . '.php';
     }
     //		else
     //			throw new \Exception('No holidays file for this language: '.$locale.'.');
     if (empty($year)) {
         $year = date('Y');
     }
     $holidays = array();
     if (!empty($input_holidays)) {
         $holidays = $input_holidays;
     }
     // Set the fixed holidays from the holidays file
     if (isset($holidays['fix'])) {
         foreach ($holidays['fix'] as $key => $record) {
             if (is_string($record)) {
                 $month_day = explode("-", $key);
                 $date = mktime(0, 0, 0, $month_day[0], $month_day[1], $year);
                 $holiday = new Holiday();
                 $holiday->name = $record;
                 $holiday->date = date('Y-m-d', $date);
                 $holiday->region = $locale;
                 $holiday->save();
             } else {
                 if (is_array($record)) {
                     $month_day = explode("-", $key);
                     $date = mktime(0, 0, 0, $month_day[0], $month_day[1], $year);
                     $holiday = new Holiday();
                     $holiday->name = $record['name'];
                     $holiday->date = date('Y-m-d', $date);
                     $holiday->region = $locale;
                     $holiday->free_day = $record['free'];
                     $holiday->save();
                 }
             }
         }
     }
     // Set the variable holidays
     if (isset($holidays['var']) && function_exists('easter_date') && $year > 1969 && $year < 2037) {
         //			$easter_day = easter_date($year);
         $easterDT = \GO\Base\Util\Date\DateTime::getEasterDatetime($year);
         $easter_day = $easterDT->format('U');
         foreach ($holidays['var'] as $key => $record) {
             if (is_string($record)) {
                 $date = strtotime($key . " days", $easter_day);
                 $holiday = new Holiday();
                 $holiday->name = $record;
                 $holiday->date = date('Y-m-d', $date);
                 $holiday->region = $locale;
                 $holiday->save();
             } else {
                 if (is_array($record)) {
                     $date = strtotime($key . " days", $easter_day);
                     $holiday = new Holiday();
                     $holiday->name = $record['name'];
                     $holiday->date = date('Y-m-d', $date);
                     $holiday->region = $locale;
                     $holiday->free_day = $record['free'];
                     $holiday->save();
                 }
             }
         }
     }
     if (isset($holidays['spc'])) {
         $weekday = $this->get_weekday("24", "12", $year);
         foreach ($holidays['spc'] as $key => $name) {
             if (is_string($record)) {
                 $count = $key - $weekday;
                 $date = strtotime($count . " days", mktime(0, 0, 0, "12", "24", $year));
                 $holiday = new Holiday();
                 $holiday->name = $record;
                 $holiday->date = date('Y-m-d', $date);
                 $holiday->region = $locale;
                 $holiday->save();
             } else {
                 if (is_array($record)) {
                     $count = $key - $weekday;
                     $date = strtotime($count . " days", mktime(0, 0, 0, "12", "24", $year));
                     $holiday = new Holiday();
                     $holiday->name = $record['name'];
                     $holiday->date = date('Y-m-d', $date);
                     $holiday->region = $locale;
                     $holiday->free_day = $record['free'];
                     $holiday->save();
                 }
             }
         }
     }
     if (isset($holidays['fn'])) {
         foreach ($holidays['fn'] as $def) {
             $d = call_user_func($def[1], $year);
             if (!empty($d)) {
                 $holiday = new Holiday();
                 $holiday->name = $def[0];
                 $holiday->date = $d;
                 $holiday->region = $locale;
                 $holiday->save();
             }
         }
     }
 }
 public function add_holidays()
 {
     $this->autoRender = false;
     //debug($this->request->data);
     App::uses('Holiday', 'ScheduleManager.Model');
     $holidayModel = new Holiday();
     if ($this->request->is('post') || $this->request->is('put')) {
         $holidayModel->create();
         $data = $holidayModel->save($this->request->data);
         if ($data) {
             echo json_encode(array("Error" => "", $data));
         } else {
             echo json_encode(array("Error" => 'Error'));
         }
     }
 }