Skip to content

Commit

Permalink
CS
Browse files Browse the repository at this point in the history
  • Loading branch information
dergel committed Feb 26, 2023
1 parent d9a10a3 commit 984d0c9
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 53 deletions.
13 changes: 7 additions & 6 deletions plugins/manager/lib/yform/manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,13 @@ public function getDataPage()
]));

$searchObject = new rex_yform_manager_search($this->table);
$searchObject->setSearchLinkVars($this->getLinkVars());
$searchObject->setSearchLinkVars($rex_yform_list);
$searchObject->setSearchLinkVars(['rex_yform_filter' => $rex_yform_filter]);
$searchObject->setSearchLinkVars(['rex_yform_set' => $rex_yform_set]);
$searchObject->setSearchLinkVars(['rex_yform_manager_opener' => $rex_yform_manager_opener]);
$searchObject->setSearchLinkVars(['rex_yform_manager_popup' => $rex_yform_manager_popup]);
$searchObject
->setSearchLinkVars($this->getLinkVars())
->setSearchLinkVars($rex_yform_list)
->setSearchLinkVars(['rex_yform_filter' => $rex_yform_filter])
->setSearchLinkVars(['rex_yform_set' => $rex_yform_set])
->setSearchLinkVars(['rex_yform_manager_opener' => $rex_yform_manager_opener])
->setSearchLinkVars(['rex_yform_manager_popup' => $rex_yform_manager_popup]);

