tethys/app/Models/DatasetFinder.php

113 lines
2.9 KiB
PHP
Raw Permalink Normal View History

2018-08-06 12:30:51 +00:00
<?php
2018-09-10 13:09:10 +00:00
namespace App\Models;
2018-08-06 12:30:51 +00:00
2018-09-10 13:09:10 +00:00
use App\Models\Dataset;
2018-08-06 12:30:51 +00:00
/**
* DocumentFinder short summary.
*
* DocumentFinder description.
*
* @version 1.0
* @author kaiarn
*/
class DatasetFinder
{
/**
* @var \Illuminate\Database\Eloquent\Builder
*/
2018-09-10 13:09:10 +00:00
private $select = null;
2018-08-06 12:30:51 +00:00
/**
* Create new instance of Opus_DocumentList class. The created object
* allows to get custom subsets (or lists) of all existing Opus_Documents.
*/
public function __construct()
{
// $table = Opus_Db_TableGateway::getInstance(self::$_tableGatewayClass);
// $this->_db = $table->getAdapter();
2018-09-10 13:09:10 +00:00
// $this->select = $this->_db->select()->from(array('d' => 'documents'));
2018-08-06 12:30:51 +00:00
2018-09-10 13:09:10 +00:00
$this->select = Dataset::query(); //>select('name', 'email as user_email')
2018-08-06 12:30:51 +00:00
}
/**
* Add constraints to be applied on the result set.
*
* @param string $serverStateArray
* @return DatasetFinder Fluent interface.
*/
public function setServerStateInList($serverStateArray)
{
2018-09-10 13:09:10 +00:00
$this->select->whereIn('server_state', $serverStateArray);
//$this->select->where('server_state IN (?)', $serverStateArray);
2018-08-06 12:30:51 +00:00
return $this;
}
/**
* Add constraints to be applied on the result set.
*
* @param string $type
* @return DatasetFinder Fluent interface.
*/
public function setType($type)
{
2018-09-10 13:09:10 +00:00
$this->select->where('type', $type);
2018-08-06 12:30:51 +00:00
return $this;
}
/**
* Add constraints to be applied on the result set.
*
* @param string $type
* @return DatasetFinder Fluent interface.
*/
public function setServerState($serverState)
{
2018-09-10 13:09:10 +00:00
//$this->select->where('server_state', '=', $serverState);
$this->select->where('server_state', 'LIKE', "%".$serverState."%");
2018-08-06 12:30:51 +00:00
return $this;
}
/**
* Returns a list of distinct document types for the given constraint set.
*
* @return array
*/
public function groupedTypesPlusCount()
{
2018-09-10 13:09:10 +00:00
//$this->select->reset('columns');
$test = $this->select
2018-08-06 12:30:51 +00:00
//->select("type") // "count(DISTINCT id)");
->selectRaw('type, count(DISTINCT id) as count')
->groupBy('type')
->pluck('count', 'type')
->toArray();
return $test;
}
/**
* Returns the number of (distinct) documents for the given constraint set.
*
* @return int
*/
public function count()
{
2018-09-10 13:09:10 +00:00
$this->select->count();
2018-08-06 12:30:51 +00:00
}
/**
* Returns a list of (distinct) document ids for the given constraint set.
*
* NOTE: It was not possible to make sure only DISTINCT identifiers are returned. Therefore array_unique is used.
* See OPUSVIER-3644 for more information.
*
* @return array
*/
public function ids()
{
//return array_unique($this->_db->fetchCol($this->getSelectIds()));
2018-09-10 13:09:10 +00:00
return $this->select->pluck('id')->toArray();
2018-08-06 12:30:51 +00:00
}
}