Enh: Added File::findByRecord for searching all attached files of a given ActiveRecord

This commit is contained in:
buddh4 2017-03-13 22:27:57 +01:00
parent 008f751e3b
commit 78aeb563d6
2 changed files with 15 additions and 1 deletions

View File

@ -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)

View File

@ -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()]);
}
}