dougua2309 2014-01-18 18:29
浏览 17
已采纳

Symfony2我应该在哪里为记录实体生成的仪表板页面跟踪统计信息?

In my Symfony2 project I have an entity type called "question".

Questions originate from a finite number of sources, at the moment there are two sources.

I want to build a dashboard page just to give an overview of how many questions are coming in from each source. EG: Total questions from source in last hour, last 24 hours, average number of questions per minute, per hour, per day, per week. This weeks total vs. last weeks total. Etc. etc.

I'm not sure what the neatest way to do this is to fit with Symfony2's architecture. Should I add my custom queries to my QuestionRepository? Or, should I just create a custom service called something like QuestionReports, and add custom queries to it? Or...something else?

Thank you!

  • 写回答

1条回答 默认 最新

  • douguxun6866 2014-01-20 11:27
    关注

    I suggest you to keep a simple solution, add new methods in your QuestionRepository, for example getQuestionsFrom($dateStart), getAverageNumberOfQuestionsPer($period), etc.

    Then call these methods in your controller and pass the results as parameters:

    public function dashboardAction()
    {
        $dt = new \Datetime("now");
        $dt->modify('-1 hour');
    
        $questions_from_last_hour = $this->getDoctrine()
            ->getRepository('AcmeWebsiteBundle:Question')
            ->getQuestionsFrom($dt);
    
        $dt = new \Datetime("now");
        $dt->modify('-24 hour');
    
        $questions_from_last_24h = $this->getDoctrine()
            ->getRepository('AcmeWebsiteBundle:Question')
            ->getQuestionsFrom($dt);
    
        // ...
    
        $twig_template = 'AcmeWebsiteBundle:Default:dashboard.html.twig';
    
        return $this->render($twig_template,
            array(
                'questions_from_last_hour' => $questions_from_last_hour,
                'questions_from_last_24h' => $questions_from_last_24h,
                // ...
            )
        );
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 请问如何在openpcdet上对KITTI数据集的测试集进行结果评估?
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失
  • ¥60 要数控稳压电源测试数据
  • ¥15 能帮我写下这个编程吗
  • ¥15 ikuai客户端l2tp协议链接报终止15信号和无法将p.p.p6转换为我的l2tp线路
  • ¥15 phython读取excel表格报错 ^7个 SyntaxError: invalid syntax 语句报错