Changeset 501

Show
Ignore:
Timestamp:
08/16/08 13:44:17 (3 months ago)
Author:
padams
Message:

adding OFC, sparklines, revamped metrics, revamped db, etc.

Location:
trunk
Files:
96 added
59 modified

Legend:

Unmodified
Added
Removed
  • trunk/modules/base/classes/entityManager.php

    r500 r501  
    6767        } 
    6868         
    69         function _getProperties() { 
    70                  
    71                 $vars = get_object_vars($this->entity); 
    72                  
    73                 $properties = array(); 
    74                  
    75                 foreach ($vars as $k => $v) { 
    76                          
    77                         $properties[$k] = $v->value; 
    78                          
    79                 } 
    80                  
    81                 return $properties;      
    82         } 
    83          
    84         function getColumns() { 
    85                  
    86                 $all_cols = get_object_vars($this->entity); 
    87                  
    88                 return array_keys($all_cols); 
    89                  
     69        /** 
     70         * Create Table 
     71         * 
     72         * Handled by DB abstraction layer because the SQL associated with this is way too DB specific 
     73         */ 
     74        function createTable() { 
     75                 
     76                // Persist table 
     77                $status = $this->db->createTable($this->entity); 
     78                 
     79                if ($status == true): 
     80                        $this->e->notice(sprintf("%s Table Created.", get_class($this->entity))); 
     81                        return true; 
     82                else: 
     83                        $this->e->notice(sprintf("%s Table Creation Failed.", get_class($this->entity))); 
     84                        return false; 
     85                endif; 
     86         
     87        } 
     88         
     89        /** 
     90         * DROP Table 
     91         * 
     92         * Drops a table. will throw error is table does not exist 
     93         */ 
     94        function dropTable() { 
     95                 
     96                // Persist table 
     97                $status = $this->db->dropTable(get_class($this->entity)); 
     98                 
     99                if ($status == true): 
     100                        return true; 
     101                else: 
     102                        return false; 
     103                endif; 
     104         
     105        } 
     106         
     107        function addColumn($column_name) { 
     108                 
     109                // Persist table 
     110                $status = $this->db->addColumn(get_class($this->entity), $column_name, $this->entity->$column_name->getDefinition()); 
     111                 
     112                if ($status == true): 
     113                        return true; 
     114                else: 
     115                        return false; 
     116                endif; 
     117                 
     118        } 
     119         
     120        function dropColumn($column_name) { 
     121                 
     122                $status = $this->db->dropColumn(get_class($this->entity), $column_name); 
     123                 
     124                if ($status == true): 
     125                        return true; 
     126                else: 
     127                        return false; 
     128                endif;           
     129                 
     130        } 
     131         
     132        function modifyColumn($column_name) { 
     133         
     134                $status = $this->db->modifyColumn(get_class($this->entity), $column_name, $this->entity->$column_name->getDefinition()); 
     135                 
     136                if ($status == true): 
     137                        return true; 
     138                else: 
     139                        return false; 
     140                endif;           
     141         
     142         
     143        } 
     144         
     145        function renameColumn($old_column_name, $column_name) { 
     146         
     147                $status = $this->db->renameColumn(get_class($this->entity), $old_column_name, $column_name); 
     148                 
     149                if ($status == true): 
     150                        return true; 
     151                else: 
     152                        return false; 
     153                endif;           
     154                 
     155        } 
     156         
     157        function renameTable($new_table_name) { 
     158         
     159                $status = $this->db->renameTable(get_class($this->entity), $new_table_name); 
     160                 
     161                if ($status == true): 
     162                        return true; 
     163                else: 
     164                        return false; 
     165                endif;           
     166                return; 
    90167        } 
    91168         
     
    99176                 
    100177        } 
    101          
    102         /** 
    103          * Create Table 
    104          * 
    105          * Handled by DB abstraction layer because the SQL associated with this is way too DB specific 
    106          */ 
    107         function createTable() { 
    108                  
    109                 // Persist table 
    110                 $status = $this->db->createTable($this->entity); 
    111                  
    112                 if ($status == true): 
    113                         $this->e->notice(sprintf("%s Table Created.", get_class($this->entity))); 
    114                         return true; 
    115                 else: 
    116                         $this->e->notice(sprintf("%s Table Creation Failed.", get_class($this->entity))); 
    117                         return false; 
    118                 endif; 
    119          
    120         } 
    121          
    122         /** 
    123          * DROP Table 
    124          * 
    125          * Drops a table. will throw error is table does not exist 
    126          */ 
    127         function dropTable() { 
    128                  
    129                 // Persist table 
    130                 $status = $this->db->dropTable(get_class($this->entity)); 
    131                  
    132                 if ($status == true): 
    133                         return true; 
    134                 else: 
    135                         return false; 
    136                 endif; 
    137          
    138         } 
    139          
    140         function addColumn($column_name) { 
    141                  
    142                 // Persist table 
    143                 $status = $this->db->addColumn(get_class($this->entity), $column_name, $this->entity->$column_name->getDefinition()); 
    144                  
    145                 if ($status == true): 
    146                         return true; 
    147                 else: 
    148                         return false; 
    149                 endif; 
    150                  
    151         } 
    152          
    153         function dropColumn($column_name) { 
    154                  
    155                 $status = $this->db->dropColumn(get_class($this->entity), $column_name); 
    156                  
    157                 if ($status == true): 
    158                         return true; 
    159                 else: 
    160                         return false; 
    161                 endif;           
    162                  
    163         } 
    164          
    165         function modifyColumn($column_name) { 
    166          
    167                 $status = $this->db->modifyColumn(get_class($this->entity), $column_name, $this->entity->$column_name->getDefinition()); 
    168                  
    169                 if ($status == true): 
    170                         return true; 
    171                 else: 
    172                         return false; 
    173                 endif;           
    174          
    175          
    176         } 
    177          
    178         function renameColumn($old_column_name, $column_name) { 
    179          
    180                 $status = $this->db->renameColumn(get_class($this->entity), $old_column_name, $column_name); 
    181                  
    182                 if ($status == true): 
    183                         return true; 
    184                 else: 
    185                         return false; 
    186                 endif;           
    187                  
    188         } 
    189          
    190         function renameTable($new_table_name) { 
    191          
    192                 $status = $this->db->renameTable(get_class($this->entity), $new_table_name); 
    193                  
    194                 if ($status == true): 
    195                         return true; 
    196                 else: 
    197                         return false; 
    198                 endif;           
    199                 return; 
    200         } 
    201          
    202          
    203178         
    204179        /** 
     
    225200        } 
    226201         
    227          
    228202        /** 
    229203         * Delete Object 
     
    245219                return $this->entity->getByColumn($col, $value); 
    246220                 
    247         } 
    248          
    249         function find($params = array()) { 
    250                  
    251                  
    252                 $params['primary_obj'] = $this->entity; 
    253                  
    254                 return $this->db->getObjs($params); 
    255                  
    256         } 
    257          
    258         function query($params) { 
    259                  
    260                 $this->params['primary_obj'] = $this->entity; 
    261                  
    262                 if (!empty($params)): 
    263                         return $this->db->selectQuery(array_merge($this->params, $params)); 
    264                 else: 
    265                         return $this->db->selectQuery($this->params); 
    266                 endif; 
    267         } 
    268          
    269          
    270         /** 
    271          * Sets object attributes 
    272          * 
    273          * @param unknown_type $array 
    274          */ 
    275         function setProperties($array) { 
    276                  
    277                 $properties = $this->getColumns(); 
    278                  
    279                 foreach ($properties as $k => $v) { 
    280                                  
    281                                 if (!empty($array[$v])): 
    282                                         $this->entity->$v->value = $array[$v]; 
    283                                 endif; 
    284                                  
    285                         } 
    286                  
    287                 return; 
    288         } 
    289          
    290         function setGuid($string) { 
    291                  
    292                 return owa_lib::setStringGuid($string); 
    293                  
    294         } 
    295          
    296         function set($name, $value) { 
    297                  
    298                 return $this->entity->$name->value = $value; 
    299221        } 
    300222         
     
    305227        function setValues($values) { 
    306228                 
    307                 return $this->setProperties($values); 
    308                  
     229                return $this->entity->setProperties($values); 
     230                 
     231        } 
     232         
     233        /** 
     234         * Sets object attributes 
     235         * 
     236         * @param unknown_type $array 
     237         */ 
     238        function setProperties($array) { 
     239                 
     240                $this->entity->setProperties($array); 
     241                 
     242                return; 
     243        } 
     244         
     245        function set($name, $value) { 
     246                 
     247                return $this->entity->$name->value = $value; 
    309248        } 
    310249         
     
    314253        } 
    315254         
     255        function _getProperties() { 
     256                 
     257                return $this->entity->_getProperties(); 
     258                 
     259        } 
     260         
     261        function getColumns($return_as_string = false, $as_namespace = '', $table_namespace = false) { 
     262                 
     263                return $this->entity->getColumns($return_as_string, $as_namespace, $table_namespace); 
     264                 
     265        } 
     266         
     267        function getColumnsSql($as_namespace = '', $table_namespace = true) { 
     268         
     269                return $this->entity->getColumnsSql($as_namespace, $table_namespace); 
     270 
     271        } 
     272         
     273        /** 
     274         *  
     275         * @depricated 
     276         */ 
     277        function find($params = array()) { 
     278                 
     279                $db = owa_coreAPI::dbSingleton(); 
     280                 
     281                $db->selectFrom(get_class($this->entity), $db->removeNs($this->entity->getTableName())); 
     282                 
     283                $values = $this->entity->getColumns(); 
     284                 
     285                $primary_obj_ns = $db->removeNs(get_class($this->entity)); 
     286                 
     287                foreach ($values as $k => $v) { 
     288                         
     289                        if (empty($params['related_objs'])): 
     290                                $db->selectColumn($v); 
     291                        else: 
     292                                $db->selectColumn($primary_obj_ns.'.'.$v, $primary_obj_ns.'_'.$v); 
     293                        endif; 
     294                         
     295                } 
     296                 
     297                $db->selectFrom(get_class($this->entity), $ns); 
     298 
     299                // add related objects 
     300                if(!empty($params['related_objs'])): 
     301                 
     302                        foreach ($params['related_objs'] as $fk => $v_obj) { 
     303                         
     304                                $values = $v_obj->entity->getColumns(); 
     305                                 
     306                                $ns = $db->removeNs(get_class($v_obj->entity)); 
     307                                 
     308                                foreach ($values as $k_values => $v_values) { 
     309                         
     310                                                $db->selectColumn($ns.'.'.$v_values, $ns.'_'.$v_values); 
     311                                         
     312                                } 
     313                                 
     314                                $for_key = $primary_obj_ns . '.' . $fk; 
     315                                $pk = $ns . '.id'; 
     316                                 
     317                                $db->join(OWA_SQL_JOIN_LEFT_OUTER, get_class($v_obj->entity), $ns, $for_key, $pk); 
     318 
     319                        } 
     320                 
     321                endif; 
     322                 
     323                 
     324  &nb