<commit_before><?php

namespace Bishopm\Connexion\Http\Controllers;

use Illuminate\Http\Request, Bishopm\Connexion\Models\Gchord;
use App\Http\Requests, Bishopm\Connexion\Models\User, Bishopm\Connexion\Models\Song, Auth, Bishopm\Connexion\Models\Set, Bishopm\Connexion\Models\Setitem, View, Redirect, DB;
use App\Http\Controllers\Controller, Bishopm\Connexion\Http\Requests\SongsRequest, Bishopm\Connexion\Libraries\Fpdf\Fpdf; 

class SongsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $data['lets']=array('1'=>'A','2'=>'B','3'=>'C','4'=>'D','5'=>'E','6'=>'F','7'=>'G','8'=>'H','9'=>'I','10'=>'J','11'=>'K','12'=>'L','13'=>'M','14'=>'N','15'=>'O','16'=>'P','17'=>'Q','18'=>'R','19'=>'S','20'=>'T','21'=>'U','22'=>'V','23'=>'W','24'=>'X','25'=>'Y','26'=>'Z');
        $data['songs']=Song::orderBy('title')->get();
        $data['songcount']=count($data['songs']);
        $lasthree=date("Y-m-d",strtotime("-3 month"));
        $recents=Set::with('setitems')->where('servicedate','>',$lasthree)->get();
        $arecents=array();
        $newest=array();
        $mostrecentset=0;
        foreach ($recents as $recent){
            if (!array_key_exists($recent->service->servicetime,$arecents)){
                $arecents[$recent->service->servicetime]=array();
            }
            foreach ($recent->setitems as $si){
                if (array_key_exists($si->song_id,$arecents[$recent->service->servicetime])){
                    if ($si->song->musictype<>'liturgy'){
                        $arecents[$recent->service->servicetime][$si->song_id]['count']++;
                    }
                } else {
                    if ($si->song->musictype<>'liturgy'){
                        $arecents[$recent->service->servicetime][$si->song_id]['count']=1;
                        $arecents[$recent->service->servicetime][$si->song_id]['title']=$si->song->title;
                        $arecents[$recent->service->servicetime][$si->song_id]['musictype']=$si->song->musictype;
                        $arecents[$recent->service->servicetime][$si->song_id]['id']=$si->song_id;
                    }
                }
                $newest[strtotime($recent->servicedate)][$recent->service->servicetime][$si->song_id]['title']=$si->song->title;
                $newest[strtotime($recent->servicedate)][$recent->service->servicetime][$si->song_id]['musictype']=$si->song->musictype;
                $newest[strtotime($recent->servicedate)][$recent->service->servicetime][$si->song_id]['id']=$si->song_id;
                if (strtotime($recent->servicedate)>$mostrecentset){
                    $mostrecentset=strtotime($recent->servicedate);
                }
            }
        }
        krsort($newest);
        $newestsets=reset($newest);
        if ($newestsets){
            ksort($newestsets);
        } else {
            $newestsets=array();<commit_msg>Fix song update<commit_after><?php

namespace Bishopm\Connexion\Http\Controllers;

use Illuminate\Http\Request, Bishopm\Connexion\Models\Gchord;
use App\Http\Requests, Bishopm\Connexion\Models\User, Bishopm\Connexion\Models\Song, Auth, Bishopm\Connexion\Models\Set, Bishopm\Connexion\Models\Setitem, View, Redirect, DB;
use App\Http\Controllers\Controller, Bishopm\Connexion\Http\Requests\SongsRequest, Bishopm\Connexion\Libraries\Fpdf\Fpdf; 

class SongsController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $data['lets']=array('1'=>'A','2'=>'B','3'=>'C','4'=>'D','5'=>'E','6'=>'F','7'=>'G','8'=>'H','9'=>'I','10'=>'J','11'=>'K','12'=>'L','13'=>'M','14'=>'N','15'=>'O','16'=>'P','17'=>'Q','18'=>'R','19'=>'S','20'=>'T','21'=>'U','22'=>'V','23'=>'W','24'=>'X','25'=>'Y','26'=>'Z');
        $data['songs']=Song::orderBy('title')->get();
        $data['songcount']=count($data['songs']);
        $lasthree=date("Y-m-d",strtotime("-3 month"));
        $recents=Set::with(['setitems' => function($query) { $query->orderBy('itemorder', 'asc'); }])->where('servicedate','>',$lasthree)->get();
        $arecents=array();
        $newest=array();
        $mostrecentset=0;
        foreach ($recents as $recent){
            if (!array_key_exists($recent->service->servicetime,$arecents)){
                $arecents[$recent->service->servicetime]=array();
            }
            foreach ($recent->setitems as $si){
                if (array_key_exists($si->song_id,$arecents[$recent->service->servicetime])){
                    if ($si->song->musictype<>'liturgy'){
                        $arecents[$recent->service->servicetime][$si->song_id]['count']++;
                    }
                } else {
                    if ($si->song->musictype<>'liturgy'){
                        $arecents[$recent->service->servicetime][$si->song_id]['count']=1;
                        $arecents[$recent->service->servicetime][$si->song_id]['title']=$si->song->title;
                        $arecents[$recent->service->servicetime][$si->song_id]['musictype']=$si->song->musictype;
                        $arecents[$recent->service->servicetime][$si->song_id]['id']=$si->song_id;
                    }
                }
                $newest[strtotime($recent->servicedate)][$recent->service->servicetime][$si->song_id]['title']=$si->song->title;
                $newest[strtotime($recent->servicedate)][$recent->service->servicetime][$si->song_id]['musictype']=$si->song->musictype;
                $newest[strtotime($recent->servicedate)][$recent->service->servicetime][$si->song_id]['id']=$si->song_id;
                if (strtotime($recent->servicedate)>$mostrecentset){
                    $mostrecentset=strtotime($recent->servicedate);
                }
            }
        }
        //dd($newest);
        krsort($newest);
        $newestsets=reset($newest);
        if ($newestsets){
            ksort($newestsets);
        } else {
            $newestsets=array();
{'fraction_non_alphanumeric': 0.22546767312110272, 'fraction_numerical': 0.015096816540859863, 'mean_word_length': 2.86984126984127, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 173, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3093063', 'n_tokens_mistral': 2064, 'n_tokens_neox': 1955, 'n_words': 166}