Rewrote group dropdown fill function to include the entire tree.
[timetracker.git] / WEB-INF / lib / ttUser.class.php
index 16e2d2d..8f9578d 100644 (file)
@@ -55,7 +55,6 @@ class ttUser {
   var $date_format = null;      // Date format.
   var $time_format = null;      // Time format.
   var $week_start = 0;          // Week start day.
-  var $show_holidays = 0;       // Whether to show holidays in calendar.
   var $tracking_mode = 0;       // Tracking mode.
   var $project_required = 0;    // Whether project selection is required on time entires.
   var $task_required = 0;       // Whether task selection is required on time entires.
@@ -148,7 +147,6 @@ class ttUser {
       $this->configHelper = new ttConfigHelper($val['config']);
 
       // Set user config options.
-      $this->show_holidays = $this->configHelper->getDefinedValue('show_holidays');
       $this->punch_mode = $this->configHelper->getDefinedValue('punch_mode');
       $this->allow_overlap = $this->configHelper->getDefinedValue('allow_overlap');
       $this->future_entries = $this->configHelper->getDefinedValue('future_entries');
@@ -205,6 +203,11 @@ class ttUser {
     return ($this->behalfGroup ? $this->behalfGroup->time_format : $this->time_format);
   }
 
+  // getWeekStart returns week start day for active group.
+  function getWeekStart() {
+    return ($this->behalfGroup ? $this->behalfGroup->week_start : $this->week_start);
+  }
+
   // getTrackingMode returns tracking mode for active group.
   function getTrackingMode() {
     return ($this->behalfGroup ? $this->behalfGroup->tracking_mode : $this->tracking_mode);
@@ -245,6 +248,11 @@ class ttUser {
     return ($this->behalfGroup ? $this->behalfGroup->configHelper->getConfig() : $this->configHelper->getConfig());
   }
 
+  // getConfigHelper returns ttConfigHelper instance for active group.
+  function getConfigHelper() {
+    return ($this->behalfGroup ? $this->behalfGroup->configHelper : $this->configHelper);
+  }
+
   // 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.
@@ -552,6 +560,38 @@ class ttUser {
     return $groups;
   }
 
+  // getGroupsForDropdown2 obtains an array of groups to populate the "Group" dropdown.
+  // It consists of the entire tree starting from user home group down.
+  // Group name is prefixed with additional characters to indicate subgroups level.
+  function getGroupsForDropdown2() {
+    global $user;
+
+    // Start with user home group.
+    $groups = array();
+    $subgroup_level = 0;
+    $group_id = $user->group_id;
+
+    $this->addGroup($groups, $group_id, $subgroup_level);
+    return $groups;
+  }
+
+  // addGroup is a recursive function to populate a tree of groups.
+  function addGroup(&$groups, $group_id, $subgroup_level) {
+    // Add indentation markup to indicate subdirectory level.
+    for ($i = 0; $i < $subgroup_level; $i++) {
+      $name .= '🛑'; // Unicode stop sign.
+    }
+    if ($subgroup_level) $name .= ' '; // Add an extra space.
+    $name .= ttGroupHelper::getGroupName($group_id);
+
+    $groups[] = array('id'=>$group_id, 'name'=>$name);
+
+    $subgroups = $this->getSubgroups($group_id);
+    foreach($subgroups as $subgroup) {
+      $this->addGroup($groups, $subgroup['id'], $subgroup_level+1);
+    }
+  }
+
   // getSubgroups obtains a list of immediate subgroups.
   function getSubgroups($group_id = null) {
     $mdb2 = getConnection();