Forums › Forums › OroCRM › OroCRM – How do I? Questions › How to use date range?
This topic contains 7 replies, has 2 voices, and was last updated by abel 7 years, 7 months ago.
Starting from March 1, 2020 the forum has been switched to the read-only mode. Please head to StackOverflow for support.
- CreatorTopic
- September 7, 2016 at 2:32 am #29048
I want add and get value from date range.
Use it in my bundle and show like that:
How can do that? - CreatorTopic
- AuthorReplies
- September 8, 2016 at 8:59 am #29049
Hi,
I think you should use oro_type_widget_date_range:
PHP12345678910$builder->add('date_range','oro_type_widget_date_range',array('label' => 'Range','required' => true,// 'mapped' => false,'value_types' => true));September 9, 2016 at 9:04 am #29050I was used dateRange follow your answer, I can create form and save data date range to database.
But if I use it for filter data then some problem was occurred.
I use date range follow CampaignBundle.
***** My code include:
1. Function in Controller1234567891011121314151617181920212223$qb = $this->getDoctrine()->getManager()->createQueryBuilder();$qb->select(sprintf('o.doc_date'),sprintf('o.amount'))->from('TnaPosBundle:Order', 'o');$em = $this->getDoctrine()->getManager();$query = $em->createQuery("SELECT t.created_atFROM TnaMyChartBundle:Test t");$data = $query->getResult();$dateRange = $data[0]['created_at'];$result = $this->get('pos_bundle.test')->getOrderData($qb, $dateRange);var_dump($result);return array();2. Provider
123456789/*** @param array $dateRange* @return array*/public function getOrderData(QueryBuilder $qb, array $dateRange) {$this->dateFilterProcessor->process($qb, $dateRange, 'o.created_at');return $this->aclHelper->apply($qb)->getArrayResult();}******* my date_range data like this:
1array(3) { ["type"]=> int(1) ["value"]=> array(2) { ["start"]=> string(10) "2016-01-01" ["end"]=> string(10) "2016-12-31" } ["part"]=> string(5) "value" }********* ISSUE
When I dump data ($result), in my interface show 2 notice123Notice: Undefined index: start in /var/www/html/orocrm/vendor/oro/platform/src/Oro/Bundle/DashboardBundle/Filter/DateFilterProcessor.php on line 50Notice: Undefined index: end in /var/www/html/orocrm/vendor/oro/platform/src/Oro/Bundle/DashboardBundle/Filter/DateFilterProcessor.php on line 51And data are not filtered.
The same when I change date_range to ‘this month’ or somthing (not have end_date and start_date)
What wrong in my code?September 11, 2016 at 8:35 pm #29051Update!!!
I had read class Oro\Bundle\DashboardBundle\Filter\DateFilterProcessor
function getModifiedDateData(array $dateData) have this code12345$dateData['value'] = ['start' => $dateData['start'],'end' => $dateData['end']];unset($dateData['start'], $dateData['end']);so I think $dateData have construct like that
123456{"type": ...,"start": ...,"end": ...,"part": ...}and after that, $dateData construct was converted to
123456"type": ...,"value": {"start": ...,"end": ...},"part": ...finally, it’s return
1return $this->modifier->modify($dateData, ['start', 'end'], false);But my dateRange data have construct
123456"type": ...,"value": {"start": ...,"end": ...},"part": ...So I think I need change this function, then I create new class DateFilterProcessor and class DateRangeFilter in direct Filter in my bundle. Next I was changed service.yml
After that, it’s work true if I choose date range “Custom” (With between or laterthan or earlierthan), but when I choose different date range (‘today’, ‘this week’, ‘this month’, ‘this quarter’, ‘this year’), it’s not filter and no error.
How can I fix it?September 12, 2016 at 11:16 pm #29052I was dumped array date range of widget Campaigns By Close Revenue, and this is result
12345678array(6) {["start"]=> object(Carbon\Carbon)#22534 (3) { ["date"]=> string(19) "2015-12-31 17:00:00" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }["end"]=> object(Carbon\Carbon)#22525 (3) { ["date"]=> string(19) "2016-12-31 16:59:59" ["timezone_type"]=> int(3) ["timezone"]=> string(3) "UTC" }["type"]=> int(11)["part"]=> NULL["prev_start"]=> NULL["prev_end"]=> NULL}It’s not like my date range when I save in database. But I couldn’t found where this function call
123$this->get('oro_dashboard.widget_configs')->getWidgetOptions($this->getRequest()->query->get('_widgetId', null))->get('dateRange')Then how can I convert my date range to array as above?
September 13, 2016 at 12:57 am #29053I was found function getConvertedValue() in class Oro\Bundle\DashboardBundle\Provider\Converters\FilterDateRangeConverter, that function convert data date range to array like last comment.
I call this function with my dateRange and 3 parameter array null. I think it’s not best idea but still now, it’s work fine :)
But I have different question:
When I use Entity Repository, I create function for return 1 queryBuilder but when I call this function to use, my IDE show error cant not found in \Doctrine\Common\Persistence\ObjectRepository. What happend there?
My code include:
Entity Repository:123456789101112131415/*** @param string $orderAlias* @return QueryBuilder*/public function getOrderTestQB($orderAlias) {$qb = $this->getEntityManager()->createQueryBuilder();$qb->select(sprintf('%s.doc_date', $orderAlias),sprintf('%s.amount', $orderAlias))->from('TnaPosBundle:Order', $orderAlias);return $qb;}And where I call function:
1234567891011121314/*** @param array $dateRange* @return array*/public function getOrderData(array $dateRange) {$qb = $this->getOrderRepository()->getOrderTestQB('o');$this->dateFilterProcessor->process($qb, $dateRange, 'o.doc_date');return $this->aclHelper->apply($qb)->getArrayResult();}public function getOrderRepository() {return $this->registry->getRepository('TnaPosBundle:Order');}I was followed code in core.
September 19, 2016 at 7:46 am #29054Hi,
Can you show me please more detailed error message with stack trace? Also i want to know content of getOrderRepository() function.
Does your order entity contain @ORM\Entity(repositoryClass=”Oro\Bundle\EmailBundle\Entity\Repository\EmailRepository”) annotation ?
September 19, 2016 at 11:19 pm #29055Right, I’m not have annotation @ORM\Entity(repositoryClass=”Oro\Bundle\EmailBundle\Entity\Repository\EmailRepository”) in my entity class.
Thanks for reply! - AuthorReplies
The forum ‘OroCRM – How do I? Questions’ is closed to new topics and replies.