initial commit
This commit is contained in:
commit
e869a1cab4
107 changed files with 9029 additions and 0 deletions
144
app/controllers/CallbackController.php
Normal file
144
app/controllers/CallbackController.php
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
<?php
|
||||
|
||||
class CallbackController extends ControllerBase
|
||||
{
|
||||
/**
|
||||
* @var \Model\Data\User
|
||||
*/
|
||||
protected $_user;
|
||||
|
||||
public function initialize()
|
||||
{
|
||||
$this->_user = $this->_getAuth()->getUser();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $page
|
||||
*/
|
||||
public function listAction($page = 1)
|
||||
{
|
||||
$paginator = Model\Data\Callback::getPaginationList($this->_user->getId(), $page, 10);
|
||||
|
||||
if ($paginator->getPaginate()->current > $paginator->getPaginate()->total_pages) {
|
||||
$paginator->setCurrentPage(1);
|
||||
}
|
||||
|
||||
$this->view->page = $paginator->getPaginate();
|
||||
$this->view->pagination_url = '/callback/list/';
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new test session.
|
||||
*/
|
||||
public function newAction()
|
||||
{
|
||||
$form = new Form\CallbackCreate();
|
||||
|
||||
if ($this->request->isPost()) {
|
||||
$data = $this->request->getPost();
|
||||
|
||||
if ($form->isValid($data)) {
|
||||
$callback = new Model\Data\Callback();
|
||||
$callback->User = $this->_user;
|
||||
|
||||
$callback->setName($this->request->getPost());
|
||||
|
||||
$result = $callback->save();
|
||||
if ($result) {
|
||||
$callback->refresh();
|
||||
|
||||
return $this->response->redirect(array(
|
||||
'for' => 'cb-created',
|
||||
'id' => $callback->getPublicId()));
|
||||
} else {
|
||||
foreach($callback->getMessages() as $msg) {
|
||||
$this->flash->error($msg);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$msg = '<ul>';
|
||||
|
||||
foreach($form->getMessages() as $message) {
|
||||
$msg .= '<li><strong>' . $message->getField() . '</strong>: '. $message->getMessage() . '</li>';
|
||||
}
|
||||
|
||||
$msg .= '</ul>';
|
||||
$this->flash->message('error', $msg);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
$this->view->form = $form;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function createdAction($id)
|
||||
{
|
||||
$row = Model\Data\Callback::get($id);
|
||||
if (!$row) {
|
||||
|
||||
}
|
||||
$this->view->id = $id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Monitor a test session.
|
||||
*
|
||||
* @param $id
|
||||
* @param $page
|
||||
*/
|
||||
public function showAction($id = null, $page = 1)
|
||||
{
|
||||
$callback = Model\Data\Callback::findFirst(array(
|
||||
'conditions' => 'public_id = ?0 AND userid = ?1',
|
||||
'bind' => array($id, $this->_user->getId())
|
||||
));
|
||||
|
||||
if (!$callback) {
|
||||
$this->_forward404();
|
||||
return;
|
||||
}
|
||||
|
||||
$paginator = $callback->getRequestPaginator($page, 30);
|
||||
|
||||
$this->view->item = $callback;
|
||||
$this->view->page = $paginator->getPaginate();
|
||||
$this->view->pagination_url = '/callback/show/' . $id . '/';
|
||||
}
|
||||
|
||||
/**
|
||||
* This is the action that the API to be
|
||||
* tested should make it's callback to. So we can catch it.
|
||||
*
|
||||
* @Acl(resource="api")
|
||||
* @param int $id The test session id so
|
||||
* we know what test it belongs to.
|
||||
* @return string
|
||||
*/
|
||||
public function endpointAction($id)
|
||||
{
|
||||
$this->view->disable();
|
||||
|
||||
$callback = Model\Data\Callback::get($id);
|
||||
|
||||
$request = new Model\Data\Request();
|
||||
|
||||
$request->setHeaders($this->request->getHeaders());
|
||||
$request->setBody($this->request->getRawBody());
|
||||
|
||||
$dt = new DateTime();
|
||||
|
||||
$callback->setLastRequest($dt->format('Y-m-d H:i:s'));
|
||||
|
||||
$meta = new Model\Data\RequestMeta();
|
||||
$meta->Callback = $callback;
|
||||
$meta->RequestObject = $request;
|
||||
$result = $meta->save();
|
||||
if ($result == false) {
|
||||
var_dump($meta->getMessages());
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in a new issue