/** * @covers hypeJunction\Inbox\Group::add * @covers hypeJunction\Inbox\Group::entities * @covers hypeJunction\Inbox\Group::toEntity */ public function testEntities() { $mock = $this->getMock('\\ElggEntity'); $mock->expects($this->once())->method('getGUID')->willReturn(4); $entities = $this->object->add('foo')->add(array('bar', new stdClass()))->add(0)->add(1)->add(array(2, 3))->add($mock)->entities(); $this->assertInternalType('array', $entities); foreach ($entities as $entity) { $this->assertInstanceOf('\\ElggEntity', $entity); } }
/** * {@inheritdoc} */ public function execute() { if ($this->entity instanceof Message) { $this->message_hash = $this->entity->getHash(); $this->message_type = $this->entity->getMessageType(); } else { if (!$this->message_type) { $this->message_type = Message::TYPE_PRIVATE; } } // files being uploaded via $_FILES $uploads = UploadHandler::handle('attachments'); if ($uploads) { foreach ($uploads as $upload) { if ($upload instanceof ElggFile) { $this->attachment_guids[] = $upload->guid; } } } $this->attachments = Group::create($this->attachment_guids)->entities(); $access_id = AccessCollection::create(array($this->sender_guid, $this->recipient_guids))->getCollectionId(); foreach ($this->attachments as $attachment) { $attachment->origin = 'messages'; $attachment->access_id = $access_id; $attachment->save(); } $guid = Message::factory(array('sender' => $this->sender_guid, 'recipients' => $this->recipient_guids, 'subject' => $this->subject, 'body' => $this->body, 'message_hash' => $this->message_hash, 'attachments' => $this->attachments))->send(); $this->entity = $guid ? get_entity($guid) : false; if (!$this->entity) { // delete attachment if message failed to send foreach ($this->attachments as $attachment) { $attachment->delete(); } $this->result->addError(elgg_echo('inbox:send:error:generic')); return; } $sender = $this->entity->getSender(); $this->message_type = $this->entity->getMessageType(); $this->message_hash = $this->entity->getHash(); $ruleset = hypeInbox()->config->getRuleset($this->message_type); $this->attachments = array_map(array(hypeInbox()->model, 'getLinkTag'), $this->attachments); $body = array_filter(array($ruleset->hasSubject() ? $this->entity->subject : '', $this->entity->getBody(), implode(', ', array_filter($this->attachments)))); $notification_body = implode(PHP_EOL, $body); foreach ($this->recipient_guids as $recipient_guid) { $recipient = get_entity($recipient_guid); if (!$recipient) { continue; } $type_label = strtolower($ruleset->getSingularLabel($recipient->language)); $subject = elgg_echo('inbox:notification:subject', array($type_label), $recipient->language); $notification = elgg_echo('inbox:notification:body', array($type_label, $sender->name, $notification_body, elgg_view('output/url', array('href' => $this->entity->getURL())), $sender->name, elgg_view('output/url', array('href' => elgg_normalize_url("messages/thread/{$this->message_hash}#reply")))), $recipient->language); $summary = elgg_echo('inbox:notification:summary', array($type_label), $recipient->language); notify_user($recipient->guid, $sender->guid, $subject, $notification, array('action' => 'send', 'object' => $this->entity, 'summary' => $summary)); } $this->result->addMessage(elgg_echo('inbox:send:success')); $this->result->setForwardURL($this->entity->getURL()); }
/** * Prepare compose form variables * * @param integer $recipient_guids GUIDs of recipients if any * @param string $message_type Type of the message being composed * @param ElggObject $entity Message to which the reply is to be sent * @return array An array of form variables */ public function prepareFormValues($recipient_guids = null, $message_type = null, $entity = null) { if (!$message_type) { $message_type = Message::TYPE_PRIVATE; } $recipient_guids = Group::create($recipient_guids)->guids(); $ruleset = hypeInbox()->config->getRuleset($message_type); $values = array('entity' => $entity, 'multiple' => $ruleset->allowsMultipleRecipients(), 'has_subject' => $ruleset->hasSubject(), 'allows_attachments' => $ruleset->allowsAttachments(), 'subject' => $entity ? "Re: {$entity->title}" : '', 'body' => '', 'recipient_guids' => $recipient_guids, 'message_type' => $message_type); if (elgg_is_sticky_form('messages')) { $sticky = elgg_get_sticky_values('messages'); foreach ($sticky as $field => $value) { if ($field == 'recipient_guids' && is_string($value)) { $value = string_to_tag_array($value); } $values[$field] = $value; } } elgg_clear_sticky_form('messages'); return $values; }
/** * Create a new group from a mixed data set * * @param array $data Data set * @return Group */ public static function create($data) { $group = new Group(); return $group->add($data); }