pear: contribution ?
| From: | alx alx | Date: | Wed, 16 Jan 2002 15:05:35 +0000 |
| Subject: | pear: contribution ? | ||
| Groups: | php.pear.cvs | ||
| Request: | Send a blank email to pear-cvs+get-1977@lists.php.net to get a copy of this message | ||
hi,
I'm not sure to post this stuff to the right
place, but I'm a newbies with the open source
developement ...
I've made a class (code is realy hugly), but
before going on, i would like to have some
advices.
This class will (or would) permiss to build a
search engine only with a few line of code and
render the result of the SQL request in the
style of your choice xml, html ... (excuse my
english, i'm just a french man), so maybe some
people are developing the same thing at this
time ...
(the code is realy ugly, but if someone think
that it could be use, i will rewrite it)
/*
//To init this class:
$Rendersqlclass = new Render_sql
($dsn,$root,$sql,$mode,$ID,$recherche);
//To display it
$Rendersqlclass->Disp();
*/
<?php
// +---------------------------------------------
-------------------------+
// | PHP Version
4
|
// +---------------------------------------------
-------------------------+
// | Copyright (c) 1997-2002 The PHP
Group |
// +---------------------------------------------
-------------------------+
// | This source file is subject to version 2.0
of the PHP license, |
// | that is bundled with this package in the
file LICENSE, and is |
// | available at through the world-wide-web
at |
// |
http://www.php.net/license/2_02.txt.
|
// | If you did not receive a copy of the PHP
license and are unable to |
// | obtain it through the world-wide-web,
please send a note to |
// | license@php.net so we can mail you a copy
immediately. |
// +---------------------------------------------
-------------------------+
// | Authors:
alx@devel.zzn.com |
// +---------------------------------------------
-------------------------+
//
//todo: pagination
require_once("DB.php");
require_once("DB_pager/Pager.php");
require_once("XML_sql2xml/sql2xml.php");
include("Template_PHPLIB/Template_PHPLIB.php");
class Render_sql {
var $dsn;
var $root;
var $sql;
var $mode;
var $ID;
var $recherche;
function Render_sql ($dsn = Null,$root=Null,
$sql=Null, $mode=Null,$ID=0,$recherche=Null) {
if (isset($dsn)&&isset($sql)){
$this->dsn=$dsn;
$this->root=$root;
$this->sql=$sql;
$this->mode=$mode;
$this->ID=$ID;
$this-
>recherche=$recherche;
}
else{
$this->$mode="Erreur";
}
}
function Disp_xml(){
$sql2xmlclass = new xml_sql2xml
($this->dsn);
$xml= $sql2xmlclass->getxml($this-
>sql);
echo $xml;
}
function Disp_html(){
$db = DB::connect($this->dsn);
$result = $db->query($this->sql);
$DBP = new DB_Pager($result,$this-
>ID,5,10);
$Mydata=$DBP->build();
# create Template instance called $t
$t = new Template_PHPLIB($this-
>root, "keep");
# define variables named page and
box, referencing files
$t->setFile(array(
"page" => "page.ihtml",
"box" => "box.ihtml"));
# extract the block named "row"
from "box", creating a
# reference to {rows} in "box".
$t->setBlock("box", "row", "rows");
# define the variables TITLE and
PAGETITLE
$t->setVar(array("DSN" => $this-
>dsn,
"ROOT" => $this-
>root,
"SQL" => $this-
>sql,
"MODE" => $this-
>mode,
"PAGETITLE" => "hugo",
"IDN" =>$Mydata
['next'],
"IDP" =>$this->ID-5,
"Pager" =>"Pager",
"Key" =>$this-
>recherche,
"current" =>$Mydata
['current'],
"numrows" =>$Mydata
['numrows'],
"next" =>$Mydata
['next'],
"prev" =>$Mydata
['prev'],
"remain" =>$Mydata
['remain'],
"numpages" =>$Mydata
['numpages'],
"from" =>$Mydata
['from'],
"to" =>$Mydata['to'],
"limit" =>$Mydata
['limit'],
"pages" =>$Mydata
['pages'])
);
# define NUM and BIGNUM, then
append "row" to "rows"...
while ($row = $DBP->fetchRow()){
$t->setVar(array("C1" => $row
[0],"C2" => $row[1],"C3" => $row[2]));
$t->parse("rows", "row",
true);
}
# build out from box, then build
out from page...
$t->parse("OUT", array
("box", "page"));
# finish out and print it.
$t->p("OUT");
}
function Disp(){
switch($this->mode){
case "xml":
$this->Disp_xml
();
break;
case "Erreur":
echo "Informations
insuffisantes";
break;
case "html":
default :
$this->Disp_html
();
break;
}
}
}
?>
Get your Free E-mail at http://devel.zzn.com
____________________________________________________________
Get your own FREE Web and POP E-mail Service in 14 languages at http://www.zzn.com.