You are here

public static function MaestroEngine::getAssignedNamesOfQueueItem in Maestro 3.x

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

Returns the assignment records as an associative array (if specified as such), or keyed array with the assigned ID as the key and the assignment as a string, for the specific Queue item.

Format of the associative array is.

[Assigned ID][ 'assign_id' => the assigned ID (username, role name etc), 'by_variable' => the assignment type if by variable or not (fixed or variable), 'assign_type' => the assignment type, 'id' => the ID of the assignment record ]

Alternatively the structure of the keyed single entry array is: [Assigned ID (username, role name, etc.)] => "The Assigned ID":"fixed or variable"

Parameters

string $queueID: The queue ID for the fetch to operate on.

bool $associativeArray: Set to TRUE to have an associative array returned. FALSE for simple keyed array on the asignees.

3 calls to MaestroEngine::getAssignedNamesOfQueueItem()
MaestroEngineActiveAssignments::render in src/Plugin/views/field/MaestroEngineActiveAssignments.php
Renders the field.
MaestroEngineAdminOperations::render in src/Plugin/views/field/MaestroEngineAdminOperations.php
Renders the field.
maestro_tokens in ./maestro.module
Implements hook_tokens().

File

src/Engine/MaestroEngine.php, line 728

Class

MaestroEngine
Class MaestroEngine.

Namespace

Drupal\maestro\Engine

Code

public static function getAssignedNamesOfQueueItem($queueID, $associativeArray = FALSE) {
  $output = [];

  // Lets get the assignments based on this queue ID.
  $query = \Drupal::entityTypeManager()
    ->getStorage('maestro_production_assignments')
    ->getQuery();
  $query
    ->condition('queue_id', $queueID);
  $entity_ids = $query
    ->execute();
  if (count($entity_ids) > 0) {
    foreach ($entity_ids as $assignmentID) {
      $assignRecord = \Drupal::entityTypeManager()
        ->getStorage('maestro_production_assignments')
        ->load($assignmentID);
      $assignRecord->by_variable
        ->getString() == 0 ? $type = t('Fixed') : ($type = t('Variable'));
      if ($associativeArray) {
        $output[$assignRecord->assign_id
          ->getString()] = [
          'assign_id' => $assignRecord->assign_id
            ->getString(),
          'by_variable' => $type,
          'assign_type' => $assignRecord->assign_type
            ->getString(),
          'id' => $assignRecord->id
            ->getString(),
        ];
      }
      else {

        // technically, you should only have one assignment record per entity here.  So shouldn't have to
        // worry about having the same username or role or group etc. named twice and having the array overwritten.
        $output[$assignRecord->assign_id
          ->getString()] = $assignRecord->assign_id
          ->getString() . ':' . $type;
      }
    }
  }
  return $output;
}