Example #1
0
File: row.php Project: nikis/Go
 /**
  * Check if data is duplicated
  * @return Row
  */
 public function isDuplicate($create = false)
 {
     $fields = $this->table->unique();
     $dat = array();
     if ($create) {
         // if we add new row
         foreach ($fields as $field) {
             if (isset($this->data[$field])) {
                 $dat[$field] = $this->data[$field];
             }
         }
     } else {
         foreach ($fields as $field) {
             if (isset($this->data[$field]) && isset($this->modifiedData[$field])) {
                 $dat[$field] = $this->data[$field];
             }
         }
     }
     if (empty($dat)) {
         return false;
     }
     $builder = $this->table->builder();
     foreach ($dat as $key => $val) {
         $builder->where($key, '=', $val);
     }
     $row = $this->table->first($builder);
     return $row->isEmpty() ? false : $row;
 }