Location: PHPKode > projects > Course-manager > courseman-0.1.1/array-operations.php
<?php
  function delimited_array_elements($array,$delimiter,$zero="") {
    global $debug;
    if($debug["old-debug"]) {
?>
<pre>
delimited_array_elements
</pre>
<?php
    }
    $result = "";
    foreach($array as $element) {
      if($result == "") {
        $result = $element;
      } else {
        $result .= $delimiter . $element;
      }
    }
    return ($result == "") ? $zero : $result;
  }
  function map_function($function,$array) {
    global $debug;
    if($debug["old-debug"]) {
?>
<pre>
map_function
</pre>
<?php
    }
    $result = array();
    foreach($array as $key => $element) {
      $result[$key] = $function($element);
    }
    return $result;
  }
  function map_function_using_key($function,$array) {
    global $debug;
    if($debug["old-debug"]) {
?>
<pre>
map_function_using_key
</pre>
<?php
    }
    $result = array();
    foreach($array as $key => $element) {
      $result[$key] = $function($key,$element);
    }
    return $result;
  }
  function map_method($method,$array,$arguments) {
    global $debug;
    if($debug["old-debug"]) {
?>
<pre>
map_method
</pre>
<?php
    }
    $result = array();
    foreach($array as $key => $element) {
      $result[$key] = $element['calls']($element,$method,$arguments);
    }
    return $result;
  }
  function map_field_access($field,$array) {
    $result = array();
    foreach($array as $key => $element) {
      $result[$key] = $element[$field];
    }
    return $result;
  }
  function conjuncted($one,$other) {
    return $one && $other;
  }
  function disjuncted($one,$other) {
    return $one || $other;
  }
  function concatenated($one,$other) {
    global $debug;
    if($debug["old-debug"]) {
?>
<pre>
concatenated
</pre>
<?php
    }
    return $one . $other;
  }
  function null_reduce($ignored,$also_ignored) {
    return null;
  }
  function disjuncted_input_checks($input,$arguments) {
    global $debug;
    if($debug["old-debug"]) {
?>
<pre>
disjuncted_input_checks
</pre>
<?php
    }
    return delimited_array_elements(
		map_function(
			parenthesized,
			map_method(
				'input_check_condition',
				$input['elements'],
				$arguments)),
		'
		&& ');
  }
  function disjuncted_server_input_checks($input,$arguments) {
    return reduced_method_call($input,
                               'server_input_check_condition',
			       $arguments);
  }
  function reduced_method_call(&$object,$method,$arguments) {
    global $debug;
    if($debug["old-debug"]) {
?>
<pre>
reduced_method_call
</pre>
<?php
    }
    $result = $object['initial_' . $method];
    $reduction = concatenated;
    if(isset($object['reduction_' . $method])) {
      $reduction = $object['reduction_' . $method];
    }
    foreach ($object['elements'] as $element) {
      $result = $reduction($result,$element['calls'](
						$element,
						$method,
						$arguments));
    }
    return $result;
  }
  function fallback_to_reduced_method_call(&$object,$method,$arguments) {
    global $debug;
    if($debug["old-debug"]) {
?>
<pre>
fallback_to_reduced_method_call
</pre>
<?php
    }
    if ($object['has_method']($object,$method)) {
      return method_call($object,$method,$arguments);
    } else {
      return reduced_method_call($object,$method,$arguments);
    }
  }
?>
Return current item: Course-manager