ezpersistentobject.php

00001 <?php
00002 //
00003 // Definition of eZPersistentObject class
00004 //
00005 // Created on: <16-Apr-2002 11:08:14 amos>
00006 //
00007 // Copyright (C) 1999-2003 Exponential. All rights reserved.
00008 //
00009 // This source file is part of the Exponential (tm) Open Source Content
00010 // Management System.
00011 //
00012 // This file may be distributed and/or modified under the terms of the
00013 // "GNU General Public License" version 2 as published by the Free
00014 // Software Foundation and appearing in the file LICENSE.GPL included in
00015 // the packaging of this file.
00016 //
00017 // Licencees holding valid "Exponential professional licences" may use this
00018 // file in accordance with the "Exponential professional licence" Agreement
00019 // provided with the Software.
00020 //
00021 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING
00022 // THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00023 // PURPOSE.
00024 //
00025 // The "Exponential professional licence" is available at
00026 // http://ez.no/products/licences/professional/. For pricing of this licence
00027 // please contact us via e-mail to licence@ez.no. Further contact
00028 // information is available at http://ez.no/home/contact/.
00029 //
00030 // The "GNU General Public License" (GPL) is available at
00031 // http://www.gnu.org/copyleft/gpl.html.
00032 //
00033 // Contact licence@ez.no if any conditions of this licencing isn't clear to
00034 // you.
00035 //
00036 
00064 include_once( "lib/ezdb/classes/ezdb.php" );
00065 include_once( "lib/ezutils/classes/eztexttool.php" );
00066 include_once( "lib/ezutils/classes/ezdebug.php" );
00067 
eZPersistentObject
00069 {
eZPersistentObject( $row )
00077     {
00078         $this->PersistentDataDirty = false;
00079         if ( is_numeric( $row ) )
00080             $row =& $this->fetch( $row, false );
00081         $this->fill( $row );
00082     }
00083 
fill( &$row )
00091     {
00092         if ( $row == false )
00093             return;
00094         $def =& $this->definition();
00095         $fields =& $def["fields"];
00096         reset( $fields );
00097         while ( ($key = key( $fields ) ) !== null )
00098         {
00099             $item =& $fields[$key];
00100             $this->$item =& $row[$key];
00101             next( $fields );
00102         }
00103     }
00104 
fetchObject( 
00111                                &$def,
00113                                $field_filters,
00115                                $conds,
00116                                $asObject = true,
00118                                $grouping = null,
00120                                $custom_fields = null )
00121     {
00122         $rows =& eZPersistentObject::fetchObjectList( $def, $field_filters, $conds,
00123                                                       array(), null, $asObject,
00124                                                       $grouping, $custom_fields );
00125         return $rows[0];
00126     }
00127 
remove( $conditions = null, $extraConditions = null )
00136     {
00137         $def =& $this->definition();
00138         $keys =& $def["keys"];
00139         if ( !is_array( $conditions ) )
00140         {
00141             $conditions = array();
00142             foreach ( $keys as $key )
00143             {
00144                 $value =& $this->attribute( $key );
00145                 $conditions[$key] =& $value;
00146             }
00147         }
00148         eZPersistentObject::removeObject( $def, $conditions, $extraConditions );
00149     }
00150 
removeObject( &$def, $conditions = null, $extraConditions = null )
00158     {
00159         $db =& eZDB::instance();
00160 
00161         $table =& $def["name"];
00162         if ( is_array( $extraConditions ) )
00163         {
00164             foreach ( $extraConditions as $key => $cond )
00165             {
00166                 $conditions[$key] = $cond;
00167             }
00168         }
00169         $cond_text = eZPersistentObject::conditionText( $conditions );
00170 
00171         $db->query( "DELETE FROM $table $cond_text" );
00172     }
00173 
store( $fieldFilters = null )
00179     {
00180         eZPersistentObject::storeObject( $this, $fieldFilters );
00181     }
00182 
sync( $fieldFilters = null )
00188     {
00189         if ( $this->hasDirtyData() )
00190             $this->store( $fieldFilters );
00191     }
00192 
storeObject( &$obj, $fieldFilters = null )
00199     {
00200         $db =& eZDB::instance();
00201 
00202         $def =& $obj->definition();
00203         $fields =& $def["fields"];
00204         $keys =& $def["keys"];
00205         $table =& $def["name"];
00206         $relations =& $def["relations"];
00207         $insert_object = false;
00208         $exclude_fields = array();
00209         foreach ( $keys as $key )
00210         {
00211             $value =& $obj->attribute( $key );
00212             if ( is_null( $value ) )
00213             {
00214                 $insert_object = true;
00215                 $exclude_fields[] = $key;
00216             }
00217         }
00218         $key_conds = array();
00219         foreach ( $keys as $key )
00220         {
00221             $value =& $obj->attribute( $key );
00222             $key_conds[$key] = $value;
00223         }
00224         $important_keys = $keys;
00225         if ( is_array( $relations ) )
00226         {
00227             $important_keys = array();
00228             foreach( $relations as $relation => $relation_data )
00229             {
00230                 if ( !in_array( $relation, $keys ) )
00231                     $important_keys[] = $relation;
00232             }
00233         }
00234         if ( !$insert_object and count( $important_keys ) != 1  )
00235         {
00236             $rows =& eZPersistentObject::fetchObjectList( $def, $keys, $key_conds,
00237                                                           array(), null, false,
00238                                                           null, null );
00239             if ( count( $rows ) == 0 )
00240                 $insert_object = true;
00241         }
00242         if ( $insert_object )
00243         {
00244             $use_fields = array_diff( array_keys( $fields ), $exclude_fields );
00245             $field_text = implode( ", ", $use_fields );
00246             $use_values = array();
00247             foreach ( $use_fields as $key )
00248             {
00249                 $value =& $obj->attribute( $key );
00250                 $use_values[] = "'" . $db->escapeString( $value ) . "'";
00251             }
00252             $value_text = implode( ", ", $use_values );
00253             $sql = "INSERT INTO $table ($field_text) VALUES($value_text)";
00254 //             eZDebug::writeNotice( $sql );
00255             $db->query( $sql );
00256 
00257             if ( isset( $def["increment_key"] ) && !($obj->attribute( $def["increment_key"]) > 0) )
00258             {
00259                 $inc =& $def["increment_key"];
00260                 $id = $db->lastSerialID( $table, $inc );
00261                 if ( $id !== false )
00262                     $obj->setAttribute( $inc, $id );
00263             }
00264         }
00265         else
00266         {
00267             $use_fields = array_diff( array_keys( $fields ), $keys );
00268             $field_text = "";
00269             $field_text_len = 0;
00270             $i = 0;
00271             foreach ( $use_fields as $key )
00272             {
00273                 $value =& $obj->attribute( $key );
00274                 $field_text_entry = $key . "='" . $db->escapeString( $value ) . "'";
00275                 $field_text_len += strlen( $field_text_entry );
00276                 $needNewline = false;
00277                 if ( $field_text_len > 60 )
00278                 {
00279                     $needNewline = true;
00280                     $field_text_len = 0;
00281                 }
00282                 if ( $i > 0 )
00283                     $field_text .= "," . ($needNewline ? "\n    " : ' ');
00284                 $field_text .= $field_text_entry;
00285                 ++$i;
00286             }
00287             $cond_text = eZPersistentObject::conditionText( $key_conds );
00288             $sql = "UPDATE $table\nSET $field_text$cond_text";
00289 //             eZDebug::writeNotice( $sql );
00290             $db->query( $sql );
00291         }
00292         $obj->setHasDirtyData( false );
00293     }
00294 
conditionText( &$conditions )
00299     {
00300         $row = null;
00301         return eZPersistentObject::conditionTextByRow( $conditions, $row );
00302     }
00303 
conditionTextByRow( &$conditions, &$row )
00309     {
00310         $db =& eZDB::instance();
00311 
00312         $where_text = "";
00313         if ( is_array( $conditions ) and
00314              count( $conditions ) > 0 )
00315         {
00316             $where_text = "\nWHERE  ";
00317             $i = 0;
00318             foreach ( $conditions as $id => $cond )
00319             {
00320                 if ( $i > 0 )
00321                     $where_text .= " AND ";
00322                 if ( is_array( $row ) )
00323                 {
00324                     $where_text .= $cond . "='" . $db->escapeString( $row[$cond] ) . "'";
00325                 }
00326                 else
00327                 {
00328                     if ( is_array( $cond ) )
00329                     {
00330                         if ( is_array( $cond[0] ) )
00331                         {
00332                             $where_text .= $id . ' IN ( ';
00333                             $j = 0;
00334                             foreach ( $cond[0] as $value )
00335                             {
00336                                 if ( $j > 0 )
00337                                     $where_text .= ", ";
00338                                 $where_text .= "'" . $db->escapeString( $value ) . "'";
00339                                 ++$j;
00340                             }
00341                             $where_text .= ' ) ';
00342                         }
00343                         else if ( is_array( $cond[1] ) )
00344                         {
00345                             $range = $cond[1];
00346                             $where_text .= "$id BETWEEN '" . $range[0] . "' AND '" . $range[1] . "'";
00347                         }
00348                         else
00349                             $where_text .= $id . $cond[0] . "'" . $db->escapeString( $cond[1] ) . "'";
00350                     }
00351                     else
00352                         $where_text .= $id . "='" . $db->escapeString( $cond ) . "'";
00353                 }
00354                 ++$i;
00355             }
00356         }
00357         return $where_text;
00358     }
00359 
00364     function &fetchObjectList( 
00365                                &$def,
00367                                $field_filters = null,
00369                                $conds = null,
00371                                $sorts = null,
00373                                $limit = null,
00374                                $asObject = true,
00376                                $grouping = false,
00378                                $custom_fields = null )
00379     {
00380         $db =& eZDB::instance();
00381         $fields =& $def["fields"];
00382         $table =& $def["name"];
00383         $class_name =& $def["class_name"];
00384         if ( is_array( $field_filters ) )
00385             $field_array = array_unique( array_intersect(
00386                                              $field_filters, array_keys( $fields ) ) );
00387         else
00388             $field_array = array_keys( $fields );
00389         if ( $custom_fields !== null and is_array( $custom_fields ) )
00390         {
00391             foreach( $custom_fields as $custom_field )
00392             {
00393                 $custom_text = $custom_field["operation"];
00394                 if ( isset( $custom_field["name"] ) )
00395                 {
00396                     $field_name =& $custom_field["name"];
00397                     $custom_text .= " AS $field_name";
00398                 }
00399                 $field_array[] = $custom_text;
00400             }
00401         }
00402         $field_text = '';
00403         $i = 0;
00404         foreach ( $field_array as $field_item )
00405         {
00406             if ( ( $i % 7 ) == 0 and
00407                  $i > 0 )
00408                 $field_text .= ",\n       ";
00409             else if ( $i > 0 )
00410                 $field_text .= ', ';
00411             $field_text .= $field_item;
00412             ++$i;
00413         }
00414 
00415         $where_text = eZPersistentObject::conditionText( $conds );
00416         $sort_text = "";
00417         if ( isset( $def["sort"] ) or is_array( $sorts ) )
00418         {
00419             $sort_list =& $def["sort"];
00420             if ( is_array( $sorts ) )
00421                 $sort_list =& $sorts;
00422             if ( count( $sort_list ) > 0 )
00423             {
00424                 $sort_text = "\nORDER BY ";
00425                 $i = 0;
00426                 foreach ( $sort_list as $sort_id => $sort_type )
00427                 {
00428                     if ( $i > 0 )
00429                         $sort_text .= ", ";
00430                     if ( $sort_type == "desc" )
00431                         $sort_text .= "$sort_id DESC";
00432                     else
00433                         $sort_text .= "$sort_id ASC";
00434                     ++$i;
00435                 }
00436             }
00437         }
00438 
00439         $grouping_text = "";
00440         if ( isset( $def["grouping"] ) or ( is_array( $grouping ) and count( $grouping) > 0 ) )
00441         {
00442             $grouping_list =& $def["grouping"];
00443             if ( is_array( $grouping ) )
00444                 $grouping_list =& $grouping;
00445             if ( count( $grouping_list ) > 0 )
00446             {
00447                 $grouping_text = "\nGROUP BY ";
00448                 $i = 0;
00449                 foreach ( $grouping_list as $grouping_id )
00450                 {
00451                     if ( $i > 0 )
00452                         $grouping_text .= ", ";
00453                     $grouping_text .= "$grouping_id";
00454                     ++$i;
00455                 }
00456             }
00457         }
00458 
00459         $db_params = array();
00460         if ( is_array( $limit ) )
00461         {
00462             if ( isset( $limit["offset"] ) )
00463             {
00464                 $db_params["offset"] = $limit["offset"];
00465                 $db_params["limit"] = $limit["length"];
00466             }
00467             else
00468             {
00469                 $db_params["limit"] = $limit["length"];
00470             }
00471         }
00472 
00473         $sqlText = "SELECT $field_text\nFROM   $table" . $where_text . $grouping_text . $sort_text;
00474         $rows =& $db->arrayQuery( $sqlText,
00475                                   $db_params );
00476 
00477         return eZPersistentObject::handleRows( $rows, $class_name, $asObject );
00478     }
00479 
00480     function &handleRows( &$rows, $class_name, $asObject )
00481     {
00482         if ( $asObject )
00483         {
00484             $objects = array();
00485             foreach ( $rows as $row )
00486             {
00487                 $objects[] = new $class_name( $row );
00488             }
00489             return $objects;
00490         }
00491         else
00492             return $rows;
00493     }
00494 
00498     function swapRow( $table, &$keys, &$order_id, &$rows, $id1, $id2 )
00499     {
00500         $db =& eZDB::instance();
00501         $text = $order_id . "='" . $db->escapeString( $rows[$id1][$order_id] ) . "' WHERE ";
00502         $i = 0;
00503         foreach ( $keys as $key )
00504         {
00505             if ( $i > 0 )
00506                 $text .= " AND ";
00507             $text .= $key . "='" . $db->escapeString( $rows[$id2][$key] ) . "'";
00508             ++$i;
00509         }
00510         return "UPDATE $table SET $text";
00511     }
00512 
00518     function newObjectOrder( &$def, $orderField, $conditions )
00519     {
00520         $db =& eZDB::instance();
00521         $table =& $def["name"];
00522         $keys =& $def["keys"];
00523         $cond_text = eZPersistentObject::conditionText( $conditions );
00524         $rows =& $db->arrayQuery( "SELECT MAX($orderField) AS $orderField FROM $table $cond_text" );
00525         if ( count( $rows ) > 0 and isset( $rows[0][$orderField] ) )
00526             return $rows[0][$orderField] + 1;
00527         else
00528             return 1;
00529     }
00530 
00541     function reorderObject( &$def,
00543                             $orderField,
00544                             $conditions,
00545                             $down = true )
00546     {
00547         $db =& eZDB::instance();
00548         $table =& $def["name"];
00549         $keys =& $def["keys"];
00550 
00551         reset( $orderField );
00552         $order_id = key( $orderField );
00553         $order_val = $orderField[$order_id];
00554         if ( $down )
00555         {
00556             $order_operator = ">=";
00557             $order_type = "asc";
00558             $order_add = -1;
00559         }
00560         else
00561         {
00562             $order_operator = "<=";
00563             $order_type = "desc";
00564             $order_add = 1;
00565         }
00566         $fields = array_merge( $keys, array( $order_id ) );
00567         $rows =& eZPersistentObject::fetchObjectList( $def,
00568                                                       $fields,
00569                                                       array_merge( $conditions,
00570                                                                    array( $order_id => array( $order_operator,
00571                                                                                               $order_val ) ) ),
00572                                                       array( $order_id => $order_type ),
00573                                                       array( "length" => 2 ),
00574                                                       false );
00575         if ( count( $rows ) == 2 )
00576         {
00577             $swapSQL1 = eZPersistentObject::swapRow( $table, $keys, $order_id, $rows, 1, 0 );
00578             $swapSQL2 = eZPersistentObject::swapRow( $table, $keys, $order_id, $rows, 0, 1 );
00579 //             eZDebug::writeDebug( $swapSQL1, 'swapSQL1' );
00580 //             eZDebug::writeDebug( $swapSQL2, 'swapSQL2' );
00581             $db->query( $swapSQL1 );
00582             $db->query( $swapSQL2 );
00583         }
00584         else
00585         {
00586             $tmp =& eZPersistentObject::fetchObjectList( $def,
00587                                                          $fields,
00588                                                          $conditions,
00589                                                          array( $order_id => $order_type ),
00590                                                          array( "length" => 1 ),
00591                                                          false );
00592             $where_text = eZPersistentObject::conditionTextByRow( $keys, $rows[0] );
00593             $db->query( "UPDATE $table SET $order_id='" . ( $tmp[0][$order_id] + $order_add ) .
00594                         "'$where_text"  );
00595         }
00596     }
00597 
00633     function &definition()
00634     {
00635         return array();
00636     }
00637 
00638     function &escapeArray( &$array )
00639     {
00640         $db =& eZDB::instance();
00641         $out = array();
00642         foreach( $array as $key => $value )
00643         {
00644             if ( is_array( $value ) )
00645             {
00646                 $tmp = array();
00647                 foreach( $value as $valueItem )
00648                 {
00649                     $tmp[] = $db->escapeString( $valueItem );
00650                 }
00651                 $out[$key] = $tmp;
00652                 unset( $tmp );
00653             }
00654             else
00655                 $out[$key] = $db->escapeString( $value );
00656         }
00657         return $out;
00658     }
00659 
00660     // Too slow
00661 //     function updateObjectList2( $parameters )
00662 //     {
00663 //         $db =& eZDB::instance();
00664 //         $def =& $parameters['definition'];
00665 //         $table =& $def['name'];
00666 //         $fields =& $def['fields'];
00667 //         $keys =& $def['keys'];
00668 
00669 //         $updateFields =& eZPersistentObject::escapeArray( $parameters['update_fields'] );
00670 //         $conditions =& eZPersistentObject::escapeArray( $parameters['conditions'] );
00671 
00672 //         $query = array( 'UPDATE ',
00673 //                         $table,
00674 //                         ' SET ' );
00675 //         $query[] = eZTextTool::arrayAddDelimiter( eZTextTool::arrayElevateKeys( $updateFields, '', "='", "'" ), ', ' );
00676 //         $query[] = ' WHERE ';
00677 //         $conditionArray = array();
00678 //         foreach( $conditions as $conditionKey => $condition )
00679 //         {
00680 //             if ( is_array( $condition ) )
00681 //             {
00682 //                 $conditionArray[] = array( $conditionKey,
00683 //                                            ' IN (',
00684 //                                            eZTextTool::arrayAddDelimiter( $condition, ', ', "'", "'" ),
00685 //                                            ')' );
00686 //             }
00687 //             else
00688 //                 $conditionArray[] = array( $conditionKey,
00689 //                                            "='",
00690 //                                            $condition,
00691 //                                            "'" );
00692 //         }
00693 //         $query[] = eZTextTool::arrayAddDelimiter( $conditionArray, ' AND ' );
00694 //         return implode( '', eZTextTool::arrayFlatten( $query ) );
00695 
00696 //         // UPDATE ez... SET is_enabled='1' WHERE (ID='1' OR ID='2') AND version='0';
00697 //         // UPDATE ez... SET is_enabled='1' WHERE ID IN ('1', '2') AND version='0';
00698 //     }
00699 
00700     function updateObjectList( $parameters )
00701     {
00702         $db =& eZDB::instance();
00703         $def =& $parameters['definition'];
00704         $table =& $def['name'];
00705         $fields =& $def['fields'];
00706         $keys =& $def['keys'];
00707 
00708         $updateFields =& $parameters['update_fields'];
00709         $conditions =& $parameters['conditions'];
00710 
00711         $query = "UPDATE $table SET ";
00712         $i = 0;
00713         foreach( $updateFields as $field => $value )
00714         {
00715             if ( $i > 0 )
00716                 $query .= ', ';
00717             $query .= $field . "='" . $db->escapeString( $value ) . "'";
00718             ++$i;
00719         }
00720         $query .= "\n" . 'WHERE ';
00721         $i = 0;
00722         foreach( $conditions as $conditionKey => $condition )
00723         {
00724             if ( $i > 0 )
00725                 $query .= ' AND ';
00726             if ( is_array( $condition ) )
00727             {
00728                 $query .= $conditionKey . ' IN (';
00729                 $j = 0;
00730                 foreach( $condition as $conditionValue )
00731                 {
00732                     if ( $j > 0 )
00733                         $query .= ', ';
00734                     $query .= "'" . $db->escapeString( $conditionValue ) . "'";
00735                     ++$j;
00736                 }
00737                 $query .= ')';
00738             }
00739             else
00740                 $query .= $conditionKey . "='" . $db->escapeString( $condition ) . "'";
00741             ++$i;
00742         }
00743         $db->query( $query );
00744 
00745         // UPDATE ez... SET is_enabled='1' WHERE (ID='1' OR ID='2') AND version='0';
00746         // UPDATE ez... SET is_enabled='1' WHERE ID IN ('1', '2') AND version='0';
00747     }
00748 
00749     // Slower than #1
00750 //     function updateObjectList3( $parameters )
00751 //     {
00752 //         $db =& eZDB::instance();
00753 //         $def =& $parameters['definition'];
00754 //         $table =& $def['name'];
00755 //         $fields =& $def['fields'];
00756 //         $keys =& $def['keys'];
00757 
00758 //         $updateFields =& eZPersistentObject::escapeArray( $parameters['update_fields'] );
00759 //         $conditions =& eZPersistentObject::escapeArray( $parameters['conditions'] );
00760 
00761 //         $query = array( 'UPDATE ',
00762 //                         $table,
00763 //                         ' SET ' );
00764 //         $i = 0;
00765 //         foreach( $updateFields as $field => $value )
00766 //         {
00767 //             if ( $i > 0 )
00768 //                 $query[] = ', ';
00769 //             $query[] = $field;
00770 //             $query[] = "='";
00771 //             $query[] = $value;
00772 //             $query[] = "'";
00773 //             ++$i;
00774 //         }
00775 //         $query[] = ' WHERE ';
00776 //         $i = 0;
00777 //         foreach( $conditions as $conditionKey => $condition )
00778 //         {
00779 //             if ( $i > 0 )
00780 //                 $query[] = ' AND ';
00781 //             if ( is_array( $condition ) )
00782 //             {
00783 //                 $query[] = $conditionKey;
00784 //                 $query[] = ' IN (';
00785 //                 $j = 0;
00786 //                 foreach( $condition as $conditionValue )
00787 //                 {
00788 //                     if ( $j > 0 )
00789 //                         $query[] = ', ';
00790 //                     $query[] = "'";
00791 //                     $query[] = $conditionValue;
00792 //                     $query[] = "'";
00793 //                     ++$j;
00794 //                 }
00795 //                 $query[] = ')';
00796 //             }
00797 //             else
00798 //             {
00799 //                 $query[] = $conditionKey;
00800 //                 $query[] = "='";
00801 //                 $query[] = $condition;
00802 //                 $query[] = "'";
00803 //             }
00804 //             ++$i;
00805 //         }
00806 //         return implode( '', $query );
00807 
00808 //         // UPDATE ez... SET is_enabled='1' WHERE (ID='1' OR ID='2') AND version='0';
00809 //         // UPDATE ez... SET is_enabled='1' WHERE ID IN ('1', '2') AND version='0';
00810 //     }
00811 
00816     function &attributes()
00817     {
00818         $def =& $this->definition();
00819         $attrs = array_keys( $def["fields"] );
00820         if ( isset( $def["function_attributes"] ) )
00821             $attrs = array_merge( $attrs, array_keys( $def["function_attributes"] ) );
00822         return $attrs;
00823     }
00824 
00828     function hasAttribute( $attr )
00829     {
00830         $def =& $this->definition();
00831         $has_attr = isset( $def["fields"][$attr] );
00832         if ( !$has_attr and isset( $def["function_attributes"] ) )
00833             $has_attr = isset( $def["function_attributes"][$attr] );
00834         return $has_attr;
00835     }
00836 
00841     function &attribute( $attr )
00842     {
00843         $def =& $this->definition();
00844         $fields =& $def["fields"];
00845         $functions =& $def["functions"];
00846         $attr_functions = null;
00847         if ( isset( $def["function_attributes"] ) )
00848             $attr_functions = $def["function_attributes"];
00849         if ( !isset( $fields[$attr] ) )
00850         {
00851             if ( !is_null( $attr_functions ) or
00852                  !isset( $attr_functions[$attr] ) )
00853             {
00854                 eZDebug::writeError( "Undefined attribute '$attr', cannot get",
00855                                      $def['class_name'] );
00856                 return null;
00857             }
00858         }
00859         if ( !is_null( $attr_functions ) and isset( $attr_functions[$attr] ) )
00860         {
00861             $function_name = $attr_functions[$attr];
00862             return $this->$function_name();
00863         }
00864         else if ( isset( $functions[$attr] ) )
00865         {
00866             $function_name = $functions[$attr];
00867             return $this->$function_name();
00868         }
00869         else
00870         {
00871             $attr_name = $fields[$attr];
00872             return $this->$attr_name;
00873         }
00874     }
00875 
00880     function setAttribute( $attr, $val )
00881     {
00882         $def =& $this->definition();
00883         $fields =& $def["fields"];
00884         $functions =& $def["set_functions"];
00885         if ( !isset( $fields[$attr] ) )
00886         {
00887             eZDebug::writeError( "Undefined attribute '$attr', cannot set",
00888                                  $def['class_name'] );
00889             return;
00890         }
00891         if ( isset( $functions[$attr] ) )
00892         {
00893             $function_name = $functions[$attr];
00894             $this->$function_name( $val );
00895         }
00896         else
00897         {
00898             $attr_name = $fields[$attr];
00899             $this->$attr_name = $val;
00900             $this->setHasDirtyData( true );
00901         }
00902     }
00903 
00908     function hasDirtyData()
00909     {
00910         return $this->PersistentDataDirty;
00911     }
00912 
00917     function setHasDirtyData( $hasDirtyData )
00918     {
00919         $this->PersistentDataDirty = $hasDirtyData;
00920     }
00921 
00924     var $PersistentDataDirty;
00925 }
00926 
00927 ?>
 

Exponential