Example #1
0
 /**
  * Does a typeahead search on name by item type
  */
 public static function getNameTypeahead($query, $type)
 {
     $cacheKey = 'MalItem::getTypeahead_' . $query . '_' . $type;
     $retVal = Lib\Cache::Get($cacheKey);
     if (false === $retVal && strlen($query) > 1) {
         $retVal = null;
         $result = Lib\Db::Query('SELECT * FROM mal_items WHERE item_type = :type AND item_name REGEXP(:query) ORDER BY item_name', [':query' => '[[:<:]]' . $query, ':type' => $type]);
         if ($result && $result->count) {
             $retVal = [];
             while ($row = Lib\Db::Fetch($result)) {
                 $item = new MalItem($row);
                 $item->sources = $item->getParents();
                 $retVal[] = $item;
             }
         }
         Lib\Cache::Set($cacheKey, $retVal, 3600);
     }
     return $retVal;
 }
Example #2
0
 public static function render()
 {
     $query = Lib\Url::Get('q');
     $bracketId = Lib\Url::GetInt('bracketId');
     $out = Api\MalItem::getNameTypeahead($query, 'character');
     if ($bracketId) {
         $out = array_merge($out, self::_getSimilarCharacters($bracketId, $query));
     }
     // Standardize the output
     $out = self::_standardizeData($out);
     Lib\Display::renderJson($out);
 }