From 2668b80599f46cd5c7e55905df4901077f646448 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 12 Nov 2017 14:21:34 +0100 Subject: [PATCH] Standardize code --- htdocs/langs/en_US/opensurvey.lang | 1 + .../class/opensurveysondage.class.php | 85 ++++++++++++++++--- htdocs/opensurvey/list.php | 13 ++- htdocs/resource/class/dolresource.class.php | 15 ++-- 4 files changed, 90 insertions(+), 24 deletions(-) diff --git a/htdocs/langs/en_US/opensurvey.lang b/htdocs/langs/en_US/opensurvey.lang index f42ea006eb6..1f8a90b5657 100644 --- a/htdocs/langs/en_US/opensurvey.lang +++ b/htdocs/langs/en_US/opensurvey.lang @@ -57,3 +57,4 @@ ErrorInsertingComment=There was an error while inserting your comment MoreChoices=Enter more choices for the voters SurveyExpiredInfo=The poll has been closed or voting delay has expired. EmailSomeoneVoted=%s has filled a line.\nYou can find your poll at the link: \n%s +ShowSurvey=Show survey \ No newline at end of file diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php index 95af2b130d5..a2b6096d77c 100644 --- a/htdocs/opensurvey/class/opensurveysondage.class.php +++ b/htdocs/opensurvey/class/opensurveysondage.class.php @@ -37,7 +37,7 @@ class Opensurveysondage extends CommonObject public $element='opensurvey_sondage'; //!< Id that identify managed objects public $table_element='opensurvey_sondage'; //!< Name of table without prefix where object is stored public $picto = 'opensurvey'; - + public $id_sondage; /** * @deprecated @@ -75,7 +75,7 @@ class Opensurveysondage extends CommonObject */ public $allow_spy; - + /** * Draft status (not used) */ @@ -88,9 +88,9 @@ class Opensurveysondage extends CommonObject * Closed */ const STATUS_CLOSED = 2; - - - + + + /** * Constructor * @@ -110,7 +110,7 @@ class Opensurveysondage extends CommonObject * @param int $notrigger 0=launch triggers after, 1=disable triggers * @return int <0 if KO, Id of created object if OK */ - function create($user, $notrigger=0) + function create(User $user, $notrigger=0) { $error=0; @@ -200,7 +200,7 @@ class Opensurveysondage extends CommonObject * @param string $numsurvey Ref of survey (admin or not) * @return int <0 if KO, >0 if OK */ - function fetch($id,$numsurvey='') + function fetch($id, $numsurvey='') { $sql = "SELECT"; $sql.= " t.id_sondage,"; @@ -275,7 +275,7 @@ class Opensurveysondage extends CommonObject * @param int $notrigger 0=launch triggers after, 1=disable triggers * @return int <0 if KO, >0 if OK */ - function update($user, $notrigger=0) + function update(User $user, $notrigger=0) { global $conf, $langs; $error=0; @@ -348,7 +348,7 @@ class Opensurveysondage extends CommonObject * @param string $numsondage Num sondage admin to delete * @return int <0 if KO, >0 if OK */ - function delete($user, $notrigger, $numsondage) + function delete(User $user, $notrigger, $numsondage) { global $conf, $langs; $error=0; @@ -402,6 +402,63 @@ class Opensurveysondage extends CommonObject } } + /** + * Return a link to the object card (with optionaly the picto) + * + * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) + * @param int $notooltip 1=Disable tooltip + * @param string $morecss Add more css on link + * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking + * @return string String with URL + */ + function getNomUrl($withpicto=0, $notooltip=0, $morecss='', $save_lastsearch_value=-1) + { + global $db, $conf, $langs; + global $dolibarr_main_authentication, $dolibarr_main_demo; + global $menumanager; + + if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips + + $result = ''; + $companylink = ''; + + $label = '' . $langs->trans("ShowSurvey") . ''; + $label.= '
'; + $label.= '' . $langs->trans('Ref') . ': ' . $this->ref.'
'; + $label.= '' . $langs->trans('Title') . ': ' . $this->title.'
'; + + $url = DOL_URL_ROOT.'/opensurvey/card.php?id='.$this->id; + + // Add param to save lastsearch_values or not + $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); + if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; + if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; + + $linkclose=''; + if (empty($notooltip)) + { + if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) + { + $label=$langs->trans("ShowMyObject"); + $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"'; + } + $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"'; + $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"'; + } + else $linkclose = ($morecss?' class="'.$morecss.'"':''); + + $linkstart = ''; + $linkend=''; + + $result .= $linkstart; + if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1); + if ($withpicto != 2) $result.= $this->ref; + $result .= $linkend; + + return $result; + } + /** * Return array of lines * @@ -544,8 +601,8 @@ class Opensurveysondage extends CommonObject $this->allow_spy = ($this->allow_spy ? 1 : 0); $this->sujet = trim($this->sujet); } - - + + /** * Return status label of Order * @@ -556,7 +613,7 @@ class Opensurveysondage extends CommonObject { return $this->LibStatut($this->status,$mode); } - + /** * Return label of status * @@ -567,7 +624,7 @@ class Opensurveysondage extends CommonObject function LibStatut($status,$mode) { global $langs, $conf; - + //print 'x'.$status.'-'.$billed; if ($mode == 0) { @@ -606,5 +663,5 @@ class Opensurveysondage extends CommonObject if ($status==self::STATUS_CLOSED) return ''.$langs->trans('Closed').' '.img_picto($langs->trans('Closed'),'statut6'); } } - + } diff --git a/htdocs/opensurvey/list.php b/htdocs/opensurvey/list.php index 8c3f43b03d3..0ca1819e7bc 100644 --- a/htdocs/opensurvey/list.php +++ b/htdocs/opensurvey/list.php @@ -171,12 +171,19 @@ while ($i < min($num,$limit)) else dol_print_error($db); $opensurvey_static->id=$obj->id_sondage; + $opensurvey_static->ref=$obj->id_sondage; + $opensurvey_static->title=$obj->titre; $opensurvey_static->status=$obj->status; print ''; + + // Ref print ''; - print ''.img_picto('','object_opensurvey').' '.$obj->id_sondage.''; - print ''.dol_htmlentities($obj->titre).''; + print $opensurvey_static->getNomUrl(1); + print ''; + + // Title + print ''.dol_htmlentities($obj->titre).''; $type=($obj->format=='A')?'classic':'date'; print img_picto('',dol_buildpath('/opensurvey/img/'.($type == 'classic'?'chart-32.png':'calendar-32.png'),1),'width="16"',1); print ' '.$langs->trans($type=='classic'?"TypeClassic":"TypeDate"); @@ -200,7 +207,7 @@ while ($i < min($num,$limit)) print''.$nbuser.''."\n"; print ''.dol_print_date($db->jdate($obj->date_fin),'day'); - if ($db->jdate($obj->date_fin) < time()) { print ' ('.$langs->trans("Expired").')'; } + if ($db->jdate($obj->date_fin) < time()) { print img_warning($langs->trans("Expired")); } print ''; print''.$opensurvey_static->getLibStatut(5).''."\n"; diff --git a/htdocs/resource/class/dolresource.class.php b/htdocs/resource/class/dolresource.class.php index 10c7c2f9f85..1933d670cab 100644 --- a/htdocs/resource/class/dolresource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -936,20 +936,21 @@ class Dolresource extends CommonObject $result=''; $label=$langs->trans("ShowResource").': '.$this->ref; + $linkstart = ''; + $linkend = ''; if ($option == '') { - $link = ''; + $linkstart = ''; $picto='resource'; $label=$langs->trans("ShowResource").': '.$this->ref; - + $linkend=''; } - $linkend=''; + $result .= $linkstart; + if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1); + if ($withpicto != 2) $result.= $this->ref; + $result .= $linkend; - - if ($withpicto) $result.=($link.img_object($label, $picto, 'class="classfortooltip"').$linkend); - if ($withpicto && $withpicto != 2) $result.=' '; - $result.=$link.$this->ref.$linkend; return $result; }