setTable( new UsersStatisticsTable()); } /** * * create or update a stat row * if a row that matches the ip, user agent and accept language exists in the table, update the row * otherwise insert a new row * * @param array $data * * @return $this */ public function save($data) { $row = null; $data = $this->_prepareSaveData($data); $select = $this->_table->select() ->where('remote_addr = ?', $data['remote_addr']) ->where('http_user_agent = ?', $data['http_user_agent']); $row = $this->_table->fetchRow($select); $data['updated_at'] = new Expr('now()'); if (count($row) > 0) { if (isset($data['http_referrer'])) { unset($data['http_referrer']); } $this->_table->update($data, "id='{$row['id']}'"); } else { $data['created_at'] = new Expr('now()'); $this->_table->insert($data); } return $this; } }