PageRenderTime 28ms CodeModel.GetById 13ms app.highlight 7ms RepoModel.GetById 6ms app.codeStats 0ms

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

https://github.com/glockops/concrete5
PHP | 93 lines | 77 code | 16 blank | 0 comment | 24 complexity | 064f1a078e7fcef9d144ce7ce13e570f MD5 | raw file
 1<?
 2defined('C5_EXECUTE') or die("Access Denied.");
 3
 4class Concrete5_Model_ViewUserAttributesUserPermissionKey extends UserPermissionKey  {
 5
 6	protected function getAllowedAttributeKeyIDs($list = false) {
 7		if (!$list) {
 8			$u = new User();
 9			$accessEntities = $u->getUserAccessEntityObjects();
10			$list = $this->getAccessListItems(UserPermissionKey::ACCESS_TYPE_ALL, $accessEntities);
11			$list = PermissionDuration::filterByActive($list);
12		}
13		
14		$db = Loader::db();
15		$allakIDs = $db->GetCol('select akID from UserAttributeKeys');
16		$akIDs = array();
17		foreach($list as $l) {
18			if ($l->getAttributesAllowedPermission() == 'N') {
19				$akIDs = array();
20			}
21			if ($l->getAttributesAllowedPermission() == 'C') {
22				if ($l->getAccessType() == PermissionKey::ACCESS_TYPE_EXCLUDE) {
23					$akIDs = array_values(array_diff($akIDs, $l->getAttributesAllowedArray()));
24				} else { 
25					$akIDs = array_unique(array_merge($akIDs, $l->getAttributesAllowedArray()));
26				}
27			}
28			if ($l->getAttributesAllowedPermission() == 'A') {
29				$akIDs = $allakIDs;
30			}
31		}
32		
33		return $akIDs;
34	}
35	
36	
37	public function getMyAssignment() {
38		$u = new User();
39		$asl = new ViewUserAttributesUserPermissionAssignment();
40		if ($u->isSuperUser()) {
41			$asl->setAttributesAllowedPermission('A');
42			return $asl;
43		}
44
45		$pae = $this->getPermissionAccessObject();
46		if (!is_object($pae)) {
47			return $asl;
48		}
49		
50		$accessEntities = $u->getUserAccessEntityObjects();
51		$accessEntities = $pae->validateAndFilterAccessEntities($accessEntities);
52		$list = $this->getAccessListItems(UserPermissionKey::ACCESS_TYPE_ALL, $accessEntities);
53		$list = PermissionDuration::filterByActive($list);
54
55		foreach($list as $l) {
56			if ($l->getAttributesAllowedPermission() == 'N') {
57				$asl->setAttributesAllowedPermission('N');
58			}
59
60			if ($l->getAttributesAllowedPermission() == 'C') {
61				$asl->setAttributesAllowedPermission('C');
62			}
63
64			if ($l->getAttributesAllowedPermission() == 'A') {
65				$asl->setAttributesAllowedPermission('A');
66			}
67		}	
68		
69		$asl->setAttributesAllowedArray($this->getAllowedAttributeKeyIDs($list));
70		return $asl;
71	}
72	
73	public function validate($obj = false) {
74		$u = new User();
75		if ($u->isSuperUser()) {
76			return true;
77		}
78
79		$types = $this->getAllowedAttributeKeyIDs();
80		if ($obj != false) {
81			if (is_object($obj)) {
82				$akID = $obj->getAttributeKeyID();
83			} else {
84				$akID = $obj;
85			}
86			return in_array($akID, $types);
87		} else {
88			return count($types) > 0;
89		}
90	}	
91
92	
93}