Chng #3816: Use of static::class query class within ContentActiveRecord::find() instead of getObjectModel()

This commit is contained in:
buddh4 2020-01-09 14:37:27 +01:00
parent 8b3b4ac29a
commit b9eefb2ddd
2 changed files with 57 additions and 15 deletions

View File

@ -22,6 +22,7 @@ HumHub Change Log (DEVELOP)
- Fix: Prevent sidebar swipe on menu scroll
- Fix #3805: Cannot select more than one activity in E-Mail Summaries settings
- Fix #3802: 'usersearch-status' dropdown triggers reload on click
- Chng #3816: Use of `static::class` query class within `ContentActiveRecord::find()` instead of `getObjectModel()`
1.4.0-beta.2

View File

@ -228,6 +228,7 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner, Movable
* @param array $labels
* @param bool $includeContentName
* @return Label[]|\string[] content labels used for example in wallentrywidget
* @throws \Exception
*/
public function getLabels($labels = [], $includeContentName = true)
{
@ -279,22 +280,30 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner, Movable
{
if(!$this->hasManagePermission()) {
return null;
} elseif(is_string($this->managePermission)) { // Simple Permission class specification
}
if(is_string($this->managePermission)) { // Simple Permission class specification
return $this->managePermission;
} elseif(is_array($this->managePermission)) {
}
if(is_array($this->managePermission)) {
if(isset($this->managePermission['class'])) { // ['class' => '...', 'callback' => '...']
$handler = $this->managePermission['class'].'::'.$this->managePermission['callback'];
return call_user_func($handler, $this);
} else { // Simple Permission array specification
return $this->managePermission;
}
} elseif(is_callable($this->managePermission)) { // anonymous function
return $this->managePermission($this);
} elseif($this->managePermission instanceof BasePermission) {
// Simple Permission array specification
return $this->managePermission;
} else {
return null;
}
if(is_callable($this->managePermission)) { // anonymous function
return $this->managePermission($this);
}
if($this->managePermission instanceof BasePermission) {
return $this->managePermission;
}
return null;
}
/**
@ -329,7 +338,7 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner, Movable
* Returns an instance of the assigned wall entry widget instance. This can be used to check matadata fields
* of the related widget.
*
* @return null|\humhub\modules\content\widgets\WallEntry for this class by wallEntryClass property , null will be
* @return null|WallEntry for this class by wallEntryClass property , null will be
* returned if this wallEntryClass is empty
*/
public function getWallEntryWidget()
@ -343,7 +352,9 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner, Movable
$widget = new $class;
$widget->contentObject = $this;
return $widget;
} else {
}
if($this->wallEntryClass) {
$class = $this->wallEntryClass;
$widget = new $class;
return $widget;
@ -354,6 +365,7 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner, Movable
/**
* @inheritdoc
* @throws Exception
*/
public function beforeSave($insert)
{
@ -390,6 +402,24 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner, Movable
parent::afterSave($insert, $changedAttributes);
}
/**
* Returns the class used in the polymorphic content relation.
* By default this function will return the static class.
*
* Subclasses of existing content record classes may overwrite this function in order to remain the actual
* base type as follows:
*
* ```
* public static function getObjectModel() {
* return BaseType::class
* }
* ```
*
* This will force the usage of the `BaseType` class when creating, deleting or querying the content relation.
* This is used in cases in which a subclass extends the a base record class without implementing a custom content type.
*
* @return string
*/
public static function getObjectModel() {
return static::class;
}
@ -408,7 +438,7 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner, Movable
}
/**
* @return \humhub\modules\user\models\User the owner of this content record
* @return User the owner of this content record
*/
public function getOwner()
{
@ -448,12 +478,22 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner, Movable
/**
* Returns an ActiveQueryContent to find content.
*
* Results of this query will be static typed.
* In order to force a specific type as query result this function needs to be overwritten as:
*
* ```
* public static function find()
* {
* return new ActiveQueryContent(MyBaseType::class);
* }
* ```
*
* {@inheritdoc}
* @return ActiveQueryContent
*/
public static function find()
{
return new ActiveQueryContent(static::getObjectModel());
return new ActiveQueryContent(static::class);
}
/**
@ -488,13 +528,14 @@ class ContentActiveRecord extends ActiveRecord implements ContentOwner, Movable
/**
* {@inheritdoc}
*/
public final function move(ContentContainerActiveRecord $container = null, $force = false)
final public function move(ContentContainerActiveRecord $container = null, $force = false)
{
return $this->content->move($container, $force);
}
/**
* This function can be overwritten in order to define model specific logic as moving sub-content or other related
* This function is called after the content hast been moved and can be overwritten
* in order to define model specific logic as moving sub-content or other related.
* @param ContentContainerActiveRecord|null $container
*/
public function afterMove(ContentContainerActiveRecord $container = null) {}