/** * Get omero files * * @param string $path * @param int|string $page * @param null $search_text * @return array */ public function get_listing($path = '/', $page = '1', $search_text = null) { global $CFG, $OUTPUT; // format the current selected URL if (empty($path)) { $path = '/'; } // Initializes the data structures needed to build the response $list = array(); $list['list'] = array(); $list['manage'] = get_config('omero', 'omero_restendpoint'); $list['dynload'] = true; $list['nologin'] = true; $list['search_query'] = $search_text; // Host the navigation links $navigation_list = array(); // Enable/Disable the search field $list['nosearch'] = false; // process search request if (isset($search_text) || PathUtils::is_annotations_query($path)) { if (isset($search_text)) { $response = $this->omero->process_search($search_text, $this->access_key, $this->access_secret); } else { $response = $this->process_request($path); } foreach ($response as $item) { $itype = "Tag"; if (strcmp($item->type, "tagset") == 0) { $itype = "TagSet"; } $obj = $this->process_list_item($itype, $item); if ($obj != null) { $list['list'][] = $obj; } } // Set this result as a search result $list['issearchresult'] = true; // Build the navigation bar $list['path'] = $this->build_navigation_bar($navigation_list, "/find/annotations", "", $search_text); } else { // true if the list is a search result $list['issearchresult'] = false; if (PathUtils::is_root_path($path)) { $list['list'][] = $this->process_list_item("ProjectRoot", (object) $this->PROJECTS_ROOT_ITEM); $list['list'][] = $this->process_list_item("TagRoot", (object) $this->TAGS_ROOT_ITEM); // Build the navigation bar $list['path'] = $this->build_navigation_bar($navigation_list, $path); } else { if (PathUtils::is_projects_root($path)) { debugging("The root project path has been selected !!!"); $response = $this->process_request(PathUtils::build_project_list_url()); foreach ($response as $item) { $obj = $this->process_list_item("Project", $item); if ($obj != null) { $list['list'][] = $obj; } } // Build the navigation bar $list['path'] = $this->build_navigation_bar($navigation_list, $path); } else { if (PathUtils::is_annotations_root($path)) { debugging("The root tag path has been selected !!!"); $response = $this->process_request(PathUtils::build_annotation_list_url()); foreach ($response as $item) { $itype = "Tag"; if (strcmp($item->type, "tagset") == 0) { $itype = "TagSet"; } $obj = $this->process_list_item($itype, $item); if ($obj != null) { $list['list'][] = $obj; } } // Build the navigation bar $list['path'] = $this->build_navigation_bar($navigation_list, $path); } else { if (PathUtils::is_tagset_root($path)) { debugging("The tagset root path has been selected: {$path} !!!"); $response = $this->process_request($path); foreach ($response->tags as $item) { $obj = $this->process_list_item("Tag", $item); if ($obj != null) { $list['list'][] = $obj; } } // Build the navigation bar $list['path'] = $this->build_navigation_bar($navigation_list, $path, $response); } else { if (PathUtils::is_tag($path)) { debugging("Tag selected: {$path}!!!"); $selected_obj_info = $this->process_request($path); $response = $selected_obj_info; foreach ($response->images as $item) { $obj = $this->process_list_item("Image", $item); if ($obj != null) { $list['list'][] = $obj; } } // Build the navigation bar $list['path'] = $this->build_navigation_bar($navigation_list, $path, $response); } else { if (PathUtils::is_project($path)) { $project_id = PathUtils::get_element_id_from_url($path, "project"); $response = $this->process_request(PathUtils::build_dataset_list_url($project_id)); if (isset($response->datasets)) { foreach ($response->datasets as $item) { $obj = $this->process_list_item("Dataset", $item); if ($obj != null) { $list['list'][] = $obj; } } } // Build the navigation bar $list['path'] = $this->build_navigation_bar($navigation_list, $path, $response); } else { if (PathUtils::is_dataset($path)) { debugging("Dataset selected!!!"); $response = $this->process_request($path); // Build the navigation bar $list['path'] = $this->build_navigation_bar($navigation_list, $path, $response); // process images if ($this->ENABLE_PAGINATION) { if (empty($page)) { $page = 1; } else { $page = (int) $page; } $num_images_per_page = 12; $list['page'] = $page; $list['pages'] = 1; if (count($response) > 12) { $list['pages'] = 1 + ceil((count($response) - 12) / $num_images_per_page); } $last = $page == 1 ? 12 : $page * $num_images_per_page; $first = $last - ($page == 1 ? 12 : $num_images_per_page); $counter = 0; foreach ($response as $item) { if ($counter == $last) { break; } if ($counter < $first) { $counter++; continue; } else { $processed_item = $this->process_list_item("Image", $item); if ($processed_item != null) { $list['list'][] = $processed_item; } $counter++; } } } else { $list['pages'] = 1; foreach ($response->images as $item) { $processed_item = $this->process_list_item("Image", $item); if ($processed_item != null) { $list['list'][] = $processed_item; } } return $list; } } else { debugging("Unknown resource selected: {$path} !!!: "); } } } } } } } } return $list; }