1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace app\models\sitemap; |
4
|
|
|
|
5
|
|
|
use yii\helpers\Url; |
6
|
|
|
use Itstructure\Sitemap\interfaces\Basic; |
7
|
|
|
use Itstructure\Sitemap\interfaces\GoogleAlternateLang; |
8
|
|
|
use Itstructure\AdminModule\models\Language; |
9
|
|
|
use app\models\Contact; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* Class SitemapContact |
13
|
|
|
* |
14
|
|
|
* @package app\commands\models\sitemap |
15
|
|
|
*/ |
16
|
|
|
class SitemapContact extends Contact implements Basic, GoogleAlternateLang |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* Handle materials by selecting batch of elements. |
20
|
|
|
* Increase this value and got more handling speed but more memory usage. |
21
|
|
|
* |
22
|
|
|
* @var int |
23
|
|
|
*/ |
24
|
|
|
public $sitemapBatchSize = 10; |
25
|
|
|
/** |
26
|
|
|
* List of available site languages |
27
|
|
|
* |
28
|
|
|
* @var array [langId => langCode] |
29
|
|
|
*/ |
30
|
|
|
public $sitemapLanguages = []; |
31
|
|
|
/** |
32
|
|
|
* If TRUE - Yii::$app->language will be switched for each sitemapLanguages and restored after. |
33
|
|
|
* |
34
|
|
|
* @var bool |
35
|
|
|
*/ |
36
|
|
|
public $sitemapSwithLanguages = true; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @var Contact |
40
|
|
|
*/ |
41
|
|
|
private $model; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* @inheritdoc |
45
|
|
|
*/ |
46
|
|
|
public function init() |
47
|
|
|
{ |
48
|
|
|
$this->sitemapLanguages = Language::getShortLanguageList(); |
49
|
|
|
|
50
|
|
|
parent::init(); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
/** |
54
|
|
|
* @inheritdoc |
55
|
|
|
*/ |
56
|
|
|
public function getSitemapItems($lang = null) |
57
|
|
|
{ |
58
|
|
|
$this->model = Contact::getDefaultContacts(); |
|
|
|
|
59
|
|
|
|
60
|
|
|
if (empty($this->model)) { |
61
|
|
|
return null; |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
return [ |
65
|
|
|
[ |
66
|
|
|
'loc' => Url::to('/' . $lang . '/contact', true), |
67
|
|
|
'lastmod' => $this->getSitemapLastmod(), |
68
|
|
|
'changefreq' => $this->getSitemapChangefreq(), |
69
|
|
|
'priority' => $this->getSitemapPriority(), |
70
|
|
|
'alternateLinks' => $this->getSitemapAlternateLinks(), |
71
|
|
|
], |
72
|
|
|
]; |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* @inheritdoc |
77
|
|
|
*/ |
78
|
|
|
public function getSitemapItemsQuery($lang = null) |
79
|
|
|
{ |
80
|
|
|
return null; |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @inheritdoc |
85
|
|
|
*/ |
86
|
|
|
public function getSitemapLoc($lang = null) |
87
|
|
|
{ |
88
|
|
|
return Url::to('/' . $lang . '/contact', true); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
/** |
92
|
|
|
* @inheritdoc |
93
|
|
|
*/ |
94
|
|
|
public function getSitemapLastmod($lang = null) |
95
|
|
|
{ |
96
|
|
|
return (new \DateTime($this->model->updated_at))->getTimestamp(); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* @inheritdoc |
101
|
|
|
*/ |
102
|
|
|
public function getSitemapChangefreq($lang = null) |
103
|
|
|
{ |
104
|
|
|
return static::CHANGEFREQ_MONTHLY; |
105
|
|
|
} |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @inheritdoc |
109
|
|
|
*/ |
110
|
|
|
public function getSitemapPriority($lang = null) |
111
|
|
|
{ |
112
|
|
|
return static::PRIORITY_8; |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @inheritdoc |
117
|
|
|
*/ |
118
|
|
|
public function getSitemapAlternateLinks() |
119
|
|
|
{ |
120
|
|
|
$buffer = []; |
121
|
|
|
|
122
|
|
|
foreach ($this->sitemapLanguages as $langCode) { |
123
|
|
|
$buffer[$langCode] = $this->getSitemapLoc($langCode); |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
return $buffer; |
127
|
|
|
} |
128
|
|
|
} |
129
|
|
|
|
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.