tableName = DB_PREFIX_SERVICE.'DocItem'; $this->id_doc = intval($id_doc); $this->DBObj(); } function getDelimiter() { return ':'; } function getTypes() { $tableName = $this->tableNameDB.'Type'; $sql = "SELECT name, title FROM {$tableName}"; return $this->db->queryAll($sql, null, MDB2_FETCHMODE_ASSOC, true); } function _getJoin4Grid() { return "INNER JOIN {$this->tableNameDB}Type AS {$this->tableName}Type ON {$this->tableName}Type.name = {$this->tableName}.type"; } function _getWhat4Grid() { return parent::_getWhat4Grid().", {$this->tableName}type.title AS type"; } function delete() { $this->_initTable(); $this->table->delete('id_doc = '. $this->db->quote($this->id_doc, 'integer')); } function getList() { $sql = "SELECT CONCAT({$this->tableName}Type.name, '".DocItem::getDelimiter()."', {$this->tableName}.name ) AS id, CONCAT({$this->tableName}Type.title, '".DocItem::getDelimiter()."', {$this->tableName}.name ) AS title FROM {$this->tableNameDB} AS {$this->tableName} ".$this->_getJoin4Grid()." WHERE {$this->tableName}.id_doc != 0 AND {$this->tableName}.id_doc = ".$this->db->quote($this->id_doc, 'integer')." ORDER BY {$this->tableName}.sorder "; $list = $this->db->queryAll($sql, null, MDB2_FETCHMODE_ASSOC, true); if (PEAR::isError($list)){ $GLOBALS['_DEBUG']['level'] = D_ECHO; dump($list->getUserInfo(), 'docItem->getList error'); } return $list; } function save($list) { $this->_initTable(); $this->delete(); if (is_array($list)){ $types = array_keys($this->getTypes()); foreach ($list as $sorder => $item) { list($type, $name) = explode(DocItem::getDelimiter(), $item); if (!in_array($type,$types)){ continue; } $data = array( 'id_doc' => $this->id_doc, 'type' => $type, 'name' => $name, 'sorder' => $sorder, ); $this->insert($data); } } return true; } function getNames() { $names = array(); $sql = "SELECT * FROM {$this->tableNameDB}Type "; $types = $this->db->queryAll($sql); foreach ($types as $type) { $names[ $type['name'] ]['title'] = $type['title']; $docItem = SiteMap::getObj(Doc::getClassPath($type['name']), $docItemArr) ; if (!is_null($docItem)) { $editable = intval(!is_null($docItem->editType)); $names[ $type['name'] ]['editable'] = $editable; if ( is_callable(array(&$docItem, 'getNames'))){ foreach ($docItem->getNames() as $name) { $key = $type['name'].DocItem::getDelimiter().$name; $names[ $type['name'] ]['items'][$key] = $name; } }else { $names[ $type['name'] ]['items'] = array($type['name'].DocItem::getDelimiter().'Nameless' => 'Nameless'); } } } return $names; } } ?>