You are here

function coder_upgrade_upgrade_call_menu_tree_data_alter in Coder 7

Same name and namespace in other branches
  1. 7.2 coder_upgrade/conversions/call.inc \coder_upgrade_upgrade_call_menu_tree_data_alter()

Implements hook_upgrade_call_menu_tree_data().

File

coder_upgrade/conversions/call.inc, line 1867
Provides conversion routines applied to function calls.

Code

function coder_upgrade_upgrade_call_menu_tree_data_alter(&$node, &$reader) {

  // Create helper objects.
  $editor = PGPEditor::getInstance();

  // Get the function call object.
  $item =& $node->data;

  // Function now expects an array of links, rather than a query resource.
  $p1 = $item
    ->getParameter()
    ->getElement();
  if (!is_object($p1)) {

    // TODO
    return;
  }
  elseif (get_class($p1) == 'PGPOperand') {
    $resource = $p1
      ->toString();
  }
  elseif (get_class($p1) == 'PGPFunctionCall') {
    $resource = '$result';
    $statement = $editor
      ->textToStatements('$result = ' . $p1
      ->toString())
      ->getElement(0);
    $item
      ->insertStatementBefore($statement);
  }

  // Insert statements.
  $statement = $editor
    ->textToStatements('$list = array()')
    ->getElement(0);
  $item
    ->insertStatementBefore($statement);
  $statement = $editor
    ->textToStatements("foreach ({$resource} as \$item) {\n\t\$list[] = \$item;\n}")
    ->getElement(0);
  $item
    ->insertStatementBefore($statement);
  $editor
    ->setParameter($item, 0, '$list');
}