/** * Dislike an item * * @example $this->Post->dislike(1, $this->Auth->user('id)) * @param int $foreign_id ID of the item * @param int $user_id ID the user */ public function dislike(Model $Model, $foreign_id, $user_id) { if (!$Model->exists($foreign_id)) { throw new NotFoundException(); } if (!$Model->isLikedBy($foreign_id, $user_id)) { throw new NotLikedException(); } $like = $Model->Like->find('first', array('conditions' => array('Like.model' => $Model->alias, 'Like.foreign_id' => $foreign_id, 'Like.user_id' => $user_id))); $Model->Like->delete($like['Like']['id']); $Model->getEventManager()->dispatch(new CakeEvent('Plugin.Like.dislike', $like)); }