summaryrefslogtreecommitdiff
path: root/app/helpers.php
diff options
context:
space:
mode:
authorhorus2020-10-01 01:15:59 +0200
committerhorus2020-10-01 01:15:59 +0200
commit24583ef2b3e7185f3a3e12cd1566bdada6d2f743 (patch)
treeb3ca7e1bc909e3b4c64d112c2394a7834a014bc7 /app/helpers.php
parente6194704303c4e5ad44c1bb9d6c2e17fe5eb133b (diff)
downloadsenpai-24583ef2b3e7185f3a3e12cd1566bdada6d2f743.tar.gz
add form to change season
Diffstat (limited to 'app/helpers.php')
-rw-r--r--app/helpers.php46
1 files changed, 46 insertions, 0 deletions
diff --git a/app/helpers.php b/app/helpers.php
index c5a227c..7214626 100644
--- a/app/helpers.php
+++ b/app/helpers.php
@@ -1,4 +1,5 @@
<?php
+use Illuminate\Support\Facades\DB;
use Carbon\Carbon;
function replaceSpecialChars($string) {
@@ -105,6 +106,37 @@ function nextSeason( $month = null ){
return $next;
}
+function lastSeason( $month = null ){
+ if ( is_null($month) ) {
+ $month = (int)date("m");
+ }
+
+ $last = $month - 3;
+ if ( $last <= 0 ) {
+ $last = $last + 12;
+ }
+
+ return $last;
+}
+
+function getFieldSeasonName() {
+ $first = (int)date("m");
+ $second = lastSeason($first);
+ $third = lastSeason($second);
+ $fourth = lastSeason($third);
+
+ return '"' . getSeason($first) . '", "' . getSeason($second) . '", "' . getSeason($third) . '", "' . getSeason($fourth) . '"';
+}
+
+function getFieldSeasonNameNext() {
+ $first = (int)date("m");
+ $second = nextSeason($first);
+ $third = nextSeason($second);
+ $fourth = nextSeason($third);
+
+ return '"' . getSeason($first) . '", "' . getSeason($second) . '", "' . getSeason($third) . '", "' . getSeason($fourth) . '"';
+}
+
function escapeLike($string){
$search = array('%', '_');
$replace = array('\%', '\_');
@@ -145,3 +177,17 @@ function camo($url) {
return $url;
}
+
+function getChangeSeasonOptions() {
+ return DB::select('
+ SELECT DISTINCT season_name,season_year
+ FROM anime
+ WHERE
+ season_name IS NOT NULL
+ AND
+ season_name != ""
+ AND
+ season_year IS NOT NULL
+ ORDER BY season_year DESC, FIELD(season_name, ' . getFieldSeasonName() . ') ASC'
+ );
+}