PageRenderTime 13ms CodeModel.GetById 9ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/web/concrete/core/models/permission/keys/custom/edit_page_theme.php

https://github.com/glockops/concrete5
PHP | 56 lines | 46 code | 10 blank | 0 comment | 14 complexity | 8479f39ddee43274e11c2930422c04e8 MD5 | raw file
 1<?
 2defined('C5_EXECUTE') or die("Access Denied.");
 3
 4class Concrete5_Model_EditPageThemePagePermissionKey extends PagePermissionKey  {
 5	
 6	protected function getAllowedThemeIDs() {
 7
 8		$u = new User();
 9		$pae = $this->getPermissionAccessObject();
10		if (!is_object($pae)) {
11			return array();
12		}
13		
14		$accessEntities = $u->getUserAccessEntityObjects();
15		$accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
16		$list = $this->getAccessListItems(PagePermissionKey::ACCESS_TYPE_ALL, $accessEntities);
17		$list = PermissionDuration::filterByActive($list);
18		
19		$db = Loader::db();
20		$allptIDs = $db->GetCol('select ptID from PageThemes order by ptID asc');
21		$ptIDs = array();
22		foreach($list as $l) {
23			if ($l->getThemesAllowedPermission() == 'N') {
24				$ptIDs = array();
25			}
26			if ($l->getThemesAllowedPermission() == 'C') {
27				if ($l->getAccessType() == PagePermissionKey::ACCESS_TYPE_EXCLUDE) {
28					$ptIDs = array_values(array_diff($ptIDs, $l->getThemesAllowedArray()));
29				} else { 
30					$ptIDs = array_unique(array_merge($ptIDs, $l->getThemesAllowedArray()));
31				}
32			}
33			if ($l->getThemesAllowedPermission() == 'A') {
34				$ptIDs = $allptIDs;
35			}
36		}
37		
38		return $ptIDs;
39	}
40	
41	public function validate($theme = false) {
42		$u = new User();
43		if ($u->isSuperUser()) {
44			return true;
45		}
46
47		$themes = $this->getAllowedThemeIDs();
48		if ($theme != false) {
49			return in_array($theme->getThemeID(), $themes);
50		} else {
51			return count($themes) > 0;
52		}
53	}
54	
55	
56}