Ivan - Fix list-owning issues [skip ci]

This commit is contained in:
ivan 2016-07-05 20:40:30 -03:00
parent f4450e81de
commit 09e163f00a
7 changed files with 48 additions and 10 deletions

View File

@ -58,11 +58,11 @@ class CreateController extends Controller {
'file' => '',
'date' => date("F j, Y, g:i a"),
'unread' => false,
'closed' => false,
'author' => null,
'owner'=> null
'closed' => false
));
$ticket->getBeanInstance()->ownCommentList[] = RedBean::dispense('comment');
//TODO: Add logged user as author
$ticket->setAuthor(User::getUser(1));
$ticket->store();
}

View File

@ -38,6 +38,7 @@ class LoginController extends Controller {
return array(
'userId' => $userInstance->id,
'list' => count($userInstance->ownTicketList),
'userEmail' => $userInstance->email,
'token' => $this->getSession()->getToken()
);

View File

@ -1,4 +1,5 @@
<?php
use RedBeanPHP\Facade as RedBean;
class SignUpController extends Controller {
const PATH = '/signup';
@ -22,6 +23,8 @@ class SignUpController extends Controller {
'password' => Hashing::hashPassword($password)
));
//$userInstance->getBeanInstance()->sharedTicketList[] = RedBean::dispense('ticket');
return $userInstance->store();
}
}

View File

@ -4,6 +4,8 @@ use RedBeanPHP\Facade as RedBean;
class Ticket extends DataStore {
const TABLE = 'ticket';
private $author;
public static function getProps() {
return array(
'ticketNumber',
@ -26,10 +28,29 @@ class Ticket extends DataStore {
}
public function getDefaultProps() {
return array();
return array(
'owner' => null
);
}
public function setAuthor(User $user) {
$this->author = $user;
$this->author->addTicket($this);
$this->setProperties(array(
'author' => $this->author->getBeanInstance()
));
}
public function addComment(Comment $comment) {
$this->getBeanInstance()->ownCommentList[] = $comment->getBeanInstance();
}
public function store() {
parent::store();
if ($this->author instanceof User) {
$this->author->store();
}
}
}

View File

@ -15,8 +15,7 @@ class User extends DataStore {
'email',
'password',
'name',
'verificationToken',
'ownTicketList'
'verificationToken'
);
}
@ -24,8 +23,8 @@ class User extends DataStore {
return array();
}
public function addTicket($ticket) {
$this->ownTicketList[] = $ticket;
public function addTicket(Ticket $ticket) {
$this->getBeanInstance()->sharedTicketList[] = $ticket->getBeanInstance();
}
public static function getUser($value, $property = 'id') {

14
tests/ticket/comment.rb Normal file
View File

@ -0,0 +1,14 @@
describe 'ticket/comment/' do
it 'should fail if not logged' do
end
describe 'on successful request' do
it 'should add comment to current ticket' do
end
it 'should link the comment to author' do
end
end
end

View File

@ -1,4 +1,4 @@
describe '/user/login' do
describe '/ticket/create' do
it 'should fail if title is too short' do
result = request('/ticket/create',{
title: 'GG'