ContentAbstract   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 108
ccs 30
cts 30
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getAllByOrder() 0 4 2
A getByLanguageAndOrder() 0 9 2
A getSiblingByIdAndLanguageAndOrder() 0 10 2
A getSiblingArrayById() 0 16 1
A publishByDate() 0 11 1
1
<?php
2
namespace Redaxscript\Model;
3
4
/**
5
 * abstract class to create a model class
6
 *
7
 * @since 4.0.0
8
 *
9
 * @package Redaxscript
10
 * @category Model
11
 * @author Henry Ruhs
12
 */
13
14
abstract class ContentAbstract extends ModelAbstract
15
{
16
	/**
17
	 * get all by order
18
	 *
19
	 * @since 4.0.0
20
	 *
21
	 * @param string $orderColumn name of the column to order
22
	 *
23
	 * @return object|null
24
	 */
25
26 2
	public function getAllByOrder(string $orderColumn = 'rank') : ?object
27
	{
28 2
		return $this->query()->orderBySetting($orderColumn)->findMany() ? : null;
29
	}
30
31
	/**
32
	 * get the content by language and order
33
	 *
34
	 * @since 4.0.0
35
	 *
36
	 * @param string $language
37
	 * @param string $orderColumn name of the column to order
38
	 *
39
	 * @return object|null
40
	 */
41
42 3
	public function getByLanguageAndOrder(string $language = null, string $orderColumn = 'rank') : ?object
43
	{
44
		return $this
45 3
			->query()
46 3
			->whereLanguageIs($language)
47 3
			->where('status', 1)
48 3
			->orderBySetting($orderColumn)
49 3
			->findMany() ? : null;
50
	}
51
52
	/**
53
	 * get the sibling by id and language and order
54
	 *
55
	 * @since 4.0.0
56
	 *
57
	 * @param int $contentId
58
	 * @param string $language
59
	 * @param string $orderColumn name of the column to order
60
	 *
61
	 * @return object|null
62
	 */
63
64 3
	public function getSiblingByIdAndLanguageAndOrder(int $contentId = null, string $language = null, string $orderColumn = 'rank') : ?object
65
	{
66
		return $this
67 3
			->query()
68 3
			->whereIn('id', $this->getSiblingArrayById($contentId))
69 3
			->where('status', 1)
70 3
			->whereLanguageIs($language)
71 3
			->orderBySetting($orderColumn)
72 3
			->findMany() ? : null;
73
	}
74
75
	/**
76
	 * get sibling array by id
77
	 *
78
	 * @param int $contentId identifier of the content
79
	 *
80
	 * @return array|null
81
	 */
82
83 7
	public function getSiblingArrayById(int $contentId = null) : ?array
84
	{
85
		return $this
86 7
			->query()
87 7
			->select('id')
88 7
			->whereAnyIs(
89
			[
90
				[
91 7
					'id' => $contentId
92
				],
93
				[
94 7
					'sibling' => $contentId
95
				]
96
			])
97 7
			->findFlatArray();
98
	}
99
100
	/**
101
	 * publish by date
102
	 *
103
	 * @since 3.3.0
104
	 *
105
	 * @param string $date
106
	 *
107
	 * @return int
108
	 */
109
110 2
	public function publishByDate(string $date = null) : int
111
	{
112
		return $this
113 2
			->query()
114 2
			->whereLt('date', $date)
115 2
			->where('status', 2)
116 2
			->findMany()
117 2
			->set('status', 1)
118 2
			->save()
119 2
			->count();
120
	}
121
}
122