1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185
|
<?php
class module_articles extends abstract_module{
public function before(){
//ici on force l'authentification sur l'ensemble du module
//_root::getAuth()->enable();
$this->oLayout=new _layout('template1');
//$this->oLayout->addModule('menu','menu::index');
//instancier le module
$oModuleMenu=new module_menu;
//recupere la vue du module
$oView=$oModuleMenu->_index();
//assigner la vue retournee a votre layout
$this->oLayout->add('menu',$oView);
}
public function _index(){
//on considere que la page par defaut est la page de listage
$this->_list();
}
public function before_list(){
//ici on force l'authentification sur le couple exemple::list
_root::getAuth()->enable();
}
public function _list(){
$tArticles=model_articles::getInstance()->findAll();
$oView=new _view('articles::list');
$oView->tArticles=$tArticles;
$this->oLayout->add('main',$oView);
}
public function _new(){
$tMessage=$this->save();
$oArticles=new row_articles;
$oView=new _view('articles::new');
$oView->oArticles=$oArticles;
$oPluginXsrf=new plugin_xsrf();
$oView->token=$oPluginXsrf->getToken();
$oView->tMessage=$tMessage;
$this->oLayout->add('main',$oView);
}
public function _edit(){
$tMessage=$this->save();
$oArticles=model_articles::getInstance()->findById( _root::getParam('id') );
$oView=new _view('articles::edit');
$oView->oArticles=$oArticles;
$oView->tId=model_articles::getInstance()->getIdTab();
$oPluginXsrf=new plugin_xsrf();
$oView->token=$oPluginXsrf->getToken();
$oView->tMessage=$tMessage;
$this->oLayout->add('main',$oView);
}
public function _show(){
$oArticles=model_articles::getInstance()->findById( _root::getParam('id') );
$oView=new _view('articles::show');
$oView->oArticles=$oArticles;
$this->oLayout->add('main',$oView);
}
public function _delete(){
$tMessage=$this->delete();
$oArticles=model_articles::getInstance()->findById( _root::getParam('id') );
$oView=new _view('articles::delete');
$oView->oArticles=$oArticles;
$oPluginXsrf=new plugin_xsrf();
$oView->token=$oPluginXsrf->getToken();
$oView->tMessage=$tMessage;
$this->oLayout->add('main',$oView);
}
public function save(){
if(!_root::getRequest()->isPost() ){ //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=_root::getParam('id',null);
if($iId==null){
$oArticles=new row_articles;
}else{
$oArticles=model_articles::getInstance()->findById( _root::getParam('id',null) );
}
$tId=model_articles::getInstance()->getIdTab();
$tColumn=model_articles::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);
$oArticles->$sColumn=$oPluginUpload->getPath();
continue;
}else if( _root::getParam($sColumn,null) === null ){
continue;
}else if( in_array($sColumn,$tId)){
continue;
}
$oArticles->$sColumn=_root::getParam($sColumn,null) ;
}
if($oArticles->save()){
//une fois enregistre on redirige (vers la page liste)
_root::redirect('articles::list');
}else{
return $oArticles->getListError();
}
}
public function delete(){
if(!_root::getRequest()->isPost() ){ //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() );
}
$oArticles=model_articles::getInstance()->findById( _root::getParam('id',null) );
$oArticles->delete();
//une fois enregistre on redirige (vers la page liste)
_root::redirect('articles::list');
}
public function after(){
$this->oLayout->show();
}
}
/*variables
#select $oView->tJoinarticles=articles::getInstance()->getSelect();#fin_select
#uploadsave $oPluginUpload=new plugin_upload($sColumn);
if($oPluginUpload->isValid()){
$sNewFileName=_root::getConfigVar('path.upload').$sColumn.'_'.date('Ymdhis');
$oPluginUpload->saveAs($sNewFileName);
$oArticles->$sColumn=$oPluginUpload->getPath();
continue;
}else #fin_uploadsave
variables*/ |
Partager