2016-04-19 11:02:55 +02:00
< ? php
2018-09-25 15:00:37 +02:00
/* Copyright ( C ) 2007 - 2018 Laurent Destailleur < eldy @ users . sourceforge . net >
2016-04-19 11:02:55 +02:00
* Copyright ( C ) 2014 Juanjo Menent < jmenent @ 2 byte . es >
* Copyright ( C ) 2015 Florian Henry < florian . henry @ open - concept . pro >
* Copyright ( C ) 2015 Raphaël Doursenaud < rdoursenaud @ gpcsolutions . fr >
2020-09-28 20:39:02 +02:00
* Copyright ( C ) 2020 Nicolas ZABOURI < info @ inovea - conseil . com >
2016-04-19 11:02:55 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 3 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2016-04-19 11:02:55 +02:00
*/
/**
2019-12-15 10:02:20 +01:00
* \file htdocs / website / class / websitepage . class . php
2017-10-20 21:39:19 +02:00
* \ingroup website
2017-08-03 01:45:31 +02:00
* \brief File for the CRUD class of websitepage ( Create / Read / Update / Delete )
2016-04-19 11:02:55 +02:00
*/
// Put here all includes required by your class file
2019-11-08 15:51:54 +01:00
require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php' ;
2016-04-19 11:02:55 +02:00
//require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
//require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
/**
* Class Websitepage
*/
class WebsitePage extends CommonObject
{
/**
* @ var string Id to identify managed objects
*/
public $element = 'websitepage' ;
2018-09-02 22:05:19 +02:00
2016-04-19 11:02:55 +02:00
/**
* @ var string Name of table without prefix where object is stored
*/
public $table_element = 'website_page' ;
2018-09-02 22:05:19 +02:00
2017-10-26 02:55:43 +02:00
/**
2017-11-03 15:56:16 +01:00
* @ var string String with name of icon for websitepage . Must be the part after the 'object_' into object_myobject . png
2017-10-26 02:55:43 +02:00
*/
2019-10-31 21:09:33 +01:00
public $picto = 'file-code' ;
2016-04-19 11:02:55 +02:00
2020-06-06 18:57:24 +02:00
2018-10-12 12:23:45 +02:00
/**
2020-10-07 15:01:28 +02:00
* @ var int ID
*/
2016-04-19 11:02:55 +02:00
public $fk_website ;
2018-10-12 12:23:45 +02:00
2016-04-19 11:02:55 +02:00
public $pageurl ;
2018-02-28 14:36:22 +01:00
public $aliasalt ;
2017-12-02 13:24:21 +01:00
public $type_container ;
2018-08-31 19:26:08 +02:00
2018-11-20 16:48:34 +01:00
/**
* @ var string title
*/
public $title ;
2018-08-31 19:26:08 +02:00
/**
* @ var string description
*/
2016-04-19 11:02:55 +02:00
public $description ;
2018-11-20 16:48:34 +01:00
/**
* @ var string image
*/
public $image ;
/**
* @ var string keywords
*/
2016-04-19 11:02:55 +02:00
public $keywords ;
2019-12-07 13:09:55 +01:00
/**
* @ var string language code ( 'en' , 'fr' , 'en-gb' , .. )
*/
public $lang ;
2018-11-20 16:48:34 +01:00
2020-11-26 11:09:35 +01:00
public $allowed_in_frames ;
2017-10-02 00:08:00 +02:00
public $htmlheader ;
2016-04-19 11:02:55 +02:00
public $content ;
2018-02-14 20:33:48 +01:00
public $grabbed_from ;
2018-10-05 15:51:08 +02:00
/**
* @ var int Status
*/
2016-04-19 11:02:55 +02:00
public $status ;
2019-11-10 12:23:37 +01:00
2019-11-10 12:22:24 +01:00
/**
* @ var integer | string date_creation
*/
2016-04-21 03:18:42 +02:00
public $date_creation ;
2019-11-10 12:23:37 +01:00
2019-11-10 12:22:24 +01:00
/**
* @ var integer | string date_modification
*/
2016-04-21 03:18:42 +02:00
public $date_modification ;
2016-04-19 11:02:55 +02:00
2020-03-12 20:50:36 +01:00
/**
* @ var string author_alias
*/
public $author_alias ;
2021-02-26 12:03:07 +01:00
/**
* @ var string path of external object
*/
2020-10-07 15:01:28 +02:00
public $object_type ;
2020-09-28 20:39:02 +02:00
2020-10-07 15:01:28 +02:00
/**
* @ var string id of external object
*/
public $fk_object ;
2018-02-14 20:33:48 +01:00
2019-10-31 21:09:33 +01:00
const STATUS_DRAFT = 0 ;
const STATUS_VALIDATED = 1 ;
2020-05-14 18:55:20 +02:00
/**
* 'type' if the field format ( 'integer' , 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter]]' , 'varchar(x)' , 'double(24,8)' , 'real' , 'price' , 'text' , 'html' , 'date' , 'datetime' , 'timestamp' , 'duration' , 'mail' , 'phone' , 'url' , 'password' )
* Note : Filter can be a string like " (t.ref:like:'SO-%') or (t.date_creation:<:'20160101') or (t.nature:is:NULL) "
* 'label' the translation key .
* 'enabled' is a condition when the field must be managed ( Example : 1 or ' $conf -> global -> MY_SETUP_PARAM )
* 'position' is the sort order of field .
* 'notnull' is set to 1 if not null in database . Set to - 1 if we must set data to null if empty ( '' or 0 ) .
* 'visible' says if field is visible in list ( Examples : 0 = Not visible , 1 = Visible on list and create / update / view forms , 2 = Visible on list only , 3 = Visible on create / update / view form only ( not list ), 4 = Visible on list and update / view form only ( not create ) . 5 = Visible on list and view only ( not create / not update ) . Using a negative value means field is not shown by default on list but can be selected for viewing )
* 'noteditable' says if field is not editable ( 1 or 0 )
* 'default' is a default value for creation ( can still be overwrote by the Setup of Default Values if field is editable in creation form ) . Note : If default is set to '(PROV)' and field is 'ref' , the default value will be set to '(PROVid)' where id is rowid when a new record is created .
* 'index' if we want an index in database .
* 'foreignkey' => 'tablename.field' if the field is a foreign key ( it is recommanded to name the field fk_ ... ) .
* 'searchall' is 1 if we want to search in this field when making a search from the quick search button .
* 'isameasure' must be set to 1 if you want to have a total on list for this field . Field type must be summable like integer or double ( 24 , 8 ) .
* 'css' is the CSS style to use on field . For example : 'maxwidth200'
* 'help' is a string visible as a tooltip on field
* 'showoncombobox' if value of the field must be visible into the label of the combobox that list record
* 'disabled' is 1 if we want to have the field locked by a 'disabled' attribute . In most cases , this is never set into the definition of $fields into class , but is set dynamically by some part of code .
2021-04-29 12:10:55 +02:00
* 'arrayofkeyval' to set list of value if type is a list of predefined values . For example : array ( " 0 " => " Draft " , " 1 " => " Active " , " -1 " => " Cancel " )
2020-05-14 18:55:20 +02:00
* 'comment' is not used . You can store here any text of your choice . It is not used by application .
*
* Note : To have value dynamic , you can set value to 0 in definition and edit the value on the fly into the constructor .
*/
2019-10-31 21:09:33 +01:00
2017-07-28 14:54:13 +02:00
// BEGIN MODULEBUILDER PROPERTIES
2016-04-19 11:02:55 +02:00
/**
2020-10-07 15:01:28 +02:00
* @ var array Array with all fields and their property . Do not use it as a static var . It may be modified by constructor .
*/
2019-11-08 15:51:54 +01:00
public $fields = array (
2020-10-07 15:01:28 +02:00
'rowid' => array ( 'type' => 'integer' , 'label' => 'TechnicalID' , 'enabled' => 1 , 'visible' =>- 1 , 'notnull' => 1 , 'index' => 1 , 'position' => 1 , 'comment' => 'Id' ),
2019-11-08 15:51:54 +01:00
'pageurl' => array ( 'type' => 'varchar(16)' , 'label' => 'WEBSITE_PAGENAME' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'index' => 1 , 'position' => 10 , 'searchall' => 1 , 'comment' => 'Ref/alias of page' ),
'aliasalt' => array ( 'type' => 'varchar(255)' , 'label' => 'AliasAlt' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'index' => 0 , 'position' => 11 , 'searchall' => 0 , 'comment' => 'Alias alternative of page' ),
'type_container' => array ( 'type' => 'varchar(16)' , 'label' => 'Type' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'index' => 0 , 'position' => 12 , 'comment' => 'Type of container' ),
2019-12-16 14:29:47 +01:00
'title' => array ( 'type' => 'varchar(255)' , 'label' => 'Label' , 'enabled' => 1 , 'visible' => 1 , 'position' => 30 , 'searchall' => 1 , 'help' => 'UseTextBetween5And70Chars' ),
2020-10-07 15:01:28 +02:00
'description' => array ( 'type' => 'varchar(255)' , 'label' => 'Description' , 'enabled' => 1 , 'visible' => 1 , 'position' => 30 , 'searchall' => 1 ),
2019-11-08 15:51:54 +01:00
'image' => array ( 'type' => 'varchar(255)' , 'label' => 'Image' , 'enabled' => 1 , 'visible' => 1 , 'position' => 32 , 'searchall' => 0 , 'help' => 'Relative path of media. Used if Type is "blogpost"' ),
'keywords' => array ( 'type' => 'varchar(255)' , 'label' => 'Keywords' , 'enabled' => 1 , 'visible' => 1 , 'position' => 45 , 'searchall' => 0 ),
2020-05-14 18:55:20 +02:00
'lang' => array ( 'type' => 'varchar(6)' , 'label' => 'Lang' , 'enabled' => 1 , 'notnull' =>- 1 , 'visible' => 1 , 'position' => 45 , 'searchall' => 0 ),
2017-07-28 14:54:13 +02:00
//'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>1, 'index'=>true, 'position'=>1000),
2020-10-07 15:01:28 +02:00
'fk_website' => array ( 'type' => 'integer' , 'label' => 'WebsiteId' , 'enabled' => 1 , 'visible' => 1 , 'notnull' => 1 , 'position' => 40 , 'searchall' => 0 , 'foreignkey' => 'websitepage.rowid' ),
'fk_page' => array ( 'type' => 'integer' , 'label' => 'ParentPageId' , 'enabled' => 1 , 'visible' => 1 , 'notnull' =>- 1 , 'position' => 45 , 'searchall' => 0 , 'foreignkey' => 'website.rowid' ),
2021-01-26 12:43:23 +01:00
'allowed_in_frames' => array ( 'type' => 'integer' , 'label' => 'AllowedInFrames' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 48 , 'searchall' => 0 , 'default' => 0 ),
2020-10-07 15:01:28 +02:00
'htmlheader' => array ( 'type' => 'text' , 'label' => 'HtmlHeader' , 'enabled' => 1 , 'visible' => 0 , 'position' => 50 , 'searchall' => 0 ),
'content' => array ( 'type' => 'mediumtext' , 'label' => 'Content' , 'enabled' => 1 , 'visible' => 0 , 'position' => 51 , 'searchall' => 0 ),
2019-11-08 15:51:54 +01:00
'grabbed_from' => array ( 'type' => 'varchar(255)' , 'label' => 'GrabbedFrom' , 'enabled' => 1 , 'visible' => 1 , 'index' => 1 , 'position' => 400 , 'comment' => 'URL page content was grabbed from' ),
2020-10-07 15:01:28 +02:00
'date_creation' => array ( 'type' => 'datetime' , 'label' => 'DateCreation' , 'enabled' => 1 , 'visible' =>- 1 , 'notnull' => 1 , 'position' => 500 ),
2019-11-08 15:51:54 +01:00
'tms' => array ( 'type' => 'timestamp' , 'label' => 'DateModification' , 'enabled' => 1 , 'visible' =>- 1 , 'notnull' => 1 , 'position' => 501 ),
2017-10-22 16:45:18 +02:00
//'date_valid' =>array('type'=>'datetime', 'label'=>'DateValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>502),
2019-11-08 15:51:54 +01:00
'fk_user_creat' => array ( 'type' => 'integer' , 'label' => 'UserAuthor' , 'enabled' => 1 , 'visible' =>- 1 , 'notnull' => true , 'position' => 510 ),
2020-03-12 20:50:36 +01:00
'author_alias' => array ( 'type' => 'varchar(64)' , 'label' => 'AuthorAlias' , 'enabled' => 1 , 'visible' =>- 1 , 'index' => 0 , 'position' => 511 , 'comment' => 'Author alias' ),
'fk_user_modif' => array ( 'type' => 'integer' , 'label' => 'UserModif' , 'enabled' => 1 , 'visible' =>- 1 , 'position' => 512 ),
2017-10-22 16:45:18 +02:00
//'fk_user_valid' =>array('type'=>'integer', 'label'=>'UserValidation', 'enabled'=>1, 'visible'=>-1, 'position'=>512),
2019-11-08 15:51:54 +01:00
'import_key' => array ( 'type' => 'varchar(14)' , 'label' => 'ImportId' , 'enabled' => 1 , 'visible' =>- 1 , 'index' => 1 , 'position' => 1000 , 'notnull' =>- 1 ),
2020-10-31 14:32:18 +01:00
'object_type' => array ( 'type' => 'varchar(255)' , 'label' => 'ObjectType' , 'enabled' => 1 , 'visible' => 0 , 'position' => 46 , 'searchall' => 0 , 'help' => '' ),
'fk_object' => array ( 'type' => 'varchar(255)' , 'label' => 'ObjectId' , 'enabled' => 1 , 'visible' => 0 , 'position' => 47 , 'searchall' => 0 , 'help' => '' )
2017-07-28 14:54:13 +02:00
);
// END MODULEBUILDER PROPERTIES
2016-04-27 09:41:42 +02:00
2016-04-19 11:02:55 +02:00
2020-06-06 18:57:24 +02:00
// If this object has a subtable with lines
2020-12-05 23:53:55 +01:00
// /**
// * @var string Name of subtable line
// */
2020-06-06 18:57:24 +02:00
//public $table_element_line = 'mymodule_myobjectline';
/**
2020-12-05 23:53:55 +01:00
* @ var string Field with ID of parent key if this field has a parent or for child tables
2020-06-06 18:57:24 +02:00
*/
2020-06-11 18:31:26 +02:00
public $fk_element = 'fk_website_page' ;
2020-06-06 18:57:24 +02:00
2020-12-05 23:53:55 +01:00
// /**
// * @var string Name of subtable class that manage subtable lines
// */
2020-06-06 18:57:24 +02:00
//public $class_element_line = 'MyObjectline';
/**
* @ var array List of child tables . To test if we can delete object .
*/
//protected $childtables=array();
/**
* @ var array List of child tables . To know object to delete on cascade .
*/
protected $childtablesoncascade = array ( 'categorie_website_page' );
2016-04-19 11:02:55 +02:00
/**
* Constructor
*
* @ param DoliDb $db Database handler
*/
public function __construct ( DoliDB $db )
{
$this -> db = $db ;
}
/**
* Create object into database
*
* @ param User $user User that creates
* @ param bool $notrigger false = launch triggers after , true = disable triggers
2017-08-20 18:50:51 +02:00
* @ return int < 0 if KO , Id of created object if OK
2016-04-19 11:02:55 +02:00
*/
public function create ( User $user , $notrigger = false )
{
2018-02-19 14:56:37 +01:00
$this -> description = dol_trunc ( $this -> description , 255 , 'right' , 'utf-8' , 1 );
$this -> keywords = dol_trunc ( $this -> keywords , 255 , 'right' , 'utf-8' , 1 );
2021-02-26 12:03:07 +01:00
if ( $this -> aliasalt ) {
$this -> aliasalt = ',' . preg_replace ( '/,+$/' , '' , preg_replace ( '/^,+/' , '' , $this -> aliasalt )) . ',' ; // content in database must be ',xxx,...,yyy,'
}
2018-02-19 14:56:37 +01:00
2021-06-29 15:29:28 +02:00
$this -> pageurl = preg_replace ( '/[^a-z0-9\-\_]/i' , '' , $this -> pageurl );
$this -> pageurl = preg_replace ( '/\-\-+/' , '-' , $this -> pageurl );
$this -> pageurl = preg_replace ( '/^\-/' , '' , $this -> pageurl );
2020-02-21 11:36:16 +01:00
// Remove spaces and be sure we have main language only
$this -> lang = preg_replace ( '/[_-].*$/' , '' , trim ( $this -> lang )); // en_US or en-US -> en
2017-08-20 18:50:51 +02:00
return $this -> createCommon ( $user , $notrigger );
2016-04-19 11:02:55 +02:00
}
/**
* Load object in memory from the database
*
2019-02-25 20:35:59 +01:00
* @ param int $id Id object .
* - If this is 0 , the value into $page will be used . If not found or $page not defined , the default page of website_id will be used or the first page found if not set .
* - If value is < 0 , we must exclude this ID .
* @ param string $website_id Web site id ( page name must also be filled if this parameter is used )
2020-03-13 10:05:54 +01:00
* @ param string $page Page name ( website id must also be filled if this parameter is used ) . Exemple 'myaliaspage' or 'fr/myaliaspage'
2019-02-25 20:35:59 +01:00
* @ param string $aliasalt Alternative alias to search page ( slow )
2016-04-19 11:02:55 +02:00
*
* @ return int < 0 if KO , 0 if not found , > 0 if OK
*/
2018-02-28 14:36:22 +01:00
public function fetch ( $id , $website_id = null , $page = null , $aliasalt = null )
2016-04-19 11:02:55 +02:00
{
dol_syslog ( __METHOD__ , LOG_DEBUG );
$sql = 'SELECT' ;
$sql .= ' t.rowid,' ;
$sql .= " t.fk_website, " ;
2017-12-02 13:24:21 +01:00
$sql .= ' t.type_container,' ;
2016-04-19 11:02:55 +02:00
$sql .= " t.pageurl, " ;
2018-02-28 14:36:22 +01:00
$sql .= " t.aliasalt, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.title, " ;
$sql .= " t.description, " ;
2018-11-20 18:29:29 +01:00
$sql .= " t.image, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.keywords, " ;
2017-10-02 00:08:00 +02:00
$sql .= " t.htmlheader, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.content, " ;
2017-07-22 20:01:29 +02:00
$sql .= " t.lang, " ;
$sql .= " t.fk_page, " ;
2020-11-26 11:09:35 +01:00
$sql .= " t.allowed_in_frames, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.status, " ;
2017-08-20 19:47:55 +02:00
$sql .= " t.grabbed_from, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.date_creation, " ;
2018-09-10 21:55:03 +02:00
$sql .= " t.tms as date_modification, " ;
2018-09-25 15:00:37 +02:00
$sql .= " t.fk_user_creat, " ;
2020-03-12 20:50:36 +01:00
$sql .= " t.author_alias, " ;
2020-04-04 18:35:40 +02:00
$sql .= " t.fk_user_modif, " ;
2020-09-28 18:17:23 +02:00
$sql .= " t.import_key, " ;
2020-10-01 15:18:19 +02:00
$sql .= " t.object_type, " ;
2020-10-07 15:01:28 +02:00
$sql .= " t.fk_object " ;
2019-11-08 15:51:54 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this -> table_element . ' as t' ;
2017-05-30 18:50:54 +02:00
//$sql .= ' WHERE entity IN ('.getEntity('website').')'; // entity is on website level
2017-04-28 13:10:08 +02:00
$sql .= ' WHERE 1 = 1' ;
2021-02-26 12:03:07 +01:00
if ( $id > 0 ) {
2021-03-14 11:48:39 +01:00
$sql .= ' AND t.rowid = ' . (( int ) $id );
2021-02-26 12:03:07 +01:00
} else {
if ( $id < 0 ) {
$sql .= ' AND t.rowid <> ' . abs ( $id );
}
2017-07-21 02:30:02 +02:00
if ( null !== $website_id ) {
2020-10-07 15:01:28 +02:00
$sql .= " AND t.fk_website = ' " . $this -> db -> escape ( $website_id ) . " ' " ;
if ( $page ) {
$pagetouse = $page ;
$langtouse = '' ;
$tmppage = explode ( '/' , $page );
if ( ! empty ( $tmppage [ 1 ])) {
$pagetouse = $tmppage [ 1 ];
2021-02-26 12:03:07 +01:00
if ( strlen ( $tmppage [ 0 ])) {
$langtouse = $tmppage [ 0 ];
}
2020-10-07 15:01:28 +02:00
}
$sql .= " AND t.pageurl = ' " . $this -> db -> escape ( $pagetouse ) . " ' " ;
2021-02-26 12:03:07 +01:00
if ( $langtouse ) {
$sql .= " AND t.lang = ' " . $this -> db -> escape ( $langtouse ) . " ' " ;
}
}
if ( $aliasalt ) {
$sql .= " AND (t.aliasalt LIKE '%, " . $this -> db -> escape ( $aliasalt ) . " ,%' OR t.aliasalt LIKE '%, " . $this -> db -> escape ( $aliasalt ) . " ,%') " ;
2020-10-07 15:01:28 +02:00
}
2017-07-21 02:30:02 +02:00
}
}
2020-10-07 15:01:28 +02:00
$sql .= $this -> db -> plimit ( 1 );
2017-07-02 23:38:19 +02:00
2016-04-19 11:02:55 +02:00
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$numrows = $this -> db -> num_rows ( $resql );
if ( $numrows ) {
$obj = $this -> db -> fetch_object ( $resql );
$this -> id = $obj -> rowid ;
2016-04-27 09:41:42 +02:00
2016-04-19 11:02:55 +02:00
$this -> fk_website = $obj -> fk_website ;
2017-12-02 13:24:21 +01:00
$this -> type_container = $obj -> type_container ;
2018-10-14 18:44:29 +02:00
2016-04-19 11:02:55 +02:00
$this -> pageurl = $obj -> pageurl ;
2018-10-14 18:44:29 +02:00
$this -> ref = $obj -> pageurl ;
2018-02-28 14:36:22 +01:00
$this -> aliasalt = preg_replace ( '/,+$/' , '' , preg_replace ( '/^,+/' , '' , $obj -> aliasalt ));
2018-10-14 18:44:29 +02:00
2016-04-19 11:02:55 +02:00
$this -> title = $obj -> title ;
$this -> description = $obj -> description ;
2018-11-20 18:29:29 +01:00
$this -> image = $obj -> image ;
2016-04-19 11:02:55 +02:00
$this -> keywords = $obj -> keywords ;
2017-10-02 00:08:00 +02:00
$this -> htmlheader = $obj -> htmlheader ;
2016-04-19 11:02:55 +02:00
$this -> content = $obj -> content ;
2017-07-22 20:01:29 +02:00
$this -> lang = $obj -> lang ;
$this -> fk_page = $obj -> fk_page ;
2020-11-26 11:09:35 +01:00
$this -> allowed_in_frames = $obj -> allowed_in_frames ;
2016-04-19 11:02:55 +02:00
$this -> status = $obj -> status ;
2017-08-20 19:47:55 +02:00
$this -> grabbed_from = $obj -> grabbed_from ;
2016-04-19 11:02:55 +02:00
$this -> date_creation = $this -> db -> jdate ( $obj -> date_creation );
$this -> date_modification = $this -> db -> jdate ( $obj -> date_modification );
2018-09-25 15:00:37 +02:00
$this -> fk_user_creat = $obj -> fk_user_creat ;
2020-03-12 20:50:36 +01:00
$this -> author_alias = $obj -> author_alias ;
2018-09-10 21:55:03 +02:00
$this -> fk_user_modif = $obj -> fk_user_modif ;
2020-04-04 18:35:40 +02:00
$this -> import_key = $obj -> import_key ;
2020-10-01 15:18:19 +02:00
$this -> object_type = $obj -> object_type ;
2020-10-07 15:01:28 +02:00
$this -> fk_object = $obj -> fk_object ;
2016-04-19 11:02:55 +02:00
}
$this -> db -> free ( $resql );
if ( $numrows ) {
return 1 ;
} else {
return 0 ;
}
} else {
2019-11-08 15:51:54 +01:00
$this -> errors [] = 'Error ' . $this -> db -> lasterror ();
dol_syslog ( __METHOD__ . ' ' . join ( ',' , $this -> errors ), LOG_ERR );
2016-04-19 11:02:55 +02:00
2019-11-08 15:51:54 +01:00
return - 1 ;
2016-04-19 11:02:55 +02:00
}
}
/**
2020-03-21 11:04:33 +01:00
* Return array of all web site pages .
2016-04-19 11:02:55 +02:00
*
2016-05-07 16:38:32 +02:00
* @ param string $websiteid Web site
* @ param string $sortorder Sort Order
* @ param string $sortfield Sort field
* @ param int $limit limit
* @ param int $offset Offset
* @ param array $filter Filter array
* @ param string $filtermode Filter mode ( AND or OR )
* @ return array | int int < 0 if KO , array of pages if OK
2016-04-19 11:02:55 +02:00
*/
2019-01-27 15:20:16 +01:00
public function fetchAll ( $websiteid , $sortorder = '' , $sortfield = '' , $limit = 0 , $offset = 0 , array $filter = array (), $filtermode = 'AND' )
2016-04-19 11:02:55 +02:00
{
dol_syslog ( __METHOD__ , LOG_DEBUG );
2019-11-08 15:51:54 +01:00
$records = array ();
2016-04-27 09:41:42 +02:00
2016-04-19 11:02:55 +02:00
$sql = 'SELECT' ;
$sql .= ' t.rowid,' ;
$sql .= " t.fk_website, " ;
2017-12-02 13:24:21 +01:00
$sql .= " t.type_container, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.pageurl, " ;
2018-02-28 14:36:22 +01:00
$sql .= " t.aliasalt, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.title, " ;
$sql .= " t.description, " ;
2018-11-20 18:29:29 +01:00
$sql .= " t.image, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.keywords, " ;
2017-10-02 00:08:00 +02:00
$sql .= " t.htmlheader, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.content, " ;
2017-07-22 20:01:29 +02:00
$sql .= " t.lang, " ;
$sql .= " t.fk_page, " ;
2020-11-26 11:09:35 +01:00
$sql .= " t.allowed_in_frames, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.status, " ;
2017-08-20 19:47:55 +02:00
$sql .= " t.grabbed_from, " ;
2016-04-19 11:02:55 +02:00
$sql .= " t.date_creation, " ;
2018-09-10 21:55:03 +02:00
$sql .= " t.tms as date_modification, " ;
2018-09-25 15:00:37 +02:00
$sql .= " t.fk_user_creat, " ;
2020-03-12 20:50:36 +01:00
$sql .= " t.author_alias, " ;
2020-04-04 18:35:40 +02:00
$sql .= " t.fk_user_modif, " ;
2020-09-28 18:17:23 +02:00
$sql .= " t.import_key, " ;
2020-10-01 15:18:19 +02:00
$sql .= " t.object_type, " ;
2020-10-07 15:01:28 +02:00
$sql .= " t.fk_object " ;
2019-11-08 15:51:54 +01:00
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this -> table_element . ' as t' ;
2021-03-30 11:36:50 +02:00
$sql .= ' WHERE t.fk_website = ' . (( int ) $websiteid );
2021-01-26 13:11:10 +01:00
// Manage filter (same than into countAll)
2016-04-19 11:02:55 +02:00
$sqlwhere = array ();
if ( count ( $filter ) > 0 ) {
foreach ( $filter as $key => $value ) {
2021-10-07 16:09:32 +02:00
if ( $key == 't.rowid' || $key == 'rowid' || $key == 't.fk_website' || $key == 'fk_website' || $key == 'status' || $key == 't.status' ) {
2021-08-28 01:45:53 +02:00
$sqlwhere [] = $key . " = " . (( int ) $value );
2021-10-07 16:09:32 +02:00
} elseif ( $key == 'type_container' || $key == 't.type_container' ) {
2020-09-19 22:59:04 +02:00
$sqlwhere [] = $key . " = ' " . $this -> db -> escape ( $value ) . " ' " ;
2020-02-28 18:21:26 +01:00
} elseif ( $key == 'lang' || $key == 't.lang' ) {
2020-05-14 17:27:12 +02:00
$listoflang = array ();
2020-05-14 18:41:31 +02:00
$foundnull = 0 ;
2020-05-21 09:07:10 +02:00
foreach ( explode ( ',' , $value ) as $tmpvalue ) {
2020-05-14 18:41:31 +02:00
if ( $tmpvalue == 'null' ) {
$foundnull ++ ;
continue ;
}
2020-05-14 17:27:12 +02:00
$listoflang [] = " ' " . $this -> db -> escape ( substr ( str_replace ( " ' " , '' , $tmpvalue ), 0 , 2 )) . " ' " ;
}
2021-04-09 01:31:55 +02:00
$stringtouse = $key . " IN ( " . $this -> db -> sanitize ( join ( ',' , $listoflang ), 1 ) . " ) " ;
2021-02-26 12:03:07 +01:00
if ( $foundnull ) {
2021-08-28 01:45:53 +02:00
$stringtouse = " ( " . $stringtouse . " OR " . $key . " IS NULL) " ;
2021-02-26 12:03:07 +01:00
}
2020-05-14 18:41:31 +02:00
$sqlwhere [] = $stringtouse ;
2016-04-27 09:41:42 +02:00
} else {
2021-08-28 01:45:53 +02:00
$sqlwhere [] = $key . " LIKE '% " . $this -> db -> escape ( $value ) . " %' " ;
2016-04-27 09:41:42 +02:00
}
2016-04-19 11:02:55 +02:00
}
}
if ( count ( $sqlwhere ) > 0 ) {
2021-09-02 13:58:42 +02:00
$sql .= " AND ( " . implode ( ' ' . $this -> db -> escape ( $filtermode ) . ' ' , $sqlwhere ) . ')' ;
2016-04-19 11:02:55 +02:00
}
2016-04-27 09:41:42 +02:00
2016-04-19 11:02:55 +02:00
if ( ! empty ( $sortfield )) {
2018-09-25 15:00:37 +02:00
$sql .= $this -> db -> order ( $sortfield , $sortorder );
2016-04-19 11:02:55 +02:00
}
if ( ! empty ( $limit )) {
2021-08-27 22:42:04 +02:00
$sql .= $this -> db -> plimit ( $limit , $offset );
2016-04-19 11:02:55 +02:00
}
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$num = $this -> db -> num_rows ( $resql );
2021-02-26 12:03:07 +01:00
while ( $obj = $this -> db -> fetch_object ( $resql )) {
2017-01-03 11:22:03 +01:00
$record = new self ( $this -> db );
2016-04-23 21:34:10 +02:00
$record -> id = $obj -> rowid ;
$record -> fk_website = $obj -> fk_website ;
2017-12-02 13:24:21 +01:00
$record -> type_container = $obj -> type_container ;
2016-04-23 21:34:10 +02:00
$record -> pageurl = $obj -> pageurl ;
2018-02-28 14:36:22 +01:00
$record -> aliasalt = preg_replace ( '/,+$/' , '' , preg_replace ( '/^,+/' , '' , $obj -> aliasalt ));
2016-04-23 21:34:10 +02:00
$record -> title = $obj -> title ;
$record -> description = $obj -> description ;
2018-11-20 18:29:29 +01:00
$record -> image = $obj -> image ;
2016-04-23 21:34:10 +02:00
$record -> keywords = $obj -> keywords ;
2017-10-02 00:08:00 +02:00
$record -> htmlheader = $obj -> htmlheader ;
2016-04-23 21:34:10 +02:00
$record -> content = $obj -> content ;
2017-07-22 20:01:29 +02:00
$record -> lang = $obj -> lang ;
$record -> fk_page = $obj -> fk_page ;
2020-11-26 11:09:35 +01:00
$record -> allowed_in_frames = $obj -> allowed_in_frames ;
2016-04-23 21:34:10 +02:00
$record -> status = $obj -> status ;
2017-08-20 19:47:55 +02:00
$record -> grabbed_from = $obj -> grabbed_from ;
2016-04-23 21:34:10 +02:00
$record -> date_creation = $this -> db -> jdate ( $obj -> date_creation );
$record -> date_modification = $this -> db -> jdate ( $obj -> date_modification );
2018-09-25 15:00:37 +02:00
$record -> fk_user_creat = $obj -> fk_user_creat ;
2020-03-12 20:50:36 +01:00
$record -> author_alias = $obj -> author_alias ;
2018-09-10 21:55:03 +02:00
$record -> fk_user_modif = $obj -> fk_user_modif ;
2020-04-04 18:35:40 +02:00
$record -> import_key = $obj -> import_key ;
2020-10-01 15:18:19 +02:00
$record -> object_type = $obj -> object_type ;
2020-09-28 18:17:23 +02:00
$record -> fk_object = $obj -> fk_object ;
2016-05-01 21:19:29 +02:00
//var_dump($record->id);
2016-04-23 21:34:10 +02:00
$records [ $record -> id ] = $record ;
2016-04-19 11:02:55 +02:00
}
$this -> db -> free ( $resql );
2016-04-23 21:34:10 +02:00
return $records ;
2016-04-19 11:02:55 +02:00
} else {
2019-11-08 15:51:54 +01:00
$this -> error = 'Error ' . $this -> db -> lasterror ();
2019-08-17 17:39:31 +02:00
$this -> errors [] = $this -> error ;
2019-11-08 15:51:54 +01:00
dol_syslog ( __METHOD__ . ' ' . join ( ',' , $this -> errors ), LOG_ERR );
2016-04-19 11:02:55 +02:00
2016-04-23 21:34:10 +02:00
return - 1 ;
2016-04-19 11:02:55 +02:00
}
}
2020-03-10 15:59:48 +01:00
/**
* Count objects in the database .
*
* @ param string $websiteid Web site
* @ param array $filter Filter array
* @ param string $filtermode Filter mode ( AND or OR )
* @ return int int < 0 if KO , array of pages if OK
*/
public function countAll ( $websiteid , array $filter = array (), $filtermode = 'AND' )
{
dol_syslog ( __METHOD__ , LOG_DEBUG );
$result = 0 ;
$sql = 'SELECT COUNT(t.rowid) as nb' ;
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this -> table_element . ' as t' ;
2021-03-30 11:36:50 +02:00
$sql .= ' WHERE t.fk_website = ' . (( int ) $websiteid );
2021-01-26 13:11:10 +01:00
// Manage filter (same than into fetchAll)
2020-03-10 15:59:48 +01:00
$sqlwhere = array ();
if ( count ( $filter ) > 0 ) {
foreach ( $filter as $key => $value ) {
2021-01-26 13:11:10 +01:00
if ( $key == 't.rowid' || $key == 't.fk_website' || $key == 'status' ) {
2021-08-28 01:45:53 +02:00
$sqlwhere [] = $key . " = " . (( int ) $value );
2021-01-26 13:11:10 +01:00
} elseif ( $key == 'type_container' ) {
$sqlwhere [] = $key . " = ' " . $this -> db -> escape ( $value ) . " ' " ;
2020-03-10 15:59:48 +01:00
} elseif ( $key == 'lang' || $key == 't.lang' ) {
2021-01-26 13:11:10 +01:00
$listoflang = array ();
$foundnull = 0 ;
foreach ( explode ( ',' , $value ) as $tmpvalue ) {
if ( $tmpvalue == 'null' ) {
$foundnull ++ ;
continue ;
}
$listoflang [] = " ' " . $this -> db -> escape ( substr ( str_replace ( " ' " , '' , $tmpvalue ), 0 , 2 )) . " ' " ;
}
2021-04-26 19:12:23 +02:00
$stringtouse = $key . " IN ( " . $this -> db -> sanitize ( join ( ',' , $listoflang ), 1 ) . " ) " ;
2021-02-26 12:03:07 +01:00
if ( $foundnull ) {
2021-08-28 01:45:53 +02:00
$stringtouse = " ( " . $stringtouse . " OR " . $key . " IS NULL) " ;
2021-02-26 12:03:07 +01:00
}
2021-01-26 13:11:10 +01:00
$sqlwhere [] = $stringtouse ;
2020-03-10 15:59:48 +01:00
} else {
2021-08-28 01:45:53 +02:00
$sqlwhere [] = $key . " LIKE '% " . $this -> db -> escape ( $value ) . " %' " ;
2020-03-10 15:59:48 +01:00
}
}
}
if ( count ( $sqlwhere ) > 0 ) {
2021-09-02 13:58:42 +02:00
$sql .= ' AND (' . implode ( ' ' . $this -> db -> escape ( $filtermode ) . ' ' , $sqlwhere ) . ')' ;
2020-03-10 15:59:48 +01:00
}
$resql = $this -> db -> query ( $sql );
if ( $resql ) {
$obj = $this -> db -> fetch_object ( $resql );
if ( $obj ) {
$result = $obj -> nb ;
}
$this -> db -> free ( $resql );
return $result ;
} else {
$this -> error = 'Error ' . $this -> db -> lasterror ();
$this -> errors [] = $this -> error ;
dol_syslog ( __METHOD__ . ' ' . join ( ',' , $this -> errors ), LOG_ERR );
return - 1 ;
}
}
2016-04-19 11:02:55 +02:00
/**
* Update object into database
*
* @ param User $user User that modifies
* @ param bool $notrigger false = launch triggers after , true = disable triggers
2017-08-20 19:47:55 +02:00
* @ return int < 0 if KO , > 0 if OK
2016-04-19 11:02:55 +02:00
*/
public function update ( User $user , $notrigger = false )
{
2018-02-28 14:36:22 +01:00
$this -> description = dol_trunc ( $this -> description , 255 , 'right' , 'utf-8' , 1 );
$this -> keywords = dol_trunc ( $this -> keywords , 255 , 'right' , 'utf-8' , 1 );
2021-02-26 12:03:07 +01:00
if ( $this -> aliasalt ) {
$this -> aliasalt = ',' . preg_replace ( '/,+$/' , '' , preg_replace ( '/^,+/' , '' , $this -> aliasalt )) . ',' ; // content in database must be ',xxx,...,yyy,'
}
2018-02-28 14:36:22 +01:00
2021-06-29 15:29:28 +02:00
$this -> pageurl = preg_replace ( '/[^a-z0-9\-\_]/i' , '' , $this -> pageurl );
$this -> pageurl = preg_replace ( '/\-\-+/' , '-' , $this -> pageurl );
$this -> pageurl = preg_replace ( '/^\-/' , '' , $this -> pageurl );
2020-02-21 11:36:16 +01:00
// Remove spaces and be sure we have main language only
$this -> lang = preg_replace ( '/[_-].*$/' , '' , trim ( $this -> lang )); // en_US or en-US -> en
if ( $this -> fk_page > 0 ) {
if ( empty ( $this -> lang )) {
$this -> error = " ErrorLanguageMandatoryIfPageSetAsTranslationOfAnother " ;
return - 1 ;
}
$tmppage = new WebsitePage ( $this -> db );
$tmppage -> fetch ( $this -> fk_page );
if ( $tmppage -> lang == $this -> lang ) {
$this -> error = " ErrorLanguageOfTranslatedPageIsSameThanThisPage " ;
return - 1 ;
}
}
2017-08-20 19:47:55 +02:00
return $this -> updateCommon ( $user , $notrigger );
2016-04-19 11:02:55 +02:00
}
/**
* Delete object in database
*
2017-08-20 18:50:51 +02:00
* @ param User $user User that deletes
* @ param bool $notrigger false = launch triggers after , true = disable triggers
* @ return int < 0 if KO , > 0 if OK
2016-04-19 11:02:55 +02:00
*/
public function delete ( User $user , $notrigger = false )
{
2022-07-12 10:56:03 +02:00
global $conf ;
2020-06-06 18:57:24 +02:00
$error = 0 ;
// Delete all child tables
if ( ! $error ) {
2021-02-26 12:03:07 +01:00
foreach ( $this -> childtablesoncascade as $table ) {
2020-06-06 18:57:24 +02:00
$sql = " DELETE FROM " . MAIN_DB_PREFIX . $table ;
$sql .= " WHERE fk_website_page = " . ( int ) $this -> id ;
$result = $this -> db -> query ( $sql );
if ( ! $result ) {
$error ++ ;
$this -> errors [] = $this -> db -> lasterror ();
break ;
}
}
}
if ( ! $error ) {
2022-07-12 10:09:01 +02:00
$result = $this -> deleteCommon ( $user , $notrigger );
2021-02-26 12:03:07 +01:00
if ( $result <= 0 ) {
2020-06-06 18:57:24 +02:00
$error ++ ;
}
}
2017-10-07 02:29:27 +02:00
2021-02-26 12:03:07 +01:00
if ( ! $error ) {
2019-11-08 15:51:54 +01:00
$websiteobj = new Website ( $this -> db );
2017-10-07 02:29:27 +02:00
$result = $websiteobj -> fetch ( $this -> fk_website );
2021-02-26 12:03:07 +01:00
if ( $result > 0 ) {
2017-10-07 02:29:27 +02:00
global $dolibarr_main_data_root ;
2022-04-25 10:14:30 +02:00
$pathofwebsite = $dolibarr_main_data_root . ( $conf -> entity > 1 ? '/' . $conf -> entity : '' ) . '/website/' . $websiteobj -> ref ;
2017-10-07 02:29:27 +02:00
2019-11-08 15:51:54 +01:00
$filealias = $pathofwebsite . '/' . $this -> pageurl . '.php' ;
$filetpl = $pathofwebsite . '/page' . $this -> id . '.tpl.php' ;
2017-10-07 02:29:27 +02:00
dol_delete_file ( $filealias );
dol_delete_file ( $filetpl );
2020-06-11 18:31:26 +02:00
} else {
$this -> error = $websiteobj -> error ;
$this -> errors = $websiteobj -> errors ;
2017-10-07 02:29:27 +02:00
}
}
2020-10-07 15:01:28 +02:00
if ( ! $error ) {
2020-06-11 18:31:26 +02:00
return 1 ;
} else {
return - 1 ;
}
2016-04-19 11:02:55 +02:00
}
/**
* Load an object from its id and create a new one in database
*
2017-08-03 01:45:31 +02:00
* @ param User $user User making the clone
2017-07-22 20:01:29 +02:00
* @ param int $fromid Id of object to clone
* @ param string $newref New ref / alias of page
* @ param string $newlang New language
* @ param int $istranslation 1 = New page is a translation of the cloned page .
2018-08-13 23:22:20 +02:00
* @ param int $newwebsite 0 = Same web site , > 0 = Id of new website
2020-01-11 14:44:12 +01:00
* @ param string $newtitle New title
2017-08-21 00:40:45 +02:00
* @ return mixed New object created , < 0 if KO
2016-04-19 11:02:55 +02:00
*/
2020-01-11 14:44:12 +01:00
public function createFromClone ( User $user , $fromid , $newref , $newlang = '' , $istranslation = 0 , $newwebsite = 0 , $newtitle = '' )
2016-04-19 11:02:55 +02:00
{
2017-08-03 01:45:31 +02:00
global $hookmanager , $langs ;
2019-01-15 10:53:28 +01:00
$now = dol_now ();
2017-08-03 01:45:31 +02:00
$error = 0 ;
2017-07-21 13:38:13 +02:00
2016-04-19 11:02:55 +02:00
dol_syslog ( __METHOD__ , LOG_DEBUG );
2017-07-21 13:38:13 +02:00
$object = new self ( $this -> db );
2016-04-19 11:02:55 +02:00
2020-01-11 14:44:12 +01:00
// Clean parameters
2020-01-16 02:54:00 +01:00
if ( empty ( $newref ) && ! empty ( $newtitle )) {
$newref = strtolower ( dol_sanitizeFileName ( preg_replace ( '/\s+/' , '-' , $newtitle ), '-' , 1 ));
2020-01-11 14:44:12 +01:00
}
// Check parameters
if ( empty ( $newref )) {
$langs -> load ( " errors " );
2020-01-16 02:54:00 +01:00
$this -> error = $langs -> trans ( " ErrorFieldRequired " , $langs -> transnoentitiesnoconv ( " WEBSITE_TITLE " ));
2020-01-11 14:44:12 +01:00
return - 1 ;
}
2016-04-19 11:02:55 +02:00
$this -> db -> begin ();
// Load source object
$object -> fetch ( $fromid );
// Reset object
$object -> id = 0 ;
// Clear fields
2017-07-22 20:01:29 +02:00
$object -> ref = $newref ;
$object -> pageurl = $newref ;
2018-02-28 14:36:22 +01:00
$object -> aliasalt = '' ;
2018-09-25 15:00:37 +02:00
$object -> fk_user_creat = $user -> id ;
2020-03-12 20:50:36 +01:00
$object -> author_alias = '' ;
2019-01-15 10:53:28 +01:00
$object -> date_creation = $now ;
2020-01-11 14:44:12 +01:00
$object -> title = ( $newtitle == '1' ? $object -> title : ( $newtitle ? $newtitle : $object -> title ));
2020-12-06 15:59:19 +01:00
$object -> description = $object -> title ;
2021-02-26 12:03:07 +01:00
if ( ! empty ( $newlang )) {
$object -> lang = $newlang ;
}
if ( $istranslation ) {
$object -> fk_page = $fromid ;
} else {
$object -> fk_page = 0 ;
}
if ( ! empty ( $newwebsite )) {
$object -> fk_website = $newwebsite ;
}
2020-04-04 18:35:40 +02:00
$object -> import_key = '' ;
2022-03-24 15:42:01 +01:00
$object -> status = self :: STATUS_DRAFT ;
2016-04-19 11:02:55 +02:00
// Create clone
2017-08-03 01:45:31 +02:00
$object -> context [ 'createfromclone' ] = 'createfromclone' ;
2016-04-19 11:02:55 +02:00
$result = $object -> create ( $user );
if ( $result < 0 ) {
2017-07-21 13:38:13 +02:00
$error ++ ;
$this -> error = $object -> error ;
2016-04-19 11:02:55 +02:00
$this -> errors = $object -> errors ;
2019-11-08 15:51:54 +01:00
dol_syslog ( __METHOD__ . ' ' . join ( ',' , $this -> errors ), LOG_ERR );
2016-04-19 11:02:55 +02:00
}
2019-01-19 12:46:38 +01:00
unset ( $object -> context [ 'createfromclone' ]);
2016-04-19 11:02:55 +02:00
// End
if ( ! $error ) {
$this -> db -> commit ();
2017-08-21 00:40:45 +02:00
return $object ;
2016-04-19 11:02:55 +02:00
} else {
$this -> db -> rollback ();
2017-07-21 13:38:13 +02:00
return - 1 ;
2016-04-19 11:02:55 +02:00
}
}
/**
* Return a link to the user card ( with optionaly the picto )
* Use this -> id , this -> lastname , this -> firstname
*
* @ param int $withpicto Include picto in link ( 0 = No picto , 1 = Include picto into link , 2 = Only picto )
* @ param string $option On what the link point to
2020-10-07 15:01:28 +02:00
* @ param integer $notooltip 1 = Disable tooltip
* @ param int $maxlen Max length of visible user name
* @ param string $morecss Add more css on link
2016-04-19 11:02:55 +02:00
* @ return string String with URL
*/
2019-02-25 20:35:59 +01:00
public function getNomUrl ( $withpicto = 0 , $option = '' , $notooltip = 0 , $maxlen = 24 , $morecss = '' )
2016-04-19 11:02:55 +02:00
{
global $langs , $conf , $db ;
2020-10-07 15:01:28 +02:00
global $dolibarr_main_authentication , $dolibarr_main_demo ;
global $menumanager ;
$result = '' ;
$label = '<u>' . $langs -> trans ( " Page " ) . '</u>' ;
$label .= '<br>' ;
$label .= '<b>' . $langs -> trans ( 'Ref' ) . ':</b> ' . $this -> ref . '<br>' ;
$label .= '<b>' . $langs -> trans ( 'ID' ) . ':</b> ' . $this -> id . '<br>' ;
$label .= '<b>' . $langs -> trans ( 'Title' ) . ':</b> ' . $this -> title . '<br>' ;
$label .= '<b>' . $langs -> trans ( 'Language' ) . ':</b> ' . $this -> lang ;
$url = DOL_URL_ROOT . '/website/index.php?websiteid=' . $this -> fk_website . '&pageid=' . $this -> id ;
$linkclose = '' ;
2021-02-26 12:03:07 +01:00
if ( empty ( $notooltip )) {
if ( ! empty ( $conf -> global -> MAIN_OPTIMIZEFORTEXTBROWSER )) {
2020-10-07 15:01:28 +02:00
$label = $langs -> trans ( " ShowMyObject " );
$linkclose .= ' alt="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
}
$linkclose .= ' title="' . dol_escape_htmltag ( $label , 1 ) . '"' ;
$linkclose .= ' class="classfortooltip' . ( $morecss ? ' ' . $morecss : '' ) . '"' ;
2021-02-26 12:03:07 +01:00
} else {
$linkclose = ( $morecss ? ' class="' . $morecss . '"' : '' );
2020-10-07 15:01:28 +02:00
}
$linkstart = '<a href="' . $url . '"' ;
$linkstart .= $linkclose . '>' ;
2019-11-08 15:51:54 +01:00
$linkend = '</a>' ;
2016-04-19 11:02:55 +02:00
2019-10-31 21:09:33 +01:00
//$linkstart = $linkend = '';
$result .= $linkstart ;
2021-02-26 12:03:07 +01:00
if ( $withpicto ) {
$result .= img_picto (( $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 ;
}
2019-10-31 21:09:33 +01:00
$result .= $linkend ;
2017-10-26 02:55:43 +02:00
2016-04-19 11:02:55 +02:00
return $result ;
}
2016-04-27 09:41:42 +02:00
2016-04-19 11:02:55 +02:00
/**
* Retourne le libelle du status d ' un user ( actif , inactif )
*
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long , 5 = Libelle court + Picto
* @ return string Label of status
*/
2019-02-25 20:35:59 +01:00
public function getLibStatut ( $mode = 0 )
2016-04-19 11:02:55 +02:00
{
2019-01-27 11:55:16 +01:00
return $this -> LibStatut ( $this -> status , $mode );
2016-04-19 11:02:55 +02:00
}
2020-10-07 15:01:28 +02:00
// phpcs:disable PEAR.NamingConventions.ValidFunctionName.ScopeNotCamelCaps
2016-04-19 11:02:55 +02:00
/**
* Renvoi le libelle d ' un status donne
*
* @ param int $status Id status
* @ param int $mode 0 = libelle long , 1 = libelle court , 2 = Picto + Libelle court , 3 = Picto , 4 = Picto + Libelle long , 5 = Libelle court + Picto
* @ return string Label of status
*/
2019-02-25 20:35:59 +01:00
public function LibStatut ( $status , $mode = 0 )
2016-04-19 11:02:55 +02:00
{
2020-10-07 15:01:28 +02:00
// phpcs:enable
2016-04-19 11:02:55 +02:00
global $langs ;
2021-02-26 12:03:07 +01:00
if ( empty ( $this -> labelStatus ) || empty ( $this -> labelStatusShort )) {
2019-10-31 21:09:33 +01:00
global $langs ;
//$langs->load("mymodule");
2021-10-16 19:37:57 +02:00
$this -> labelStatus [ self :: STATUS_DRAFT ] = $langs -> transnoentitiesnoconv ( 'Disabled' );
$this -> labelStatus [ self :: STATUS_VALIDATED ] = $langs -> transnoentitiesnoconv ( 'Enabled' );
$this -> labelStatusShort [ self :: STATUS_DRAFT ] = $langs -> transnoentitiesnoconv ( 'Disabled' );
$this -> labelStatusShort [ self :: STATUS_VALIDATED ] = $langs -> transnoentitiesnoconv ( 'Enabled' );
2016-04-19 11:02:55 +02:00
}
2019-10-31 21:09:33 +01:00
$statusType = 'status5' ;
2021-02-26 12:03:07 +01:00
if ( $status == self :: STATUS_VALIDATED ) {
$statusType = 'status4' ;
}
2019-10-31 21:09:33 +01:00
2019-11-01 12:52:03 +01:00
return dolGetStatus ( $this -> labelStatus [ $status ], $this -> labelStatusShort [ $status ], '' , $statusType , $mode );
2016-04-19 11:02:55 +02:00
}
2016-04-27 09:41:42 +02:00
2020-05-26 01:07:09 +02:00
/**
* Sets object to given categories .
*
* Deletes object from existing categories not supplied .
* Adds it to non existing supplied categories .
* Existing categories are left untouch .
*
* @ param int [] | int $categories Category ID or array of Categories IDs
* @ return int < 0 if KO , > 0 if OK
*/
public function setCategories ( $categories )
{
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php' ;
return $this -> setCategoriesCommon ( $categories , Categorie :: TYPE_WEBSITE_PAGE );
}
2016-04-27 09:41:42 +02:00
2016-04-19 11:02:55 +02:00
/**
* Initialise object with example values
* Id must be 0 if object instance is a specimen
*
* @ return void
*/
public function initAsSpecimen ()
{
2018-09-10 21:55:03 +02:00
global $user ;
2016-04-19 11:02:55 +02:00
$this -> id = 0 ;
2016-04-27 09:41:42 +02:00
2019-11-08 15:51:54 +01:00
$now = dol_now ();
2017-07-02 23:38:19 +02:00
2016-04-19 11:02:55 +02:00
$this -> fk_website = '' ;
2017-12-02 13:24:21 +01:00
$this -> type_container = 'page' ;
$this -> pageurl = 'specimen' ;
2018-02-28 14:36:22 +01:00
$this -> aliasalt = 'specimenalt' ;
2017-01-03 11:22:03 +01:00
$this -> title = 'My Page' ;
$this -> description = 'This is my page' ;
2018-11-20 18:29:29 +01:00
$this -> image = '' ;
2017-01-03 11:22:03 +01:00
$this -> keywords = 'keyword1, keyword2' ;
2020-11-26 11:09:35 +01:00
$this -> allowed_in_frames = 1 ;
2017-10-02 00:08:00 +02:00
$this -> htmlheader = '' ;
2017-01-03 11:22:03 +01:00
$this -> content = '<html><body>This is a html content</body></html>' ;
2016-04-19 11:02:55 +02:00
$this -> status = '' ;
2017-08-20 19:47:55 +02:00
$this -> grabbed_from = '' ;
2017-01-03 11:22:03 +01:00
$this -> date_creation = $now - ( 24 * 30 * 3600 );
$this -> date_modification = $now - ( 24 * 7 * 3600 );
2018-09-25 15:00:37 +02:00
$this -> fk_user_creat = $user -> id ;
2020-03-12 20:50:36 +01:00
$this -> author_alias = 'mypublicpseudo' ;
2016-04-19 11:02:55 +02:00
}
}