Add functions for creating courses and enroling users

Created on 19 September 2023, about 1 year ago

Problem/Motivation

Need to push courses into Moodle and enrol users onto those courses.

Proposed resolution

Add helper methods to RestFunctions

πŸ“Œ Task
Status

Fixed

Version

1.1

Component

Code

Created by

πŸ‡³πŸ‡±Netherlands ekes

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @ekes
  • Status changed to Fixed about 1 year ago
  • πŸ‡³πŸ‡±Netherlands ekes
  • πŸ‡ΊπŸ‡ΈUnited States goose2000

    I created an event subscriber for when a Drupal Commerce order has been moved to a 'complete' state. I thinking I could then use this module to invoke an enrollment at that time. I.E. purchase a moodle course.

    
    namespace Drupal\moodle_rest_enroll\EventSubscriber;
    
    use Symfony\Component\EventDispatcher\EventSubscriberInterface;
    use Drupal\state_machine\Event\WorkflowTransitionEvent;
    use Drupal\Core\Entity\EntityTypeManager;
    
    /**
     * Class OrderCompleteSubscriber.
     *
     * @package Drupal\moodle_rest_enroll
     */
    class OrderCompleteSubscriber implements EventSubscriberInterface {
    
      /**
       * Drupal\Core\Entity\EntityTypeManager definition.
       *
       * @var \Drupal\Core\Entity\EntityTypeManager
       */
      protected $entityTypeManager;
    
      /**
       * Constructor.
       */
      public function __construct(EntityTypeManager $entity_type_manager) {
        $this->entityTypeManager = $entity_type_manager;
      }
    
      /**
       * {@inheritdoc}
       */
      static function getSubscribedEvents() {
        $events['commerce_order.place.post_transition'] = ['orderCompleteHandler'];
    
        return $events;
      }
    
      /**
       * This method is called whenever the commerce_order.place.post_transition event is
       * dispatched.
       *
       * @param WorkflowTransitionEvent $event
       */
      public function orderCompleteHandler(WorkflowTransitionEvent $event) {
        /** @var \Drupal\commerce_order\Entity\OrderInterface $order */
        $order = $event->getEntity();
        // Order items in the cart.
        $items = $order->getItems();
    	\Drupal::logger('moodle_rest_enroll')->notice("Subscricer for orderCompleteHandler WORKED!", []);
        
        // Write your custom logic here. Enrol a user into a Moodle course here...
      }
    
    }
    
    
  • Automatically closed - issue fixed for 2 weeks with no activity.

Production build 0.71.5 2024