/src/OroCRM/Bundle/DemoDataBundle/Migrations/Data/Demo/ORM/LoadReportData.php

https://github.com/jrcollado1987/crm · PHP · 111 lines · 76 code · 13 blank · 22 comment · 1 complexity · 87a56a93c459a2f1291ad5b919cd88d2 MD5 · raw file

  1. <?php
  2. namespace OroCRM\Bundle\DemoDataBundle\Migrations\Data\Demo\ORM;
  3. use Doctrine\Common\DataFixtures\DependentFixtureInterface;
  4. use Oro\Bundle\OrganizationBundle\Entity\BusinessUnit;
  5. use Oro\Bundle\ReportBundle\Entity\Report;
  6. use Oro\Bundle\ReportBundle\Entity\ReportType;
  7. use Doctrine\Common\DataFixtures\AbstractFixture;
  8. use Doctrine\Common\Persistence\ObjectManager;
  9. use Doctrine\ORM\EntityManager;
  10. class LoadReportData extends AbstractFixture implements DependentFixtureInterface
  11. {
  12. /** @var EntityManager */
  13. protected $em;
  14. // @codingStandardsIgnoreStart
  15. protected $reports = array(
  16. array(
  17. 'name' => 'Total Forecast',
  18. 'description' => 'This report forecasts maximum projected income from all current opportunities.',
  19. 'type' => 'table',
  20. 'owner' => 'Acme, General',
  21. 'entity' => 'OroCRM\Bundle\SalesBundle\Entity\Opportunity',
  22. 'definition' => '{"filters":[{"columnName":"probability","criterion":{"filter":"number","data":{"value":0,"type":"4"}}},"AND",{"columnName":"probability","criterion":{"filter":"number","data":{"value":1,"type":"4"}}}],"grouping_columns":[{"name":"probability","oro_report_form[grouping][columnNames]":"probability"}],"columns":[{"name":"budgetAmount","label":"Budget amount","func":{"name":"Sum","group_type":"aggregates","group_name":"number"},"sorting":""},{"name":"probability","label":"Probability","func":"","sorting":"DESC"}]}'
  23. ),
  24. array(
  25. 'name' => 'Leads by Geography',
  26. 'description' => 'Geographical distribution of Leads',
  27. 'type' => 'table',
  28. 'owner' => 'Acme, General',
  29. 'entity' => 'OroCRM\Bundle\SalesBundle\Entity\Lead',
  30. 'definition' => ' {"filters":[],"grouping_columns":[{"name":"address+Oro\\\\Bundle\\\\AddressBundle\\\\Entity\\\\Address::region+Oro\\\\Bundle\\\\AddressBundle\\\\Entity\\\\Region::name","oro_report_form[grouping][columnNames]":"address+Oro\\\\Bundle\\\\AddressBundle\\\\Entity\\\\Address::region+Oro\\\\Bundle\\\\AddressBundle\\\\Entity\\\\Region::name"}],"columns":[{"name":"address+Oro\\\\Bundle\\\\AddressBundle\\\\Entity\\\\Address::region+Oro\\\\Bundle\\\\AddressBundle\\\\Entity\\\\Region::name","label":"State","func":"","sorting":"ASC"},{"name":"id","label":"NUMBER OF LEADS","func":{"name":"Count","group_type":"aggregates","group_name":"number"},"sorting":""}]}'
  31. ),
  32. );
  33. // @codingStandardsIgnoreEnd
  34. /**
  35. * {@inheritdoc}
  36. */
  37. public function getDependencies()
  38. {
  39. return [
  40. 'OroCRM\Bundle\DemoDataBundle\Migrations\Data\Demo\ORM\LoadBusinessUnitData'
  41. ];
  42. }
  43. /**
  44. * {@inheritDoc}
  45. */
  46. public function load(ObjectManager $manager)
  47. {
  48. $this->initSupportingEntities($manager);
  49. $this->loadReports();
  50. }
  51. protected function initSupportingEntities(ObjectManager $manager = null)
  52. {
  53. if ($manager) {
  54. $this->em = $manager;
  55. }
  56. }
  57. public function loadReports()
  58. {
  59. foreach ($this->reports as $values) {
  60. $report = new Report();
  61. $report->setName($values['name']);
  62. $report->setDescription($values['description']);
  63. $report->setEntity($values['entity']);
  64. /** @var ReportType $type */
  65. $type = $this->em
  66. ->getRepository('OroReportBundle:ReportType')
  67. ->findOneBy(array('name' => $values['type']));
  68. $report->setType($type);
  69. /** @var BusinessUnit $owner */
  70. $owner = $this->em
  71. ->getRepository('OroOrganizationBundle:BusinessUnit')
  72. ->findOneBy(array('name' => $values['owner']));
  73. $report->setOwner($owner);
  74. $report->setDefinition($values['definition']);
  75. $this->persist($this->em, $report);
  76. }
  77. $this->flush($this->em);
  78. }
  79. /**
  80. * Persist object
  81. *
  82. * @param mixed $manager
  83. * @param mixed $object
  84. */
  85. private function persist($manager, $object)
  86. {
  87. $manager->persist($object);
  88. }
  89. /**
  90. * Flush objects
  91. *
  92. * @param mixed $manager
  93. */
  94. private function flush($manager)
  95. {
  96. $manager->flush();
  97. }
  98. }