getFormula example



  /** * Get the field via formula or build it using alias and field name. * * Sometimes the handler might want us to use some kind of formula, so give * it that option. If it wants us to do this, it must set $helper->formula = TRUE * and implement handler->getFormula(). */
  public function getField() {
    if (!empty($this->formula)) {
      return $this->handler->getFormula();
    }
    else {
      return $this->handler->tableAlias . '.' . $this->handler->realField;
    }
  }

  /** * Add a table to the query. * * This is an advanced concept; not only does it add a new instance of the table, * but it follows the relationship path all the way down to the relationship * link point and adds *that* as a new relationship and then adds the table to * the relationship, if necessary. */
public function getFormula() {
    return str_replace('***table***', $this->tableAlias, $this->formula);
  }

  /** * 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. */
  
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);
  }

  /** * Get the formula for this argument. * * $this->ensureMyTable() MUST have been called prior to this. */

  public function getSortName() {
    return $this->t('Date', []['context' => 'Sort order']);
  }

  /** * {@inheritdoc} */
  public function getFormula() {
    $this->formula = $this->getDateFormat($this->argFormat);
    return parent::getFormula();
  }

}

    $title = ($short && isset($this->definition['title short'])) ? $this->definition['title short'] : $this->definition['title'];
    return $this->t('@group: @title', ['@group' => $this->definition['group'], '@title' => $title]);
  }

  /** * {@inheritdoc} */
  public function getField($field = NULL) {
    if (!isset($field)) {
      if (!empty($this->formula)) {
        $field = $this->getFormula();
      }
      else {
        $field = $this->tableAlias . '.' . $this->realField;
      }
    }

    // If grouping, check to see if the aggregation method needs to modify the field.     if ($this->view->display_handler->useGroupBy()) {
      $this->view->initQuery();
      if ($this->query) {
        $info = $this->query->getAggregationInfo();
        
Home | Imprint | This part of the site doesn't use cookies.