public function projectAction() { $image_model = new ImageModel(); $project_model = new ProjectModel(); $contribution_model = new ContributionModel(); $active_projects = $project_model->getActive(); //Build thumbs array from active projects $thumbs = array(); foreach ($active_projects as $project) { $thumbs[] = $image_model->getPrimary($project['id']); } $this->view->thumbs = $thumbs; $project_id = $this->_request->getParam('id'); $view_id = $this->_request->getParam('view'); if ($this->is_ajax) { $project_id = $_POST['id']; } if (!$project_id) { $thumbs = reset($thumbs); $project_id = $thumbs['project_id']; } $this->project = $project_model->getOne($project_id); $this->project['description'] = stripslashes($this->project['description']); $this->project['contributions'] = $contribution_model->getOne($project_id); $this->project['images'] = $image_model->getAll($project_id); //If the view is set, loop through the images and find the file_name that matches if (isset($view_id)) { foreach ($this->project['images'] as $image) { if ($image['id'] == $view_id) { $this->project['view'] = $image['file_name']; } } } else { //Else just assume the first file_name $this->project['view'] = $this->project['images']['image1']['file_name']; } if ($this->is_ajax) { $this->_helper->json($this->project); } $this->view->project = $this->project; }
public function updateAction() { if (!isset($this->admin_session->user)) { header("Location: /"); } $project_model = new ProjectModel(); $contributions_model = new ContributionModel(); $project_id = array($this->_request->getParam('id')); $update = array($_POST['title'], $_POST['description'], $_POST['url'], $_POST['status']); $contributions = explode(", ", $_POST['contributions']); $contributions_model->deleteAll($project_id[0]); if ($project_id && !empty($contributions)) { foreach ($contributions as $contribution) { $contributions_model->addOne($project_id, array($contribution)); } } $success = $project_model->updateOne($project_id, $update); header("Location: /admin/projects"); }