_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 = '
';
foreach($form->getMessages() as $message) {
$msg .= '- ' . $message->getField() . ': '. $message->getMessage() . '
';
}
$msg .= '
';
$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());
}
}
}