From f721338bd8dbaaff0b6a9c99c2f7c4b8daeb866f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Fri, 30 Oct 2020 07:57:53 +0100 Subject: [PATCH] work on members --- htdocs/adherents/class/adherent.class.php | 23 ++++++++++++++------ htdocs/adherents/class/api_members.class.php | 8 +++++-- 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/htdocs/adherents/class/adherent.class.php b/htdocs/adherents/class/adherent.class.php index c48b00050f8..f18ee002cfd 100644 --- a/htdocs/adherents/class/adherent.class.php +++ b/htdocs/adherents/class/adherent.class.php @@ -2274,14 +2274,16 @@ class Adherent extends CommonObject * Used to build previews or test instances. * id must be 0 if object instance is a specimen. * - * @return void + * @return int */ public function initAsSpecimen() { global $user, $langs; + $now = dol_now(); // Initialise parametres $this->id = 0; + $this->entity = 1; $this->specimen = 1; $this->civility_id = 0; $this->lastname = 'DOLIBARR'; @@ -2298,24 +2300,30 @@ class Adherent extends CommonObject $this->country = 'France'; $this->morphy = 'mor'; $this->email = 'specimen@specimen.com'; - $this->socialnetworks = array('skype' => 'skypepseudo', 'twitter' => 'twitterpseudo', 'facebook' => 'facebookpseudo', 'linkedin' => 'linkedinpseudo'); + $this->socialnetworks = array( + 'skype' => 'skypepseudo', + 'twitter' => 'twitterpseudo', + 'facebook' => 'facebookpseudo', + 'linkedin' => 'linkedinpseudo', + ); $this->phone = '0999999999'; $this->phone_perso = '0999999998'; $this->phone_mobile = '0999999997'; - $this->note_private = 'No comment'; - $this->birth = time(); + $this->note_public = 'This is a public note'; + $this->note_private = 'This is a private note'; + $this->birth = $now; $this->photo = ''; $this->public = 1; $this->statut = 0; - $this->datefin = time(); - $this->datevalid = time(); + $this->datefin = $now; + $this->datevalid = $now; $this->typeid = 1; // Id type adherent $this->type = 'Type adherent'; // Libelle type adherent $this->need_subscription = 0; - $this->first_subscription_date = time(); + $this->first_subscription_date = $now; $this->first_subscription_date_start = $this->first_subscription_date; $this->first_subscription_date_end = dol_time_plus_duree($this->first_subscription_date_start, 1, 'y'); $this->first_subscription_amount = 10; @@ -2324,6 +2332,7 @@ class Adherent extends CommonObject $this->last_subscription_date_start = $this->first_subscription_date; $this->last_subscription_date_end = dol_time_plus_duree($this->last_subscription_date_start, 1, 'y'); $this->last_subscription_amount = 10; + return 1; } diff --git a/htdocs/adherents/class/api_members.class.php b/htdocs/adherents/class/api_members.class.php index 230b839f726..66bc91c0cf1 100644 --- a/htdocs/adherents/class/api_members.class.php +++ b/htdocs/adherents/class/api_members.class.php @@ -65,8 +65,12 @@ class Members extends DolibarrApi throw new RestException(401); } - $member = new Adherent($this->db); - $result = $member->fetch($id); + $member = new Adherent($this->db); + if ($id == 0) { + $result = $member->initAsSpecimen(); + } else { + $result = $member->fetch($id); + } if (!$result) { throw new RestException(404, 'member not found'); }