Skip to content

Commit

Permalink
bugfix of SQL-Statement is_voted + Some Beauty fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
hhunderter committed Jul 20, 2019
1 parent 1c2a080 commit 80222df
Show file tree
Hide file tree
Showing 14 changed files with 100 additions and 82 deletions.
9 changes: 7 additions & 2 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.1',
'version' => '1.4.2',
'icon_small' => 'fa-list-ol',
'author' => 'Reilard, Dennis alias hhunderter ',
'link' => '',
Expand Down Expand Up @@ -183,7 +183,12 @@ public function getUpdate($installedVersion)
/*
bugfix of SQL-Statement is_voted
*/
case "1.4.1": //update zu ?
case "1.4.1": //update zu 1.4.2
/*
bugfix of SQL-Statement is_voted
Some Beauty fixes
*/
case "1.4.2": //update zu ?
}
return 'Update function executed.';
}
Expand Down
28 changes: 15 additions & 13 deletions controllers/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ public function indexAction()

$this->getView()->set('regist_accept', $this->getConfig()->get('regist_accept'));
$this->getView()->set('hoererchartsMapper', $hoererchartsMapper);

$start_datetime = null;
if ($this->getConfig()->get('radio_hoerercharts_Start_Datetime')) $start_datetime = new \Ilch\Date($this->getConfig()->get('radio_hoerercharts_Start_Datetime'));
$end_datetime = null;
if ($this->getConfig()->get('radio_hoerercharts_End_Datetime')) $end_datetime = new \Ilch\Date($this->getConfig()->get('radio_hoerercharts_End_Datetime'));
$formatdatetime = 'd.m.Y H:i';

$hoererchartsconfig = array('allsecvote'=>$this->getConfig()->get('radio_hoerercharts_all_sec_vote'),
'guestallow'=>$this->getConfig()->get('radio_hoerercharts_Guest_Allow'),
'start_datetime'=>$start_datetime,
Expand All @@ -55,7 +55,7 @@ public function indexAction()
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){
$this->getView()->set('voted', true);
$this->getView()->set('entries', $hoererchartsMapper->getEntriesBy(['setfree' => 1], ['votes' => 'DESC','id' => 'DESC']));
Expand All @@ -68,16 +68,18 @@ public function indexAction()
$hoererchartsMapper->update($this->getRequest()->getPost('hoerercharts-d'), -1);

$voteId = $hoererchartsuservotesMapper->getEntryByUserSession($this->getUser());

$datenow = new \Ilch\Date();

$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));
$hoererchartsuservotesMapper->save($model);

setcookie('RadioHoererCharts_is_voted', session_id(), strtotime( '+1 days' ), '/', $_SERVER['SERVER_NAME'], (isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] != 'off'), true);

$this->redirect()
->withMessage('saveSuccess')
->to(['action' => 'index']);
Expand All @@ -92,7 +94,7 @@ public function indexAction()
}
$this->getView()->set('entries', $hoererchartsMapper->getEntries(['setfree' => 1]));
}

$this->getView()->set('gettext', (!empty($this->getRequest()->getParam('copy'))?$hoererchartsMapper->gettext():''));
}
}
Expand All @@ -102,9 +104,9 @@ public function treatAction()
$hoererchartsconfig = array('guestallow'=>$this->getConfig()->get('radio_hoerercharts_Guest_Allow'),
'allowsuggestion'=>$this->getConfig()->get('radio_hoerercharts_allow_suggestion')
);

