ThemeSettings::attributeLabels()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 0
1
<?php
2
3
class ThemeSettings extends CiiSettingsModel
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
4
{
5
	/**
6
	 * The active theme
7
	 * @var string
8
	 */
9
	public $theme = 'default';
10
11
	/**
12
	 * Validation rules for the theme
13
	 * @return array
14
	 */
15
	public function rules()
16
	{
17
		return array(
18
			array('theme', 'required'),
19
			array('theme', 'length', 'max' => 255)
20
		);
21
	}
22
23
	/**
24
	 * Attribute labels for themes
25
	 * @return array
26
	 */
27
	public function attributeLabels()
28
	{
29
		return array(
30
			'theme' => Yii::t('ciims.models.theme', 'Theme'),
31
		);
32
	}
33
34
	/**
35
	 * Returns the active theme name
36
	 * @return string
37
	 */
38
	public function getTheme()
39
	{
40
		return $this->theme;
41
	}
42
43
	/**
44
	 * Retrieves all of the themes from webroot.themes and returns them in an array group by type, each containing
45
	 * the contents of theme.json.
46
	 *
47
	 * The themes are then cached for easy retrieval later. (I really hate unecessary DiskIO if something isn't changing...)
48
	 *
49
	 * @return array
50
	 */
51
	public function getThemes()
52
	{
53
		$themes = Yii::app()->cache->get('settings_themes');
54
55
		if ($themes == false)
56
		{
57
			$themes = array();
58
			$currentTheme = Cii::getConfig('theme');
59
			$themePath = Yii::getPathOfAlias('base.themes') . DS;
60
			$directories = glob($themePath . "*", GLOB_ONLYDIR);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal * does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
61
62
			// Pushes the current theme onto the top of the list
63
			foreach ($directories as $k=>$dir)
64
			{
65
				if ($dir == Yii::getPathOfAlias('base.themes').DS.$currentTheme)
66
				{
67
					unset($directories[$k]);
68
					break;
69
				}
70
			}
71
72
			array_unshift($directories, $themePath.$currentTheme);
73
74
			foreach($directories as $dir)
75
			{
76
				$json = CJSON::decode(file_get_contents($dir . DIRECTORY_SEPARATOR . 'composer.json'));
77
				$name = $json['name'];
78
				$key = str_replace('ciims-themes/', '', $name);
79
80
				$themes[$key] = array(
81
					'path' 		=> $dir,
82
					'name' 		=> $name,
83
					'hidden' 	=> isset($json['hidden']) ? $json['hidden'] : false
84
				);
85
			}
86
87
			Yii::app()->cache->set('settings_themes', $themes);
88
			return $themes;
89
		}
90
91
		return $themes;
92
	}
93
}