18 use Illuminate\Database\Capsule\Manager as Capsule;
82 public function orderBy($column, $direction =
'DESC') {
83 if ($column ===
'lastModified') {
84 $this->orderColumn =
'i.last_modified';
85 } elseif ($column ===
'seq') {
86 $this->orderColumn =
'o.seq';
88 $this->orderColumn =
'i.date_published';
90 $this->orderDirection = $direction;
183 $this->limit = $count;
205 ->select(
'i.issue_id')
213 public function getIds() {
216 ->select(
'i.issue_id')
217 ->pluck(
'i.issue_id')
225 $this->columns[] =
'i.*';
226 $q = Capsule::table(
'issues as i')
227 ->leftJoin(
'issue_settings as is',
'i.issue_id',
'=',
'is.issue_id')
228 ->leftJoin(
'custom_issue_orders as o',
'o.issue_id',
'=',
'i.issue_id')
229 ->orderBy($this->orderColumn, $this->orderDirection)
230 ->groupBy(
'i.issue_id', $this->orderColumn);
235 if (is_null($this->contextId)) {
236 $q->where(
'i.journal_id',
'=', CONTEXT_ID_NONE);
237 } elseif ($this->contextId !==
'*') {
238 $q->where(
'i.journal_id',
'=' , $this->contextId);
242 if (!is_null($this->isPublished)) {
243 $q->where(
'i.published', $this->isPublished ? 1 : 0);
247 if (!is_null($this->volumes)) {
248 $q->whereIn(
'i.volume', $this->volumes);
252 if (!is_null($this->numbers)) {
253 $q->whereIn(
'i.number', $this->numbers);
257 if (!is_null($this->years)) {
258 $q->whereIn(
'i.year', $this->years);
262 if (!empty($this->issueIds)) {
263 $q->whereIn(
'i.issue_id', $this->issueIds);
277 $volumeRegex =
'/' . preg_quote(__(
'issue.vol')) .
'\s\S/';
279 if (count($matches)) {
280 $volume = trim(str_replace(__(
'issue.vol'),
'', $matches[0]));
283 $numberRegex =
'/' . preg_quote(__(
'issue.no')) .
'\s\S/';
285 if (count($matches)) {
286 $number = trim(str_replace(__(
'issue.no'),
'', $matches[0]));
290 if (count($matches)) {
291 $year = substr($matches[0], 1, 4);
294 if ($volume !==
'' || $number !==
'' || $year !==
'') {
295 $q->where(
function($q) use ($volume, $number, $year) {
297 $q->where(
'i.volume',
'=', $volume);
300 $q->where(
'i.number',
'=', $number);
303 $q->where(
'i.year',
'=', $year);
310 foreach ($words as $word) {
311 $word = strtolower(addcslashes($word,
'%_'));
312 $q->where(
function($q) use ($word) {
313 $q->where(
function($q) use ($word) {
314 $q->where(
'is.setting_name',
'title');
315 $q->where(Capsule::raw(
'lower(is.setting_value)'),
'LIKE',
"%{$word}%");
317 ->orWhere(
function($q) use ($word) {
318 $q->where(
'is.setting_name',
'description');
319 $q->where(Capsule::raw(
'lower(is.setting_value)'),
'LIKE',
"%{$word}%");
323 if (ctype_digit($word) && strlen($word) === 4) {
324 $q->orWhere(
'i.year',
'=', $word);
334 $q->select($this->columns);