-
Notifications
You must be signed in to change notification settings - Fork 7
Resolução do exercicio #34 #35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: desafios
Are you sure you want to change the base?
Changes from 28 commits
87e7c79
dd3e676
b186fef
0e36c6b
56a063e
6dc8534
bf9e843
ca1e557
d8ff9aa
e42eb56
f86a705
ce624e9
20f458d
ffca46f
21b157c
783795a
eee03db
37026dd
1214824
54ec617
6231266
7c8591a
1397291
2a0aa95
846ec52
911f0d7
7ed697d
b8fbf6e
7504ed3
50746ff
4c0a65b
bf08ad7
61c99f7
5582e2f
9617bf9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| <?php | ||
|
|
||
| require '../../vendor/autoload.php'; | ||
| use DojoPHP\UpdateFileJson\UpdateFileJsonAPI; | ||
|
|
||
| // Preenchendo dados padrão | ||
|
|
||
| $data = [ | ||
| 'nome' => 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); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,75 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="pt"> | ||
| <head> | ||
| <meta charset="UTF-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0"> | ||
| <meta http-equiv="X-UA-Compatible" content="ie=edge"> | ||
| <title>Atualizando ficheiro do dojo</title> | ||
| <!-- Compiled and minified CSS --> | ||
| <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/0.100.2/css/materialize.min.css"> | ||
| <link href="https://fonts.googleapis.com/css?family=Inconsolata" rel="stylesheet"> | ||
| <style> | ||
| *{ | ||
| font-family:'Inconsolata', monospace; | ||
| font-size: 14pt; | ||
| } | ||
| body{ | ||
| color:#555; | ||
| } | ||
| h3{ | ||
| padding-bottom: 12px; | ||
| border-bottom: 1px solid #f0f0f0; | ||
| } | ||
| .red{ | ||
| background: transparent !important; | ||
| color: #F44336; | ||
| } | ||
| #avatar | ||
| { | ||
| font-size: 12pt !important; | ||
| font-weight: lighter; | ||
| } | ||
| .btn{ | ||
| background-color: #81d4fa; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body class="white"> | ||
| <div class=""> | ||
| <h3 class="center-align truncate"> Adicionando novos dados ao arquivo json </h3> | ||
|
|
||
| <div class="container"> | ||
| <p class="red">* Preencha os campos </p> | ||
| <label for="name">*Nome</label> | ||
| <input type="text" class="form-control" name="name" id="name" placeholder=" Eg. Acidiney Dias "/> | ||
| <label for="function">*Função</label> | ||
| <input type="text" class="form-control" name="function" id="function" placeholder=" Eg. Desenvolvedor PHP "/> | ||
| <button onclick="onSubmit()" class="btn">Carregar novo registro</button> | ||
| <p class="red"> Status de retorno </p> | ||
| <div id="return"></div> | ||
| <hr /> | ||
| <p class="red"> * PREVIEW</p> | ||
| </div> | ||
| <iframe src="http://dojo-php.herokuapp.com/ConvertjsonToArray/" width="100%" height="600" style="border:0px"></iframe> | ||
|
||
| </div> | ||
| <script id="frame" src="https://code.jquery.com/jquery-3.2.1.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script> | ||
| <script> | ||
|
|
||
| function onSubmit(){ | ||
| $.ajax({ | ||
| url:"controller.php", | ||
| type:"POST", | ||
| dataType: 'json', | ||
| data: { | ||
| "name": $("#name").val(), | ||
| "function": $("#function").val(), | ||
| }, | ||
| success: function(data){ | ||
| $('#return').html(data); | ||
| document.getElementById('frame').contentDocument.location.reload(true); | ||
| } | ||
| }); | ||
| } | ||
| </script> | ||
| </body> | ||
| </html> | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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": "" | ||
| } | ||
| ] | ||
| } | ||
| {"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":""},{"nome":"Cuz\u00e3o","cargo":"aaa","avatar":""},{"nome":"aa","cargo":"aaa","avatar":""}]} | ||
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| <?php | ||
|
|
||
| namespace DojoPHP\UpdateFileJson; | ||
|
|
||
| /** | ||
| * @author Acidiney Dias | ||
| * @desc this class expected three parameters [$dataInput(is Array), $source and a $key] | ||
| * @return json with a message with status the return | ||
| */ | ||
| class UpdateFileJsonAPI | ||
| { | ||
|
|
||
| public $source; | ||
| public $data = []; | ||
| public $openFile; | ||
| public $alterFile; | ||
| public $key; | ||
|
|
||
| public function __construct($dataInputs = [], $source, $key) | ||
| { | ||
| $this->source = $source; | ||
| $this->data = $dataInputs; | ||
| $this->key = $key; | ||
| } | ||
|
|
||
| public function UpdateFile() | ||
| { | ||
|
|
||
| // var_dump($this->data); echo "<br />"; | ||
| // 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 not was updated!"], 400); | ||
|
||
| endif; | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
target="_blank"é meio inseguro de usar 💥.. Viu a minha sugestão na outra vez @acidiney?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Claro que vi, isso é do exercicio antigo nem retifiquei mais kkkk