public function doaddAction() { $struct = $this->getInput('struct', 'post'); $pageid = $this->getInput('pageid', 'post'); $model = $this->getInput('model', 'post'); if (!$model || $pageid < 1) { $this->showError('operate.fail'); } Wekit::load('design.PwDesignPermissions'); $permissions = $this->_getPermissionsService()->getPermissionsForPage($this->loginUser->uid, $pageid); if ($permissions < PwDesignPermissions::IS_DESIGN) { $this->showError("DESIGN:permissions.fail"); } Wind::import('SRV:design.bo.PwDesignModelBo'); $bo = new PwDesignModelBo($model); if (!$bo->isModel()) { $this->showError('operate.fail'); } $name = trim($this->getInput('module_name', 'post')); if (empty($name)) { $this->showError('DESIGN:module.name.empty'); } $cache = $this->getInput('cache', 'post'); $property = $this->getInput('property', 'post'); isset($property['html']) && ($property['html'] = $this->_getDesignService()->filterTemplate($property['html'])); if ($property['limit'] > 200) { $this->showError('DESIGN:maxlimit.error'); } $cls = sprintf('PwDesign%sDataService', ucwords($model)); Wind::import('SRV:design.srv.model.' . $model . '.' . $cls); $service = new $cls(); $ds = $this->_getModuleDs(); Wind::import('SRV:design.dm.PwDesignModuleDm'); $dm = new PwDesignModuleDm(); $dm->setPageId($pageid)->setStruct($struct)->setFlag($model)->setName($name)->setCache($cache)->setModuleType(PwDesignModule::TYPE_DRAG)->setIsused(1); $resource = $ds->addModule($dm); if ($resource instanceof PwError) { $this->showError($resource->getError()); } $dm = new PwDesignModuleDm($resource); if (method_exists($service, 'decorateSaveProperty')) { $property = $service->decorateSaveProperty($property, $resource); if ($property instanceof PwError) { $this->showError($property->getError()); } } $dm->setProperty($property); if ($property['html_tpl']) { $dm->setModuleTpl($property['html_tpl']); } $r = $ds->updateModule($dm); if ($r instanceof PwError) { $this->showError($r->getError()); } Wind::import('SRV:design.srv.data.PwAutoData'); $srv = new PwAutoData($resource); $srv->addAutoData(); $this->setOutput($resource, 'data'); $this->showMessage("operate.success"); }
public function doaddAction() { $model = $this->getInput('model', 'post'); if (!$model) { $this->showError('operate.fail'); } Wind::import('SRV:design.bo.PwDesignModelBo'); $bo = new PwDesignModelBo($model); if (!$bo->isModel()) { $this->showError('operate.fail'); } $name = trim($this->getInput('module_name', 'post')); if (empty($name)) { $this->showError('DESIGN:module.name.empty'); } $cache = $this->getInput('cache', 'post'); $property = $this->getInput('property', 'post'); if ($property['limit'] > 200) { $this->showError('DESIGN:maxlimit.error'); } $cls = sprintf('PwDesign%sDataService', ucwords($model)); Wind::import('SRV:design.srv.model.' . $model . '.' . $cls); $service = new $cls(); if (method_exists($service, 'decorateSaveProperty')) { $property = $service->decorateSaveProperty($property); if ($property instanceof PwError) { $this->showError($property->getError()); } } $ds = $this->_getModuleDs(); Wind::import('SRV:design.dm.PwDesignModuleDm'); $dm = new PwDesignModuleDm(); $dm->setFlag($model)->setName($name)->setProperty($property)->setCache($cache)->setModuleType(PwDesignModule::TYPE_SCRIPT)->setIsused(1); if ($property['html_tpl']) { $dm->setModuleTpl($property['html_tpl']); } $resource = $ds->addModule($dm); if ($resource instanceof PwError) { $this->showError($resource->getError()); } $moduleid = (int) $resource; Wind::import('SRV:design.srv.data.PwAutoData'); $srv = new PwAutoData($moduleid); $srv->addAutoData(); //调用模块token $token = WindUtility::generateRandStr(10); $this->_getScriptDs()->addScript((int) $moduleid, $token, 0); $tab = array('property', 'template'); Wind::import('SRV:design.bo.PwDesignModelBo'); $bo = new PwDesignModelBo($model); $modelInfo = $bo->getModel(); if (is_array($modelInfo['tab'])) { foreach ($tab as $k => $v) { if (in_array($v, $modelInfo['tab'])) { $_tab[] = $tab[$k]; } } $tab = $_tab; } if (in_array('template', $tab)) { $this->showMessage("operate.success", "design/template/edit?isscript=1&moduleid=" . $moduleid, true); } else { $this->showMessage("operate.success", "design/module/run?type=api", true); } }