You are here

CourseType.php in Course 3.x

File

modules/course_migrate/src/Plugin/migrate/source/CourseType.php
View source
<?php

namespace Drupal\course_migrate\Plugin\migrate\source;

use Drupal\migrate\Row;
use Drupal\migrate_drupal\Plugin\migrate\source\DrupalSqlBase;

/**
 * Drupal 7 course source from database.
 *
 * @MigrateSource(
 *   id = "d7_course_type",
 *   source_module = "course"
 * )
 */
class CourseType extends DrupalSqlBase {

  /**
   * {@inheritdoc}
   */
  public function query() {
    $course_types = [];
    $query = $this
      ->select('node_type', 'nt')
      ->fields('nt', [
      'type',
      'name',
    ]);
    $result = $query
      ->execute();
    while ($row = $result
      ->fetch()) {
      if ($this
        ->variableGet("course_use_" . $row['type'], 0) == 1) {
        $course_types[] = $row['type'];
      }
    }
    $query = $this
      ->select('node_type', 'nt')
      ->fields('nt', [
      'type',
      'name',
    ]);
    $query
      ->condition('type', $course_types, 'in');
    return $query;
  }

  /**
   * {@inheritdoc}
   */
  public function fields() {
    return [
      'type' => $this
        ->t('The machine-readable name of this profile type.'),
      'name' => $this
        ->t('The human-readable name of this profile type.'),
    ];
  }

  /**
   * {@inheritdoc}
   */
  public function getIds() {
    $ids['type']['type'] = 'string';
    return $ids;
  }

}

Classes

Namesort descending Description
CourseType Drupal 7 course source from database.