Esempio n. 1
0
<?php

$folder_guid = (int) get_input('folder_guid');
$container_guid = elgg_extract("container_guid", $vars, elgg_get_page_owner_guid());
$current_folder = elgg_extract("folder", $vars, $folder_guid);
$type = elgg_extract("type", $vars);
unset($vars["folder"]);
unset($vars["type"]);
unset($vars["container_guid"]);
if ($type == 'folder') {
    if (!elgg_extract("value", $vars)) {
        if (!empty($current_folder)) {
            $vars["value"] = get_entity($current_folder)->parent_guid;
        }
    }
} elseif (!elgg_extract("value", $vars)) {
    $vars["value"] = $current_folder;
}
$folders = file_tools_get_folders($container_guid);
$options = array(0 => elgg_echo("file_tools:input:folder_select:main"));
if (!empty($folders)) {
    $options = $options + file_tools_build_select_options($folders, 1);
}
$vars["options_values"] = $options;
echo elgg_view("input/dropdown", $vars);
Esempio n. 2
0
/**
 * Make folder select options
 *
 * @param array $folders folders to make the options for
 * @param int   $depth   current depth
 *
 * @return string
 */
function file_tools_build_select_options($folders, $depth = 0)
{
    $result = array();
    if (!empty($folders)) {
        foreach ($folders as $index => $level) {
            /**
             * $level contains
             * folder: the folder on this level
             * children: potential children
             *
             */
            if ($folder = elgg_extract("folder", $level)) {
                $result[$folder->getGUID()] = str_repeat("-", $depth) . $folder->title;
            }
            if ($childen = elgg_extract("children", $level)) {
                $result += file_tools_build_select_options($childen, $depth + 1);
            }
        }
    }
    return $result;
}
Esempio n. 3
0
<?php

$folder_guid = (int) get_input("folder_guid");
$container_guid = elgg_extract("container_guid", $vars, elgg_get_page_owner_guid());
$current_folder = elgg_extract("folder", $vars, $folder_guid);
$type = elgg_extract("type", $vars);
unset($vars["folder"]);
unset($vars["type"]);
unset($vars["container_guid"]);
if ($type == "folder") {
    if (!elgg_extract("value", $vars)) {
        if (!empty($current_folder)) {
            $vars["value"] = get_entity($current_folder)->parent_guid;
        }
    }
} elseif (!elgg_extract("value", $vars)) {
    $vars["value"] = $current_folder;
}
$folders = file_tools_get_folders($container_guid);
$options = array(0 => elgg_echo("file_tools:input:folder_select:main"));
if (!empty($folders)) {
    $options = $options + file_tools_build_select_options($folders, 1, $folder_guid, '-1');
}
$vars["options_values"] = $options;
echo elgg_view("input/dropdown", $vars);
Esempio n. 4
0
/**
 * Make folder select options
 *
 * @param array $folders folders to make the options for
 * @param int   $depth   current depth
 *
 * @return []
 */
function file_tools_build_select_options($folders, $depth = 0)
{
    $result = [];
    if (empty($folders)) {
        return [];
    }
    foreach ($folders as $index => $level) {
        /**
         * $level contains
         * folder: the folder on this level
         * children: potential children
         *
         */
        $folder = elgg_extract('folder', $level);
        if (!empty($folder)) {
            $result[$folder->getGUID()] = str_repeat('-', $depth) . ' ' . $folder->title;
        }
        $childen = elgg_extract('children', $level);
        if (!empty($childen)) {
            $result += file_tools_build_select_options($childen, $depth + 1);
        }
    }
    return $result;
}