diff --git a/protected/humhub/docs/CHANGELOG.md b/protected/humhub/docs/CHANGELOG.md index 26fdc46307..5481a72cca 100644 --- a/protected/humhub/docs/CHANGELOG.md +++ b/protected/humhub/docs/CHANGELOG.md @@ -3,6 +3,8 @@ HumHub Change Log 1.2.0-beta.3 under developement -------------------------------- +- Enh: Added File::findByRecord for searching all attached files of a given ActiveRecord +- Fix: Only set js view state for non full page load and pjax - Fix: Small gap on TopNav mouse hover (acs-ferreira) - Enh: Humand readable file sizes. (acs-ferreira) - Enh: Changed default $minInput of SpacePickerField to 2. (githubjeka) diff --git a/protected/humhub/modules/file/models/File.php b/protected/humhub/modules/file/models/File.php index a898f8d7fe..92e8e443e4 100644 --- a/protected/humhub/modules/file/models/File.php +++ b/protected/humhub/modules/file/models/File.php @@ -136,12 +136,13 @@ class File extends FileCompat /** * Checks if given file can deleted. * - * If the file is not an instance of HActiveRecordContent or HActiveRecordContentAddon + * If the file is not an instance of ContentActiveRecord or ContentAddonActiveRecord * the file is readable for all unless there is method canWrite or canDelete implemented. */ public function canDelete($userId = "") { $object = $this->getPolymorphicRelation(); + if ($object != null) { if ($object instanceof ContentAddonActiveRecord) { return $object->canWrite($userId); @@ -186,5 +187,16 @@ class File extends FileCompat return $this->_store; } + + /** + * Returns all attached Files of the given $record. + * + * @param \yii\db\ActiveRecord $record + * @return File[] + */ + public static function findByRecord(\yii\db\ActiveRecord $record) + { + return self::findAll(['object_model' => $record->className(), 'object_id' => $record->getPrimaryKey()]); + } }