/** * Add messageboard post * * @param ElggUser $poster User posting the message * @param ElggUser $owner User who owns the message board * @param string $message The posted message * @param int $access_id Access level (see defines in elgglib.php) * @return bool */ function messageboard_add($poster, $owner, $message, $access_id = ACCESS_PUBLIC) { $result_id = $owner->annotate('messageboard', $message, $access_id, $poster->guid); if (!$result_id) { return false; } elgg_create_river_item(array('view' => 'river/object/messageboard/create', 'action_type' => 'messageboard', 'subject_guid' => $poster->guid, 'object_guid' => $owner->guid, 'access_id' => $access_id, 'annotation_id' => $result_id)); // Send notification only if poster isn't the owner if ($poster->guid != $owner->guid) { $subject = elgg_echo('messageboard:email:subject', array(), $owner->language); $body = elgg_echo('messageboard:email:body', array($poster->name, $message, elgg_get_site_url() . "messageboard/owner/" . $owner->username, $poster->name, $poster->getURL()), $owner->language); notify_user($owner->guid, $poster->guid, $subject, $body); } return $result_id; }
/** * Make sure entity is loaded from cache during save operations * See #10612 */ public function testNewUserLoadedFromCacheDuringSaveOperations() { $user = new \ElggUser(); // Add temporary metadata, annotation and private settings // to extend the scope of tests and catch issues with save operations $user->test_metadata = 'bar'; $user->annotate('test_annotation', 'baz'); $user->setPrivateSetting('test_setting', 'foo'); $metadata_called = false; $metadata_event_handler = function ($event, $type, $metadata) use(&$metadata_called) { /* @var $metadata \ElggMetadata */ $entity = get_entity($metadata->entity_guid); $this->assertEqual($metadata->entity_guid, $entity->guid); $metadata_called = true; }; $annotation_called = false; $annotation_event_handler = function ($event, $type, $annotation) use(&$annotation_called) { /* @var $metadata \ElggAnnotation */ $entity = get_entity($annotation->entity_guid); $this->assertEqual($annotation->entity_guid, $entity->guid); $annotation_called = true; }; elgg_register_event_handler('create', 'metadata', $metadata_event_handler); elgg_register_event_handler('create', 'annotation', $annotation_event_handler); $user->save(); elgg_unregister_event_handler('create', 'metadata', $metadata_event_handler); elgg_unregister_event_handler('create', 'annotation', $annotation_event_handler); $user->delete(); $this->assertTrue($metadata_called); $this->assertTrue($annotation_called); }
/** * Add messageboard post * * @param ElggUser $poster User posting the message * @param ElggUser $owner User who owns the message board * @param string $message The posted message * @param int $access_id Access level (see defines in elgglib.php) * @return bool */ function messageboard_add($poster, $owner, $message, $access_id = ACCESS_PUBLIC) { $result = $owner->annotate('messageboard', $message, $access_id, $poster->guid); if (!$result) { return false; } add_to_river('river/object/messageboard/create', 'messageboard', $poster->guid, $owner->guid, $access_id, 0, $result); // only send notification if not self if ($poster->guid != $owner->guid) { $subject = elgg_echo('messageboard:email:subject'); $body = elgg_echo('messageboard:email:body', array($poster->name, $message, elgg_get_site_url() . "messageboard/" . $owner->username, $poster->name, $poster->getURL())); notify_user($owner->guid, $poster->guid, $subject, $body); } return $result; }