@@ 154-162 (lines=9) @@ | ||
151 | * @return integer number of comments |
|
152 | * |
|
153 | */ |
|
154 | public static function countComments($postId){ |
|
155 | ||
156 | $database = Database::openConnection(); |
|
157 | $database->prepare("SELECT COUNT(*) AS count FROM comments WHERE post_id = :post_id"); |
|
158 | $database->bindValue(":post_id", $postId); |
|
159 | $database->execute(); |
|
160 | ||
161 | return (int)$database->fetchAssociative()["count"]; |
|
162 | } |
|
163 | ||
164 | } |
@@ 195-204 (lines=10) @@ | ||
192 | * @param string $userIp |
|
193 | * @return bool |
|
194 | */ |
|
195 | private function isIpBlocked($userIp){ |
|
196 | ||
197 | $database = Database::openConnection(); |
|
198 | $database->prepare("SELECT ip FROM blocked_ips WHERE ip = :ip LIMIT 1"); |
|
199 | ||
200 | $database->bindValue(":ip", $userIp); |
|
201 | $database->execute(); |
|
202 | ||
203 | return $database->countRows() >= 1; |
|
204 | } |
|
205 | ||
206 | /** |
|
207 | * Adds a new record(if not exists) to ip_failed_logins table, |
|
@@ 349-359 (lines=11) @@ | ||
346 | * @return boolean |
|
347 | * |
|
348 | */ |
|
349 | private function isEmailExists($email){ |
|
350 | ||
351 | // email is already unique in the database, |
|
352 | // So, we can't have more than 2 users with the same emails |
|
353 | $database = Database::openConnection(); |
|
354 | $database->prepare("SELECT * FROM users WHERE email = :email AND is_email_activated = 1 LIMIT 1"); |
|
355 | $database->bindValue(':email', $email); |
|
356 | $database->execute(); |
|
357 | ||
358 | return $database->countRows() === 1; |
|
359 | } |
|
360 | ||
361 | /** |
|
362 | * Insert or Update(if already exists) |
@@ 344-352 (lines=9) @@ | ||
341 | * @return string |
|
342 | * |
|
343 | */ |
|
344 | private static function updateSessionId($userId, $sessionId = null){ |
|
345 | ||
346 | $database = Database::openConnection(); |
|
347 | $database->prepare("UPDATE users SET session_id = :session_id WHERE id = :id"); |
|
348 | ||
349 | $database->bindValue(":session_id", $sessionId); |
|
350 | $database->bindValue(":id", $userId); |
|
351 | $database->execute(); |
|
352 | } |
|
353 | ||
354 | /** |
|
355 | * Remove the session |