OOP plays a central role for Topincs when working with data in the store.
Tobjects represent topics and domain classes are used for type specific behavior.
For almost everything else there is simply a global function.
This is delibarate choice to increase productivity. Always use the simplest concept that works!
Even the smallest unnecessary increase in complexity will slow you down in a frequent task like
programming PDF or email generation, therefore neither classes nor namespaces.
It should be as simple as a function call.
Require the session to contain a task and the request to contain its correct solution. If either one is missing, the request execution is stopped and a randomly selected task is sent to the client.
Return the numeric id of the user group the current user account is a member of. The id of the user group unauthenticated is always 0, independent of the actual system id of the topic representing this user group.
[%email(
from: "batman@topincs.com",
to: "justiceleague@topincs.com",
cc: "superman@topincs.com",
subject: "Mess in the community kitchen",
text: "Dear all,\ni do not wanna complain again, but Superman has again …"
);%]
Override the negotiated UI lanuage in a mutilingual store. This is useful when a service is made available in a single language only with inline forms or service calls.
Change the language to a specific one. Labels, the word function family, and the txt function will respect this. Return back to initial languge, by passing nothing.
lang
(
?string$lang
)
:
void
Examples
[%lang("de");%]
[%lang($customer->get_language()->get_iso_code());
email(
to: $customer->get_email(),
subject: txt("invoice"),
text: twig("invoice.txt.twig", $context)
);%]
[%// Creating a login link that is valid for a maximum of 7 days:
$login_url = url(".login?" . ticket($some_user_name));%]
[%// Create a link to a service with the formal name %reply% to
// allow the email recipient to reply with single click and confirmation.
$ticket = ticket($user, new DateInterval("P2D"));
$reply_url = url("reply?inquiry=5759&" . $ticket);%]
Create a temporary file which is automatically deleted when the request finishes.
tmp_file
(
)
:
Absolute filepath
Examples
[%// In this simple example we zip all images of Frank
// and send them to the browser in one zip archive.
$file = tmp_file();
$zip = new ZipArchive();
$zip->open($file);
foreach ($frank->get_all_images() as $image) {
$zip->addFile($image->file()->path, $image->id . "jpg");
}
$zip->close();
content_type("zip");
readfile($file);
// No need to unlink file, it is deleted automatically.%]
Retrieve a string in the current user interface language. Or in a specific language. Parameters after the key are substituted in order for %1, %2, etc.
txt
(
string$key,string$rest
)
:
string
Examples
[%$title = txt("title"); // "For your information", "Zu Ihrer Information"%]
[%WARNING!!!
This works and will remain working, but using the lang function is better.
txt calls come usually in bulk. With the approach above you carry the
language around in the code which cloggs it and makes changes
more difficult. A call to lang avoids that and simplifies the code.
// We need a specific language, different from the negogiated language.
$lang = $someone->get_language();
$subject = txt($lang->id, "email_subject") // "Your chance", "Ihre Chance"
$body = txt(
$lang->id,
"email_body",
$someone->get_first_name(),
$someone->get_last_name(),
$someone->get_dob()->format(txt($lang->id, "date_format")
);
%]