function cis_section_cron

cis7 cis_section.module cis_section_cron()
cle7 cis_section.module cis_section_cron()
elmsmedia7 cis_section.module cis_section_cron()
icor7 cis_section.module cis_section_cron()
meedjum_blog7 cis_section.module cis_section_cron()
mooc7 cis_section.module cis_section_cron()

Implements hook_cron().

File

sites/all/modules/elmsln_contrib/cis_connector/features/cis_section/cis_section.module, line 22
Code for the CIS Section feature.

Code

function cis_section_cron() {
  // the magic that keeps sections in sync with the cis
  $query = array(
    'type' => 'course',
    'field_machine_name' => str_replace('/', '', base_path()),
    'deep-load-refs' => 'field_collection_item', // special property that tells sections from course
  );
  // return a course
  $return = _cis_connection_query($query, 'node', 'json', 'GET', 'cis', '', FALSE);
  // look for 1 record
  if (count($return['list']) == 1) {
    $section_strings = array();
    $course = $return['list'][0];
    // loop through offerings
    foreach ($course['field_offerings'] as $offering) {
      // loop through sections if they exist
      if (isset($offering['field_sections']['und']) && count($offering['field_sections']['und']) > 0) {
        foreach ($offering['field_sections']['und'] as $section) {
          // verify that this has the full object and has dates
          if (isset($section['item_id']) && isset($section['field_access_dates']['und'])) {
            $start = $section['field_access_dates']['und'][0]['value'];
            // loop through access strings
            // this is the magic that binds students to sections automatically
            // and allows the entire network to work as an OG dark-net :)
            if (isset($section['field_access_string']['und']) && count($section['field_access_string']['und']) > 0) {
              foreach ($section['field_access_string']['und'] as $string) {
                $section_strings[$string['safe_value']] = $string['safe_value'];
              }
            }
          }
        }
      }
    }
    // loop through section strings to make sure we have a matching section node
    foreach ($section_strings as $section_id) {
      // if we don't know about this section, create it
      if (!_cis_section_load_section_by_id($section_id)) {
        $section = new stdClass();
        $section->type = 'section';
        node_object_prepare($section);
        // currently both items are given the section id
        $section->title = $section_id;
        $section->field_section_id['und'][0]['value'] = $section_id;
        // mark this as active so it can sync with systems
        $section->field_cis_active['und'][0]['value'] = 1;
        $section->language = LANGUAGE_NONE;
        // default these to admin ownership for less chance of seeing it
        $section->uid = 1;
        // save section, cron job will then be able to check data source for roster
        // if that functionality is enabled in local instance
        node_save($section);
      }
    }
  }
  // test for if we should sync w/ our roster provider
  $frequency = variable_get('cis_service_connection_sync_frequency', CIS_SERVICE_CONNECTION_SYNC_FREQUENCY);
  $interval = 86400 * $frequency;
  // always sync if this call just came from drush
  // sync this course with LMS based on section data if time has passed
  // sync if there's an argument asking to force sync
  if (drupal_is_cli() || isset($_GET['force_roster_sync']) || (REQUEST_TIME - variable_get('cis_service_connection_last_sync', 0)) > $interval) {
    // simple section pull based on those included locally
    $sections = array_keys(cis_section_all_sections(TRUE));
    // pull the roster together
    $roster = cis_section_assemble_roster($sections);
    // build the user accounts
    watchdog('roster', 'Roster service synced with !roster sections', array('!roster' => count($roster)));
    _cis_section_create_accounts($roster);
  }
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.