You are here

SlideActivityAnswer.php in Opigno module 8

Same filename and directory in other branches
  1. 3.x src/Plugin/ActivityAnswer/SlideActivityAnswer.php

File

src/Plugin/ActivityAnswer/SlideActivityAnswer.php
View source
<?php

namespace Drupal\opigno_module\Plugin\ActivityAnswer;

use Drupal\opigno_module\ActivityAnswerPluginBase;
use Drupal\opigno_module\Entity\OpignoActivityInterface;
use Drupal\opigno_module\Entity\OpignoAnswerInterface;

/**
 * Class SlideActivityAnswer.
 *
 * @ActivityAnswer(
 *   id="opigno_slide",
 * )
 */
class SlideActivityAnswer extends ActivityAnswerPluginBase {

  /**
   * {@inheritdoc}
   */
  public function evaluatedOnSave(OpignoActivityInterface $activity) {
    return TRUE;
  }

  /**
   * {@inheritdoc}
   */
  public function getScore(OpignoAnswerInterface $answer) {

    /* @var $db_connection \Drupal\Core\Database\Connection */
    $db_connection = \Drupal::service('database');
    $score = 0;
    $activity = $answer
      ->getActivity();
    $score_query = $db_connection
      ->select('opigno_module_relationship', 'omr')
      ->fields('omr', [
      'max_score',
    ])
      ->condition('omr.parent_id', $answer
      ->getModule()
      ->id())
      ->condition('omr.parent_vid', $answer
      ->getModule()
      ->getRevisionId())
      ->condition('omr.child_id', $activity
      ->id())
      ->condition('omr.child_vid', $activity
      ->getRevisionId());
    $score_result = $score_query
      ->execute()
      ->fetchObject();
    if ($score_result) {
      $score = $score_result->max_score;
    }
    return $score;
  }

  /**
   * {@inheritdoc}
   */
  public function getAnswerResultItemHeaders() {
    return [
      $this
        ->t('Slide content'),
    ];
  }

  /**
   * Returns answer result data.
   */
  public function getAnswerResultItemData(OpignoAnswerInterface $answer) {
  }

}

Classes

Namesort descending Description
SlideActivityAnswer Class SlideActivityAnswer.