if ($hoererchartsconfig['allowsuggestion'] and ((!$this->getUser() and $hoererchartsconfig['guestallow']) or $this->getUser())){

$hoererchartssuggestionMapper = new HoererChartsSuggestionMapper();
$captchaNeeded = captchaNeeded();

Expand All @@ -114,25 +116,25 @@ public function treatAction()
$this->getLayout()->getHmenu()
->add($this->getTranslator()->trans('hoerercharts'), ['action' => 'index'])
->add($this->getTranslator()->trans('add'), ['action' => 'treat']);

$this->getView()->set('captchaNeeded', $captchaNeeded);

if ($this->getRequest()->isPost()) {

$validation = Validation::create($this->getRequest()->getPost(), array_merge([
'interpret' => 'required',
'songtitel' => 'required'
],($captchaNeeded?['captcha' => 'captcha']:[])));

if ($validation->isValid()) {
$hoererchartsModel = new HoererChartsModel();

if ($this->getUser()) $hoererchartsModel->setUser_Id($this->getUser()->getId());

$hoererchartsModel->setInterpret($this->getRequest()->getPost('interpret'))
->setSongTitel($this->getRequest()->getPost('songtitel'))
->setVotes(0);

$hoererchartssuggestionMapper->save($hoererchartsModel);

$this->redirect()
Expand Down
26 changes: 13 additions & 13 deletions controllers/admin/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function init()
'url' => $this->getLayout()->getUrl(['controller' => 'settings', 'action' => 'index'])
]
];

if ($this->getRequest()->getActionName() != 'reset') {
$items[0][0] = [
'name' => 'add',
Expand Down Expand Up @@ -71,13 +71,13 @@ public function indexAction()
->add($this->getTranslator()->trans('manage'), ['action' => 'index']);

$this->getView()->set('hoererchartsMapper', $hoererchartsMapper);

$start_datetime = null;
if ($this->getConfig()->get('radio_hoerercharts_Start_Datetime')) $start_datetime = new \Ilch\Date($this->getConfig()->get('radio_hoerercharts_Start_Datetime'));
$end_datetime = null;
if ($this->getConfig()->get('radio_hoerercharts_End_Datetime')) $end_datetime = new \Ilch\Date($this->getConfig()->get('radio_hoerercharts_End_Datetime'));
$formatdatetime = 'd.m.Y H:i';

$hoererchartsconfig = array('start_datetime'=>$start_datetime,
'allowsuggestion'=>$this->getConfig()->get('radio_hoerercharts_allow_suggestion'),
'end_datetime'=>$end_datetime,
Expand All @@ -89,7 +89,7 @@ public function indexAction()
'Star5'=>$this->getConfig()->get('radio_hoerercharts_Star5'));
$this->getView()->set('config', $hoererchartsconfig);
$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 ($this->getRequest()->getPost('check_entries')) {
Expand All @@ -108,7 +108,7 @@ public function indexAction()
$hoererchartsModel->setSetFree(0);
$hoererchartsMapper->save($hoererchartsModel);
}

$this->addMessage('updateSuccess');
$this->redirect(['action' => 'index']);
}
Expand All @@ -120,7 +120,7 @@ public function indexAction()
$this->getView()->set('badgeSuggestion', count($suggestionentries));
}
}

public function updateAction()
{
if ($this->getRequest()->isSecure()) {
Expand All @@ -144,7 +144,7 @@ public function treatAction()
->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{
$hoererchartsModel = $hoererchartsMapper->getEntryById($this->getRequest()->getParam('id'));
Expand Down Expand Up @@ -176,7 +176,7 @@ public function treatAction()
$hoererchartsModel->setInterpret($this->getRequest()->getPost('interpret'))
->setSongTitel($this->getRequest()->getPost('songtitel'))
->setVotes(0);

if ($this->getRequest()->getParam('suggestion')) $hoererchartssuggestionMapper->save($hoererchartsModel);
else $hoererchartsMapper->save($hoererchartsModel);

Expand Down Expand Up @@ -209,17 +209,17 @@ public function delAction()
}
$this->redirect(array_merge(['action' => 'index'],(($this->getRequest()->getParam('suggestion'))?['suggestion' => 'true']:[])));
}

public function allowsuggestionAction()
{
$allowsuggestion = $this->getConfig()->get('radio_hoerercharts_allow_suggestion');
if ($allowsuggestion)
$this->getConfig()->set('radio_hoerercharts_allow_suggestion', 0);
else
$this->getConfig()->set('radio_hoerercharts_allow_suggestion', 1);

$this->addMessage('updateSuccess');

$this->redirect(['action' => 'index', 'suggestion' => 'true']);
}

Expand Down Expand Up @@ -250,12 +250,12 @@ public function resetAction()
if ($this->getRequest()->isSecure()) {
$hoererchartsMapper->reset();
$hoererchartsuservotesMapper->reset();

$this->addMessage('saveSuccess');
$this->redirect(['action' => 'index']);
}
}

