public function CourseEnrollmentEditAction::execute in Course 3.x
Same name and namespace in other branches
- 8.3 src/Plugin/Action/CourseEnrollmentEditAction.php \Drupal\course\Plugin\Action\CourseEnrollmentEditAction::execute()
- 8.2 src/Plugin/Action/CourseEnrollmentEditAction.php \Drupal\course\Plugin\Action\CourseEnrollmentEditAction::execute()
Executes the plugin.
Overrides ExecutableInterface::execute
File
- src/
Plugin/ Action/ CourseEnrollmentEditAction.php, line 33
Class
- CourseEnrollmentEditAction
- Action description.
Namespace
Drupal\course\Plugin\ActionCode
public function execute($entity = NULL) {
$course = $entity
->getCourse();
$account = $entity
->getUser();
foreach ($this
->getConfiguration()['course_objects'] as $id => $complete) {
if ($complete !== '') {
// There was a change
$courseObject = CourseObject::load($id);
$fulfillment = $courseObject
->getFulfillment($account);
if ($complete == 1) {
// Completed
$fulfillment
->setOption('message', "Fulfillment completed via bulk action.");
$fulfillment
->setComplete();
}
if ($complete == -1) {
// Delete attempt
$fulfillment
->delete();
}
if ($complete == 0) {
// Fail user
$fulfillment
->setOption('message', "Fulfillment failed via bulk action.");
$fulfillment
->setComplete(FALSE);
$fulfillment
->setGrade(0);
}
$fulfillment
->save();
}
}
// Recheck requirements.
$entity
->track();
\Drupal::messenger()
->addStatus(t('Updated enrollment for %user', array(
'%user' => $account->name,
)));
}