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' => '', 'file' => '',
'date' => date("F j, Y, g:i a"), 'date' => date("F j, Y, g:i a"),
'unread' => false, 'unread' => false,
'closed' => false, 'closed' => false
'author' => null,
'owner'=> null
)); ));
$ticket->getBeanInstance()->ownCommentList[] = RedBean::dispense('comment');
//TODO: Add logged user as author
$ticket->setAuthor(User::getUser(1));
$ticket->store(); $ticket->store();
} }

View File

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

View File

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

View File

@ -4,6 +4,8 @@ use RedBeanPHP\Facade as RedBean;
class Ticket extends DataStore { class Ticket extends DataStore {
const TABLE = 'ticket'; const TABLE = 'ticket';
private $author;
public static function getProps() { public static function getProps() {
return array( return array(
'ticketNumber', 'ticketNumber',
@ -26,10 +28,29 @@ class Ticket extends DataStore {
} }
public function getDefaultProps() { 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) { public function addComment(Comment $comment) {
$this->getBeanInstance()->ownCommentList[] = $comment->getBeanInstance(); $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', 'email',
'password', 'password',
'name', 'name',
'verificationToken', 'verificationToken'
'ownTicketList'
); );
} }
@ -24,8 +23,8 @@ class User extends DataStore {
return array(); return array();
} }
public function addTicket($ticket) { public function addTicket(Ticket $ticket) {
$this->ownTicketList[] = $ticket; $this->getBeanInstance()->sharedTicketList[] = $ticket->getBeanInstance();
} }
public static function getUser($value, $property = 'id') { 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 it 'should fail if title is too short' do
result = request('/ticket/create',{ result = request('/ticket/create',{
title: 'GG' title: 'GG'