www.hubleto.eu Reddit User Guide Stack Overflow LinkedIn Report an issue

Table description

describeTable() returns a Hubleto\Framework\Description\Table. Always start from the description of the parent and change it:

apps/Customers/Models/Customer.php (excerpt)
  public function describeTable(): Table
  {
    $description = parent::describeTable();
    $description->ui['title'] = ''; //$this->translate('Customers');
    $description->ui['addButtonText'] = $this->translate('Add Customer');
    $description->show(['header', 'fulltextSearch', 'columnSearch', 'moreActionsButton']);
    $description->hide(['footer']);

    $description->addFilter('fCustomerActive', [
      'title' => $this->translate('Active'),
      'options' => [ 0 => $this->translate('Active'), 1 => $this->translate('Non-active') ],
      // 'default' => 0,
    ]);

    $fTagColors = [];
    $fTagOptions = [];
    foreach ($this->getModel(Tag::class)->record->get() as $value) {
      $fTagColors[$value->id] = $value->color;
      $fTagOptions[$value->id] = $value->name;
    }
    $description->addFilter('fTag', [
      'title' => $this->translate('Tag'),
      'type' => 'multipleSelectButtons',
      'colors' => $fTagColors,
      'options' => $fTagOptions,
    ]);

    return $description;
  }

Properties

Property Meaning
ui Texts and visibility of the parts of the table (below).
permissions canCreate, canRead, canUpdate, canDelete. All true after Model::describeTable().
columns The columns that the table shows (from describeColumns()).
inputs The inputs of the columns.

Properties.

The ui array

Key Default Meaning
title, subTitle '' Title of the table.
addButtonText '' Text of the "add" button.
showHeader, showFooter, showHeaderTitle true Parts of the table.
showFilter, showSidebarFilter true The filters.
showReloadButton true The reload button.
showAddButton true The add button.
showFulltextSearch false Fulltext search above the table.
showColumnSearch false Search field in each column header.
showMoreActionsButton false The "more actions" menu.
showInsertRow false An empty row for quick insertion.

Keys of ui.

Methods

Method Purpose
show(['header', 'fulltextSearch']) Turns parts of the UI on. The names are the ui keys without show.
hide(['footer']) Turns parts of the UI off.
showOnlyColumns([...]), hideColumns([...]) Select the visible columns.
addColumn($name, $column) Adds a column that is not in describeColumns().
addFilter($name, $config) Adds a filter. Its name arrives as filters[<name>].
setPermissions($create, $read, $update, $delete) Changes permissions. See the note about setPermissions() in Permissions.
setOrderBy($field, $direction) Default sorting.

Methods.

Filters

A filter is declared in the table description and applied in the record manager:

apps/Deals/Models/Deal.php (excerpt)
  public function describeTable(): \Hubleto\Framework\Description\Table
  {
    $description = parent::describeTable();
    $description->ui['addButtonText'] = $this->translate('Add Deal');
    $description->show(['header', 'fulltextSearch', 'columnSearch', 'moreActionsButton']);
    $description->hide(['footer']);
    $description->ui['filters'] = [
      'fDealClosed' => [
        'direction' => 'horizontal',
        'options' => [
          1 => $this->translate('Open'),
          2 => $this->translate('Closed'),
          3 => $this->translate('All'),
        ],
        'default' => 1,
      ],
      'fDealWorkflowStep' => Workflow::buildTableFilterForWorkflowSteps($this, $this->translate('State')),
      'fDealSourceChannel' => [ 'title' => $this->translate('Source channel'), 'type' => 'multipleSelectButtons', 'options' => array_map(fn($v) => $this->translate($v), self::ENUM_SOURCE_CHANNELS) ],
      'fDealOwnership' => [ 'title' => $this->translate('Ownership'), 'options' => [ 0 => $this->translate('All'), 1 => $this->translate('Owned by me'), 2 => $this->translate('Managed by me') ] ],
    ];

    $description->addFilter('fDealWithPlan', [
      'title' => $this->translate('Planning'),
      'options' => [
        1 => $this->translate('With plan'),
        2 => $this->translate('Without plan')
      ]
    ]);

    return $description;
  }
apps/Deals/Models/RecordManagers/Deal.php (excerpt)
  public function addUrlFiltersToQuery(mixed $query): mixed
  {
    $query = parent::addUrlFiltersToQuery($query);

    $hubleto = \Hubleto\Erp\Loader::getGlobalApp();

    if ($hubleto->router()->urlParamAsInteger("idCustomer") > 0) {
      $query = $query->where("deals.id_customer", $hubleto->router()->urlParamAsInteger("idCustomer"));
    }

    $filters = $hubleto->router()->urlParamAsArray("filters");

    $query = Workflow::applyWorkflowStepFilter(
      $this->model,
      $query,
      (array) ($filters['fDealWorkflowStep'] ?? [])
    );

    if (isset($filters["fDealSourceChannel"]) && $filters["fDealSourceChannel"] > 0) {
      $query = $query->where("deals.source_channel", $filters["fDealSourceChannel"]);
    }
    if (isset($filters["fDealResult"]) && $filters["fDealResult"] > 0) {
      $query = $query->where("deals.deal_result", $filters["fDealResult"]);
    }
    if (isset($filters["fDealBusinessType"]) && $filters["fDealBusinessType"] > 0) {
      $query = $query->where("deals.business_type", $filters["fDealBusinessType"]);
    }
    if (isset($filters["fDealBusinessType"]) && $filters["fDealBusinessType"] > 0) {
      $query = $query->where("deals.business_type", $filters["fDealBusinessType"]);
    }

    if (isset($filters["fDealOwnership"])) {
      switch ($filters["fDealOwnership"]) {
        case 1: $query = $query->where("deals.id_owner", $hubleto->authProvider()->getUserId());
          break;
        case 2: $query = $query->where("deals.id_manager", $hubleto->authProvider()->getUserId());
          break;
      }
    }

    $fDealClosed = $filters['fDealClosed'] ?? 1;
    if ($fDealClosed == 1) $query = $query->where("deals.is_closed", false);
    if ($fDealClosed == 2) $query = $query->where("deals.is_closed", true);

More in describeTable().