$searchForm = '';
if ($this->table->isSearchable() && $this->hasDataPageFunction('search')) {
Expand Down
17 changes: 10 additions & 7 deletions plugins/manager/lib/yform/manager/search.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

class rex_yform_manager_search
{
private $linkVars = [];
private $scriptPath = '';
private array $linkVars = [];
private string $scriptPath = '';

/** @var rex_yform_manager_table */
protected $table;
protected $fields;
protected array $fields;

public function __construct(rex_yform_manager_table $table)
{
Expand All @@ -28,22 +28,25 @@ public function __construct(rex_yform_manager_table $table)
$this->setScriptPath($_SERVER['PHP_SELF']);
}

public function setLinkVar($k, $v)
public function setLinkVar(string $k, mixed $v): self
{
$this->linkVars[$k] = $v;
return $this;
}

public function setSearchLinkVars(array $vars)
public function setSearchLinkVars(array $vars): self
{
$this->linkVars = array_merge($this->linkVars, $vars);
return $this;
}

public function setScriptPath($scriptpath)
public function setScriptPath(string $scriptpath): self
{
$this->scriptPath = $scriptpath;
return $this;
}

public function getYForm()
public function getYForm(): rex_yform
{
$yform = new rex_yform();
$yform->setObjectparams('form_name', 'rex_yform_searchvars-'.$this->table->getTableName());
Expand Down
44 changes: 22 additions & 22 deletions plugins/manager/lib/yform/manager/table.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
class rex_yform_manager_table implements ArrayAccess
{
protected $values = [];

protected $columns = [];

/** @var rex_yform_manager_field[] */
Expand All @@ -19,11 +18,11 @@ class rex_yform_manager_table implements ArrayAccess
/** @var rex_yform_manager_field[] */
protected $relations;

protected static $debug = false;
protected static bool $debug = false;

/** @var self[] */
protected static $tables = [];
protected static $loadedAllTables = false;
protected static bool $loadedAllTables = false;

private static $cache;
protected $relatedTableNames = [];
Expand Down Expand Up @@ -168,17 +167,17 @@ public static function table()

// -------------------------------------------------------------------------

public function getTableName()
public function getTableName(): string
{
return $this->values['table_name'];
}

public function getName()
public function getName(): string
{
return $this->values['name'];
}

public function getNameLocalized()
public function getNameLocalized(): string
{
$table_name = $this->getTableName();
$name = $this->getName();
Expand All @@ -197,7 +196,7 @@ public function getId()
return $this->values['id'];
}

public function hasId()
public function hasId(): bool
{
$columns = rex_sql::showColumns($this->getTableName());
foreach ($columns as $column) {
Expand All @@ -208,52 +207,52 @@ public function hasId()
return false;
}

public function isActive()
public function isActive(): bool
{
return 1 == $this->values['status'];
}

public function isHidden()
public function isHidden(): bool
{
return 1 == $this->values['hidden'];
}

public function isSearchable()
public function isSearchable(): bool
{
return 1 == $this->values['search'];
}

public function isImportable()
public function isImportable(): bool
{
return 1 == $this->values['import'];
}

public function isExportable()
public function isExportable(): bool
{
return 1 == $this->values['export'];
}

public function isMassDeletionAllowed()
public function isMassDeletionAllowed(): bool
{
return 1 == $this->values['mass_deletion'];
}

public function isMassEditAllowed()
public function isMassEditAllowed(): bool
{
return 1 == $this->values['mass_edit'];
}

public function overwriteSchema()
public function overwriteSchema(): bool
{
return (1 == $this->values['schema_overwrite']) ? true : false;
}

public function hasHistory()
public function hasHistory(): bool
{
return 1 == $this->values['history'];
}

public function parseLayout(rex_fragment $fragment)
public function parseLayout(rex_fragment $fragment): string
{
return $fragment->parse('yform/manager/page/layout.php');
}
Expand Down Expand Up @@ -528,15 +527,16 @@ public function __toString()
return $this->getTableName();
}

public static function deleteCache()
public static function deleteCache(): void
{
rex_file::delete(self::cachePath());
self::$cache = null;
self::$tables = [];
self::$loadedAllTables = false;
dump('table cache deleted');
}

private static function getCache()
private static function getCache(): mixed
{
if (null !== self::$cache) {
return self::$cache;
Expand Down Expand Up @@ -592,17 +592,17 @@ private static function getCache()
return self::$cache;
}

private static function cachePath()
private static function cachePath(): string
{
return rex_path::pluginCache('yform', 'manager', 'tables.cache');
}

public function isGranted($type, rex_user $user)
public function isGranted(string $type, rex_user $user): bool
{
return rex_yform_manager_table_authorization::onAttribute($type, $this, $user);
}

public function getCSRFKey()
public function getCSRFKey(): string
{
return 'table_field-'.$this->getTableName();
}
Expand Down
23 changes: 5 additions & 18 deletions plugins/manager/lib/yform/manager/table/authorization.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,11 @@ class rex_yform_manager_table_authorization
public const VIEW = 'VIEW';
public const EDIT = 'EDIT';

public static $tableAuthorizations = null;

/**
* @param string $attribute
* @param rex_yform_manager_table $userTable
* @param null|rex_user $user
* @return bool
* @var null|array<string, mixed>
*/
public static ?array $tableAuthorizations = null;

public static function onAttribute(string $attribute, rex_yform_manager_table $userTable, rex_user $user = null): bool
{
if (null !== self::$tableAuthorizations) {
Expand Down Expand Up @@ -42,11 +39,6 @@ public static function onAttribute(string $attribute, rex_yform_manager_table $u
return self::onAttribute($attribute, $userTable, $user);
}

/**
* @param rex_yform_manager_table $table
* @param null|rex_user $user
* @return bool
*/
private static function canView(rex_yform_manager_table $table, rex_user $user = null): bool
{
if (!$user) {
Expand All @@ -60,14 +52,9 @@ private static function canView(rex_yform_manager_table $table, rex_user $user =
/** @var rex_yform_manager_table_perm_view $complexPerm */
$complexPerm = $user->getComplexPerm('yform_manager_table_view');

return $complexPerm->hasPerm($table->getTableName());
return null !== $complexPerm && $complexPerm->hasPerm($table->getTableName());
}

/**
* @param rex_yform_manager_table $table
* @param null|rex_user $user
* @return bool
*/
private static function canEdit(rex_yform_manager_table $table, rex_user $user = null): bool
{
if (!$user) {
Expand All @@ -81,6 +68,6 @@ private static function canEdit(rex_yform_manager_table $table, rex_user $user =
/** @var rex_yform_manager_table_perm_edit $complexPerm */
$complexPerm = $user->getComplexPerm('yform_manager_table_edit');

return $complexPerm->hasPerm($table->getTableName());
return null !== $complexPerm && $complexPerm->hasPerm($table->getTableName());
}
}

0 comments on commit 984d0c9

Please sign in to comment.