Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Domain/Access/AttributeFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ public static function Create($entityTableAndColumn, $attributes)

$idEquals = new SqlFilterEquals($attributeId, $attribute->Id());
$f->AppendSql('LEFT JOIN `' . TableNames::CUSTOM_ATTRIBUTE_VALUES . '` `a' . $id . '` ON `a0`.`entity_id` = `a' . $id . '`.`entity_id` ');
if ($attribute->Type() == CustomAttributeTypes::MULTI_LINE_TEXTBOX || $attribute->Type() == CustomAttributeTypes::SINGLE_LINE_TEXTBOX) {
if ((int)$attribute->Type() === CustomAttributeTypes::MULTI_LINE_TEXTBOX || (int)$attribute->Type() === CustomAttributeTypes::SINGLE_LINE_TEXTBOX) {
$attributeFragment->_And($idEquals->_And(new SqlFilterLike($attributeValue, $attribute->Value())));
} elseif ($attribute->Type() == CustomAttributeTypes::CHECKBOX && $attribute->Value() == '0') {
} elseif ((int)$attribute->Type() === CustomAttributeTypes::CHECKBOX && $attribute->Value() == '0') {
$attributeFragment->_And(new SqlFilterFreeForm('NOT EXISTS (SELECT 1 FROM `' . TableNames::CUSTOM_ATTRIBUTE_VALUES . '` `b` WHERE `b`.`entity_id` = `a0`.`entity_id` AND `b`.`custom_attribute_id` = ' . $id . ')'));
} else {
$attributeFragment->_And($idEquals->_And(new SqlFilterEquals($attributeValue, $attribute->Value())));
Expand Down
6 changes: 3 additions & 3 deletions Domain/CustomAttribute.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public function __construct(
$this->category = $category;
$this->SetRegex($regex);
$this->required = $required;
if ($category != CustomAttributeCategory::RESERVATION) {
if ((int)$category !== CustomAttributeCategory::RESERVATION) {
$this->entityIds = is_array($entityIds) ? $entityIds : ($entityIds);
}
$this->adminOnly = $adminOnly;
Expand Down Expand Up @@ -452,7 +452,7 @@ public function Update($label, $regex, $required, $possibleValues, $sortOrder, $
$this->SetRegex($regex);
$this->required = $required;

if ($this->category != CustomAttributeCategory::RESERVATION) {
if ((int)$this->category !== CustomAttributeCategory::RESERVATION) {
$entityIds = is_array($entityIds) ? $entityIds : [$entityIds];
$removed = array_diff($this->entityIds, $entityIds);
$added = array_diff($entityIds, $this->entityIds);
Expand Down Expand Up @@ -503,7 +503,7 @@ public function WithEntityDescriptions($entityDescriptions)
*/
public function WithSecondaryEntities($category, $entityIds, $entityDescriptions = null)
{
if ($this->category != CustomAttributeCategory::RESERVATION) {
if ((int)$this->category !== CustomAttributeCategory::RESERVATION && (int)$this->category !== CustomAttributeCategory::RESOURCE) {
return;
}

Expand Down
50 changes: 44 additions & 6 deletions Pages/Admin/ManageAttributesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ public function GetLabel();

/**
* @abstract
* return int|CustomAttributeTypes
* return CustomAttributeTypes
*/
public function GetType();

/**
* return int|CustomAttributeCategory
* return CustomAttributeCategory
*/
public function GetCategory();

Expand All @@ -43,7 +43,7 @@ public function GetEntityIds();
public function GetPossibleValues();

/**
* return int|CustomAttributeCategory
* return CustomAttributeCategory
*/
public function GetRequestedCategory();

Expand All @@ -63,7 +63,7 @@ public function GetIsAdminOnly();
public function BindAttributes($attributes);

/**
* @param $categoryId int|CustomAttributeCategory
* @param $categoryId CustomAttributeCategory
*/
public function SetCategory($categoryId);

Expand All @@ -73,12 +73,12 @@ public function SetCategory($categoryId);
public function GetAttributeId();

/**
* @return int|null
* @return int[]
*/
public function GetSecondaryEntityIds();

/**
* @return CustomAttributeCategory|int|null
* @return CustomAttributeCategory|null
*/
public function GetSecondaryCategory();

Expand All @@ -91,6 +91,11 @@ public function GetLimitAttributeScope();
* @return bool
*/
public function GetIsPrivate();

/**
* Set template variables for category-based field visibility
*/
public function SetCategoryVisibilityRules();
}

class ManageAttributesPage extends ActionPage implements IManageAttributesPage
Expand Down Expand Up @@ -240,6 +245,39 @@ public function GetIsPrivate()
return !empty($isPrivate);
}

public function SetCategoryVisibilityRules()
{
// Define which fields are visible for which categories
// This moves the visibility logic from JavaScript to PHP/Smarty
$this->Set('ShowAppliesToFor', [
CustomAttributeCategory::USER => true,
CustomAttributeCategory::RESOURCE_TYPE => true,
CustomAttributeCategory::RESERVATION => false,
CustomAttributeCategory::RESOURCE => false,
]);

$this->Set('ShowAdminOnlyFor', [
CustomAttributeCategory::RESERVATION => true,
CustomAttributeCategory::RESOURCE => true,
CustomAttributeCategory::USER => true,
CustomAttributeCategory::RESOURCE_TYPE => true,
]);

$this->Set('ShowPrivateFor', [
CustomAttributeCategory::RESERVATION => true,
CustomAttributeCategory::RESOURCE => false,
CustomAttributeCategory::USER => false,
CustomAttributeCategory::RESOURCE_TYPE => false,
]);

$this->Set('ShowSecondaryEntitiesFor', [
CustomAttributeCategory::RESERVATION => true,
CustomAttributeCategory::RESOURCE => true,
CustomAttributeCategory::USER => false,
CustomAttributeCategory::RESOURCE_TYPE => false,
]);
}

public function ProcessDataRequest($dataRequest)
{
$this->presenter->HandleDataRequest($dataRequest);
Expand Down
2 changes: 1 addition & 1 deletion Pages/Admin/ManageResourcesPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -1323,7 +1323,7 @@ public function AsFilter($customAttributes)

$idEquals = new SqlFilterEquals($attributeId, $id);
$f->AppendSql('LEFT JOIN `' . TableNames::CUSTOM_ATTRIBUTE_VALUES . '` `a' . $id . '` ON `a0`.`entity_id` = `a' . $id . '`.`entity_id` ');
if ($attribute->Type() == CustomAttributeTypes::MULTI_LINE_TEXTBOX || $attribute->Type() == CustomAttributeTypes::SINGLE_LINE_TEXTBOX) {
if ((int)$attribute->Type() === CustomAttributeTypes::MULTI_LINE_TEXTBOX || (int)$attribute->Type() === CustomAttributeTypes::SINGLE_LINE_TEXTBOX) {
$attributeFragment->_And($idEquals->_And(new SqlFilterLike($attributeValue, $value)));
} else {
$attributeFragment->_And($idEquals->_And(new SqlFilterEquals($attributeValue, $value)));
Expand Down
2 changes: 2 additions & 0 deletions Presenters/Admin/ManageAttributesPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ public function __construct(IManageAttributesPage $page, IAttributeRepository $a

public function PageLoad()
{
// Set category visibility flags for template conditional rendering
$this->page->SetCategoryVisibilityRules();
}

public function AddAttribute()
Expand Down
Loading