public static function get_root_json(array $children, $op = self::OP_AND, $show = true) {

        // Get the basic object.
        $result = self::get_nested_json($children, $op);

        // Check $op type.
        switch($op) {
            case self::OP_AND:
            case self::OP_NOT_OR:
                $multishow = true;
                break;
            case self::OP_OR:
            case self::OP_NOT_AND:
                $multishow = false;
                break;
        }

        // Add show options depending on operator.
        if ($multishow) {
            if (is_bool($show)) {
                $result->showc = array_pad(array(), count($result->c), $show);
            } else if (is_array($show)) {
                // The JSON will break if anything isn't an actual bool, so check.
                foreach ($show as $item) {
                    if (!is_bool($item)) {
                        throw new \coding_exception('$show array members must be bool');
                    }
                }
                // Check the size matches.
                if (count($show) != count($result->c)) {
                    throw new \coding_exception('$show array size does not match $children');
                }
                $result->showc = $show;
            } else {
                throw new \coding_exception('$show must be bool or array');
            }
        } else {
            if (!is_bool($show)) {
                throw new \coding_exception('For this operator, $show must be bool');
            }
            $result->show = $show;
        }

        return $result;
    }
public static function get_root_json(array $children, $op = self::OP_AND, $show = true) {

        // Get the basic object.
        $result = self::get_nested_json($children, $op);

        // Check $op type.
        switch($op) {
            case self::OP_AND:
            case self::OP_NOT_OR:
                $multishow = true;
                break;
            case self::OP_OR:
            case self::OP_NOT_AND:
                $multishow = false;
                break;
        }

        // Add show options depending on operator.
        if ($multishow) {
            if (is_bool($show)) {
                $result->showc = array_pad(array(), count($result->c), $show);
            } else if (is_array($show)) {
                // The JSON will break if anything isn't an actual bool, so check.
                foreach ($show as $item) {
                    if (!is_bool($item)) {
                        throw new \coding_exception('$show array members must be bool');
                    }
                }
                // Check the size matches.
                if (count($show) != count($result->c)) {
                    throw new \coding_exception('$show array size does not match $children');
                }
                $result->showc = $show;
            } else {
                throw new \coding_exception('$show must be bool or array');
            }
        } else {
            if (!is_bool($show)) {
                throw new \coding_exception('For this operator, $show must be bool');
            }
            $result->show = $show;
        }

        return $result;
    }
public static function get_root_json ( array $ children , $ op = self :: OP_AND , $ show = true ) { // Get the basic object. $ result = self :: get_nested_json ( $ children , $ op ) ; // Check $op type. switch ( $ op ) { case self :: OP_AND : case self :: OP_NOT_OR : $ multishow = true ; break ; case self :: OP_OR : case self :: OP_NOT_AND : $ multishow = false ; break ; } // Add show options depending on operator. if ( $ multishow ) { if ( is_bool ( $ show ) ) { $ result -> showc = array_pad ( array ( ) , count ( $ result -> c ) , $ show ) ; } else if ( is_array ( $ show ) ) { // The JSON will break if anything isn't an actual bool, so check. foreach ( $ show as $ item ) { if ( ! is_bool ( $ item ) ) { throw new \ coding_exception ( '$show array members must be bool' ) ; } } // Check the size matches. if ( count ( $ show ) != count ( $ result -> c ) ) { throw new \ coding_exception ( '$show array size does not match $children' ) ; } $ result -> showc = $ show ; } else { throw new \ coding_exception ( '$show must be bool or array' ) ; } } else { if ( ! is_bool ( $ show ) ) { throw new \ coding_exception ( 'For this operator, $show must be bool' ) ; } $ result -> show = $ show ; } return $ result ; }
Returns a JSON object which corresponds to a tree at root level.

Intended for unit testing, as normally the JSON values are constructed
by JavaScript code.

The $show parameter can be a boolean for all OP_xx options. For OP_AND
and OP_NOT_OR where you have individual show options, you can specify
a boolean (same for all) or an array.

@param array $children Array of JSON objects from component children
@param string $op Operator (tree::OP_xx)
@param bool|array $show Whether 'show' option is turned on (see above)
@return stdClass JSON object ready for encoding
@throws coding_exception If you get parameters wrong
Returns a JSON object which corresponds to a tree at root level .