Suggestions::create PHP 메소드

create() 공개 메소드

public create ( $postData )
    public function create($postData)
    {
        if (strlen($postData["body"]) < 10) {
            throw new Exception(L::get("SUGGESTION_DESCRIPTION_TOO_SHORT"));
        }
        if (strlen($postData["subject"]) < 5) {
            throw new Exception(L::get("SUGGESTION_TITLE_TOO_SHORT"), 412);
        }
        $sth = $this->db->prepare("INSERT INTO suggestions(title, body, userid, added) VALUES(?, ?, ?, NOW())");
        $sth->bindParam(1, $postData["subject"], PDO::PARAM_INT);
        $sth->bindParam(2, $postData["body"], PDO::PARAM_INT);
        $sth->bindValue(3, $this->user->getId(), PDO::PARAM_INT);
        $sth->execute();
        $suggestId = $this->db->lastInsertId();
        $topic = $this->forum->addTopic(Config::SUGGESTION_FORUM_ID, $postData["subject"], $postData["body"], $postData["body"], true);
        $this->db->query('UPDATE suggestions SET topicid = ' . $topic["id"] . ' WHERE id = ' . $suggestId);
        $this->vote($suggestId, "up");
        return $topic;
    }

Usage Example

예제 #1
0
     httpResponse($news->delete($params[1]));
     break;
 case validateRoute('GET', 'suggestions'):
     $suggestions = new Suggestions($db, $user);
     $arr = $suggestions->get($_GET["view"] ?: 'top', (int) $_GET["limit"] ?: 10);
     httpResponse($arr);
     break;
 case validateRoute('POST', 'suggestions/\\d+/votes'):
     $suggestions = new Suggestions($db, $user);
     $arr = $suggestions->vote($params[1], $postdata["direction"]);
     httpResponse($arr);
     break;
 case validateRoute('POST', 'suggestions'):
     $forum = new Forum($db, $user);
     $suggestions = new Suggestions($db, $user, $forum);
     httpResponse($suggestions->create($postdata));
     break;
 case validateRoute('PATCH', 'suggestions/\\d+'):
     $suggestions = new Suggestions($db, $user);
     httpResponse($suggestions->update($params[1], $postdata));
     break;
 case validateRoute('GET', 'sweTvGuide'):
     $week = (int) $_GET["week"];
     $cacheId = 'swetvguide-' . $week;
     if ($memcache && ($cached = $memcache->get($cacheId))) {
         if ($week == 0) {
             $user->updateLastTorrentViewAccess('last_tvbrowse');
         }
         httpResponse($cached);
     } else {
         $torrent = new Torrent($db, $user);