public function createAction() { $entity = new Project(); $proj = $this->request->getParam("project"); $dev = load_developer_where('name = "' . $this->request->getParam("owner_name") . '"'); if ($dev == null) { //Create the developer if it's not on our database already $dev = new Developer(); $dev->name = $this->request->getParam("owner_name"); $dev->avatar_url = $this->request->getParam("owner_avatar"); save_developer($dev); } else { //Update the avatar if it changed if ($dev->avatar_url != $this->request->getParam("owner_avatar")) { $dev->avatar_url = $this->request->getParam("owner_avatar"); save_developer($dev); } } if (!load_project_where("name = '" . $proj['name'] . "' and owner_id = " . $dev->id)) { $proj['url'] = str_replace("https", "", $proj['url']); $proj['url'] = str_replace("http", "", $proj['url']); $proj['url'] = str_replace("://", "", $proj['url']); $proj['url'] = "http://" . $proj['url']; $proj['owner_id'] = $dev->id; $proj['published'] = 1; $entity->load_from_array($proj); if (save_project($entity)) { //Create the first set of stats $entity->saveInitStats(); $entity->grabHistoricData(); $this->flash->setSuccess("The project was added correctly, thanks!"); $this->redirect_to(project_show_path($entity)); } else { $this->render(array("entity" => $entity), "new"); } } else { $this->flash->setError("This project has already been submited"); $this->render(array("entity" => $entity), "new"); } }
/** Retrieves a list of Project @order = Optional, can be an array of keys or just a single key to order by the results @limit = Optional */ function list_project($order = null, $limit = null, $where = null) { global $__db_conn; $sql = "SELECT * FROM project"; if ($where != null) { $sql .= " WHERE {$where} "; } if ($order != null) { $order_str = $order; if (is_array($order)) { $order_str = implode(",", $order); } $sql .= " order by {$order_str}"; } if ($limit != null) { $sql .= " limit {$limit}"; } Makiavelo::info("== Loading projects:: " . $sql); $result = mysql_query($sql, $__db_conn); if (!$result) { Makiavelo::info("ERROR MYSQL: " . mysql_error() . " - " . $sql); return array(); } $results = array(); while ($row = mysql_fetch_assoc($result)) { $tmp = new Project(); $tmp->load_from_array($row); $results[] = $tmp; } return $results; }