From 2dcc6e4e6e8bb4026a30a322d415f77f24f39a10 Mon Sep 17 00:00:00 2001 From: Dennis Reilard Date: Fri, 24 Jul 2020 17:35:30 +0200 Subject: [PATCH] Fix Date bug on create Some Beauty code fixes Fix Date bug on create --- config/config.php | 16 +++++++++++++--- controllers/Index.php | 24 ++++++++++++++---------- controllers/admin/Index.php | 30 ++++++++++++++++++------------ controllers/admin/Settings.php | 4 ++-- mappers/HoererChartsUserVotes.php | 15 +++++++-------- 5 files changed, 54 insertions(+), 35 deletions(-) diff --git a/config/config.php b/config/config.php index 26deb55..4e3e795 100644 --- a/config/config.php +++ b/config/config.php @@ -10,7 +10,7 @@ class Config extends \Ilch\Config\Install { public $config = [ 'key' => 'radiohoerercharts', - 'version' => '1.4.3', + 'version' => '1.4.4', 'icon_small' => 'fa-list-ol', 'author' => 'Reilard, Dennis alias hhunderter ', 'link' => '', @@ -148,7 +148,8 @@ public function getUpdate($installedVersion) $this->db()->query('ALTER TABLE `[prefix]_radio_hoerercharts_uservotes` ADD COLUMN `last_activity` DATETIME NOT NULL AFTER `session_id`;'); $this->db()->query('ALTER TABLE `[prefix]_radio_hoerercharts` ADD COLUMN `setfree` TINYINT(1) NOT NULL DEFAULT \'1\' AFTER `id`;'); $this->db()->query('ALTER TABLE `[prefix]_radio_hoerercharts` ADD COLUMN `datecreate` DATETIME NOT NULL AFTER `votes`;'); - $datecreate = new \Ilch\Date(); + $date = new \Ilch\Date(); + $datecreate = new \Ilch\Date($date->format("Y-m-d H:i:s",true)); $this->db()->query('UPDATE `[prefix]_radio_hoerercharts` SET `datecreate` = "'.$datecreate.'"'); $this->db()->query('ALTER TABLE `[prefix]_radio_hoerercharts` ADD COLUMN `user_id` INT(11) NOT NULL AFTER `datecreate`;'); $this->db()->query('CREATE TABLE IF NOT EXISTS `[prefix]_radio_hoerercharts_suggestion` ( @@ -192,7 +193,16 @@ public function getUpdate($installedVersion) /* Some Beauty fixes */ - case "1.4.2": //update zu ? + case "1.4.3": //update zu 1.4.4 + /* + Some Beauty code fixes + Fix Date bug on create + */ + $date = new \Ilch\Date(); + $datecreate = new \Ilch\Date($date->format("Y-m-d H:i:s",true)); + $this->db()->query('UPDATE `[prefix]_radio_hoerercharts` SET `datecreate` = "'.$datecreate.'" WHERE `datecreate` = "0000-00-00 00:00:00"'); + case "1.4.4": //update zu ? + } return 'Update function executed.'; } diff --git a/controllers/Index.php b/controllers/Index.php index b0859c2..2ca3ecf 100644 --- a/controllers/Index.php +++ b/controllers/Index.php @@ -52,14 +52,14 @@ public function indexAction() $this->getView()->set('userMapper', $userMapper); $this->getView()->set('votedatetime', ((!$hoererchartsconfig['start_datetime'] and !$hoererchartsconfig['end_datetime'])?'':$this->getTranslator()->trans('votedatetime').(($hoererchartsconfig['start_datetime'] and $hoererchartsconfig['end_datetime'])?call_user_func_array([$this->getTranslator(), 'trans'], array('fromto', $hoererchartsconfig['start_datetime']->format($formatdatetime),$hoererchartsconfig['end_datetime']->format($formatdatetime))):(($hoererchartsconfig['start_datetime'])?$this->getTranslator()->trans('from').' '.$hoererchartsconfig['start_datetime']->format($formatdatetime):$this->getTranslator()->trans('to').' '.$hoererchartsconfig['end_datetime']->format($formatdatetime)))."

")); - if ($hoererchartsMapper->checkDB()){ + if ($hoererchartsMapper->checkDB()) { $vote_allowed = $hoererchartsMapper->vote_allowed($hoererchartsconfig['start_datetime'], $hoererchartsconfig['end_datetime']); $this->getView()->set('vote_allowed', $vote_allowed); - if ($hoererchartsuservotesMapper->is_voted($this->getUser(), $hoererchartsconfig['guestallow'], $hoererchartsconfig['allsecvote']) or !$vote_allowed){ + if ($hoererchartsuservotesMapper->is_voted($this->getUser(), $hoererchartsconfig['guestallow'], $hoererchartsconfig['allsecvote']) or !$vote_allowed) { $this->getView()->set('voted', true); $this->getView()->set('entries', $hoererchartsMapper->getEntriesBy(['setfree' => 1], ['votes' => 'DESC','id' => 'DESC'])); - }else{ + } else { if ($this->getRequest()->getPost('saveHoererCharts')) { $validation_indb = Validation::create($this->getRequest()->getPost(), ['hoerercharts-d' => 'required|unique:radio_hoerercharts,id']); $validation = Validation::create($this->getRequest()->getPost(), ['hoerercharts-d' => 'required|numeric']); @@ -69,13 +69,14 @@ public function indexAction() $voteId = $hoererchartsuservotesMapper->getEntryByUserSession($this->getUser()); - $datenow = new \Ilch\Date(); + $date = new \Ilch\Date(); + $datenow = new \Ilch\Date($date->format("Y-m-d H:i:s",true)); $model = new HoererChartsUserVotesModel(); if ($voteId) $model->setId($voteId); if ($this->getUser()) $model->setUser_Id($this->getUser()->getId()); $model->setSessionId(session_id()); - $model->setLast_Activity($datenow->format("Y-m-d H:i:s",true)); + $model->setLast_Activity($datenow); $hoererchartsuservotesMapper->save($model); setcookie('RadioHoererCharts_is_voted', session_id(), strtotime( '+1 days' ), '/', $_SERVER['SERVER_NAME'], (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off'), true); @@ -84,7 +85,7 @@ public function indexAction() ->withMessage('saveSuccess') ->to(['action' => 'index']); } - if ($validation->isValid() and $validation_indb->isValid()){ + if ($validation->isValid() and $validation_indb->isValid()) { $validation->getErrorBag()->addError('hoerercharts-d','Manipulation'); } $this->redirect() @@ -105,7 +106,7 @@ public function treatAction() 'allowsuggestion'=>$this->getConfig()->get('radio_hoerercharts_allow_suggestion') ); - if ($hoererchartsconfig['allowsuggestion'] and ((!$this->getUser() and $hoererchartsconfig['guestallow']) or $this->getUser())){ + if ($hoererchartsconfig['allowsuggestion'] and ((!$this->getUser() and $hoererchartsconfig['guestallow']) or $this->getUser())) { $hoererchartssuggestionMapper = new HoererChartsSuggestionMapper(); $captchaNeeded = captchaNeeded(); @@ -128,12 +129,15 @@ public function treatAction() if ($validation->isValid()) { $hoererchartsModel = new HoererChartsModel(); + $date = new \Ilch\Date(); + $datenow = new \Ilch\Date($date->format("Y-m-d H:i:s",true)); if ($this->getUser()) $hoererchartsModel->setUser_Id($this->getUser()->getId()); $hoererchartsModel->setInterpret($this->getRequest()->getPost('interpret')) ->setSongTitel($this->getRequest()->getPost('songtitel')) - ->setVotes(0); + ->setVotes(0) + ->setDateCreate($datenow); $hoererchartssuggestionMapper->save($hoererchartsModel); @@ -147,10 +151,10 @@ public function treatAction() ->withErrors($validation->getErrorBag()) ->to(['action' => 'treat']); } - }else{ + } else { $this->redirect(['action' => 'index']); } - }else{ + } else { $this->redirect(['action' => 'index']); } } diff --git a/controllers/admin/Index.php b/controllers/admin/Index.php index c8ba0d2..0a63afb 100644 --- a/controllers/admin/Index.php +++ b/controllers/admin/Index.php @@ -50,7 +50,7 @@ public function init() } else { $items[0]['active'] = true; } - }else{ + } else { $items[1]['active'] = true; } @@ -91,7 +91,7 @@ public function indexAction() $this->getView()->set('suggestion', $this->getRequest()->getParam('suggestion')); $this->getView()->set('votedatetime', $this->getTranslator()->trans('votedatetime').((!$hoererchartsconfig['start_datetime'] and !$hoererchartsconfig['end_datetime'])?$this->getTranslator()->trans('notset'):(($hoererchartsconfig['start_datetime'] and $hoererchartsconfig['end_datetime'])?call_user_func_array([$this->getTranslator(), 'trans'], array('fromto', $hoererchartsconfig['start_datetime']->format($formatdatetime),$hoererchartsconfig['end_datetime']->format($formatdatetime))):(($hoererchartsconfig['start_datetime'])?$this->getTranslator()->trans('from').' '.$hoererchartsconfig['start_datetime']->format($formatdatetime):$this->getTranslator()->trans('to').' '.$hoererchartsconfig['end_datetime']->format($formatdatetime)))."")); - if ($hoererchartsMapper->checkDB()){ + if ($hoererchartsMapper->checkDB()) { if ($this->getRequest()->getPost('check_entries')) { if ($this->getRequest()->getPost('action') == 'delete') { foreach ($this->getRequest()->getPost('check_entries') as $entryId) { @@ -100,7 +100,7 @@ public function indexAction() } $this->addMessage('deleteSuccess'); $this->redirect(['action' => 'index']); - }elseif ($this->getRequest()->getPost('action') == 'setfree'){ + } elseif ($this->getRequest()->getPost('action') == 'setfree') { foreach ($this->getRequest()->getPost('check_entries') as $entryId) { $hoererchartsModel = $hoererchartssuggestionMapper->getEntryById($entryId); $hoererchartssuggestionMapper->delete($entryId); @@ -138,15 +138,17 @@ public function treatAction() $hoererchartsMapper = new HoererChartsMapper(); $hoererchartssuggestionMapper = new HoererChartsSuggestionMapper(); - if ($hoererchartsMapper->checkDB()){ + if ($hoererchartsMapper->checkDB()) { if ($this->getRequest()->getParam('id')) { $this->getLayout()->getAdminHmenu() ->add($this->getTranslator()->trans('hoerercharts'), ['action' => 'index']) ->add($this->getTranslator()->trans('manage'), ['action' => 'index']) ->add($this->getTranslator()->trans('edit'), ['action' => 'treat']); - if ($this->getRequest()->getParam('suggestion')) $this->getView()->set('entrie', $hoererchartssuggestionMapper->getEntryById($this->getRequest()->getParam('id'))); - else{ + if ($this->getRequest()->getParam('suggestion')) { + $hoererchartsModel = new HoererChartsModel(); + $this->getView()->set('entrie', $hoererchartssuggestionMapper->getEntryById($this->getRequest()->getParam('id'))); + } else { $hoererchartsModel = $hoererchartsMapper->getEntryById($this->getRequest()->getParam('id')); $this->getView()->set('entrie', $hoererchartsModel); } @@ -166,10 +168,14 @@ public function treatAction() ],(($this->getRequest()->getParam('suggestion'))?[]:['setfree' => 'required|numeric|min:0|max:1']))); if ($validation->isValid()) { + $date = new \Ilch\Date(); + $datenow = new \Ilch\Date($date->format("Y-m-d H:i:s",true)); + if ($this->getRequest()->getParam('id')) { $hoererchartsModel->setId($this->getRequest()->getParam('id')); - }else{ + } else { if ($this->getUser()) $hoererchartsModel->setUser_Id($this->getUser()->getId()); + $hoererchartsModel->setDateCreate($datenow); } if (!$this->getRequest()->getParam('suggestion')) $hoererchartsModel->setSetFree($this->getRequest()->getPost('setfree')); @@ -182,15 +188,15 @@ public function treatAction() $this->redirect() ->withMessage('saveSuccess') - ->to(['action' => 'index']); + ->to(array_merge(['action' => 'index'],(($this->getRequest()->getParam('suggestion'))?['suggestion' => 'true']:[]))); } $this->addMessage($validation->getErrorBag()->getErrorMessages(), 'danger', true); $this->redirect() ->withInput() ->withErrors($validation->getErrorBag()) - ->to(['action' => 'treat', 'id' => $this->getRequest()->getParam('id')]); + ->to(array_merge(['action' => 'treat', 'id' => $this->getRequest()->getParam('id')],(($this->getRequest()->getParam('suggestion'))?['suggestion' => 'true']:[]))); } - }else{ + } else { $this->redirect(array_merge(['action' => 'index'],(($this->getRequest()->getParam('suggestion'))?['suggestion' => 'true']:[]))); } } @@ -227,7 +233,7 @@ public function suggestionenableAction() { $hoererchartsMapper = new HoererChartsMapper(); $hoererchartssuggestionMapper = new HoererChartsSuggestionMapper(); - if ($hoererchartsMapper->checkDB()){ + if ($hoererchartsMapper->checkDB()) { if ($this->getRequest()->isSecure()) { $hoererchartsModel = $hoererchartssuggestionMapper->getEntryById($this->getRequest()->getParam('id')); $hoererchartssuggestionMapper->delete($this->getRequest()->getParam('id')); @@ -246,7 +252,7 @@ public function resetAction() $hoererchartsMapper = new HoererChartsMapper(); $hoererchartsuservotesMapper = new HoererChartsUserVotesMapper(); - if ($hoererchartsMapper->checkDB()){ + if ($hoererchartsMapper->checkDB()) { if ($this->getRequest()->isSecure()) { $hoererchartsMapper->reset(); $hoererchartsuservotesMapper->reset(); diff --git a/controllers/admin/Settings.php b/controllers/admin/Settings.php index 521e1a2..ec6d78e 100644 --- a/controllers/admin/Settings.php +++ b/controllers/admin/Settings.php @@ -49,7 +49,7 @@ public function indexAction() ->add($this->getTranslator()->trans('hoerercharts'), ['controller' => 'index', 'action' => 'index']) ->add($this->getTranslator()->trans('settings'), ['action' => 'index']); - if ($hoererchartsMapper->checkDB()){ + if ($hoererchartsMapper->checkDB()) { if ($this->getRequest()->isPost()) { $validation = Validation::create($this->getRequest()->getPost(), [ 'Program_Name' => 'required', @@ -107,7 +107,7 @@ public function votedatetimeAction() ->add($this->getTranslator()->trans('hoerercharts'), ['controller' => 'index', 'action' => 'index']) ->add($this->getTranslator()->trans('settings'), ['action' => 'votedatetime']); - if ($hoererchartsMapper->checkDB()){ + if ($hoererchartsMapper->checkDB()) { if ($this->getRequest()->isPost()) { if (trim($this->getRequest()->getPost('start_datetime'))) $this->getConfig()->set('radio_hoerercharts_Start_Datetime', new \Ilch\Date($this->getRequest()->getPost('start_datetime'))); else $this->getConfig()->set('radio_hoerercharts_Start_Datetime', ''); diff --git a/mappers/HoererChartsUserVotes.php b/mappers/HoererChartsUserVotes.php index 25a265a..b343cb1 100644 --- a/mappers/HoererChartsUserVotes.php +++ b/mappers/HoererChartsUserVotes.php @@ -179,9 +179,9 @@ public function getEntryByUserSession($User = null) if ($User) $User_Id = $User->getId(); $oldsession = session_id(); - if (isset($_COOKIE['RadioHoererCharts_is_voted'])){ + if (isset($_COOKIE['RadioHoererCharts_is_voted'])) { $oldsession = $_COOKIE['RadioHoererCharts_is_voted']; - if ($oldsession != session_id()){ + if ($oldsession != session_id()) { setcookie('RadioHoererCharts_is_voted', session_id(), strtotime( '+1 days' ), '/', $_SERVER['SERVER_NAME'], (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off'), true); } } @@ -191,7 +191,7 @@ public function getEntryByUserSession($User = null) ->Where(['session_id' => $oldsession]) ->execute() ->fetchCell(); - if (!$voteId and $User_Id > 0){ + if (!$voteId and $User_Id > 0) { $voteId = (int) $this->db()->select('id') ->from('radio_hoerercharts_uservotes') ->Where(['user_id >' => 0, 'user_id' => $User_Id]) @@ -213,7 +213,6 @@ public function getEntryByUserSession($User = null) public function is_voted($User = null, $guestallow = false, $timediff = 30) { $date = new \Ilch\Date(); - $datenow = new \Ilch\Date($date->format("Y-m-d H:i:s",true)); //$datenow->modify('+1 hours'); @@ -222,7 +221,7 @@ public function is_voted($User = null, $guestallow = false, $timediff = 30) $voteId = $this->getEntryByUserSession($User); - if ($voteId > 0){ + if ($voteId > 0) { $returnvalue = true; $entryModel = $this->getEntryById($voteId); @@ -230,12 +229,12 @@ public function is_voted($User = null, $guestallow = false, $timediff = 30) if (!empty($entryModel->getLast_Activity())) $dateentry = new \Ilch\Date($entryModel->getLast_Activity()); else $dateentry = clone $datenow; - if ($timediff > 0){ + if ($timediff > 0) { $dateentryclone = clone $dateentry; $dateentryclone->modify('+'.$timediff.' seconds'); - if ($dateentryclone->getTimestamp() < $datenow->getTimestamp()){ + if ($dateentryclone->getTimestamp() < $datenow->getTimestamp()) { $returnvalue = false; } } @@ -245,7 +244,7 @@ public function is_voted($User = null, $guestallow = false, $timediff = 30) $entryModel->setSessionId(session_id()); $this->save($entryModel); return $returnvalue; - }else{ + } else { if (!$User_Id and !$guestallow) return true; else