Ejemplo n.º 1
0
function check_logic_hook_file($module_name, $event, $action_array)
{
    require_once 'include/utils/logic_utils.php';
    $add_logic = false;
    if (file_exists("custom/modules/{$module_name}/logic_hooks.php")) {
        $hook_array = get_hook_array($module_name);
        if (check_existing_element($hook_array, $event, $action_array) == true) {
            //the hook at hand is present, so do nothing
        } else {
            $add_logic = true;
            $logic_count = count($hook_array[$event]);
            if ($action_array[0] == "") {
                $action_array[0] = $logic_count + 1;
            }
            $hook_array[$event][] = $action_array;
        }
        //end if the file exists already
    } else {
        $add_logic = true;
        if ($action_array[0] == "") {
            $action_array[0] = 1;
        }
        $hook_array = array();
        $hook_array[$event][] = $action_array;
        //end if else file exists already
    }
    if ($add_logic == true) {
        //reorder array by element[0]
        //$hook_array = reorder_array($hook_array, $event);
        //!!!Finish this above TODO
        $new_contents = replace_or_add_logic_type($hook_array);
        write_logic_file($module_name, $new_contents);
        //end if add_element is true
    }
    //end function check_logic_hook_file
}
Ejemplo n.º 2
0
function remove_logic_hook($module_name, $event, $action_array)
{
    require_once 'include/utils/logic_utils.php';
    $add_logic = false;
    if (file_exists("custom/modules/" . $module_name . "/logic_hooks.php")) {
        // The file exists, let's make sure the hook is there
        $hook_array = get_hook_array($module_name);
        if (check_existing_element($hook_array, $event, $action_array) == true) {
            // The hook is there, time to take it out.
            foreach ($hook_array[$event] as $i => $hook) {
                // We don't do a full comparison below just in case the filename changes
                if ($hook[0] == $action_array[0] && $hook[1] == $action_array[1] && $hook[3] == $action_array[3] && $hook[4] == $action_array[4]) {
                    unset($hook_array[$event][$i]);
                }
            }
            $new_contents = replace_or_add_logic_type($hook_array);
            write_logic_file($module_name, $new_contents);
        }
    }
}
Ejemplo n.º 3
0
 /**
  * @dataProvider check_existing_elementProvider
  */
 public function testcheck_existing_element($hook_array, $event, $action_array, $expected)
 {
     //test with dataset containing valid and invalid cases
     $this->assertSame(check_existing_element($hook_array, $event, $action_array), $expected);
 }