public function process($data) { if ($this->isValid($data) !== true) { throw new C3op_Form_ReceivableCreateException('Invalid data!'); } else { $db = Zend_Registry::get('db'); $receivableMapper = new C3op_Projects_ReceivableMapper($db); $predictedDate = $this->predictedDate->GetValue(); $dateValidator = new C3op_Util_ValidDate(); if ($dateValidator->isValid($predictedDate)) { $converter = new C3op_Util_DateConverter(); $dateForMysql = $converter->convertDateToMySQLFormat($predictedDate); $predictedDateConvertedToMySQL = $dateForMysql; } $realDate = $this->realDate->GetValue(); $dateValidator = new C3op_Util_ValidDate(); if ($dateValidator->isValid($realDate)) { $converter = new C3op_Util_DateConverter(); $dateForMysql = $converter->convertDateToMySQLFormat($realDate); $realDateConvertedToMySQL = $dateForMysql; $receivable->SetRealDate($realDateConvertedToMySQL); } $receivable = new C3op_Projects_Receivable($this->project->GetValue(), $predictedDateConvertedToMySQL, $this->predictedValue->GetValue()); $receivable->SetTitle($this->title->GetValue()); $receivable->SetProject((double) $this->project->GetValue()); $receivable->SetRealValue((double) $this->realValue->GetValue()); $receivableMapper->insert($receivable); } }
public function process($data) { $db = Zend_Registry::get('db'); $actionMapper = new C3op_Projects_ActionMapper($db); if ($this->isValid($data) !== true) { throw new C3op_Form_ActionEditException('Invalid data!'); } else { $id = $data['id']; $action = $actionMapper->findById($id); $action->SetTitle($data['title']); $action->SetProject($data['project']); $action->SetStatus($data['status']); $action->SetDescription($data['description']); $action->SetSubordinatedTo($data['subordinatedTo']); $action->SetResponsible($data['responsible']); $action->SetMilestone($data['milestone']); $action->SetRequirementForReceiving($data['requirementForReceiving']); $predictedBeginDate = $data['predictedBeginDate']; $dateValidator = new C3op_Util_ValidDate(); if ($dateValidator->isValid($predictedBeginDate)) { $converter = new C3op_Util_DateConverter(); $dateForMysql = $converter->convertDateToMySQLFormat($predictedBeginDate); $action->SetPredictedBeginDate($dateForMysql); } $predictedFinishDate = $data['predictedFinishDate']; $dateValidator = new C3op_Util_ValidDate(); if ($dateValidator->isValid($predictedFinishDate)) { $converter = new C3op_Util_DateConverter(); $dateForMysql = $converter->convertDateToMySQLFormat($predictedFinishDate); $action->SetPredictedFinishDate($dateForMysql); } $actionMapper->update($action); return $id; } }
private function prepareDateValueToSet($value, C3op_Util_ValidDate $validator, C3op_Util_DateConverter $converter) { if ($validator->isValid($value)) { return $converter->convertDateToMySQLFormat($value); } else { return ""; } }
public function process($data) { if ($this->isValid($data) !== true) { throw new C3op_Form_HumanResourceCreateException('Invalid data!'); } else { $db = Zend_Registry::get('db'); $humanResourceMapper = new C3op_Projects_HumanResourceMapper($db); $humanResource = $humanResourceMapper->findById($this->id->GetValue()); $actionMapper = new C3op_Projects_ActionMapper($this->db); $itsAction = $actionMapper->findById($humanResource->GetAction()); $weHaveThedates = true; $predictedBeginDate = $this->predictedBeginDate->GetValue(); $dateValidator = new C3op_Util_ValidDate(); if ($dateValidator->isValid($predictedBeginDate)) { $converter = new C3op_Util_DateConverter(); $newBeginDate = $converter->convertDateToMySQLFormat($predictedBeginDate); } else { $weHaveThedates = false; } $predictedFinishDate = $this->predictedFinishDate->GetValue(); $dateValidator = new C3op_Util_ValidDate(); if ($dateValidator->isValid($predictedFinishDate)) { $converter = new C3op_Util_DateConverter(); $newFinishDate = $converter->convertDateToMySQLFormat($predictedFinishDate); } else { $weHaveThedates = false; } if (!$weHaveThedates) { throw new C3op_Form_HumanResourceCreateException('É obrigatório informar as datas contratadas.'); } $formerPredictedBeginDate = $itsAction->GetPredictedBeginDate(); $formerPredictedFinishDate = $itsAction->GetPredictedFinishDate(); $dateChanged = false; if ($dateValidator->isValid($formerPredictedBeginDate) && $formerPredictedBeginDate != $newBeginDate) { $dateChanged = true; } if ($dateValidator->isValid($formerPredictedFinishDate) && $formerPredictedFinishDate != $newFinishDate) { $dateChanged = true; } $observation = $this->observation->GetValue(); if ($dateChanged && $observation == "") { throw new C3op_Form_HumanResourceCreateException('Mudanças de data devem ser justificadas.'); } else { C3op_Projects_HumanResourceContracting::ContactContract($itsAction, $humanResource, $humanResourceMapper); if ($observation != "" && $itsAction->GetPredictedBeginDate() != $newBeginDate) { C3op_Projects_ActionDateChange::ChangePredictedBeginDate($itsAction, $actionMapper, $newBeginDate, $observation); } if ($observation != "" && $itsAction->GetPredictedFinishDate() != $newFinishDate) { C3op_Projects_ActionDateChange::ChangePredictedFinishDate($itsAction, $actionMapper, $newFinishDate, $observation); } $actionMapper->update($itsAction); $humanResourceMapper->update($humanResource); return $humanResource->GetId(); } } }
public function testTryingToConvertBadDateRaiseError() { $converter = new C3op_Util_DateConverter(); $invalidDate = "30-30-2003"; $this->setExpectedException('C3op_Util_DateException'); $date = $converter->convertDateToMySQLFormat($invalidDate); $invalidDate = "an7yth4ing3"; $this->setExpectedException('C3op_Util_DateException'); $date = $converter->convertDateToMySQLFormat($invalidDate); }
public function process($data) { if ($this->isValid($data) !== true) { throw new C3op_Form_ActionCreateException('Invalid data!'); } else { $db = Zend_Registry::get('db'); $actionMapper = new C3op_Projects_ActionMapper($db); $action = new C3op_Projects_Action($this->project->GetValue()); // $action->SetTitle($this->title->GetValue()); $action->SetTitle($data['title']); $action->SetStatus(C3op_Projects_ActionStatusConstants::STATUS_PLAN); $action->SetDescription($this->description->GetValue()); $predictedBeginDate = $this->predictedBeginDate->GetValue(); $dateValidator = new C3op_Util_ValidDate(); if ($dateValidator->isValid($predictedBeginDate)) { $converter = new C3op_Util_DateConverter(); $dateForMysql = $converter->convertDateToMySQLFormat($predictedBeginDate); $action->SetPredictedBeginDate($dateForMysql); } $predictedFinishDate = $this->predictedFinishDate->GetValue(); $dateValidator = new C3op_Util_ValidDate(); if ($dateValidator->isValid($predictedFinishDate)) { $converter = new C3op_Util_DateConverter(); $dateForMysql = $converter->convertDateToMySQLFormat($predictedFinishDate); $action->SetPredictedFinishDate($dateForMysql); } $action->SetSubordinatedTo($this->subordinatedTo->GetValue()); $action->SetResponsible($this->responsible->GetValue()); $milestone = $this->milestone->GetValue(); if ($milestone == '1') { $action->SetMilestone(1); } else { $action->SetMilestone(0); } $requirementForReceiving = $this->requirementForReceiving->GetValue(); if ($requirementForReceiving == '1') { $action->SetRequirementForReceiving(1); } else { $action->SetRequirementForReceiving(0); } $actionMapper->insert($action); return $action->getId(); } }
public function process($data) { if ($this->isValid($data) !== true) { throw new C3op_Form_OutlayCreateException('Invalid data!'); } else { $db = Zend_Registry::get('db'); $outlayMapper = new C3op_Projects_OutlayMapper($db); $outlay = new C3op_Projects_Outlay($this->humanResource->GetValue()); $outlay->SetAction($this->action->GetValue()); $outlay->SetProject($this->project->GetValue()); $outlay->SetPredictedValue($this->predictedValue->GetValue()); $predictedDate = $this->predictedDate->GetValue(); $dateValidator = new C3op_Util_ValidDate(); if ($dateValidator->isValid($predictedDate)) { $converter = new C3op_Util_DateConverter(); $dateForMysql = $converter->convertDateToMySQLFormat($predictedDate); $outlay->SetPredictedDate($dateForMysql); } $outlay->SetObservation($this->observation->GetValue()); $outlayMapper->insert($outlay); } }
public function process($data) { if ($this->isValid($data) !== true) { throw new C3op_Form_ProjectCreateException('Invalid data!'); } else { $db = Zend_Registry::get('db'); $projectMapper = new C3op_Projects_ProjectMapper($db); $project = new C3op_Projects_Project(); $project->SetTitle($this->title->GetValue()); $project->SetClient($this->client->GetValue()); $project->SetOurResponsible($this->ourResponsible->GetValue()); $project->SetResponsibleAtClient($this->responsibleAtClient->GetValue()); $beginDate = $this->beginDate->GetValue(); $dateValidator = new C3op_Util_ValidDate(); if ($dateValidator->isValid($beginDate)) { $converter = new C3op_Util_DateConverter(); $dateForMysql = $converter->convertDateToMySQLFormat($beginDate); $project->SetBeginDate($dateForMysql); } $finishDate = $this->finishDate->GetValue(); $dateValidator = new C3op_Util_ValidDate(); if ($dateValidator->isValid($finishDate)) { $converter = new C3op_Util_DateConverter(); $dateForMysql = $converter->convertDateToMySQLFormat($finishDate); $project->SetFinishDate($dateForMysql); } $project->SetValue($this->value->GetValue()); $project->SetStatus($this->status->GetValue()); $project->SetContractNature($this->contractNature->GetValue()); $project->SetAreaActivity($this->areaActivity->GetValue()); $project->SetOverhead($this->overhead->GetValue()); $project->SetManagementFee($this->managementFee->GetValue()); $project->SetObject($this->object->GetValue()); $project->SetSummary($this->summary->GetValue()); $project->SetObservation($this->observation->GetValue()); $projectMapper->insert($project); } }
public function testThatIsPossibleToChangeABeginDate() { $titleInserted = 'HOHOHO a project inserted to try to change date'; $dateBeginAtFirst = "25-12-2011"; $p = new C3op_Projects_Project(); $p->SetTitle($titleInserted); class_exists('C3op_Util_ValidDate') || (require APPLICATION_PATH . "/../library/C3op/Util/validDate.php"); $dateConverter = new C3op_Util_DateConverter(); $p->SetDateBegin($dateConverter->convertDateToMySQLFormat($dateBeginAtFirst)); $this->projectMapper->insert($p); $this->inserts[$p->getId()] = array('p' => $p, 'persistence' => false); $id = $p->getId(); $p2 = $this->projectMapper->findById($id); $newDate = "2012-05-01"; $p2->SetDateBegin($newDate); $this->assertEquals($p->getDateBegin(), $newDate); }