Fix start/offset/limit

This commit is contained in:
Miles Lott 2001-03-22 02:39:38 +00:00
parent c5e34d10b5
commit 1bafd75341

View File

@ -362,17 +362,17 @@
// This logic allows you to limit rows, or not. // This logic allows you to limit rows, or not.
// The export feature, for example, does not limit rows. // The export feature, for example, does not limit rows.
// This way, it can retrieve all rows at once. // This way, it can retrieve all rows at once.
/* if ($start && $offset) { if ($start && $offset) {
$limit = $this->db->limit($start,$offset); //$limit = $this->db->limit($start,$offset);
} elseif ($start && !$offset) { } elseif ($start && !$offset) {
$limit = ""; $limit = "";
} elseif(!$start && !$offset) { } elseif(!$start && !$offset) {
$limit = ""; $limit = $this->total_records;
} else { #(!$start && $offset) { } else { #(!$start && $offset) {
$start = 0; $start = 0;
$limit = $this->db->limit($start,$offset); //$limit = $this->db->limit($start,$offset);
} }
*/
$this->db3 = $this->db2 = $this->db; // Create new result objects before our queries $this->db3 = $this->db2 = $this->db; // Create new result objects before our queries
/* /*
if ($query) { if ($query) {
@ -403,28 +403,41 @@
} }
*/ */
$sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "phpgwowner=*".$owner); $sri = ldap_search($this->ldap, $phpgw_info["server"]["ldap_contact_context"], "phpgwowner=*");
$ldap_fields = ldap_get_entries($this->ldap, $sri); $ldap_fields = ldap_get_entries($this->ldap, $sri);
$this->total_records = ldap_count_entries($this->ldap, $sri); $this->total_records = ldap_count_entries($this->ldap, $sri);
// $end = $offset - $start; // This logic allows you to limit rows, or not.
// 92 records minus 0 = 92. // The export feature, for example, does not limit rows.
// 92 records minus 15 = 77. // This way, it can retrieve all rows at once.
$end = $start + $offset; if ($start && $offset) {
echo $end; $limit = $start + $offset;;
} elseif ($start && !$offset) {
$limit = $start;
} elseif(!$start && !$offset) {
$limit = $this->total_records;
} else { #(!$start && $offset) {
$start = 0;
$limit = $offset;
}
//echo '('.$start.','.$limit.')';
reset($ldap_fields); reset($ldap_fields);
for ($i=$start;$i<$end;$i++) { $j=0;
for ($i=$start;$i<$limit;$i++) {
if ($i<$this->total_records && $ldap_fields[$i]["uid"][0]) {
//echo '<br>j:'.$j;
// unique id, lid for group/account records, // unique id, lid for group/account records,
// type id (g/u) for groups/accounts, and // type id (g/u) for groups/accounts, and
// id of owner/parent for the record // id of owner/parent for the record
$return_fields[$i]["id"] = $ldap_fields[$i]["uidnumber"][0]; $return_fields[$j]["id"] = $ldap_fields[$i]["uidnumber"][0];
$return_fields[$i]["lid"] = $ldap_fields[$i]["uid"][0]; $return_fields[$j]["lid"] = $ldap_fields[$i]["uid"][0];
$return_fields[$i]["tid"] = $ldap_fields[$i]["phpgwcontacttype"][0]; $return_fields[$j]["tid"] = $ldap_fields[$i]["phpgwcontacttype"][0];
$return_fields[$i]["owner"] = $ldap_fields[$i]["phpgwowner"][0]; $return_fields[$j]["owner"] = $ldap_fields[$i]["phpgwowner"][0];
if (gettype($stock_fieldnames) == "array") { if (gettype($stock_fieldnames) == "array") {
while (list($f_name,$f_value) = each($stock_fieldnames)) { while (list($f_name,$f_value) = each($stock_fieldnames)) {
$return_fields[$i][$f_name] = $ldap_fields[$i][$f_value][0]; $return_fields[$j][$f_name] = $ldap_fields[$i][$f_value][0];
} }
reset($stock_fieldnames); reset($stock_fieldnames);
} }
@ -434,9 +447,11 @@
// If its not in the list to be returned, don't return it. // If its not in the list to be returned, don't return it.
// This is still quicker then 5(+) separate queries // This is still quicker then 5(+) separate queries
if ($extra_fields[$this->db2->f("contact_name")]) { if ($extra_fields[$this->db2->f("contact_name")]) {
$return_fields[$i][$this->db2->f("contact_name")] = $this->db2->f("contact_value"); $return_fields[$j][$this->db2->f("contact_name")] = $this->db2->f("contact_value");
} }
} }
$j++;
}
} }
return $return_fields; return $return_fields;
} }