I wan to retrieve the department name and role assigned

protected static function SendEmailForActivation(
    \Admin $admin, string $activationLink, string $email)
{
    // Below variables are used in email template.
    $adminName = $admin->displayName();
    $activationUrl = $activationLink;
    $logo = \Registry::siteUrl('/dns_full_logo.png');

    /* send mail */
    ob_start();
    eval(\Registry::template('EmailAccountActivation'));
    $bodyHtml = ob_get_clean(); 

The template is sending the username in the email after retrieving it as “adminName”.
Additionally, I need to retrieve the department name and assigned role from the database. Could you please provide guidance on the process to retrieve this information?

I’m assuming that your \Admin class (or some related class) interacts with a database where the department name and role assigned to an admin are stored.

For illustration purposes, I’ll use a hypothetical database structure. Your actual implementation might differ:

class Admin {

    private $id; // assuming each admin has a unique ID

    // ... other properties and methods ...

    public function getDepartment() {
        $db = // get database connection;
        $query = $db->prepare("SELECT department FROM admin_table WHERE id = ?");
        $query->bind_param("i", $this->id);
        $query->execute();
        $result = $query->get_result();
        $row = $result->fetch_assoc();
        return $row['department'] ?? null;
    }

    public function getRole() {
        $db = // get database connection;
        $query = $db->prepare("SELECT role FROM admin_table WHERE id = ?");
        $query->bind_param("i", $this->id);
        $query->execute();
        $result = $query->get_result();
        $row = $result->fetch_assoc();
        return $row['role'] ?? null;
    }
}

Retrieve and Assign the Department and Role in Your Method

In your SendEmailForActivation method, retrieve the department and role using the methods from the first step:

$department = $admin->getDepartment();
$role = $admin->getRole();

Remember that this is an assumption but gives you an idea of how to solve the problem.
Good luck

Sponsor our Newsletter | Privacy Policy | Terms of Service