本文整理汇总了PHP中Project::setAttributes方法的典型用法代码示例。如果您正苦于以下问题:PHP Project::setAttributes方法的具体用法?PHP Project::setAttributes怎么用?PHP Project::setAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Project
的用法示例。
在下文中一共展示了Project::setAttributes方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: edit
/**
* 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
}
示例2: testCRUD
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);
}
示例3: testCreate
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);
}
示例4: testCreate
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);
}
示例5: testCreate
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);
}
示例6: actionAdmin
/**
* 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));
}
示例7: save
/**
* 保存项目
*/
public function save($data = array())
{
$oneProject = new Project();
$data['user_id'] = Yii::app()->user->getId();
$oneProject->setAttributes($data);
$oneProject->save();
}