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;
|
2019-09-02 14:58:08 +00:00
|
|
|
use DateTime;
|
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
|
|
|
|
2019-09-02 14:58:08 +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);
|
|
|
|
|
|
|
|
$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();
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|