initial commit
This commit is contained in:
commit
e869a1cab4
107 changed files with 9029 additions and 0 deletions
7
app/models/Data/Base.php
Normal file
7
app/models/Data/Base.php
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
<?php
|
||||
|
||||
namespace Model\Data;
|
||||
|
||||
class Base
|
||||
{
|
||||
}
|
||||
275
app/models/Data/Callback.php
Normal file
275
app/models/Data/Callback.php
Normal file
|
|
@ -0,0 +1,275 @@
|
|||
<?php
|
||||
|
||||
namespace Model\Data;
|
||||
|
||||
use Mvc\Model\Behavior\RandomId as RandomIdBehavior;
|
||||
use Phalcon\Mvc\Model;
|
||||
|
||||
class Callback extends Model
|
||||
{
|
||||
|
||||
/**
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $userid;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $name;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $public_id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $color;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $created_at;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $last_request;
|
||||
|
||||
/**
|
||||
* Method to set the value of field id
|
||||
*
|
||||
* @param integer $id
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the value of field userid
|
||||
*
|
||||
* @param integer $userid
|
||||
* @return $this
|
||||
*/
|
||||
public function setUserid($userid)
|
||||
{
|
||||
$this->userid = $userid;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the value of field name
|
||||
*
|
||||
* @param string $name
|
||||
* @return $this
|
||||
*/
|
||||
public function setName($name)
|
||||
{
|
||||
$this->name = $name;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the value of field public_id
|
||||
*
|
||||
* @param string $public_id
|
||||
* @return $this
|
||||
*/
|
||||
public function setPublicId($public_id)
|
||||
{
|
||||
$this->public_id = $public_id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the value of field color
|
||||
*
|
||||
* @param string $color
|
||||
* @return $this
|
||||
*/
|
||||
public function setColor($color)
|
||||
{
|
||||
$this->color = $color;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the value of field created_at
|
||||
*
|
||||
* @param string $created_at
|
||||
* @return $this
|
||||
*/
|
||||
public function setCreatedAt($created_at)
|
||||
{
|
||||
$this->created_at = $created_at;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the value of field last_request
|
||||
*
|
||||
* @param string $last_request
|
||||
* @return $this
|
||||
*/
|
||||
public function setLastRequest($last_request)
|
||||
{
|
||||
$this->last_request = $last_request;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of field id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of field userid
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getUserid()
|
||||
{
|
||||
return $this->userid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of field name
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getName()
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of field public_id
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getPublicId()
|
||||
{
|
||||
return $this->public_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of field color
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getColor()
|
||||
{
|
||||
return $this->color;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of field created_at
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getCreatedAt()
|
||||
{
|
||||
return $this->created_at;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of field last_request
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getLastRequest()
|
||||
{
|
||||
return $this->last_request;
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize method for model.
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
$this->useDynamicUpdate(true);
|
||||
|
||||
$this->hasMany('id', 'Model\Data\RequestMeta', 'callbackid', array('foreignKey' => true, 'alias' => 'Requests'));
|
||||
$this->belongsTo('userid', 'Model\Data\User', 'id', array('foreignKey' => true, 'alias' => 'User'));
|
||||
|
||||
$this->addBehavior(new RandomIdBehavior(array(
|
||||
'field' => 'public_id',
|
||||
'length' => 8,
|
||||
)));
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns table name mapped in the model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getSource()
|
||||
{
|
||||
return 'callback';
|
||||
}
|
||||
|
||||
public function getRequestPaginator($page = 1, $limit = 30)
|
||||
{
|
||||
return RequestMeta::getPaginator($this, $page, $limit);
|
||||
}
|
||||
|
||||
public static function get($pid)
|
||||
{
|
||||
return parent::findFirst(array(
|
||||
'public_id = :pid:',
|
||||
'bind' => array('pid' => $pid),
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $userid
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return \Phalcon\Paginator\AdapterInterface
|
||||
*/
|
||||
public static function getPaginationList($userid, $page = 1, $limit = 30)
|
||||
{
|
||||
$builder = (new self())->getModelsManager()->createBuilder();
|
||||
|
||||
$builder->from('Model\Data\Callback')
|
||||
->where('userid = :uid:', array('uid' => $userid))
|
||||
->orderBy('created_at DESC');
|
||||
|
||||
$paginator = new \Phalcon\Paginator\Adapter\QueryBuilder(array(
|
||||
'builder' => $builder,
|
||||
'page' => $page,
|
||||
'limit' => $limit
|
||||
));
|
||||
|
||||
return $paginator;
|
||||
}
|
||||
}
|
||||
93
app/models/Data/Request.php
Normal file
93
app/models/Data/Request.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?php
|
||||
|
||||
namespace Model\Data;
|
||||
|
||||
use Phalcon\Mvc\Model;
|
||||
|
||||
class Request extends Model
|
||||
{
|
||||
protected $id;
|
||||
|
||||
protected $headers = array();
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
protected $body;
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
$this->useDynamicUpdate(true);
|
||||
$this->setSource('request_object');
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $id
|
||||
* @return Request
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array
|
||||
*/
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $headers
|
||||
* @return Request
|
||||
*/
|
||||
public function setHeaders($headers)
|
||||
{
|
||||
foreach($headers as $k => $v) {
|
||||
|
||||
if (strlen($v) < 1) {
|
||||
unset($headers[$k]);
|
||||
}
|
||||
}
|
||||
$this->headers = $headers;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getBody()
|
||||
{
|
||||
return $this->body;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $body
|
||||
* @return Request
|
||||
*/
|
||||
public function setBody($body)
|
||||
{
|
||||
$this->body = $body;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function afterFetch()
|
||||
{
|
||||
$this->headers = json_decode($this->headers, true);
|
||||
}
|
||||
|
||||
public function beforeSave()
|
||||
{
|
||||
$this->headers = json_encode($this->headers);
|
||||
}
|
||||
}
|
||||
169
app/models/Data/RequestMeta.php
Normal file
169
app/models/Data/RequestMeta.php
Normal file
|
|
@ -0,0 +1,169 @@
|
|||
<?php
|
||||
|
||||
namespace Model\Data;
|
||||
|
||||
use Phalcon\Mvc\Model;
|
||||
|
||||
class RequestMeta extends Model
|
||||
{
|
||||
/**
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $id;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var integer
|
||||
*/
|
||||
protected $callbackid;
|
||||
|
||||
/**
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $timestamp;
|
||||
|
||||
/**
|
||||
* Initialize method for model.
|
||||
*/
|
||||
public function initialize()
|
||||
{
|
||||
$this->skipAttributes(array('request_object_id'));
|
||||
$this->setSource('request_meta');
|
||||
$this->useDynamicUpdate(true);
|
||||
|
||||
// Relationships
|
||||
|
||||
$this->belongsTo('callbackid', 'Model\Data\Callback', 'id', array('alias' => 'Callback'));
|
||||
$this->hasOne('id', 'Model\Data\Request', 'id', array('alias' => 'RequestObject'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the value of field id
|
||||
*
|
||||
* @param integer $id
|
||||
* @return $this
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the value of field callbackid
|
||||
*
|
||||
* @param integer $callbackid
|
||||
* @return $this
|
||||
*/
|
||||
public function setCallbackid($callbackid)
|
||||
{
|
||||
$this->callbackid = $callbackid;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Method to set the value of field Timestamp
|
||||
*
|
||||
* @param string $Timestamp
|
||||
* @return $this
|
||||
*/
|
||||
public function setTimestamp($timestamp)
|
||||
{
|
||||
$this->timestamp = $timestamp;
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of field id
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of field callbackid
|
||||
*
|
||||
* @return integer
|
||||
*/
|
||||
public function getCallbackid()
|
||||
{
|
||||
return $this->callbackid;
|
||||
}
|
||||
|
||||
public function getSize()
|
||||
{
|
||||
$headers = $this->getHeaders();
|
||||
|
||||
foreach($headers as $k => $v) {
|
||||
|
||||
if ($k == 'Content-Length') {
|
||||
return $v;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public function getType()
|
||||
{
|
||||
$headers = $this->getHeaders();
|
||||
|
||||
foreach($headers as $k => $v) {
|
||||
|
||||
if ($k == 'Content-Type') {
|
||||
return substr($v, strrpos($v, '/') + 1);
|
||||
}
|
||||
}
|
||||
return 'Unknown';
|
||||
}
|
||||
|
||||
public function getHeaders()
|
||||
{
|
||||
return $this->getRequestObject()->getHeaders();
|
||||
}
|
||||
|
||||
public function getBody()
|
||||
{
|
||||
return $this->getRequestObject()->getBody();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of field Timestamp
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getTimestamp()
|
||||
{
|
||||
return $this->timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Callback $callback
|
||||
* @param int $page
|
||||
* @param int $limit
|
||||
* @return \Phalcon\Paginator\AdapterInterface
|
||||
*/
|
||||
static public function getPaginator(Callback $callback, $page = 1, $limit = 30)
|
||||
{
|
||||
$builder = (new self())->getModelsManager()->createBuilder();
|
||||
|
||||
$builder->from('Model\Data\RequestMeta')
|
||||
->where('callbackid = :cid:', array('cid' => $callback->getId()))
|
||||
->orderBy('timestamp desc');
|
||||
|
||||
$paginator = new \Phalcon\Paginator\Adapter\QueryBuilder(array(
|
||||
'builder' => $builder,
|
||||
'page' => $page,
|
||||
'limit' => $limit
|
||||
));
|
||||
|
||||
return $paginator;
|
||||
}
|
||||
}
|
||||
113
app/models/Data/User.php
Normal file
113
app/models/Data/User.php
Normal file
|
|
@ -0,0 +1,113 @@
|
|||
<?php
|
||||
|
||||
namespace Model\Data;
|
||||
|
||||
use Phalcon\Mvc\Model;
|
||||
|
||||
class User extends Model
|
||||
{
|
||||
protected $id;
|
||||
|
||||
protected $username;
|
||||
|
||||
protected $email;
|
||||
|
||||
protected $deleted;
|
||||
|
||||
protected $password;
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
$this->useDynamicUpdate(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getId()
|
||||
{
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $id
|
||||
* @return User
|
||||
*/
|
||||
public function setId($id)
|
||||
{
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getUsername()
|
||||
{
|
||||
return $this->username;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $username
|
||||
* @return User
|
||||
*/
|
||||
public function setUsername($username)
|
||||
{
|
||||
$this->username = $username;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getEmail()
|
||||
{
|
||||
return $this->email;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $email
|
||||
* @return User
|
||||
*/
|
||||
public function setEmail($email)
|
||||
{
|
||||
$this->email = $email;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getDeleted()
|
||||
{
|
||||
return $this->deleted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $deleted
|
||||
* @return User
|
||||
*/
|
||||
public function setDeleted($deleted)
|
||||
{
|
||||
$this->deleted = $deleted;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getPassword()
|
||||
{
|
||||
return $this->password;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $password
|
||||
* @return User
|
||||
*/
|
||||
public function setPassword($password)
|
||||
{
|
||||
$this->password = $password;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
Reference in a new issue