<?php
namespace MatthiasWeb\RealMediaLibrary\metadata;

defined( 'ABSPATH' ) or die( 'No script kiddies please!' );

/**
 * Trait common folder meta helper methods.
 * 
 * @since 4.0.8
 */
trait CommonFolderTrait {
    use CommonTrait;
    
    /**
     * Gets (and persists) a checkbox to the folder metadata.
     * 
     * @param string $meta The meta key
     * @param IFolder $folder The folder
     * @param boolean $persist If setted it will be updated or deleted
     * @returns boolean
     */
    static protected function is($meta, $folder, $persist = null) {
        if ($persist !== null) {
            if ($persist) {
                $update = update_media_folder_meta($folder->getId(), $meta, $persist);
                return $update > 0 || $update;
            }else{
                return delete_media_folder_meta($folder->getId(), $meta);
            }
        }
        return (boolean) get_media_folder_meta($folder->getId(), $meta, true);
    }
}