public function saveMediaCategoryAssignments(int $mediaId, array $categoryIds = null)
    {
        // Delete current category assignments for this media ID
        $this->deleteMediaCategoryAssignments($mediaId);

        // Insert all assignments, if the category ID's array is not empty
        if (null !== $categoryIds) {
            $this->sql = 'insert into media_category_map (media_id, category_id) values ';
            foreach ($categoryIds as $id) {
                $this->sql .= '(?, ?),';
                $this->bindValues[] = $mediaId;
                $this->bindValues[] = $id;
            }
            $this->sql = rtrim($this->sql, ',') . ';';
            $this->execute();
        }
    }
public function saveMediaCategoryAssignments(int $mediaId, array $categoryIds = null)
    {
        // Delete current category assignments for this media ID
        $this->deleteMediaCategoryAssignments($mediaId);

        // Insert all assignments, if the category ID's array is not empty
        if (null !== $categoryIds) {
            $this->sql = 'insert into media_category_map (media_id, category_id) values ';
            foreach ($categoryIds as $id) {
                $this->sql .= '(?, ?),';
                $this->bindValues[] = $mediaId;
                $this->bindValues[] = $id;
            }
            $this->sql = rtrim($this->sql, ',') . ';';
            $this->execute();
        }
    }
public function saveMediaCategoryAssignments ( int $ mediaId , array $ categoryIds = null ) { // Delete current category assignments for this media ID $ this -> deleteMediaCategoryAssignments ( $ mediaId ) ; // Insert all assignments, if the category ID's array is not empty if ( null !== $ categoryIds ) { $ this -> sql = 'insert into media_category_map (media_id, category_id) values ' ; foreach ( $ categoryIds as $ id ) { $ this -> sql .= '(?, ?),' ; $ this -> bindValues [ ] = $ mediaId ; $ this -> bindValues [ ] = $ id ; } $ this -> sql = rtrim ( $ this -> sql , ',' ) . ';' ; $ this -> execute ( ) ; } }
Save Media Category Assignments

For a media ID, save category array
@param int   $mediaId
@param array $categoryIds
@return mixed
Save Media Category Assignments