/** * 从A版块复制主题分类至B版块 * * @param int $fromFid * @param int $toFid */ public function copyTopicType($fromFid, $toFid) { $this->_getTopictypeDs()->deleteTopicTypeByFid($toFid); $topicTypes = $this->_getTopictypeDs()->getTypesByFid($fromFid); $idMap = $subTopicTypes = array(); Wind::import('SRV:forum.dm.PwTopicTypeDm'); foreach ($topicTypes as $k => $v) { if ($v['parentid']) { $subTopicTypes[$k] = $v; continue; } $dm = new PwTopicTypeDm(); $dm->setFid($toFid)->setIsSystem($v['issys'])->setVieworder($v['vieworder'])->setLogo($v['logo'])->setName($v['name']); $id = $this->_getTopictypeDs()->addTopicType($dm); $idMap[$v['id']] = $id; } if ($subTopicTypes) { foreach ($subTopicTypes as $k => $v) { $dm = new PwTopicTypeDm(); $dm->setFid($toFid)->setIsSystem($v['issys'])->setVieworder($v['vieworder'])->setLogo($v['logo'])->setName($v['name'])->setParentId($idMap[$v['parentid']]); $this->_getTopictypeDs()->addTopicType($dm); } } return true; }
/** * 保存主题分类 * * @param $fid */ protected function doeditTopicType($fid) { //主题分类 list($t_vieworder, $t_name, $t_logo, $t_issys) = $this->getInput(array('t_vieworder', 't_name', 't_logo', 't_issys'), 'post'); list($t_new_vieworder, $t_new_name, $t_new_logo, $t_new_issys) = $this->getInput(array('t_new_vieworder', 't_new_name', 't_new_logo', 't_new_issys'), 'post'); list($t_new_sub_vieworder, $t_new_sub_name, $t_new_sub_logo, $t_new_sub_issys) = $this->getInput(array('t_new_sub_vieworder', 't_new_sub_name', 't_new_sub_logo', 't_new_sub_issys'), 'post'); is_array($t_name) || ($t_name = array()); is_array($t_new_name) || ($t_new_name = array()); is_array($t_new_sub_name) || ($t_new_sub_name = array()); Wind::import('SRV:forum.dm.PwTopicTypeDm'); $topicTypeService = Wekit::load('forum.PwTopicType'); /* @var $topicTypeService PwTopicType */ //$logos = $this->_uploadTopicTypeIcon(); $logos = array(); //TODO图标功能暂取消 /* 更新原有 */ $updateTopicTypes = array(); //待更新topicType Dm foreach ($t_name as $k => $v) { $dm = new PwTopicTypeDm($k); $dm->setFid($fid)->setVieworder($t_vieworder[$k])->setName($t_name[$k])->setIsSystem($t_issys[$k]); $logos['t_logo'][$k] && $dm->setLogo($logos['t_logo'][$k]['filename']); $result = $dm->beforeUpdate(); if ($result instanceof PwError) { $this->showError($result->getError()); } $updateTopicTypes[] = $dm; } /* 新增主题分类 */ $newTopicTypes = array(); if (!$t_new_name) { $t_new_name = array(); } foreach ($t_new_name as $k => $v) { if (!$v) { continue; } $dm = new PwTopicTypeDm(); $dm->setFid($fid)->setVieworder($t_new_vieworder[$k])->setName($t_new_name[$k])->setIsSystem($t_new_issys[$k]); $logos['t_new_logo'][$k] && $dm->setLogo($logos['t_new_logo'][$k]['filename']); $result = $dm->beforeAdd(); if ($result instanceof PwError) { $this->showError($result->getError()); } $newTopicTypes[$k] = $dm; } /* 新增二级主题分类 */ $newSubTopicTypes = array(); if (!$t_new_sub_name) { $t_new_sub_name = array(); } foreach ($t_new_sub_name as $parentId => $newSubs) { if (!is_array($newSubs)) { continue; } foreach ($newSubs as $k => $v) { $dm = new PwTopicTypeDm(); $dm->setFid($fid)->setVieworder($t_new_sub_vieworder[$parentId][$k])->setName($t_new_sub_name[$parentId][$k])->setIsSystem($t_new_sub_issys[$parentId][$k]); $logos['t_new_sub_logo'][$k] && $dm->setLogo($logos['t_new_sub_logo'][$k]['filename']); $result = $dm->beforeAdd(); if ($result instanceof PwError) { $this->showError($result->getError()); } $newSubTopicTypes[$parentId][] = $dm; } } /* 执行更新 */ foreach ($updateTopicTypes as $v) { $topicTypeService->updateTopicType($v); } /* 执行新增 */ $newTopicIds = array(); foreach ($newTopicTypes as $k => $v) { $topicId = $topicTypeService->addTopicType($v); is_numeric($topicId) && ($newTopicIds[$k] = $topicId); } foreach ($newSubTopicTypes as $k => $v) { if (!$k) { continue; } foreach ($v as $k2 => $v2) { $parentId = is_numeric($k) ? $k : $newTopicIds[$k]; if (!$parentId) { continue; } $v2->setParentId($parentId); $topicTypeService->addTopicType($v2); } } //end 主题分类 }