TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 12-30-2008, 10:55 PM   #1 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default The Config Class

UPDATE

Heres what I have so far in this config class:

LATEST
PHP Code:
class TalkPHP_Config {

    
// -- Public members -- //
    
public static $configinfo = array();


    
// -- Private members -- //
    
    
private $iSettingID;


    private 
$sSettingname;


    private 
$sSettingvalue;


    
// -- Protected members -- //


    
protected $dbobj;

    
// -- Deprecated
    // protected $query;
    

    
public function __construct($dbObj) {

        if ( 
is_object($dbObj) && $dbObj instanceof DBMysql )
        {
            
$this->dbobj $dbObj;
        } else throw new 
Exception"Database Object failed, error called." );

        
self::grabOptions();

    }

    public function &
option($optionname$optionvalue)
    {

        if ( isset(
$optionname) && isset($optionvalue) )
        {

            
$this->sSettingname  $optionname;
            
$this->sSettingvalue $optionvalue;

        } 
        
        return 
false;

    }

    
/**
     * Create Options
     *
     * @return boolean
     */
    
public function create($optionname$optionvalue)
    {
        
        
$this->sSettingname $optionname;
        
$this->sSettingvalue $optionvalue;
        
        if ( isset(
$this->sSettingname)
        &&  isset(
$this->sSettingvalue) )
        {
            
$this->sSettingname  $this->dbobj->secure($this->sSettingname);
            
$this->sSettingvalue $this->dbobj->secure($this->sSettingvalue);

            
$this->dbobj->exeQuery("INSERT INTO `options` VALUES('','$this->sSettingname','$this->sSettingvalue');");

            return 
true;

        }

        return 
false;

    }

    
/**
     * Remove Options
     *
     * @return boolean
     */
    
public function remove($optionid)
    {
        
        
$this->iSettingID $optionid;

        if ( 
is_numeric($this->iSettingID) )
        {
            
            
$this->dbobj->exeQuery("DELETE FROM `options` WHERE option_id = $this->iSettingID");
            return 
true;
            
        }

        return 
false;
    }

    
/**
     * Edit Options
     *
     * @return boolean
     */
    
public function edit()
    {
        if ( isset(
$this->sSettingname)
        && isset(
$this->sSettingvalue) )
        {
            
$this->sSettingname  $this->dbobj->secure($this->sSettingname);
            
$this->sSettingvalue $this->dbobj->secure($this->sSettingvalue);
            
$name2id self::Name2Id();
            
            
$this->dbobj->exeQuery("UPDATE `options`
            SET `option_name` = '
$this->sSettingname', 
            `option_value` = '
$this->sSettingvalue'
            WHERE option_id = 
$name2id");

            return 
true;

        }
        
        return 
false;
    }

    
/**
     * Grab all the Options
     *
     */
    
private function grabOptions()
    {
        
$options $this->dbobj->exeQuery("SELECT option_id, option_name, option_value FROM `$this->table`");

        if ( 
$options->rows() > )
        {

            while ( 
$options->getFetch(falsetrue) )
            {
                
                
$this->configinfo["$options[option_name]"] = $options[option_value];
                
            }

            return 
true;

        }
        
        return 
false;

    }

    
/**
     * Converts the Name to the Id of the settings
     * 
     * @return int
     */
    
private function Name2Id()
    {

        if ( isset(
$this->sSettingname) )
        {
            
$this->sSettingname $this->dbobj->secure($this->sSettingname);

            
$name2id $this->dbobj->exeQuery("SELECT option_id, option_name FROM `$this->table` WHERE option_name = '$this->sSettingname'");

            if ( 
$name2id->rows() > )
            {
                
$name2id->getFetch(falsetrue);

                return 
$name2id["option_id"];
            }

        } 
//else trigger_error( self::ERR_SETTINGS_NAME_EMPTY,  E_USER_ERROR );

        
return false;
    }


__________________
VillageIdiot can have my babbies ;d

Last edited by Orc : 01-16-2009 at 05:03 AM.
Orc is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Tutorial] How to organize your classes | Part 1 Tanax Advanced PHP Programming 10 03-01-2009 10:08 PM
A Generic Singleton Base Class Theo Advanced PHP Programming 7 08-18-2008 02:25 AM
[Tutorial] Basic tutorial about class basics Tanax Absolute Beginners 14 07-24-2008 01:37 PM
PHP5 Classes A to Z Part 1 quantumkangaroo Advanced PHP Programming 11 04-01-2008 04:21 AM
Tutorial: PHP and OOP, a beginners guide Village Idiot Tips & Tricks 0 09-06-2007 04:23 PM


All times are GMT. The time now is 06:50 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design