Finish the refactoring for Json.

This commit is contained in:
Sébastien Lucas 2014-01-08 10:54:16 +01:00
parent 91aa062860
commit 1dfdd22f43
2 changed files with 17 additions and 18 deletions

View file

@ -101,6 +101,22 @@ class JSONRenderer
return array ( "title" => $entry->title, "content" => $entry->content, "navlink" => $entry->getNavLink () ); return array ( "title" => $entry->title, "content" => $entry->content, "navlink" => $entry->getNavLink () );
} }
public static function getContentArrayTypeahead ($page) {
$out = array ();
foreach ($page->entryArray as $entry) {
if ($entry instanceof EntryBook) {
array_push ($out, array ("class" => $entry->className, "title" => $entry->title, "navlink" => $entry->book->getDetailUrl ()));
} else {
if (empty ($entry->className) xor Base::noDatabaseSelected ()) {
array_push ($out, array ("class" => $entry->className, "title" => $entry->title, "navlink" => $entry->getNavLink ()));
} else {
array_push ($out, array ("class" => $entry->className, "title" => $entry->content, "navlink" => $entry->getNavLink ()));
}
}
}
return $out;
}
public static function getJson ($complete = false) { public static function getJson ($complete = false) {
global $config; global $config;
$page = getURLParam ("page", Base::PAGE_INDEX); $page = getURLParam ("page", Base::PAGE_INDEX);
@ -114,7 +130,7 @@ class JSONRenderer
$currentPage->InitializeContent (); $currentPage->InitializeContent ();
if ($search) { if ($search) {
return $currentPage->getContentArrayTypeahead (); return self::getContentArrayTypeahead ($currentPage);
} }
$out = array ( "title" => $currentPage->title); $out = array ( "title" => $currentPage->title);

View file

@ -551,23 +551,6 @@ class Page
if (get_class ($this->entryArray [0]) == "EntryBook") return true; if (get_class ($this->entryArray [0]) == "EntryBook") return true;
return false; return false;
} }
public function getContentArrayTypeahead () {
$out = array ();
foreach ($this->entryArray as $entry) {
if ($entry instanceof EntryBook) {
array_push ($out, array ("class" => $entry->className, "title" => $entry->title, "navlink" => $entry->book->getDetailUrl ()));
} else {
if (empty ($entry->className) xor Base::noDatabaseSelected ()) {
array_push ($out, array ("class" => $entry->className, "title" => $entry->title, "navlink" => $entry->getNavLink ()));
} else {
array_push ($out, array ("class" => $entry->className, "title" => $entry->content, "navlink" => $entry->getNavLink ()));
}
}
}
return $out;
}
} }
class PageAllAuthors extends Page class PageAllAuthors extends Page