예제 #1
0
 // validate
 if ($title == '') {
     $json = array('error' => 'You must provide a title.');
     exit(json_encode($json));
 } elseif ($message == '') {
     $json = array('error' => 'You must provide some text for the message.');
     exit(json_encode($json));
 }
 if ($cat == '') {
     $cat = null;
 }
 // create discussion
 $discussion = new Discussion(array('creator_id' => Session::getUserID(), 'project_id' => $project->getID(), 'title' => $title, 'message' => $message, 'category' => $cat));
 $discussion->save();
 // assign parent_id to self
 $discussion->setParentID($discussion->getID());
 $discussion->save();
 // attach any uploads
 // Upload::attachToItem(
 // $token,
 // Upload::TYPE_DISCUSSION,
 // $discussion->getID(),
 // $project->getID()
 // );
 // log it
 $logEvent = new Event(array('event_type_id' => 'create_discussion', 'project_id' => $project->getID(), 'user_1_id' => Session::getUserID(), 'item_1_id' => $discussion->getID(), 'data_1' => $title, 'data_2' => $message));
 $logEvent->save();
 // we're done here
 Session::setMessage('You created a new discussion.');
 // if category is set, redirect back to other section
 switch ($cat) {