コード例 #1
0
ファイル: folksoResQuery-test.php プロジェクト: josf/folkso
 function testResEans()
 {
     $rq = new folksoResQuery();
     $sql = $rq->resEans(102);
     $this->assertTrue(is_string($sql));
     $this->assertNoPattern('/<<</', $sql);
     $this->assertPattern('/=\\s+r\\.id/', $sql);
     $this->assertPattern('/UNION/', $sql);
     $this->assertPattern('/=\\s+r\\.id/', $sql);
     $sql2 = $rq->resEans('http://www.fabula.org/actualites/article22843.php');
     $this->assertTrue(is_string($sql2));
     $this->assertNoPattern('/<<</', $sql2);
     $this->assertPattern('/url_whack/', $sql2);
     $this->assertNoPattern('/resource_id\\s+=\\s+1233/', $sql2, 'No EAN without option');
     $sql3 = $rq->resEans('http://www.fabula.org/actualites/article22843.php', 0, false, true);
 }
コード例 #2
0
ファイル: resource.php プロジェクト: josf/folkso
/**
 * 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;
}