Skip to content

Commit

Permalink
fixed finding element on array
Browse files Browse the repository at this point in the history
  • Loading branch information
julianCast committed Feb 28, 2017
1 parent 7649081 commit 5784358
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions Controller/api/getStory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
$placeName = strtolower($_POST['place']);

// Stories already read by user
$readStories = $_POST['read_stories'];
$readStories = $_POST['read_stories'];
// Language user
$lang = $_POST['lang'];

Expand Down Expand Up @@ -67,10 +67,10 @@
}

// Get random story from DB
if ($readStories) {
if (count($readStories) > 0) {
do {
$rndStory = Historia::random($lang);
} while (!_isStoryUnique($rndStory->id));
} while (array_search($rndStory->id, $readStories) != FALSE);
} else {
$rndStory = Historia::random($lang);
}
Expand Down Expand Up @@ -157,18 +157,19 @@
"title" => $title,
"story" => $storyText,
"author" => $author,
"storyID" => $rndStory->id
"storyID" => $rndStory->id,
"test" => $readStories
);
header('Content-Type: application/json');

echo json_encode($arrayHistoria);

// Check if @id parameter is found in array
function _isStoryUnique($id) {
foreach ($readStories as &$key) {
if ($id != $key) {
return true;
break;
}
}
}
// function _isStoryUnique($id) {
// foreach ($readStories as &$key) {
// if ($id != $key) {
// return true;
// break;
// }
// }
// }

0 comments on commit 5784358

Please sign in to comment.