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

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

namespace Drupal\closedquestion\Question\Mapping;

use Drupal\closedquestion\Question\CqQuestionInterface;

/**
 * Class CqInlineOption.
 *
 * An option to choose from in a Fillblanks question.
 *
 * @package Drupal\closedquestion\Question\Mapping
 */
class CqInlineOption {

  /**
   * The identifier of the option.
   *
   * @var string
   */
  private $identifier;

  /**
   * The (html) text of the option.
   *
   * @var string
   */
  private $text;

  /**
   * The group-identifier of the group that this option belongs to.
   *
   * @var string
   */
  private $group = 'default';

  /**
   * Creates a new CqInlineOption.
   *
   * @param \DOMElement $node
   *   The XML node to use to initialise the option.
   * @param \Drupal\closedquestion\Question\CqQuestionInterface $context
   *   The question or other object that the item can query for things like the
   *   current answer, draggables, hotspots and html processing.
   */
  public function __construct(\DOMElement $node, CqQuestionInterface $context) {

    $this->text .= \Drupal::service('closedquestion.utility.xml_lib')->getTextContent($node, $context, FALSE);

    $attribs = $node->attributes;

    $item = $attribs->getNamedItem('identifier');
    if ($item === NULL) {
      $item = $attribs->getNamedItem('id');
    }
    if ($item === NULL) {
      $item = $attribs->getNamedItem('name');
    }
    if ($item !== NULL) {
      $this->identifier = $item->nodeValue;
    }

    $item = $attribs->getNamedItem('group');
    if ($item !== NULL && !empty($item->nodeValue)) {
      $this->group = $item->nodeValue;
    }
  }

  /**
   * Get the text of this option.
   *
   * @return string
   *   Text of this option.
   */
  public function getText() {
    return $this->text;
  }

  /**
   * Get the identifier of this option.
   *
   * @return string
   *   ID of this option.
   */
  public function getIdentifier() {
    return $this->identifier;
  }

  /**
   * Get the group identifier of this option.
   *
   * @return string
   *   Group ID of this option.
   */
  public function getGroup() {
    return $this->group;
  }

  /**
   * Get the text of this option, for text-review purposes.
   *
   * @return string
   *   Text of this option.
   */
  public function getAllText() {
    $retval = $this->identifier . ': ' . $this->text;
    return $retval;
  }

}

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

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