1
0
mirror of https://github.com/Chouchen/shorturl.git synced 2018-06-07 06:34:38 +02:00
shorturl/trunk/class/ShortURL.php
2010-12-23 11:26:25 +00:00

35 lines
1011 B
PHP

<?
include 'XMLSQL.php';
class ShortURL extends XMLSQL{
const DATABASE = "db/database.xml";
const STATE_ALREADY_EXIST = "Ce nom de raccourci existe déjà";
const STATE_FIELD_MISSING = "Merci de remplir les 2 champs. ";
const STATE_ERROR = "Erreur. ";
public $_debug = false;
public function __construct($path = ''){
parent::__construct($path.self::DATABASE);
}
public function shortThisUrl($longUrl, $shortName){
if($this->pkAlreadyExists($shortName, 'url')){
return self::STATE_ALREADY_EXIST;
}else{
return $this->insert(array('url'=>$longUrl), rawurlencode($shortName))->into('url')->query();
}
}
public function findThisUrl($shortName){
if($this->pkAlreadyExists(rawurlencode($shortName), 'url')){
return $this->select(array('url'))->from('url')->where(rawurlencode($shortName))->query();
}else{
return;
}
}
public function extractEverything(){
return $this->select()->from('url')->query();
}
}