Problems, need help? Have a tip or advice? Post it here.
8 posts Page 1 of 1
@All Couchies,

My folders are generated using the "dynamic_folder".
json.png
json.png (19.07 KiB) Viewed 1794 times



I have the following code to display the folder structure in JSON.

Code: Select all
<?php require_once( '../couch/cms.php' ); ?>
<cms:content_type 'application/json'/>
   <cms:template title='Department JSON' order='101' icon='home' hidden='1 '/>
   <cms:content_type 'application/json'/>
   <cms:set deptId="<cms:gpc 'deptId' method='get' />" />
   <cms:set dept_count='0' scope='global' />
   {
      "department" :
      [
         <cms:folders masterpage='dept-emp.php' order='desc' depth='1'>
         {
            "deptId":"<cms:show k_folder_id />",
            "deptName":"<cms:show k_folder_title />",
            "hasChild":"<cms:if k_folder_totalchildren = '0'>0<cms:else />1</cms:if>",
            "<cms:show k_folder_title />":
            [
               <cms:set sub_dept_count='0' />
               <cms:if k_folder_immediate_children >
               <cms:folders masterpage='dept-emp.php' order='desc' childof=k_folder_name depth='0'>
                  {
                     "deptId":"<cms:show k_folder_id />",
                     "deptName":"<cms:show k_folder_title />",
                     "hasChild":"<cms:if k_folder_totalchildren = '0'>0<cms:else />1</cms:if>",
                     "<cms:show k_folder_title />":
                     [
                        <cms:set sub_sub_dept_count='0' />
                        <cms:if k_folder_immediate_children >
                           <cms:folders masterpage='dept-emp.php' order='desc' childof=k_folder_name depth='1'>
                           {
                              "deptId":"<cms:show k_folder_id />",
                              "deptName":"<cms:show k_folder_title />",
                              "hasChild":"<cms:if k_folder_totalchildren = '0'>0<cms:else />1</cms:if>"
                           }<cms:incr sub_sub_dept_count /><cms:if sub_sub_dept_count!=k_total_folders> , </cms:if>
                           </cms:folders>
                        </cms:if>
                     ]
                  }<cms:incr sub_dept_count /><cms:if sub_dept_count!=k_total_folders> , </cms:if>
               </cms:folders>
            </cms:if>
            ]
         }
         <cms:incr dept_count />
         <cms:if dept_count!=k_total_folders> , </cms:if>
         </cms:folders>
      ]
   }
<?php COUCH::invoke(); ?>


I made the above refering to the post:
viewtopic.php?f=2&t=3112

But I have the following problem. The folders are not outputting as they should.
I have the structure:
Development
- Software Developer
- - Mobile Developer
- - - iPhone Developer


But the JSON is outputted as here. Please see object #5.

Also I was wondering if an N-Depth JSON can be achieved or not, coz the number of department and their child or child-of-child, etc are not defined beforehand.

Regards,
GenXCoders
Image
where innovation meets technology
Why did you decide to keep
depth='1'
?
To select the top level folders.

I also selected depth=0 but then that causes the current problem, which you can see by clicking the "here" link in the original post. The problem is that the departments are getting repeated.
Image
where innovation meets technology
genxcoders wrote: departments are getting repeated.

Then it's probably that we must help couch to understand which k_folder_name is used. It might be taking the very first context and not the immediate parent-tag context.
Before using childof save k_folder_name explicitly to some new variable.
@genxcoders, just like the other post you referred to, could you please post a static piece of valid JSON containing the hierarchical data in the exact format you require?
@KK Sir

I have generated a regular JSON as is required. But where I get stuck is, the number of child-of-child, child-of-(child-of-child), so on is not fixed as I am using dynamic folders.

I am looking for a JSON of this manner:
Code: Select all
{
    "department":
     [
        {
            "deptId": "1",
            "deptName": "Training",
            "hasChild": "1",
            "Training":
            [
                {
                    "deptId": "11",
                    "deptName": "Members",
                    "hasChild": "0",
                    "Members": []
                },
                {
                    "deptId": "12",
                    "deptName": "Department Head",
                    "hasChild": "0",
                    "Department Head": []
                }
            ]
        },
        {
            "deptId": "2",
            "deptName": "Development",
            "hasChild": "1",
            "Training":
            [
                {
                    "deptId": "21",
                    "deptName": "Members",
                    "hasChild": "1",
                    "Members":
                    [
                        {
                             "deptId": "211",
                             "deptName": "Members",
                             "hasChild": "0",
                             "Members": []
                        }
                    ]
                },
                {
                    "deptId": "22",
                    "deptName": "Department Head",
                    "hasChild": "0",
                    "Department Head": []
                }
            ]
        }


as can be seen, whenever the "hasChild" parameter is set to "1" the JSON for all child departments should keep on generating. Also, only top-level departments (folders) should be displayed for each level.

The Keys are:
1. deptId = <cms:show k_folder_id />
2. deptName (i.e. Training, Development, Members, etc.) = <cms:show k_folder_title /> {also, there are repetative department (folder) names}
3. hasChild = <cms:if k_folder_totalchildren = '0'>0<cms:else />1</cms:if>

My requirement is pretty similar to the example here. But in this case the output can be like,
Code: Select all
Countries > States > Cities > Sub-urbs > Districts > Taluka > ... (with no fixed depth)


Regards,
Aashish
Image
where innovation meets technology
@KK Sir...
Bump...
Image
where innovation meets technology
8 posts Page 1 of 1
cron