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

76 lines
2.6 KiB
PHP
Raw Permalink 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
->select(DB::raw('EXTRACT(YEAR FROM server_date_published) as published_date'))
// ->select(DB::raw("DATE_PART('year', server_date_published) as published_date"))
// ->select(DB::raw("YEAR(server_date_published) AS published_date"))
->distinct(true);
$this->years = $select->pluck('published_date')->toArray();
// $years = $select->pluck('server_date_published')->toArray();
// $this->years = array_map(function ($pdate) {
// $dateValue = strtotime($pdate);
// if ($dateValue != false) {
// $year = date("Y", $dateValue);
// return $year;
// }
// }, $years);
2018-08-06 12:30:51 +00:00
$this->ids = array();
2021-05-25 12:15:02 +00:00
return view(
'frontend.sitelink.index',
['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->orderBy('publish_id')
2018-08-06 12:30:51 +00:00
->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]);
2021-05-25 12:15:02 +00:00
return view(
'frontend.sitelink.index',
['years' => $this->years, 'documents' => $documents]
);
2018-08-06 12:30:51 +00:00
}
}
}