Exemple #1
0
function _getThemeChildNodes($theme_id, $cat_id, $level) {
  $theme_type = 0;
  $query = 'select theme_type from "Theme" where theme_id = %d';
  $query_args = array($theme_id);
  $result = db_query($query, $query_args);
  if (!$result) {
    return false;
  } else {
    if($obj = db_fetch_object($result)) {
      $theme_type = $obj->theme_type;
    }
  }

  $themes = array();
  if($theme_type == 1) {
    $query = 'SELECT theme_id, theme_name, icon FROM "Theme" where theme_id != parent_id and parent_id = %d and status = 1 order by theme_name';
    $result = db_query($query, $theme_id);
    if (!$result) {
      return false;
    } else {
      while($obj = db_fetch_object($result)) {
        $thm = array();
        $thm['type'] = 'theme';
        $thm['id'] = $obj->theme_id;
        $thm['name'] = $obj->theme_name;
        $thm['icon'] = $obj->icon;
        if($level > 1) {
          $t = _getThemeChildNodes($theme_id, $cat_id, $level - 1);
          if($t === false) {
            return false;
          }
          if(count($t) > 0) {
            $thm['children'] = $t;
          }
        }
        $themes[] = $thm;
      }
    }
  } elseif($theme_type == 2) {
    if($cat_id == 0) {
      $query = 'select category_id, category_name from "Categories_Structure" where category_id = parent_id';
      $result = db_query($query);
    } else {
      $query = 'select category_id, category_name from "Categories_Structure" where category_id != parent_id and parent_id = %d';
      $query_args = array($cat_id);
      $result = db_query($query, $query_args);
    }
    if (!$result) {
      return false;
    } else {
      while($obj = db_fetch_object($result)) {
        $thm = array();
        $thm['type'] = 'category';
        $thm['id'] = $obj->category_id;
        $thm['name'] = $obj->category_name;
        $thm['icon'] = $obj->icon;

        $children = array();
        if($level > 1) {
          $t = _getThemeChildNodes($theme_id, $obj->category_id, $level - 1);
          if($t === false) {
            return false;
          }
          if(count($t) > 0) {
            //$thm['children'] = $t;
            $children = $t;
          }
        }

        if(count($children) > 0) {
          $thm['children'] = $children;
        }

        $themes[] = $thm;
      }

      // Check if any layers are assigned to this theme_id and category_id;
      $query1 = 'select layer_tablename, layer_name, layer_type, nid from "Meta_Layer" where status = 1 and layer_id in (select layer_id from "Theme_Layer_Mapping" where status = 1 and theme_id = %d and category_id = %d)';
      $query_args1 = array($theme_id,  $cat_id);
      $result1 = db_query($query1, $query_args1);
      $layers = array();
      if (!$result1) {
        return false;
      } else {
        while($obj1 = db_fetch_object($result1)) {
          $lyr = array();
          $lyr['type'] = 'layer';
          $lyr['id'] = $obj1->layer_tablename;
          $lyr['name'] = $obj1->layer_name;
          switch($obj1->layer_type) {
            case 'POINT':
            case 'MULTIPOINT':
              $lyr['layer_type'] = 'POINT';
              break;
            case 'POLYGON':
            case 'MULTIPOLYGON':
              $lyr['layer_type'] = 'POLYGON';
              break;
            case 'LINE':
            case 'LINESTRING':
            case 'MULTILINESTRING':
              $lyr['layer_type'] = 'LINE';
              break;
            case 'RASTER':
              $lyr['layer_type'] = 'RASTER';
              break;
            default:
              $lyr['layer_type'] = $obj1->layer_type;
              break;
          }
          $lyr['nid'] = $obj1->nid;
          $layers[] = $lyr;
        }
      }
      if(count($layers) > 0) {
        $themes = array_merge($themes, $layers);
      }

    }
  }

  return $themes;
}
function getThemesChildNodes($xmlDoc, &$rootNode, $paramsNode) {
  $theme_id = $paramsNode->getElementsByTagName('theme_id')->item(0)->nodeValue;
  $category_id = $paramsNode->getElementsByTagName('category_id')->item(0)->nodeValue;
  $level = $paramsNode->getElementsByTagName('level')->item(0)->nodeValue;

  if($category_id == null || $category_id == '') {
    $category_id = 0;
  }

  if($level == null || $level == '') {
    $level = 1;
  }

  if($theme_id == null || $theme_id == '') {
    setError($xmlDoc, $rootNode, "Required parameters not set.");
    return;
  } else {
    $thms = _getThemeChildNodes($theme_id, $category_id, $level);
    if($thms === false) {
      setError($xmlDoc, $rootNode, "Error fetching information.");
    } else {
      setNoError($xmlDoc, $rootNode);
      $thmsNode = addXMLChildNode($xmlDoc, $rootNode, "theme", null, array('id' => $theme_id, 'category_id' => $category_id, 'level' => $level));

      if($category_id == 0) {
        $nid = 0;
        $images = '';
        $videos = '';
        $query = 'select nid, images, videos from "Theme" where theme_id = %d';
        $query_args = array($theme_id);
        $result = db_query($query, $query_args);
        if(!$result) {
          return false;
        } else {
          if($obj = db_fetch_object($result)) {
            $nid = $obj->nid;
            $images = array();
            $str = $obj->images;
            if($str != NULL || !empty($str)) {
              $images = explode(",", $str);
            }
            $videos = array();
            $str = $obj->videos;
            if($str != NULL || !empty($str)) {
              $videos = explode(",", $str);
            }
          }
        }
        if($nid > 0) {
          $teaser = getReadMoreDrupalNodeTeaser($nid, 150);
          addXMLChildNode($xmlDoc, $thmsNode, 'narrative', $teaser, array('nid' => $nid));
        }

        $mediaNode = addXMLChildNode($xmlDoc, $thmsNode, 'media');

        $base_path = base_path();

        $imagesNode = addXMLChildNode($xmlDoc, $mediaNode, 'images');
        foreach ($images as $im) {
          addXMLChildNode($xmlDoc, $imagesNode, "image", $im, array('src' => $base_path . 'sites/default/files/images/theme_' . $theme_id . '/' . $im));
        }

        $videosNode = addXMLChildNode($xmlDoc, $mediaNode, 'videos');
        foreach ($videos as $vd) {
          addXMLChildNode($xmlDoc, $videosNode, "video", $vd, array('src' => $base_path . 'sites/default/files/videos/theme_' . $theme_id . '/' . $vd));
        }
      }

      createXMLForThemeChildNodes($xmlDoc, $thmsNode, $thms);
    }
  }
}