Added stream channels instead of show in stream flag

This commit is contained in:
Lucas Bartholemy 2017-01-18 19:14:11 +01:00
parent 43374aaf3b
commit b94b77484f
8 changed files with 122 additions and 19 deletions

View File

@ -28,12 +28,17 @@ class Activity extends ContentActiveRecord
* @inheritdoc
*/
public $wallEntryClass = "humhub\modules\activity\widgets\Activity";
/**
* @inheritdoc
*/
public $autoFollow = false;
/**
* @inheritdoc
*/
protected $streamChannel = 'activity';
/**
* @inheritdoc
*/

View File

@ -50,13 +50,21 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner
* @var string WallEntry widget class
*/
public $wallEntryClass = "";
/**
* Defines if originator automatically follows this content when saved.
* @var type
*/
public $autoFollow = true;
/**
* The stream channel where this content should displayed.
* Set to null when this content should not appear on the stream.
*
* @since 1.2
* @var string|null the stream channel
*/
protected $streamChannel = 'default';
/**
* @inheritdoc
@ -100,6 +108,7 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner
/**
* Returns a description of this particular content.
*
* This will be used to create a text preview of the content record. (e.g. in Activities or Notifications)
* You need to override this method in your content implementation.
*
@ -167,6 +176,8 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner
throw new Exception("Could not validate associated Content Record! (" . print_r($this->content->getErrors(), 1) . ")");
}
$this->content->setAttribute('stream_channel', $this->streamChannel, false);
return parent::beforeSave($insert);
}
@ -176,7 +187,7 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner
public function afterSave($insert, $changedAttributes)
{
// Auto follow this content
if($this->autoFollow) {
if ($this->autoFollow) {
$this->follow($this->content->created_by);
}

View File

@ -0,0 +1,20 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2017 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\stream;
/**
* Stream Module provides stream (wall) backend and frontend
*
* @author Luke
* @since 1.2
*/
class Module extends \humhub\components\Module
{
}

View File

@ -12,6 +12,7 @@ use Yii;
use yii\base\Action;
use humhub\modules\content\models\Content;
use humhub\modules\user\models\User;
use humhub\modules\stream\models\StreamQuery;
use yii\base\ActionEvent;
use yii\base\Exception;
@ -195,9 +196,7 @@ abstract class Stream extends Action
}
if ($this->mode == self::MODE_ACTIVITY) {
$this->streamQuery->includes(\humhub\modules\activity\models\Activity::className());
$this->streamQuery->query()->leftJoin('activity', 'content.object_id=activity.id AND content.object_model=:activityModel', ['activityModel' => \humhub\modules\activity\models\Activity::className()]);
// Note that if $this->user is null the streamQuery will use the current user identity!
$this->streamQuery->channel(StreamQuery::CHANNEL_ACTIVITY);
$this->streamQuery->query()->andWhere('content.created_by != :userId', [':userId' => $this->streamQuery->user->id]);
}
}

View File

@ -0,0 +1,8 @@
<?php
return [
'id' => 'stream',
'class' => \humhub\modules\stream\Module::className(),
'isCoreModule' => true,
];
?>

View File

@ -0,0 +1,34 @@
<?php
use yii\db\Migration;
class m170118_162332_streamchannel extends Migration
{
public function up()
{
$this->addColumn('content', 'stream_channel', $this->char(15)->null());
$this->update('content', ['stream_channel' => 'activity', 'show_in_stream' => 0], ['object_model' => \humhub\modules\activity\models\Activity::className(), 'show_in_stream' => 1]);
$this->update('content', ['stream_channel' => 'default'], ['show_in_stream' => 1]);
$this->dropColumn('content', 'show_in_stream');
$this->createIndex('stream_channe', 'content', 'stream_channel', false);
}
public function down()
{
echo "m170118_162332_streamchannel cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -32,6 +32,12 @@ class StreamQuery extends \yii\base\Model
const FILTER_PRIVATE = "visibility_private";
const FILTER_PUBLIC = "visibility_public";
/**
* Default channels
*/
const CHANNEL_DEFAULT = 'default';
const CHANNEL_ACTIVITY = 'activity';
/**
* Maximum wall entries per request
*/
@ -44,6 +50,11 @@ class StreamQuery extends \yii\base\Model
*/
protected $_includes;
/**
* @var string stream channel to display
*/
protected $_channel;
/**
* Can be set to filter out specific content types.
*
@ -51,12 +62,6 @@ class StreamQuery extends \yii\base\Model
*/
protected $_excludes;
/**
* Used to deactivate the default exclusion of activity entries
* @var type
*/
public $prevenActivityFilter = false;
/**
* The user which requested the stream. By default the current user identity.
* @var \humhub\modules\user\models\User
@ -113,7 +118,6 @@ class StreamQuery extends \yii\base\Model
* @var \yii\db\ActiveQuery
*/
protected $_query;
protected $_built = false;
public function rules()
@ -234,7 +238,7 @@ class StreamQuery extends \yii\base\Model
}
public function query($build = false)
{
{
if ($build) {
$this->setupQuery();
}
@ -259,6 +263,11 @@ class StreamQuery extends \yii\base\Model
$this->checkFrom();
$this->setupCriteria();
$this->setupFilters();
if (empty($this->_channel)) {
$this->channel(self::CHANNEL_DEFAULT);
}
$this->_built = true;
}
@ -441,11 +450,6 @@ class StreamQuery extends \yii\base\Model
$this->_excludes = [$this->_excludes];
}
// Filter out Activity Entrys by default
if (!$this->prevenActivityFilter && !in_array(\humhub\modules\activity\models\Activity::className(), $this->_includes)) {
$this->_excludes[] = \humhub\modules\activity\models\Activity::className();
}
if (count($this->_excludes) === 1) {
$this->_query->andWhere(['!=', "content.object_model", $this->_excludes[0]]);
} else if (!empty($this->_excludes)) {
@ -453,4 +457,17 @@ class StreamQuery extends \yii\base\Model
}
}
/**
* Sets the channel for this stream query
*
* @param string $channel
* @return StreamQuery
*/
public function channel($channel)
{
$this->_channel = $channel;
$this->_query->andWhere(['content.stream_channel' => $channel]);
return $this;
}
}

View File

@ -0,0 +1,9 @@
{
"id": "stream",
"name": "Stream",
"description": "Stream Core",
"keywords": [
"core"
],
"version": "1.2"
}