Пример #1
0
 public function setUserAttitude(\User $user, $att)
 {
     self::checkIfCanVote($user);
     $dbw = wfGetDB(DB_MASTER);
     // Get current attitude
     $oldatt = $this->getUserAttitude($user);
     // Short path, return if they match
     if ($oldatt === $att) {
         return;
     }
     // Delete entry if the attitude is neutral
     if ($att === static::ATTITUDE_NORMAL) {
         $dbw->delete('FlowThreadAttitude', array('flowthread_att_id' => $this->id->getBin(), 'flowthread_att_userid' => $user->getId()));
     } else {
         if ($oldatt !== static::ATTITUDE_NORMAL) {
             $dbw->update('FlowThreadAttitude', array('flowthread_att_type' => $att), array('flowthread_att_id' => $this->id->getBin(), 'flowthread_att_userid' => $user->getId()));
         } else {
             $dbw->insert('FlowThreadAttitude', array('flowthread_att_id' => $this->id->getBin(), 'flowthread_att_type' => $att, 'flowthread_att_userid' => $user->getId()));
         }
     }
     // Update number in the main table
     if ($oldatt === static::ATTITUDE_LIKE) {
         $this->favorCount--;
     } else {
         if ($oldatt === static::ATTITUDE_REPORT) {
             $this->reportCount--;
         }
     }
     if ($att === static::ATTITUDE_LIKE) {
         $this->favorCount++;
     } else {
         if ($att === static::ATTITUDE_REPORT) {
             $this->reportCount++;
         }
     }
     $this->updateFavorReportCount();
 }