Invite::create PHP Method

create() public method

public create ( $postdata = null )
    public function create($postdata = null)
    {
        if ($this->user->isInviteBanned()) {
            throw new Exception(L::get("INVITE_BANNED"), 401);
        }
        if ($this->user->getClass() < User::CLASS_ACTOR) {
            throw new Exception(L::get("INVITE_MINIMUM_CLASS_ERROR"), 401);
        }
        if ($this->user->getInvites() == 0) {
            throw new Exception(L::get("INVITES_DEPLETED"), 400);
        }
        $this->db->query("UPDATE users SET invites = invites - 1 WHERE id = " . $this->user->getId());
        $sth = $this->db->prepare("INSERT INTO invites(userid, secret, skapad) VALUES(?, ?, NOW())");
        $sth->bindValue(1, $this->user->getId(), PDO::PARAM_INT);
        $sth->bindValue(2, md5(uniqid()), PDO::PARAM_STR);
        $sth->execute();
    }

Usage Example

Example #1
0
     $bonusShop = new BonusShop($db, $user);
     httpResponse($bonusShop->getShopItems());
     break;
 case validateRoute('POST', 'bonus-shop/\\d+'):
     $mailbox = new Mailbox($db, $user);
     $bonusShop = new BonusShop($db, $user, $mailbox);
     $bonusShop->buy((int) $params[1], $postdata);
     httpResponse();
     break;
 case validateRoute('GET', 'invites'):
     $invite = new Invite($db, $user);
     httpResponse($invite->query());
     break;
 case validateRoute('POST', 'invites'):
     $invite = new Invite($db, $user);
     httpResponse($invite->create());
     break;
 case validateRoute('DELETE', 'invites/\\d+'):
     $invite = new Invite($db, $user);
     httpResponse($invite->delete((int) $params[1]));
     break;
 case validateRoute('GET', 'friends'):
     $friends = new Friends($db, $user);
     httpResponse($friends->query());
     break;
 case validateRoute('POST', 'friends'):
     $friends = new Friends($db, $user);
     httpResponse($friends->create($postdata));
     break;
 case validateRoute('DELETE', 'friends/\\d+'):
     $friends = new Friends($db, $user);
All Usage Examples Of Invite::create