original_string: public static function create_calendar_events($events) {
          global $DB, $USER;
  
          // Parameter validation.
          $params = self::validate_parameters(self::create_calendar_events_parameters(), array('events' => $events));
  
          $transaction = $DB->start_delegated_transaction();
          $return = array();
          $warnings = array();
  
          foreach ($params['events'] as $event) {
  
              // Let us set some defaults.
              $event['userid'] = $USER->id;
              $event['modulename'] = '';
              $event['instance'] = 0;
              $event['subscriptionid'] = null;
              $event['uuid']= '';
              $event['format'] = external_validate_format($event['format']);
              if ($event['repeats'] > 0) {
                  $event['repeat'] = 1;
              } else {
                  $event['repeat'] = 0;
              }
  
              $eventobj = new calendar_event($event);
  
              // Let's check if the user is allowed to delete an event.
              if (!calendar_add_event_allowed($eventobj)) {
                  $warnings [] = array('item' => $event['name'], 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to create this event');
                  continue;
              }
              // Let's create the event.
              $var = $eventobj->create($event);
              $var = (array)$var->properties();
              if ($event['repeat']) {
                  $children = $DB->get_records('event', array('repeatid' => $var['id']));
                  foreach ($children as $child) {
                      $return[] = (array) $child;
                  }
              } else {
                  $return[] = $var;
              }
          }
  
          // Everything done smoothly, let's commit.
          $transaction->allow_commit();
          return array('events' => $return, 'warnings' => $warnings);
      }
code: public static function create_calendar_events($events) {
          global $DB, $USER;
  
          // Parameter validation.
          $params = self::validate_parameters(self::create_calendar_events_parameters(), array('events' => $events));
  
          $transaction = $DB->start_delegated_transaction();
          $return = array();
          $warnings = array();
  
          foreach ($params['events'] as $event) {
  
              // Let us set some defaults.
              $event['userid'] = $USER->id;
              $event['modulename'] = '';
              $event['instance'] = 0;
              $event['subscriptionid'] = null;
              $event['uuid']= '';
              $event['format'] = external_validate_format($event['format']);
              if ($event['repeats'] > 0) {
                  $event['repeat'] = 1;
              } else {
                  $event['repeat'] = 0;
              }
  
              $eventobj = new calendar_event($event);
  
              // Let's check if the user is allowed to delete an event.
              if (!calendar_add_event_allowed($eventobj)) {
                  $warnings [] = array('item' => $event['name'], 'warningcode' => 'nopermissions', 'message' => 'you do not have permissions to create this event');
                  continue;
              }
              // Let's create the event.
              $var = $eventobj->create($event);
              $var = (array)$var->properties();
              if ($event['repeat']) {
                  $children = $DB->get_records('event', array('repeatid' => $var['id']));
                  foreach ($children as $child) {
                      $return[] = (array) $child;
                  }
              } else {
                  $return[] = $var;
              }
          }
  
          // Everything done smoothly, let's commit.
          $transaction->allow_commit();
          return array('events' => $return, 'warnings' => $warnings);
      }
code_tokens: public static function create_calendar_events ( $ events ) { global $ DB , $ USER ; // Parameter validation. $ params = self :: validate_parameters ( self :: create_calendar_events_parameters ( ) , array ( 'events' => $ events ) ) ; $ transaction = $ DB -> start_delegated_transaction ( ) ; $ return = array ( ) ; $ warnings = array ( ) ; foreach ( $ params [ 'events' ] as $ event ) { // Let us set some defaults. $ event [ 'userid' ] = $ USER -> id ; $ event [ 'modulename' ] = '' ; $ event [ 'instance' ] = 0 ; $ event [ 'subscriptionid' ] = null ; $ event [ 'uuid' ] = '' ; $ event [ 'format' ] = external_validate_format ( $ event [ 'format' ] ) ; if ( $ event [ 'repeats' ] > 0 ) { $ event [ 'repeat' ] = 1 ; } else { $ event [ 'repeat' ] = 0 ; } $ eventobj = new calendar_event ( $ event ) ; // Let's check if the user is allowed to delete an event. if ( ! calendar_add_event_allowed ( $ eventobj ) ) { $ warnings [ ] = array ( 'item' => $ event [ 'name' ] , 'warningcode' => 'nopermissions' , 'message' => 'you do not have permissions to create this event' ) ; continue ; } // Let's create the event. $ var = $ eventobj -> create ( $ event ) ; $ var = ( array ) $ var -> properties ( ) ; if ( $ event [ 'repeat' ] ) { $ children = $ DB -> get_records ( 'event' , array ( 'repeatid' => $ var [ 'id' ] ) ) ; foreach ( $ children as $ child ) { $ return [ ] = ( array ) $ child ; } } else { $ return [ ] = $ var ; } } // Everything done smoothly, let's commit. $ transaction -> allow_commit ( ) ; return array ( 'events' => $ return , 'warnings' => $ warnings ) ; }
docstring: Delete Calendar events.
  
  @param array $events A list of events to create.
  @return array array of events created.
  @since Moodle 2.5
  @throws moodle_exception if user doesnt have the permission to create events.
docstring_tokens: Delete Calendar events .