diff --git a/app/ConvertjsonToArray/index.html b/app/ConvertjsonToArray/index.html index 1d6095b..e011dd0 100644 --- a/app/ConvertjsonToArray/index.html +++ b/app/ConvertjsonToArray/index.html @@ -9,8 +9,7 @@ .container { box-sizing: border-box; - padding-top:5%; - + padding-top:5%; } .panel { @@ -31,14 +30,13 @@ } - -
+ +

Caminho do arquivo: data/codingdojo.json

-

Lista de membros

@@ -57,7 +55,6 @@

Criado Por Acidiney Dias

$.ajax({ url:"controller.php", type:"POST", - data:{'date': data, 'opt' : 1}, dataType: 'json', success: function(data){ $('#carregamento').html(data.app); @@ -67,4 +64,4 @@

Criado Por Acidiney Dias

} - \ No newline at end of file + diff --git a/app/UpdateFileJson/controller.php b/app/UpdateFileJson/controller.php new file mode 100644 index 0000000..c9f3a7f --- /dev/null +++ b/app/UpdateFileJson/controller.php @@ -0,0 +1,19 @@ + addslashes($_POST['name']), + 'cargo' => addslashes($_POST['function']), + 'avatar' => '', +]; +$source = '../../data/codingdojo.json'; +$key = 'membros'; + +// Instaciando Classe UpdateFileJsonAPI +$new = new UpdateFileJsonAPI($data, $source, $key); +$msg = $new->UpdateFile(); +echo json_encode($msg); \ No newline at end of file diff --git a/app/UpdateFileJson/index.html b/app/UpdateFileJson/index.html new file mode 100644 index 0000000..0a8d1eb --- /dev/null +++ b/app/UpdateFileJson/index.html @@ -0,0 +1,76 @@ + + + + + + + Atualizando ficheiro do dojo + + + + + + +
+

Adicionando novos dados ao arquivo json

+ +
+

* Preencha os campos

+ + + + + +

Status de retorno

+
+
+

* PREVIEW

+
+ +
+ + + + \ No newline at end of file diff --git a/app/index.php b/app/index.php new file mode 100644 index 0000000..25d2fad --- /dev/null +++ b/app/index.php @@ -0,0 +1,42 @@ + + + + + + + Dojo PHP -> Projects + + + + + + + +

Lista diretórios

+

+
+ read()) !== false){ + if(is_dir($arquivo)){ + echo " + ".$arquivo.'
'; + } + } + $diretorio -> close(); + ?> +
+

@acidiney_dias

+ + \ No newline at end of file diff --git a/data/codingdojo.json b/data/codingdojo.json index 549c423..3b8829c 100644 --- a/data/codingdojo.json +++ b/data/codingdojo.json @@ -1,67 +1 @@ -{ - "app": "Coding Dojo Angola", - "url": "http://codingdojoangola.com", - "email": "geral@codingdojoangola.com", - "membros": [ - { - "nome": "Lucius Curado", - "cargo": "Moderador e Organizador", - "avatar": "" - }, - { - "nome": "José Cage", - "cargo": "Moderador e instrutor", - "avatar": "" - }, - { - "nome": "Doriel Fonseca", - "cargo": "Instrutor #dojojavascript", - "avatar": "" - }, - { - "nome": "Pedro Massango", - "cargo": "Desenvolvedor Java", - "avatar": "" - }, - { - "nome": "Eleandro Duzentos", - "cargo": "Desenvolvedor PHP e .Net", - "avatar": "" - }, - { - "nome": "Renato Martins", - "cargo": "Desenvolvedor Java e PHP", - "avatar": "" - }, - { - "nome": "Victor Kiffen", - "cargo": "Desenvolvedor Java", - "avatar": "" - }, - { - "nome": "Jetro Domingos", - "cargo": "Desenvolvedor Java", - "avatar": "" - }, - { - "nome": "Acidiney Dias", - "cargo": "Desenvolvedor PHP", - "avatar": "" - }, - { - "nome": "Nelson Júnior", - "cargo": "Desenvolvedor PHP", - "avatar": "" - }, - { - "nome": "Masiry Link", - "cargo": "Desenvolvedor PHP", - "avatar": "" - }, - { - "nome": "Aleixo Jeronimo", - "cargo": "", - "avatar": "" - } - ] -} \ No newline at end of file +{"app":"Coding Dojo Angola","url":"http:\/\/codingdojoangola.com","email":"geral@codingdojoangola.com","membros":[{"nome":"Lucius Curado","cargo":"Moderador e Organizador","avatar":""},{"nome":"Jos\u00e9 Cage","cargo":"Moderador e instrutor","avatar":""},{"nome":"Doriel Fonseca","cargo":"Instrutor #dojojavascript","avatar":""},{"nome":"Pedro Massango","cargo":"Desenvolvedor Java","avatar":""},{"nome":"Eleandro Duzentos","cargo":"Desenvolvedor PHP e .Net","avatar":""},{"nome":"Renato Martins","cargo":"Desenvolvedor Java e PHP","avatar":""},{"nome":"Victor Kiffen","cargo":"Desenvolvedor Java","avatar":""},{"nome":"Jetro Domingos","cargo":"Desenvolvedor Java","avatar":""},{"nome":"Acidiney Dias","cargo":"Desenvolvedor PHP","avatar":""},{"nome":"Nelson J\u00fanior","cargo":"Desenvolvedor PHP","avatar":""},{"nome":"Masiry Link","cargo":"Desenvolvedor PHP","avatar":""},{"nome":"Aleixo Jeronimo","cargo":"","avatar":""}]} \ No newline at end of file diff --git a/src/ArrayDeInformacoes/ArrayInformationsAPI.php b/src/ArrayDeInformacoes/ArrayInformationsAPI.php index a959061..0577072 100644 --- a/src/ArrayDeInformacoes/ArrayInformationsAPI.php +++ b/src/ArrayDeInformacoes/ArrayInformationsAPI.php @@ -26,11 +26,11 @@ public function __construct($email, $name, $telephone) public function CreateArrayWithInformation() { $this->data = - [ - 'E-mail' => $this->email, - 'Name' => $this->name, - 'Telefone' => $this->telephone, - ]; + [ + 'E-mail' => $this->email, + 'Name' => $this->name, + 'Telefone' => $this->telephone, + ]; return $this->data; } diff --git a/src/ConvertJsonToArray/ConvertJsonForArrayAPI.php b/src/ConvertJsonToArray/ConvertJsonForArrayAPI.php index c8108c9..350b83b 100644 --- a/src/ConvertJsonToArray/ConvertJsonForArrayAPI.php +++ b/src/ConvertJsonToArray/ConvertJsonForArrayAPI.php @@ -9,17 +9,18 @@ */ class ConvertJsonForArrayAPI { - public $source; - public $data; + public $source; + public $data; - public function __construct($source) - { - $this->source = $source; - $this->data = file_get_contents($source); - } + public function __construct($source) + { + $this->source = $source; + } - public function Itera() - { - return json_decode($this->data, true); - } -} + public function Itera() + { + $this->data = file_get_contents($this->source); + + return json_decode($this->data, true); + } +} \ No newline at end of file diff --git a/src/UpdateFileJson/UpdateFileJsonAPI.php b/src/UpdateFileJson/UpdateFileJsonAPI.php new file mode 100644 index 0000000..9613c58 --- /dev/null +++ b/src/UpdateFileJson/UpdateFileJsonAPI.php @@ -0,0 +1,50 @@ +source = $source; + $this->data = $dataInputs; + $this->key = $key; + } + + public function UpdateFile() + { + + // var_dump($this->data); echo "
"; + // I'm open file Json passed + $this->openFile = file_get_contents($this->source); + + // Transform "temporary" he in array for php understand + $this->alterFile = json_decode($this->openFile, true); + + // Now I'm used a method the PHP for add the new data in my collection data, + //using array push + + array_push($this->alterFile["$this->key"], $this->data); + + // So I'm encode again the file for json formatter + $this->alterFile = json_encode($this->alterFile); + + // In the end, I'm add the new data in my file original + if (file_put_contents($this->source, $this->alterFile)): + return json_encode(["message" => "File updated with success!"], 201); else: + return json_encode(["message" => "File was not updated!"], 400); + endif; + } +} diff --git a/tests/ConvertJsonToArray/ConvertJsonForArrayTest.php b/tests/ConvertJsonToArray/ConvertJsonForArrayTest.php index 1cbbd18..f47259c 100644 --- a/tests/ConvertJsonToArray/ConvertJsonForArrayTest.php +++ b/tests/ConvertJsonToArray/ConvertJsonForArrayTest.php @@ -1,9 +1,11 @@ url = 'https://github.com/codingdojoangola/dojophp/raw/desafios/data/codingdojo.json'; - $this->instance = new ConvertJsonForArrayAPI($this->url); + public function testGetData() + { + $this->url = './data/codingdojo.json'; + $this->instance = new ConvertJsonForArrayAPI($this->url); - $data = $this->instance->Itera(); + $data = $this->instance->Itera(); - $this->assertNotEmpty($data); - $this->assertInternalType('array', $data); - $this->assertArrayHasKey('membros', $data); - } + $this->assertNotEmpty($data); + $this->assertInternalType('array', $data); + $this->assertArrayHasKey('membros', $data); + } } + diff --git a/tests/UpdateFileJsonTest/UpdateFileJsonTest.php b/tests/UpdateFileJsonTest/UpdateFileJsonTest.php new file mode 100644 index 0000000..6980ce8 --- /dev/null +++ b/tests/UpdateFileJsonTest/UpdateFileJsonTest.php @@ -0,0 +1,37 @@ +source = "./data/codingdojo.json"; + $this->key = "membros"; + $this->data = [ + "nome" => "Test Unit", + "cargo" => "Test Function", + "avatar" => "" + ]; + // New instance the API + $UFJA = new UpdateFileJsonAPI($this->data, $this->source, $this->key); + $result = json_decode($UFJA->UpdateFile(), true); + // Testing result + $this->assertNotEmpty($result); + $this->assertInternalType('array', $result); + $this->assertArrayHasKey('message', $result); + } + } \ No newline at end of file