123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- <?php
- namespace Cas\Dao;
- use KIF\Dao\AbstractDao;
- use KIF\Verify;
- use KIF\Dao\SqlHelper;
- class ArticleLikeCounter extends AbstractDao {
- protected $tableName = 'article_like_counter';
-
- protected $primaryKey = 'event_id';
-
- public function getLikes($event_id) {
- if (!Verify::unsignedInt($event_id)) {
- return 0;
- }
-
- $result = $this->fetchOne(array('event_id' => $event_id), 'likes');
-
- return (int) $result['likes'];
- }
-
- public function incrLikes($event_id) {
- if (!Verify::unsignedInt($event_id)) {
- return false;
- }
-
- $tableInfo = array(
- 'event_id' => $event_id,
- 'likes' => 1,
- );
- $onDuplicate = array(
- 'likes' => SqlHelper::wrapperNoQuote('`likes`+1'),
- );
- $tmpResult = $this->insertDuplicate($tableInfo, $onDuplicate);
- if (!$tmpResult) {
- return false;
- }
-
- return true;
- }
-
- public function decrLikes($event_id) {
- if (!Verify::unsignedInt($event_id)) {
- return false;
- }
-
- $updateResult = $this->update(array(
- 'likes' => SqlHelper::wrapperNoQuote('`likes` - 1'),
- ), array(
- 'event_id' => $event_id,
- ));
- if (!$updateResult) {
- return false;
- }
-
- return true;
- }
- }
|