Contao\FilesModel::findMultipleByIds PHP Method

findMultipleByIds() public static method

Find multiple files by their IDs or UUIDs
public static findMultipleByIds ( array $arrIds, array $arrOptions = [] ) : Collection | FilesModel[] | FilesModel | null
$arrIds array An array of IDs or UUIDs
$arrOptions array An optional options array
return Contao\Model\Collection | FilesModel[] | FilesModel | null A collection of models or null if there are no files
    public static function findMultipleByIds($arrIds, array $arrOptions = array())
    {
        if (!is_array($arrIds) || empty($arrIds)) {
            return null;
        }
        if (\Validator::isUuid(current($arrIds))) {
            return static::findMultipleByUuids($arrIds, $arrOptions);
        }
        return parent::findMultipleByIds($arrIds, $arrOptions);
    }

Usage Example

Ejemplo n.º 1
0
 /**
  * Translate the file IDs to file paths
  */
 protected function convertValuesToPaths()
 {
     if (empty($this->varValue)) {
         return;
     }
     if (!is_array($this->varValue)) {
         $this->varValue = array($this->varValue);
     } elseif (empty($this->varValue[0])) {
         $this->varValue = array();
     }
     if (empty($this->varValue)) {
         return;
     }
     // TinyMCE will pass the path instead of the ID
     if (strncmp($this->varValue[0], \Config::get('uploadPath') . '/', strlen(\Config::get('uploadPath')) + 1) === 0) {
         return;
     }
     // Ignore the numeric IDs when in switch mode (TinyMCE)
     if (\Input::get('switch')) {
         return;
     }
     $objFiles = \FilesModel::findMultipleByIds($this->varValue);
     if ($objFiles !== null) {
         $this->varValue = array_values($objFiles->fetchEach('path'));
     }
 }
All Usage Examples Of Contao\FilesModel::findMultipleByIds