id_fm = intval($id_fm); parent::DBObj($id); } function getTypes() { $sql = "SELECT * FROM {$this->tableNameDB}Type "; return $this->db->queryAll($sql, null, MDB2_FETCHMODE_ASSOC, true); } function getValidators() { $sql = "SELECT * FROM {$this->tableNameDB}Validator "; return $this->db->queryAll($sql, null, MDB2_FETCHMODE_ASSOC, true); } function initFromArray($data, $files = null) { $data['id_fm'] = $this->id_fm; return parent::initFromArray($data, $files); } function initFromDB() { parent::initFromDB(); $this->id_fm = $this->getData('id_fm'); } function _initLabel($id = null) { if (is_null($id)) { $id = $this->id; } require_once ('class/DB/Lang/Content.php'); $this->label = new LangContent($this->tableName . 'Label', $id, 'label'); } function insert($data = null) { parent::insert($data); $this->_initLabel(); $this->label->save($this->_data); $this->saveValid($this->_data['valid']); $this->saveValue($this->_data['value']); $sql = "SELECT MAX(sorter) FROM {$this->tableNameDB} WHERE id_fm = " . $this->db->quote($this->id_fm); $sorter = $this->db->queryOne($sql) + 1; $this->table->update(array('sorter' => $sorter), 'id = ' . $this->db->quote($this->id)); return $this->id; } function _initTable() { parent::_initTable(); if (!is_object($this->valid)) { require_once ('class/DB/DBTable.php'); $this->valid = new DBTable($this->tableName . 'Valid'); $this->value = new DBTable($this->tableName . 'Value'); } return true; } function saveValid($list, $id_fmf = null) { $this->_initTable(); if (is_null($id_fmf)) { $id_fmf = $this->id; } $this->valid->delete('id_fmf = ' . $this->db->quote($id_fmf)); foreach ((array) $list as $sorter => $validator) { $data = array('id_fmf' => $id_fmf, 'validator' => $validator, 'sorter' => $sorter); $this->valid->insert($data); } } function saveValue($list, $id_fmf = null) { $this->_initTable(); if (is_null($id_fmf)) { $id_fmf = $this->id; } $this->value->delete('id_fmf = ' . $this->db->quote($id_fmf)); require_once 'class/DB/Lang/DLang.php'; $DLang = new DLang(); foreach ($DLang->getList() as $lang) { $lang = $lang['name']; foreach ((array) $list[$lang] as $sorter => $value) { $data = array('id_fmf' => $id_fmf, 'lang' => $lang, 'value' => $value, 'sorter' => $sorter); $this->value->insert($data); } } ; return true; } function delete() { parent::delete(); $this->_initLabel(); $this->label->delete(); } function update($data = null, $files = null) { parent::update($data); $this->_initLabel(); $this->label->save($this->_data); $this->saveValid($this->_data['valid']); $this->saveValue($this->_data['value']); return true; } function _getWhat4Grid() { return parent::_getWhat4Grid() . ", {$this->tableName}Type.name AS type_name, {$this->tableName}Type.title AS type, {$this->tableName}Label.label AS label, IF ({$this->tableName}.show_in_list = 'y', 'Yes', 'No') AS show_in_list_title "; } function _getJoin4Grid($opt) { $DLangTbl = 'tbl' . DB_PREFIX_SERVICE . 'DLang'; $DLangTbl = $this->db->$DLangTbl; return " INNER JOIN {$this->tableNameDB}Type AS {$this->tableName}Type ON {$this->tableName}Type.name = {$this->tableName}.type LEFT JOIN {$this->tableNameDB}Label AS {$this->tableName}Label ON {$this->tableName}Label.id_parent = {$this->tableName}.id INNER JOIN {$DLangTbl} AS DLang ON DLang.name = {$this->tableName}Label.lang "; if (is_null($opt['lang'])) { $join .= " AND DLang.def = 'y' "; } else { $join .= " AND DLang.name = " . $this->db->quote($lang); } } function getFromDB($id, $field = false) { $res = parent::getFromDB($id); $this->_initLabel($id); $res = $res + $this->label->get(); $sql = "SELECT validator FROM {$this->tableNameDB}Valid WHERE id_fmf = " . $this->db->quote($id) . ' ORDER BY sorter'; $res['valid'] = $this->db->queryCol($sql); $sql = "SELECT * FROM {$this->tableNameDB}Value WHERE id_fmf = " . $this->db->quote($id) . ' ORDER BY sorter'; foreach ($this->db->queryAll($sql) as $val) { $lang = $val['lang']; $res['value'][$lang][] = $val['value']; } // vdie($res['value'], $this->db->queryAll($sql)); // $res['value'] = $this->db->queryAll($sql); return $this->getSubElem($res, $field); } function _getGroup4Grid() { return " GROUP BY {$this->tableName}.id"; } function _getWhere4Grid() { //dump(parent::_getWhere4Grid()." AND ({$this->tableName}.id_fm = ".$this->db->quote($this->id_fm)." OR {$this->tableName}.id_fm=". //(strpos(CURR_PAGE,'admin')===false?"1":'3').')'); $cWhere = parent::_getWhere4Grid() . " AND ({$this->tableName}.id_fm = " . $this->db->quote($this->id_fm); if (strpos(CURR_PAGE, 'admin') === false) $cWhere .= " OR {$this->tableName}.id_fm=1"; if ($_REQUEST['action']=='add_attendee' || $_REQUEST['action']=='getEventInfo') $cWhere .= " OR {$this->tableName}.id_fm=3"; $cWhere .= ")"; return $cWhere; } function getErrorMsg($valid, $lang, $label) { static $errors; if (!isset($errors[$valid][$lang])) { $sql = "SELECT msg FROM {$this->tableNameDB}ErrorMsg WHERE valid = " . $this->db->quote($valid) . ' AND lang = ' . $this->db->quote( $lang); $errors[$valid][$lang] = $this->db->queryOne($sql); } return str_replace('{name}', $label, $errors[$valid][$lang]); } function reorder($list) { $this->_initTable(); foreach ((array) $list as $sorter => $id) { $this->table->update(array('sorter' => $sorter), 'id = ' . $this->db->quote($id) . ' AND id_fm = ' . $this->db->quote($this->id_fm)); } return true; } function chngShowingInList() { if ('y' == $this->getFromDB($this->id, 'show_in_list')) { $show_in_list = 'n'; } else { $show_in_list = 'y'; } $this->_initTable(); $this->table->update(array('show_in_list' => $show_in_list), 'id = ' . $this->db->quote($this->id)); return true; } function getformName() { return $this->db->queryOne('SELECT name FROM mn_EventForm WHERE id=' . $this->id_fm); } } ?>