mirror of
https://github.com/humhub/humhub.git
synced 2025-01-30 21:07:41 +01:00
Revert "Refactor HActiveRecord and comment widgets"
This commit is contained in:
parent
f6353719ed
commit
08dbcbfbbf
@ -32,7 +32,14 @@
|
||||
* @package humhub.components
|
||||
* @since 0.5
|
||||
*/
|
||||
abstract class HActiveRecord extends CActiveRecord {
|
||||
abstract class HActiveRecord extends CActiveRecord
|
||||
{
|
||||
|
||||
// Avoid Errors when fields not exists
|
||||
public $created_at;
|
||||
public $created_by;
|
||||
public $updated_at;
|
||||
public $updated_by;
|
||||
|
||||
/**
|
||||
* Inits the active records and registers the event interceptor
|
||||
@ -51,33 +58,33 @@ abstract class HActiveRecord extends CActiveRecord {
|
||||
*/
|
||||
protected function beforeValidate()
|
||||
{
|
||||
|
||||
$userID = ! empty(Yii::app()->user) ? Yii::app()->user->id : 0;
|
||||
|
||||
// check if this object has 'created_by' if it does and
|
||||
// its a new record please set it to current userID
|
||||
if ($this->hasAttribute('created_by') && $this->isNewRecord)
|
||||
$this->created_by = $userID;
|
||||
// Check if we got an user object
|
||||
if (isset(Yii::app()->user)) {
|
||||
$userId = Yii::app()->user->id;
|
||||
} else {
|
||||
$userId = 0;
|
||||
}
|
||||
|
||||
|
||||
if ($this->isNewRecord) {
|
||||
// set the create date, last updated date and the user doing the creating
|
||||
$this->created_at = $this->updated_at = new CDbExpression('NOW()');
|
||||
if ($this->created_by == "")
|
||||
$this->created_by = $userId;
|
||||
}
|
||||
|
||||
// check if this object has 'updated_by' if it does and
|
||||
// its NOT a new record please update it to current userID
|
||||
if ($this->hasAttribute('updated_by') && !$this->isNewRecord)
|
||||
$this->updated_by = $userID;
|
||||
if ($userId != 0) {
|
||||
//not a new record, so just set the last updated time and last updated user id
|
||||
$this->updated_at = new CDbExpression('NOW()');
|
||||
if ($this->updated_by == "")
|
||||
$this->updated_by = $userId;
|
||||
}
|
||||
|
||||
|
||||
return parent::beforeValidate();
|
||||
}
|
||||
|
||||
public function behaviors()
|
||||
{
|
||||
return array(
|
||||
'CTimestampBehavior' => array(
|
||||
'class' => 'zii.behaviors.CTimestampBehavior',
|
||||
'createAttribute' => 'created_at',
|
||||
'updateAttribute' => 'updated_at',
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the creator user of this active record
|
||||
* (Faster than relation() because cached).
|
||||
@ -110,4 +117,4 @@ abstract class HActiveRecord extends CActiveRecord {
|
||||
return get_class($this) . "_" . $this->id;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
1
protected/config/.gitignore
vendored
1
protected/config/.gitignore
vendored
@ -1 +0,0 @@
|
||||
_settings.php
|
@ -9,41 +9,46 @@
|
||||
* @package humhub.modules_core.comment
|
||||
* @since 0.5
|
||||
*/
|
||||
class CommentsWidget extends HWidget {
|
||||
class CommentsWidget extends HWidget
|
||||
{
|
||||
|
||||
/**
|
||||
* Content Object
|
||||
*/
|
||||
public $object;
|
||||
/**
|
||||
* Content Object
|
||||
*/
|
||||
public $object;
|
||||
|
||||
/**
|
||||
* Executes the widget.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
/**
|
||||
* Executes the widget.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
|
||||
$modelName = $this->object->content->object_model;
|
||||
$modelId = $this->object->content->object_id;
|
||||
|
||||
// Indicates that the number of comments was limited
|
||||
$isLimited = false;
|
||||
$modelName = $this->object->content->object_model;
|
||||
$modelId = $this->object->content->object_id;
|
||||
|
||||
// Indicates that the number of comments was limited
|
||||
$isLimited = false;
|
||||
|
||||
// Count all Comments
|
||||
$commentCount = Comment::GetCommentCount($modelName, $modelId);
|
||||
$comments = Comment::GetCommentsLimited($modelName, $modelId, 2);
|
||||
// Count all Comments
|
||||
$commentCount = Comment::GetCommentCount($modelName, $modelId);
|
||||
$comments = Comment::GetCommentsLimited($modelName, $modelId, 2);
|
||||
|
||||
if ($commentCount > 2)
|
||||
$isLimited = true;
|
||||
if ($commentCount > 2)
|
||||
$isLimited = true;
|
||||
|
||||
$this->render('comments', array(
|
||||
'object' => $this->object,
|
||||
'comments' => $comments,
|
||||
'modelName' => $modelName,
|
||||
'modelId' => $modelId,
|
||||
'id' => $modelName . "_" . $modelId,
|
||||
'isLimited' => $isLimited,
|
||||
'total' => $commentCount
|
||||
));
|
||||
}
|
||||
$this->render('comments', array(
|
||||
'object' => $this->object,
|
||||
|
||||
'comments' => $comments,
|
||||
'modelName' => $modelName,
|
||||
'modelId' => $modelId,
|
||||
'id' => $modelName . "_" . $modelId,
|
||||
'isLimited' => $isLimited,
|
||||
'total' => $commentCount
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -10,21 +10,25 @@
|
||||
*/
|
||||
class ShowCommentWidget extends HWidget {
|
||||
|
||||
/**
|
||||
* @var Comment object to display
|
||||
*/
|
||||
public $comment = null;
|
||||
/**
|
||||
* @var Comment object to display
|
||||
*/
|
||||
public $comment = null;
|
||||
|
||||
/**
|
||||
* Executes the widget.
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
$user = $this->comment->user;
|
||||
$this->render('showComment', array(
|
||||
'comment' => $this->comment,
|
||||
'user' => $user,
|
||||
));
|
||||
}
|
||||
/**
|
||||
* Executes the widget.
|
||||
*/
|
||||
public function run() {
|
||||
|
||||
}
|
||||
$user = $this->comment->user;
|
||||
|
||||
$this->render('showComment', array(
|
||||
'comment' => $this->comment,
|
||||
'user' => $user,
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user