Skip to main content

Entity Management

@ZeyOS.Object — entity management (28 methods)

The Object class provides an ORM-like interface for reading and writing ZeyOS entities (contacts, transactions, tasks, etc.):

ZYMBA
// Load an existing entity
$contact = new @ZeyOS.Object("contacts", $contactId);
$contact.load();

echo $contact.getID();
echo $contact.getEntity(); // "contacts"
echo $contact.getField("name");
echo $contact.getField("email");

$fieldNames = $contact.listFieldNames();
$allFields = $contact.listFields(); // key-value pairs

Creating and updating

ZYMBA
$contact = new @ZeyOS.Object("contacts");

$contact.setField("name", "Alice Smith");
$contact.setField("email", "[email protected]");

// Or set multiple fields at once
$contact.setFields([
name: "Alice Smith",
status: 1
]);

$contact.save();
echo $contact.getID(); // New ID after insert

Specialized field methods

ZYMBA
// JSON field (auto-serializes arrays)
$contact.setFieldJSON("metadata", [source: "api", version: 2]);
$meta = $contact.getFieldJSON("metadata");

// Array field
$contact.setFieldArray("tags", ["vip", "premium"]);
$tags = $contact.getFieldArray("tags");

// Encrypted field
$contact.setFieldEncrypted("ssn", "123-45-6789");

// Binary file attachment
$contact.writeBinFile("avatar", $imageData);
$avatar = $contact.readBinFile("avatar");

Deleting

ZYMBA
if ($contact.canDelete()) {
$contact.delete();
}

// Erase with callback for related records
$contact.erase(function($entity, $id) {
@Console.log("Cascading delete: $entity #$id");
});

Extended data and tags

ZYMBA
$extData = $contact.selectExtData();
$tags = $contact.selectTags();

@ZeyOS.ObjectTransaction — transaction documents (17 methods)

Extends @ZeyOS.Object with transaction-specific operations (invoices, orders, etc.):

ZYMBA
$order = new @ZeyOS.ObjectTransaction($orderId);
$order.load();

echo $order.isBilling(); // Is this an invoice?
echo $order.isProcurement(); // Is this a purchase order?
echo $order.isProduction(); // Is this a production order?

// Line items
$items = $order.getItems();

$order.setItems([
[itemID: $item1Id, quantity: 2, unitprice: 9.99],
[itemID: $item2Id, quantity: 1, unitprice: 29.99]
]);

// Calculate totals
$order.calculateTotals();
$order.calculateTaxes();
echo $order.getBalance();

// Process (book inventory, create accounting entries)
$order.process($fields, $serials);

// Close/cancel
if ($order.canClose()) $order.close();
if ($order.canCancel()) $order.cancel();

// Import/export XML
$xml = $order.toXML("zugferd", "invoice");
$order.fromXML($xmlString);

@ZeyOS.TransactionContext

Wrap multiple entity operations in a single atomic database transaction:

ZYMBA
with (new @ZeyOS.TransactionContext) {
$order = new @ZeyOS.ObjectTransaction();
$order.setFields([name: "New Order", contactID: $customerId]);
$order.save();

for ($items as $item) {
$lineItem = new @ZeyOS.ObjectTransaction();
$lineItem.setFields($item);
$lineItem.save();
}
// Auto-commits. If any save() throws, everything rolls back.
}

@ZeyOS.ObjectUser — user management (19 methods)

ZYMBA
$user = new @ZeyOS.ObjectUser($userId);
$user.load();

echo $user.isAdmin();
echo $user.getLang(); // "en", "de", etc.
echo $user.getLastLogin();

// Permissions
echo $user.hasAccess("contacts", true); // Can write contacts?
echo $user.hasPermission("admin.settings"); // Has permission?
echo $user.hasPermissionApp("myapp"); // Can access app?
echo $user.inGroup($groupId); // In group?

$groups = $user.listGroups();
$perms = $user.listPermissions();
$apps = $user.listPermittedApps();

// Password management
$user.setPassword("newPassword");
$valid = $user.verifyPassword("inputPassword");

// Settings
$settings = $user.getSettings();
$user.setSettings($newSettings);

@ZeyOS.ExtData — extended data fields (12 methods)

Custom fields beyond the standard entity schema:

ZYMBA
$ext = new @ZeyOS.ExtData("contacts", $contactId);

$ext.setField("customField1", "value");
$ext.setFields([field1: "a", field2: "b"]);

echo $ext.getField("customField1");
echo $ext.hasField("customField1"); // true
echo $ext.countFields();

$names = $ext.listFieldNames();
$all = $ext.listFields();

$ext.removeFields(["field1", "field2"]);
$ext.clear(); // Remove all extended data

@ZeyOS.Tags — entity tagging (12 methods)

ZYMBA
$tags = new @ZeyOS.Tags("contacts", $contactId);

$tags.addTags(["vip", "premium", "active"]);
echo $tags.hasTag("vip"); // true
echo $tags.hasAllTags(["vip", "active"]); // true
echo $tags.hasAnyTags(["vip", "deleted"]); // true
echo $tags.countTags(); // 3

$list = $tags.listTags(); // ["vip", "premium", "active"]

$tags.removeTags(["active"]);
$tags.resetTags(["vip", "premium"]); // Replace all tags
$tags.clear(); // Remove all tags

@ZeyOS.NumFormat — document numbering (6 methods)

Auto-incrementing number sequences for document numbering:

ZYMBA
$fmt = new @ZeyOS.NumFormat("invoice");

echo $fmt.getName(); // "invoice"
echo $fmt.getFormat(); // Format pattern
echo $fmt.getNumber(); // Current counter value

$next = $fmt.nextNumber(); // Get next number in sequence
$fmt.incrementCounter(1); // Manually increment

@ZeyOS.BinFile — binary file storage (6 methods)

ZYMBA
$file = new @ZeyOS.BinFile($fileId);

if ($file.exists()) {
$content = $file.read();
$file.readOut(); // Stream directly to output
}

$file.write($binaryData);
echo $file.getID();

@ZeyOS.TempFile — temporary files (10 methods)

ZYMBA
$tmp = new @ZeyOS.TempFile("export");

$tmp.write("CSV content here");
$tmp.writeJSON([data: $rows]);

$content = $tmp.read();
$data = $tmp.readJSON();

echo $tmp.getName(); // Temp file name
echo $tmp.getPath(); // Full file path

$tmp.reserve(); // Prevent auto-cleanup
$tmp.delete(); // Manual cleanup

@ZeyOS.KeyAuth — API key authentication (2 methods)

ZYMBA
// Create an authentication hash from a key
$hash = @ZeyOS.KeyAuth.create($apiKey);

// Verify a key against the stored hash
$valid = @ZeyOS.KeyAuth.verify($apiKey);