$this->getView()->set('entries', $hoererchartsuservotesMapper->getEntries([]));
}
}
6 changes: 3 additions & 3 deletions controllers/admin/Settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,11 @@ public function indexAction()
->set('Star5', $this->getConfig()->get('radio_hoerercharts_Star5'));
}
}

public function votedatetimeAction()
{
$hoererchartsMapper = new HoererChartsMapper();

$this->getLayout()->setFile('modules/admin/layouts/iframe');
$this->getLayout()->getAdminHmenu()
->add($this->getTranslator()->trans('hoerercharts'), ['controller' => 'index', 'action' => 'index'])
Expand All @@ -118,7 +118,7 @@ public function votedatetimeAction()
->withMessage('saveSuccess')
->to(['action' => 'votedatetime']);
}

$start_datetime = null;
if ($this->getConfig()->get('radio_hoerercharts_Start_Datetime')) $start_datetime = new \Ilch\Date($this->getConfig()->get('radio_hoerercharts_Start_Datetime'));
$end_datetime = null;
Expand Down
13 changes: 6 additions & 7 deletions mappers/HoererCharts.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function checkDB()
{
return $this->db()->ifTableExists('[prefix]_radio_hoerercharts');
}

/**
* Gets the Entries.
*
Expand All @@ -33,7 +33,7 @@ public function getEntries($where = [], $pagination = null)
->from('radio_hoerercharts')
->where($where)
->order(['setfree' => 'DESC', 'id' => 'DESC']);

if ($pagination !== null) {
$select->limit($pagination->getLimit())
->useFoundRows();
Expand Down Expand Up @@ -279,7 +279,7 @@ public function getStars($votes = 0, $config = null, $showstars = false)
}
return $stars;
}

/**
* Checks if voting is allowed.
*
Expand All @@ -290,9 +290,9 @@ public function getStars($votes = 0, $config = null, $showstars = false)
public function vote_allowed($start_datetime = null, $end_datetime = null)
{
$date = new \Ilch\Date();

$datenow = new \Ilch\Date($date->format("Y-m-d H:i:s",true));

if (!$start_datetime and !$end_datetime){
return true;
}else{
Expand All @@ -306,9 +306,8 @@ public function vote_allowed($start_datetime = null, $end_datetime = null)
return (($datenow->getTimestamp() <= $end_datetime->getTimestamp()) ? true : false);
}
}
//var_dump($datenow,$start_datetime,$end_datetime);
return (($datenow->getTimestamp() >= $start_datetime->getTimestamp() && $datenow->getTimestamp() <= $end_datetime->getTimestamp()) ? true : false);
}
}

}
4 changes: 2 additions & 2 deletions mappers/HoererChartsSuggestion.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public function checkDB()
{
return $this->db()->ifTableExists('[prefix]_radio_hoerercharts_suggestion');
}

/**
* Gets the Entries.
*
Expand All @@ -33,7 +33,7 @@ public function getEntries($where = [], $pagination = null)
->from('radio_hoerercharts_suggestion')
->where($where)
->order(['id' => 'DESC']);

if ($pagination !== null) {
$select->limit($pagination->getLimit())
->useFoundRows();
Expand Down
Loading

0 comments on commit 80222df

Please sign in to comment.