Skip to content

Commit

Permalink
Fix Date bug on create
Browse files Browse the repository at this point in the history
Some Beauty code fixes
Fix Date bug on create
  • Loading branch information
Dennis Reilard committed Jul 24, 2020
1 parent 3972086 commit 2dcc6e4
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 35 deletions.
16 changes: 13 additions & 3 deletions config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' => '',
Expand Down Expand Up @@ -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` (
Expand Down Expand Up @@ -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.';
}
Expand Down
24 changes: 14 additions & 10 deletions controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)))."<br><br>"));
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']);
Expand All @@ -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);
Expand All @@ -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()
Expand All @@ -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();
Expand All @@ -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);

Expand All @@ -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']);
}
}
Expand Down
30 changes: 18 additions & 12 deletions controllers/admin/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function init()
} else {
$items[0]['active'] = true;
}
}else{
} else {
$items[1]['active'] = true;
}

Expand Down Expand Up @@ -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) {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
}
Expand All @@ -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'));
Expand All @@ -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']:[])));
}
}
Expand Down Expand Up @@ -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'));
Expand All @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions controllers/admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -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', '');
Expand Down
15 changes: 7 additions & 8 deletions mappers/HoererChartsUserVotes.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand All @@ -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])
Expand All @@ -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');

Expand All @@ -222,20 +221,20 @@ 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);

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;
}
}
Expand All @@ -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
Expand Down

0 comments on commit 2dcc6e4

Please sign in to comment.