setCountField example

/** * Build the summary query based on a formula. */
  protected function summaryQuery() {
    $this->ensureMyTable();
    // Now that our table is secure, get our formula.     $formula = $this->getFormula();

    // Add the field.     $this->base_alias = $this->name_alias = $this->query->addField(NULL, $formula$this->field);
    $this->query->setCountField(NULL, $formula$this->field);

    return $this->summaryBasics(FALSE);
  }

  /** * Build the query based upon the formula. */
  public function query($group_by = FALSE) {
    $this->ensureMyTable();
    // Now that our table is secure, get our formula.     $placeholder = $this->placeholder();
    
protected function summaryQuery() {
    if (empty($this->definition['many to one'])) {
      $this->ensureMyTable();
    }
    else {
      $this->tableAlias = $this->helper->summaryJoin();
    }

    if (empty($this->options['glossary'])) {
      // Add the field.       $this->base_alias = $this->query->addField($this->tableAlias, $this->realField);
      $this->query->setCountField($this->tableAlias, $this->realField);
    }
    else {
      // Add the field.       $formula = $this->getFormula();
      $this->base_alias = $this->query->addField(NULL, $formula$this->field . '_truncated');
      $this->query->setCountField(NULL, $formula$this->field, $this->field . '_truncated');
    }

    $this->summaryNameField();
    return $this->summaryBasics(FALSE);
  }

  

  public function summaryBasics($count_field = TRUE) {
    // Add the number of nodes counter     $distinct = ($this->view->display_handler->getOption('distinct') && empty($this->query->no_distinct));

    $count_alias = $this->query->addField($this->view->storage->get('base_table')$this->view->storage->get('base_field'), 'num_records', ['count' => TRUE, 'distinct' => $distinct]);
    $this->query->addGroupBy($this->name_alias);

    if ($count_field) {
      $this->query->setCountField($this->tableAlias, $this->realField);
    }

    $this->count_alias = $count_alias;
  }

  /** * Sorts the summary based upon the user's selection. * * The base variant of this is usually adequate. * * @param $order * The order selected in the UI. * @param string|null $by * (optional) This parameter sets the direction for which to order. * Defaults to NULL. */
Home | Imprint | This part of the site doesn't use cookies.