Esempio n. 1
0
 public function handleUpdateDate($firstName, $surName, $mail, $date, $type, $spz, $tel, $carMakes, $carModel, $additionalInfo)
 {
     if ($this->isAjax()) {
         $this->defaults = array('firstName' => $firstName, 'surName' => $surName, 'mail' => $mail, 'date' => $date, 'type' => $type, 'spz' => $spz, 'telNumber' => $tel, 'carMakes' => $carMakes, 'carModel' => $carModel, 'additionalInfo' => $additionalInfo);
         $day = date('N', strtotime(str_replace(' ', '', $date)));
         $multiplier = 0;
         switch ($type) {
             case 5:
                 $multiplier = 1;
                 break;
             case 6:
                 $multiplier = 3;
                 break;
             case 7:
                 $multiplier = 3;
                 break;
         }
         if ($day != 7) {
             $this->timeIntervals = $this->reservationManager->getIntervalsForDay(Nette\Utils\DateTime::createFromFormat('d. m. Y', $date), $multiplier);
         } else {
             $this->timeIntervals = array(Model\ExceptionMessages::NOT_DEFINED => 'Zavřeno');
         }
         $this->redrawControl('addReservationSnippet');
     }
 }
Esempio n. 2
0
 public function sinceDate($placeId, $date = null, $count = 7)
 {
     $files = array();
     $dir = dir($this->resolveDir($placeId));
     if ($dir === false) {
         return array();
     }
     while (false != ($entry = $dir->read())) {
         if (strrpos($entry, '.') != 10 || strrchr($entry, '.') != '.tmp') {
             continue;
         }
         // add filename without ext
         $files[] = strstr($entry, '.', true);
     }
     sort($files);
     $datePlain = is_int($date) ? date('Y-m-d', $date) : $date;
     $pos = 0;
     self::binarySearch($datePlain, $files, 'strcmp', $pos);
     $selection = array_slice($files, $pos, $count);
     $result = array();
     foreach ($selection as $item) {
         $itemDate = DateTime::createFromFormat('Y-m-d', $item)->getTimestamp();
         $result[$itemDate] = $this->forDate($placeId, $item);
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * Returns date
  *
  * @return mixed
  */
 public function getValue()
 {
     if (strlen($this->value) > 0) {
         return DateTime::createFromFormat($this->format, $this->value);
     }
     return $this->value;
 }
Esempio n. 4
0
 /**
  * @param array $data
  * @return Address
  */
 public static function createFromArray(array $data)
 {
     $data['first_seen'] = DateTime::createFromFormat(DateTime::ATOM, $data['first_seen']);
     $data['last_seen'] = DateTime::createFromFormat(DateTime::ATOM, $data['last_seen']);
     $address = new Address();
     $address->data = $data;
     return $address;
 }
Esempio n. 5
0
 /**
  * @param array $data
  * @return Block
  */
 public static function createFromArray(array $data)
 {
     $data['block_time'] = DateTime::createFromFormat(DateTime::ATOM, $data['block_time']);
     $data['arrival_time'] = DateTime::createFromFormat(DateTime::ATOM, $data['arrival_time']);
     $block = new Block();
     $block->data = $data;
     return $block;
 }
Esempio n. 6
0
 /**
  * @return DataGrid
  */
 public function create()
 {
     $grid = $this->gridFactory->create();
     $grid->addColumnText("id", "ID");
     $grid->addColumnText("name", "Name")->setFilterText();
     $grid->addColumnDateTime("date", "Date")->setFilterDate();
     $grid->setDataSource([["id" => 1, "name" => "Karel", "date" => DateTime::createFromFormat("d.m.Y", "10.10.2000")], ["id" => 2, "name" => "Pavel", "date" => new DateTime()]]);
     return $grid;
 }
Esempio n. 7
0
 /**
  * @param string $email
  * @param User|null $sender
  */
 public function __construct($email, User $sender = null)
 {
     $this->setEmail($email);
     $this->sender = $sender;
     $this->generateToken();
     $startDate = \Nette\Utils\DateTime::createFromFormat('!Y-m-d', date('Y-m-d'));
     $this->setValidity($startDate);
     $this->lastSending = $startDate;
 }
Esempio n. 8
0
 /**
  * Returns control's value.
  * @return string
  */
 public function getValue()
 {
     $value = parent::getValue();
     // convert to Nette\Utils\DateTime
     if ($value && is_string($value)) {
         $format = "d.m.Y";
         $value = DateTime::createFromFormat($format, $value);
     }
     return $value ? $value : NULL;
 }
 /**
  * Returns date
  *
  * @return mixed
  */
 public function getValue()
 {
     if (strlen($this->value) > 0) {
         $date = DateTime::createFromFormat($this->format, $this->value);
         if ($date === FALSE) {
             $this->addError($this->getValueErrorMessage());
             return FALSE;
         }
         return $date->setTime(0, 0, 0);
     }
     return $this->value;
 }
Esempio n. 10
0
 public function convertToPHPValue($value, AbstractPlatform $platform)
 {
     if ($value === NULL) {
         return NULL;
     } elseif ($value instanceof \DateTime) {
         return NetteDateTime::from($value);
     }
     $val = NetteDateTime::createFromFormat($platform->getDateTimeFormatString(), $value);
     if (!$val) {
         throw ConversionException::conversionFailedFormat($value, $this->getName(), $platform->getDateTimeFormatString());
     }
     return NetteDateTime::from($val);
 }
Esempio n. 11
0
 public function formSucceeded(RegistrationForm $form)
 {
     if ($form['remember']->getValue()) {
         $this->user->setExpiration('14 days', false);
     } else {
         $this->user->setExpiration('20 minutes', true);
     }
     $date = DateTime::createFromFormat('Y-m-d', date("Y-m-d"));
     try {
         $this->manager->add($form['username']->getValue(), $form['password']->getValue(), $form['email']->getValue(), $date);
         $this->user->login($form['username']->getValue(), $form['password']->getValue());
     } catch (Nette\Security\AuthenticationException $e) {
         $form->addError($e->getMessage());
     }
 }
 /**
  * @Todo Separate this method to some DateTime Utils class
  *
  * @param string $value
  * @param string $pattern
  * @return DateTime
  * @throws DateTimeParseException
  */
 private static function validateValue($value, $pattern)
 {
     $value = static::strip($value);
     if (($parsed = DateTime::createFromFormat($pattern, $value)) === FALSE) {
         throw new DateTimeParseException("Value does not match desired format: '{$pattern}'.");
     }
     $error = DateTime::getLastErrors();
     if ($error['error_count'] > 0 || $error['warning_count'] > 0) {
         throw new DateTimeParseException('Invalid date given. ' . 'Errors: ' . implode(', ', $error['errors']) . ' ' . 'Warnings: ' . implode(', ', $error['warnings']));
     }
     $strippedCrossCheckValue = static::strip($parsed->format($pattern));
     if ($value !== $strippedCrossCheckValue) {
         throw new DateTimeParseException("Invalid date given. Check value does not match original. ['{$strippedCrossCheckValue}' !== '{$value}']");
     }
     return $parsed;
 }
 /**
  * @secured
  */
 public function handleRemoveItem($day)
 {
     $this->checkDayValue($day);
     try {
         $this->itemFacade->removeListingItem($day, $this->listing);
         if ($this->presenter->isAjax()) {
             $item = new FillingItem(DateTime::createFromFormat('d.m.Y', $day . '.' . $this->listing->getMonth() . '.' . $this->listing->getYear()));
             $this['itemsTable']->refreshTable([$item]);
         } else {
             $this->flashMessage('Řádek byl vymazán.', 'success');
             $this->redirect('this');
         }
     } catch (ListingNotFoundException $lnf) {
         $this->flashMessage('Výčetka, kterou se snažíte upravit, nebyla nalezena.');
         $this->redirect('Listing:overview');
     }
 }
Esempio n. 14
0
 /**
  * @param array $data
  * @return Transaction
  */
 public static function createFromArray(array $data)
 {
     $transaction = new Transaction();
     foreach ($data['inputs'] as $key => $inputData) {
         $transaction->inputs[$key] = Input::createFromArray($inputData);
     }
     foreach ($data['outputs'] as $key => $outputData) {
         $transaction->outputs[$key] = Output::createFromArray($outputData);
     }
     unset($data['inputs']);
     unset($data['outputs']);
     $data['first_seen_at'] = DateTime::createFromFormat(DateTime::ATOM, $data['first_seen_at']);
     $data['last_seen_at'] = DateTime::createFromFormat(DateTime::ATOM, $data['last_seen_at']);
     $data['block_time'] = DateTime::createFromFormat(DateTime::ATOM, $data['block_time']);
     $transaction->data = $data;
     return $transaction;
 }
Esempio n. 15
0
 /**
  * @return DateTime|NULL
  */
 public function getValue()
 {
     if (!($value = $this->value)) {
         return NULL;
     }
     if ($value instanceof \DateTime || is_int($value)) {
         return DateTime::from($value);
     }
     try {
         return DateTime::createFromFormat($this->format, $this->value);
     } catch (\Exception $e) {
     }
     if ($time = strtotime($value)) {
         return DateTime::from($value);
     }
     return NULL;
 }
 /**
  * @return FALSE|mixed|Utils\DateTime|null
  */
 public function getValue()
 {
     $value = parent::getValue();
     if ($value instanceof Utils\DateTime) {
         return $value;
     } elseif (is_array($value)) {
         return $value;
     } else {
         if ($value === FALSE || $value === NULL) {
             return NULL;
         } else {
             $value = Utils\DateTime::createFromFormat($this->getDateTimeFormat(TRUE), $value);
             if ($value === FALSE) {
                 return NULL;
             }
         }
     }
     return $value;
 }
Esempio n. 17
0
 /**
  * @secured
  */
 public function handleRemoveItem($day)
 {
     $noDays = $this->listing->getNumberOfDaysInMonth();
     if (!is_numeric($day) or !($day >= 1 and $day <= $noDays)) {
         $this->redirect('this');
     }
     try {
         $this->itemFacade->removeListingItem($day, $this->listing);
         if ($this->presenter->isAjax()) {
             $this->listing = $this->listingFacade->getEntireListingByID($this->listing->listingID);
             $item = new FillingItem(DateTime::createFromFormat('d.m.Y', $day . '.' . $this->listing->month . '.' . $this->listing->year));
             $this->itemsCollection = [$item];
             $this['itemsTable']->redrawControl();
         } else {
             $this->flashMessage('Řádek byl vymazán.', 'success');
             $this->redirect('this');
         }
     } catch (ListingNotFoundException $lnf) {
         $this->flashMessage('Výčetka, kterou se snažíte upravit, nebyla nalezena.');
         $this->redirect('Listing:overview');
     }
 }
Esempio n. 18
0
 /**
  * Zpracovani formulare s clankem
  * @param Form $form
  * @param Nette\Utils\ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     //nastaveni datumu zverejneni
     if (empty($values->publishDate)) {
         $date = new DateTime();
     } else {
         $date = DateTime::createFromFormat('d. m. Y, H:i', $values->publishDate);
     }
     $values->offsetSet('publishDate', $date);
     //novy clanek nebo jeho editace
     $result = empty($values->id) ? $this->newArticle($values) : $this->editArticle($values);
     if ($result) {
         $form->getPresenter()->flashMessage($form->getTranslator()->translate('system.requestS'), 'success');
     } else {
         $form->getPresenter()->flashMessage($form->getTranslator()->translate('system.requestN'), 'danger');
     }
 }
Esempio n. 19
0
 public function formCalculatorSucceeded($form)
 {
     if ($form['submit']->isSubmittedBy()) {
         $date = DateTime::createFromFormat('Y-m-d', date("Y-m-d"))->format('Y-m-d');
         $currentCalculation = $this->calculationFacade->findByDate($date, $this->addressId);
         if ($currentCalculation == NULL) {
             $this->calculationFacade->update(array('date' => $date, 'address' => $this->addressFacade->find($this->addressId)));
             $currentCalculation = $this->calculationFacade->findByDate($date, $this->addressId);
         } else {
             $items = $this->calculationItemFacade->findCalculationItems($currentCalculation->getId());
             foreach ($items as $item) {
                 $this->calculationItemFacade->delete($item->getId());
             }
         }
         foreach ($this->tariffs as $item) {
             $this->calculationItemFacade->update(array('tariff' => $item['value'], 'previous' => $form['previous_' . array_search($item, $this->tariffs)]->getValue(), 'current' => $form['current_' . array_search($item, $this->tariffs)]->getValue(), 'calculation' => $currentCalculation, 'name' => $item['name']));
         }
     } else {
         if ($form['addCategory']->isSubmittedBy()) {
             foreach ($form['addCategory']->values as $newCategory) {
                 $this->tariffFacade->update(array('address' => $this->addressFacade->find($this->addressId), 'value' => (double) str_replace(',', '.', $newCategory['tariff']), 'name' => $newCategory['category']));
             }
         } else {
             if ($form['deleteAddress']->isSubmittedBy()) {
                 $this->addressFacade->delete($this->addressId);
                 throw new InvalidArgumentException('Address with id=' . $this->addressId . ' has been deleted');
             } else {
                 foreach (array_keys($this->tariffs) as $key) {
                     if ($form['delete_' . $key]->isSubmittedBy()) {
                         $this->tariffFacade->delete($key);
                     }
                 }
             }
         }
     }
 }
 /**
  * @param $value
  * @return FALSE|Utils\DateTime|null
  * @throws DatePickerException
  */
 private function _prepareValue($value)
 {
     if ($value instanceof Utils\DateTime) {
         //...
     } elseif ($value instanceof \DateTime) {
         $value = Utils\DateTime::createFromFormat($this->getDateTimeFormat(TRUE), $value->format($this->getDateTimeFormat(TRUE)));
     } elseif (is_string($value) && $value != '') {
         $value = Utils\DateTime::createFromFormat($this->getDateTimeFormat(TRUE), $value);
     } elseif (empty($value)) {
         $value = NULL;
     }
     if ($value === FALSE) {
         throw new DatePickerException('Not valid string!');
     }
     if ($value instanceof Utils\DateTime && $this->time == FALSE) {
         $value->setTime(0, 0, 0);
     }
     return $value;
 }
 /**
  * @param string $value
  * @param string $pattern
  * @return DateTime
  * @throws DateTimeParseException
  */
 protected function createFromFormat($value, $pattern)
 {
     $parsed = DateTime::createFromFormat($pattern, $value);
     $errors = DateTime::getLastErrors();
     if ($parsed === FALSE || $errors['error_count'] > 0 || $errors['warning_count'] > 0) {
         $message = sprintf('Invalid date given. Errors: [%s], Warnings: [%s]', implode(', ', $errors['errors']), implode(', ', $errors['warnings']));
         throw new DateTimeParseException(sprintf("Value does not match desired format: '%s'. Error message: '%s'", $pattern, $message));
     }
     return $parsed;
 }
Esempio n. 22
0
 /**
  * Zpracovani formulare s anketou
  * @param Form $form
  * @param Nette\Utils\ArrayHash $values
  */
 public function formSucceeded(Form $form, $values)
 {
     if (!empty($values->expiration)) {
         $expiration = DateTime::createFromFormat(self::$dateMask, $values->expiration);
         $values->expiration = $expiration;
     } else {
         $values->expiration = NULL;
     }
     if (empty($values->id)) {
         //novy
         $result = $this->newVote($values);
     } else {
         //editace
         $result = $this->editVote($values);
     }
     if ($result) {
         $form->getPresenter()->flashMessage($form->getTranslator()->translate('system.requestS'), 'success');
     } else {
         $form->getPresenter()->flashMessage($form->getTranslator()->translate('system.requestN'), 'danger');
     }
 }