/
ESitemapBehavior.php
57 lines (53 loc) · 1.66 KB
/
ESitemapBehavior.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<?php
/**
* ESitemapBehavior.php File
*
* @copyright (c) Dana Luther
* @license https://opensource.org/licenses/BSD-2-Clause BSD-2-Clause
* @link https://www.yiiframework.com/extension/esitemap esitemap
* @package ESitemap
*/
/**
* Description of ESitemapBehavior
*
* @author Dana Luther <dana@lutherweb.com>
* @version 1.1
*/
class ESitemapBehavior extends CBehavior {
/**
* Populate the array of site links
* @param array[] &$list The array which holds the array of link information: loc, frequency, priority
* @param ESitemapModel[] $classesConfig Array of class configuration Models
* @param string $default_scope The default scope to use if one is not defined in the class. Defaults to 'sitemap'
* @return array[]
*/
public function populateSitemap( $list, $classes, $default_scope = 'sitemap' )
{
// Loop through each of the classes, setting the defaults for all models
// of that type and then setting the specific model attributes into the
// listing for the class type
foreach( $classes as $modelType )
{
$esm = new ESitemapModel;
$esm->attributes = $modelType;
if (!$esm->validate())
{
Yii::log('Impropertly configured sitemap class object: '.print_r($esm->errors, true), 'warning', 'ext.sitemap.ESitemapBeahvior');
continue;
//throw new CException('Improperly configured sitemap class object: '.print_r($esm->errors, true));
}
$models = $esm->models;
foreach( $models as $model )
{
$list[] = array(
// replace model slugs with model attribute values
'loc'=> $esm->loc($model),
'frequency'=>$esm->frequency,
'priority'=>$esm->priority,
);
}
}
return $list;
}
}
?>