SproutCMS

This is the code documentation for the SproutCMS project

class MultiEdit

UI system for rapid adding/editing of any number of (sub-)records

Example

$images = MultiEdit::load('gallery_images', ['gallery_id' => $gallery_id], 'record_order');
MultiEdit::itemName('Image');
MultiEdit::reorder();
MultiEdit::setPostAddJavaScriptFunc('load_thumbnails');
MultiEdit::display('images', $images, @$_SESSION['gallery']['field_errors']['multiedit_images']);

Extending this class

<?php
/**
* New class description goes here
* 
* @author Your Name, 2024-05-07
**/
class NewClassName extends MultiEdit {
    
    /**
    * Displays a multiedit field
    **/
    public function display (string $key, array|null $data, array $errors) {
        // Method code goes here
    }
    
    /**
    * Returns true if the multiedit record is empty, false otherwise
    **/
    public function recordEmpty (array $record, array $defaults) {
        // Method code goes here
    }
    
    /**
    * Set the item name for a multiedit.
    * e.g. 'image'
    **/
    public function itemName ($item_name) {
        // Method code goes here
    }
    
    /**
    * Set the name of a javascript function to call after each multiedit item is added
    * 
    * The JavaScript function is called with the following arguments:
    *     $div     jQuery element for the outer div
    *     data     Array of field data OR null for a new record
    *     idx      The record index
    **/
    public function setPostAddJavaScriptFunc (string $function_name) {
        // Method code goes here
    }
    
    /**
    * Enable multiedit reordering
    **/
    public function reorder () {
        // Method code goes here
    }
    
    /**
    * Returns an array of data, which should be put into a view, and passed into MultiEdit::display.
    **/
    public function load (string $table, array $where, string|array $order) {
        // Method code goes here
    }
    
}
?>