Показать сообщение отдельно

  #7  
Старый 04.02.2009, 04:18
Chrek625
Участник форума
Регистрация: 06.06.2006
Сообщений: 163
Провел на форуме:
1025198

Репутация: 11
По умолчанию

Доброго всем времени суток.
Снова прошу помощи у меня опять возникла проблема с $this.

PHP код:
<?php

include_once("classes/DBManager.php");
include_once(
"PEAR.php");

class 
DBObject {
    var 
$DBManager;
    var 
$__table;
    var 
$__keyColumn;
    var 
$data = array();
    var 
$view;
    var 
$_isLoaded false;
    var 
$_changedColumns = array();

    
/**
    * Constructor
    *
    * Creates a new DBObject
    * if $objectId is specified gets data from database
    *
    * @param    DBManager   &$DBManager instance of DBManager
    * @param    mixed       $objectId   identity of object instance in database
    * @access public
    */
    
function DBObject(&$DBManager$objectId=null) {
        
$this->DBManager =& $DBManager;
        if (
$objectId !== null) {
            
$this->objectId $objectId;
            
$this->get($objectId);
        }
    }

    
/**
    * Gets data of current object from database and put it into class variables
    *
    * @param    mixed       $objectId   identity of object instance in database
    * @access public
    */
    
function get($objectId=null$fieldsArray=array()) {
        if (
$objectId !== null) {
            
$this->objectId $objectId;
        }
        if (
is_array($fieldsArray) and sizeof($fieldsArray)>0) {
                
$fieldList implode(','$fieldsArray);
        } else {
                
$fieldList "*";
        }

        if (isset(
$this->objectId)) {
            
$this->data $this->DBManager->SingleRowQuery("SELECT $fieldList FROM `{$this->__table}` WHERE {$this->__table}.{$this->__keyColumn}='{$this->objectId}'");
            if (
$this->data) {
                
$this->_isLoaded true;
                return 
true;
            }
        }
        return 
false;
    }

    
/**
    * Stores data of current object from class variables into database
    *
    * @access public
    */
    
function insert() {
        if (!isset(
$this->objectId)) {
            
$this->$objectId $this->generateId();   <<-- строчка с ошибкой
        
}
        
$setClause $this->_prepareSetClause();
        if (
strlen($setClause)>0) {
        
$sql "INSERT INTO `{$this->__table}` SET $setClause ";
//        echo "$sql<br>";
            
return $this->DBManager->ExecuteQuery($sql);
        }
        return 
false;
    }

    
/**
    * Updates data of current object from class variables into database
    *
    * @access public
    */
    
function update() {
        if (isset(
$this->objectId)) {
            
$setClause $this->_prepareSetClause();
            if (
strlen($setClause)>0) {
                return 
$this->DBManager->ExecuteQuery("UPDATE `{$this->__table}` SET $setClause WHERE {$this->__table}.{$this->__keyColumn}='{$this->objectId}'");
            }
        }
        return 
false;
    }

    
/**
    * Deletes current object in database and unsets class variables
    *
    * @access public
    */
    
function delete() {
        if (isset(
$this->objectId)) {
            return 
$this->DBManager->ExecuteQuery("DELETE FROM `{$this->__table}` WHERE {$this->__table}.{$this->__keyColumn}='{$this->objectId}'");
        }
        return 
false;
    }

    function 
getVariable($variableName) {
        if (
$variableName) {
            if (
in_array($variableNamearray_keys($this->data))) {
                return 
$this->data[$variableName];
            }
        }
        return 
null;
    }


    function 
setVariable($variableName$variableValue) {
        
$this->_changedColumns[] = $variableName;
        
$this->data[$variableName] = $variableValue;
    }

    function 
increaseVariable($variableName$increaseValue) {
        
$this->setVariable($variableName$this->getVariable($variableName)+$increaseValue);
    }

    function 
decreaseVariable($variableName$decreaseValue) {
        
$this->setVariable($variableName$this->getVariable($variableName)-$decreaseValue);
    }

    function 
removeVariable($variableName) {
        if (
$variableName) {
            if (
in_array($variableNamearray_keys($this->data))) {
                unset(
$this->data[$variableName]);
            }
        }
    }

    function 
isVariableEquals($variableName$value) {
        return (
$this->getVariable($variableName) == $value);
    }

    function 
generateId() {
        
$id '';
        for( 
$i=0;$i<9;$i++ ) {
            
$id .= strval(rand(0,9));
        }
        return 
$id;
    }

    function 
_prepareSetClause() {
        
$setClause '';
        if (
$this->_isLoaded) {
            if (
sizeof($this->_changedColumns)>0) {
                foreach (
$this->_changedColumns as $columnName) {
                    if (
$columnName != $this->__keyColumn and strval(intval($columnName))!=$columnName) {
                        
$setClause .= "{$this->__table}.$columnName = '".mysql_escape_string($this->getVariable($columnName))."',";
                    }
                }
                
$setClause substr($setClause,0,-1);
            }
        } else {
            if (
sizeof($this->data)>0) {
                foreach (
$this->data as $columnName=>$columnValue) {
                    if (
$columnName != $this->__keyColumn and strval(intval($columnName))!=$columnName) {
                        
$setClause .= "{$this->__table}.$columnName = '".mysql_escape_string($columnValue)."',";
                    }
                }
                
$setClause substr($setClause,0,-1);
            }
        }
        return 
$setClause;
    }

    function 
getView($templateFile="index.html") {
//        require_once 'HTML/Template/Flexy.php';
/*        $flexy = new HTML_Template_Flexy();
        if ($flexy->compile($templateFile)===true) {
            $output = $flexy->bufferedOutputObject($this);
        }
        return $output;*/
    
}

    function 
lockTable() {
    return;
    }

    function 
unlockTable() {
    return;
    }
    
    
    function 
getSystemParam($param)
    {
        
$SQLQuery "select $param from system_parameters";
        
$res $this->DBManager->SingleRowQuery($SQLQuery);
        return 
$res[0];
    }
    
    function 
getItemNameField()
    {
        
$lang $this->_app_voc->words['LANG'];
        if (
$lang == 'ENG')
        {
            return 
'name_eng';
        }
        else if (
$lang == 'RUS')
        {
            return 
'name';
        }
        
    }

    function 
getNameField()
    {
        
$lang $this->_app_voc->words['LANG'];
        if (
$lang == 'ENG')   return 'name_eng';
        else if (
$lang == 'RUS')     return 'name_rus';
    }

    function 
getDescrField()
    {
        
$lang $this->_app_voc->words['LANG'];
        if (
$lang == 'ENG')   return 'descr_eng';
        else if (
$lang == 'RUS')     return 'descr_rus';
    }
    
    
    function 
getRaceName($race)
    {
        
$name_field $this->getNameField();
        
$sql "select $name_field from Alignments where al_name = '$race'";
        
$name $this->DBManager->SingleRowQuery($sql);
        return 
$name[0];
    }
    
    function 
_safe_symbol($text)
    {
        
$text str_replace('&'''$text);
        return 
$text;
    }

}

?>
подскажите в чём ошибка в строчке $this->$objectId = $this->generateId();
 
Ответить с цитированием