Example #1
0
	public function fetchAllValidations($userId)
	{
		$contactId = $this->userIdToContactId($userId);
		$resultSet = $this->getDbTable()->fetchAllValidations($contactId);
		$entries = array();
		foreach($resultSet as $row){
			$entry = new Pment_Models_Mplan();
			$entry->setPlanId($row->planId)
				->setPlanName($row->planName)
				->setTypeId($row->typeId)
				->setTypeName($row->typeName)
				->setYearNum($row->yearNum)
				->setMonNum($row->monNum)
				->setProjectId($row->projectId)
				->setProjectName($row->name)
				->setPDate($row->pDate)
				->setContactId($row->contactId)
				->setContactName($row->contactName);
			$entries[] = $entry;
			}
		return $entries;
		}
	public function editAction()
	{
		$groupId = $this->getGroupId();
		if($groupId != 3) //for test purpose
		{
			$this->_redirect('/pment/cpp');
			}
		$editForm = new Pment_Forms_MplanSave();
		$editForm->submit->setLabel('保存修改返回');
		$editForm->submit2->setLabel('继续修改材料');

		$mplans = new Pment_Models_MplanMapper();
		$mplans->populateDd($editForm);
		$planId = $this->_getParam('id',0);
		$projectId =$this->getProjectId();
		$editForm = $mplans->formValidator($editForm,1);

		if($this->getRequest()->isPost())
		{
			$formData = $this->getRequest()->getPost();
			$btClicked = $this->getRequest()->getPost('submit');
			if($editForm->isValid($formData))
			{
				$array = $mplans->dataValidator($formData,1);
				$trigger = $array['trigger'];
				$errorMsg = $array['errorMsg'];
				if($trigger == 0)
				{
					$userId = $this->getUserId();
					$users = new System_Models_UserMapper();
					$contactId = $users->getContactId($userId); 
					$mplan = new Pment_Models_Mplan();
					$mplan->setPlanId($planId);
					$mplan->setProjectId($projectId);
					$mplan->setPlanName($editForm->getValue('planName'));
					$mplan->setTypeId($editForm->getValue('typeId'));
					$mplan->setYearNum($editForm->getValue('yearNum'));
					$mplan->setMonNum($editForm->getValue('monNum'));
					$mplan->setPDate($editForm->getValue('pDate'));
					$mplan->setStatus(0);
					$mplan->setContactId($contactId);
					$mplan->setRemark($editForm->getValue('remark'));
					$mplans->save($mplan);
					if($btClicked == '保存修改返回')
					{
						$this->_redirect('/pment/mplan');
						}
						else
						{
							$this->_redirect('/pment/material/index/id/'.$planId);
							}
					}
					else
					{
						$editForm->populate($formData);
						}
			}
			else
				{
					$editForm->populate($formData);
					}
		}
		else
		{
			if($planId >0)
			{
				$arrayMplan = $mplans->findArrayMplan($planId);
				$editForm->populate($arrayMplan);
				}
				else
				{
					$this->_redirect('pment/mplan');
					}
			}
		$this->view->editForm = $editForm;
		$this->view->id = $planId; 
	}