You are here

public static function MaestroEngine::getAssignedTaskQueueIds in Maestro 8.2

Same name and namespace in other branches
  1. 3.x src/Engine/MaestroEngine.php \Drupal\maestro\Engine\MaestroEngine::getAssignedTaskQueueIds()

Fetch a user's assigned tasks. Maestro base functionality will determine user and role assignments. You can implement hook_maestro_post_fetch_assigned_queue_tasks(int userID, array &$entity_ids) to fetch your own custom assignments whether that be by OG or some other assignment method.

Parameters

int $userID: The numeric (integer) user ID for the user you wish to get their tasks for.

Return value

array An array of entity IDs if they exist. These entity IDs are the IDs from the maestro_queue table

2 calls to MaestroEngine::getAssignedTaskQueueIds()
MaestroEngine::canUserExecuteTask in src/Engine/MaestroEngine.php
Determines if a user is assigned to execute a specific task.
MaestroTaskConsoleController::getTasks in modules/maestro_taskconsole/src/Controller/MaestroTaskConsoleController.php
GetTasks method This method is called by the menu router for /taskconsole. The output of this method is the current user's task console.

File

src/Engine/MaestroEngine.php, line 581

Class

MaestroEngine
Class MaestroEngine.

Namespace

Drupal\maestro\Engine

Code

public static function getAssignedTaskQueueIds($userID) {

  /*
   * Assignments by variable are done in the assignment table identical to that
   * of the regular user or role assignment, however the only difference is that
   * there is an entity reference to the variable's ID and the by_variable flag
   * is set.  Therefore we can simply look for role and user assignments with
   * this query and return that as the queue IDs assigned to the user.
   *
   * The state of the task item needs to be checked to ensure that it has not been completed.
   */
  \Drupal::entityTypeManager()
    ->getViewBuilder('maestro_production_assignments')
    ->resetCache();
  $account = User::load($userID);
  $userRoles = $account
    ->getRoles(TRUE);
  $query = \Drupal::entityQuery('maestro_production_assignments');
  $andConditionByUserID = $query
    ->andConditionGroup()
    ->condition('assign_id', $account
    ->getAccountName())
    ->condition('assign_type', 'user');
  $orConditionAssignID = $query
    ->orConditionGroup()
    ->condition($andConditionByUserID);
  $roleAND = NULL;
  foreach ($userRoles as $userRole) {
    $roleAND = $query
      ->andConditionGroup()
      ->condition('assign_id', $userRole)
      ->condition('assign_type', 'role');
    $orConditionAssignID
      ->condition($roleAND);
  }
  $query
    ->condition($orConditionAssignID);
  $query
    ->condition('task_completed', '0');
  $assignmentIDs = $query
    ->execute();
  $queueIDs = [];
  foreach ($assignmentIDs as $entity_id) {
    $assignmentRecord = \Drupal::entityTypeManager()
      ->getStorage('maestro_production_assignments')
      ->load($entity_id);

    // Check if this queueID and the associated process is complete or not.
    $queueRecord = self::getQueueEntryById($assignmentRecord->queue_id
      ->getString());
    if ($queueRecord) {
      $processRecord = self::getProcessEntryById($queueRecord->process_id
        ->getString());
      if ($queueRecord->status
        ->getString() == '0' && $queueRecord->archived
        ->getString() == '0' && $processRecord->complete
        ->getString() == '0') {
        $queueIDs[] = $assignmentRecord->queue_id
          ->getString();
      }
    }
  }

  // Now to invoke other modules to add their entity IDs to the already fetched list
  // pass to the invoked handler, the user ID and the current set of entity IDs.
  \Drupal::moduleHandler()
    ->invokeAll('maestro_post_fetch_assigned_queue_tasks', [
    $userID,
    &$queueIDs,
  ]);
  return $queueIDs;
}