Heartbeat.php 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708
  1. <?php
  2. namespace Drupal\heartbeat\Entity;
  3. use Drupal\Core\Entity\EntityStorageInterface;
  4. use Drupal\Core\Field\BaseFieldDefinition;
  5. use Drupal\Core\Entity\RevisionableContentEntityBase;
  6. use Drupal\Core\Entity\EntityChangedTrait;
  7. use Drupal\Core\Entity\EntityTypeInterface;
  8. use Drupal\Core\Utility\Token;
  9. use Drupal\Core\Url;
  10. use Drupal\Core\Link;
  11. use Drupal\Core\Database\Database;
  12. use Drupal\user\UserInterface;
  13. /**
  14. * Defines the Heartbeat entity.
  15. *
  16. * @ingroup heartbeat
  17. *
  18. * @ContentEntityType(
  19. * id = "heartbeat",
  20. * label = @Translation("Heartbeat"),
  21. * bundle_label = @Translation("Heartbeat type"),
  22. * handlers = {
  23. * "storage" = "Drupal\heartbeat\HeartbeatStorage",
  24. * "view_builder" = "Drupal\Core\Entity\EntityViewBuilder",
  25. * "list_builder" = "Drupal\heartbeat\HeartbeatListBuilder",
  26. * "views_data" = "Drupal\heartbeat\Entity\HeartbeatViewsData",
  27. * "translation" = "Drupal\heartbeat\HeartbeatTranslationHandler",
  28. *
  29. * "form" = {
  30. * "default" = "Drupal\heartbeat\Form\HeartbeatForm",
  31. * "add" = "Drupal\heartbeat\Form\HeartbeatForm",
  32. * "edit" = "Drupal\heartbeat\Form\HeartbeatForm",
  33. * "delete" = "Drupal\heartbeat\Form\HeartbeatDeleteForm",
  34. * },
  35. * "access" = "Drupal\heartbeat\HeartbeatAccessControlHandler",
  36. * "route_provider" = {
  37. * "html" = "Drupal\heartbeat\HeartbeatHtmlRouteProvider",
  38. * },
  39. * },
  40. * base_table = "heartbeat",
  41. * data_table = "heartbeat_field_data",
  42. * revision_table = "heartbeat_revision",
  43. * revision_data_table = "heartbeat_field_revision",
  44. * translatable = TRUE,
  45. * admin_permission = "administer heartbeat entities",
  46. * entity_keys = {
  47. * "id" = "id",
  48. * "revision" = "vid",
  49. * "bundle" = "type",
  50. * "label" = "name",
  51. * "uuid" = "uuid",
  52. * "uid" = "uid",
  53. * "nid" = "nid",
  54. * "langcode" = "langcode",
  55. * "status" = "status",
  56. * },
  57. * links = {
  58. * "canonical" = "/admin/structure/heartbeat/{heartbeat}",
  59. * "add-page" = "/admin/structure/heartbeat/add",
  60. * "add-form" = "/admin/structure/heartbeat/add/{heartbeat_type}",
  61. * "edit-form" = "/admin/structure/heartbeat/{heartbeat}/edit",
  62. * "delete-form" = "/admin/structure/heartbeat/{heartbeat}/delete",
  63. * "version-history" = "/admin/structure/heartbeat/{heartbeat}/revisions",
  64. * "revision" = "/admin/structure/heartbeat/{heartbeat}/revisions/{heartbeat_revision}/view",
  65. * "revision_revert" = "/admin/structure/heartbeat/{heartbeat}/revisions/{heartbeat_revision}/revert",
  66. * "translation_revert" = "/admin/structure/heartbeat/{heartbeat}/revisions/{heartbeat_revision}/revert/{langcode}",
  67. * "revision_delete" = "/admin/structure/heartbeat/{heartbeat}/revisions/{heartbeat_revision}/delete",
  68. * "collection" = "/admin/structure/heartbeat",
  69. * },
  70. * bundle_entity_type = "heartbeat_type",
  71. * field_ui_base_route = "entity.heartbeat_type.edit_form"
  72. * )
  73. */
  74. // Always block from display
  75. const HEARTBEAT_NONE = -1;
  76. // Display only activity messages that are mine or addressed to me
  77. const HEARTBEAT_PRIVATE = 0;
  78. // Only the person that is chosen by the actor, can see the message
  79. const HEARTBEAT_PUBLIC_TO_ADDRESSEE = 1;
  80. // Display activity message of all my user relations, described in contributed modules
  81. const HEARTBEAT_PUBLIC_TO_CONNECTED = 2;
  82. // Everyone can see this activity message, unless this type of message is set to private
  83. const HEARTBEAT_PUBLIC_TO_ALL = 4;
  84. //Group Types
  85. const HEARTBEAT_GROUP_NONE = 11;
  86. const HEARTBEAT_GROUP_SINGLE = 12;
  87. const HEARTBEAT_GROUP_SUMMARY = 13;
  88. const FILE_FIELD = 'Drupal\file\Plugin\Field\FieldType\FileFieldItemList';
  89. class Heartbeat extends RevisionableContentEntityBase implements HeartbeatInterface {
  90. use EntityChangedTrait;
  91. /**
  92. * {@inheritdoc}
  93. */
  94. public static function preCreate(EntityStorageInterface $storage_controller, array &$values) {
  95. parent::preCreate($storage_controller, $values);
  96. }
  97. /**
  98. * {@inheritdoc}
  99. */
  100. public function preSave(EntityStorageInterface $storage) {
  101. parent::preSave($storage);
  102. foreach (array_keys($this->getTranslationLanguages()) as $langcode) {
  103. $translation = $this->getTranslation($langcode);
  104. // If no owner has been set explicitly, make the anonymous user the owner.
  105. if (!$translation->getOwner()) {
  106. $translation->setOwnerId(0);
  107. }
  108. }
  109. // If no revision author has been set explicitly, make the heartbeat owner the
  110. // revision author.
  111. if (!$this->getRevisionUser()) {
  112. $this->setRevisionUserId($this->getOwnerId());
  113. }
  114. }
  115. /**
  116. * {@inheritdoc}
  117. */
  118. public function getType() {
  119. return $this->bundle();
  120. }
  121. /**
  122. * {@inheritdoc}
  123. */
  124. public function getName() {
  125. return $this->get('name')->value;
  126. }
  127. /**
  128. * {@inheritdoc}
  129. */
  130. public function setName($name) {
  131. $this->set('name', $name);
  132. return $this;
  133. }
  134. /**
  135. * Gets the Heartbeat message.
  136. *
  137. * @return string
  138. * Message of the Heartbeat.
  139. */
  140. public function getMessage() {
  141. return $this->get('message');
  142. }
  143. /**
  144. * Sets the Heartbeat Message.
  145. *
  146. * @param $name
  147. * @return
  148. * @internal param string $message The Heartbeat Message
  149. */
  150. public function setMessage($message) {
  151. $this->set('message', $message);
  152. }
  153. /**
  154. * {@inheritdoc}
  155. */
  156. public function getCreatedTime() {
  157. return $this->get('created')->value;
  158. }
  159. /**
  160. * {@inheritdoc}
  161. */
  162. public function setCreatedTime($timestamp) {
  163. $this->set('created', $timestamp);
  164. return $this;
  165. }
  166. /**
  167. * {@inheritdoc}
  168. */
  169. public function getOwner() {
  170. return $this->get('uid')->entity;
  171. }
  172. /**
  173. * {@inheritdoc}
  174. */
  175. public function getOwnerId() {
  176. return $this->get('uid')->target_id;
  177. }
  178. /**
  179. * {@inheritdoc}
  180. */
  181. public function setOwnerId($uid) {
  182. $this->set('uid', $uid);
  183. return $this;
  184. }
  185. /**
  186. * {@inheritdoc}
  187. */
  188. public function setOwner(UserInterface $account) {
  189. $this->set('uid', $account->id());
  190. return $this;
  191. }
  192. /**
  193. * {@inheritdoc}
  194. */
  195. public function isPublished() {
  196. return (bool) $this->getEntityKey('status');
  197. }
  198. /**
  199. * {@inheritdoc}
  200. */
  201. public function setPublished($published) {
  202. $this->set('status', $published ? TRUE : FALSE);
  203. return $this;
  204. }
  205. /**
  206. * {@inheritdoc}
  207. */
  208. public function getRevisionCreationTime() {
  209. return $this->get('revision_timestamp')->value;
  210. }
  211. /**
  212. * {@inheritdoc}
  213. */
  214. public function setRevisionCreationTime($timestamp) {
  215. $this->set('revision_timestamp', $timestamp);
  216. return $this;
  217. }
  218. /**
  219. * {@inheritdoc}
  220. */
  221. public function getRevisionUser() {
  222. return $this->get('revision_uid')->entity;
  223. }
  224. /**
  225. * {@inheritdoc}
  226. */
  227. public function setRevisionUserId($uid) {
  228. $this->set('revision_uid', $uid);
  229. return $this;
  230. }
  231. /**
  232. * {@inheritdoc}
  233. */
  234. public static function baseFieldDefinitions(EntityTypeInterface $entity_type) {
  235. $fields = parent::baseFieldDefinitions($entity_type);
  236. $fields['uid'] = BaseFieldDefinition::create('entity_reference')
  237. ->setLabel(t('Authored by'))
  238. ->setDescription(t('The user ID of author of the Heartbeat entity.'))
  239. ->setRevisionable(TRUE)
  240. ->setSetting('target_type', 'user')
  241. ->setSetting('handler', 'default')
  242. ->setTranslatable(TRUE)
  243. ->setDisplayOptions('view', array(
  244. 'label' => 'hidden',
  245. 'type' => 'author',
  246. 'weight' => 0,
  247. ))
  248. ->setDisplayOptions('form', array(
  249. 'type' => 'entity_reference_autocomplete',
  250. 'weight' => 5,
  251. 'settings' => array(
  252. 'match_operator' => 'CONTAINS',
  253. 'size' => '60',
  254. 'autocomplete_type' => 'tags',
  255. 'placeholder' => '',
  256. ),
  257. ))
  258. ->setDisplayConfigurable('form', TRUE)
  259. ->setDisplayConfigurable('view', TRUE);
  260. $fields['nid'] = BaseFieldDefinition::create('entity_reference')
  261. ->setLabel(t('Node'))
  262. ->setDescription(t('The content associated with this Heartbeat'))
  263. ->setSetting('target_type', 'node')
  264. ->setSetting('handler', 'default')
  265. ->setRevisionable(TRUE);
  266. $fields['name'] = BaseFieldDefinition::create('string')
  267. ->setLabel(t('Name'))
  268. ->setDescription(t('The name of the Heartbeat entity.'))
  269. ->setRevisionable(TRUE)
  270. ->setSettings(array(
  271. 'max_length' => 50,
  272. 'text_processing' => 0,
  273. ))
  274. ->setDefaultValue('')
  275. ->setDisplayOptions('view', array(
  276. 'label' => 'above',
  277. 'type' => 'string',
  278. 'weight' => -4,
  279. ))
  280. ->setDisplayOptions('form', array(
  281. 'type' => 'string_textfield',
  282. 'weight' => -4,
  283. ))
  284. ->setDisplayConfigurable('form', TRUE)
  285. ->setDisplayConfigurable('view', TRUE);
  286. $fields['message'] = BaseFieldDefinition::create('string_long')
  287. ->setLabel(t('Message'))
  288. ->setDescription(t('The message of the Heartbeat entity.'))
  289. ->setRevisionable(TRUE);
  290. $fields['status'] = BaseFieldDefinition::create('boolean')
  291. ->setLabel(t('Publishing status'))
  292. ->setDescription(t('A boolean indicating whether the Heartbeat is published.'))
  293. ->setRevisionable(TRUE)
  294. ->setDefaultValue(TRUE);
  295. $fields['created'] = BaseFieldDefinition::create('created')
  296. ->setLabel(t('Created'))
  297. ->setDescription(t('The time that the entity was created.'));
  298. $fields['changed'] = BaseFieldDefinition::create('changed')
  299. ->setLabel(t('Changed'))
  300. ->setDescription(t('The time that the entity was last edited.'));
  301. $fields['revision_timestamp'] = BaseFieldDefinition::create('created')
  302. ->setLabel(t('Revision timestamp'))
  303. ->setDescription(t('The time that the current revision was created.'))
  304. ->setQueryable(FALSE)
  305. ->setRevisionable(TRUE);
  306. $fields['revision_uid'] = BaseFieldDefinition::create('entity_reference')
  307. ->setLabel(t('Revision user ID'))
  308. ->setDescription(t('The user ID of the author of the current revision.'))
  309. ->setSetting('target_type', 'user')
  310. ->setQueryable(FALSE)
  311. ->setRevisionable(TRUE);
  312. $fields['revision_translation_affected'] = BaseFieldDefinition::create('boolean')
  313. ->setLabel(t('Revision translation affected'))
  314. ->setDescription(t('Indicates if the last edit of a translation belongs to current revision.'))
  315. ->setReadOnly(TRUE)
  316. ->setRevisionable(TRUE)
  317. ->setTranslatable(TRUE);
  318. return $fields;
  319. }
  320. /**
  321. * Returns the node type label for the passed node.
  322. *
  323. * @param \Drupal\heartbeat\Entity\HeartbeatInterface $heartbeat
  324. * A heartbeat entity to return the heartbeat type's label for.
  325. *
  326. * @return string|false
  327. * The heartbeat type label or FALSE if the heartbeat type is not found.
  328. *
  329. * @todo Add this as generic helper method for config entities representing
  330. * entity bundles.
  331. */
  332. public function heartbeat_get_type(HeartbeatInterface $heartbeat) {
  333. $type = HeartbeatType::load($heartbeat->bundle());
  334. return $type ? $type->label() : FALSE;
  335. }
  336. /**
  337. * Updates all heartbeat activities of one type to be of another type.
  338. *
  339. * @param string $old_id
  340. * The current heartbeat type of the activities.
  341. * @param string $new_id
  342. * The new heartbeat type of the activities.
  343. *
  344. * @return
  345. * The number of activities whose heartbeat type field was modified.
  346. */
  347. public function heartbeat_type_update_nodes($old_id, $new_id) {
  348. return \Drupal::entityManager()->getStorage('heartbeat')->updateType($old_id, $new_id);
  349. }
  350. /**
  351. * Builds a message template for a given HeartbeatType
  352. *
  353. * @param HeartbeatType $heartbeatType
  354. * @param null $mediaData
  355. * @return null|string
  356. */
  357. public static function buildMessage(Token $tokenService, $preparsedMessage, $entities = NULL, $entityType, $mediaData = NULL) {
  358. $options = null;
  359. if ($entityType === 'flag') {
  360. $returnMessage = self::handleMultipleEntities($tokenService, $preparsedMessage, $entities);
  361. // $returnMessage = "jigga";
  362. return strlen($returnMessage) > 0 ? $returnMessage : "Error creating message";
  363. }
  364. $parsedMessage = $tokenService->replace($preparsedMessage . '<a href="/node/[node:nid]">', $entities);
  365. /** @noinspection NestedTernaryOperatorInspection */
  366. $message = $parsedMessage;
  367. $message .= $mediaData ? self::buildMediaMarkup($mediaData) : '';
  368. $message .= '</a>';
  369. return $message;
  370. }
  371. private static function buildMediaMarkup($mediaData) {
  372. $markup = '';
  373. foreach ($mediaData as $media) {
  374. $markup .= self::mediaTag($media->type, $media->path);
  375. }
  376. return $markup;
  377. }
  378. private static function mediaTag($type, $filePath) {
  379. //TODO put this into new method
  380. if ($type == 'image') { $type = 'img';}
  381. return '<'. $type . ' src="' . str_replace('public://', '/sites/default/files/', $filePath) . '" / >';
  382. }
  383. protected static function handleMultipleEntities(\Drupal\token\token $tokenService, $message, $entities) {
  384. $tokens = $tokenService->scan($message);
  385. foreach($tokens as $key => $token) {
  386. foreach ($token as $type) {
  387. if (substr_count($message, $type) > 1) {
  388. foreach ($entities as $entityKey => $entityValue) {
  389. if ($entityValue instanceof \stdClass && count($entityValue->entities) > 1) {
  390. if ($key == $entityValue->type) {
  391. $messageArray = explode($type, $message);
  392. $stringRebuild = array();
  393. $replacements = array();
  394. $i = 0;
  395. foreach ($entityValue->entities as $entity) {
  396. $stringRebuild[] = $tokenService->replace($message, array($key => $entity));
  397. foreach (self::getWordRepeats($stringRebuild[$i]) as $word => $num) {
  398. if ($num > 1 && !strpos($messageArray[1], $word)) {
  399. $replacements[] = $word;
  400. }
  401. }
  402. $i++;
  403. }
  404. if (count($replacements) == 2) {
  405. $uid = $entityValue->entities[0]->id();
  406. $uid_target = $entityValue->entities[1]->id();
  407. $query = Database::getConnection()->query('
  408. SELECT status
  409. FROM heartbeat_friendship
  410. WHERE uid = :uid AND uid_target = :uid_target', array(
  411. ':uid' => $uid,
  412. ':uid_target' => $uid_target
  413. )
  414. );
  415. if ($query->fetchCol()[0] < 1) {
  416. $messageArray[1] = ' has requested friendship with ';
  417. }
  418. $user1Link = Link::fromTextAndUrl($replacements[0], $entityValue->entities[0]->toUrl());
  419. $user2Link = Link::fromTextAndUrl($replacements[1], $entityValue->entities[1]->toUrl());
  420. $rebuiltMessage = $user1Link->toString() . $messageArray[1] . $user2Link->toString();
  421. return $rebuiltMessage;
  422. }
  423. }
  424. }
  425. }
  426. }
  427. }
  428. }
  429. return null;
  430. }
  431. /**
  432. * Helper method to identify the number of times a word is repeated in a phrase
  433. *
  434. * @param $phrase
  435. * @return array
  436. */
  437. public static function getWordRepeats($phrase) {
  438. $counts = array();
  439. $words = explode(' ', $phrase);
  440. foreach ($words as $word) {
  441. if (!array_key_exists($word, $counts)) {
  442. $counts[$word] = 0;
  443. }
  444. $word = preg_replace("#[^a-zA-Z\-]#", "", $word);
  445. ++$counts[$word];
  446. }
  447. return $counts;
  448. }
  449. /**
  450. * Returns class of argument
  451. *
  452. * @param $field
  453. * @return string
  454. */
  455. public static function findClass($field) {
  456. return get_class($field);
  457. }
  458. /**
  459. * Returns an array of classes for array argument
  460. * @param $fields
  461. * @return array
  462. */
  463. public static function findAllMedia($fields) {
  464. return array_map(array(get_called_class(), 'findClass'), $fields);
  465. }
  466. /**
  467. * Returns all media types for an array of fields
  468. *
  469. * @param $fields
  470. * @return array
  471. * @throws \Drupal\Core\Entity\Exception\UndefinedLinkTemplateException
  472. * @throws \Drupal\Core\Entity\EntityMalformedException
  473. */
  474. public static function mediaFieldTypes($fields) {
  475. $types = array();
  476. foreach ($fields as $field) {
  477. if ($field instanceof \Drupal\file\Plugin\Field\FieldType\FileFieldItemList) {
  478. if ($field->getFieldDefinition()->getType() === 'image' ||
  479. $field->getFieldDefinition()->getType() === 'video' ||
  480. $field->getFieldDefinition()->getType() === 'audio') {
  481. $fieldValue = $field->getValue();
  482. $fileId = $fieldValue[0]['target_id'];
  483. $file = \Drupal::entityTypeManager()->getStorage('file')->load($fileId);
  484. if ($file !== NULL && is_object($file)) {
  485. $url = Url::fromUri($file->getFileUri());
  486. $mediaObject = self::createHeartbeatMedia($field->getFieldDefinition()->getType(), $url->getUri());
  487. $types[] = $mediaObject;
  488. } else {
  489. continue;
  490. }
  491. }
  492. }
  493. }
  494. return $types;
  495. }
  496. /**
  497. * Parses a HeartbeatType message template and maps
  498. * variable values onto matching keywords
  499. *
  500. * @param $translatedMessage
  501. * @param $variables
  502. * @return string
  503. */
  504. public static function parseMessage($translatedMessage, $variables) {
  505. return strtr($translatedMessage, $variables);
  506. }
  507. public static function createHeartbeatMedia($type, $path) {
  508. $mediaObject = new \stdClass();
  509. $mediaObject->type = $type;
  510. $mediaObject->path = $path;
  511. return $mediaObject;
  512. }
  513. public static function getEntityNames($entityTypes) {
  514. $names = array();
  515. foreach ($entityTypes as $type) {
  516. if (($type->getBaseTable() === 'node') ||
  517. ($type->getBaseTable() === 'user')
  518. ||
  519. ($type->getStorageClass() !== NULL &&
  520. strpos($type->getStorageClass(), $type->getLabel()->getUntranslatedString())
  521. )
  522. ) {
  523. $names[] = $type->id();
  524. }
  525. }
  526. sort($names);
  527. return $names;
  528. }
  529. /**
  530. * Updates the friendship status of these two users
  531. *
  532. * @param $uid
  533. * @param $uid_target
  534. * @param $unixtime
  535. * @param $friendStatus
  536. * @return \Drupal\Core\Database\StatementInterface|int|null
  537. */
  538. public static function updateFriendship($uid, $uid_target, $unixtime, $friendStatus) {
  539. // $query = Database::getConnection()->upsert('heartbeat_friendship')
  540. // ->fields(array(
  541. // 'uid' => $uid,
  542. // 'uid_target' => $uid_target,
  543. // 'created' => $unixtime,
  544. // 'status' => $friendStatus,
  545. // ))
  546. // ->key('uid_relation');
  547. // return $query->execute();
  548. $update = Database::getConnection()->update('heartbeat_friendship')
  549. ->fields(['status' => $friendStatus])
  550. ->condition('uid', $uid, '=')
  551. ->condition('uid_target', $uid_target, '=');
  552. if (!$update->execute()) {
  553. $insert = Database::getConnection()->insert('heartbeat_friendship')
  554. ->fields([
  555. 'uid' => $uid,
  556. 'uid_target' => $uid_target,
  557. 'created' => $unixtime,
  558. 'status' => $friendStatus
  559. ]);
  560. if (!$insert->execute()) {
  561. \Drupal::logger('Heartbeat')->error('Unable to update friendship between %uid and %uid_target', array('%uid' => $uid, '%uid_target' => $uid_target));
  562. }
  563. }
  564. }
  565. /**
  566. * Gets the Heartbeat user.
  567. *
  568. * @return int
  569. * The uid of the Heartbeat's user.
  570. */
  571. public function getUid()
  572. {
  573. // TODO: Implement getUid() method.
  574. }
  575. /**
  576. * Sets the Heartbeat user.
  577. *
  578. * @param int uid
  579. * The Heartbeat user.
  580. *
  581. */
  582. public function setUid($uid)
  583. {
  584. // TODO: Implement setUid() method.
  585. }
  586. /**
  587. * Gets the Heartbeat's associated node nid.
  588. *
  589. * @return int
  590. * The nid of the Heartbeat's associated node.
  591. */
  592. public function getNid() {
  593. return $this->get('nid');
  594. }
  595. /**
  596. * Sets the Heartbeat user.
  597. *
  598. * @param int uid
  599. * The Heartbeat user.
  600. *
  601. */
  602. public function setNid($nid) {
  603. $this->set('nid', $nid);
  604. }
  605. }