Allows to user add likes or dislikes to posts in social wall. Requires DB changes: ```sql CREATE TABLE message_likes (id BIGINT AUTO_INCREMENT NOT NULL, message_id BIGINT NOT NULL, user_id INT NOT NULL, liked TINYINT(1) DEFAULT '0' NOT NULL, disliked TINYINT(1) DEFAULT '0' NOT NULL, updated_at DATETIME NOT NULL, INDEX IDX_B66CB196537A1329 (message_id), INDEX IDX_B66CB196A76ED395 (user_id), INDEX idx_message_likes_uid_mid (message_id, user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB; ALTER TABLE message_likes ADD CONSTRAINT FK_B66CB196537A1329 FOREIGN KEY (message_id) REFERENCES message (id) ON DELETE CASCADE; ALTER TABLE message_likes ADD CONSTRAINT FK_B66CB196A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE; ``` - edit src/Chamilo/CoreBundle/Entity/MessageLikes.php and follow the instructions about the @ORM\Entity() line - edit src/Chamilo/CoreBundle/Entity/Message.php and fllow the instruccions about the @ORM\OneToMany line for the $likes property - launch composer install to rebuild the autoload.phppull/2858/head
parent
2e92ad6327
commit
9af667f5af
@ -0,0 +1,186 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace Chamilo\CoreBundle\Entity; |
||||
|
||||
use Chamilo\UserBundle\Entity\User; |
||||
use Doctrine\ORM\Mapping as ORM; |
||||
use Doctrine\ORM\Mapping\Index; |
||||
|
||||
/** |
||||
* Class MessageLikes. |
||||
* |
||||
* @package Chamilo\CoreBundle\Entity |
||||
* |
||||
* @ORM\Table( |
||||
* name="message_likes", |
||||
* indexes={ |
||||
* @Index(name="idx_message_likes_uid_mid", columns={"message_id", "user_id"}) |
||||
* } |
||||
* ) |
||||
* Add @ to the next line if api_get_configuration_value('social_enable_likes_messages') is true |
||||
* ORM\Entity() |
||||
*/ |
||||
class MessageLikes |
||||
{ |
||||
/** |
||||
* @var int |
||||
* |
||||
* @ORM\Column(name="id", type="bigint") |
||||
* @ORM\Id() |
||||
* @ORM\GeneratedValue() |
||||
*/ |
||||
private $id; |
||||
/** |
||||
* @var Message |
||||
* |
||||
* @ORM\ManyToOne(targetEntity="Chamilo\CoreBundle\Entity\Message", inversedBy="likes") |
||||
* @ORM\JoinColumn(name="message_id", referencedColumnName="id", nullable=false, onDelete="CASCADE") |
||||
*/ |
||||
private $message; |
||||
/** |
||||
* @var User |
||||
* |
||||
* @ORM\ManyToOne(targetEntity="Chamilo\UserBundle\Entity\User") |
||||
* @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false, onDelete="CASCADE") |
||||
*/ |
||||
private $user; |
||||
/** |
||||
* @var bool |
||||
* |
||||
* @ORM\Column(name="liked", type="boolean", options={"default": false}) |
||||
*/ |
||||
private $liked; |
||||
/** |
||||
* @var bool |
||||
* |
||||
* @ORM\Column(name="disliked", type="boolean", options={"default": false}) |
||||
*/ |
||||
private $disliked; |
||||
/** |
||||
* @var \DateTime |
||||
* |
||||
* @ORM\Column(name="updated_at", type="datetime", nullable=false) |
||||
*/ |
||||
private $updatedAt; |
||||
|
||||
/** |
||||
* @return int |
||||
*/ |
||||
public function getId() |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
/** |
||||
* @param int $id |
||||
* |
||||
* @return MessageLikes |
||||
*/ |
||||
public function setId($id) |
||||
{ |
||||
$this->id = $id; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return Message |
||||
*/ |
||||
public function getMessage() |
||||
{ |
||||
return $this->message; |
||||
} |
||||
|
||||
/** |
||||
* @param Message $message |
||||
* |
||||
* @return MessageLikes |
||||
*/ |
||||
public function setMessage(Message $message) |
||||
{ |
||||
$this->message = $message; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return User |
||||
*/ |
||||
public function getUser() |
||||
{ |
||||
return $this->user; |
||||
} |
||||
|
||||
/** |
||||
* @param User $user |
||||
* |
||||
* @return MessageLikes |
||||
*/ |
||||
public function setUser(User $user) |
||||
{ |
||||
$this->user = $user; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return bool |
||||
*/ |
||||
public function isLiked() |
||||
{ |
||||
return $this->liked; |
||||
} |
||||
|
||||
/** |
||||
* @param bool $liked |
||||
* |
||||
* @return MessageLikes |
||||
*/ |
||||
public function setLiked($liked) |
||||
{ |
||||
$this->liked = $liked; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return bool |
||||
*/ |
||||
public function isDisliked() |
||||
{ |
||||
return $this->disliked; |
||||
} |
||||
|
||||
/** |
||||
* @param bool $disliked |
||||
* |
||||
* @return MessageLikes |
||||
*/ |
||||
public function setDisliked($disliked) |
||||
{ |
||||
$this->disliked = $disliked; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @return \DateTime |
||||
*/ |
||||
public function getUpdatedAt() |
||||
{ |
||||
return $this->updatedAt; |
||||
} |
||||
|
||||
/** |
||||
* @param \DateTime $updatedAt |
||||
* |
||||
* @return MessageLikes |
||||
*/ |
||||
public function setUpdatedAt(\DateTime $updatedAt) |
||||
{ |
||||
$this->updatedAt = $updatedAt; |
||||
|
||||
return $this; |
||||
} |
||||
} |
Loading…
Reference in new issue