You are here

public function Matrix::shift in Business Rules 8

Same name and namespace in other branches
  1. 2.x src/Util/Flowchart/Matrix.php \Drupal\business_rules\Util\Flowchart\Matrix::shift()

Shift cells that contains one element to bottom, left or right.

Parameters

\Drupal\business_rules\Util\Flowchart\Element $element: The element.

string $direction: The direction: bottom|left|right.

int $distance: The distance to shift.

File

src/Util/Flowchart/Matrix.php, line 349

Class

Matrix
The matrix to handle the Business Rule flowchart.

Namespace

Drupal\business_rules\Util\Flowchart

Code

public function shift(Element $element, $direction, $distance = 1) {
  switch ($direction) {
    case 'bottom':
      $cells = $this
        ->getBottomCells($element);
      $cells = array_reverse($cells);
      foreach ($cells as $cell) {
        $x = $cell['index_x'];
        $y = $cell['index_y'];
        $element = $cell['element'];
        $this
          ->putElementInPosition($element, $x, $y + $distance);
        $this->matrix[$x][$y]['element'] = NULL;
      }
      break;
    case 'right':
      $cells = $this
        ->getRightCells($element);
      $cells = array_reverse($cells);
      foreach ($cells as $cell) {
        $x = $cell['index_x'];
        $y = $cell['index_y'];
        $element = $cell['element'];
        $this
          ->putElementInPosition($element, $x + $distance, $y);
        $this->matrix[$x][$y]['element'] = NULL;
      }
      break;
    case 'left':
      $cells = $this
        ->getLeftCells($element);
      foreach ($cells as $cell) {
        $x = $cell['index_x'];
        $y = $cell['index_y'];
        $element = $cell['element'];
        $this
          ->putElementInPosition($element, $x - $distance, $y);
        $this->matrix[$x][$y]['element'] = NULL;
      }
      break;
  }
}