public function get($query) { $collection = array(); $results = mysql_query($query); while ($row = mysql_fetch_array($results, MYSQL_ASSOC)) { $obj = newObj('Row'); $obj->populate($row); $collection[] = $obj; } return $collection; }
// no id, ad new entity to model $done = newObj('model_' . $modelId)->append($in); if (!$done) { rest_utils::sendResponse($data, 500); } else { rest_utils::sendResponse($data, 201, $done); $tags = http_request::getString('tags'); if ($tags) { tag::set($modelId, $done, $tags); } } } break; case 'put': rest_utils::authenticate(); $in = newObj('entity_' . $modelId)->validate($data->getRequestVars(), sprintf('madr_%s_%s', $data->getMethod(), $modelId)); if (!$in) { rest_utils::sendResponse($data, 400); } $post_vars = $data->getRequestVars(); newObj('model_' . $modelId)->update($in); rest_utils::sendResponse($data, 201, $done); $tags = http_request::getString('tags'); if ($tags) { tag::set($modelId, $post_vars['id'], $tags); } break; case 'delete': rest_utils::sendResponse($data, 501, $done); break; }
function newObject($class, $id = 0) { global $SYS; $bm = getmicrotime(); $fname = session_save_path() . "/coreg2_cache/" . $class . "_" . $SYS["PROJECT"] . ".obj"; if (file_exists($fname) && $SYS["bcompiler_extension"]) { if (!class_exists("Ente_{$class}")) { $fd = fopen($fname, "r"); bcompiler_read($fd); fclose($fd); } $class_name = "Ente_{$class}"; $tmp = new $class_name($class); $tmp->load($id); } else { $tmp = newObj($class); debug("Inicialiando objecto {$id}"); $tmp->load($id); debug("Tiempo de carga de la clase " . (getmicrotime() - $bm) . " s.", "yellow"); $SYS["load_class_time"] += getmicrotime() - $bm; $SYS["total_classes_loaded"]++; if ($SYS["bcompiler_extension"]) { $fd = fopen($fname, "w"); bcompiler_write_header($fd); bcompiler_write_class($fd, "Ente_{$class}"); bcompiler_write_footer($fd); fclose($fd); } } return $tmp; }