~porten-deactivatedaccount/eventum/devel

« back to all changes in this revision

Viewing changes to lib/eventum/class.report.php

  • Committer: Raul Raat
  • Date: 2010-02-10 13:30:36 UTC
  • mto: This revision was merged to the branch mainline in revision 4052.
  • Revision ID: raulraat@gmail.com-20100210133036-qycplv3twdh0sddf
- add Custom Fields Weekly Report

Show diffs side-by-side

added added

removed removed

Lines of Context:
774
774
 
775
775
        return $data;
776
776
    }
777
 
 
778
 
 
 
777
    /**
 
778
     * Returns data for the custom fields weekly report, based on the field and options passed in.
 
779
     *
 
780
     * @access  public
 
781
     * @param   integer $fld_id The id of the custom field.
 
782
     * @param   array $cfo_ids An array of option ids.
 
783
     * @param   string $start_date
 
784
     * @param   string $end_date
 
785
     * @return  array An array of data.
 
786
     */
 
787
    function getCustomFieldWeeklyReport($fld_id, $cfo_ids, $start_date, $end_date)
 
788
    {
 
789
        $prj_id = Auth::getCurrentProject();
 
790
        $fld_id = Misc::escapeInteger($fld_id);
 
791
        $cfo_ids = Misc::escapeInteger($cfo_ids);
 
792
        // get field values
 
793
        $options = Custom_Field::getOptions($fld_id, $cfo_ids);
 
794
 
 
795
        $sql = "SELECT
 
796
                    iss_id, 
 
797
                    SUM(ttr_time_spent) time_spent,
 
798
                    iss_summary,
 
799
                    iss_customer_id,
 
800
                    iss_private,
 
801
                    fld_id
 
802
                 FROM
 
803
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field, 
 
804
                    " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "time_tracking,";
 
805
            if (count($options) > 0) {
 
806
                $sql .= "
 
807
                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "custom_field_option,";
 
808
            }
 
809
            $sql .= "
 
810
                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_custom_field,
 
811
                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue,
 
812
                        " . APP_DEFAULT_DB . "." . APP_TABLE_PREFIX . "issue_user
 
813
                    WHERE
 
814
                        ttr_created_date BETWEEN '" . Misc::escapeString($start_date) . "' AND '" . Misc::escapeString($end_date) . "' AND
 
815
                        fld_id = icf_fld_id AND
 
816
                        ttr_iss_id = iss_id AND
 
817
                                ";
 
818
            if (count($options) > 0) {
 
819
                $sql .=
 
820
                        " cfo_id = icf_value AND";
 
821
            }
 
822
            $sql .= "
 
823
                        icf_iss_id = iss_id AND
 
824
                        isu_iss_id = iss_id AND
 
825
                        icf_fld_id = $fld_id";
 
826
            if (count($options) > 0) {
 
827
                $sql .= " AND
 
828
                        cfo_id IN('" . join("','", Misc::escapeString(array_keys($options))) . "')";
 
829
            }
 
830
            $sql .= "
 
831
                    GROUP BY
 
832
                        iss_id";
 
833
 
 
834
        $res = DB_Helper::getInstance()->getAll($sql, DB_FETCHMODE_ASSOC);
 
835
        if (PEAR::isError($res)) {
 
836
            Error_Handler::logError(array($res->getMessage(), $res->getDebugInfo()), __FILE__, __LINE__);
 
837
            return array();
 
838
        } else {
 
839
                for ($i = 0; $i < count($res); $i++) {
 
840
                $res[$i]['field_value'] = Custom_Field::getDisplayValue($res[$i]['iss_id'], $res[$i]['fld_id']);
 
841
                $res[$i]['time_spent_human'] = Misc::getFormattedTime($res[$i]['time_spent'], false);
 
842
            }
 
843
            return $res;
 
844
        }
 
845
    }
779
846
    /**
780
847
     * Returns workload information for the specified date range and interval.
781
848
     *