PageRenderTime 87ms CodeModel.GetById 82ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

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

https://github.com/glockops/concrete5
PHP | 62 lines | 53 code | 9 blank | 0 comment | 17 complexity | 1585c2ee65d960a927495709a41566b2 MD5 | raw file
 1<?
 2defined('C5_EXECUTE') or die("Access Denied.");
 3
 4class Concrete5_Model_AddBlockBlockTypePermissionKey extends BlockTypePermissionKey  {
 5
 6	protected function getAllowedBlockTypeIDs() {
 7
 8		$u = new User();
 9		$pae = $this->getPermissionAccessObject();
10		if (!is_object($pae)) {
11			return array();
12		}
13		$accessEntities = $u->getUserAccessEntityObjects();
14		$accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
15		$list = $this->getAccessListItems(PermissionKey::ACCESS_TYPE_ALL, $accessEntities);
16		$list = PermissionDuration::filterByActive($list);
17		
18		$db = Loader::db();
19		$btIDs = array();
20		if (count($list) > 0) {
21			$dsh = Loader::helper('concrete/dashboard');
22			if ($dsh->inDashboard()) {
23				$allBTIDs = $db->GetCol('select btID from BlockTypes');
24			} else { 
25				$allBTIDs = $db->GetCol('select btID from BlockTypes where btIsInternal = 0');
26			}
27			foreach($list as $l) {
28				if ($l->getBlockTypesAllowedPermission() == 'N') {
29					$btIDs = array();
30				}
31				if ($l->getBlockTypesAllowedPermission() == 'C') {
32					if ($l->getAccessType() == PermissionKey::ACCESS_TYPE_EXCLUDE) {
33						$btIDs = array_values(array_diff($btIDs, $l->getBlockTypesAllowedArray()));
34					} else { 
35						$btIDs = array_unique(array_merge($btIDs, $l->getBlockTypesAllowedArray()));
36					}
37				}
38				if ($l->getBlockTypesAllowedPermission() == 'A') {
39					$btIDs = $allBTIDs;
40				}
41			}
42		}
43				
44		return $btIDs;
45	}
46	
47	public function validate($bt = false) {
48		$u = new User();
49		if ($u->isSuperUser()) {
50			return true;
51		}
52
53		$types = $this->getAllowedBlockTypeIDs();
54		if ($bt != false) {
55			return in_array($bt->getBlockTypeID(), $types);
56		} else {
57			return count($types) > 0;
58		}
59	}	
60
61	
62}