<?php

function smarty_function_get_znz_customer_id($params, &$smarty)
{
    if (empty($params['id_user'])) {
        throw new InvalidArgumentException('Missing id_user');
    }

    $result = null;

    $znzId = sqlQueryBuilder()
        ->select('id_znz')
        ->from('znz_users')
        ->where(\Query\Operator::equals(['id_user' => $params['id_user']]))
        ->execute()->fetchOne();

    if ($znzId) {
        $result = $znzId;
    }

    if (!empty($params['assign'])) {
        $smarty->assign($params['assign'], $result);
    } else {
        return $result;
    }
}
