public function create($data) { $entityManager = $this->getEntityManager(); $user = $this->getUserById($data['userId']); unset($data['userId']); $engineeringPrice = new UserEngineeringPrice(); $engineeringPrice->setData(['user' => $user, 'engineeringcategory' => $entityManager->getReference('\\Common\\Entity\\EngineeringCategory', $data['engineeringcategory']['id']), 'unit' => $entityManager->getReference('\\Common\\Entity\\Unit', $data['unit']['id']), 'price' => $data['price']]); $engineeringPrice->save($entityManager); return new JsonModel(['engineeringPrice' => $engineeringPrice->getData()]); }
public function create($pdata) { error_reporting(E_ALL); ini_set('display_errors', 1); $data = array(); $data['isActive'] = $pdata['isActive']; $data['profileUpdated'] = $pdata['profileUpdated']; $data['city'] = $pdata['city']; $data['currency'] = $pdata['currency']; $data['createdTime'] = new \DateTime('now'); $data['lastLogin'] = new \DateTime('now'); $data['email'] = $pdata['email']; $data['firstName'] = $pdata['firstname']; $data['lastName'] = $pdata['surname']; $data['password'] = $pdata['password']; $data['phone'] = $pdata['phone']; $data['cellphone'] = $pdata['cellphone']; $data['gender'] = $pdata['gender']; $data['comments'] = $pdata['comments']; $data['position'] = $pdata['position']; $data['contracted'] = $pdata['contracted']; $data['name'] = $pdata['name']; $entityManager = $this->getEntityManager(); $data['company_id'] = $entityManager->getRepository('User\\Entity\\Company')->findOneBy(array('id' => $pdata['company'])); $data['country'] = $entityManager->getRepository('User\\Entity\\Country')->findOneBy(array('id' => $pdata['country'])); $data['pm'] = $entityManager->getRepository('User\\Entity\\Staff')->findOneBy(array('id' => $pdata['pm']['id'])); $data['sales'] = $entityManager->getRepository('User\\Entity\\Staff')->findOneBy(array('id' => $pdata['sales']['id'])); $userExist = $entityManager->getRepository('User\\Entity\\User')->findOneBy(array('email' => $pdata['email'])); if ($userExist) { return new JsonModel(['success' => 'failed', 'msg' => '']); } else { $user = new User(); $user->setData($data); $user->save($entityManager); $user->createEmployer($this, $data, $entityManager, $pdata['lang_code']); $employer = $user->getEmployer(); $employer->updateData(array('position' => $pdata['position'], 'company' => $data['company_id'], 'defaultServiceLevel' => $pdata['defaultServiceLevel'], 'comments' => $pdata['comments'], 'contracted' => $pdata['contracted'], 'pm' => $data['pm'], 'name' => $pdata['name'], 'sales' => $data['sales'])); $employer->save($entityManager); $ret_data = $user->getData(); $projectType = array(); // Set Translation Price foreach ($pdata['translationPrices'] as $k => $v) { if (!in_array(1, $projectType)) { $projectType[] = 1; } $translationPrice = array('user' => $user, 'sourceLanguage' => $entityManager->getRepository('User\\Entity\\Language')->findOneBy(array('id' => $v['sourceLanguage']['id'])), 'targetLanguage' => $entityManager->getRepository('User\\Entity\\Language')->findOneBy(array('id' => $v['targetLanguage']['id'])), 'price' => $v['price']); $pTranslationPrice = new UserTranslationPrice(); $pTranslationPrice->setData($translationPrice); $pTranslationPrice->save($entityManager); } // Set Desktop Prices foreach ($pdata['desktopPrices'] as $k => $v) { if ($v['priceMac'] != 0 || $v['priceHourMac'] != 0) { if (!in_array(4, $projectType)) { $projectType[] = 4; } } if ($v['pricePc'] != 0 || $v['priceHourPc'] != 0) { if (!in_array(5, $projectType)) { $projectType[] = 5; } } $desktopPrice = array('user' => $user, 'language' => $entityManager->getRepository('User\\Entity\\Language')->findOneBy(array('id' => $v['language']['id'])), 'software' => $entityManager->getRepository('User\\Entity\\DesktopSoftware')->findOneBy(array('id' => $v['language']['id'])), 'priceMac' => $v['priceMac'], 'pricePc' => $v['pricePc'], 'priceHourMac' => $v['priceHourMac'], 'priceHourPc' => $v['priceHourPc']); $pDesktopPrice = new UserDesktopPrice(); $pDesktopPrice->setData($desktopPrice); $pDesktopPrice->save($entityManager); } // Set Interpreting Price foreach ($pdata['interpretingPrices'] as $k => $v) { if (!in_array(7, $projectType)) { $projectType[] = 7; $projectType[] = 8; $projectType[] = 9; $projectType[] = 10; } $interpretingPrice = array('user' => $user, 'sourceLanguage' => $entityManager->getRepository('User\\Entity\\Language')->findOneBy(array('id' => $v['sourceLanguage']['id'])), 'targetLanguage' => $entityManager->getRepository('User\\Entity\\Language')->findOneBy(array('id' => $v['targetLanguage']['id'])), 'service' => $entityManager->getRepository('User\\Entity\\InterpretingService')->findOneBy(array('id' => $v['service']['id'])), 'priceDay' => $v['priceDay'], 'priceHalfDay' => $v['priceHalfDay']); $pInterpretingPrice = new UserInterpretingPrice(); $pInterpretingPrice->setData($interpretingPrice); $pInterpretingPrice->save($entityManager); } // Set TM Ratio if ($pdata['tmRatio'] != null) { if (!in_array(2, $projectType)) { $projectType[] = 2; } } $pTmRatio = new UserTmRatio(); $tmRatio = array('repetitions' => $pdata['tmRatio']['repetitions'], 'yibai' => $pdata['tmRatio']['yibai'], 'jiuwu' => $pdata['tmRatio']['jiuwu'], 'bawu' => $pdata['tmRatio']['bawu'], 'qiwu' => $pdata['tmRatio']['qiwu'], 'wushi' => $pdata['tmRatio']['wushi'], 'nomatch' => $pdata['tmRatio']['nomatch'], 'user' => $user); $pTmRatio->setData($tmRatio); $pTmRatio->save($entityManager); // Set Engineering Price foreach ($pdata['engineeringPrices'] as $k => $v) { if ($pdata['tmRatio'] != null) { if (!in_array(6, $projectType)) { $projectType[] = 6; } } $engineeringPrice = array('engineeringcategory' => $entityManager->getRepository('Common\\Entity\\EngineeringCategory')->findOneBy(array('id' => $v['engineeringcategory']['id'])), 'unit' => $entityManager->getRepository('Common\\Entity\\Unit')->findOneBy(array('id' => $v['unit']['id'])), 'price' => $v['price'], 'user' => $user); $pEngineeringPrices = new UserEngineeringPrice(); $pEngineeringPrices->setData($engineeringPrice); $pEngineeringPrices->save($entityManager); } $user->setData(array('types' => $projectType)); $user->save($entityManager); //var_dump($projectType); exit; return new JsonModel(['user' => $ret_data, 'success' => 'success']); } }