| Conditions | 5 |
| Paths | 16 |
| Total Lines | 148 |
| Code Lines | 77 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 42 | function sendMail2member($mode, $eventId, $memberUid, $subject, $tplMessage) |
||
|
|
|||
| 43 | { |
||
| 44 | //mode = 0 pas d'entete |
||
| 45 | //mode = 1 format text |
||
| 46 | //mode = 2: format html |
||
| 47 | |||
| 48 | global $xoopsConfig, $xoopsDB; |
||
| 49 | // $t = print_r($xoopsConfig, true); |
||
| 50 | // echo "<pre>{$t}</pre>"; |
||
| 51 | /* |
||
| 52 | $memberUid = 1; |
||
| 53 | $eventId = 393; |
||
| 54 | $message = "Bonne journée à tous"; |
||
| 55 | $newStatus = 1; |
||
| 56 | $oldStatus = 0; |
||
| 57 | |||
| 58 | */ |
||
| 59 | |||
| 60 | //l'utilisateur ne pas etre notifié par mail |
||
| 61 | //if ($mode == 0) exit; |
||
| 62 | //------------------------------------------------------- |
||
| 63 | $tblMember = $xoopsDB->prefix('extcal_eventmember'); |
||
| 64 | $tblNotMember = $xoopsDB->prefix('extcal_eventnotmember'); |
||
| 65 | $tblUsers = $xoopsDB->prefix('users'); |
||
| 66 | $tblEvent = $xoopsDB->prefix('extcal_event'); |
||
| 67 | |||
| 68 | //-------------------------------------------------------------- |
||
| 69 | //Recuperation des données event,user et member |
||
| 70 | //Recuperation des données de l'evennement |
||
| 71 | $eventHandler = Helper::getInstance()->getHandler(_EXTCAL_CLN_EVENT); |
||
| 72 | $obj = $eventHandler->getEvent($eventId); |
||
| 73 | $event = $eventHandler->objectToArray($obj); |
||
| 74 | $eventHandler->formatEventDate($event, _MD_EXTCAL_FORMAT_DATE); |
||
| 75 | |||
| 76 | $submiter_uid = $event['event_submitter']; |
||
| 77 | // Utility::echoArray($event,'event'); |
||
| 78 | //-------------------------------------------------------------- |
||
| 79 | //Recuperation des données du user createur de l'evennement |
||
| 80 | $sql = <<<__sql__ |
||
| 81 | SELECT if(tu.name='', tu.uname, tu.name) AS name, tu.uname, tu.email |
||
| 82 | FROM {$tblUsers} tu |
||
| 83 | WHERE tu.uid = {$submiter_uid}; |
||
| 84 | __sql__; |
||
| 85 | |||
| 86 | $rst = $xoopsDB->query($sql); |
||
| 87 | $submiter = $xoopsDB->fetchArray($rst); |
||
| 88 | // echo "{$sql}<br>"; |
||
| 89 | // Utility::echoArray($submiter,'submiter'); |
||
| 90 | //-------------------------------------------------------------- |
||
| 91 | //Recuperation des données du membre inscrit |
||
| 92 | $sql = <<<__sql__ |
||
| 93 | SELECT if(tu.name='', tu.uname, tu.name) AS name, tu.uname, tu.email |
||
| 94 | FROM {$tblUsers} tu |
||
| 95 | WHERE tu.uid = {$memberUid}; |
||
| 96 | __sql__; |
||
| 97 | |||
| 98 | $rst = $xoopsDB->query($sql); |
||
| 99 | $acteur = $xoopsDB->fetchArray($rst); |
||
| 100 | //echo "{$sql}<br>"; |
||
| 101 | // Utility::echoArray($acteur,'acteur'); |
||
| 102 | //-------------------------------------------------------------- |
||
| 103 | //Recuperation des données des membres présents |
||
| 104 | $sql = <<<__sql__ |
||
| 105 | SELECT tu.uid, if(tu.name='', tu.uname, tu.name) AS name, tu.uname, tu.email, |
||
| 106 | tm.status |
||
| 107 | FROM {$tblMember} tm, |
||
| 108 | {$tblUsers} tu |
||
| 109 | WHERE tm.uid = tu.uid |
||
| 110 | AND tm.event_id = {$eventId} |
||
| 111 | __sql__; |
||
| 112 | |||
| 113 | $rst = $xoopsDB->query($sql); |
||
| 114 | $members = []; |
||
| 115 | while (false !== ($row = $xoopsDB->fetchArray($rst))) { |
||
| 116 | $row['status'] = _MD_EXTCAL_PRESENT; |
||
| 117 | $members[$row['uid']] = $row; |
||
| 118 | } |
||
| 119 | |||
| 120 | //-------------------------------------------------------------- |
||
| 121 | //Recuperation des données des membres absents |
||
| 122 | $sql = <<<__sql__ |
||
| 123 | SELECT tu.uid, if(tu.name='', tu.uname, tu.name) AS name, tu.uname, tu.email, |
||
| 124 | tm.status |
||
| 125 | FROM {$tblNotMember} tm, |
||
| 126 | {$tblUsers} tu |
||
| 127 | WHERE tm.uid = tu.uid |
||
| 128 | AND tm.event_id = {$eventId} |
||
| 129 | __sql__; |
||
| 130 | |||
| 131 | $rst = $xoopsDB->query($sql); |
||
| 132 | while (false !== ($row = $xoopsDB->fetchArray($rst))) { |
||
| 133 | $row['status'] = _MD_EXTCAL_ABSENT; |
||
| 134 | $members[$row['uid']] = $row; |
||
| 135 | } |
||
| 136 | |||
| 137 | // Utility::echoArray($members,'members'); |
||
| 138 | // exit; |
||
| 139 | |||
| 140 | //-------------------------------------------------------------- |
||
| 141 | //Message et sujet du mail |
||
| 142 | $action = ''; //a voir JJD |
||
| 143 | $message = sprintf($tplMessage, $acteur['name']); |
||
| 144 | //$subject .= ' (' . rand(1, 100) . ')'; |
||
| 145 | $subject .= ' - ' . $acteur['name']; |
||
| 146 | //-------------------------------------------------------------- |
||
| 147 | //Chargement du template dans le dossier de langue |
||
| 148 | //$f = _EXTCAL_PATH_LG . $xoopsConfig['language'] . '\mail_inscription.html'; |
||
| 149 | //$tpl = new tpl($f); |
||
| 150 | $tpl = new \XoopsTpl(); |
||
| 151 | |||
| 152 | $tpl->assign('dateAction', date(_MD_EXTCAL_FORMAT_DATE)); |
||
| 153 | $tpl->assign('submiter', $submiter); |
||
| 154 | $tpl->assign('event', $event); |
||
| 155 | $tpl->assign('acteur', $acteur); |
||
| 156 | $tpl->assign('members', $members); |
||
| 157 | $tpl->assign('action', $action); |
||
| 158 | $tpl->assign('subject', $subject); |
||
| 159 | $tpl->assign('message', $message); |
||
| 160 | $tpl->assign('xoopsConfig', $xoopsConfig); |
||
| 161 | $tpl->assign('br', '<br>'); |
||
| 162 | |||
| 163 | //-------------------------------------------------------------- |
||
| 164 | $destinataires = []; |
||
| 165 | $destinataires[$submiter['email']] = $submiter['email']; |
||
| 166 | $destinataires[$acteur['email']] = $acteur['email']; |
||
| 167 | // while (list($k, $row) = each($members)) { |
||
| 168 | foreach ($members as $k => $row) { |
||
| 169 | $destinataires[$row['email']] = $row['email']; |
||
| 170 | } |
||
| 171 | |||
| 172 | // Utility::echoArray($destinataires); |
||
| 173 | // exit; |
||
| 174 | |||
| 175 | $mail_fromName = $xoopsConfig['sitename']; |
||
| 176 | $mail_fromemail = $xoopsConfig['adminmail']; |
||
| 177 | $mail_subject = $subject; |
||
| 178 | |||
| 179 | $bEcho = false; |
||
| 180 | $mode = _EXTCAL_HEADER_HTML; |
||
| 181 | $sep = '|'; |
||
| 182 | |||
| 183 | $template = 'extcal_mail_member_text.tpl'; |
||
| 184 | if (_EXTCAL_HEADER_HTML == $mode) { |
||
| 185 | $template = 'extcal_mail_member_html.tpl'; |
||
| 186 | } |
||
| 187 | $mail_body = $tpl->fetch('db:' . $template); |
||
| 188 | |||
| 189 | extcal_SendMail($destinataires, $mail_fromName, $mail_fromemail, $mail_subject, $mail_body, $bEcho = false, $mode = 0, $sep = '|'); |
||
| 190 | |||
| 334 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.