<?php

namespace Modules;

class Ography  {
    
    public $entries = array();
    
    function __construct($path="./default.csv",$header=TRUE) {
        $raw = array();
        $row = 0;

        if(is_file($path))
            $file_handle = fopen($path,"r");
        if($file_handle) {
            while(($data = fgetcsv($file_handle,1000, ",")) !== FALSE) {
                if(!$row) {
                    if($header) {
                        $keys = $data;
                        $row++;
                        continue;
                    } else {
                        $keys = FALSE;
                    }
                }
                if(is_array($keys)) {
                    $num = count($data);
                    $temp = array();
                    for($c=0; $c<$num; $c++) {
                        $temp[$keys[$c]] = $data[$c];
                    }
                    array_push($this->entries, $temp);
                    $row++;
                    unset($temp);
                } else {
                    array_push($this->entries, $data);
                }
            }
            fclose($file_handle);
        }
        
    }

    static function filter_field($key,$function) {
        if(function_exists($function)) {
            foreach ($this->entries as $k=>$entry) {
                $this->entries[$k][$key]=call_user_func($function,$entry[$key]);
            }
            return TRUE;
        } else {
            return FALSE;
        }
    }
    static function get_item() {
        return array();
    }
}