Created
November 26, 2014 09:53
-
-
Save bourg-ismael/5d195021178a556b8b8c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* | |
* @param User $user | |
* @param User $admin | |
* @param Questionnaire $questionnaire | |
* @param type $nbCredits | |
* @return type | |
*/ | |
public function createAssessment(User &$user, User $admin, $questionnaires) | |
{ | |
$em = $this->serviceLocator->get('entity-manager'); | |
$productBundleManager = $this->getServiceLocator()->get('application.common.service.productBundle'); | |
$nbCreditsForAll = 0; | |
foreach($questionnaires as $k => $questionnaireId) { | |
$assessmentHydrator = new DoctrineObjectHydrator($em, 'Application\Common\Entity\Assessment'); | |
$questionnaire = $em->getRepository('Application\Common\Entity\Questionnaire')->find($questionnaireId); | |
$nbCreditsForAll += $nbCredits = $productBundleManager->getByQuestionnaireAndCompany($questionnaire, $admin->getCompany())->getCredit(); | |
$assessment = $assessmentHydrator->hydrate([ | |
'user' => $user, | |
'questionnaire' => $questionnaire, | |
'testAdministrator' => $admin, | |
'locale' => $user->getLocale(), | |
'isVisible' => true, | |
'credit' => $nbCredits, | |
'status' => Assessment::TODO_STATUS, | |
'creationDate' => new \DateTime(), | |
'status' => Assessment::TODO_STATUS | |
], | |
new Assessment() | |
); | |
$assessmentReports = new ArrayCollection(); | |
$productBundle = $productBundleManager->getByQuestionnaireAndCompany($questionnaire, $admin); | |
$reports = $productBundle->getReports(); | |
foreach($reports as $report) { | |
$isvisible = ($report->getLabel() === \Application\Common\Entity\Report::FEEDBACKWEB_REPORT_LABEL) ?: false; | |
$assessmentReport = new AssessmentReport(); | |
$assessmentReport->setAssessment($assessment)->setIsVisible($isvisible)->setReport($report); | |
$assessmentReports->add($assessmentReport); | |
} | |
$assessment->addAssessmentReports($assessmentReports); | |
$user->addAssessment($assessment); | |
} | |
$accountManager = $this->getServiceLocator()->get('application.common.service.account'); | |
$accountManager->debitAccount($this->identity()->getCompany()->getAccount(), $nbCreditsForAll); | |
return $assessment; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Catchable fatal error: Argument 2 passed to Application\Common\Service\ProductBundleManager::getByQuestionnaireAndCompany() must be an instance of Application\Common\Entity\Company, instance of Application\Common\Entity\User given, called in /vagrant/module/Application/src/Application/Common/Service/AssessmentManager.php on line 758 and defined in /vagrant/module/Application/src/Application/Common/Service/ProductBundleManager.php on line 37 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment