PHP code example of grigorygraborenko / recursive-admin

1. Go to this page and download the library: Download grigorygraborenko/recursive-admin library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

grigorygraborenko / recursive-admin example snippets


$bundles = [
...
new Grigorygraborenko\RecursiveAdmin\RecursiveAdminBundle(),


use Grigorygraborenko\RecursiveAdmin\Annotations\Admin;

/**
 * @ORM\Entity
 * @Admin(entity=["ROLE_ADMIN", "ROLE_TESTER"], sortBy="name", priority=1000, label="Result of Test")
 */
class TestResult {

    /**
     * @ORM\Column(type="string")
     * @Admin(read="ROLE_ADMIN", priority=10, label="Test Name")
     */
    protected $name;

public function SERVICE_FUNCTION($container, $admin) {

    $user_input = array(
        "api" => array(
            "type" => "select"
            ,"label" => "Which API?"
            ,"choices" => array(
                array("label" => "Internal", "value" => "int_01")
                ,array("label" => "External", "value" => "ext_02")
                ,array("label" => "All of them", "value" => "*")
            )
        )
        ,"num_tests" => array(
            "type" => "integer"
            ,"label" => "How many times should the tests run?"
            ,"default" => 1
            ,"omatic tests for each API"
            ,"permission" => "ROLE_SUPER_ADMIN"
            ,"input" => $super_user_input
        )
    );
}

public function runTests($container, $admin, $input) {
    ...
    if($some_error) {
        return "Tests had an error of some sort";
    }
    ...
    return array("report" => "Everything went well");
}

return array("file" => array("name" => "test_results.csv", "contents" => "test,result\ninternal,passed\nexternal,passed\n"));


    public static function adminStatic($container, $admin) {
        return array(
            "headers" => array(
                array("label" => "Action", "permission" => "ROLE_ADMIN", "priority" => 50)
            )
            ,"create" => array(
                "callback" => "adminCreate"
                ,"input" => $create_input
            )

        );
    }
    
    public function adminActions($container, $admin) {

        if(!$this->isBannable()) {
            return array(); // no custom actions at all
        }
    
        $ban_input = array(
            "reason" => array(
                "type" => "boolean"
                ,"label" => "Ban forever?"
               ,"default" => false
            )
        );

        return array(
            "ban" => array(
                "heading" => "Action"
                ,"callback" => "adminBan"
                ,"permission" => "ROLE_ADMIN"
                ,"class" => ($this->is_unbanned ? "btn-danger" : "btn-warning")
                ,"label" => ($this->is_unbanned ? "BAN" : "UNBAN")
                ,"input" => ($this->is_unbanned ? $ban_input : array())
                ,"description" => ($is_unbanned ? "Unban this user" : "Ban this user")
            )
        )
    }
    
    public function adminBan($container, $admin, $input) {
        ...
        if($error_str) {
            return "Error: error_str";
        }
        return array(
            "affected_fields" => array("is_unbanned", "date_banned")
            ,"report" => "This user was banned or unbanned"
        );
    }
    

    $user_input = array(
        "test_name" => array("type" => "string", "label" => "Name of New Test", " => true, "lines" => 4) // lines will enable textarea with N rows
        ,"test_quantity" => array("type" => "integer", "label" => "How many times it should run", "default" => 1)
        ,"test_fraction" => array("type" => "decimal", "label" => "Fraction of acceptable errors", "bel" => "Both internal & external", "value" => "hybrid")
        ))
        ,"test_rerun" => array("type" => "select", "label" => "Re-run in case of failure?", "default" => "false", "choices" => array(
            array("label" => "No", "value" => "false")
            ,array("label" => "Yes", "value" => "true", "input" => array(
                "test_num_reruns" => array("type" => "integer", "label" => "How many times it should attempt to re-run", "default" => 10)
                ,"test_justification" => array("type" => "string", "label" => "Why should this test re-run?", "default" => "Because why not.")
            ))
        ))
        ,"test_user" => array("type" => "entity", "label" => "A user responsible for this test", "entity" => 'AppBundle\Entity\User')
        ,"test_dependencies" => array("type" => "multientity", "label" => "A list of tests that must run first", , "entity" => 'AppBundle\Entity\TestSpec')
        ,"test_error_descriptions" => array("type" => "array", "label" => "A list of descriptions for error codes", "input" => array(
            "code" => array("type" => "integer", "label" => "Error code", "

    // the callback function will get something like this back:
    $input_result = array(
        "test_name" => "Division by zero"
        ,"test_quantity" => 3
        ,"test_fraction" => 0.2
        ,"test_type" => "internal"
        ,"test_rerun" => "true" // if this was "false", the array would not have the next two entries
        ,"test_num_reruns" => 126 // only appears if "test_rerun" was "true"
        ,"test_justification" => "Just in case that zero wasn't really zero, but a really small number." // only appears if "test_rerun" was "true"
        ,"test_user" => "ID_43tgf43mn9j38er23" // Not an object, but an ID
        ,"test_dependencies" => array("ID_3hj767jfgfdg", "ID_rthg54trhytj4t") // Not an array of objects, but ID's
        ,"test_error_descriptions" => array(
            array("code" => 12, "description" => "Something mysterious went wrong")
            ,array("code" => 46, "description" => "Negative zero encountered")
            ,array("code" => 1, "description" => "There was an error detected in the error detection subroutines")
        )
        ,"test_file" => [OBJECT]
    );

    // either this...
    ,"test_rerun" => array("value" => "true", "input" => array(
        "test_num_reruns" => 126
        ,"test_justification" => "Just in case that zero wasn't really zero, but a really small number."
    )
    // ...or this
    ,"test_rerun" => array("value" => "false", "input" => array()