/** * Update project * * @param void * @return null */ function edit() { $this->wireframe->print_button = false; if ($this->request->isApiCall() && !$this->request->isSubmitted()) { $this->httpError(HTTP_ERR_BAD_REQUEST, null, true, true); } // if if ($this->active_project->isNew()) { $this->httpError(HTTP_ERR_NOT_FOUND); } // if if (!$this->active_project->canEdit($this->logged_user)) { $this->httpError(HTTP_ERR_FORBIDDEN); } // if $project_data = $this->request->post('project'); if (!is_array($project_data)) { $project_data = array('name' => $this->active_project->getName(), 'overview' => $this->active_project->getOverview(), 'default_visibility' => $this->active_project->getDefaultVisibility(), 'leader_id' => $this->active_project->getLeaderId(), 'group_id' => $this->active_project->getGroupId(), 'company_id' => $this->active_project->getCompanyId(), 'default_visibility' => $this->active_project->getDefaultVisibility(), 'starts_on' => $this->active_project->getStartsOn()); } // if $this->smarty->assign('project_data', $project_data); if ($this->request->isSubmitted()) { db_begin_work(); $old_name = $this->active_project->getName(); $this->active_project->setAttributes($project_data); if ($this->active_project->isModified('leader_id') && $this->active_project->getLeaderId()) { $leader = Users::findById($this->active_project->getLeaderId()); if (instance_of($leader, 'User')) { $this->active_project->setLeader($leader); } // if } // if if ($this->active_project->isModified('company_id')) { cache_remove('project_icons'); } // if $save = $this->active_project->save(); if ($save && !is_error($save)) { db_commit(); if ($this->request->isApiCall()) { $this->serveData($this->active_project, 'project'); } else { flash_success('Project :name has been updated', array('name' => $old_name)); $this->redirectToUrl($this->active_project->getOverviewUrl()); } // if } else { db_rollback(); if ($this->request->isApiCall()) { $this->serveData($save); } else { $this->smarty->assign('errors', $save); } // if } // if } // if }
public function testCRUD() { //CREATE Test $newProject = new Project(); $projectName = 'This is a Test'; $newProject->setAttributes(array('name' => $projectName, 'description' => 'This project is for test purpose only', 'start_date' => '2010-11-15 15:00:00', 'end_date' => '2010-12-06 00:00:00', 'update_user_id' => 1, 'category' => 2, 'status' => 1, 'owner' => 1)); $this->assertTrue($newProject->save(false)); //READ Test $readProject = Project::model()->findByPk($newProject->id); $this->assertTrue($readProject instanceof Project); $this->assertEquals($projectName, $readProject->name); //UPDATE Test $updateProjectName = 'Updated Name2'; $newProject->name = $updateProjectName; $this->AssertTrue($newProject->save(false)); $updatedProject = Project::model()->findByPk($newProject->id); $this->assertTrue($updatedProject instanceof Project); $this->assertNotEquals($projectName, $updatedProject->name); //DELETE Test $deletedProjectId = $newProject->id; $newProject->delete(); $deletedProject = Project::model()->findByPk($newProject->id); $this->assertEquals(Null, $deletedProject); //GetUserVote Test $project = Project::model()->findByPk(18); $this->assertTrue($project->getUserVote(7) == true); //Vote Test $this->assertTrue($project->vote(1, 1) == 1); }
public function testCreate() { // CREATE new project $newProject = new Project(); $newProjectName = 'Test Project Creation'; $newProject->setAttributes(array('name' => $newProjectName, 'description' => 'This is a test for new project creation')); Yii::app()->user->setId($this->users('user1')->id); // Save the new project, triggering attribute validation $this->assertTrue($newProject->save()); // READ back the newly created project to ensure the creation worked $retrievedProject = Project::model()->findByPk($newProject->id); $this->assertTrue($retrievedProject instanceof Project); $this->assertEquals($newProjectName, $retrievedProject->name); $this->assertEquals(Yii::app()->user->id, $retrievedProject->create_user_id); }
public function testCreate() { //Create new project $newProject = new Project(); $newProjectName = 'Test Project 1'; $newProject->setAttributes(array('name' => $newProjectName, 'description' => 'Unit test for project creation')); //Set user Yii::app()->user->setID($this->users('user1')->id); $this->assertTrue($newProject->save()); //Read newly created project $retrievedProject = Project::model()->findByPk($newProject->id); $this->assertTrue($retrievedProject instanceof Project); $this->assertEquals($newProjectName, $retrievedProject->name); //Check user $this->assertEquals(Yii::app()->user->id, $retrievedProject->create_user_id); }
public function testCreate() { // Create a new project $newProject = new Project(); $newProjectName = 'Test Project Creation'; $newProject->setAttributes(array('name' => $newProjectName, 'description' => 'This is a test for new project creation')); // Set the application user id to the first user in our fixture data Yii::app()->user->setId($this->users('user1')->id); $this->assertTrue($newProject->save()); // Read back the newly created Project to ensure the creation worked $retrievedProject = Project::model()->findByPk($newProject->id); $this->assertTrue($retrievedProject instanceof Project); $this->assertEquals($newProjectName, $retrievedProject->name); // Ensure the user associated with creating the new project is the same as the application user we set when saving the project $this->assertEquals(Yii::app()->user->id, $retrievedProject->create_user_id); }
public function testCreate() { //CREATE a new Project $newProject=new Project; $newProjectName = 'Test Project Creation'; $newProject->setAttributes(array( 'name' => $newProjectName, 'description' => 'This is a test for new project creation', 'createTime' => '2009-09-09 00:00:00', 'createUser' => '1', 'updateTime' => '2009-09-09 00:00:00', 'updateUser' => '1', ) ); $this->assertTrue($newProject->save(false)); //READ back the newly created Project to ensure the creation worked $retrievedProject=Project::model()->findByPk($newProject->id); $this->assertTrue($retrievedProject instanceof Project); $this->assertEquals($newProjectName,$retrievedProject->name); }
/** * Manages all models. */ public function actionAdmin() { $model = new Project('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['Project'])) { $model->setAttributes($_GET['Project']); } $this->render('admin', array('model' => $model)); }
/** * 保存项目 */ public function save($data = array()) { $oneProject = new Project(); $data['user_id'] = Yii::app()->user->getId(); $oneProject->setAttributes($data); $oneProject->save(); }