<?php

/*

SELECT SUBSTR( o.`namespace`, 1, 11) AS ns_1, t.`name` AS ns_2, o.`name`, o.`value`
FROM `wp_gen_options` o, `wp_terms` t
WHERE o.`namespace` LIKE  'cm-%-opt-%'
AND o.`namespace` NOT LIKE  'cm-%-opt-archive'
AND o.`namespace` NOT LIKE  'cm-%-opt-index'
AND o.`namespace` NOT LIKE  'cm-%-opt-search'

AND t.`term_id` = SUBSTR( o.`namespace`, 12)

ORDER BY o.`namespace`, o.`name`




SELECT `namespace`, `name`, `value`
FROM  `wp_gen_options`
WHERE  `namespace` LIKE  'cm-%-opt-%'
AND ( 0
OR `namespace` LIKE  'cm-%-opt-archive'
OR `namespace` LIKE  'cm-%-opt-index'
OR `namespace` LIKE  'cm-%-opt-search'
)
ORDER BY `namespace`, `name`

*/
  
class dataInstallCategories{

    public $structure;
    public $ids = array();

    function addToWP(){
        $this->addToWPRecursive( 0, $this->structure );
        return $this->structure;
    }
    
    function addToWPRecursive( $parent, &$structure ){
        foreach( $structure as $key=>$settings) {
            $cat_ID = wp_create_term( $settings['title'], 'category');
            $this->ids[ $settings['title'] ] = (int) $cat_ID['term_id'];

            $structure[$key]['ID'] = $cat_ID;
            $structure[$key]['parent'] = $parent;

            if( isSet($structure[$key]['items']) ){
                $this->addToWPRecursive( $cat_ID, $structure[$key]['items'] );
            }
        }
    }

    function __construct(){
        $this->structure = array();
        $this->structure['Blog'] = array( 'title' => 'Blog', );
        $this->structure['Portfolio'] = array( 'title' => 'Portfolio', );
        $this->structure['Portfolio Fullwidth'] = array( 'title' => 'Portfolio Fullwidth', );
    }
}
