diff --git a/Conjuro/Conjuro.php b/Conjuro/Conjuro.php index dd42670..df55c23 100644 --- a/Conjuro/Conjuro.php +++ b/Conjuro/Conjuro.php @@ -50,6 +50,9 @@ */ public function DBlist($type,$filter=false){ $result=$this->db()->list($type,$filter); + foreach($data as $i => $row){ + $data[$i]['$type']=$type; + } $this->DBLog($_SESSION['user']['user'],'LIST',$type,['filter'=>$filter,'count'=>count($result)]); return $result; } @@ -58,10 +61,7 @@ * Return single entity from DB */ public function DBget($type,$key=""){ - $data=$this->db()->get($type,$key); - foreach($data as $i => $row){ - $data[$i]['$type']=$type; - } + $data=$this->db()->get($type,$key); $this->DBLog($_SESSION['user']['user'],'GET',$type,['id'=>$id]); return $data; } @@ -152,7 +152,7 @@ public function login($usr,$pwd){ $_SESSION['user']=null; // Reset previous login if any $usr=strtolower($usr); - $user=$this->DBget('users',["user"=>$usr]);// TODO check active field. + $user=$this->DBget('users',$usr);// TODO check active field. $user['user']=strtolower($user['user']); if ($user) return $_SESSION['user']=$user; diff --git a/Conjuro/dirDB.php b/Conjuro/dirDB.php index 536b01f..93fde5a 100644 --- a/Conjuro/dirDB.php +++ b/Conjuro/dirDB.php @@ -23,19 +23,13 @@ public function insert($table,$data,$many=false){ $url=$this->url; if ($many){ - $this->call("${url}/action/insertMany",[ - "dataSource"=>$this->dataSource, - "database"=>$this->db, - "collection"=>$table, - "document"=>$data,// <- in this case $data should be a simepl array of associative arrays - ]); + foreach($data as $v){ + $id=$v["id"]=$this->guidv4(); + $this->write("$base/$table/$id.json",$v); + } }else{ - $this->call("${url}/action/insertOne",[ - "dataSource"=>$this->dataSource, - "database"=>$this->db, - "collection"=>$table, - "document"=>$data, - ]); + $id=$data["id"]=$this->guidv4(); + $this->write("$base/$table/$id.json",$data); } } @@ -69,11 +63,33 @@ } function read($path){ + if (!file_exists($path)) + return null; $result=file_get_contents($path); if ($result===false) return null; return json_decode($result,true); } + + function write($path,$data){ + var_dump($path);die(); + $data=json_encode($data); + file_put_contents($path,$data); + } + + function guidv4($data = null) { + // Generate 16 bytes (128 bits) of random data or use the data passed into the function. + $data = $data ?? random_bytes(16); + assert(strlen($data) == 16); + + // Set version to 0100 + $data[6] = chr(ord($data[6]) & 0x0f | 0x40); + // Set bits 6-7 to 10 + $data[8] = chr(ord($data[8]) & 0x3f | 0x80); + + // Output the 36 character UUID. + return vsprintf('%s%s-%s-%s-%s-%s%s%s', str_split(bin2hex($data), 4)); + } } ?> \ No newline at end of file diff --git a/Conjuro/myJsonDB.php b/Conjuro/myJsonDB.php new file mode 100644 index 0000000..c54a190 --- /dev/null +++ b/Conjuro/myJsonDB.php @@ -0,0 +1,4 @@ + Json database connector + // MyJson is a connection to MySQL that imitates partially no-sql databases like Mongo. +?> \ No newline at end of file diff --git a/content/controls/common-admin.php b/content/controls/common-admin.php index 330f72d..2571d52 100644 --- a/content/controls/common-admin.php +++ b/content/controls/common-admin.php @@ -42,6 +42,8 @@ } }, new class("builder") extends Control{ + // Para medir el layout usar una clase Page falsa que genere metricas sobre el uso del layout + protected function renderControl($meta,$data) { ?>