29 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
40 public $table_element =
'c_partnership_type';
45 public $element =
'partnership_type';
50 public $picto =
'generic';
56 public $ismultientitymanaged = 1;
70 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
71 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>15,
'index'=>1),
72 'code' =>array(
'type'=>
'varchar(32)',
'label'=>
'Code',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>20),
73 'label' =>array(
'type'=>
'varchar(64)',
'label'=>
'Label',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>25,
'showoncombobox'=>1),
74 'active' =>array(
'type'=>
'integer',
'label'=>
'Active',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>30),
90 if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields[
'rowid'])) {
91 $this->fields[
'rowid'][
'visible'] = 0;
93 if (!
isModEnabled(
'multicompany') && isset($this->fields[
'entity'])) {
94 $this->fields[
'entity'][
'enabled'] = 0;
104 foreach ($this->fields as $key => $val) {
105 if (isset($val[
'enabled']) && empty($val[
'enabled'])) {
106 unset($this->fields[$key]);
111 if (is_object($langs)) {
112 foreach ($this->fields as $key => $val) {
113 if (!empty($val[
'arrayofkeyval']) && is_array($val[
'arrayofkeyval'])) {
114 foreach ($val[
'arrayofkeyval'] as $key2 => $val2) {
115 $this->fields[$key][
'arrayofkeyval'][$key2] = $langs->trans($val2);
132 return $resultcreate;
142 public function fetch($id, $ref =
null)
159 public function fetchAll($sortorder =
'', $sortfield =
'', $limit = 0, $offset = 0, array $filter = array(), $filtermode =
'AND')
169 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
170 if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
171 $sql .=
" WHERE t.entity IN (".getEntity($this->element).
")";
173 $sql .=
" WHERE 1 = 1";
177 if (count($filter) > 0) {
178 foreach ($filter as $key => $value) {
179 if ($key ==
't.rowid') {
180 $sqlwhere[] = $key.
" = ".((int) $value);
181 } elseif (in_array($this->fields[$key][
'type'], array(
'date',
'datetime',
'timestamp'))) {
182 $sqlwhere[] = $key.
" = '".$this->db->idate($value).
"'";
183 } elseif ($key ==
'customsql') {
184 $sqlwhere[] = $value;
185 } elseif (strpos($value,
'%') ===
false) {
186 $sqlwhere[] = $key.
" IN (".$this->db->sanitize($this->db->escape($value)).
")";
188 $sqlwhere[] = $key.
" LIKE '%".$this->db->escape($value).
"%'";
192 if (count($sqlwhere) > 0) {
193 $sql .=
" AND (".implode(
" ".$filtermode.
" ", $sqlwhere).
")";
196 if (!empty($sortfield)) {
197 $sql .= $this->db->order($sortfield, $sortorder);
199 if (!empty($limit)) {
200 $sql .= $this->db->plimit($limit, $offset);
203 $resql = $this->db->query(
$sql);
205 $num = $this->db->num_rows($resql);
207 while ($i < ($limit ? min($limit, $num) : $num)) {
208 $obj = $this->db->fetch_object($resql);
210 $record =
new self($this->db);
211 $record->setVarsFromFetchObj($obj);
213 $records[$record->id] = $record;
217 $this->db->free($resql);
221 $this->errors[] =
'Error '.$this->db->lasterror();
222 dol_syslog(__METHOD__.
' '.join(
',', $this->errors), LOG_ERR);
247 public function delete(
User $user, $notrigger =
false)
262 public function getNomUrl($withpicto = 0, $option =
'', $notooltip = 0, $morecss =
'', $save_lastsearch_value = -1)
264 global $conf, $langs, $hookmanager;
266 if (!empty($conf->dol_no_mouse_hover)) {
272 $label =
img_picto(
'', $this->picto).
' <u>'.$langs->trans(
"PartnershipType").
'</u>';
273 if (isset($this->status)) {
274 $label .=
' '.$this->getLibStatut(5);
277 $label .=
'<b>'.$langs->trans(
'Code').
':</b> '.$this->code;
278 $label .=
'<br><b>'.$langs->trans(
'Label').
':</b> '.$this->label;
283 if ($option !=
'nolink') {
285 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
286 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
287 $add_save_lastsearch_values = 1;
289 if ($url && $add_save_lastsearch_values) {
290 $url .=
'&save_lastsearch_values=1';
295 if (empty($notooltip)) {
296 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
297 $label = $langs->trans(
"ShowMyObject");
298 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
300 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
301 $linkclose .=
' class="classfortooltip'.($morecss ?
' '.$morecss :
'').
'"';
303 $linkclose = ($morecss ?
' class="'.$morecss.
'"' :
'');
306 if ($option ==
'nolink' || empty($url)) {
307 $linkstart =
'<span';
309 $linkstart =
'<a href="'.$url.
'"';
311 $linkstart .= $linkclose.
'>';
312 if ($option ==
'nolink' || empty($url)) {
313 $linkend =
'</span>';
318 $result .= $linkstart;
320 if (empty($this->showphoto_on_popup)) {
322 $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);
326 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
328 list($class, $module) = explode(
'@', $this->picto);
331 $filename = $filearray[0][
'name'];
332 if (!empty($filename)) {
333 $pospoint = strpos($filearray[0][
'name'],
'.');
335 $pathtophoto = $class.
'/'.$this->
ref.
'/thumbs/'.substr($filename, 0, $pospoint).
'_mini'.substr($filename, $pospoint);
336 if (empty($conf->global->{strtoupper($module.
'_'.$class).
'_FORMATLISTPHOTOSASUSERS'})) {
337 $result .=
'<div class="floatleft inline-block valignmiddle divphotoref"><div class="photoref"><img class="photo'.$module.
'" alt="No photo" border="0" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$module.
'&entity='.$conf->entity.
'&file='.urlencode($pathtophoto).
'"></div></div>';
339 $result .=
'<div class="floatleft inline-block valignmiddle divphotoref"><img class="photouserphoto userphoto" alt="No photo" border="0" src="'.DOL_URL_ROOT.
'/viewimage.php?modulepart='.$module.
'&entity='.$conf->entity.
'&file='.urlencode($pathtophoto).
'"></div>';
344 $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);
349 if ($withpicto != 2) {
350 $result .= $this->ref;
356 global $action, $hookmanager;
357 $hookmanager->initHooks(array(
'myobjectdao'));
358 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
359 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
361 $result = $hookmanager->resPrint;
363 $result .= $hookmanager->resPrint;
377 $sql =
"SELECT rowid, date_creation as datec, tms as datem,";
378 $sql .=
" fk_user_creat, fk_user_modif";
379 $sql .=
" FROM ".MAIN_DB_PREFIX.$this->table_element.
" as t";
380 $sql .=
" WHERE t.rowid = ".((int) $id);
382 $result = $this->db->query(
$sql);
384 if ($this->db->num_rows($result)) {
385 $obj = $this->db->fetch_object($result);
386 $this->
id = $obj->rowid;
388 $this->user_creation_id = $obj->fk_user_creat;
389 $this->user_modification_id = $obj->fk_user_modif;
390 $this->date_creation = $this->db->jdate($obj->datec);
391 $this->date_modification = empty($obj->datem) ?
'' : $this->db->jdate($obj->datem);
394 $this->db->free($result);
412 $this->initAsSpecimenCommon();