/** * Override parent's implementation as we need to generate the stream * * @since 1.2 * @access public * @param string * @return */ public function addFile($title = null) { // Run the parent's logics first $result = parent::addFile($title); if ($result instanceof SocialException) { return $result; } // Create a stream item for the groups now $stream = FD::stream(); $tpl = $stream->getTemplate(); $actor = FD::user(); // this is a cluster stream and it should be viewable in both cluster and user page. $tpl->setCluster($this->group->id, SOCIAL_TYPE_GROUP, $this->group->type); // Set the actor $tpl->setActor($actor->id, SOCIAL_TYPE_USER); // Set the context $tpl->setContext($result->id, SOCIAL_TYPE_FILES); // Set the verb $tpl->setVerb('uploaded'); $file = FD::table('File'); $file->load($result->id); // Set the params to cache the group data $registry = FD::registry(); $registry->set('group', $this->group); $registry->set('file', $file); // Set the params to cache the group data $tpl->setParams($registry); // since this is a cluster and user stream, we need to call setPublicStream // so that this stream will display in unity page as well // This stream should be visible to the public $tpl->setAccess('core.view'); $streamItem = $stream->add($tpl); // Prepare the stream permalink $permalink = FRoute::stream(array('layout' => 'item', 'id' => $streamItem->uid)); // Notify group members when a new file is uploaded $this->group->notifyMembers('file.uploaded', array('fileId' => $file->id, 'fileName' => $file->name, 'fileSize' => $file->getSize(), 'permalink' => $permalink, 'userId' => $file->user_id)); return $result; }
/** * Override parent's behavior to insert a file * * @since 1.3 * @access public * @param string * @return */ public function addFile($title = null) { // Run the parent's logics first $result = parent::addFile($title); if ($result instanceof SocialException) { return $result; } $createStream = $this->input->get('createStream', false, 'bool'); if ($createStream) { // Create a new stream for the user upload now $stream = FD::stream(); $tpl = $stream->getTemplate(); // Set the actor $tpl->setActor($this->my->id, SOCIAL_TYPE_USER); // Set the context $tpl->setContext($result->id, SOCIAL_TYPE_FILES); // Set the verb $tpl->setVerb('uploaded'); // Set the access for this stream item $tpl->setAccess('core.view'); // Insert the stream now $streamItem = $stream->add($tpl); } return $result; }