| 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; |
| 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 | | |
| 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; |
| | 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 | if(!empty($params['constraints'])): |
| | 325 | foreach ($params['constraints'] as $k_con => $v_con) { |
| | 326 | |
| | 327 | if (is_array($v_con)): |
| | 328 | $db->where($k_con, $v_con['value'], $v_con['operator']); |
| | 329 | else: |
| | 330 | $db->where($k_con, $v_con); |
| | 331 | endif; |
| | 332 | } |
| | 333 | endif; |
| | 334 | |
| | 335 | return $db->getAllRows(); |
| | 336 | |
| | 337 | } |
| | 338 | |
| | 339 | /** |
| | 340 | * |
| | 341 | * @depricated |
| | 342 | */ |
| | 343 | function query($params) { |
| | 344 | |
| | 345 | $db = owa_coreAPI::dbSingleton(); |
| | 346 | |
| | 347 | $primary_obj_ns = $db->removeNs(get_class($this->entity)); |
| | 348 | |
| | 349 | if (!empty($params)): |
| | 350 | if (!empty($this->params)): |
| | 351 | $params = array_merge($this->params, $params); |
| | 352 | endif; |
| | 353 | endif; |
| | 354 | |
| | 355 | // construct FROM |
| | 356 | $db->selectFrom(get_class($this->entity), $db->removeNs($this->entity->getTableName())); |
| | 357 | $db->selectColumn($params['select']); |
| | 358 | $pns = $db->removeNs($this->entity->getTableName()); |
| | 359 | // add related objects |
| | 360 | if(!empty($params['related_objs'])): |
| | 361 | |
| | 362 | foreach ($params['related_objs'] as $fk => $v_obj) { |
| | 363 | |
| | 364 | //$values = $v_obj->entity->getColumns(); |
| | 365 | |
| | 366 | $ns = $db->removeNs(get_class($v_obj->entity)); |
| | 367 | |
| | 368 | //foreach ($values as $k_values => $v_values) { |
| | 369 | |
| | 370 | // $db->selectColumn($ns.'.'.$v_values, $ns.'_'.$v_values); |
| | 371 | |
| | 372 | //} |
| | 373 | |
| | 374 | $for_key = $primary_obj_ns . '.' . $fk; |
| | 375 | $pk = $ns . '.id'; |
| | 376 | |
| | 377 | $db->join(OWA_SQL_JOIN_LEFT_OUTER, get_class($v_obj->entity), $ns, $for_key, $pk); |
| | 378 | |
| | 379 | } |
| | 380 | |
| | 381 | endif; |
| | 382 | |
| | 383 | |
| | 384 | |
| | 385 | if(!empty($params['constraints'])): |
| | 386 | foreach ($params['constraints'] as $k_con => $v_con) { |
| | 387 | |
| | 388 | $db->where($k_con, $v_con['value'], $v_con['operator']); |
| | 389 | |
| | 390 | } |
| | 391 | endif; |
| | 392 | |
| | 393 | // construct GROUP BY |
| | 394 | |
| | 395 | if(!empty($params['groupby'])): |
| | 396 | |
| | 397 | if (is_array($params['groupby'])): |
| | 398 | |
| | 399 | foreach ($params['groupby'] as $groupby) { |
| | 400 | |
| | 401 | $db->groupBy($groupby); |
| | 402 | |
| | 403 | } |
| | 404 | else: |
| | 405 | $db->groupBy($params['groupby']); |
| | 406 | endif; |
| | 407 | |
| | 408 | endif; |
| | 409 | |
| | 410 | // construct ORDER |
| | 411 | |
| | 412 | if(!empty($params['orderby'])): |
| | 413 | |
| | 414 | if (is_array($params['orderby'])): |
| | 415 | |
| | 416 | foreach ($params['orderby'] as $orderby) { |
| | 417 | |
| | 418 | $db->groupBy($orderby); |
| | 419 | |
| | 420 | } |
| | 421 | else: |
| | 422 | $db->orderBy($params['groupby']); |
| | 423 | endif; |
| | 424 | |
| | 425 | endif; |
| | 426 | |
| | 427 | if(!empty($params['order'])): |
| | 428 | $db->order($params['order']); |
| | 429 | endif; |
| | 430 | |
| | 431 | // construct LIMIT |
| | 432 | |
| | 433 | if(!empty($params['limit'])): |
| | 434 | $db->limit($params['order']); |
| | 435 | endif; |
| | 436 | |
| | 437 | // construct OFFSET |
| | 438 | |
| | 439 | if(!empty($params['offset'])): |
| | 440 | $db->offset($params['offset']); |
| | 441 | endif; |
| | 442 | |
| | 443 | if(!empty($params['result_format'])): |
| | 444 | $db->setFormat($params['result_format']); |
| | 445 | endif; |
| | 446 | |
| | 447 | return $db->getAllRows(); |
| | 448 | |
| | 449 | |
| | 450 | |
| | 451 | } |
| | 452 | |
| | 453 | /** |
| | 454 | * |
| | 455 | * @depricated |
| | 456 | */ |