first_name.' '.$this->last_name; } protected $cardsCount = array(); protected $avgDays = array(); protected $commisionSum = array(); /** * Zjistí počet případů v zadaném období * * @param date $from * @param date $to * @return integer */ public function getCardsCount($from = null, $to =null) { if(isset($this->cardsCount[$from.'@'.$to])) { return $this->cardsCount[$from.'@'.$to]; } $query = Doctrine::getTable('Card')->createQuery() ->addWhere('user_id = ?', $this->getUserId()); if(!is_null($from)) { $query->addWhere('case_end_date >= ?', $from); } if(!is_null($to)) { $query->addWhere('case_end_date <= ?', $to); } $this->cardsCount[$from.'@'.$to] = $query->count(); return $query->count(); } /** * Zjistí pruměrný počet dní trvání případů v zadaném období * * @param date $from * @param date $to * @return integer */ public function getAvgDays($from = null, $to =null) { if(isset($this->avgDays[$from.'@'.$to])) { return $this->avgDays[$from.'@'.$to]; } $query = Doctrine::getTable('Card')->createQuery('c') ->leftJoin('c.Attachments a') ->addWhere('c.user_id = ?', $this->getUserId()); if(!is_null($from)) { $query->addWhere('c.case_end_date >= ?', $from); } if(!is_null($to)) { $query->addWhere('c.case_end_date <= ?', $to); } $result = $query->select('avg(TO_DAYS(c.case_end_date) - TO_DAYS(IFNULL(a.requisition_date, c.created_at))) as avg_days') ->groupBy('user_id') ->fetchArray(); $this->avgDays[$from.'@'.$to] = isset($result[0]['avg_days']) ? round($result[0]['avg_days']) : 0; return $this->avgDays[$from.'@'.$to]; } /** * Zjistí provizi získanou uživatelem v daném období * * @param date $from * @param date $to * @return integer */ public function getCommisionSum($from = null, $to =null) { if(isset($this->commisionSum[$from.'@'.$to])) { return $this->commisionSum[$from.'@'.$to]; } $query = Doctrine::getTable('Card')->createQuery() ->addWhere('user_id = ?', $this->getUserId()); if(!is_null($from)) { $query->addWhere('case_end_date >= ?', $from); } if(!is_null($to)) { $query->addWhere('case_end_date <= ?', $to); } $result = 0; foreach($query->execute() as $card) { $balance = $card->getBalance(); $result += $balance['costs']; } $this->commisionSum[$from.'@'.$to] = round($result); return $this->commisionSum[$from.'@'.$to]; } }