예제 #1
0
 function makeDistinct($ar_limit)
 {
     $colNames = $this->getColumnNames();
     // calc limit
     if (!isset($ar_limit[0]) && !isset($ar_limit[1])) {
         $limit = -1;
     } else {
         if (count($ar_limit) > 1) {
             $limit = $ar_limit[0] + $ar_limit[1];
         } else {
             $limit = $ar_limit[0];
         }
     }
     $rs = new ResultSet();
     $rs->copyColumData($this);
     $distinctRows = array();
     $this->reset();
     while (++$this->pos < count($this->rows)) {
         $currentValues = array();
         foreach ($colNames as $col) {
             array_push($currentValues, md5($this->getCurrentValueByName($col)));
         }
         $joinedValues = join("-", $currentValues);
         if (!array_key_exists($joinedValues, $distinctRows)) {
             $distinctRows[$joinedValues] = 1;
             $rs->append(false);
             $rs->rows[$rs->pos]->fields = $this->rows[$this->pos]->fields;
             $rs->rows[$rs->pos]->id = $this->rows[$this->pos]->id;
         }
         if ($limit != -1) {
             if ($rs->getRowCount() >= $limit) {
                 break;
             }
         }
     }
     --$this->pos;
     return $rs;
 }