code
stringlengths 31
1.39M
| docstring
stringlengths 23
16.8k
| func_name
stringlengths 1
126
| language
stringclasses 1
value | repo
stringlengths 7
63
| path
stringlengths 7
166
| url
stringlengths 50
220
| license
stringclasses 7
values |
---|---|---|---|---|---|---|---|
public function resolveItemAttributes(): Closure
{
return function (string $filename, int $index = 0): ComponentAttributesBagContract {
if (\is_null($this->itemAttributes)) {
return new MoonShineComponentAttributeBag();
}
return new MoonShineComponentAttributeBag(
(array) \call_user_func($this->itemAttributes, $filename, $index),
);
};
}
|
@return Closure(string $filename, int $index, static): ComponentAttributesBagContract
|
resolveItemAttributes
|
php
|
moonshine-software/moonshine
|
src/UI/src/Traits/Fields/FileTrait.php
|
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/FileTrait.php
|
MIT
|
public function extraAttributes(Closure $callback): static
{
$this->extraAttributes = $callback;
return $this;
}
|
@param Closure(string $filename, int $index): ?FileItemExtra $callback
|
extraAttributes
|
php
|
moonshine-software/moonshine
|
src/UI/src/Traits/Fields/FileTrait.php
|
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/FileTrait.php
|
MIT
|
public function resolveExtraAttributes(): Closure
{
return function (string $filename, int $index = 0): ?FileItemExtra {
if (\is_null($this->extraAttributes)) {
return null;
}
return \call_user_func($this->extraAttributes, $filename, $index);
};
}
|
@return Closure(string $filename, int $index, static): ?FileItemExtra
|
resolveExtraAttributes
|
php
|
moonshine-software/moonshine
|
src/UI/src/Traits/Fields/FileTrait.php
|
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/FileTrait.php
|
MIT
|
public function customName(Closure $name): static
{
$this->customName = $name;
return $this;
}
|
@param Closure(mixed $file, static $ctx): string $name
|
customName
|
php
|
moonshine-software/moonshine
|
src/UI/src/Traits/Fields/FileTrait.php
|
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/FileTrait.php
|
MIT
|
public function getCustomName(): ?Closure
{
return $this->customName;
}
|
@return null|Closure(mixed $file, static $ctx): string
|
getCustomName
|
php
|
moonshine-software/moonshine
|
src/UI/src/Traits/Fields/FileTrait.php
|
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/FileTrait.php
|
MIT
|
public function remainingValuesResolver(Closure $callback): static
{
$this->remainingValuesResolver = $callback;
return $this;
}
|
@param Closure(static $ctx): Collection $callback
|
remainingValuesResolver
|
php
|
moonshine-software/moonshine
|
src/UI/src/Traits/Fields/FileTrait.php
|
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/FileTrait.php
|
MIT
|
public function updateOnPreview(
?Closure $url = null,
?ResourceContract $resource = null,
mixed $condition = null,
array $events = [],
): static {
$this->updateOnPreview = value($condition, $this) ?? true;
if (! $this->updateOnPreview) {
return $this;
}
if (! \is_null($resource)) {
$this->nowOn(
page: $resource instanceof CrudResourceContract ? $resource->getFormPage() : null,
resource: $resource
);
}
$router = $this->getCore()->getRouter();
return $this->setUpdateOnPreviewUrl(
$url ?? static fn (?DataWrapperContract $data, mixed $value, FieldContract $field): ?string => $data?->getKey() ? $router->getEndpoints()->updateField(
resource: $field->getNowOnResource(),
extra: [
'resourceItem' => $data->getKey(),
'relation' => data_get($field->getNowOnQueryParams(), 'relation'),
],
) : null,
$events
);
}
|
@param ?Closure(mixed $data, mixed $value, static $field): string $url
|
updateOnPreview
|
php
|
moonshine-software/moonshine
|
src/UI/src/Traits/Fields/UpdateOnPreview.php
|
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/UpdateOnPreview.php
|
MIT
|
public function setUpdateOnPreviewUrl(Closure $url, array $events = []): static
{
$this->updateOnPreviewUrl = $url;
return $this->onChangeUrl(
$this->updateOnPreviewUrl,
method: HttpMethod::PUT,
events: $events
);
}
|
@param Closure(mixed $data, mixed $value, FieldContract $field): string $url
|
setUpdateOnPreviewUrl
|
php
|
moonshine-software/moonshine
|
src/UI/src/Traits/Fields/UpdateOnPreview.php
|
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/UpdateOnPreview.php
|
MIT
|
public function link(
string|Closure $link,
string|Closure $name = '',
?string $icon = null,
bool $withoutIcon = false,
bool $blank = false,
): static {
$this->isLink = true;
$this->linkIcon = $icon;
$this->withoutIcon = $withoutIcon;
$this->linkValue = $link;
$this->linkName = $name;
$this->linkBlank = $blank;
return $this;
}
|
@param string|(Closure(string $value, static $ctx): string) $link
@param string|(Closure(string $value, static $ctx): string) $name
|
link
|
php
|
moonshine-software/moonshine
|
src/UI/src/Traits/Fields/WithLink.php
|
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/WithLink.php
|
MIT
|
public function sortable(Closure|string|null $callback = null): static
{
$this->sortable = true;
$this->sortableCallback = $callback;
return $this;
}
|
Define whether if index page can be sorted by this field
|
sortable
|
php
|
moonshine-software/moonshine
|
src/UI/src/Traits/Fields/WithSorts.php
|
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Fields/WithSorts.php
|
MIT
|
public function vertical(null|Closure|int $title = null, null|Closure|int $value = null): static
{
$this->isVertical = true;
$this->verticalTitleCallback = $title;
$this->verticalValueCallback = $value;
return $this;
}
|
@param null|int|Closure(FieldContract $field, ComponentContract $default, static $ctx): ComponentContract $title
@param null|int|Closure(FieldContract $field, ComponentContract $default, static $ctx): ComponentContract $value
|
vertical
|
php
|
moonshine-software/moonshine
|
src/UI/src/Traits/Table/TableStates.php
|
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Table/TableStates.php
|
MIT
|
public function removeAfterClone(): static
{
return $this->customAttributes([
'data-remove-after-clone' => 1,
]);
}
|
Remove empty table row after clone
|
removeAfterClone
|
php
|
moonshine-software/moonshine
|
src/UI/src/Traits/Table/TableStates.php
|
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Table/TableStates.php
|
MIT
|
public function statesToArray(): array
{
return [
'preview' => $this->isPreview(),
'notfound' => $this->hasNotFound(),
'creatable' => $this->isCreatable(),
'reindex' => $this->isReindex(),
'reorderable' => $this->isReorderable(),
'simple' => $this->isSimple(),
'sticky' => $this->isSticky(),
'stickyButtons' => $this->isStickyButtons(),
'lazy' => $this->isLazy(),
'columnSelection' => $this->isColumnSelection(),
'searchable' => $this->isSearchable(),
'searchValue' => $this->getCore()->getRequest()->getScalar('search', ''),
];
}
|
@return array{
preview: bool,
notfound: bool,
creatable: bool,
reindex: bool,
reorderable: bool,
simple: bool,
sticky: bool,
stickyButtons: bool,
searchable: bool,
searchValue: string,
columnSelection: bool,
}
|
statesToArray
|
php
|
moonshine-software/moonshine
|
src/UI/src/Traits/Table/TableStates.php
|
https://github.com/moonshine-software/moonshine/blob/master/src/UI/src/Traits/Table/TableStates.php
|
MIT
|
protected function defineRoutes($router): void
{
$router->get('/quick-page', QuickPageController::class)->name('tests.quick-page');
}
|
Define routes setup.
@param \Illuminate\Routing\Router $router
@return void
|
defineRoutes
|
php
|
moonshine-software/moonshine
|
tests/TestCase.php
|
https://github.com/moonshine-software/moonshine/blob/master/tests/TestCase.php
|
MIT
|
public function redeem($code, string $email = null)
{
$invite = $this->prep($code, $email);
$invite->increment('uses');
}
|
@param $code
@param string|null $email
@throws ExpiredInviteCode
@throws InvalidInviteCode
@throws MaxUsesReached
@throws NotYourInviteCode
|
redeem
|
php
|
clarkeash/doorman
|
src/Doorman.php
|
https://github.com/clarkeash/doorman/blob/master/src/Doorman.php
|
MIT
|
public function check($code, string $email = null)
{
try {
$this->prep($code, $email);
return true;
} catch (DoormanException $e) {
$this->error = $e->getMessage();
return false;
}
}
|
@param $code
@param string|null $email
@return bool
|
check
|
php
|
clarkeash/doorman
|
src/Doorman.php
|
https://github.com/clarkeash/doorman/blob/master/src/Doorman.php
|
MIT
|
protected function prep($code, string $email = null)
{
$this->error = '';
$invite = $this->lookupInvite($code);
$this->validateInvite($invite, $email);
return $invite;
}
|
@param $code
@param string|null $email
@return \Clarkeash\Doorman\Models\BaseInvite
@throws \Clarkeash\Doorman\Exceptions\ExpiredInviteCode
@throws \Clarkeash\Doorman\Exceptions\InvalidInviteCode
@throws \Clarkeash\Doorman\Exceptions\MaxUsesReached
@throws \Clarkeash\Doorman\Exceptions\NotYourInviteCode
|
prep
|
php
|
clarkeash/doorman
|
src/Doorman.php
|
https://github.com/clarkeash/doorman/blob/master/src/Doorman.php
|
MIT
|
protected function lookupInvite($code): BaseInvite
{
try {
return $this->invite->where('code', '=', Str::upper($code))->firstOrFail();
} catch (ModelNotFoundException $e) {
throw new InvalidInviteCode(trans('doorman::messages.invalid', ['code' => $code]));
}
}
|
@param $code
@return \Clarkeash\Doorman\Models\BaseInvite
@throws \Clarkeash\Doorman\Exceptions\InvalidInviteCode
|
lookupInvite
|
php
|
clarkeash/doorman
|
src/Doorman.php
|
https://github.com/clarkeash/doorman/blob/master/src/Doorman.php
|
MIT
|
protected function validateInvite(BaseInvite $invite, string $email = null)
{
if ($invite->isFull()) {
throw new MaxUsesReached(trans('doorman::messages.maxed', ['code' => $invite->code]));
}
if ($invite->hasExpired()) {
throw new ExpiredInviteCode(trans('doorman::messages.expired', ['code' => $invite->code]));
}
if ($invite->isRestricted() && !$invite->isRestrictedFor($email)) {
throw new NotYourInviteCode(trans('doorman::messages.restricted', ['code' => $invite->code]));
}
}
|
@param \Clarkeash\Doorman\Models\BaseInvite $invite
@param string|null $email
@throws \Clarkeash\Doorman\Exceptions\ExpiredInviteCode
@throws \Clarkeash\Doorman\Exceptions\MaxUsesReached
@throws \Clarkeash\Doorman\Exceptions\NotYourInviteCode
|
validateInvite
|
php
|
clarkeash/doorman
|
src/Doorman.php
|
https://github.com/clarkeash/doorman/blob/master/src/Doorman.php
|
MIT
|
public function getDefaultDriver()
{
return $this->container['config']['doorman.driver'];
}
|
Get the default driver name.
@return DriverInterface
|
getDefaultDriver
|
php
|
clarkeash/doorman
|
src/DoormanManager.php
|
https://github.com/clarkeash/doorman/blob/master/src/DoormanManager.php
|
MIT
|
public function for(string $email)
{
if ($this->invite->where('for', strtolower($email))->first()) {
throw new DuplicateException('You cannot create more than 1 invite code for an email');
}
$this->email = $email;
return $this;
}
|
@param string $email
@return $this
@throws \Clarkeash\Doorman\Exceptions\DuplicateException
|
for
|
php
|
clarkeash/doorman
|
src/Generator.php
|
https://github.com/clarkeash/doorman/blob/master/src/Generator.php
|
MIT
|
protected function build(): BaseInvite
{
$invite = app()->make(BaseInvite::class);
$invite->code = Str::upper($this->manager->code());
$invite->for = $this->email;
$invite->max = $this->uses;
$invite->valid_until = $this->expiry;
return $invite;
}
|
@return \Clarkeash\Doorman\Models\BaseInvite
@throws \Illuminate\Contracts\Container\BindingResolutionException
|
build
|
php
|
clarkeash/doorman
|
src/Generator.php
|
https://github.com/clarkeash/doorman/blob/master/src/Generator.php
|
MIT
|
public function make()
{
$invites = collect();
if (!is_null($this->email) && $this->amount > 1) {
throw new DuplicateException('You cannot create more than 1 invite code for an email');
}
for ($i = 0; $i < $this->amount; $i++) {
$invite = $this->build();
$invites->push($invite);
$invite->save();
}
return $invites;
}
|
@return \Illuminate\Support\Collection
@throws DuplicateException
@throws \Illuminate\Contracts\Container\BindingResolutionException
|
make
|
php
|
clarkeash/doorman
|
src/Generator.php
|
https://github.com/clarkeash/doorman/blob/master/src/Generator.php
|
MIT
|
public function once(): BaseInvite
{
return tap($this->build())->save();
}
|
@return BaseInvite
@throws \Illuminate\Contracts\Container\BindingResolutionException
|
once
|
php
|
clarkeash/doorman
|
src/Generator.php
|
https://github.com/clarkeash/doorman/blob/master/src/Generator.php
|
MIT
|
public function handle()
{
$useless = $this->invite->useless()->count();
$this->invite->useless()->delete();
$this->info('Successfully deleted ' . $useless . ' expired invites from the database.');
}
|
Execute the console command.
@return mixed
|
handle
|
php
|
clarkeash/doorman
|
src/Commands/CleanupCommand.php
|
https://github.com/clarkeash/doorman/blob/master/src/Commands/CleanupCommand.php
|
MIT
|
public function handle(): void
{
try {
/** @var Generator $generator */
$generator = Doorman::generate();
if ($this->option('email')) {
$generator->for($this->option('email'));
}
if ($this->option('uses')) {
$generator->uses($this->option('uses'));
}
if ($this->option('unlimited')) {
$generator->unlimited();
}
if ($this->option('expiry')) {
$generator->expiresOn(Carbon::parse($this->option('expiry'))->endOfDay());
}
$invite = $generator->once();
$this->info('Successfully created invite code: ' . $invite->code);
} catch (\Exception $e) {
$this->error('Failed to create invite code: ' . $e->getMessage());
}
}
|
Execute the console command.
@return void
|
handle
|
php
|
clarkeash/doorman
|
src/Commands/MakeCommand.php
|
https://github.com/clarkeash/doorman/blob/master/src/Commands/MakeCommand.php
|
MIT
|
public function code(): string
{
return Str::random(config('doorman.basic.length', 5));
}
|
Create an invite code.
@return string
|
code
|
php
|
clarkeash/doorman
|
src/Drivers/BasicDriver.php
|
https://github.com/clarkeash/doorman/blob/master/src/Drivers/BasicDriver.php
|
MIT
|
public function code(): string
{
$version = config('doorman.uuid.version', 4);
$method = 'createVersion' . $version . 'Uuid';
if (method_exists($this, $method)) {
return $this->$method();
}
throw new InvalidArgumentException("Version [$version] not supported.");
}
|
Create an invite code.
@return string
|
code
|
php
|
clarkeash/doorman
|
src/Drivers/UuidDriver.php
|
https://github.com/clarkeash/doorman/blob/master/src/Drivers/UuidDriver.php
|
MIT
|
public function hasExpired(): bool
{
if (is_null($this->valid_until)) {
return false;
}
return $this->valid_until->isPast();
}
|
Has the invite expired.
@return bool
|
hasExpired
|
php
|
clarkeash/doorman
|
src/Models/Invite.php
|
https://github.com/clarkeash/doorman/blob/master/src/Models/Invite.php
|
MIT
|
public function isFull(): bool
{
if ($this->max == 0) {
return false;
}
return $this->uses >= $this->max;
}
|
Is the invite full.
@return bool
|
isFull
|
php
|
clarkeash/doorman
|
src/Models/Invite.php
|
https://github.com/clarkeash/doorman/blob/master/src/Models/Invite.php
|
MIT
|
public function isRestricted(): bool
{
return !is_null($this->for);
}
|
Is the invite restricted to a user.
@return bool
|
isRestricted
|
php
|
clarkeash/doorman
|
src/Models/Invite.php
|
https://github.com/clarkeash/doorman/blob/master/src/Models/Invite.php
|
MIT
|
public function isRestrictedFor($email): bool
{
return strtolower($email) == $this->for;
}
|
Is the invite restricted for a particular user.
@param string $email
@return bool
|
isRestrictedFor
|
php
|
clarkeash/doorman
|
src/Models/Invite.php
|
https://github.com/clarkeash/doorman/blob/master/src/Models/Invite.php
|
MIT
|
public function isUseless(): bool
{
return $this->hasExpired() || $this->isFull();
}
|
Can the invite be used anymore.
@return bool
|
isUseless
|
php
|
clarkeash/doorman
|
src/Models/Invite.php
|
https://github.com/clarkeash/doorman/blob/master/src/Models/Invite.php
|
MIT
|
public function scopeExpired(Builder $query): Builder
{
return $query->where('valid_until', '<', Carbon::now(config('app.timezone')));
}
|
Scope a query to only include expired invites.
@param \Illuminate\Database\Eloquent\Builder $query
@return \Illuminate\Database\Eloquent\Builder
|
scopeExpired
|
php
|
clarkeash/doorman
|
src/Models/Invite.php
|
https://github.com/clarkeash/doorman/blob/master/src/Models/Invite.php
|
MIT
|
public function scopeFull(Builder $query): Builder
{
return $query->where('max', '!=', 0)->whereRaw('uses = max');
}
|
Scope a query to only include full invites.
@param \Illuminate\Database\Eloquent\Builder $query
@return \Illuminate\Database\Eloquent\Builder
|
scopeFull
|
php
|
clarkeash/doorman
|
src/Models/Invite.php
|
https://github.com/clarkeash/doorman/blob/master/src/Models/Invite.php
|
MIT
|
public function scopeUseless(Builder $query): Builder
{
return $query
->where(function ($q) {
$this->scopeExpired($q);
})
->orWhere(function ($q) {
$this->scopeFull($q);
});
}
|
Scope a query to only include useless invites.
@param \Illuminate\Database\Eloquent\Builder $query
@return \Illuminate\Database\Eloquent\Builder
|
scopeUseless
|
php
|
clarkeash/doorman
|
src/Models/Invite.php
|
https://github.com/clarkeash/doorman/blob/master/src/Models/Invite.php
|
MIT
|
public function passes($attribute, $value)
{
return $this->doorman->check($value, $this->email);
}
|
Determine if the validation rule passes.
@param string $attribute
@param mixed $value
@return bool
|
passes
|
php
|
clarkeash/doorman
|
src/Validation/DoormanRule.php
|
https://github.com/clarkeash/doorman/blob/master/src/Validation/DoormanRule.php
|
MIT
|
public function message()
{
return $this->doorman->error;
}
|
Get the validation error message.
@return string|array
|
message
|
php
|
clarkeash/doorman
|
src/Validation/DoormanRule.php
|
https://github.com/clarkeash/doorman/blob/master/src/Validation/DoormanRule.php
|
MIT
|
protected function getPackageProviders($app)
{
return [
DoormanServiceProvider::class
];
}
|
Get package providers.
@param \Illuminate\Foundation\Application $app
@return array
|
getPackageProviders
|
php
|
clarkeash/doorman
|
tests/TestCase.php
|
https://github.com/clarkeash/doorman/blob/master/tests/TestCase.php
|
MIT
|
protected function getPackageAliases($app)
{
return [
'Doorman' => Doorman::class
];
}
|
Get package aliases.
@param \Illuminate\Foundation\Application $app
@return array
|
getPackageAliases
|
php
|
clarkeash/doorman
|
tests/TestCase.php
|
https://github.com/clarkeash/doorman/blob/master/tests/TestCase.php
|
MIT
|
protected function getEnvironmentSetUp($app)
{
// Setup default database to use sqlite :memory:
$app['config']->set('database.default', 'testbench');
$app['config']->set('database.connections.testbench', [
'driver' => 'sqlite',
'database' => ':memory:',
'prefix' => '',
]);
}
|
Define environment setup.
@param \Illuminate\Foundation\Application $app
@return void
|
getEnvironmentSetUp
|
php
|
clarkeash/doorman
|
tests/TestCase.php
|
https://github.com/clarkeash/doorman/blob/master/tests/TestCase.php
|
MIT
|
static function sql($Query)
{
$args = func_get_args ();
if (get_class ( self::$Db ) == "PDO")
return call_user_func_array ( "self::sqlPdo", $args );
else
if (get_class ( self::$Db ) == "mysqli")
return call_user_func_array ( "self::sqlMysqli", $args );
else
throw new Exception ( "Unknown database interface type." );
}
|
The Jf::sql function. The behavior of this function is as follows:
* On queries with no parameters, it should use query function and fetch all results (no prepared statement)
* On queries with parameters, parameters are provided as question marks (?) and then additional function arguments will be
bound to question marks.
* On SELECT, it will return 2D array of results or NULL if no result.
* On DELETE, UPDATE it returns affected rows
* On INSERT, if auto-increment is available last insert id, otherwise affected rows
@todo currently sqlite always returns sequence number for lastInsertId, so there's no way of knowing if insert worked instead of execute result. all instances of ==1 replaced with >=1 to check for insert
@param string $Query
@throws Exception
@return array|integer|null
|
sql
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/Jf.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/Jf.php
|
Apache-2.0
|
function add($Title, $Description, $ParentID = null)
{
if ($ParentID === null)
$ParentID = $this->rootId ();
return (int)$this->{$this->type ()}->insertChildData ( array ("Title" => $Title, "Description" => $Description ), "ID=?", $ParentID );
}
|
Adds a new role or permission
Returns new entry's ID
@param string $Title
Title of the new entry
@param string $Description
Description of the new entry
@param integer $ParentID
optional ID of the parent node in the hierarchy
@return integer ID of the new entry
|
add
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function addPath($Path, array $Descriptions = null)
{
if ($Path[0] !== "/")
throw new \Exception ("The path supplied is not valid.");
$Path = substr ( $Path, 1 );
$Parts = explode ( "/", $Path );
$Parent = 1;
$index = 0;
$CurrentPath = "";
$NodesCreated = 0;
foreach ($Parts as $p)
{
if (isset ($Descriptions[$index]))
$Description = $Descriptions[$index];
else
$Description = "";
$CurrentPath .= "/{$p}";
$t = $this->pathId($CurrentPath);
if (! $t)
{
$IID = $this->add($p, $Description, $Parent);
$Parent = $IID;
$NodesCreated++;
}
else
{
$Parent = $t;
}
$index += 1;
}
return (int)$NodesCreated;
}
|
Adds a path and all its components.
Will not replace or create siblings if a component exists.
@param string $Path
such as /some/role/some/where - Must begin with a / (slash)
@param array $Descriptions
array of descriptions (will add with empty description if not available)
@return integer Number of nodes created (0 if none created)
|
addPath
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function count()
{
$Res = Jf::sql ( "SELECT COUNT(*) FROM {$this->tablePrefix()}{$this->type()}" );
return (int)$Res [0] ['COUNT(*)'];
}
|
Return count of the entity
@return integer
|
count
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
public function returnId($entity = null)
{
if (substr ($entity, 0, 1) == "/") {
$entityID = $this->pathId($entity);
} else {
$entityID = $this->titleId($entity);
}
return $entityID;
}
|
Returns ID of entity
@param string $entity (Path or Title)
@return mixed ID of entity or null
|
returnId
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
public function titleId($Title)
{
return $this->{$this->type ()}->getID ( "Title=?", $Title );
}
|
Returns ID belonging to a title, and the first one on that
@param string $Title
@return integer Id of specified Title
|
titleId
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
protected function getRecord($ID)
{
$args = func_get_args ();
return call_user_func_array ( array ($this->{$this->type ()}, "getRecord" ), $args );
}
|
Return the whole record of a single entry (including Rght and Lft fields)
@param integer $ID
|
getRecord
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function getTitle($ID)
{
$r = $this->getRecord ( "ID=?", $ID );
if ($r)
return $r ['Title'];
else
return null;
}
|
Returns title of entity
@param integer $ID
@return string NULL
|
getTitle
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function getPath($ID)
{
$res = $this->{$this->type ()}->pathConditional ( "ID=?", $ID );
$out = null;
if (is_array ( $res ))
foreach ( $res as $r )
if ($r ['ID'] == 1)
$out = '/';
else
$out .= "/" . $r ['Title'];
if (strlen ( $out ) > 1)
return substr ( $out, 1 );
else
return $out;
}
|
Returns path of a node
@param integer $ID
@return string path
|
getPath
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function getDescription($ID)
{
$r = $this->getRecord ( "ID=?", $ID );
if ($r)
return $r ['Description'];
else
return null;
}
|
Return description of entity
@param integer $ID
@return string NULL
|
getDescription
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function edit($ID, $NewTitle = null, $NewDescription = null)
{
$Data = array ();
if ($NewTitle !== null)
$Data ['Title'] = $NewTitle;
if ($NewDescription !== null)
$Data ['Description'] = $NewDescription;
return $this->{$this->type ()}->editData ( $Data, "ID=?", $ID ) == 1;
}
|
Edits an entity, changing title and/or description. Maintains Id.
@param integer $ID
@param string $NewTitle
@param string $NewDescription
|
edit
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function children($ID)
{
return $this->{$this->type ()}->childrenConditional ( "ID=?", $ID );
}
|
Returns children of an entity
@param integer $ID
@return array
|
children
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function descendants($ID)
{
$res = $this->{$this->type ()}->descendantsConditional(/* absolute depths*/false, "ID=?", $ID );
$out = array ();
if (is_array ( $res ))
foreach ( $res as $v )
$out [$v ['Title']] = $v;
return $out;
}
|
Returns descendants of a node, with their depths in integer
@param integer $ID
@return array with keys as titles and Title,ID, Depth and Description
|
descendants
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function depth($ID)
{
return $this->{$this->type ()}->depthConditional ( "ID=?", $ID );
}
|
Return depth of a node
@param integer $ID
|
depth
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function parentNode($ID)
{
return $this->{$this->type ()}->parentNodeConditional ( "ID=?", $ID );
}
|
Returns parent of a node
@param integer $ID
@return array including Title, Description and ID
|
parentNode
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function reset($Ensure = false)
{
if ($Ensure !== true)
{
throw new \Exception ("You must pass true to this function, otherwise it won't work.");
return;
}
$res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}{$this->type()}" );
$Adapter = get_class(Jf::$Db);
if ($this->isMySql())
Jf::sql ( "ALTER TABLE {$this->tablePrefix()}{$this->type()} AUTO_INCREMENT=1 " );
elseif ($this->isSQLite())
Jf::sql ( "delete from sqlite_sequence where name=? ", $this->tablePrefix () . "{$this->type()}" );
else
throw new \Exception ( "Rbac can not reset table on this type of database: {$Adapter}" );
$iid = Jf::sql ( "INSERT INTO {$this->tablePrefix()}{$this->type()} (Title,Description,Lft,Rght) VALUES (?,?,?,?)", "root", "root",0,1 );
return (int)$res;
}
|
Reset the table back to its initial state
Keep in mind that this will not touch relations
@param boolean $Ensure
must be true to work, otherwise an \Exception is thrown
@throws \Exception
@return integer number of deleted entries
|
reset
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function assign($Role, $Permission)
{
if (is_numeric($Role))
{
$RoleID = $Role;
} else {
if (substr($Role, 0, 1) == "/")
$RoleID = Jf::$Rbac->Roles->pathId($Role);
else
$RoleID = Jf::$Rbac->Roles->titleId($Role);
}
if (is_numeric($Permission))
{
$PermissionID = $Permission;
} else {
if (substr($Permission, 0, 1) == "/")
$PermissionID = Jf::$Rbac->Permissions->pathId($Permission);
else
$PermissionID = Jf::$Rbac->Permissions->titleId($Permission);
}
return Jf::sql("INSERT INTO {$this->tablePrefix()}rolepermissions
(RoleID,PermissionID,AssignmentDate)
VALUES (?,?,?)", $RoleID, $PermissionID, Jf::time()) >= 1;
}
|
Assigns a role to a permission (or vice-verse)
@param mixed $Role
Id, Title and Path
@param mixed $Permission
Id, Title and Path
@return boolean inserted or existing
@todo: Check for valid permissions/roles
@todo: Implement custom error handler
|
assign
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function unassign($Role, $Permission)
{
if (is_numeric($Role))
{
$RoleID = $Role;
} else {
if (substr($Role, 0, 1) == "/")
$RoleID = Jf::$Rbac->Roles->pathId($Role);
else
$RoleID = Jf::$Rbac->Roles->titleId($Role);
}
if (is_numeric($Permission))
{
$PermissionID = $Permission;
} else {
if (substr($Permission, 0, 1) == "/")
$PermissionID = Jf::$Rbac->Permissions->pathId($Permission);
else
$PermissionID = Jf::$Rbac->Permissions->titleId($Permission);
}
return Jf::sql("DELETE FROM {$this->tablePrefix()}rolepermissions WHERE
RoleID=? AND PermissionID=?", $RoleID, $PermissionID) == 1;
}
|
Unassigns a role-permission relation
@param mixed $Role
Id, Title and Path
@param mixed $Permission:
Id, Title and Path
@return boolean
|
unassign
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function resetAssignments($Ensure = false)
{
if ($Ensure !== true)
{
throw new \Exception ("You must pass true to this function, otherwise it won't work.");
return;
}
$res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}rolepermissions" );
$Adapter = get_class(Jf::$Db);
if ($this->isMySql())
Jf::sql ( "ALTER TABLE {$this->tablePrefix()}rolepermissions AUTO_INCREMENT =1 " );
elseif ($this->isSQLite())
Jf::sql ( "delete from sqlite_sequence where name=? ", $this->tablePrefix () . "_rolepermissions" );
else
throw new \Exception ( "Rbac can not reset table on this type of database: {$Adapter}" );
$this->assign ( $this->rootId(), $this->rootId());
return $res;
}
|
Remove all role-permission relations
mostly used for testing
@param boolean $Ensure
must be set to true or throws an \Exception
@return number of deleted assignments
|
resetAssignments
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function assign($Role, $Permission)
{
return $this->Roles->assign($Role, $Permission);
}
|
Assign a role to a permission.
Alias for what's in the base class
@param string|integer $Role
Id, Title or Path
@param string|integer $Permission
Id, Title or Path
@return boolean
|
assign
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function check($Permission, $UserID = null)
{
if ($UserID === null)
throw new \RbacUserNotProvidedException ("\$UserID is a required argument.");
// convert permission to ID
if (is_numeric ( $Permission ))
{
$PermissionID = $Permission;
}
else
{
if (substr ( $Permission, 0, 1 ) == "/")
$PermissionID = $this->Permissions->pathId ( $Permission );
else
$PermissionID = $this->Permissions->titleId ( $Permission );
}
// if invalid, throw exception
if ($PermissionID === null)
throw new RbacPermissionNotFoundException ( "The permission '{$Permission}' not found." );
if ($this->isSQLite())
{
$LastPart="AS Temp ON ( TR.ID = Temp.RoleID)
WHERE
TUrel.UserID=?
AND
Temp.ID=?";
}
else //mysql
{
$LastPart="ON ( TR.ID = TRel.RoleID)
WHERE
TUrel.UserID=?
AND
TPdirect.ID=?";
}
$Res=Jf::sql ( "SELECT COUNT(*) AS Result
FROM
{$this->tablePrefix()}userroles AS TUrel
JOIN {$this->tablePrefix()}roles AS TRdirect ON (TRdirect.ID=TUrel.RoleID)
JOIN {$this->tablePrefix()}roles AS TR ON ( TR.Lft BETWEEN TRdirect.Lft AND TRdirect.Rght)
JOIN
( {$this->tablePrefix()}permissions AS TPdirect
JOIN {$this->tablePrefix()}permissions AS TP ON ( TPdirect.Lft BETWEEN TP.Lft AND TP.Rght)
JOIN {$this->tablePrefix()}rolepermissions AS TRel ON (TP.ID=TRel.PermissionID)
) $LastPart",
$UserID, $PermissionID );
return $Res [0] ['Result'] >= 1;
}
|
Checks whether a user has a permission or not.
@param string|integer $Permission
you can provide a path like /some/permission, a title, or the
permission ID.
in case of ID, don't forget to provide integer (not a string
containing a number)
@param string|integer $UserID
User ID of a user
@throws RbacPermissionNotFoundException
@throws RbacUserNotProvidedException
@return boolean
|
check
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function enforce($Permission, $UserID = null)
{
if ($UserID === null)
throw new \RbacUserNotProvidedException ("\$UserID is a required argument.");
if (! $this->check($Permission, $UserID)) {
header('HTTP/1.1 403 Forbidden');
die("<strong>Forbidden</strong>: You do not have permission to access this resource.");
}
return true;
}
|
Enforce a permission on a user
@param string|integer $Permission
path or title or ID of permission
@param integer $UserID
@throws RbacUserNotProvidedException
|
enforce
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function reset($Ensure = false)
{
if ($Ensure !== true) {
throw new \Exception ("You must pass true to this function, otherwise it won't work.");
return;
}
$res = true;
$res = $res and $this->Roles->resetAssignments ( true );
$res = $res and $this->Roles->reset ( true );
$res = $res and $this->Permissions->reset ( true );
$res = $res and $this->Users->resetAssignments ( true );
return $res;
}
|
Remove all roles, permissions and assignments
mostly used for testing
@param boolean $Ensure
must set or throws error
@return boolean
|
reset
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function remove($ID, $Recursive = false)
{
$this->unassignRoles ( $ID );
if (! $Recursive)
return $this->permissions->deleteConditional ( "ID=?", $ID );
else
return $this->permissions->deleteSubtreeConditional ( "ID=?", $ID );
}
|
Remove permissions from system
@param integer $ID
permission id
@param boolean $Recursive
delete all descendants
|
remove
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function unassignRoles($ID)
{
$res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}rolepermissions WHERE
PermissionID=?", $ID );
return (int)$res;
}
|
Unassignes all roles of this permission, and returns their number
@param integer $ID
Permission Id
@return integer
|
unassignRoles
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function roles($Permission, $OnlyIDs = true)
{
if (!is_numeric($Permission))
$Permission = $this->returnId($Permission);
if ($OnlyIDs)
{
$Res = Jf::sql ( "SELECT RoleID AS `ID` FROM
{$this->tablePrefix()}rolepermissions WHERE PermissionID=? ORDER BY RoleID", $Permission );
if (is_array ( $Res ))
{
$out = array ();
foreach ( $Res as $R )
$out [] = $R ['ID'];
return $out;
}
else
return null;
} else {
return Jf::sql ( "SELECT `TP`.ID, `TP`.Title, `TP`.Description FROM {$this->tablePrefix()}roles AS `TP`
LEFT JOIN {$this->tablePrefix()}rolepermissions AS `TR` ON (`TR`.RoleID=`TP`.ID)
WHERE PermissionID=? ORDER BY TP.ID", $Permission );
}
}
|
Returns all roles assigned to a permission
@param mixed $Permission
Id, Title, Path
@param boolean $OnlyIDs
if true, result will be a 1D array of IDs
@return Array 2D or 1D or null
|
roles
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function remove($ID, $Recursive = false)
{
$this->unassignPermissions ( $ID );
$this->unassignUsers ( $ID );
if (! $Recursive)
return $this->roles->deleteConditional ( "ID=?", $ID );
else
return $this->roles->deleteSubtreeConditional ( "ID=?", $ID );
}
|
Remove roles from system
@param integer $ID
role id
@param boolean $Recursive
delete all descendants
|
remove
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function unassignPermissions($ID)
{
$r = Jf::sql ( "DELETE FROM {$this->tablePrefix()}rolepermissions WHERE
RoleID=? ", $ID );
return $r;
}
|
Unassigns all permissions belonging to a role
@param integer $ID
role ID
@return integer number of assignments deleted
|
unassignPermissions
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function unassignUsers($ID)
{
return Jf::sql ( "DELETE FROM {$this->tablePrefix()}userroles WHERE
RoleID=?", $ID );
}
|
Unassign all users that have a certain role
@param integer $ID
role ID
@return integer number of deleted assignments
|
unassignUsers
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function hasPermission($Role, $Permission)
{
$Res = Jf::sql ( "
SELECT COUNT(*) AS Result
FROM {$this->tablePrefix()}rolepermissions AS TRel
JOIN {$this->tablePrefix()}permissions AS TP ON ( TP.ID= TRel.PermissionID)
JOIN {$this->tablePrefix()}roles AS TR ON ( TR.ID = TRel.RoleID)
WHERE TR.Lft BETWEEN
(SELECT Lft FROM {$this->tablePrefix()}roles WHERE ID=?)
AND
(SELECT Rght FROM {$this->tablePrefix()}roles WHERE ID=?)
/* the above section means any row that is a descendants of our role (if descendant roles have some permission, then our role has it two) */
AND TP.ID IN (
SELECT parent.ID
FROM {$this->tablePrefix()}permissions AS node,
{$this->tablePrefix()}permissions AS parent
WHERE node.Lft BETWEEN parent.Lft AND parent.Rght
AND ( node.ID=? )
ORDER BY parent.Lft
);
/*
the above section returns all the parents of (the path to) our permission, so if one of our role or its descendants
has an assignment to any of them, we're good.
*/
", $Role, $Role, $Permission );
return $Res [0] ['Result'] >= 1;
}
|
Checks to see if a role has a permission or not
@param integer $Role
ID
@param integer $Permission
ID
@return boolean
@todo: If we pass a Role that doesn't exist the method just returns false. We may want to check for a valid Role.
|
hasPermission
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function permissions($Role, $OnlyIDs = true)
{
if (! is_numeric ($Role))
$Role = $this->returnId($Role);
if ($OnlyIDs)
{
$Res = Jf::sql ( "SELECT PermissionID AS `ID` FROM {$this->tablePrefix()}rolepermissions WHERE RoleID=? ORDER BY PermissionID", $Role );
if (is_array ( $Res ))
{
$out = array ();
foreach ( $Res as $R )
$out [] = $R ['ID'];
return $out;
}
else
return null;
} else {
return Jf::sql ( "SELECT `TP`.ID, `TP`.Title, `TP`.Description FROM {$this->tablePrefix()}permissions AS `TP`
LEFT JOIN {$this->tablePrefix()}rolepermissions AS `TR` ON (`TR`.PermissionID=`TP`.ID)
WHERE RoleID=? ORDER BY TP.ID", $Role );
}
}
|
Returns all permissions assigned to a role
@param integer $Role
ID
@param boolean $OnlyIDs
if true, result would be a 1D array of IDs
@return Array 2D or 1D or null
the two dimensional array would have ID,Title and Description of permissions
|
permissions
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function hasRole($Role, $UserID = null)
{
if ($UserID === null)
throw new \RbacUserNotProvidedException ("\$UserID is a required argument.");
if (is_numeric ( $Role ))
{
$RoleID = $Role;
}
else
{
if (substr ( $Role, 0, 1 ) == "/")
$RoleID = Jf::$Rbac->Roles->pathId ( $Role );
else
$RoleID = Jf::$Rbac->Roles->titleId ( $Role );
}
$R = Jf::sql ( "SELECT * FROM {$this->tablePrefix()}userroles AS TUR
JOIN {$this->tablePrefix()}roles AS TRdirect ON (TRdirect.ID=TUR.RoleID)
JOIN {$this->tablePrefix()}roles AS TR ON (TR.Lft BETWEEN TRdirect.Lft AND TRdirect.Rght)
WHERE
TUR.UserID=? AND TR.ID=?", $UserID, $RoleID );
return $R !== null;
}
|
Checks to see whether a user has a role or not
@param integer|string $Role
id, title or path
@param integer $User
UserID, not optional
@throws RbacUserNotProvidedException
@return boolean success
|
hasRole
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function assign($Role, $UserID = null)
{
if ($UserID === null)
throw new \RbacUserNotProvidedException ("\$UserID is a required argument.");
if (is_numeric($Role))
{
$RoleID = $Role;
} else {
if (substr($Role, 0, 1) == "/")
$RoleID = Jf::$Rbac->Roles->pathId($Role);
else
$RoleID = Jf::$Rbac->Roles->titleId($Role);
}
$res = Jf::sql ( "INSERT INTO {$this->tablePrefix()}userroles
(UserID,RoleID,AssignmentDate)
VALUES (?,?,?)
", $UserID, $RoleID, Jf::time () );
return $res >= 1;
}
|
Assigns a role to a user
@param mixed $Role
Id, Path or Title
@param integer $UserID
UserID (use 0 for guest)
@throws RbacUserNotProvidedException
@return boolean inserted or existing
|
assign
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function unassign($Role, $UserID = null)
{
if ($UserID === null)
throw new \RbacUserNotProvidedException ("\$UserID is a required argument.");
if (is_numeric($Role))
{
$RoleID = $Role;
} else {
if (substr($Role, 0, 1) == "/")
$RoleID = Jf::$Rbac->Roles->pathId($Role);
else
$RoleID = Jf::$Rbac->Roles->titleId($Role);
}
return Jf::sql("DELETE FROM {$this->tablePrefix()}userroles WHERE UserID=? AND RoleID=?", $UserID, $RoleID) >= 1;
}
|
Unassigns a role from a user
@param mixed $Role
Id, Title, Path
@param integer $UserID
UserID (use 0 for guest)
@throws RbacUserNotProvidedException
@return boolean success
|
unassign
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function allRoles($UserID = null)
{
if ($UserID === null)
throw new \RbacUserNotProvidedException ("\$UserID is a required argument.");
return Jf::sql ( "SELECT TR.*
FROM
{$this->tablePrefix()}userroles AS `TRel`
JOIN {$this->tablePrefix()}roles AS `TR` ON
(`TRel`.RoleID=`TR`.ID)
WHERE TRel.UserID=?", $UserID );
}
|
Returns all roles of a user
@param integer $UserID
Not optional
@throws RbacUserNotProvidedException
@return array null
|
allRoles
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function roleCount($UserID = null)
{
if ($UserID === null)
throw new \RbacUserNotProvidedException ("\$UserID is a required argument.");
$Res = Jf::sql ( "SELECT COUNT(*) AS Result FROM {$this->tablePrefix()}userroles WHERE UserID=?", $UserID );
return (int)$Res [0] ['Result'];
}
|
Return count of roles assigned to a user
@param integer $UserID
@throws RbacUserNotProvidedException
@return integer Count of Roles assigned to a User
|
roleCount
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
function resetAssignments($Ensure = false)
{
if ($Ensure !== true)
{
throw new \Exception ("You must pass true to this function, otherwise it won't work.");
return;
}
$res = Jf::sql ( "DELETE FROM {$this->tablePrefix()}userroles" );
$Adapter = get_class(Jf::$Db);
if ($this->isMySql())
Jf::sql ( "ALTER TABLE {$this->tablePrefix()}userroles AUTO_INCREMENT =1 " );
elseif ($this->isSQLite())
Jf::sql ( "delete from sqlite_sequence where name=? ", $this->tablePrefix () . "_userroles" );
else
throw new \Exception ("Rbac can not reset table on this type of database: {$Adapter}");
$this->assign ( "root", 1 /* root user */ );
return $res;
}
|
Remove all role-user relations
mostly used for testing
@param boolean $Ensure
must set to true or throws an Exception
@return number of deleted relations
|
resetAssignments
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/rbac.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/rbac.php
|
Apache-2.0
|
protected function assign($Table,$ID,$Left,$Right)
{
$this->Table=$Table;
$this->ID=$ID;
$this->Left=$Left;
$this->Right=$Right;
}
|
Assigns fields of the table
@param String $Table
@param String $ID
@param String $Left
@param String $Right
|
assign
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
function descendantCount($ID)
{
$Res=Jf::sql("SELECT ({$this->right()}-{$this->left()}-1)/2 AS `Count` FROM
{$this->table()} WHERE {$this->id()}=?",$ID);
return sprintf("%d",$Res[0]["Count"])*1;
}
|
Returns number of descendants
@param Integer $ID
@return Integer Count
|
descendantCount
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
function depth($ID)
{
return count($this->path($ID))-1;
}
|
Returns the depth of a node in the tree
Note: this uses path
@param Integer $ID
@return Integer Depth from zero upwards
@seealso path
|
depth
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
function sibling($ID,$SiblingDistance=1)
{
$Parent=$this->parentNode($ID);
$Siblings=$this->children($Parent[$this->id()]);
if (!$Siblings) return null;
foreach ($Siblings as &$Sibling)
{
if ($Sibling[$this->id()]==$ID) break;
$n++;
}
return $Siblings[$n+$SiblingDistance];
}
|
Returns a sibling of the current node
Note: You can't find siblings of roots
Note: this is a heavy function on nested sets, uses both children (which is quite heavy) and path
@param Integer $ID
@param Integer $SiblingDistance from current node (negative or positive)
@return Array Node on success, null on failure
|
sibling
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
function parentNode($ID)
{
$Path=$this->path($ID);
if (count($Path)<2) return null;
else return $Path[count($Path)-2];
}
|
Returns the parent of a node
Note: this uses path
@param Integer $ID
@return Array parentNode (null on failure)
@seealso path
|
parentNode
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
function delete($ID)
{
$Info=Jf::sql("SELECT {$this->left()} AS `Left`,{$this->right()} AS `Right`
FROM {$this->table()}
WHERE {$this->id()} = ?;
",$ID);
$Info=$Info[0];
$count=Jf::sql("DELETE FROM {$this->table()} WHERE {$this->left()} = ?",$Info["Left"]);
Jf::sql("UPDATE {$this->table()} SET {$this->right()} = {$this->right()} - 1, `".
$this->left."` = {$this->left()} - 1 WHERE {$this->left()} BETWEEN ? AND ?",$Info["Left"],$Info["Right"]);
Jf::sql("UPDATE {$this->table()} SET {$this->right()} = {$this->right()} - 2 WHERE `".
$this->Right."` > ?",$Info["Right"]);
Jf::sql("UPDATE {$this->table()} SET {$this->left()} = {$this->left()} - 2 WHERE `".
$this->left."` > ?",$Info["Right"]);
return $count;
}
|
Deletes a node and shifts the children up
@param Integer $ID
|
delete
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
function deleteSubtree($ID)
{
$Info=Jf::sql("SELECT {$this->left()} AS `Left`,{$this->right()} AS `Right` ,{$this->right()}-{$this->left()}+ 1 AS Width
FROM {$this->table()}
WHERE {$this->id()} = ?;
",$ID);
$Info=$Info[0];
$count=Jf::sql("
DELETE FROM {$this->table()} WHERE {$this->left()} BETWEEN ? AND ?
",$Info["Left"],$Info["Right"]);
Jf::sql("
UPDATE {$this->table()} SET {$this->right()} = {$this->right()} - ? WHERE {$this->right()} > ?
",$Info["Width"],$Info["Right"]);
Jf::sql("
UPDATE {$this->table()} SET {$this->left()} = {$this->left()} - ? WHERE {$this->left()} > ?
",$Info["Width"],$Info["Right"]);
return $count;
}
|
Deletes a node and all its descendants
@param Integer $ID
|
deleteSubtree
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
function descendants($ID,$AbsoluteDepths=false)
{
if (!$AbsoluteDepths)
$DepthConcat="- (sub_tree.depth )";
$Res=Jf::sql("
SELECT node.*, (COUNT(parent.{$this->id()})-1 $DepthConcat ) AS Depth
FROM {$this->table()} AS node,
{$this->table()} AS parent,
{$this->table()} AS sub_parent,
(
SELECT node.{$this->id()}, (COUNT(parent.{$this->id()}) - 1) AS depth
FROM {$this->table()} AS node,
{$this->table()} AS parent
WHERE node.{$this->left()} BETWEEN parent.{$this->left()} AND parent.{$this->right()}
AND node.{$this->id()} = ?
GROUP BY node.{$this->id()}
ORDER BY node.{$this->left()}
) AS sub_tree
WHERE node.{$this->left()} BETWEEN parent.{$this->left()} AND parent.{$this->right()}
AND node.{$this->left()} BETWEEN sub_parent.{$this->left()} AND sub_parent.{$this->right()}
AND sub_parent.{$this->id()} = sub_tree.{$this->id()}
GROUP BY node.{$this->id()}
HAVING Depth > 0
ORDER BY node.{$this->left()}",$ID);
return $Res;
}
|
Returns all descendants of a node
@param Integer $ID
@param Boolean $AbsoluteDepths to return Depth of sub-tree from zero or absolutely from the whole tree
@return Rowset including Depth field
@seealso children
|
descendants
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
function children($ID)
{
$Res=Jf::sql("
SELECT node.*, (COUNT(parent.{$this->id()})-1 - (sub_tree.depth )) AS Depth
FROM {$this->table()} AS node,
{$this->table()} AS parent,
{$this->table()} AS sub_parent,
(
SELECT node.{$this->id()}, (COUNT(parent.{$this->id()}) - 1) AS depth
FROM {$this->table()} AS node,
{$this->table()} AS parent
WHERE node.{$this->left()} BETWEEN parent.{$this->left()} AND parent.{$this->right()}
AND node.{$this->id()} = ?
GROUP BY node.{$this->id()}
ORDER BY node.{$this->left()}
) AS sub_tree
WHERE node.{$this->left()} BETWEEN parent.{$this->left()} AND parent.{$this->right()}
AND node.{$this->left()} BETWEEN sub_parent.{$this->left()} AND sub_parent.{$this->right()}
AND sub_parent.{$this->id()} = sub_tree.{$this->id()}
GROUP BY node.{$this->id()}
HAVING Depth = 1
ORDER BY node.{$this->left()};
",$ID);
if ($Res)
foreach ($Res as &$v)
unset($v["Depth"]);
return $Res;
}
|
Returns immediate children of a node
Note: this function performs the same as descendants but only returns results with Depth=1
@param Integer $ID
@return Rowset not including Depth
@seealso descendants
|
children
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
function path($ID)
{
$Res=Jf::sql("
SELECT parent.*
FROM {$this->table()} AS node,
".$this->table." AS parent
WHERE node.{$this->left()} BETWEEN parent.{$this->left()} AND parent.{$this->right()}
AND node.{$this->id()} = ?
ORDER BY parent.{$this->left()}",$ID);
return $Res;
}
|
Returns the path to a node, including the node
@param Integer $ID
@return Rowset nodes in path
|
path
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
function leaves($PID=null)
{
if ($PID)
$Res=Jf::sql("SELECT *
FROM {$this->table()}
WHERE {$this->right()} = {$this->left()} + 1
AND {$this->left()} BETWEEN
(SELECT {$this->left()} FROM {$this->table()} WHERE {$this->id()}=?)
AND
(SELECT {$this->right()} FROM {$this->table()} WHERE {$this->id()}=?)",$PID,$PID);
else
$Res=Jf::sql("SELECT *
FROM {$this->table()}
WHERE {$this->right()} = {$this->left()} + 1");
return $Res;
}
|
Finds all leaves of a parent
Note: if you don' specify $PID, There would be one less AND in the SQL Query
@param Integer $PID
@return Rowset Leaves
|
leaves
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
function insertSibling($ID=0)
{
// $this->DB->AutoQuery("LOCK TABLE {$this->table()} WRITE;");
//Find the Sibling
$Sibl=Jf::sql("SELECT {$this->right()} AS `Right`".
" FROM {$this->table()} WHERE {$this->id()} = ?",$ID);
$Sibl=$Sibl[0];
if ($Sibl==null)
{
$Sibl["Right"]=0;
}
Jf::sql("UPDATE {$this->table()} SET {$this->right()} = {$this->right()} + 2 WHERE {$this->right()} > ?",$Sibl["Right"]);
Jf::sql("UPDATE {$this->table()} SET {$this->left()} = {$this->left()} + 2 WHERE {$this->left()} > ?",$Sibl["Right"]);
$Res= Jf::sql("INSERT INTO {$this->table()} ({$this->left()},{$this->right()}) ".
"VALUES(?,?)",$Sibl["Right"]+1,$Sibl["Right"]+2);
// $this->DB->AutoQuery("UNLOCK TABLES");
return $Res;
}
|
Adds a sibling after a node
@param Integer $ID
@return Integer SiblingID
|
insertSibling
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
function insertChild($PID=0)
{
//Find the Sibling
$Sibl=Jf::sql("SELECT {$this->left()} AS `Left`".
" FROM {$this->table()} WHERE {$this->id()} = ?",$PID);
$Sibl=$Sibl[0];
if ($Sibl==null)
{
$Sibl["Left"]=0;
}
Jf::sql("UPDATE {$this->table()} SET {$this->right()} = {$this->right()} + 2 WHERE {$this->right()} > ?",$Sibl["Left"]);
Jf::sql("UPDATE {$this->table()} SET {$this->left()} = {$this->left()} + 2 WHERE {$this->left()} > ?",$Sibl["Left"]);
$Res=Jf::sql("INSERT INTO {$this->table()} ({$this->left()},{$this->right()}) ".
"VALUES(?,?)",$Sibl["Left"]+1,$Sibl["Left"]+2);
return $Res;
}
|
Adds a child to the beginning of a node's children
@param Integer $PID
@return Integer ChildID
|
insertChild
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
function fullTree()
{
$Res=Jf::sql("SELECT node.*, (COUNT(parent.{$this->id()}) - 1) AS Depth
FROM {$this->table()} AS node,
{$this->table()} AS parent
WHERE node.{$this->left()} BETWEEN parent.{$this->left()} AND parent.{$this->right()}
GROUP BY node.{$this->id()}
ORDER BY node.{$this->left()}");
return $Res;
}
|
Retrives the full tree including Depth field.
@return 2DArray Rowset
|
fullTree
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/base.php
|
Apache-2.0
|
protected function lock()
{
Jf::sql("LOCK TABLE {$this->table()} WRITE");
}
|
public $AutoRipRightLeft=true;
private function RipRightLeft(&$ResultSet)
{
if ($this->AutoRipRightLeft && $ResultSet)
foreach ($ResultSet as &$v)
{
if (isset($v[$this->Left]))
unset($v[$this->Left]);
if (isset($v[$this->Right]))
unset($v[$this->Right]);
}
}
|
lock
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
Apache-2.0
|
function getID($ConditionString,$Rest=null)
{
$args=func_get_args();
array_shift($args);
$Query="SELECT {$this->id()} AS ID FROM {$this->table()} WHERE $ConditionString LIMIT 1";
array_unshift($args,$Query);
$Res=call_user_func_array(("Jf::sql"),$args);
if ($Res)
return $Res[0]["ID"];
else
return null;
}
|
Returns the ID of a node based on a SQL conditional string
It accepts other params in the PreparedStatements format
@param string $Condition the SQL condition, such as Title=?
@param string $Rest optional, rest of variables to fill in placeholders of condition string, one variable for each ? in condition
@return Integer ID
|
getID
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
Apache-2.0
|
function getRecord($ConditionString,$Rest=null)
{
$args=func_get_args();
array_shift($args);
$Query="SELECT * FROM {$this->table()} WHERE $ConditionString";
array_unshift($args,$Query);
$Res=call_user_func_array(("Jf::sql"),$args);
if ($Res)
return $Res[0];
else
return null;
}
|
Returns the record of a node based on a SQL conditional string
It accepts other params in the PreparedStatements format
@param String $Condition
@param string $Rest optional, rest of variables to fill in placeholders of condition string, one variable for each ? in condition
@return Array Record
|
getRecord
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
Apache-2.0
|
function depthConditional($ConditionString,$Rest=null)
{
$Arguments=func_get_args();
$Path=call_user_func_array(array($this,"pathConditional"),$Arguments);
return count($Path)-1;
}
|
Returns the depth of a node in the tree
Note: this uses path
@param String $ConditionString
@param string $Rest optional, rest of variables to fill in placeholders of condition string, one variable for each ? in condition
@return Integer Depth from zero upwards
@seealso path
|
depthConditional
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
Apache-2.0
|
function siblingConditional($SiblingDistance=1,$ConditionString,$Rest=null)
{
$Arguments=func_get_args();
$ConditionString=$ConditionString; //prevent warning
array_shift($Arguments); //Rid $SiblingDistance
$Parent=call_user_func_array(array($this,"parentNodeConditional"),$Arguments);
$Siblings=$this->children($Parent[$this->id()]);
if (!$Siblings) return null;
$ID=call_user_func_array(array($this,"getID"),$Arguments);
foreach ($Siblings as &$Sibling)
{
if ($Sibling[$this->id()]==$ID) break;
$n++;
}
return $Siblings[$n+$SiblingDistance];
}
|
Returns a sibling of the current node
Note: You can't find siblings of roots
Note: this is a heavy function on nested sets, uses both children (which is quite heavy) and path
@param Integer $SiblingDistance from current node (negative or positive)
@param string $ConditionString
@param string $Rest optional, rest of variables to fill in placeholders of condition string, one variable for each ? in condition
@return Array Node on success, null on failure
|
siblingConditional
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
Apache-2.0
|
function parentNodeConditional($ConditionString,$Rest=null)
{
$Arguments=func_get_args();
$Path=call_user_func_array(array($this,"pathConditional"),$Arguments);
if (count($Path)<2) return null;
else return $Path[count($Path)-2];
}
|
Returns the parent of a node
Note: this uses path
@param string $ConditionString
@param string $Rest optional, rest of variables to fill in placeholders of condition string, one variable for each ? in condition
@return Array parentNode (null on failure)
@seealso path
|
parentNodeConditional
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
Apache-2.0
|
function deleteSubtreeConditional($ConditionString,$Rest=null)
{
$this->lock();
$Arguments=func_get_args();
array_shift($Arguments);
$Query="SELECT {$this->left()} AS `Left`,{$this->right()} AS `Right` ,{$this->right()}-{$this->left()}+ 1 AS Width
FROM {$this->table()}
WHERE $ConditionString";
array_unshift($Arguments,$Query);
$Info=call_user_func_array("Jf::sql",$Arguments);
$Info=$Info[0];
$count=Jf::sql("
DELETE FROM {$this->table()} WHERE {$this->left()} BETWEEN ? AND ?
",$Info["Left"],$Info["Right"]);
Jf::sql("
UPDATE {$this->table()} SET {$this->right()} = {$this->right()} - ? WHERE {$this->right()} > ?
",$Info["Width"],$Info["Right"]);
Jf::sql("
UPDATE {$this->table()} SET {$this->left()} = {$this->left()} - ? WHERE {$this->left()} > ?
",$Info["Width"],$Info["Right"]);
$this->unlock();
return $count>=1;
}
|
Deletes a node and all its descendants
@param String $ConditionString
@param string $Rest optional, rest of variables to fill in placeholders of condition string, one variable for each ? in condition
|
deleteSubtreeConditional
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
Apache-2.0
|
function descendantsConditional($AbsoluteDepths=false,$ConditionString,$Rest=null)
{
if (!$AbsoluteDepths)
$DepthConcat="- (sub_tree.innerDepth )";
$Arguments=func_get_args();
array_shift($Arguments);
array_shift($Arguments); //second argument, $AbsoluteDepths
$Query="
SELECT node.*, (COUNT(parent.{$this->id()})-1 $DepthConcat) AS Depth
FROM {$this->table()} AS node,
{$this->table()} AS parent,
{$this->table()} AS sub_parent,
(
SELECT node.{$this->id()}, (COUNT(parent.{$this->id()}) - 1) AS innerDepth
FROM {$this->table()} AS node,
{$this->table()} AS parent
WHERE node.{$this->left()} BETWEEN parent.{$this->left()} AND parent.{$this->right()}
AND (node.$ConditionString)
GROUP BY node.{$this->id()}
ORDER BY node.{$this->left()}
) AS sub_tree
WHERE node.{$this->left()} BETWEEN parent.{$this->left()} AND parent.{$this->right()}
AND node.{$this->left()} BETWEEN sub_parent.{$this->left()} AND sub_parent.{$this->right()}
AND sub_parent.{$this->id()} = sub_tree.{$this->id()}
GROUP BY node.{$this->id()}
HAVING Depth > 0
ORDER BY node.{$this->left()}";
array_unshift($Arguments,$Query);
$Res=call_user_func_array("Jf::sql",$Arguments);
return $Res;
}
|
Returns all descendants of a node
Note: use only a sinlge condition here
@param boolean $AbsoluteDepths to return Depth of sub-tree from zero or absolutely from the whole tree
@param string $Condition
@param string $Rest optional, rest of variables to fill in placeholders of condition string, one variable for each ? in condition
@return Rowset including Depth field
@seealso children
|
descendantsConditional
|
php
|
OWASP/rbac
|
PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
https://github.com/OWASP/rbac/blob/master/PhpRbac/src/PhpRbac/core/lib/nestedset/full.php
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.