diff options
author | Harald Eilertsen <haraldei@anduin.net> | 2022-02-12 20:09:31 +0100 |
---|---|---|
committer | Harald Eilertsen <haraldei@anduin.net> | 2022-02-12 20:09:31 +0100 |
commit | d4cc6c399d12927541efd62c3836a86588b7a9be (patch) | |
tree | 2cc0dd93c25fd4a73bf77f86547d885facee3cd0 /includes/admin | |
parent | 87d6572d92b10ae9f987efbb84360542eb3d15dc (diff) | |
download | gigologadmin-d4cc6c399d12927541efd62c3836a86588b7a9be.tar.gz gigologadmin-d4cc6c399d12927541efd62c3836a86588b7a9be.tar.bz2 gigologadmin-d4cc6c399d12927541efd62c3836a86588b7a9be.zip |
More indentation and format if statements.
Diffstat (limited to 'includes/admin')
-rw-r--r-- | includes/admin/views/_concerts_table.php | 258 |
1 files changed, 134 insertions, 124 deletions
diff --git a/includes/admin/views/_concerts_table.php b/includes/admin/views/_concerts_table.php index 0302111..4a9c658 100644 --- a/includes/admin/views/_concerts_table.php +++ b/includes/admin/views/_concerts_table.php @@ -26,7 +26,7 @@ if (!class_exists("GiglogAdmin_ConcertsTable")) public function render(): string { return $this->render_filters() - . $this->render_concerts_table(); + . $this->render_concerts_table(); } private function render_concerts_table() : string @@ -139,48 +139,58 @@ if (!class_exists("GiglogAdmin_ConcertsTable")) if (current_user_can('administrator')) { $content .= '<td class="adminbuttons">' - . $this->adminactions($concert) - . '</td>'; + . $this->adminactions($concert) + . '</td>'; } } $content .= '</tr>'; $lastType = $concert->venue()->city(); } + $content .= '</table>'; $content.='<div id="pagtextbox">'; $content.='<span class="alignleft">'; - if($page_no > 1){ $content.= "<span><a href='?page_no=1'>First Page </a> - </span>"; } - if($page_no <= 1){ $content .="<span> </span>"; } - else $content.= "<span> <a href='?page_no=".$previous_page."' >Previous </a> </span>"; + + if($page_no > 1) { + $content.= "<span><a href='?page_no=1'>First Page </a> - </span>"; + } + + if($page_no <= 1) { + $content .="<span> </span>"; + } + else { + $content.= "<span> <a href='?page_no=".$previous_page."' >Previous </a> </span>"; + } + $content.='</span>'; $content.='<span class="aligncenter"><div style="padding: 10px 20px 0px; border-top: dotted 1px #CCC;"><strong>Page '.$page_no.' of '.$total_no_of_pages.'</strong></div></span>'; $content.='<span class="alignright">'; - if($page_no >= $total_no_of_pages){ $content .="<span> </span>";} - if($page_no < $total_no_of_pages) { $content .= '<span> <a href="?page_no='.$next_page.'"> Next </a> - </span> ';} - if($page_no < $total_no_of_pages){ - $content .= "<span><a href='?page_no=".$total_no_of_pages."'>Last Page </a></span>";} - - $content.='</span>'; - $content.='</div>'; - + if($page_no >= $total_no_of_pages) { + $content .= "<span></span>"; + } - // + if($page_no < $total_no_of_pages) { + $content .= '<span><a href="?page_no='.$next_page.'">Next</a> - </span>'; + $content .= "<span><a href='?page_no=".$total_no_of_pages."'>Last Page</a></span>"; + } + $content.='</span>'; + $content.='</div>'; - //from main form that includes filters - $content .= '</div></form></p>'; + //from main form that includes filters + $content .= '</div></form></p>'; - // return the table - return $content; - } + // return the table + return $content; + } - private function render_filters() : string - { - $cty = filter_input(INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS); + private function render_filters() : string + { + $cty = filter_input(INPUT_POST, 'selectcity', FILTER_SANITIZE_SPECIAL_CHARS); - $select = '<p><form method="POST" action="" class="filterclass">FILTER DATA: ' + $select = '<p><form method="POST" action="" class="filterclass">FILTER DATA: ' . \EternalTerror\ViewHelpers\select_field( "selectcity", array_map(fn($city) => [$city, $city], GiglogAdmin_Venue::all_cities()), @@ -188,104 +198,104 @@ if (!class_exists("GiglogAdmin_ConcertsTable")) "Select city..."); - if ( !empty($cty) ) { - //second drop down for venue - $select .= \EternalTerror\ViewHelpers\select_field( - "selectvenue", - array_map( - fn($venue) => [$venue->id(), $venue->name()], - GiglogAdmin_Venue::venues_in_city($cty) - ), - filter_input(INPUT_POST, 'selectvenue', FILTER_SANITIZE_SPECIAL_CHARS), - "Select venue..."); - } - - $select.=' Filter by month: '; - $select.= '<select name="selectmonth" size="1"><option value="0" selected="selected">- - All - -</option>'; - for ($i = 0; $i < 12; $i++) { - $time = strtotime(sprintf('%d months', $i)); - $label = date('F', $time); - $value = date('n', $time); - $select.= "<option value='$value'>$label</option>"; - } - - $select.='</select>'; - - if(is_admin()) { - //option to select own concerts only - $select .= '<input name="ownconcerts" class="ownconc" type="checkbox" value="1"' - . checked(isset($_POST['ownconcerts']) ? $_POST['ownconcerts'] : false) - . '><label for="ownconcerts">Show own concerts only</label>'; - - } - //NOTE that I remvoed </form></p> and mvoed them up to render_concerts_table function - $select .= '<input class="applybutton" type="submit" value="Apply Filters">'; - - return $select; - } + if ( !empty($cty) ) { + //second drop down for venue + $select .= \EternalTerror\ViewHelpers\select_field( + "selectvenue", + array_map( + fn($venue) => [$venue->id(), $venue->name()], + GiglogAdmin_Venue::venues_in_city($cty) + ), + filter_input(INPUT_POST, 'selectvenue', FILTER_SANITIZE_SPECIAL_CHARS), + "Select venue..."); + } - private function adminactions( GiglogAdmin_Concert $concert ) : string - { - return - '<form class="adminactions" method="POST" action="">' - . '<input type="hidden" name="cid" value="' . $concert->id() . '" />' - . \EternalTerror\ViewHelpers\select_field( - 'selectstatus', - array_map(fn($i) => [ $i, self::STATUS_LABELS[$i] ], range(1, count(self::STATUS_LABELS) - 1)), - $concert->status()) - . '<input type="submit" value="SetStatus">' - . '<input type="submit" name ="edit" value="EDIT">' - . '</form>'; - } - - /** - * Display a mark on the concert if it is new. - * I.e. imported/created within the last ten days. - * - * @return null|string - */ - private function mark_new_concert(GiglogAdmin_Concert $concert) : string - { - $now = new DateTime(); - $new_entry = $now->diff($concert->created())->days <= 10; - if ($new_entry) { - return '<span style="color:green">NEW</span>'; - } - else { - return ''; - } - } - - private function assign_role_for_user_form(string $role, GiglogAdmin_Concert $concert) : ?string - { - $roles = $concert->roles(); - $assigned_user = array_key_exists($role, $roles) ? $roles[$role] : NULL; - - //first check if current slot is taken by current user - if ( $assigned_user == $this->username ) { - $f = '<form class="unassign_concert" method="POST" action="">' - . ' <input type="hidden" name="cid" value="' . $concert->id() . '" />' - . ' <input type="hidden" name="pid" value="' . $role . '" />' - . ' <input type="submit" name="unassignitem" value=""/>' - . '</form>'; - } - elseif ( $assigned_user ) { //check if slot is taken by another user - $f = '<span class="takenby">Taken</span>' - . '<div class="takenby">Taken by ' . $assigned_user . '</div>'; - } - elseif ( array_search($this->username, $roles) ) { - // other slots for this concert are taken by user - $f = '<span class="taken_by_self">-</span>'; - } - else { //not taken by anyone - $f = '<form class="assign_concert" method="POST" action="">' - . ' <input type="hidden" name="cid" value="' . $concert->id() . '" />' - . ' <input type="hidden" name="pid" value="' . $role. '" />' - . ' <input type="submit" name="assignitem" value=""/>' - . '</form>'; - } - - return $f; - } - } - } + $select.=' Filter by month: '; + $select.= '<select name="selectmonth" size="1"><option value="0" selected="selected">- - All - -</option>'; + for ($i = 0; $i < 12; $i++) { + $time = strtotime(sprintf('%d months', $i)); + $label = date('F', $time); + $value = date('n', $time); + $select.= "<option value='$value'>$label</option>"; + } + + $select.='</select>'; + + if(is_admin()) { + //option to select own concerts only + $select .= '<input name="ownconcerts" class="ownconc" type="checkbox" value="1"' + . checked(isset($_POST['ownconcerts']) ? $_POST['ownconcerts'] : false) + . '><label for="ownconcerts">Show own concerts only</label>'; + + } + //NOTE that I remvoed </form></p> and mvoed them up to render_concerts_table function + $select .= '<input class="applybutton" type="submit" value="Apply Filters">'; + + return $select; + } + + private function adminactions( GiglogAdmin_Concert $concert ) : string + { + return + '<form class="adminactions" method="POST" action="">' + . '<input type="hidden" name="cid" value="' . $concert->id() . '" />' + . \EternalTerror\ViewHelpers\select_field( + 'selectstatus', + array_map(fn($i) => [ $i, self::STATUS_LABELS[$i] ], range(1, count(self::STATUS_LABELS) - 1)), + $concert->status()) + . '<input type="submit" value="SetStatus">' + . '<input type="submit" name ="edit" value="EDIT">' + . '</form>'; + } + + /** + * Display a mark on the concert if it is new. + * I.e. imported/created within the last ten days. + * + * @return null|string + */ + private function mark_new_concert(GiglogAdmin_Concert $concert) : string + { + $now = new DateTime(); + $new_entry = $now->diff($concert->created())->days <= 10; + if ($new_entry) { + return '<span style="color:green">NEW</span>'; + } + else { + return ''; + } + } + + private function assign_role_for_user_form(string $role, GiglogAdmin_Concert $concert) : ?string + { + $roles = $concert->roles(); + $assigned_user = array_key_exists($role, $roles) ? $roles[$role] : NULL; + + //first check if current slot is taken by current user + if ( $assigned_user == $this->username ) { + $f = '<form class="unassign_concert" method="POST" action="">' + . ' <input type="hidden" name="cid" value="' . $concert->id() . '" />' + . ' <input type="hidden" name="pid" value="' . $role . '" />' + . ' <input type="submit" name="unassignitem" value=""/>' + . '</form>'; + } + elseif ( $assigned_user ) { //check if slot is taken by another user + $f = '<span class="takenby">Taken</span>' + . '<div class="takenby">Taken by ' . $assigned_user . '</div>'; + } + elseif ( array_search($this->username, $roles) ) { + // other slots for this concert are taken by user + $f = '<span class="taken_by_self">-</span>'; + } + else { //not taken by anyone + $f = '<form class="assign_concert" method="POST" action="">' + . ' <input type="hidden" name="cid" value="' . $concert->id() . '" />' + . ' <input type="hidden" name="pid" value="' . $role. '" />' + . ' <input type="submit" name="assignitem" value=""/>' + . '</form>'; + } + + return $f; + } + } +} |