<?php

    class tematy
    {

        public static $sql_table = 'tematy';        

        public static $own_listing = false;
        public static $own_listing_parse = false;
        public static $own_options = false;
        
        public function __construct()
        {
        }
        
        public static function getList()
        {
            $query = db::$i->q("
            SELECT * 
            FROM `".( self::$sql_table )."` 
            ORDER BY `id` ASC
            " , true );
            
            if( db::$i->rows )
            {
                
                $Tematy = new stdClass;
                $Tematy->Count = db::$i->rows;
                
                while( $item = db::$i->f( $query ) )
                {
                    $Tematy->Items[] = self::parse( $item );
                }
                
                    return $Tematy;
            }
            
                return;
        }
        
        public static function parse( $item )
        {
            return core::object( $item );
        }
        
        /**
         * Pobierz temat
         * @param int $id
         * @return object $Temat
         */
        public static function get( $id )
        {
            if( !$id ) return;
            
            $data = db::$i->row("
            SELECT * 
            FROM `".( self::$sql_table )."` 
            WHERE `id`='".( $id )."'
            ");
            
                return core::object( $data );
        }
        
        public static function add( $request )
        {
            if( empty( $request['nazwa'] ) )
            {
                statement::$i->set( l('Podaj nazwę') , 'danger' );
                return;
            }
            
            $sql = array(
               'nazwa' => esc( $request['nazwa'] )
            );
            
            if( db::$i->insert( self::$sql_table , $sql ) )
            {
                statement::$i->set( 'save' );
                    return true;
            } 
            else 
            {
                statement::$i->set( 'mysql' );
            }
        }
        
        public static function options()
        {
            
        }   
        
        public static function details_parse()
        {
            
        }
        
    }
    
?>