Project

General

Profile

« Previous | Next » 

Revision eb537a36

IDeb537a36b83df334ac39d629ccc88dc579a532a9
Parent c4802754
Child 5119cb9e

Added by Jocelyn Delande about 9 years ago

small fixes arround site_point::get_all() usage

Files

  • added
  • modified
  • copied
  • renamed
  • deleted

View differences

Changesets

ajax/all_points.php
33 33
}
34 34

  
35 35

  
36
foreach(site_point::get_all() as $site_point) {
36
foreach(site_point::get_all(true) as $site_point) {
37 37
	$json['features'][] = $site_point->to_geoJSON();
38 38
}
39 39

  
class/site_point.class.php
1 1
<?php
2 2
require_once(dirname(__FILE__).'/../constants.inc.php');
3

  
4
//
5
class PanoramaFormatException extends Exception {
6
	/** If the files organization is not correct for a panorama, we can't let it go...
7
	 */
8
}
9

  
3 10
class site_point {
4 11
	/** Defines a point, with a panorama
5 12
	 */
......
11 18

  
12 19
  public function __construct($dir) {
13 20
    // si $dir n'est pas un répertoire il ne s'agit pas d'un panorama.
14
    if (!is_dir($dir)) return;
21
	  if (!is_dir($dir)) {
22
		  throw new PanoramaFormatException("$dir does not contain a panorama");
23
	  }
15 24
    $this->base_dir = $dir;
16
    $dir_fd = opendir($this->base_dir);
17

  
18
    while (false !== ($file = readdir($dir_fd))) {
19

  
20
       if (preg_match('/(.*)_[0-9]+_[0-9]+_[0-9]+\.jpg$/', $file, $reg)) {
21
	       $this->prefix = $reg[1];
22

  
23
	       break;
24
       }
25
    }
26
    closedir($dir_fd);
27
    if ($this->prefix === false) return false;
28
    $this->parse_and_cache_params();
25
    $this->prefix = basename($dir);
29 26
  }
30 27

  
31 28
  public function params_path() {
......
34 31

  
35 32
  private function parse_and_cache_params() {
36 33
    if (is_file($this->params_path())) {
37
	    $this->params = @parse_ini_file($this->params_path());
34
	    $params = parse_ini_file($this->params_path());
35
	    if ($params) {
36
		    $this->params = $params;
37
		    return $params;
38
	    }
38 39
    }
40
    return array();
39 41
  }
40 42

  
41 43
  public function get_params() {
42 44
	  // the params are cached
43
	  if (isset($this->params)) {
45
	  if (isset($this->params) && $this->params) {
44 46
		  return $this->params;
45 47
	  } else {
46
		  return parse_and_cache_params();
48
		  return $this->parse_and_cache_params();
47 49
	  }
48 50
  }
49 51

  
......
161 163
  }
162 164

  
163 165

  
164
  public static function get_all() {
166
  public static function get_all($only_with_params=false) {
167
	  /**
168
	   * @param $only_with_params : filters out the panoramas which are not parametrized
169
	   */
165 170
	  $panos = array_diff(scandir(PANORAMA_PATH), array('..', '.'));
166 171
	  $pano_instances = array();
172

  
167 173
	  foreach ($panos as $pano_name) {
168
		  $pano_instances[] = site_point::get($pano_name);
174
		  $pano =  site_point::get($pano_name);
175
		  if (! $only_with_params || $pano->has_params() ) {
176
			  $pano_instances[] = $pano;
177
		  }
169 178
	  }
170 179
	  return $pano_instances;
171 180
  }
index.php
14 14
      <?php
15 15
require_once 'class/utils.class.php';
16 16
require_once 'constants.inc.php';
17
require_once('class/site_point.class.php');
17 18
utils::init();
18 19

  
19 20
if(isset($_GET['dir']) && is_dir($_GET['dir'])) {
......
24 25

  
25 26
$dir = new sites_dir($base_dir);
26 27
try {
27
  $sites_list = $dir->get_sites();
28
  $sites_list = site_point::get_all();
28 29

  
29 30
  echo "<ul id=\"pano-list\">\n";
30 31