Back to Workflow class

Method getValidTransition

public object
getValidTransition
(array $pks, int $transitionId)
Check if a transition can be executed
Parameters
  • int[] $pks The item IDs, which should use the transition
  • int $transitionId The transition which should be executed
Returns
  • object | null
Class: Workflow
Project: Joomla

Method getValidTransition - Source code

/**
 * Check if a transition can be executed
 *
 * @param   integer[]  $pks           The item IDs, which should use the transition
 * @param   integer    $transitionId  The transition which should be executed
 *
 * @return  object | null
 */
public function getValidTransition(array $pks, int $transitionId)
{
    $pks = ArrayHelper::toInteger($pks);
    $pks = array_filter($pks);
    if (!\count($pks)) {
        return null;
    }
    $query = $this->db->getQuery(true);
    $user = $this->app->getIdentity();
    $query->select([$this->db->quoteName('t.id'), $this->db->quoteName('t.to_stage_id'), $this->db->quoteName('t.from_stage_id'), $this->db->quoteName('t.options'), $this->db->quoteName('t.workflow_id')])->from([$this->db->quoteName('#__workflow_transitions', 't')])->join('INNER', $this->db->quoteName('#__workflows', 'w'))->join('LEFT', $this->db->quoteName('#__workflow_stages', 's'), $this->db->quoteName('s.id') . ' = ' . $this->db->quoteName('t.to_stage_id'))->where([$this->db->quoteName('t.id') . ' = :id', $this->db->quoteName('t.workflow_id') . ' = ' . $this->db->quoteName('w.id'), $this->db->quoteName('t.published') . ' = 1', $this->db->quoteName('w.extension') . ' = :extension'])->bind(':id', $transitionId, ParameterType::INTEGER)->bind(':extension', $this->extension);
    $transition = $this->db->setQuery($query)->loadObject();
    $parts = explode('.', $this->extension);
    $option = reset($parts);
    if (!empty($transition->id) && $user->authorise('core.execute.transition', $option . '.transition.' . (int) $transition->id)) {
        return $transition;
    }
    return null;
}