You are here

function CourseObjectPollFulfillment::delete in Course 3.x

Remove poll votes for this user.

Overrides EntityBase::delete

File

modules/course_poll/src/Plugin/course/CourseObject/CourseObjectPollFulfillment.php, line 14

Class

CourseObjectPollFulfillment

Namespace

Drupal\course_poll\Plugin\course\CourseObject

Code

function delete() {
  $account = User::load($this->uid);
  Drupal::database()
    ->delete('poll_vote')
    ->condition('nid', $this
    ->getCourseObject()
    ->getInstanceId())
    ->condition('uid', $account->uid)
    ->execute();

  // TODO: Drupal Rector Notice: Please delete the following comment after you've made any necessary changes.
  // You will need to use `\Drupal\core\Database\Database::getConnection()` if you do not yet have access to the container here.
  Drupal::database()
    ->update('poll_choice')
    ->expression('chvotes', 'chvotes - 1')
    ->condition('chid', $this
    ->getOption('instance'))
    ->execute();
  parent::delete();
}