/** * @param $key * @param $val * @return $this */ public function set($key, $val) { $obj = null; if ($this->db->getEntityManager()) { $obj = $this->db->getRepository('\\Fraym\\Registry\\Entity\\Config')->findOneByName(strtoupper($key)); if ($obj === null) { $obj = new \Fraym\Registry\Entity\Config(); $obj->name = strtoupper($key); $this->db->persist($obj); } $obj->value = $val; $this->db->flush(); } return $this; }
/** * Check the block user view permission. * * @param $blockId * @return bool */ public function checkPermission($blockId) { if ($this->cached && isset($this->executedBlocks[$blockId])) { $xml = $this->getXMLObjectFromString($this->executedBlocks[$blockId]); } else { $block = $this->db->getEntityManager()->createQuery('select b from \\Fraym\\Block\\Entity\\Block b WHERE b.id = :id')->setParameter('id', $blockId)->useResultCache(true)->getOneOrNullResult(); $xml = $this->getXMLObjectFromString($this->wrapBlockConfig($block)); } $user = $this->user; $allow = true; if ($user->isLoggedIn()) { $userGroupIdentifiers = $user->getIdentifiersFromGroups(); $userIdentifier = $user->identifier; if (isset($xml->permissions)) { $allow = false; foreach ($xml->permissions->permission as $permission) { $identifier = $this->getXMLAttr($permission, 'identifier'); if ($userIdentifier === $identifier || in_array($identifier, $userGroupIdentifiers)) { $allow = true; break; } } } } else { if (isset($xml->permissions)) { $allow = false; } } return $allow; }