| Conditions | 10 |
| Paths | 24 |
| Total Lines | 87 |
| Code Lines | 41 |
| 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 |
||
| 31 | function printBookmarksList($aDb, $aLangs) |
||
| 32 | { |
||
| 33 | global $conf, $user; |
||
| 34 | |||
| 35 | $db = $aDb; |
||
| 36 | $langs = $aLangs; |
||
| 37 | |||
| 38 | require_once DOL_DOCUMENT_ROOT.'/bookmarks/class/bookmark.class.php'; |
||
| 39 | if (! isset($conf->global->BOOKMARKS_SHOW_IN_MENU)) $conf->global->BOOKMARKS_SHOW_IN_MENU=5; |
||
| 40 | |||
| 41 | $langs->load("bookmarks"); |
||
| 42 | |||
| 43 | $url= $_SERVER["PHP_SELF"].(! empty($_SERVER["QUERY_STRING"])?'?'.$_SERVER["QUERY_STRING"]:''); |
||
| 44 | |||
| 45 | $ret = ''; |
||
| 46 | |||
| 47 | // Menu bookmark |
||
| 48 | $ret.= '<div class="menu_top"></div>'."\n"; |
||
| 49 | |||
| 50 | $ret.= '<!-- form with POST method by default, will be replaced with GET for external link by js -->'."\n"; |
||
| 51 | $ret.= '<form id="actionbookmark" name="actionbookmark" method="POST" action="">'; |
||
| 52 | $ret.= '<select name="bookmark" id="boxbookmark" class="flat boxcombo vmenusearchselectcombo" alt="Bookmarks">'; |
||
| 53 | $ret.= '<option hidden value="listbookmarks" class="optiongrey" selected rel="'.DOL_URL_ROOT.'/bookmarks/list.php">'.$langs->trans('Bookmarks').'</option>'; |
||
| 54 | $ret.= '<option value="listbookmark" class="optionblue" rel="'.dol_escape_htmltag(DOL_URL_ROOT.'/bookmarks/list.php').'">'.dol_escape_htmltag($user->rights->bookmark->creer ? $langs->trans('EditBookmarks') : $langs->trans('ListOfBookmarks')).'...</option>'; |
||
| 55 | // Url to go on create new bookmark page |
||
| 56 | if ($user->rights->bookmark->creer) |
||
| 57 | { |
||
| 58 | $urltoadd=DOL_URL_ROOT.'/bookmarks/card.php?action=create&urlsource='.urlencode($url).'&url='.urlencode($url); |
||
| 59 | $ret.= '<option value="newbookmark" class="optionblue" rel="'.dol_escape_htmltag($urltoadd).'">'.dol_escape_htmltag($langs->trans('AddThisPageToBookmarks')).'...</option>'; |
||
| 60 | } |
||
| 61 | // Menu with all bookmarks |
||
| 62 | if (! empty($conf->global->BOOKMARKS_SHOW_IN_MENU)) |
||
| 63 | { |
||
| 64 | $sql = "SELECT rowid, title, url, target FROM ".MAIN_DB_PREFIX."bookmark"; |
||
| 65 | $sql.= " WHERE (fk_user = ".$user->id." OR fk_user is NULL OR fk_user = 0)"; |
||
| 66 | $sql.= " AND entity IN (".getEntity('bookmarks',1).")"; |
||
| 67 | $sql.= " ORDER BY position"; |
||
| 68 | if ($resql = $db->query($sql) ) |
||
| 69 | { |
||
| 70 | $i=0; |
||
| 71 | while ($i < $conf->global->BOOKMARKS_SHOW_IN_MENU && $obj = $db->fetch_object($resql)) |
||
| 72 | { |
||
| 73 | $ret.='<option name="bookmark'.$obj->rowid.'" value="'.$obj->rowid.'" '.($obj->target == 1?' target="_blank"':'').' rel="'.dol_escape_htmltag($obj->url).'">'; |
||
| 74 | //$ret.='<span class="fa fa-print">aa</span>'; |
||
| 75 | $ret.=img_picto('','object_bookmark').' '; |
||
| 76 | $ret.=$obj->title; |
||
| 77 | $ret.='</option>'; |
||
| 78 | $i++; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | else |
||
| 82 | { |
||
| 83 | dol_print_error($db); |
||
| 84 | } |
||
| 85 | } |
||
| 86 | |||
| 87 | $ret.= '</select>'; |
||
| 88 | $ret.= '</form>'; |
||
| 89 | |||
| 90 | $ret.=ajax_combobox('boxbookmark'); |
||
| 91 | |||
| 92 | $ret.='<script type="text/javascript"> |
||
| 93 | $(document).ready(function () {'; |
||
| 94 | $ret.=' jQuery("#boxbookmark").change(function() { |
||
| 95 | var urlselected = jQuery("#boxbookmark option:selected").attr("rel"); |
||
| 96 | var urltarget = jQuery("#boxbookmark option:selected").attr("target"); |
||
| 97 | if (! urltarget) { urltarget=""; } |
||
| 98 | jQuery("form#actionbookmark").attr("target",urltarget); |
||
| 99 | jQuery("form#actionbookmark").attr("action",urlselected); |
||
| 100 | |||
| 101 | console.log("We change select bookmark. We choose urlselected="+urlselected+" with target="+urltarget); |
||
| 102 | |||
| 103 | // Method is POST for internal link, GET for external |
||
| 104 | if (urlselected.startsWith(\'http\')) |
||
| 105 | { |
||
| 106 | var newmethod=\'GET\'; |
||
| 107 | jQuery("form#actionbookmark").attr("method",newmethod); |
||
| 108 | console.log("We change method to newmethod="+newmethod); |
||
| 109 | } |
||
| 110 | |||
| 111 | jQuery("#actionbookmark").submit(); |
||
| 112 | });'; |
||
| 113 | $ret.='})</script>'; |
||
| 114 | $ret .= '<div class="menu_end"></div>'; |
||
| 115 | |||
| 116 | return $ret; |
||
| 117 | } |
||
| 118 | |||
| 119 |