src/File.php
public function batchAdd($objectID, array $files) {
        $objects = [];

        foreach ($files as $description) {
            $objects[] = [
                'type' => 'C__OBJTYPE__FILE',
                'title' => $description
            ];
        }

        $cmdbObjects = new CMDBObjects($this->api);

        $fileObjectIDs = $cmdbObjects->create($objects);

        if (count($fileObjectIDs) !== count($files)) {
            throw new RuntimeException(sprintf(
                'Wanted to create %s file object(s) but got %s object identifiers',
                count($files),
                count($fileObjectIDs)
            ));
        }

        $requests = [];

        $counter = 0;

        foreach ($files as $filePath => $description) {
            $fileAsString = $this->encode($filePath);

            $requests[] = [
                'method' => 'cmdb.category.create',
                'params' => [
                    'objID' => $fileObjectIDs[$counter],
                    'catsID' => 'C__CATS__FILE_VERSIONS',
                    'data' => [
                        'file_content' => $fileAsString,
                        'file_physical' => basename($filePath),
                        'file_title' => $description,
                        'version_description' => $description
                    ]
                ]
            ];

            $requests[] = [
                'method' => 'cmdb.category.create',
                'params' => [
                    'objID' => $objectID,
                    'catgID' => 'C__CATG__FILE',
                    'data' => [
                        'file' => $fileObjectIDs[$counter]
                    ]
                ]
            ];

            $counter++;
        }

        $this->api->batchRequest($requests);

        return $this;
    }
public function batchAdd($objectID, array $files) {
        $objects = [];

        foreach ($files as $description) {
            $objects[] = [
                'type' => 'C__OBJTYPE__FILE',
                'title' => $description
            ];
        }

        $cmdbObjects = new CMDBObjects($this->api);

        $fileObjectIDs = $cmdbObjects->create($objects);

        if (count($fileObjectIDs) !== count($files)) {
            throw new RuntimeException(sprintf(
                'Wanted to create %s file object(s) but got %s object identifiers',
                count($files),
                count($fileObjectIDs)
            ));
        }

        $requests = [];

        $counter = 0;

        foreach ($files as $filePath => $description) {
            $fileAsString = $this->encode($filePath);

            $requests[] = [
                'method' => 'cmdb.category.create',
                'params' => [
                    'objID' => $fileObjectIDs[$counter],
                    'catsID' => 'C__CATS__FILE_VERSIONS',
                    'data' => [
                        'file_content' => $fileAsString,
                        'file_physical' => basename($filePath),
                        'file_title' => $description,
                        'version_description' => $description
                    ]
                ]
            ];

            $requests[] = [
                'method' => 'cmdb.category.create',
                'params' => [
                    'objID' => $objectID,
                    'catgID' => 'C__CATG__FILE',
                    'data' => [
                        'file' => $fileObjectIDs[$counter]
                    ]
                ]
            ];

            $counter++;
        }

        $this->api->batchRequest($requests);

        return $this;
    }
public function batchAdd ( $ objectID , array $ files ) { $ objects = [ ] ; foreach ( $ files as $ description ) { $ objects [ ] = [ 'type' => 'C__OBJTYPE__FILE' , 'title' => $ description ] ; } $ cmdbObjects = new CMDBObjects ( $ this -> api ) ; $ fileObjectIDs = $ cmdbObjects -> create ( $ objects ) ; if ( count ( $ fileObjectIDs ) !== count ( $ files ) ) { throw new RuntimeException ( sprintf ( 'Wanted to create %s file object(s) but got %s object identifiers' , count ( $ files ) , count ( $ fileObjectIDs ) ) ) ; } $ requests = [ ] ; $ counter = 0 ; foreach ( $ files as $ filePath => $ description ) { $ fileAsString = $ this -> encode ( $ filePath ) ; $ requests [ ] = [ 'method' => 'cmdb.category.create' , 'params' => [ 'objID' => $ fileObjectIDs [ $ counter ] , 'catsID' => 'C__CATS__FILE_VERSIONS' , 'data' => [ 'file_content' => $ fileAsString , 'file_physical' => basename ( $ filePath ) , 'file_title' => $ description , 'version_description' => $ description ] ] ] ; $ requests [ ] = [ 'method' => 'cmdb.category.create' , 'params' => [ 'objID' => $ objectID , 'catgID' => 'C__CATG__FILE' , 'data' => [ 'file' => $ fileObjectIDs [ $ counter ] ] ] ] ; $ counter ++ ; } $ this -> api -> batchRequest ( $ requests ) ; return $ this ; }
Add multiple new files to a specific object.
New file objects will be created and assigned to the specific object.

@param int $objectID Object identifier
@param array $files Associative array (key: path to file; value: description)

@return self Returns itself

@throws Exception on error
Add multiple new files to a specific object . New file objects will be created and assigned to the specific object .