More refactoring for subgroups.
[timetracker.git] / WEB-INF / lib / ttUser.class.php
index 457d230..587ca73 100644 (file)
@@ -59,7 +59,6 @@ class ttUser {
   var $punch_mode = 0;          // Whether punch mode is enabled for user.
   var $allow_overlap = 0;       // Whether to allow overlapping time entries.
   var $future_entries = 0;      // Whether to allow creating future entries.
-  var $uncompleted_indicators = 0; // Uncompleted time entry indicators (show nowhere or on users page).
   var $bcc_email = null;        // Bcc email.
   var $allow_ip = null;         // Specification from where user is allowed access.
   var $password_complexity = null; // Password complexity example.
@@ -142,7 +141,6 @@ class ttUser {
       $this->punch_mode = $config->getDefinedValue('punch_mode');
       $this->allow_overlap = $config->getDefinedValue('allow_overlap');
       $this->future_entries = $config->getDefinedValue('future_entries');
-      $this->uncompleted_indicators = $config->getDefinedValue('uncompleted_indicators');
       if ($this->isPluginEnabled('wu')) {
         $minutes_in_unit = $config->getIntValue('minutes_in_unit');
         if ($minutes_in_unit) $this->minutes_in_unit = $minutes_in_unit;
@@ -166,8 +164,13 @@ class ttUser {
     }
   }
 
+  // The getUser returns user id on behalf of whom the current user is operating.
+  function getUser() {
+    return ($this->behalf_id ? $this->behalf_id : $this->id);
+  }
+
   // The getGroup returns group id on behalf of which the current user is operating.
-   function getGroup() {
+  function getGroup() {
     return ($this->behalfGroup ? $this->behalfGroup->id : $this->group_id);
   }
 
@@ -196,9 +199,13 @@ class ttUser {
     return ($this->behalfGroup ? $this->behalfGroup->config : $this->config);
   }
 
-  // The getActiveUser returns user id on behalf of whom the current user is operating.
-  function getActiveUser() {
-    return ($this->behalf_id ? $this->behalf_id : $this->id);
+  // getConfigOption returns true if an option is defined for group.
+  // This helps us keeping a set of user attributes smaller.
+  // We determine whether the option is set only on pages that need to know.
+  // For example: confirm_save is used only on time and expense edit pages.
+  function getConfigOption($name) {
+    $config = new ttConfigHelper($this->getConfig());
+    return $config->getDefinedValue($name);
   }
 
   // can - determines whether user has a right to do something.
@@ -223,11 +230,14 @@ class ttUser {
     $result = array();
     $mdb2 = getConnection();
 
-    $group_id = $this->behalf_group_id ? $this->behalf_group_id : $this->group_id;
+    $group_id = $this->getGroup();
+    $org_id = $this->org_id;
+    $user_id = $this->getUser();
+
     // Do a query with inner join to get assigned projects.
-    $sql = "select p.id, p.name, p.description, p.tasks, upb.rate from tt_projects p
-      inner join tt_user_project_binds upb on (upb.user_id = ".$this->getActiveUser()." and upb.project_id = p.id and upb.status = 1)
-      where p.group_id = $group_id and p.status = 1 order by p.name";
+    $sql = "select p.id, p.name, p.description, p.tasks, upb.rate from tt_projects p".
+      " inner join tt_user_project_binds upb on (upb.user_id = $user_id and upb.project_id = p.id and upb.status = 1)".
+      " where p.group_id = $group_id and p.org_id = $org_id and p.status = 1 order by p.name";
     $res = $mdb2->query($sql);
     if (!is_a($res, 'PEAR_Error')) {
       while ($val = $res->fetchRow()) {
@@ -281,9 +291,12 @@ class ttUser {
 
     $mdb2 = getConnection();
 
+    $group_id = $this->getGroup();
+    $org_id = $this->org_id;
+
     // Get active clients for group.
     $clients = array();
-    $sql = "select id, name, address, projects from tt_clients where group_id = $this->group_id and status = 1";
+    $sql = "select id, name, address, projects from tt_clients where group_id = $group_id and org_id = $org_id and status = 1";
     $res = $mdb2->query($sql);
     if (!is_a($res, 'PEAR_Error')) {
       while ($val = $res->fetchRow()) {
@@ -733,7 +746,7 @@ class ttUser {
       $user_part .= ' <span class="onBehalf">'.$i18n->get('label.on_behalf').' '.htmlspecialchars($this->behalf_name).'</span>';
     }
     if ($this->behalf_group_id) {
-      $user_part .= ',  <span class="onBehalf">'.$i18n->get('label.on_behalf').' '.htmlspecialchars($this->behalf_group_name).'</span>';
+      $user_part .= ',  <span class="onBehalf">'.htmlspecialchars($this->behalf_group_name).'</span>';
     } else {
       if ($this->group_name) // Note: we did not require group names in the past.
         $user_part .= ', '.$this->group_name;