Skip to content

Commit

Permalink
fixes and improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
julianCast committed Feb 20, 2017
1 parent 0bdf661 commit 4130e5d
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 19 deletions.
6 changes: 3 additions & 3 deletions Controller/api/getStoriesLength.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@
/*
* Get stories collection length
*/
require_once '../Model/Historia.php';
require_once '../Controller/sesionCheck.php';
require_once '../../Model/Historia.php';

$collectionLength = Historia::storiesLength();
return json_encode($collectionLength);

echo json_encode($collectionLength);


27 changes: 18 additions & 9 deletions Controller/api/getStory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,9 @@
/*
* Procesa los datos recibidos de estructura.js a traves de ajax y crea la historia con las caracteristicas elegidas por el user.
*/
require_once '../Model/Historia.php';
require_once '../Model/Personaje.php';
require_once '../Model/Lugar.php';
require_once '../Model/Usuario.php';
require_once '../Controller/sesionCheck.php';
require_once '../../Model/Historia.php';
require_once '../../Model/Personaje.php';
require_once '../../Model/Lugar.php';

/*
PARAMETERS RECEIVED
Expand Down Expand Up @@ -69,12 +67,23 @@
}

// Get random story from DB
do {
if ($readStories) {
do {
$rndStory = Historia::random($lang);
} while (!_isStoryUnique($rndStory->id));
} else {
$rndStory = Historia::random($lang);
} while (!_isStoryUnique($rndStory->id));
}

// Get specific language
$langTitle = "titulo-".$lang;
$langStory = "contenido-".$lang;
if ($lang == "es") {
$langTitle = titulo_es;
$langStory = contenido_es;
} else {
$langTitle = titulo_en;
$langStory = contenido_en;
}

$historia = new Historia($rndStory->id, $rndStory->$langTitle, $rndStory->$langStory, $rndStory->autor, $rndStory->fecha);

// Aumentar numero de Cuentos leidos por ese user
Expand Down
2 changes: 1 addition & 1 deletion Controller/procesaHistoria.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}
// Selecciona historia random de DB
$historiaRnd = Historia::random();
$historia = new Historia($historiaRnd->id, $historiaRnd->titulo, $historiaRnd->contenido, $historiaRnd->autor, $historiaRnd->fecha);
$historia = new Historia($historiaRnd->id, $historiaRnd->titulo_es, $historiaRnd->contenido_es, $historiaRnd->autor, $historiaRnd->fecha);

// Aumentar numero de Cuentos leidos por ese user
$usuario = new Usuario($usuarioSes,"","","","","");
Expand Down
9 changes: 3 additions & 6 deletions Model/Historia.php
Original file line number Diff line number Diff line change
Expand Up @@ -107,17 +107,14 @@ public function toJSON(){
return json_encode($out);
}
// Devuelve un cuento random.
public static function random($language){
if (!$language) {
$language = "es";
}
public static function random(){
$conexion = StorianDB::connectDB();
$query = $conexion->query("SELECT * FROM cuento ORDER BY RAND() LIMIT 1");
return $tabla = $query->fetchObject();
}

// It returns collection length from specific language
public function storiesLength($language) {
// It returns collection length
public static function storiesLength() {
$conexion = StorianDB::connectDB();
$query = $conexion->query("SELECT * FROM `cuento`");
return $query->rowCount();
Expand Down

0 comments on commit 4130e5d

Please sign in to comment.