protected function execute(InputInterface $input, OutputInterface $output) { $manager = $this->getContainer()->get('doctrine')->getManager(); $creationDate = new \DateTime(); $creationDate->setTimezone(new \DateTimeZone('UTC')); /* * ********************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE TEST DATA INSERTION PART STARTS HERE |||| THE TEST DATA INSERTION PART STARTS HERE * FIRST WE CHECK / MAKE SURE THE TEST USER IS ADDED IN THE DATABASE. * * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ if ($input->getOption('add')) { $number = $input->getArgument('number'); //CHECK THE EXISTENCE OF THE TEST USER. //IF EXISTS , USE HIM //IF NOT EXIST , CREATE AND USE HIM. $user = $manager->getRepository('UserBundle:User')->findOneByUsername('test_user_1_test'); if ($user) { $output->writeln('Using existing test user from database. ( ApiKey = testuser1 )'); } else { $user = new User(); $user->setUsername('test_user_1_test'); $user->setApiKey('testuser1'); $user->setEmail('*****@*****.**'); $user->setPassword(md5('password')); $user->setEnabled(true); $user->setCreatedAt($creationDate); $user->setUpdatedAt($creationDate); $user->addRole('ROLE_VIEWER'); $manager->persist($user); $manager->flush(); $output->writeln(' '); $output->writeln('Testuser was missing so it has been added. (ApiKey = testuser1 )'); } // WE MUST CHECK THAT THE USER ALREADY HAS ACCESS TO THIS REGION || COUNTRY COMBINATIONS $accessclient = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever'); $access1_country = $manager->getRepository('CampaignBundle:Country')->findOneByName('USA'); $access1_region = $access1_country->getRegion(); $access2_region = $manager->getRepository('CampaignBundle:Region')->find(2); $already_has_access_to_Unilever_USA = $manager->getRepository('CampaignBundle:Useraccess')->findOneBy(['user' => $user, 'client' => $accessclient, 'country' => $access1_country, 'all_countries' => false]); $already_has_access_to_Unilever_ASIA_PACIFIC_REGION = $manager->getRepository('CampaignBundle:Useraccess')->findOneBy(['user' => $user, 'client' => $accessclient, 'region' => $access2_region, 'all_countries' => true]); //If not already exist , add the access //If not already exist , add the access if ($already_has_access_to_Unilever_USA) { $output->writeln('Test user already has access to Unilever country USA , proceeding further.'); } else { $access1 = new Useraccess(); $access1->setUser($user); $access1->setClient($accessclient); $access1->setRegion($access1_region); $access1->setCountry($access1_country); $access1->setAllCountries(FALSE); $manager->persist($access1); $output->writeln('Test user has been granted access to client Unilever country USA, proceeding.'); } if ($already_has_access_to_Unilever_ASIA_PACIFIC_REGION) { $output->writeln('Test user already has access to Unilever region ASIA PACIFIC , proceeding further.'); } else { $access2 = new Useraccess(); $access2->setUser($user); $access2->setClient($accessclient); $access2->setRegion($access2_region); $access2->setAllCountries(TRUE); $manager->persist($access2); $output->writeln('Test user has been granted access to client Unilever region ASIA PACIFIC, proceeding.'); } $manager->flush(); $output->writeln(' '); //End adding of the access //End adding of the access $campaign_creator = $manager->getRepository('UserBundle:User')->find(5); switch ($number) { /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE FIRST CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = USA , STATUS = BUILD. * * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ case 1: //FIND THE CAMPAIGN , IF UNABLE TO FIND IT , CREATE IT ! $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('USA'); $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever'); $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(1); $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status]); if ($campaign) { $existing_campaign_name = $campaign->getName(); $existing_campaign_id = $campaign->getId(); $output->writeln('A campaign for this specs already exists. '); $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id); $output->writeln('It is not the case to add another duplicate of this.'); } else { $campaign = new Campaign(); $campaign_key = Uuid::uuid4()->toString(); $campaign->setId($campaign_key); $campaign->setName('Case1.Client=Unilever.Country=USA.Status=Build'); $campaign->setCampaignstatus($status); $campaign->setCountry($country); $product = $manager->getRepository('CampaignBundle:Product')->find(25); $campaign->setProduct($product); $productline = $product->getProductline(); $campaign->setProductline($productline); $brand = $productline->getBrand(); $campaign->setBrand($brand); $division = $brand->getDivision(); $campaign->setDivision($division); $client = $division->getClient(); $campaign->setClient($client); $campaign->setCampaignidea('ninecampaignstest'); // $campaign_creator = $manager->getRepository('UserBundle:User')->find(5); $campaign->setUser($campaign_creator); $campaign->setClientPresentation(true); $campaign->setNotVisible(false); $campaign->setCompleteness(0); $campaign->setCreatedAt($creationDate); $campaign->setUpdatedAt($creationDate); $data = new \DateTime(); $timestamp = $data->getTimestamp(); $completion_min_days = 1; $completion_max_days = 15; $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400); $random_completion_timestamp = $timestamp + $random_completion_time; $rand_completion_timestamp_object = new \DateTime(); $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp); $deliverable_min_days = 15; $deliverable_max_days = 30; $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400); $random_deliverable_timestamp = $timestamp + $random_deliverable_time; $random_deliverable_timestamp_object = new \DateTime(); $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp); $campaign->setClientDeliverabledate($random_deliverable_timestamp_object); $campaign->setCompletionDate($rand_completion_timestamp_object); $manager->persist($campaign); $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($campaign_creator); $teammember->setIsReviewer(false); $manager->persist($teammember); $manager->flush(); $output->writeln(' '); $output->writeln('Created a Campaign with following combination Case1.Client=Unilever.Country=USA.Status=Build'); //ADD THE TASKS FOR THIS CAMPAIGN //Fetch all the task types $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll(); //Fetch the default task status $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1); //For each task type , add to this campaign foreach ($task_types as $tasktype) { $new_task = new Task(); $new_task->setCampaign($campaign); $new_task->setTaskname($tasktype); $new_task->setOwner($campaign_creator); $new_task->setTaskmessage(NULL); $new_task->setMatrixfileversion(0); $new_task->setTaskstatus($default_task_status); $new_task->setPhase($tasktype->getPhaseid()); $new_task->setCreatedAt($creationDate); $new_task->setCreatedby($campaign_creator); $new_task->setUpdatedAt($creationDate); $manager->persist($new_task); } $output->writeln(' '); $output->writeln('Created the tasks for the campaign ' . $campaign->getName()); $output->writeln(' '); } /// END ADD TASKS FOR THIS CAMPAIGN //VERIFY USER IS IN THIS CAMPAIGN'S TEAM $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]); if ($is_teammember) { $output->writeln('The user is already set as a teammember for this campaign.'); } else { $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($user); $teammember->setIsReviewer(true); $manager->persist($teammember); $manager->flush(); $output->writeln('The test user has been added as a normal teammember for this campaign. He is NOT reviewer.'); $output->writeln(' '); } //IF NOT , ADD HIM TO THIS CAMPAIGN ONLY AS A TEAMMEMBER $output->writeln('This case should work as intended. All data is availlable.'); $output->writeln(' '); break; /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE SECOND CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = USA , STATUS = APPROVED. * * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE SECOND CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = USA , STATUS = APPROVED. * * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ case 2: //CAMPAIGN2 IS where test user is taskowner for at least 2 tasks //and the campaign_status is approved. Clien is still Unilever and Country = USA $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('USA'); $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever'); $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(2); $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status]); if ($campaign) { $existing_campaign_name = $campaign->getName(); $existing_campaign_id = $campaign->getId(); $output->writeln('A campaign for this specs already exists. '); $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id); $output->writeln('It is not the case to add another duplicate of this.'); } else { $campaign = new Campaign(); $campaign_key = Uuid::uuid4()->toString(); $campaign->setId($campaign_key); $campaign->setName('Case2.Client=Unilever.Country=USA.Status=Approved'); $campaign->setCampaignstatus($status); $campaign->setCountry($country); $product = $manager->getRepository('CampaignBundle:Product')->find(25); $campaign->setProduct($product); $productline = $product->getProductline(); $campaign->setProductline($productline); $brand = $productline->getBrand(); $campaign->setBrand($brand); $division = $brand->getDivision(); $campaign->setDivision($division); $client = $division->getClient(); $campaign->setClient($client); $campaign->setCampaignidea('ninecampaignstest'); // $campaign_creator = $manager->getRepository('UserBundle:User')->find(5); $campaign->setUser($campaign_creator); $campaign->setClientPresentation(true); $campaign->setNotVisible(false); $campaign->setCompleteness(0); $campaign->setCreatedAt($creationDate); $campaign->setUpdatedAt($creationDate); $data = new \DateTime(); $timestamp = $data->getTimestamp(); $completion_min_days = 1; $completion_max_days = 15; $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400); $random_completion_timestamp = $timestamp + $random_completion_time; $rand_completion_timestamp_object = new \DateTime(); $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp); $deliverable_min_days = 15; $deliverable_max_days = 30; $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400); $random_deliverable_timestamp = $timestamp + $random_deliverable_time; $random_deliverable_timestamp_object = new \DateTime(); $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp); $campaign->setClientDeliverabledate($random_deliverable_timestamp_object); $campaign->setCompletionDate($rand_completion_timestamp_object); $manager->persist($campaign); $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($campaign_creator); $teammember->setIsReviewer(false); $manager->persist($teammember); $manager->flush(); $output->writeln(' '); $output->writeln('Created a Campaign with following combination Case2.Client=Unilever.Country=USA.Status=Approved'); //ADD THE TASKS FOR THIS CAMPAIGN //Fetch all the task types $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll(); //Fetch the default task status $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1); //For each task type , add to this campaign foreach ($task_types as $tasktype) { $new_task = new Task(); $new_task->setCampaign($campaign); $new_task->setTaskname($tasktype); $new_task->setOwner($campaign_creator); $new_task->setTaskmessage(NULL); $new_task->setMatrixfileversion(0); $new_task->setTaskstatus($default_task_status); $new_task->setPhase($tasktype->getPhaseid()); $new_task->setCreatedAt($creationDate); $new_task->setCreatedby($campaign_creator); $new_task->setUpdatedAt($creationDate); $manager->persist($new_task); } $output->writeln(' '); $output->writeln('Created the tasks for the campaign ' . $campaign->getName()); $output->writeln(' '); } //VERIFY USER IS IN THIS CAMPAIGN'S TEAM $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]); if ($is_teammember) { $output->writeln('The user is already set as a teammember for this campaign.'); } else { $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($user); $teammember->setIsReviewer(false); $manager->persist($teammember); $output->writeln('The test user has been added as a normal teammember for this campaign.'); $output->writeln(' '); } $manager->flush(); //Randomly assign the user as a taskowner for at leat two tasks. $random_ids = array(); $random_number_of_tasks = 6; for ($i = 2; $i < $random_number_of_tasks; $i++) { $random_ids[] = rand(1, 9); } $unique_random_ids = array_unique($random_ids); $all_tasks_of_this_campaign = $manager->getRepository('TaskBundle:Task')->findByCampaign($campaign->getId()); foreach ($all_tasks_of_this_campaign as $task) { $task->setOwner(NULL); if (in_array($task->getTaskname()->getId(), $unique_random_ids)) { ///ADD SET THIS TASK TO HAVE THE OWNER THE TEST USER. $task->setOwner($user); $output->writeln($user->getUsername() . ' has been set as a taskowner for task ' . $task->getTaskname()->getName()); } $manager->persist($task); } $manager->flush(); break; /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE THIRD CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = COMPLETED. * * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE THIRD CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = COMPLETED. * * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ case 3: //CAMPAIGN3 IS where test user is taskowner for at least 1 tasks //and the campaign_status is COMPLETE . Clien is still Unilever and Country = CHINA $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('China'); $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever'); $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(3); $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status]); if ($campaign) { $existing_campaign_name = $campaign->getName(); $existing_campaign_id = $campaign->getId(); $output->writeln('A campaign for this specs already exists. [case 3] '); $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id); $output->writeln('It is not the case to add another duplicate of this.'); } else { $campaign = new Campaign(); $campaign_key = Uuid::uuid4()->toString(); $campaign->setId($campaign_key); $campaign->setName('Case3.Client=Unilever.Country=China.Status=Completed'); $campaign->setCampaignstatus($status); $campaign->setCountry($country); $product = $manager->getRepository('CampaignBundle:Product')->find(25); $campaign->setProduct($product); $productline = $product->getProductline(); $campaign->setProductline($productline); $brand = $productline->getBrand(); $campaign->setBrand($brand); $division = $brand->getDivision(); $campaign->setDivision($division); $client = $division->getClient(); $campaign->setClient($client); $campaign->setCampaignidea('ninecampaignstest'); // $campaign_creator = $manager->getRepository('UserBundle:User')->find(5); $campaign->setUser($campaign_creator); $campaign->setClientPresentation(true); $campaign->setNotVisible(false); $campaign->setCompleteness(0); $campaign->setCreatedAt($creationDate); $campaign->setUpdatedAt($creationDate); $data = new \DateTime(); $timestamp = $data->getTimestamp(); $completion_min_days = 1; $completion_max_days = 15; $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400); $random_completion_timestamp = $timestamp + $random_completion_time; $rand_completion_timestamp_object = new \DateTime(); $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp); $deliverable_min_days = 15; $deliverable_max_days = 30; $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400); $random_deliverable_timestamp = $timestamp + $random_deliverable_time; $random_deliverable_timestamp_object = new \DateTime(); $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp); $campaign->setClientDeliverabledate($random_deliverable_timestamp_object); $campaign->setCompletionDate($rand_completion_timestamp_object); $manager->persist($campaign); $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($campaign_creator); $teammember->setIsReviewer(false); $manager->persist($teammember); $manager->flush(); $output->writeln(' '); $output->writeln('Created a Campaign with following combination Case3.Client=Unilever.Country=China.Status=Completed'); //ADD THE TASKS FOR THIS CAMPAIGN //Fetch all the task types $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll(); //Fetch the default task status $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1); //For each task type , add to this campaign foreach ($task_types as $tasktype) { $new_task = new Task(); $new_task->setCampaign($campaign); $new_task->setTaskname($tasktype); $new_task->setOwner($campaign_creator); $new_task->setTaskmessage(NULL); $new_task->setMatrixfileversion(0); $new_task->setTaskstatus($default_task_status); $new_task->setPhase($tasktype->getPhaseid()); $new_task->setCreatedAt($creationDate); $new_task->setCreatedby($campaign_creator); $new_task->setUpdatedAt($creationDate); $manager->persist($new_task); } $output->writeln(' '); $output->writeln('Created the tasks for the campaign ' . $campaign->getName()); $output->writeln(' '); } //VERIFY USER IS IN THIS CAMPAIGN'S TEAM $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]); if ($is_teammember) { $output->writeln('The user is already set as a teammember for this campaign.'); } else { $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($user); $teammember->setIsReviewer(false); $manager->persist($teammember); $output->writeln('The test user has been added as a normal teammember for this campaign.'); $output->writeln(' '); } $manager->flush(); //Randomly assign the user as a taskowner for at leat two tasks. $random_ids = array(); $random_number_of_tasks = 6; for ($i = 2; $i < $random_number_of_tasks; $i++) { $random_ids[] = rand(1, 9); } $unique_random_ids = array_unique($random_ids); $all_tasks_of_this_campaign = $manager->getRepository('TaskBundle:Task')->findByCampaign($campaign->getId()); foreach ($all_tasks_of_this_campaign as $task) { $task->setOwner(NULL); if (in_array($task->getTaskname()->getId(), $unique_random_ids)) { ///ADD SET THIS TASK TO HAVE THE OWNER THE TEST USER. $task->setOwner($user); $output->writeln($user->getUsername() . ' has been set as a taskowner for task ' . $task->getTaskname()->getName()); } $manager->persist($task); } $manager->flush(); break; /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE FOURTH CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = CANCELLED. * The test user is a taskowner for at least 1 task * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE FOURTH CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = CANCELLED. * The test user is a taskowner for at least 1 task * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ case 4: $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('China'); $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever'); $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(4); $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status]); if ($campaign) { $existing_campaign_name = $campaign->getName(); $existing_campaign_id = $campaign->getId(); $output->writeln('A campaign for this specs already exists. [case 4] '); $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id); $output->writeln('It is not the case to add another duplicate of this.'); } else { $campaign = new Campaign(); $campaign_key = Uuid::uuid4()->toString(); $campaign->setId($campaign_key); $campaign->setName('Case4.Client=Unilever.Country=China.Status=Cancelled'); $campaign->setCampaignstatus($status); $campaign->setCountry($country); $product = $manager->getRepository('CampaignBundle:Product')->find(25); $campaign->setProduct($product); $productline = $product->getProductline(); $campaign->setProductline($productline); $brand = $productline->getBrand(); $campaign->setBrand($brand); $division = $brand->getDivision(); $campaign->setDivision($division); $client = $division->getClient(); $campaign->setClient($client); $campaign->setCampaignidea('ninecampaignstest'); // $campaign_creator = $manager->getRepository('UserBundle:User')->find(5); $campaign->setUser($campaign_creator); for ($i = 1; $i < 50; $i++) { print_r($campaign_creator->getUsername()); } $campaign->setClientPresentation(true); $campaign->setNotVisible(false); $campaign->setCompleteness(0); $campaign->setCreatedAt($creationDate); $campaign->setUpdatedAt($creationDate); $data = new \DateTime(); $timestamp = $data->getTimestamp(); $completion_min_days = 1; $completion_max_days = 15; $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400); $random_completion_timestamp = $timestamp + $random_completion_time; $rand_completion_timestamp_object = new \DateTime(); $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp); $deliverable_min_days = 15; $deliverable_max_days = 30; $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400); $random_deliverable_timestamp = $timestamp + $random_deliverable_time; $random_deliverable_timestamp_object = new \DateTime(); $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp); $campaign->setClientDeliverabledate($random_deliverable_timestamp_object); $campaign->setCompletionDate($rand_completion_timestamp_object); $manager->persist($campaign); $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($campaign_creator); $teammember->setIsReviewer(false); $manager->persist($teammember); $manager->flush(); $output->writeln(' '); $output->writeln('Created a Campaign with following combination Case4.Client=Unilever.Country=China.Status=Cancelled'); //ADD THE TASKS FOR THIS CAMPAIGN //Fetch all the task types $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll(); //Fetch the default task status $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1); //For each task type , add to this campaign foreach ($task_types as $tasktype) { $new_task = new Task(); $new_task->setCampaign($campaign); $new_task->setTaskname($tasktype); $new_task->setOwner($campaign_creator); $new_task->setTaskmessage(NULL); $new_task->setMatrixfileversion(0); $new_task->setTaskstatus($default_task_status); $new_task->setPhase($tasktype->getPhaseid()); $new_task->setCreatedAt($creationDate); $new_task->setCreatedby($campaign_creator); $new_task->setUpdatedAt($creationDate); $manager->persist($new_task); } $output->writeln(' '); $output->writeln('Created the tasks for the campaign ' . $campaign->getName()); $output->writeln(' '); } //VERIFY USER IS IN THIS CAMPAIGN'S TEAM $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]); if ($is_teammember) { $output->writeln('The user is already set as a teammember for this campaign.'); } else { $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($user); $teammember->setIsReviewer(false); $manager->persist($teammember); $output->writeln('The test user has been added as a normal teammember for this campaign.'); $output->writeln(' '); } $manager->flush(); //Randomly assign the user as a taskowner for at leat two tasks. $random_ids = array(); $random_number_of_tasks = 6; for ($i = 2; $i < $random_number_of_tasks; $i++) { $random_ids[] = rand(1, 9); } $unique_random_ids = array_unique($random_ids); $all_tasks_of_this_campaign = $manager->getRepository('TaskBundle:Task')->findByCampaign($campaign->getId()); foreach ($all_tasks_of_this_campaign as $task) { $task->setOwner(NULL); if (in_array($task->getTaskname()->getId(), $unique_random_ids)) { ///ADD SET THIS TASK TO HAVE THE OWNER THE TEST USER. $task->setOwner($user); $output->writeln($user->getUsername() . ' has been set as a taskowner for task ' . $task->getTaskname()->getName()); } $manager->persist($task); } $manager->flush(); break; /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE FIFTH CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = BUILD. * THE TEST USER IS IN THE CAMPAIGN'S TEAM , BUT HE IS NOT REVIEWER , AND NOT OWNER OF ANY TASK. * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE FIFTH CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = BUILD. * THE TEST USER IS IN THE CAMPAIGN'S TEAM , BUT HE IS NOT REVIEWER , AND NOT OWNER OF ANY TASK. * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ case 5: $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('China'); $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever'); $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(1); $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status, 'name' => 'Case5.Client=Unilever.Country=China.Status=Build']); if ($campaign) { $existing_campaign_name = $campaign->getName(); $existing_campaign_id = $campaign->getId(); $output->writeln('A campaign for this specs already exists. [case 5] '); $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id); $output->writeln('It is not the case to add another duplicate of this.'); } else { $campaign = new Campaign(); $campaign_key = Uuid::uuid4()->toString(); $campaign->setId($campaign_key); $campaign->setName('Case5.Client=Unilever.Country=China.Status=Build'); $campaign->setCampaignstatus($status); $campaign->setCountry($country); $product = $manager->getRepository('CampaignBundle:Product')->find(25); $campaign->setProduct($product); $productline = $product->getProductline(); $campaign->setProductline($productline); $brand = $productline->getBrand(); $campaign->setBrand($brand); $division = $brand->getDivision(); $campaign->setDivision($division); $client = $division->getClient(); $campaign->setClient($client); $campaign->setCampaignidea('ninecampaignstest'); // $campaign_creator = $manager->getRepository('UserBundle:User')->find(5); $campaign->setUser($campaign_creator); $campaign->setClientPresentation(true); $campaign->setNotVisible(false); $campaign->setCompleteness(0); $campaign->setCreatedAt($creationDate); $campaign->setUpdatedAt($creationDate); $data = new \DateTime(); $timestamp = $data->getTimestamp(); $completion_min_days = 1; $completion_max_days = 15; $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400); $random_completion_timestamp = $timestamp + $random_completion_time; $rand_completion_timestamp_object = new \DateTime(); $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp); $deliverable_min_days = 15; $deliverable_max_days = 30; $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400); $random_deliverable_timestamp = $timestamp + $random_deliverable_time; $random_deliverable_timestamp_object = new \DateTime(); $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp); $campaign->setClientDeliverabledate($random_deliverable_timestamp_object); $campaign->setCompletionDate($rand_completion_timestamp_object); $manager->persist($campaign); $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($campaign_creator); $teammember->setIsReviewer(false); $manager->persist($teammember); $manager->flush(); $output->writeln(' '); $output->writeln('Created a Campaign with following combination Case5.Client=Unilever.Country=China.Status=Build'); //ADD THE TASKS FOR THIS CAMPAIGN //Fetch all the task types $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll(); //Fetch the default task status $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1); //For each task type , add to this campaign foreach ($task_types as $tasktype) { $new_task = new Task(); $new_task->setCampaign($campaign); $new_task->setTaskname($tasktype); $new_task->setOwner($campaign_creator); $new_task->setTaskmessage(NULL); $new_task->setMatrixfileversion(0); $new_task->setTaskstatus($default_task_status); $new_task->setPhase($tasktype->getPhaseid()); $new_task->setCreatedAt($creationDate); $new_task->setCreatedby($campaign_creator); $new_task->setUpdatedAt($creationDate); $manager->persist($new_task); } $output->writeln(' '); $output->writeln('Created the tasks for the campaign ' . $campaign->getName()); $output->writeln(' '); } //VERIFY USER IS IN THIS CAMPAIGN'S TEAM $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]); if ($is_teammember) { $output->writeln('The user is already set as a teammember for this campaign.'); } else { $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($user); $teammember->setIsReviewer(false); $manager->persist($teammember); $output->writeln('The test user has been added as a normal teammember for this campaign.'); $output->writeln(' '); } $manager->flush(); $output->writeln('In this campaign , the user is NOT reviewer , and does not own any task.'); $output->writeln(' '); break; /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE SIXTH CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = COMPLETED. * TEST USER IS NOT REVIEWER NOT TASK OWNER * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE SIXTH CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = CHINA , STATUS = COMPLETED. * TEST USER IS NOT REVIEWER NOT TASK OWNER * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ case 6: $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('China'); $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever'); $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(4); $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status, 'name' => 'Case6.Client=Unilever.Country=China.Status=Cancelled']); if ($campaign) { $existing_campaign_name = $campaign->getName(); $existing_campaign_id = $campaign->getId(); $output->writeln('A campaign for this specs already exists. [case 6] '); $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id); $output->writeln('It is not the case to add another duplicate of this.'); } else { $campaign = new Campaign(); $campaign_key = Uuid::uuid4()->toString(); $campaign->setId($campaign_key); $campaign->setName('Case6.Client=Unilever.Country=China.Status=Cancelled'); $campaign->setCampaignstatus($status); $campaign->setCountry($country); $product = $manager->getRepository('CampaignBundle:Product')->find(25); $campaign->setProduct($product); $productline = $product->getProductline(); $campaign->setProductline($productline); $brand = $productline->getBrand(); $campaign->setBrand($brand); $division = $brand->getDivision(); $campaign->setDivision($division); $client = $division->getClient(); $campaign->setClient($client); $campaign->setCampaignidea('ninecampaignstest'); // $campaign_creator = $manager->getRepository('UserBundle:User')->find(5); $campaign->setUser($campaign_creator); $campaign->setClientPresentation(true); $campaign->setNotVisible(false); $campaign->setCompleteness(0); $campaign->setCreatedAt($creationDate); $campaign->setUpdatedAt($creationDate); $data = new \DateTime(); $timestamp = $data->getTimestamp(); $completion_min_days = 1; $completion_max_days = 15; $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400); $random_completion_timestamp = $timestamp + $random_completion_time; $rand_completion_timestamp_object = new \DateTime(); $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp); $deliverable_min_days = 15; $deliverable_max_days = 30; $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400); $random_deliverable_timestamp = $timestamp + $random_deliverable_time; $random_deliverable_timestamp_object = new \DateTime(); $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp); $campaign->setClientDeliverabledate($random_deliverable_timestamp_object); $campaign->setCompletionDate($rand_completion_timestamp_object); $manager->persist($campaign); $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($campaign_creator); $teammember->setIsReviewer(false); $manager->persist($teammember); $manager->flush(); $output->writeln(' '); $output->writeln('Created a Campaign with following combination Case6.Client=Unilever.Country=China.Status=Cancelled'); //ADD THE TASKS FOR THIS CAMPAIGN //Fetch all the task types $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll(); //Fetch the default task status $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1); //For each task type , add to this campaign foreach ($task_types as $tasktype) { $new_task = new Task(); $new_task->setCampaign($campaign); $new_task->setTaskname($tasktype); $new_task->setOwner($campaign_creator); $new_task->setTaskmessage(NULL); $new_task->setMatrixfileversion(0); $new_task->setTaskstatus($default_task_status); $new_task->setPhase($tasktype->getPhaseid()); $new_task->setCreatedAt($creationDate); $new_task->setCreatedby($campaign_creator); $new_task->setUpdatedAt($creationDate); $manager->persist($new_task); } $output->writeln(' '); $output->writeln('Created the tasks for the campaign ' . $campaign->getName()); $output->writeln(' '); } //VERIFY USER IS IN THIS CAMPAIGN'S TEAM $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]); if ($is_teammember) { $output->writeln('The user is already set as a teammember for this campaign.'); } else { $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($user); $teammember->setIsReviewer(false); $manager->persist($teammember); $output->writeln('The test user has been added as a normal teammember for this campaign.'); $output->writeln(' '); } $manager->flush(); break; /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE SEVENTH CAMPAIGN CASE * CLIENT = testclientforcase7 , COUNTRY = CHINA , STATUS = CANCELLED. * * This test data should be just like case 6 , the difference is only the CLIENT ID. using client with name "testclientforcase7" * * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE SEVENTH CAMPAIGN CASE * CLIENT = testclientforcase7 , COUNTRY = CHINA , STATUS = CANCELLED. * * This test data should be just like case 6 , the difference is only the CLIENT ID. using client with name "testclientforcase7" * * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ case 7: $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('China'); $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('testclientforcase7'); if ($client) { $output->writeln('Found testclientforcase7 in the database. Proceeding..'); } else { $client = new Client(); $client->setName('testclientforcase7'); $client->setDbid(0); $client->setCreatedAt($creationDate); $client->setUpdatedAt($creationDate); $manager->persist($client); $output->writeln('A new client , testclientforcase7 has been addeed. Proceeding...'); $manager->flush(); } $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(4); $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['name' => 'Case7.Client=testclientforcase7.Country=China.Status=Cancelled']); if ($campaign) { $existing_campaign_name = $campaign->getName(); $existing_campaign_id = $campaign->getId(); $output->writeln('A campaign for this specs already exists. [case 7] '); $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id); $output->writeln('It is not the case to add another duplicate of this.'); } else { $campaign = new Campaign(); $campaign_key = Uuid::uuid4()->toString(); $campaign->setId($campaign_key); $campaign->setName('Case7.Client=testclientforcase7.Country=China.Status=Cancelled'); $campaign->setCampaignstatus($status); $campaign->setCountry($country); $product = $manager->getRepository('CampaignBundle:Product')->find(25); $campaign->setProduct($product); $productline = $product->getProductline(); $campaign->setProductline($productline); $brand = $productline->getBrand(); $campaign->setBrand($brand); $division = $brand->getDivision(); $campaign->setDivision($division); $client = $division->getClient(); $campaign->setClient($client); $campaign->setCampaignidea('ninecampaignstest'); // $campaign_creator = $manager->getRepository('UserBundle:User')->find(5); $campaign->setUser($campaign_creator); $campaign->setClientPresentation(true); $campaign->setNotVisible(false); $campaign->setCompleteness(0); $campaign->setCreatedAt($creationDate); $campaign->setUpdatedAt($creationDate); $data = new \DateTime(); $timestamp = $data->getTimestamp(); $completion_min_days = 1; $completion_max_days = 15; $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400); $random_completion_timestamp = $timestamp + $random_completion_time; $rand_completion_timestamp_object = new \DateTime(); $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp); $deliverable_min_days = 15; $deliverable_max_days = 30; $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400); $random_deliverable_timestamp = $timestamp + $random_deliverable_time; $random_deliverable_timestamp_object = new \DateTime(); $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp); $campaign->setClientDeliverabledate($random_deliverable_timestamp_object); $campaign->setCompletionDate($rand_completion_timestamp_object); $manager->persist($campaign); $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($campaign_creator); $teammember->setIsReviewer(false); $manager->persist($teammember); $manager->flush(); $output->writeln(' '); $output->writeln('Created a Campaign with following combination Case7.Client=testclientforcase7.Country=China.Status=Cancelled'); //ADD THE TASKS FOR THIS CAMPAIGN //Fetch all the task types $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll(); //Fetch the default task status $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1); //For each task type , add to this campaign foreach ($task_types as $tasktype) { $new_task = new Task(); $new_task->setCampaign($campaign); $new_task->setTaskname($tasktype); $new_task->setOwner($campaign_creator); $new_task->setTaskmessage(NULL); $new_task->setMatrixfileversion(0); $new_task->setTaskstatus($default_task_status); $new_task->setPhase($tasktype->getPhaseid()); $new_task->setCreatedAt($creationDate); $new_task->setCreatedby($campaign_creator); $new_task->setUpdatedAt($creationDate); $manager->persist($new_task); } $output->writeln(' '); $output->writeln('Created the tasks for the campaign ' . $campaign->getName()); $output->writeln(' '); } //VERIFY USER IS IN THIS CAMPAIGN'S TEAM $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]); if ($is_teammember) { $output->writeln('The user is already set as a teammember for this campaign.'); } else { $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($user); $teammember->setIsReviewer(false); $manager->persist($teammember); $output->writeln('The test user has been added as a normal teammember for this campaign.'); $output->writeln(' '); } $manager->flush(); break; /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE EIGHTH CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = PORTUGAL , STATUS = CANCELLED. * * This test data should be just like case 6 , the difference is only the COUNTRY. * * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE EIGHTH CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = PORTUGAL , STATUS = CANCELLED. * * This test data should be just like case 6 , the difference is only the COUNTRY. * * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ case 8: $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('Portugal'); $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever'); $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(4); $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status, 'name' => 'Case8.Client=Unilever.Country=Portugal.Status=Cancelled']); if ($campaign) { $existing_campaign_name = $campaign->getName(); $existing_campaign_id = $campaign->getId(); $output->writeln('A campaign for this specs already exists. [case 8] '); $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id); $output->writeln('It is not the case to add another duplicate of this.'); } else { $campaign = new Campaign(); $campaign_key = Uuid::uuid4()->toString(); $campaign->setId($campaign_key); $campaign->setName('Case8.Client=Unilever.Country=Portugal.Status=Cancelled'); $campaign->setCampaignstatus($status); $campaign->setCountry($country); $product = $manager->getRepository('CampaignBundle:Product')->find(25); $campaign->setProduct($product); $productline = $product->getProductline(); $campaign->setProductline($productline); $brand = $productline->getBrand(); $campaign->setBrand($brand); $division = $brand->getDivision(); $campaign->setDivision($division); $client = $division->getClient(); $campaign->setClient($client); $campaign->setCampaignidea('ninecampaignstest'); $campaign->setUser($campaign_creator); $campaign->setClientPresentation(true); $campaign->setNotVisible(false); $campaign->setCompleteness(0); $campaign->setCreatedAt($creationDate); $campaign->setUpdatedAt($creationDate); $data = new \DateTime(); $timestamp = $data->getTimestamp(); $completion_min_days = 1; $completion_max_days = 15; $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400); $random_completion_timestamp = $timestamp + $random_completion_time; $rand_completion_timestamp_object = new \DateTime(); $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp); $deliverable_min_days = 15; $deliverable_max_days = 30; $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400); $random_deliverable_timestamp = $timestamp + $random_deliverable_time; $random_deliverable_timestamp_object = new \DateTime(); $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp); $campaign->setClientDeliverabledate($random_deliverable_timestamp_object); $campaign->setCompletionDate($rand_completion_timestamp_object); $manager->persist($campaign); $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($campaign_creator); $teammember->setIsReviewer(false); $manager->persist($teammember); $manager->flush(); $output->writeln(' '); $output->writeln('Created a Campaign with following combination Case8.Client=Unilever.Country=Portugal.Status=Cancelled'); //ADD THE TASKS FOR THIS CAMPAIGN //Fetch all the task types $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll(); //Fetch the default task status $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1); //For each task type , add to this campaign foreach ($task_types as $tasktype) { $new_task = new Task(); $new_task->setCampaign($campaign); $new_task->setTaskname($tasktype); $new_task->setOwner($campaign_creator); $new_task->setTaskmessage(NULL); $new_task->setMatrixfileversion(0); $new_task->setTaskstatus($default_task_status); $new_task->setPhase($tasktype->getPhaseid()); $new_task->setCreatedAt($creationDate); $new_task->setCreatedby($campaign_creator); $new_task->setUpdatedAt($creationDate); $manager->persist($new_task); } $output->writeln(' '); $output->writeln('Created the tasks for the campaign ' . $campaign->getName()); $output->writeln(' '); } //VERIFY USER IS IN THIS CAMPAIGN'S TEAM $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]); if ($is_teammember) { $output->writeln('The user is already set as a teammember for this campaign.'); } else { $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($user); $teammember->setIsReviewer(false); $manager->persist($teammember); $output->writeln('The test user has been added as a normal teammember for this campaign.'); $output->writeln(' '); } $manager->flush(); break; /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE NINETH CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = PORTUGAL , STATUS = COMPLETED. * * This test data should be just like case 3 , the difference is only COUNTRY * * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE NINETH CAMPAIGN CASE * CLIENT = UNILEVER , COUNTRY = PORTUGAL , STATUS = COMPLETED. * * This test data should be just like case 3 , the difference is only COUNTRY * * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ case 9: $country = $manager->getRepository('CampaignBundle:Country')->findOneByName('Portugal'); $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('Unilever'); $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find(3); $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneBy(['client' => $client, 'country' => $country, 'campaignstatus' => $status]); if ($campaign) { $existing_campaign_name = $campaign->getName(); $existing_campaign_id = $campaign->getId(); $output->writeln('A campaign for this specs already exists. [case 9] '); $output->writeln($existing_campaign_name . ' -> ' . $existing_campaign_id); $output->writeln('It is not the case to add another duplicate of this.'); } else { $campaign = new Campaign(); $campaign_key = Uuid::uuid4()->toString(); $campaign->setId($campaign_key); $campaign->setName('Case9.Client=Unilever.Country=Portugal.Status=Completed'); $campaign->setCampaignstatus($status); $campaign->setCountry($country); $product = $manager->getRepository('CampaignBundle:Product')->find(25); $campaign->setProduct($product); $productline = $product->getProductline(); $campaign->setProductline($productline); $brand = $productline->getBrand(); $campaign->setBrand($brand); $division = $brand->getDivision(); $campaign->setDivision($division); $client = $division->getClient(); $campaign->setClient($client); $campaign->setCampaignidea('ninecampaignstest'); // $campaign_creator = $manager->getRepository('UserBundle:User')->find(5); $campaign->setUser($campaign_creator); $campaign->setClientPresentation(true); $campaign->setNotVisible(false); $campaign->setCompleteness(0); $campaign->setCreatedAt($creationDate); $campaign->setUpdatedAt($creationDate); $data = new \DateTime(); $timestamp = $data->getTimestamp(); $completion_min_days = 1; $completion_max_days = 15; $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400); $random_completion_timestamp = $timestamp + $random_completion_time; $rand_completion_timestamp_object = new \DateTime(); $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp); $deliverable_min_days = 15; $deliverable_max_days = 30; $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400); $random_deliverable_timestamp = $timestamp + $random_deliverable_time; $random_deliverable_timestamp_object = new \DateTime(); $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp); $campaign->setClientDeliverabledate($random_deliverable_timestamp_object); $campaign->setCompletionDate($rand_completion_timestamp_object); $manager->persist($campaign); $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($campaign_creator); $teammember->setIsReviewer(false); $manager->persist($teammember); $manager->flush(); $output->writeln(' '); $output->writeln('Created a Campaign with following combination Case9.Client=Unilever.Country=Portugal.Status=Completed'); //ADD THE TASKS FOR THIS CAMPAIGN //Fetch all the task types $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll(); //Fetch the default task status $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1); //For each task type , add to this campaign foreach ($task_types as $tasktype) { $new_task = new Task(); $new_task->setCampaign($campaign); $new_task->setTaskname($tasktype); $new_task->setOwner($campaign_creator); $new_task->setTaskmessage(NULL); $new_task->setMatrixfileversion(0); $new_task->setTaskstatus($default_task_status); $new_task->setPhase($tasktype->getPhaseid()); $new_task->setCreatedAt($creationDate); $new_task->setCreatedby($campaign_creator); $new_task->setUpdatedAt($creationDate); $manager->persist($new_task); } $output->writeln(' '); $output->writeln('Created the tasks for the campaign ' . $campaign->getName()); $output->writeln(' '); } //VERIFY USER IS IN THIS CAMPAIGN'S TEAM $is_teammember = $manager->getRepository('CampaignBundle:Teammember')->findOneBy(['campaign' => $campaign, 'member' => $user]); if ($is_teammember) { $output->writeln('The user is already set as a teammember for this campaign.'); } else { $teammember = new Teammember(); $teammember->setCampaign($campaign); $teammember->setMember($user); $teammember->setIsReviewer(false); $manager->persist($teammember); $output->writeln('The test user has been added as a normal teammember for this campaign.'); $output->writeln(' '); } $manager->flush(); //Randomly assign the user as a taskowner for at leat two tasks. $random_ids = array(); $random_number_of_tasks = 6; for ($i = 2; $i < $random_number_of_tasks; $i++) { $random_ids[] = rand(1, 9); } $unique_random_ids = array_unique($random_ids); $all_tasks_of_this_campaign = $manager->getRepository('TaskBundle:Task')->findByCampaign($campaign->getId()); foreach ($all_tasks_of_this_campaign as $task) { $task->setOwner(NULL); if (in_array($task->getTaskname()->getId(), $unique_random_ids)) { ///ADD SET THIS TASK TO HAVE THE OWNER THE TEST USER. $task->setOwner($user); $output->writeln($user->getUsername() . ' has been set as a taskowner for task ' . $task->getTaskname()->getName()); } $manager->persist($task); } $manager->flush(); break; /* * ************************************************************************************************************************************** * ******************************************************************************************************************************************************** * * THE TEST DATA REMOVAL PART STARTS HERE |||| THE TEST DATA REMOVAL PART STARTS HERE * * ******************************************************************************************************************************************************** * ******************************************************************************************************************************************************** */ } } elseif ($input->getOption('removecampaign')) { $number = $input->getArgument('number'); switch ($number) { case 1: $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case1.Client=Unilever.Country=USA.Status=Build'); //WHEN WE REMOVE CASE 1 , if ($campaign) { //1. We must remove any teammember relationship related to the specified campaign before removing the campaign. $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign); foreach ($teammembers as $teammember) { $manager->remove($teammember); } $manager->remove($campaign); $manager->flush(); $output->writeln(' '); $output->writeln('Removed campaign Case1.Client=Unilever.Country=USA.Status=Build. And the teammembers of this campaign.'); $output->writeln(' '); } else { $output->writeln(' '); $output->writeln('There was no campaign Case1.Client=Unilever.Country=USA.Status=Build'); $output->writeln(' '); } break; case 2: $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case2.Client=Unilever.Country=USA.Status=Approved'); //WHEN WE REMOVE CASE 1 , if ($campaign) { //1. We must remove any teammember relationship related to the specified campaign before removing the campaign. $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign); foreach ($teammembers as $teammember) { $manager->remove($teammember); } $manager->remove($campaign); $manager->flush(); $output->writeln(' '); $output->writeln('Removed campaign Case2.Client=Unilever.Country=USA.Status=Approved. And the teammembers of this campaign.'); $output->writeln(' '); } else { $output->writeln(' '); $output->writeln('There was no campaign Case2.Client=Unilever.Country=USA.Status=Approved'); $output->writeln(' '); } break; case 3: $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case3.Client=Unilever.Country=China.Status=Completed'); //WHEN WE REMOVE CASE 1 , if ($campaign) { //1. We must remove any teammember relationship related to the specified campaign before removing the campaign. $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign); foreach ($teammembers as $teammember) { $manager->remove($teammember); } $manager->remove($campaign); $manager->flush(); $output->writeln(' '); $output->writeln('Removed campaign Case3.Client=Unilever.Country=China.Status=Completed. And the teammembers of this campaign.'); $output->writeln(' '); } else { $output->writeln(' '); $output->writeln('There was no campaign Case3.Client=Unilever.Country=China.Status=Completed'); $output->writeln(' '); } break; case 4: $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case4.Client=Unilever.Country=China.Status=Cancelled'); //WHEN WE REMOVE CASE 1 , if ($campaign) { //1. We must remove any teammember relationship related to the specified campaign before removing the campaign. $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign); foreach ($teammembers as $teammember) { $manager->remove($teammember); } $manager->remove($campaign); $manager->flush(); $output->writeln(' '); $output->writeln('Removed campaign Case4.Client=Unilever.Country=China.Status=Cancelled. And the teammembers of this campaign.'); $output->writeln(' '); } else { $output->writeln(' '); $output->writeln('There was no campaign Case4.Client=Unilever.Country=China.Status=Cancelled'); $output->writeln(' '); } break; case 5: $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case5.Client=Unilever.Country=China.Status=Build'); //WHEN WE REMOVE CASE 1 , if ($campaign) { //1. We must remove any teammember relationship related to the specified campaign before removing the campaign. $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign); foreach ($teammembers as $teammember) { $manager->remove($teammember); } $manager->remove($campaign); $manager->flush(); $output->writeln(' '); $output->writeln('Removed campaign Case5.Client=Unilever.Country=China.Status=Cancelled. And the teammembers of this campaign.'); $output->writeln(' '); } else { $output->writeln(' '); $output->writeln('There was no campaign Case5.Client=Unilever.Country=China.Status=Cancelled'); $output->writeln(' '); } break; case 6: $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case6.Client=Unilever.Country=China.Status=Cancelled'); //WHEN WE REMOVE CASE 1 , if ($campaign) { //1. We must remove any teammember relationship related to the specified campaign before removing the campaign. $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign); foreach ($teammembers as $teammember) { $manager->remove($teammember); } $manager->remove($campaign); $manager->flush(); $output->writeln(' '); $output->writeln('Removed campaign Case6.Client=Unilever.Country=China.Status=Cancelled. And the teammembers of this campaign.'); $output->writeln(' '); } else { $output->writeln(' '); $output->writeln('There was no campaign Case6.Client=Unilever.Country=China.Status=Cancelled'); $output->writeln(' '); } break; case 7: $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case7.Client=testclientforcase7.Country=China.Status=Cancelled'); //WHEN WE REMOVE CASE 1 , if ($campaign) { //1. We must remove any teammember relationship related to the specified campaign before removing the campaign. $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign); foreach ($teammembers as $teammember) { $manager->remove($teammember); } $client = $manager->getRepository('CampaignBundle:Client')->findOneByName('testclientforcase7'); $manager->remove($client); $manager->remove($campaign); $manager->flush(); $output->writeln(' '); $output->writeln('Removed campaign Case7.Client=testclientforcase7.Country=China.Status=Cancelled. And the teammembers of this campaign.'); $output->writeln('Also removed the testclientforcase7 client. '); $output->writeln(' '); } else { $output->writeln(' '); $output->writeln('There was no campaign Case7.Client=testclientforcase7.Country=China.Status=Cancelled'); $output->writeln(' '); } break; case 8: $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case8.Client=Unilever.Country=Portugal.Status=Cancelled'); //WHEN WE REMOVE CASE 1 , if ($campaign) { //1. We must remove any teammember relationship related to the specified campaign before removing the campaign. $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign); foreach ($teammembers as $teammember) { $manager->remove($teammember); } $manager->remove($campaign); $manager->flush(); $output->writeln(' '); $output->writeln('Removed campaign Case8.Client=Unilever.Country=Portugal.Status=Cancelled. And the teammembers of this campaign.'); $output->writeln(' '); } else { $output->writeln(' '); $output->writeln('There was no campaign Case8.Client=Unilever.Country=Portugal.Status=Cancelled'); $output->writeln(' '); } break; case 9: $campaign = $manager->getRepository('CampaignBundle:Campaign')->findOneByName('Case9.Client=Unilever.Country=Portugal.Status=Completed'); //WHEN WE REMOVE CASE 1 , if ($campaign) { //1. We must remove any teammember relationship related to the specified campaign before removing the campaign. $teammembers = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign); foreach ($teammembers as $teammember) { $manager->remove($teammember); } $manager->remove($campaign); $manager->flush(); $output->writeln(' '); $output->writeln('Removed campaign Case9.Client=Unilever.Country=Portugal.Status=Completed. And the teammembers of this campaign.'); $output->writeln(' '); } else { $output->writeln(' '); $output->writeln('There was no campaign Case9.Client=Unilever.Country=Portugal.Status=Completed'); $output->writeln(' '); } break; } } else { } }
protected function execute(InputInterface $input, OutputInterface $output) { $manager = $this->getContainer()->get('doctrine')->getManager(); $creationDate = new \DateTime(); $creationDate->setTimezone(new \DateTimeZone('UTC')); if ($input->getOption('add')) { $existing_test_campaigns = $manager->getRepository('CampaignBundle:Campaign')->findByCampaignidea('thisisadeletabletestcampaign'); if (count($existing_test_campaigns) > 0) { $output->writeln('Found test_campaigns in database. Will delete ' . count($existing_test_campaigns) . ' test_campaigns from database.'); sleep(1); foreach ($existing_test_campaigns as $campaign) { $teammember_entries = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign); if ($teammember_entries) { foreach ($teammember_entries as $entry) { $manager->remove($entry); } } $manager->remove($campaign); } $manager->flush(); sleep(1); $output->writeln('Succesfully deleted ' . count($existing_test_campaigns) . ' test_campaigns from database.'); } $role_contrib = $manager->getRepository('UserBundle:Role')->find(2); $role_admin = $manager->getRepository('UserBundle:Role')->find(3); $contributors = array(); $administrators = array(); $all_users = $manager->getRepository('UserBundle:User')->findByConfirmationToken('deletable'); foreach ($all_users as $user) { if ($user->hasRole('ROLE_CONTRIBUTOR')) { $contributors[] = $user; } if ($user->hasRole('ROLE_ADMINISTRATOR')) { $administrators[] = $user; } } $output->writeln('All users: ' . count($all_users)); $output->writeln('Contributors: ' . count($contributors)); $output->writeln('Administrators: ' . count($administrators)); foreach ($contributors as $contributor) { $campaign = new Campaign(); $key = Uuid::uuid4()->toString(); /////RANDOMLY GRAB DATA TO POPULATE THIS CAMPAIGN /////RANDOMLY GRAB DATA TO POPULATE THIS CAMPAIGN $products_in_database = $manager->getRepository('CampaignBundle:Product')->findAll(); $number_of_products = count($products_in_database); $random_pick = rand(1, $number_of_products); $product = $manager->getRepository('CampaignBundle:Product')->find($random_pick); $productline = $product->getProductline(); $brand = $productline->getBrand(); $division = $brand->getDivision(); $client = $division->getClient(); $random_status_id = rand(1, 1); $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find($random_status_id); /////END RANDOMLY GRAB DATA TO POPULATE THIS CAMPAIGN $campaign_name = $contributor->getUsername() . 'campaignTEST'; ///ASSIGN $campaign->setCampaignidea('thisisadeletabletestcampaign'); $campaign->setId($key); $campaign->setUser($contributor); $campaign->setClient($client); $campaign->setDivision($division); $campaign->setBrand($brand); $campaign->setProductline($productline); $campaign->setProduct($product); $campaign->setName($campaign_name); $campaign->setCampaignstatus($status); /////RANDOM GRAB COUNTRY $countries = $manager->getRepository('CampaignBundle:Country')->findAll(); $country_number = count($countries); $random_country_id = rand(1, $country_number); $country = $manager->getRepository('CampaignBundle:Country')->find($random_country_id); /////END RANDOM GRAB COUNTRY ///ASSIGN $campaign->setCountry($country); $campaign->setClientPresentation(true); $campaign->setNotVisible(false); $campaign->setCompleteness(0); $campaign->setCreatedAt($creationDate); $campaign->setUpdatedAt($creationDate); $data = new \DateTime(); $timestamp = $data->getTimestamp(); $completion_min_days = 1; $completion_max_days = 15; $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400); $random_completion_timestamp = $timestamp + $random_completion_time; $rand_completion_timestamp_object = new \DateTime(); $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp); $deliverable_min_days = 15; $deliverable_max_days = 30; $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400); $random_deliverable_timestamp = $timestamp + $random_deliverable_time; $random_deliverable_timestamp_object = new \DateTime(); $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp); $campaign->setClientDeliverabledate($random_deliverable_timestamp_object); $campaign->setCompletionDate($rand_completion_timestamp_object); $manager->persist($campaign); ////// SET THE CONTRIB USER AS A TEAMMEMBER FOR THIS CAMPAIGN ////// SET THE CONTRIB USER AS A TEAMMEMBER FOR THIS CAMPAIGN $add_as_teammember = new Teammember(); $add_as_teammember->setCampaign($campaign); $add_as_teammember->setMember($contributor); $add_as_teammember->setIsReviewer(false); $manager->persist($add_as_teammember); //////////////ADD TASKS FOR THIS CONTRIB CAMPAIGN HERE //////////////ADD TASKS FOR THIS CONTRIB CAMPAIGN HERE //////////////ADD TASKS FOR THIS CONTRIB CAMPAIGN HERE //Fetch all the task types $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll(); //Fetch the default task status $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1); //For each task type , add to this campaign foreach ($task_types as $tasktype) { $new_task = new Task(); $new_task->setCampaign($campaign); $new_task->setTaskname($tasktype); $new_task->setOwner($contributor); $new_task->setTaskmessage(NULL); $new_task->setMatrixfileversion(0); $new_task->setTaskstatus($default_task_status); $new_task->setPhase($tasktype->getPhaseid()); $new_task->setCreatedAt($creationDate); $new_task->setCreatedby($contributor); $new_task->setUpdatedAt($creationDate); $manager->persist($new_task); } } foreach ($administrators as $administrator) { $admin_campaign = new Campaign(); $key = Uuid::uuid4()->toString(); /////RANDOMLY GRAB DATA TO POPULATE THIS CAMPAIGN /////RANDOMLY GRAB DATA TO POPULATE THIS CAMPAIGN $products_in_database = $manager->getRepository('CampaignBundle:Product')->findAll(); $number_of_products = count($products_in_database); $random_pick = rand(1, $number_of_products); $product = $manager->getRepository('CampaignBundle:Product')->find($random_pick); $productline = $product->getProductline(); $brand = $productline->getBrand(); $division = $brand->getDivision(); $client = $division->getClient(); $random_status_id = rand(1, 1); $status = $manager->getRepository('CampaignBundle:Campaignstatus')->find($random_status_id); /////END RANDOMLY GRAB DATA TO POPULATE THIS CAMPAIGN $campaign_name = $contributor->getUsername() . 'campaignTEST'; ///ASSIGN $admin_campaign->setCampaignidea('thisisadeletabletestcampaign'); $admin_campaign->setId($key); $admin_campaign->setUser($administrator); $admin_campaign->setClient($client); $admin_campaign->setDivision($division); $admin_campaign->setBrand($brand); $admin_campaign->setProductline($productline); $admin_campaign->setProduct($product); $admin_campaign->setName($campaign_name); $admin_campaign->setCampaignstatus($status); /////RANDOM GRAB COUNTRY $countries = $manager->getRepository('CampaignBundle:Country')->findAll(); $country_number = count($countries); $random_country_id = rand(1, $country_number); $country = $manager->getRepository('CampaignBundle:Country')->find($random_country_id); /////END RANDOM GRAB COUNTRY ///ASSIGN $admin_campaign->setCountry($country); $admin_campaign->setClientPresentation(true); $admin_campaign->setNotVisible(false); $admin_campaign->setCompleteness(0); $admin_campaign->setCreatedAt($creationDate); $admin_campaign->setUpdatedAt($creationDate); $data = new \DateTime(); $timestamp = $data->getTimestamp(); $completion_min_days = 1; $completion_max_days = 15; $random_completion_time = rand($completion_min_days * 86400, $completion_max_days * 86400); $random_completion_timestamp = $timestamp + $random_completion_time; $rand_completion_timestamp_object = new \DateTime(); $rand_completion_timestamp_object->setTimestamp($random_completion_timestamp); $deliverable_min_days = 15; $deliverable_max_days = 30; $random_deliverable_time = rand($deliverable_min_days * 86400, $deliverable_max_days * 86400); $random_deliverable_timestamp = $timestamp + $random_deliverable_time; $random_deliverable_timestamp_object = new \DateTime(); $random_deliverable_timestamp_object->setTimestamp($random_deliverable_timestamp); $admin_campaign->setClientDeliverabledate($random_deliverable_timestamp_object); $admin_campaign->setCompletionDate($rand_completion_timestamp_object); $manager->persist($admin_campaign); ////// SET THE ADMIN USER AS A TEAMMEMBER FOR THIS CAMPAIGN ////// SET THE ADMIN USER AS A TEAMMEMBER FOR THIS CAMPAIGN $add_as_teammember = new Teammember(); $add_as_teammember->setCampaign($campaign); $add_as_teammember->setMember($administrator); $add_as_teammember->setIsReviewer(false); $manager->persist($add_as_teammember); //////////////ADD TASKS FOR THIS ADMIN CAMPAIGN HERE //////////////ADD TASKS FOR THIS ADMIN CAMPAIGN HERE //////////////ADD TASKS FOR THIS ADMIN CAMPAIGN HERE //Fetch all the task types $task_types = $manager->getRepository('TaskBundle:Taskname')->findAll(); //Fetch the default task status $default_task_status = $manager->getRepository('TaskBundle:Taskstatus')->find(1); //For each task type , add to this campaign foreach ($task_types as $tasktype) { $new_task = new Task(); $new_task->setCampaign($admin_campaign); $new_task->setTaskname($tasktype); $new_task->setOwner($administrator); $new_task->setTaskmessage(NULL); $new_task->setMatrixfileversion(0); $new_task->setTaskstatus($default_task_status); $new_task->setPhase($tasktype->getPhaseid()); $new_task->setCreatedAt($creationDate); $new_task->setCreatedby($administrator); $new_task->setUpdatedAt($creationDate); $manager->persist($new_task); } } $manager->flush(); } elseif ($input->getOption('remove')) { $existing_test_campaigns = $manager->getRepository('CampaignBundle:Campaign')->findByCampaignidea('thisisadeletabletestcampaign'); $count = 0; foreach ($existing_test_campaigns as $campaign) { $teammember_entries = $manager->getRepository('CampaignBundle:Teammember')->findByCampaign($campaign); if ($teammember_entries) { foreach ($teammember_entries as $entry) { $manager->remove($entry); } } $manager->remove($campaign); $count += 1; } $manager->flush(); $output->writeln('Removed ' . $count . ' TEST_campaigns.'); } else { $output->writeln(' '); $output->writeln(' '); $output->writeln('You can use --add / --remove options to change what the command should do.The command is for testing purposes only.'); $output->writeln(' '); $output->writeln(' '); } }
/** * @ApiDoc( * description = "Creates and saves a new campaign.", * section="Z_DISABLED", * statusCodes = { * 201 = "Returned when the campaign was added to the database", * 400 = "Returned when the validation returns false ", * 403 = {"Invalid API KEY", "Incorrect combination of request inputs."}, * 500 = "Header x-wsse does not exist" * }, * requirements = { * {"name"="_format", "dataType"="string","requirement"="json|xml","description"="Format"}, * }, * parameters={ * {"name"="name", "dataType"="text", "required"=true, "description"="The campaign name"}, * {"name"="client", "dataType"="string","required"=true,"description"="The campaign client."}, * {"name"="brand", "dataType"="string","required"=true,"description"="The campaign brand."}, * {"name"="product", "dataType"="string","required"=true,"description"="The campaign product."}, * {"name"="division", "dataType"="string","required"=true,"description"="The campaign division."}, * {"name"="productline", "dataType"="string","required"=true,"description"="The campaign productline."}, * {"name"="country", "dataType"="string","required"=true,"description"="The campaign country."}, * {"name"="completion_date", "dataType"="string","required"=true,"description"="The campaign completion date."}, * {"name"="client_deliverabledate","dataType"="string","required"=true,"description"="The campaign deliverable date."}, * } * ) * return string * @View() */ public function postCampaignAction(Request $request) { $user = $this->getUser(); $creationDate = new \DateTime(); $creationDate->setTimezone(self::timezoneUTC()); $em = $this->getDoctrine()->getManager(); $key = Uuid::uuid4()->toString(); $token_key = Uuid::uuid4()->toString(); $client_id = $request->get('client'); $country_id = $request->get('country'); $brand_id = $request->get('brand'); $product_id = $request->get('product'); $productline_id = $request->get('productline'); $division_id = $request->get('division'); $response = new Response(); //Disallow VIEWERS TO POST CAMPAIGNS if ($user->hasRole('ROLE_VIEWER')) { $response->setStatusCode(403); $response->setContent(json_encode(array('success' => false, 'message' => "Viewers are not allowed to create campaigns"))); return $response; } ///////////////////////////////////////////////////////////////////////////////////// // Checks to verify object's existence into the database. ///////////////////////////////////////////////////////////////////////////////////// $client = $this->getDoctrine()->getRepository('CampaignBundle:Client')->findOneById($client_id); if (!$client) { $response->setStatusCode(403); $response->setContent(json_encode(array('success' => false, 'message' => 'Invalid ID provided for field client.'))); return $response; } $division = $this->getDoctrine()->getRepository('CampaignBundle:Division')->findOneById($division_id); if (!$division) { $response->setStatusCode(403); $response->setContent(json_encode(array('success' => false, 'message' => 'Invalid ID provided for field division.'))); return $response; } $brand = $this->getDoctrine()->getRepository('CampaignBundle:Brand')->findOneById($brand_id); if (!$brand) { $response->setStatusCode(403); $response->setContent(json_encode(array('success' => false, 'message' => 'Invalid ID provided for field brand.'))); return $response; } $productline = $this->getDoctrine()->getRepository('CampaignBundle:Productline')->findOneById($productline_id); if (!$productline) { $response->setStatusCode(403); $response->setContent(json_encode(array('success' => false, 'message' => 'Invalid ID provided for field productline.'))); return $response; } $product = $this->getDoctrine()->getRepository('CampaignBundle:Product')->findOneById($product_id); if (!$product) { $response->setStatusCode(403); $response->setContent(json_encode(array('success' => false, 'message' => 'Invalid ID provided for field product.'))); return $response; } $country = $this->getDoctrine()->getRepository('CampaignBundle:Country')->findOneById($country_id); if (!$country) { $response->setStatusCode(403); $response->setContent(json_encode(array('success' => false, 'message' => 'Invalid ID provided for field country .'))); return $response; } //AFTER VALIDATING INPUT , FOR A CONTRIBUTOR , VALIDATE THE ACCESS TOO if ($user->hasRole('ROLE_CONTRIBUTOR')) { $post_can_continue = self::validate_the_put_and_post_for_contributor($client, $country, $user); if (!$post_can_continue) { //print_r($user->getUsername()); $response->setStatusCode(200); $response->setContent(json_encode(array('success' => false, 'message' => "You do not have permissions to create a campaign for the specified client and country values"))); return $response; } } //DISABLED VALIDATION HERE // THE CLIENT WANTS TO BE ABLE TO CREATE DUPLICATE CAMPAIGNS IN SELECT CASES , SO THEY WILL BE RESPONSIBLE FOR MONITORING THE DUPLICATES MANUALLY // ///VERIFY THAT THERE IN'T ALREADY A CAMPAIGN CREATED BY THIS USER , USING THE SPECIFIED NAME. // // $campaing_already_exists_for_creator_name_combo = $this->getDoctrine()->getRepository('CampaignBundle:Campaign')->findOneBy([ // 'user' => $user, // 'name' => $request->get('name')]); // // // if ($campaing_already_exists_for_creator_name_combo) { // $response->setStatusCode(403); // $response->setContent(json_encode(array('success' => false, 'message' => 'You already have a campaign that uses that campaign name. Please choose another one!'))); // return $response; // } // /// End of newly added validation. //////// ///////////////////////////////////////////////////////////////////////////////////// // END Checks to verify object's existence into the database. //////////////////////////////////////////////////////////////////////////////////// ////RELATIONAL CHECKS ////RELATIONAL CHECKS //////////////////////////////////////////////////// // Client should have the respective division // Division should have the respective brand // Brand should have the respective productline // Productline should have the respective product ////////////////////////////////////////////////////////////////// ////////////////////// //Validate that the division specified belongs to the client specified. ////////////////////// if (!($division->getClient()->getId() == $client->getId())) { $response->setStatusCode(403); $response->setContent(json_encode(array('success' => false, 'message' => 'Division does not belong to this Client.'))); return $response; } ////////////////////// //Validate that the brand specified belongs to the division specified. ////////////////////// if (!($brand->getDivision()->getId() == $division->getId())) { $response->setStatusCode(403); $response->setContent(json_encode(array('success' => false, 'message' => 'Brand does not belong to this Division.'))); return $response; } ////////////////////// //Validate that the productline specified belongs to the brand specified. ////////////////////// if (!($productline->getBrand()->getId() == $brand->getId())) { $response->setStatusCode(403); $response->setContent(json_encode(array('success' => false, 'message' => 'Productline does not belong to this Brand.'))); return $response; } //////////////////////// //Validate that the product specified belongs to the productline specified. ////////////////////// if (!($product->getProductline()->getId() == $productline->getId())) { $response->setStatusCode(403); $response->setContent(json_encode(array('success' => false, 'message' => 'Product does not belong to this Productline.'))); return $response; } ////////////////////////////// //END RELATIONAL CHECKS ////////////////////////////// //////////////////////////////////////////////////////////////////////////////////// /////////////////////END OF CHECKS //////////////////////////////////////////////////////////////////////////////////// if (empty($request->get('completion_date'))) { $response->setStatusCode(400); $response->setContent(json_encode(array('success' => false, 'message' => 'The completion_date field is required !'))); return $response; } if (empty($request->get('client_deliverabledate'))) { $response->setStatusCode(400); $response->setContent(json_encode(array('success' => false, 'message' => 'The client_deliverabledate field is required !'))); return $response; } $completion_date_input = $request->get('completion_date'); // Inputs completion and deliverable dates: if ($completion_date_input) { $completion_date = new \DateTime($request->get('completion_date')); $completion_date->setTimezone(self::timezoneUTC()); } $deliverable_date_input = $request->get('client_deliverabledate'); if ($deliverable_date_input) { $deliverable_date = new \DateTime($request->get('client_deliverabledate')); $deliverable_date->setTimezone(self::timezoneUTC()); } //VALIDATE THAT THE COMPLETION DATE IS LATER THAN THE CLIENT_DELIVERABLEDATE if ($completion_date && $deliverable_date) { $seconds_in_one_day = 60 * 60 * 24; $ts_completion = $completion_date->getTimestamp(); $ts_deliverable = $deliverable_date->getTimestamp(); $difference = $ts_completion - $ts_deliverable; if ($difference < $seconds_in_one_day) { $response->setStatusCode(400); $response->setContent(json_encode(array('success' => false, 'message' => 'The Completion Date must be later than the Client Deliverable Date. (1 day minimum)'))); return $response; } } //ERROR MESSAGE : The Completion Date must be later than the Client Deliverable Date. $campaign_status = $this->getDoctrine()->getRepository('CampaignBundle:Campaignstatus')->find(1); // Populate the Campaign object with data from the Request: $campaign = new Campaign(); $campaign->setId($key); $campaign->setUser($user); //$campaign->setBriefOutline('This is the campaigns bief outline text. hardcoded.'); $campaign->setClientPresentation(false); $campaign->setCompleteness(0); $campaign->setName($request->get('name')); $campaign->setClient($client); $campaign->setBrand($brand); $campaign->setProduct($product); $campaign->setProductline($productline); $campaign->setDivision($division); $campaign->setCountry($country); $campaign->setCampaignstatus($campaign_status); $campaign->setCompletionDate($completion_date); $campaign->setClientDeliverabledate($deliverable_date); $campaign->setToken($token_key); $campaign->setNotVisible(false); $campaign->setScreentype('10000'); // Set time for when the file was created: $campaign->setCreatedAt($creationDate); $campaign->setUpdatedAt($creationDate); // Get validator service to check for errors: $validator = $this->get('validator'); $errors = $validator->validate($campaign); // Create and prepare the Response object to be sent back to client: $response = new Response(); if (count($errors) > 0) { // Return $errors in JSON format: $view = $this->view($errors, 400); return $this->handleView($view); } // If no errors were found, instantiate entity_manager to begin. $em->persist($campaign); ///////////////////////////////////////////////////// //Add the user who created the campaign to the campaign's team. ///////////////////////////////////////////////////// $add_as_teammember = new Teammember(); $add_as_teammember->setCampaign($campaign); $add_as_teammember->setMember($user); $add_as_teammember->setIsReviewer(false); $em->persist($add_as_teammember); ////////////////////////////////////////////////////// /// ///////////////////////////////////////////////////// //Create the set of tasks for this campaign ///////////////////////////////////////////////////// $campaign_unique_id = $campaign->getId(); $task_types = $this->getDoctrine()->getRepository('TaskBundle:Taskname')->findAll(); $default_task_status = $this->getDoctrine()->getRepository('TaskBundle:Taskstatus')->find(1); foreach ($task_types as $tasktype) { $new_task = new Task(); $new_task->setCampaign($campaign); $new_task->setTaskname($tasktype); $new_task->setOwner($user); $new_task->setTaskmessage(NULL); $new_task->setMatrixfileversion(0); $new_task->setTaskstatus($default_task_status); $new_task->setPhase($tasktype->getPhaseid()); $new_task->setCreatedAt($creationDate); $new_task->setCreatedby($user); $new_task->setUpdatedAt($creationDate); $em->persist($new_task); } ////////////////////////////////////////////////////// /// $em->flush(); $response->setStatusCode(201); $response->setContent(json_encode(array('success' => true, 'campaignID' => $campaign->getId()))); return $response; }