Author: gassla
Date: Wed May 30 10:44:23 2007
New Revision: 461

URL: http://svn.gna.org/viewcvs/phplinker?rev=461&view=rev
Log:
#145 : API Demande de la liste de toutes les categories (chapitre 3.15.1)

Modified:
    trunk/www/admin/api/fetch_categories.php   (contents, props changed)
    trunk/www/lib/category.php

Modified: trunk/www/admin/api/fetch_categories.php
URL: 
http://svn.gna.org/viewcvs/phplinker/trunk/www/admin/api/fetch_categories.php?rev=461&r1=460&r2=461&view=diff
==============================================================================
--- trunk/www/admin/api/fetch_categories.php (original)
+++ trunk/www/admin/api/fetch_categories.php Wed May 30 10:44:23 2007
@@ -16,21 +16,26 @@
     along with PHPLinker; if not, write to the Free Software
     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 */
+  /**
+   * @version $Id$
+   * @copyright Copyright (c) by ISVTEC
+   * @license GPL v2
+   */
+?>
+<?php
+require($_SERVER['DOCUMENT_ROOT']."/includes/start.php");
 
-require($_SERVER['DOCUMENT_ROOT']."/includes/start.php");
-?>
-<html>
- <head>
-  <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
- </head>
-<body>
-<?
-echo '<pre>';
+$root=0;
+$all_categs = linker_get_categories_tree_array();
+$all_categs_simple = linker_get_categories_tree_array(-1,true);
+$tree_categs = array();
+$tree_categs = linker_get_category_children($root, $all_categs, 
$tree_categs,1, true);
 
-foreach(linker_get_categories() as $category) {
-  echo "$category\n";
+foreach($tree_categs as $categ){
+  $full_name=$categ['name'];
+  $full_name=linker_get_full_name($categ['id'],$all_categs_simple,$full_name);
+  printf("category\t%d\t%s\n",$categ['id'], html_entity_decode($full_name));
 }
 
-?>
-</body>
-</html>
+
+?>

Propchange: trunk/www/admin/api/fetch_categories.php
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: trunk/www/lib/category.php
URL: 
http://svn.gna.org/viewcvs/phplinker/trunk/www/lib/category.php?rev=461&r1=460&r2=461&view=diff
==============================================================================
--- trunk/www/lib/category.php (original)
+++ trunk/www/lib/category.php Wed May 30 10:44:23 2007
@@ -24,7 +24,7 @@
 ?>
 <?php
 
-function linker_get_categories_tree_array($visible=-1){
+function linker_get_categories_tree_array($visible=-1,$simple=false){
   $tree=array();
 
   $where = 'WHERE 1=1 ';
@@ -43,12 +43,23 @@
                    "SELECT id, id_parent , id_ad_tag, visible, name FROM 
category ".$where." ORDER BY id_parent, name ");
 
   while(list($id, $id_parent , $id_ad_tag, $visible, $name 
)=mysql_fetch_array($result)) {
-    $tree[$id_parent][$id] = array(
-                                  'id_parent' => $id_parent,
-                                  'id_ad_tag' => $id_ad_tag,
-                                  'name' => 
htmlentities(utf8_decode(trim($name))),
-                                  'visible' => $visible,
-                                  );
+    if($simple) {
+      $tree[$id]=array(
+                     'id' => $id,
+                     'id_parent' => $id_parent,
+                     'id_ad_tag' => $id_ad_tag,
+                     'name' => htmlentities(utf8_decode(trim($name))),
+                     'visible' => $visible,
+                     );
+    }else{
+      $tree[$id_parent][$id] = array(
+                                    'id' => $id,
+                                    'id_parent' => $id_parent,
+                                    'id_ad_tag' => $id_ad_tag,
+                                    'name' => 
htmlentities(utf8_decode(trim($name))),
+                                    'visible' => $visible,
+                                    );
+    }
   }
   return $tree;
 }
@@ -90,6 +101,19 @@
     }
   }
   return $array_children;
+}
+
+function 
linker_get_full_name($id_child,$all_categs_simple,$full_name,$recursive=true){
+  $recursion=__FUNCTION__;
+  $id_parent=$all_categs_simple[$id_child]['id_parent'];
+
+   if(isset($all_categs_simple[$id_parent]) && $id_parent>0){
+    $full_name=$all_categs_simple[$id_parent]['name']."/".$full_name;
+    if($recursion){
+      $full_name=$recursion($id_parent,$all_categs_simple,$full_name);
+    }
+   }
+    return $full_name;
 }
 
 function linker_change_parent_category($from, $to){


_______________________________________________
PHPLinker-commits mailing list
[email protected]
https://mail.gna.org/listinfo/phplinker-commits

Reply via email to