bayzazi Posted November 13, 2014 Share Posted November 13, 2014 Bonjour à tous, via un module, j'ai un controller admin qui m'affiche les entrées d'une table en liste. Je souhaiterais n'attribuer les boutons d'action de chaque ligne que si une condition est remplie (par exemple si la ligne->active = 1). public function __construct() { $this->table = 'matable'; $this->className = 'MaClasse'; $this->lang = false; $this->bootstrap = true; $this->deleted = false; $this->display ='list'; $this->colorOnBackground = false; $this->bulk_actions = array('delete' => array('text' => $this->l('Delete selected'), 'confirm' => $this->l('Delete selected items?'))); $this->context = Context::getContext(); $this->fields_list = array ( 'id_table' => array('title' =>'#', 'class'=>'fixed-width-xs','orderby' => false), 'name' => array('title' =>$this->l('Name'),'orderby' => false), 'file_name' => array('title' =>$this->l('File Name'),'orderby' => false), 'active' => array('title' => $this->l('Done'), 'align' => 'center', 'activeVisu' => 'status', 'class' => 'fixed-width-sm', 'type' => 'bool', 'orderby' => false, 'disabled' => true), 'date_add' => array('title' =>$this->l('Create'), 'type'=>'date','orderby' => false), 'etat' => array('title' =>$this->l('Etat'),'orderby' => false) ); parent::__construct(); $this->addRowAction('update'); $this->addRowAction('import'); $this->addRowAction('delete'); } Donc du coup, mettre une condition dans les 3 dernières lignes, mais je ne vois pas comment accéder aux propriétés de chacune des lignes pour vérifier la condition. Any idea ? Link to comment Share on other sites More sharing options...
Olivier CLEMENCE Posted November 14, 2014 Share Posted November 14, 2014 Tu dois créer une fonction du genre displayAddRowActionLink(id) { my_obj=new obj(id); if(my_obj->acive==1) //j affiche mon bouton else return false } Prestashop appel des fonction du type display(nomdelaction)link pour afficher les boutons. Je dis tous ça de mémoire donc à vérifier dans un autre controller avant, mais l'idée est là 1 Link to comment Share on other sites More sharing options...
bayzazi Posted November 14, 2014 Author Share Posted November 14, 2014 Ah oui pas mal ! Je teste ça, merci pour l'info Link to comment Share on other sites More sharing options...
Olivier CLEMENCE Posted November 14, 2014 Share Posted November 14, 2014 N'hésite pas à revenir poster ton code si tu réussi, ça pourra servir au reste de la communauté. Link to comment Share on other sites More sharing options...
bayzazi Posted November 24, 2014 Author Share Posted November 24, 2014 Hello, pour info, voici donc le code final pour conditionner l'affichage des actions : public function displayUpdateLink($token = null, $id) { $my_obj = new obj($id); if($my_obj->etat=="Non traité") { $tpl = $this->createTemplate('helpers/list/list_action_edit.tpl'); if (!array_key_exists('Update', self::$cache_lang)) self::$cache_lang['Update'] = $this->l('Update', 'Helper'); $tpl->assign(array( 'href' => self::$currentIndex.'&'.$this->identifier.'='.$id.'&update=1&token='.($token != null ? $token : $this->token), 'action' => self::$cache_lang['Update'], 'id' => $id )); return $tpl->fetch(); } else return false; } Merci pour le coup de pouce ! Link to comment Share on other sites More sharing options...
Olivier CLEMENCE Posted November 24, 2014 Share Posted November 24, 2014 Super merci pour le partage, c'est toujours utile d'avoir des bouts de code Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now