/** * Check current user entry in group by code. * * @param string $code Group's code. * * @return bool */ public function inGroup($code) { $groupId = GroupTools::find($code, true)->id(); if ((int) $groupId > 0) { global $USER; return in_array($groupId, $USER->GetUserGroupArray()); } return false; }
/** * Converting content from .access.php file, with usage symbol of the codes users groups instead id's. * * @param string $content * * @return bool */ public function convertContent(&$content) { if (!$this->isFileAccess) { return false; } elseif (empty($content)) { return false; } $content = preg_replace_callback('/(PERM\\[.+\\]\\[)(\\"G?[0-9]+\\")(\\])/', function ($matches) { $matches[2] = trim($matches[2], "\""); $groupId = str_replace('G', '', $matches[2], $addG); try { $groupCode = GroupTools::findById($groupId)->code(); } catch (ValueNotFoundException $e) { return $matches[0]; } $value = ($addG ? "'G'." : '') . '\\Bex\\Tools\\Group\\GroupTools::find(\'' . $groupCode . '\', true)->id()'; return $matches[1] . $value . $matches[3]; }, $content); return true; }