DBObj($id); } function setFilter($filter) { $this->_filterQuery = (array) $filter; } function _filterSql() { $sql = (string) DBObj_Filter::perseQr($this->db, $this->_filterFields, (string) $this->_filterQuery['query']); foreach ($this->_filterQuery as $field => $value) { if (empty($value)) { continue; } switch($field) { case 'active': $value = ($value == 'y') ? 'true' : 'false'; $sql = " AND IF ({$this->tableName}.start_date <= CURDATE() AND {$this->tableName}.end_date >= CURDATE(), true, false) = {$value}"; break; case 'id_availability': $sql .= " AND {$this->tableName}.{$field} = " . (int) $value; break; } } return $sql; } function initFromForm(&$form) { $files = array(); $files['photo'] = $form->getElementValue('photo'); $data = $form->exportValues(); $data['start_date'] = $this->formaCalendartDate($data['start_date']); $data['end_date'] = $this->formaCalendartDate($data['end_date']); $this->arrayParseUrl2Tag($data); $this->initFromArray($data, $files); return true; } function delete() { $this->_deleteHistory(); $this->_files = array('photo' => array('del' => 1)); parent::delete(); return true; } function _deleteHistory() { $sql = "delete from {$this->tableNameDB}History where id_parent = " . (int) $this->id; return $this->db->query($sql); } function uniqueUser() { $time = time() - $this->timeUserClickInterval; $sql = "SELECT COUNT(*) FROM {$this->tableNameDB}History WHERE id_parent = " . (int) $this->id . " AND ip = " . $this->db->quote($_SERVER['REMOTE_ADDR']) . " AND UNIX_TIMESTAMP(added) > {$time}"; $res = $this->db->queryOne($sql); $this->_sqlError($res); return !(bool)$res; } function click() { if (!$this->uniqueUser()) { return false; } $History = new DBTable($this->tableName . 'History'); $historyData = array( 'id_parent' => intval($this->id), 'id_individual' => intval(MemberAuth::getSessionData('id')), 'ip' => strval($_SERVER['REMOTE_ADDR']), 'user_agent' => strval($_SERVER['HTTP_USER_AGENT']), 'page' => BASE_URL . '/' . CURR_PAGE . ((empty($_SERVER['QUERY_STRING'])) ? '' : '?' . $_SERVER['QUERY_STRING']), ); $History->insert($historyData); $this->initFromDB(); $data = array( 'total_cnt' => (int) $this->getData('total_cnt') + 1, 'last_month_cnt' => $this->getLastMonthCnt() ); $this->_initTable(); $this->table->update($data, 'id = ' . (int) $this->id); $this->db->query($sql); $this->_sqlError($res); } function getLastMonthCnt() { $time = time() - $this->timeInterval; $sql = "SELECT COUNT(*) FROM {$this->tableNameDB}History WHERE id_parent = " . (int) $this->id . " AND UNIX_TIMESTAMP(added) >= {$time}"; $res = $this->db->queryOne($sql); $this->_sqlError($res); return (int) $res; } function clearOldHistory() { $time = time() - $this->timeInterval; $sql = "DELETE FROM {$this->tableNameDB}History WHERE UNIX_TIMESTAMP(added) < {$time}"; $res = $this->db->query($sql); $this->_sqlError($res); } function formaCalendartDate($date) { return sprintf('%04d-%02d-%02d', $date['Y'], $date['M'], $date['d']); } function checkCalendarDate($date) { $y = (int) $date['Y']; $m = (int) $date['M']; $d = (int) $date['d']; if ($y && $m && $d) { return checkdate($m, $d, $y); } return false; } function _getWhat4Grid($opt = array()) { $what = parent::_getWhat4Grid($opt); $what .= ", IF(start_date <= curdate() AND end_date >= curdate(), 'Yes', 'No') AS active" . ", dpa.title AS availability_title"; return $what; } function _getJoin4Grid($opt = array()) { $join = parent::_getJoin4Grid($opt); $join .= "\nLEFT JOIN {$this->db->tblDFeaturedPropertyAvailability} AS dpa ON dpa.id = {$this->tableName}.id_availability"; return $join; } }