NDEVR
API Documentation
CustomerSession.h
1#pragma once
2#include "Design/Headers/ContactInfo.h"
3#include "Design/Headers/Model.h"
4#include "Base/Headers/String.h"
5#include "Base/Headers/Time.h"
6#include "Base/Headers/JSONParser.h"
7namespace NDEVR
8{
11 class Password : public Model
12 {
13 public:
17 Password(const Model& model)
18 : Model(model)
19 {
21 {
23 }
24 }
25
29 {
31 }
32
35 void setPassword(const String& address)
36 {
38 }
39
42 static constexpr const char* TypeName() { return "password"; }
43 };
44
47 class CustomerDevice : public Model
48 {
49 public:
53 CustomerDevice(const Model& model)
54 : Model(model)
55 {
57 {
59 set(NDPO::name, "PC");
60 set(NDPO::icon, "mobile");
61 }
62 }
63
67 {
68 return metaData("os_name").getAs<String>();
69 }
70
73 void setOSName(const String& os_name)
74 {
75 setMetaData("os_name", os_name);
76 }
77
84
88 {
89 return metaData("serial_number").getAs<StringView>();
90 }
91
94 void setSerialNumber(const String& serial)
95 {
96 setMetaData("serial_number", serial);
97 }
98
101 static constexpr const char* TypeName() { return "customer_device"; }
102 };
103
106 class CustomerJob : public Model
107 {
108 public:
112 CustomerJob(const Model& model)
113 : Model(model)
114 {
115 if (get<NDPN::type>() != TypeName())
116 {
118 set(NDPO::icon, "edit_map");
119 setActive(false);
120 }
121 }
122
126 bool isActive() const
127 {
129 }
130
133 void setActive(bool active)
134 {
136 }
137
140 static TranslatedString JobLabel() { return _t("Blast"); }
144 static constexpr const char* TypeName() { return "customer_job"; }
145 };
146
153 class Customer : public Model
154 {
155 public:
159 Customer(const Model& model)
160 : Model(model)
161 {
163 {
165 set(NDPO::icon, "open");
166 }
167 }
168
175
179 {
180 return getTypeChildren<PhysicalAddressModel>(PhysicalAddressModel::TypeName());
181 }
182
186 {
187 return getTypeChildren<TelephoneNumber>(TelephoneNumber::TypeName());
188 }
189
193 {
195 if (name.contains(','))
196 return name.split(',')[1].trimWhiteSpace();
197 return name;
198 }
199
203 {
205 if (name.contains(','))
206 return name.split(',')[0];
207 return "";
208 }
209
213 void updateFirstName(const String& name, const void* lock_ptr = nullptr)
214 {
215 StringView last_name = surname();
216 if (name.size() > 0 && last_name.size() > 0)
217 update(NDPO::name, last_name + ", " + name, lock_ptr);
218 else if (name.size() > 0)
219 update(NDPO::name, name, lock_ptr);
220 else
221 update(NDPO::name, ", " + last_name, lock_ptr);
222 }
223
227 void updateSurname(const String& name, const void* lock_ptr = nullptr)
228 {
229 String first_name = firstName();
230 if(name.size() > 0 && first_name.size() > 0)
231 update(NDPO::name, name + ", " + first_name, lock_ptr);
232 else if(name.size() > 0)
233 update(NDPO::name, ", " + name, lock_ptr);
234 else
235 update(NDPO::name, first_name, lock_ptr);
236 }
237
241 {
242 if (hasMetaData("email"))
243 return metaData("email").getAs<StringView>();
244 return String();
245 }
246
249 void setEmail(const String& company_name)
250 {
251 setMetaData("email", company_name);
252 }
253
257 {
258 /*$vcard = "BEGIN:VCARD\r\nVERSION:3.0\r\n
259 N:" . $_POST['surname'] . "; " . $_POST['name'] . "\r\n
260 FN : " . $_POST['name'] . " " . $_POST['surname'] . "\r\n
261 ORG : Example Organisation\r\n
262 TITLE : " . $_POST['position'] . "[" . $_POST['qualification'] . "]\r\n
263 TEL; TYPE = work, voice:" . $_POST['telephone'] . "\r\n
264 TEL; TYPE = cell, voice:" . $_POST['cellno'] . "\r\n
265 TEL; TYPE = work, fax:" . $_POST['fax'] . "\r\n
266 URL; TYPE = work:www.example.com\r\n
267 EMAIL; TYPE = internet, pref:" . $_POST['email'] . "\r\n
268 REV : " . date('Ymd') . "T195243Z\r\n
269 END : VCARD";*/
270 }
271
275 {
276 if (hasMetaData("company"))
277 return metaData("company").getAs<StringView>();
278 return StringView();
279 }
280
283 void setCompany(const String& company_name)
284 {
285 setMetaData("company", company_name);
286 }
287
290 bool hasActiveJob() const
291 {
292 Buffer<CustomerJob> current_jobs = jobs();
293 for(const CustomerJob& job : current_jobs)
294 {
295 if (job.isActive())
296 return true;
297 }
298 return false;
299 }
300
303 static constexpr const char* TypeName() { return "customer"; }
304 };
305
306}
The equivelent of std::vector but with a bit more control.
Definition Buffer.hpp:58
CustomerDevice(const Model &model)
Constructs a CustomerDevice model from an existing Model.
void setSerialNumber(const String &serial)
Sets the serial number of the device.
StringView serialNumber() const
Returns the serial number of the device.
void setOSName(const String &os_name)
Sets the operating system name of the device.
static constexpr const char * TypeName()
Returns the type name identifier for this model type.
StringView osName() const
Returns the operating system name of the device.
Buffer< Password > passwords() const
Returns all password entries stored under this device.
Model representing a customer job (e.g.
bool isActive() const
Returns whether this job is currently active.
void setActive(bool active)
Sets the active state of the job.
static constexpr const char * TypeName()
Returns the type name identifier for this model type.
static TranslatedString JobLabel()
Returns the translated display label for jobs.
CustomerJob(const Model &model)
Constructs a CustomerJob model from an existing Model.
Customer(const Model &model)
Constructs a Customer model from an existing Model.
StringView company() const
Returns the customer's company name.
void setCompany(const String &company_name)
Sets the customer's company name.
String getQRCode() const
Generates a vCard QR code string for this customer.
Buffer< PhysicalAddressModel > addresses() const
Returns all physical addresses associated with this customer.
static constexpr const char * TypeName()
Returns the type name identifier for this model type.
void updateSurname(const String &name, const void *lock_ptr=nullptr)
Updates the surname while preserving the first name.
StringView email() const
Returns the customer's email address.
StringView surname() const
Returns the surname portion of the customer name.
Buffer< TelephoneNumber > phoneNumbers() const
Returns all phone numbers associated with this customer.
void setEmail(const String &company_name)
Sets the customer's email address.
StringView firstName() const
Returns the first name portion of the customer name.
void updateFirstName(const String &name, const void *lock_ptr=nullptr)
Updates the first name while preserving the surname.
bool hasActiveJob() const
Checks whether this customer has any active jobs.
Buffer< CustomerJob > jobs() const
Returns all jobs associated with this customer.
constexpr decltype(auto) get(t_property_type property) const
Retrieves a property value from the database, cast to the requested type.
void set(t_property_type property, const t_type &value)
Sets a property value in the database.
constexpr decltype(auto) get() const
Retrieves a property value using a compile-time property constant, cast to the requested type.
bool hasMetaData(const StringView &index) const
Checks whether a metadata entry exists for the given key.
const JSONNode & metaData() const
Retrieves the entire metadata tree for this design object.
void setMetaData(const JSONNode &node)
Replaces the entire metadata tree with the given JSON node.
bool update(t_property_type property, const t_type &value, const void *lock=nullptr)
Updates a property only if the new value differs from the current value.
decltype(auto) getAs() const
Definition JSONParser.h:315
Buffer< t_type > getTypeChildren(const StringView &type) const
Returns children of a specific type, cast to the requested derived type.
Definition Model.h:770
ModelBuffer getChildrenByType(const StringView &type) const
Returns all direct children whose type matches the given string.
Model()
Default constructor. Creates an uninitialized Model.
Definition Model.h:365
String password() const
Returns the stored password string.
void setPassword(const String &address)
Sets the password string.
Password(const Model &model)
Constructs a Password model from an existing Model.
static constexpr const char * TypeName()
Returns the type name identifier for this model type.
The core String View class for the NDEVR API.
Definition StringView.h:58
constexpr uint04 size() const
Returns the byte size of this string view.
Definition StringView.h:435
The core String class for the NDEVR API.
Definition String.h:95
Any text displayed to the user should be defined as a TranslatedString which allows the program to lo...
The primary namespace for the NDEVR SDK.
@ type
The type identifier string for this model node.
Definition Model.h:58
@ uncompressed_data
Uncompressed binary data storage.
@ name
The display name of the object.
@ icon
Icon identifier for the object.
@ spacial_visible
Whether the object is visible in the 3D spatial view.