예제 #1
0
 /**
  * Get all the values for the current project and sub-projects and return 3 array:
  * 1. With Projects names.
  * 2. With users names.
  * 3. Relations Projects-User-Bookings.
  *
  * @param string  $startDate Start date for make the query.
  * @param string  $endDate   End date for make the query.
  * @param integer $projectId Current Project ID.
  *
  * @return array Array with 'users', 'projects' and 'rows'.
  */
 public function getStatistics($startDate, $endDate, $projectId)
 {
     $data['data'] = array();
     $data['data']['users'] = array();
     $data['data']['projects'] = array();
     $data['data']['rows'] = array();
     // Get Sub-Projects
     $activeRecord = new Project_Models_Project();
     $tree = new Phprojekt_Tree_Node_Database($activeRecord, $projectId);
     $tree = $tree->setup();
     $projectsId = array(0);
     foreach ($tree as $node) {
         if ($node->id) {
             $projectsId[] = (int) $node->id;
             $data['data']['projects'][$node->id] = $node->getDepthDisplay('title');
         }
     }
     // Get Timecard
     $model = new Timecard_Models_Timecard();
     $where = sprintf('(DATE(start_datetime) >= %s AND DATE(start_datetime) <= %s AND project_id IN (%s))', $model->_db->quote($startDate), $model->_db->quote($endDate), implode(", ", $projectsId));
     $records = $model->fetchAll($where);
     $users = new Phprojekt_User_User();
     foreach ($records as $record) {
         if (!isset($data['data']['users'][$record->ownerId])) {
             $user = $users->findUserById($record->ownerId);
             $data['data']['users'][$record->ownerId] = $user->username;
         }
         if (!isset($data['data']['rows'][$record->projectId][$record->ownerId])) {
             $data['data']['rows'][$record->projectId][$record->ownerId] = 0;
         }
         $data['data']['rows'][$record->projectId][$record->ownerId] += $record->minutes;
     }
     return $data;
 }
예제 #2
0
 /**
  * Test found user by id
  */
 public function testUserId()
 {
     $user = new Phprojekt_User_User(array('db' => $this->sharedFixture));
     $clone = $user->findUserById(1);
     $this->assertEquals('Test', $clone->username);
     $clone = $user->findUserById(0);
     $this->assertEquals('', $clone->username);
 }
예제 #3
0
 protected static function _setEffectiveUserById($userId)
 {
     $user = new Phprojekt_User_User();
     self::$_effectiveUser = $user->findUserById($userId);
 }
예제 #4
0
 public static function getRealUser()
 {
     static $user = null;
     if (null === $user) {
         $u = new Phprojekt_User_User();
         $user = $u->findUserById(Phprojekt_Auth::getUserId());
     }
     return $user;
 }