tethys/app/Http/Controllers/Frontend/SitelinkController.php

61 lines
2.0 KiB
PHP
Raw Normal View History

2018-08-06 12:30:51 +00:00
<?php
2018-09-06 15:58:54 +00:00
namespace App\Http\Controllers\Frontend;
2018-08-06 12:30:51 +00:00
2018-09-10 13:09:10 +00:00
use App\Models\Dataset;
2018-09-06 15:58:54 +00:00
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
2018-08-06 12:30:51 +00:00
class SitelinkController extends Controller
{
public function index()
{
//get server state published
$serverState = 'published';
$select = DB::table('documents')
2018-09-06 15:58:54 +00:00
->where('server_state', 'LIKE', "%" . $serverState . "%");
2018-08-06 12:30:51 +00:00
$select
2018-09-06 15:58:54 +00:00
->select(DB::raw('YEAR(published_date) as published_date'))
->distinct(true);
2018-08-06 12:30:51 +00:00
$this->years = $select->pluck('published_date');
$this->ids = array();
2018-09-06 15:58:54 +00:00
return view('frontend.sitelink.index')->with(['years' => $this->years, 'documents' => $this->ids]);
2018-08-06 12:30:51 +00:00
}
2018-09-10 13:09:10 +00:00
public function listDocs($year)
2018-08-06 12:30:51 +00:00
{
$this->index();
if (preg_match('/^\d{4}$/', $year) > 0) {
$serverState = 'published';
//$select = DB::table('documents')
//->where('server_state','LIKE', "%".$serverState."%");
$select = Dataset::with('titles', 'authors')
2018-09-06 15:58:54 +00:00
->where('server_state', 'LIKE', "%" . $serverState . "%");
2018-08-06 12:30:51 +00:00
2018-09-10 13:09:10 +00:00
$from = (int) $year;
2018-09-06 15:58:54 +00:00
$until = $year + 1;
2018-08-06 12:30:51 +00:00
$select
2018-09-06 15:58:54 +00:00
->whereYear('server_date_published', '>=', $from)
->whereYear('server_date_published', '<', $until);
2018-08-06 12:30:51 +00:00
$documents = $select
->get();
//$this->years = Dataset::select(DB::raw('YEAR(server_date_modified) as server_date_modified'))
//->distinct(true)
//->pluck('server_date_modified');
//->filter(function ($item) use ($year){
// return $item->year !== $year;
//});
//$select->select('id');
//$this->ids = $select->pluck('id');
//return view('rdr.sitelink.index')->with(['years'=> $this->years,'ids'=> $this->ids]);
2018-09-06 15:58:54 +00:00
return view('frontend.sitelink.index')
->with(['years' => $this->years, 'documents' => $documents]);
2018-08-06 12:30:51 +00:00
}
}
}