You are here

public function OpignoModule::getSuitableActivities in Opigno module 3.x

Same name and namespace in other branches
  1. 8 src/Entity/OpignoModule.php \Drupal\opigno_module\Entity\OpignoModule::getSuitableActivities()

Get activities related to specific skills.

File

src/Entity/OpignoModule.php, line 690

Class

OpignoModule
Defines the Module entity.

Namespace

Drupal\opigno_module\Entity

Code

public function getSuitableActivities($current_skills) {
  if (empty($current_skills)) {
    return [
      0 => 0,
    ];
  }
  $activities = [];

  /* @var $db_connection \Drupal\Core\Database\Connection */
  $db_connection = \Drupal::service('database');
  $query = $db_connection
    ->select('opigno_activity', 'oa');
  $query
    ->fields('oafd', [
    'id',
    'vid',
    'type',
    'name',
    'usage_activity',
    'skills_list',
    'skill_level',
  ]);
  $query
    ->addJoin('inner', 'opigno_activity_field_data', 'oafd', 'oa.id = oafd.id');
  $query
    ->condition('oafd.status', 1);
  $query
    ->condition('oafd.skills_list', $current_skills, 'IN');
  $query
    ->condition('oafd.usage_activity', 'global');
  $result = $query
    ->execute();
  foreach ($result as $activity) {
    $activities[$activity->id] = $activity;
  }
  return $activities;
}