Skip to content

Instantly share code, notes, and snippets.

@govaniso
Created October 1, 2019 00:10
Show Gist options
  • Save govaniso/2917498c2b7fa254babc27a1d925056b to your computer and use it in GitHub Desktop.
Save govaniso/2917498c2b7fa254babc27a1d925056b to your computer and use it in GitHub Desktop.
jardin.php
<?php
class JardinController extends AppController {
public function index() {
}
// retornar X Y para la grafica
// 5d896075f2a3a7fc14643def
public function get_xy($id = "5d896075f2a3a7fc14643def") {
$Jardin = new Jardin();
$jardin = $Jardin->get_one($id);
View::json($jardin);
}
public function set_xy($id = "5d896075f2a3a7fc14643def") {
$Jardin = new Jardin();
$jardin = $Jardin->get_one($id);
$arreglo = $jardin;
$jardin["intruso"]["x"] = 123;
$jardin["intruso"]["y"] = 345;
$jardin = $Jardin->actualizar($id, $jardin);
View::json($jardin);
}
/**
* Establece el idioma del jardin
*
* @param type $idioma 'es'
*/
public function set_lang($id, $idioma) {
$Jardin = new Jardin();
$jardin = $Jardin->get_one($id);
$jardin["lang"] = $idioma;
$jardin = $Jardin->actualizar($id, $jardin);
View::json($jardin);
}
public function get_idiomas() {
$Idiomas = new Idiomas();
$attr["fecha"] = date("h:i:s");
$IdiomaZ = new Idiomas();
$IdiomaZ->save($attr);
$idiomas = $Idiomas->findOne("5d8eaaa0c2773e2caa87d4e1");
// $idiomas->update($attr);
$idiomas = $Idiomas->findOne("5d8eaaa0c2773e2caa87d4e1");
View::json($IdiomaZ->attrs);
}
}
?>
<?php Tag::css('jardin') ?>
<?= Html::includeCss() ?>
<h1>Jardin</h1>
<div id="app_jardin">
<div id="jardin">
<div id="intruso"></div>
</div>
<div>
<div v-for="i in idiomas">
<img v-bind:src="'/kumbiaphpiot/banderas/' + i + '.jpg'">
</div>
</div>
</div>
<script>
var app_jardin = new Vue({
el: '#app_jardin',
data: {
xy: {},
x: 0,
y: 0,
idiomas: {}
},
methods: {
// Solita las coordenadas
get_xy: function () {
este = this;
axios.get('/kumbiaphpiot/jardin/get_xy/5d896075f2a3a7fc14643def').then(function (response) {
este.dispositivos = response.data;
este.x = response.data.intruso.x;
este.y = response.data.intruso.y;
// cada cierto tiempo se manda llamar a si mism
document.getElementById("intruso").style.marginLeft = este.x + "px";
document.getElementById("intruso").style.marginTop = este.y + "px";
setTimeout(function () {
app_jardin.get_xy();
}, 1000);
});
},
get_idiomas: function () {
este = this;
axios.get('/kumbiaphpiot/jardin/get_idiomas').then(function (response) {
este.idiomas = response.data;
});
}
},
mounted: function () {
this.get_xy();
this.get_idiomas();
}
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment