mirror of
https://github.com/Chouchen/shorturl.git
synced 2018-06-07 06:34:38 +02:00
Add Statistics
This commit is contained in:
parent
9ef54c068f
commit
d7c28b72ed
@ -16,12 +16,13 @@ class ShortURL extends XMLSQL{
|
|||||||
if($this->pkAlreadyExists($shortName, 'url')){
|
if($this->pkAlreadyExists($shortName, 'url')){
|
||||||
return self::STATE_ALREADY_EXIST;
|
return self::STATE_ALREADY_EXIST;
|
||||||
}else{
|
}else{
|
||||||
return $this->insert(array('url'=>$longUrl), rawurlencode($shortName))->into('url')->query();
|
return $this->insert(array('url'=>$longUrl,'hit'=>'0'), rawurlencode($shortName))->into('url')->query();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findThisUrl($shortName){
|
public function findThisUrl($shortName){
|
||||||
if($this->pkAlreadyExists(rawurlencode($shortName), 'url')){
|
if($this->pkAlreadyExists(rawurlencode($shortName), 'url')){
|
||||||
|
$this->_incrementStatFor($shortName);
|
||||||
return $this->select(array('url'))->from('url')->where(rawurlencode($shortName))->query();
|
return $this->select(array('url'))->from('url')->where(rawurlencode($shortName))->query();
|
||||||
}else{
|
}else{
|
||||||
return;
|
return;
|
||||||
@ -32,4 +33,14 @@ class ShortURL extends XMLSQL{
|
|||||||
return $this->select()->from('url')->query();
|
return $this->select()->from('url')->query();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Considering the table with $shortname already exist
|
||||||
|
*/
|
||||||
|
private function _incrementStatFor($shortName){
|
||||||
|
$currentHit = $this->select(array('hit'))->from('url')->where(rawurlencode($shortName))->query();
|
||||||
|
$currentHit = $currentHit[0];
|
||||||
|
return $this->update('url')->set(array('hit'=>$currentHit+1))->where(rawurlencode($shortName))->query();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user