Skip to content

Commit

Permalink
added storiesLength API and improved getStory
Browse files Browse the repository at this point in the history
  • Loading branch information
julianCast committed Feb 19, 2017
1 parent 87d23fc commit 0bdf661
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 27 deletions.
3 changes: 2 additions & 1 deletion .htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ RewriteRule cierraSesion$ Controller/cierraSesion.php
RewriteRule grabaHistoria$ Controller/grabarHistoria.php

# API Controllers
RewriteRule api/getStory$ Controller/api/getStory.php
RewriteRule api/get-story$ Controller/api/getStory.php
RewriteRule api/get-stories-length$ Controller/api/getStoriesLength.php

# Ver PHP errors
php_flag display_errors off
Expand Down
11 changes: 11 additions & 0 deletions Controller/api/getStoriesLength.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
/*
* Get stories collection length
*/
require_once '../Model/Historia.php';
require_once '../Controller/sesionCheck.php';

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


52 changes: 27 additions & 25 deletions Controller/api/getStory.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,45 +72,47 @@
do {
$rndStory = Historia::random($lang);
} while (!_isStoryUnique($rndStory->id));

$historia = new Historia($rndStory->id, $rndStory->titulo, $rndStory->contenido, $rndStory->autor, $rndStory->fecha);
// Get specific language
$langTitle = "titulo-".$lang;
$langStory = "contenido-".$lang;
$historia = new Historia($rndStory->id, $rndStory->$langTitle, $rndStory->$langStory, $rndStory->autor, $rndStory->fecha);

// Aumentar numero de Cuentos leidos por ese user
// $usuario = new Usuario($usuarioSes,"","","","","");
// $usuario->addNumLeidos();

// Get story info
$tittle = $historia->getTitulo();
$title = $historia->getTitulo();
$storyText = $historia->getContenido();
$author = $historia->getAutor();


// Spanish attributes
if ( $lang == "es" ) {
// Character #1
$tittle = str_replace("artDetP1m",$artDetP1m,$tittle);
$tittle = str_replace("artDetP1",$artDetP1,$tittle);
$tittle = str_replace("oaP1",$oaP1,$tittle);
$tittle = str_replace("detIndP1",$detIndP1,$tittle);
$title = str_replace("artDetP1m",$artDetP1m,$title);
$title = str_replace("artDetP1",$artDetP1,$title);
$title = str_replace("oaP1",$oaP1,$title);
$title = str_replace("detIndP1",$detIndP1,$title);
$storyText = str_replace("artDetP1m",$artDetP1m,$storyText);
$storyText = str_replace("artDetP1",$artDetP1,$storyText);
$storyText = str_replace("oaP1",$oaP1,$storyText);
$storyText = str_replace("detIndP1",$detIndP1,$storyText);
// Character #2
$tittle = str_replace("artDetP2m",$artDetP2m,$tittle);
$tittle = str_replace("artDetP2",$artDetP2,$tittle);
$tittle = str_replace("oaP2",$oaP2,$tittle);
$tittle = str_replace("detIndP2",$detIndP2,$tittle);
$title = str_replace("artDetP2m",$artDetP2m,$title);
$title = str_replace("artDetP2",$artDetP2,$title);
$title = str_replace("oaP2",$oaP2,$title);
$title = str_replace("detIndP2",$detIndP2,$title);
$storyText = str_replace("artDetP2m",$artDetP2m,$storyText);
$storyText = str_replace("artDetP2",$artDetP2,$storyText);
$storyText = str_replace("oaP2",$oaP2,$storyText);
$storyText = str_replace("detIndP2",$detIndP2,$storyText);

// Place
$tittle = str_replace("artDetLum",$artDetLum,$tittle);
$tittle = str_replace("artDetLu",$artDetLu,$tittle);
$tittle = str_replace("oaLu",$oaLu,$tittle);
$tittle = str_replace("detIndLu",$detIndLu,$tittle);
$title = str_replace("artDetLum",$artDetLum,$title);
$title = str_replace("artDetLu",$artDetLu,$title);
$title = str_replace("oaLu",$oaLu,$title);
$title = str_replace("detIndLu",$detIndLu,$title);
$storyText = str_replace("artDetLum",$artDetLum,$storyText);
$storyText = str_replace("artDetLu",$artDetLu,$storyText);
$storyText = str_replace("oaLu",$oaLu,$storyText);
Expand All @@ -119,31 +121,31 @@
}
// Common attributes
// Character #1
$tittle = str_replace("nombP1i",$nameP1,$tittle);
$tittle = str_replace("tipoP1i",$typeP1,$tittle);
$tittle = str_replace("pronP1",$pronP1,$tittle);
$tittle = str_replace("neutP1",$neutP1,$tittle);
$title = str_replace("nombP1i",$nameP1,$title);
$title = str_replace("tipoP1i",$typeP1,$title);
$title = str_replace("pronP1",$pronP1,$title);
$title = str_replace("neutP1",$neutP1,$title);
$storyText = str_replace("nombP1i",$nameP1,$storyText);
$storyText = str_replace("tipoP1i",$typeP1,$storyText);
$storyText = str_replace("pronP1",$pronP1,$storyText);
$storyText = str_replace("neutP1",$neutP1,$storyText);

// Character #2
$tittle = str_replace("nombP2i",$nameP2,$tittle);
$tittle = str_replace("tipoP2i",$typeP2,$tittle);
$tittle = str_replace("pronP2",$pronP2,$tittle);
$tittle = str_replace("neutP2",$neutP2,$tittle);
$title = str_replace("nombP2i",$nameP2,$title);
$title = str_replace("tipoP2i",$typeP2,$title);
$title = str_replace("pronP2",$pronP2,$title);
$title = str_replace("neutP2",$neutP2,$title);
$storyText = str_replace("nombP2i",$nameP2,$storyText);
$storyText = str_replace("tipoP2i",$typeP2,$storyText);
$storyText = str_replace("pronP2",$pronP2,$storyText);
$storyText = str_replace("neutP2",$neutP2,$storyText);
// Place
$tittle = str_replace("nomLui",$placeName,$tittle);
$title = str_replace("nomLui",$placeName,$title);
$storyText = str_replace("nomLui",$placeName,$storyText);

// Send data as array
$arrayHistoria = array(
"tittle" => $tittle,
"title" => $title,
"story" => $storyText,
"author" => $author,
"storyID" => $rndStory->id
Expand Down
9 changes: 8 additions & 1 deletion Model/Historia.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,17 @@ public static function random($language){
$language = "es";
}
$conexion = StorianDB::connectDB();
$query = $conexion->query("SELECT * FROM cuento WHERE lang='".$language."' ORDER BY RAND() LIMIT 1");
$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) {
$conexion = StorianDB::connectDB();
$query = $conexion->query("SELECT * FROM `cuento`");
return $query->rowCount();
}




Expand Down

0 comments on commit 0bdf661

Please sign in to comment.