function autocomplete(folksoQuery $q, folksoDBconnect $dbc, folksoSession $fks) { $i = new folksoDBinteract($dbc); $r = new folksoResponse(); if ($i->db_error()) { $r->dbConnectionError($i->error_info()); return $r; } $sql = "SELECT tagdisplay " . "FROM tag " . "WHERE tagnorm like '" . $i->dbescape(strtolower($q->get_param('q'))) . "%'"; $i->query($sql); switch ($i->result_status) { case 'DBERR': $r->dbQueryError($i->error_info()); return $r; break; case 'NOROWS': $r->setOk(204, 'No matching tags'); return $r; break; case 'OK': $r->setOk(200, 'OK I guess'); while ($row = $i->result->fetch_object()) { /** For entirely numeric tags, we enclose them in quotes so that they can be treated as text instead of as ids. **/ if (is_numeric($row->tagdisplay)) { $r->t('"' . $row->tagdisplay . '"' . "\n"); } else { $r->t($row->tagdisplay . "\n"); } } return $r; break; } }
/** * Returns an xml list of resources associated with the same ean-13 as * the selected resource * * Web params: GET, folksores, folksoean13list */ function resEans(folksoQuery $q, folksoDBconnect $dbc, folksoSession $fks) { $r = new folksoResponse(); try { $i = new folksoDBinteract($dbc); if ($i->db_error()) { $r->dbConnectionError($i->error_info()); return $r; } $rq = new folksoResQuery(); $sql = $rq->resEans($i->dbescape($q->res)); $i->query($sql); } catch (dbConnectionException $e) { $r->dbConnectionError($e->getMessage()); return $r; } catch (dbQueryException $e) { $r->dbQueryError($e->getMessage() . $e->sqlquery); return $r; } switch ($i->result_status) { case 'NOROWS': $r->setError(404, 'Resource not found', "The requested resource is not present in the database.\n" . " Maybe it has not been indexed yet, or an erroneous identifier " . " was used. "); return $r; break; case 'OK': if ($i->result->num_rows == 1) { $r->setError(404, 'No EAN-13 data associated with this resource', "There is no EAN-13 data yet for the resource " . $q->res . "."); return $r; } else { $r->setOk(200, 'EAN-13 data found'); } } $title_line = $i->result->fetch_object(); /**popping the title that we are not using, but we could if we needed too (see note in ResQuery) **/ $df = new folksoDisplayFactory(); $dd = $df->associatedEan13resources(); $dd->activate_style('xml'); $r->t($dd->startform()); while ($row = $i->result->fetch_object()) { $r->t($dd->line($row->id, $row->url, $row->title)); } $r->t($dd->endform()); return $r; }