<?php
/**
 * i-doit - Documentation and CMDB solution for IT environments
 *
 * This file is part of the i-doit framework. Modify at your own risk.
 *
 * Please visit http://www.i-doit.com/license for a full copyright and license information.
 *
 * @version     1.10
 * @package     i-doit
 * @author      synetics GmbH
 * @copyright   synetics GmbH
 * @url         http://www.i-doit.com
 * @license     http://www.i-doit.com/license
 */

/**
 * i-doit
 *
 * CMDB Specific category Database Schema
 *
 * @package    i-doit
 * @subpackage CMDB_Categories
 * @author     Dennis Stuecken <dsteucken@i-doit.org>
 * @copyright  synetics GmbH
 * @license    http://www.i-doit.com/license
 */
class isys_cmdb_ui_category_s_database_schema extends isys_cmdb_ui_category_specific
{
    /**
     * @param isys_cmdb_dao_category $catDao
     *
     * @return array|void
     */
    public function process(isys_cmdb_dao_category $catDao)
    {
        $categoryData = $catDao->get_general_data();

        if (empty($categoryData["isys_cats_database_schema_list__title"]))
        {
            $rules["C__CMDB__CATS__DB_SCHEMA__TITLE"]["p_strValue"] = $catDao->get_obj_name_by_id_as_string($_GET[C__CMDB__GET__OBJECT]);
        }
        else
        {
            $rules["C__CMDB__CATS__DB_SCHEMA__TITLE"]["p_strValue"] = $categoryData["isys_cats_database_schema_list__title"];
        } // if

        $rules["C__CMDB__CATS__DB_SCHEMA__RUNS_ON"]["p_strSelectedID"] = $categoryData["isys_connection__isys_obj__id"];

        $instances   = [];
        $instanceDao = isys_cmdb_dao_category_s_database_instance::instance($catDao->get_database_component())->get_data();
        $on          = strtolower(_L("LC__UNIVERSAL__ON"));

        while ($l_row = $instanceDao->get_row())
        {
            $instances[$l_row["isys_obj__id"]] = $l_row["isys_obj__title"] . " " . $on . " " . $catDao->get_obj_name_by_id_as_string($l_row["isys_connection__isys_obj__id"]);
        }

        $rules["C__CMDB__CATS__DB_SCHEMA__RUNS_ON"]["p_arData"]                                                       = $instances;
        $rules["C__CMDB__CATS__DB_SCHEMA__STORAGE_ENGINE"]["p_strValue"]                                              = $categoryData["isys_cats_database_schema_list__storage_engine"];
        $rules["C__CMDB__CAT__COMMENTARY_" . $catDao->get_category_type() . $catDao->get_category_id()]["p_strValue"] = $categoryData["isys_cats_database_schema_list__description"];

        $this->m_template->smarty_tom_add_rules("tom.content.bottom.content", $rules);
    }
}