followers 1
This commit is contained in:
@@ -308,6 +308,15 @@ class Converter
|
||||
'type' => 'varchar',
|
||||
'notStorable' => true,
|
||||
);
|
||||
|
||||
$ormMeta[$entityName]['fields']['followersIds'] = array(
|
||||
'type' => 'jsonArray',
|
||||
'notStorable' => true,
|
||||
);
|
||||
$ormMeta[$entityName]['fields']['followersNames'] = array(
|
||||
'type' => 'jsonObject',
|
||||
'notStorable' => true,
|
||||
);
|
||||
}
|
||||
} //END: add a field 'isFollowed' for stream => true
|
||||
|
||||
|
||||
@@ -63,6 +63,8 @@ class Record extends \Espo\Core\Services\Base
|
||||
|
||||
protected $mergeLinkList = array();
|
||||
|
||||
const FOLLOWERS_LIMIT = 10;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
@@ -169,6 +171,17 @@ class Record extends \Espo\Core\Services\Base
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadFollowers(Entity $entity)
|
||||
{
|
||||
if ($this->getMetadata()->get("scopes.".$entity->getEntityType().".stream")) {
|
||||
$data = $this->getStreamService()->getEntityFollowers($entity, self::FOLLOWERS_LIMIT);
|
||||
if ($data) {
|
||||
$entity->set('followersIds', $data['idList']);
|
||||
$entity->set('followersNames', $data['nameMap']);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadIsEditable(Entity $entity)
|
||||
{
|
||||
$entity->set('isEditable', $this->getAcl()->check($entity, 'edit'));
|
||||
@@ -231,6 +244,7 @@ class Record extends \Espo\Core\Services\Base
|
||||
$this->loadLinkMultipleFields($entity);
|
||||
$this->loadParentNameFields($entity);
|
||||
$this->loadIsFollowed($entity);
|
||||
$this->loadFollowers($entity);
|
||||
$this->loadEmailAddressField($entity);
|
||||
$this->loadPhoneNumberField($entity);
|
||||
$this->loadNotJoinedLinkFields($entity);
|
||||
|
||||
@@ -771,5 +771,43 @@ class Stream extends \Espo\Core\Services\Base
|
||||
$this->getEntityManager()->saveEntity($note);
|
||||
}
|
||||
}
|
||||
|
||||
public function getEntityFollowers(Entity $entity, $limit = false)
|
||||
{
|
||||
$query = $this->getEntityManager()->getQuery();
|
||||
$pdo = $this->getEntityManager()->getPDO();
|
||||
|
||||
if (!$limit) {
|
||||
$limit = 500;
|
||||
}
|
||||
|
||||
$sql = $query->createSelectQuery('User', array(
|
||||
'select' => ['id', 'name'],
|
||||
'join' => "
|
||||
subscription AS `subscription` ON
|
||||
subscription.user_id = user.id AND
|
||||
subscription.entity_id = ".$query->quote($entity->id)." AND
|
||||
subscription.entity_type = ".$query->quote($entity->getEntityType())."
|
||||
",
|
||||
'offset' => 0,
|
||||
'limit' => $limit
|
||||
));
|
||||
|
||||
$sth = $pdo->prepare($sql);
|
||||
$sth->execute();
|
||||
|
||||
$data = array(
|
||||
'idList' => [],
|
||||
'nameMap' => array()
|
||||
);
|
||||
|
||||
while ($row = $sth->fetch(\PDO::FETCH_ASSOC)) {
|
||||
$data['idList'][] = $row['id'];
|
||||
$data['nameMap'][$row['id']] = $row['name'];
|
||||
}
|
||||
|
||||
return $data;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user