closedquestion-8.x-3.x-dev/src/Question/Mapping/CqMappingMathExport.php

src/Question/Mapping/CqMappingMathExport.php
<?php

namespace Drupal\closedquestion\Question\Mapping;

/**
 * Class CqMappingMathExport.
 *
 * Export a variable. Always returns true.
 *
 * @package Drupal\closedquestion\Question\Mapping
 */
class CqMappingMathExport extends CqAbstractMapping {

  /**
   * Implements CqAbstractMapping::evaluate()
   */
  public function evaluate() {
    $varname = $this->getParam('varname');
    $exportname = $this->getParam('exportname');
    $exportnode = (int) $this->getParam('exportnode');
    if ($varname === NULL) {
      \Drupal::messenger()->addMessage(t('MathExport without varname attribute found.'), 'warning');
      return TRUE;
    }
    if ($exportname === NULL) {
      \Drupal::messenger()->addMessage(t('MathExport without exportname attribute found.'), 'warning');
      return TRUE;
    }
    $uid = $this->context->getUserAnswer()->getUserId();
    $thisNodeId = $this->context->getClosedQuestion()->id();
    if ($exportnode === 0 || $exportnode === $thisNodeId) {
      // In this case the userAnswer was cached in the form.
      $userAnswer =& $this->context->getUserAnswer();
    }
    else {
      $userAnswer =& closedquestion_get_useranswer($exportnode, $uid);
    }

    $value = $this->context->evaluateMath($varname);

    $exports = $userAnswer->getData('export');
    if ($exports === NULL) {
      $exports = array();
    }
    $exports[$exportname] = $value;
    $userAnswer->setData('export', $exports);

    return TRUE;
  }

  /**
   * Overrides CqAbstractMapping::getAllText()
   */
  public function getAllText() {
    $retval = array();
    $retval['logic']['#markup'] = 'Export';
    $retval += parent::getAllText();
    return $retval;
  }

}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc