public function _show() { $oPosts = model_posts::getInstance()->findBySlug(module_posts::getParam('slug')); $oView = new _view('posts::show'); $oView->oPosts = $oPosts; $oView->tJoinmodel_categories = model_categories::getInstance()->getSelect(); $oView->tJoinmodel_users = model_users::getInstance()->getSelect(); //we instance the module $oModuleComments = new module_comments(); $oModuleComments->setPostId(module_posts::getParam('id')); //si vous souhaitez indiquer au module integrable des informations sur le module parent $oModuleComments->setRootLink('default::index', array('postsAction' => 'show', 'postsid' => _root::getParam('postsid'))); //form add $oView->oCommentsAdd = $oModuleComments->_new(); //comments $oView->oComments = $oModuleComments->_index(); return $oView; }
public function processSave() { if (!_root::getRequest()->isPost() or _root::getParam('formmodule') != self::$sModuleName) { //si ce n'est pas une requete POST on ne soumet pas return null; } $oPluginXsrf = new plugin_xsrf(); if (!$oPluginXsrf->checkToken(_root::getParam('token'))) { //on verifie que le token est valide return array('token' => $oPluginXsrf->getMessage()); } $iId = module_comments::getParam('id', null); if ($iId == null) { $oComments = new row_comments(); } else { $oComments = model_comments::getInstance()->findById(module_comments::getParam('id', null)); } $tId = model_comments::getInstance()->getIdTab(); $tColumn = model_comments::getInstance()->getListColumn(); foreach ($tColumn as $sColumn) { $oPluginUpload = new plugin_upload($sColumn); if ($oPluginUpload->isValid()) { $sNewFileName = _root::getConfigVar('path.upload') . $sColumn . '_' . date('Ymdhis'); $oPluginUpload->saveAs($sNewFileName); $oComments->{$sColumn} = $oPluginUpload->getPath(); continue; } else { if (_root::getParam($sColumn, null) === null) { continue; } else { if (in_array($sColumn, $tId)) { continue; } } } $oComments->{$sColumn} = _root::getParam($sColumn, null); } $oComments->post_id = $this->post_id; if ($oComments->save()) { //une fois enregistre on redirige (vers la page liste) $this->redirect('list'); } else { return $oComments->getListError(); } }