You are here

class IndexRecord in Views Natural Sort 8.2

Hierarchy

Expanded class hierarchy of IndexRecord

File

src/IndexRecord.php, line 7

Namespace

Drupal\views_natural_sort
View source
class IndexRecord {
  protected $eid;
  protected $entityType;
  protected $field;
  protected $delta;
  protected $content;
  protected $transformations = [];
  private $database;
  public function __construct(Connection $database, array $values = []) {
    $this->database = $database;
    $this
      ->setEntityId($values['eid']);
    $this
      ->setEntityType($values['entity_type']);
    $this
      ->setField($values['field']);
    $this
      ->setDelta($values['delta']);
    $this
      ->setContent($values['content']);
  }
  public function setEntityId($eid) {
    $this->eid = $eid;
  }
  public function getEntityId() {
    return $this->eid;
  }
  public function setEntityType($entity_type) {
    $this->entityType = $entity_type;
    $this
      ->generateType();
  }
  public function getEntityType() {
    return $this->entityType;
  }
  public function setField($field) {
    $this->field = $field;
    $this
      ->generateType();
  }
  public function getField() {
    return $this->field;
  }
  public function setDelta($delta) {
    $this->delta = $delta;
  }
  public function getDelta() {
    return $this->delta;
  }
  public function setContent($string) {
    $this->content = $string;
  }
  public function getContent() {
    return $this->content;
  }
  public function setTransformations(array $transformations) {
    $this->transformations = $transformations;
  }
  public function getTransformations() {
    return $this->transformations;
  }
  public function getTransformedContent() {
    $transformed_content = $this->content;
    foreach ($this->transformations as $transformation) {
      $transformed_content = $transformation
        ->transform($transformed_content);
    }
    return mb_substr($transformed_content, 0, 255);
  }
  private function generateType() {
    $this->type = new IndexRecordType($this->entityType, $this->field);
  }
  public function getType() {
    return $this->type;
  }
  public function save() {
    $this->database
      ->merge('views_natural_sort')
      ->key([
      'eid' => $this->eid,
      'entity_type' => $this->entityType,
      'field' => $this->field,
      'delta' => $this->delta,
    ])
      ->fields([
      'eid' => $this->eid,
      'entity_type' => $this->entityType,
      'field' => $this->field,
      'delta' => $this->delta,
      'content' => $this
        ->getTransformedContent(),
    ])
      ->execute();
  }
  public function delete() {
    $this->database
      ->delete('views_natural_sort')
      ->condition('eid', $this->eid)
      ->condition('entity_type', $this->entityType)
      ->condition('field', $this->field)
      ->condition('delta', $this->delta)
      ->execute();
  }

}

Members

Namesort descending Modifiers Type Description Overrides
IndexRecord::$content protected property
IndexRecord::$database private property
IndexRecord::$delta protected property
IndexRecord::$eid protected property
IndexRecord::$entityType protected property
IndexRecord::$field protected property
IndexRecord::$transformations protected property
IndexRecord::delete public function
IndexRecord::generateType private function
IndexRecord::getContent public function
IndexRecord::getDelta public function
IndexRecord::getEntityId public function
IndexRecord::getEntityType public function
IndexRecord::getField public function
IndexRecord::getTransformations public function
IndexRecord::getTransformedContent public function
IndexRecord::getType public function
IndexRecord::save public function
IndexRecord::setContent public function
IndexRecord::setDelta public function
IndexRecord::setEntityId public function
IndexRecord::setEntityType public function
IndexRecord::setField public function
IndexRecord::setTransformations public function
IndexRecord::__construct public function