Nana-wd / FotoGalery

0 stars 0 forks source link

Описание каждого метода #7

Open hariuc opened 2 months ago

hariuc commented 2 months ago

В каждом методе класса необходимо выполнить описание типов данных. Пример можно посмотреть тут https://docs.phpdoc.org/3.0/guide/guides/types.html#supported-types

Еще один пример применения документации. Идет перед определением функции ее описание - для чего она нужна, описание параметров и их типов данных , а также описание каждого параметра для чего он нужен. и заканчивается документация типом возвращаемого значения - в нашем случае это int

/**
 * Send email
 *
 * @param string $mode              Mode (test | confirm)
 * @param string $oldemail          Target email
 * @param string $message           Message to send
 * @param string $total             Total amount of unpayed invoices
 * @param string $userlang          Code lang to use for email output.
 * @param string $oldtarget         Target name
 * @return int                      Int <0 if KO, >0 if OK
 */
function envoi_mail($mode, $oldemail, $message, $total, $userlang, $oldtarget)
{
    global $conf, $langs;

    if (getenv('DOL_FORCE_EMAIL_TO')) {
        $oldemail = getenv('DOL_FORCE_EMAIL_TO');
    }

    $newlangs = new Translate('', $conf);
    $newlangs->setDefaultLang(empty($userlang) ? getDolGlobalString('MAIN_LANG_DEFAULT', 'auto') : $userlang);
    $newlangs->load("main");
    $newlangs->load("bills");

    $subject = getDolGlobalString('SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_SUBJECT', $newlangs->trans("ListOfYourUnpaidInvoices"));
    $sendto = $oldemail;
    $from = getDolGlobalString('MAIN_MAIL_EMAIL_FROM');
    $errorsto = getDolGlobalString('MAIN_MAIL_ERRORS_TO');
    $msgishtml = -1;

    print "- Send email to '".$oldtarget."' (".$oldemail."), total: ".$total."\n";
    dol_syslog("email_unpaid_invoices_to_customers.php: send mail to ".$oldemail);

    $usehtml = 0;
    if (getDolGlobalString('SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER') && dol_textishtml(getDolGlobalString('SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER'))) {
        $usehtml += 1;
    }
    if (getDolGlobalString('SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER') && dol_textishtml(getDolGlobalString('SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER'))) {
        $usehtml += 1;
    }

    $allmessage = '';
    if (getDolGlobalString('SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER')) {
        $allmessage .= $conf->global->SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_HEADER;
    } else {
        $allmessage .= "Dear customer".($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
        $allmessage .= "Please, find a summary of the bills with pending payments from you.".($usehtml ? "<br>\n" : "\n").($usehtml ? "<br>\n" : "\n");
        $allmessage .= "Note: This list contains only unpaid invoices.".($usehtml ? "<br>\n" : "\n");
    }
    $allmessage .= $message.($usehtml ? "<br>\n" : "\n");
    $allmessage .= $langs->trans("Total")." = ".price($total, 0, $userlang, 0, 0, -1, $conf->currency).($usehtml ? "<br>\n" : "\n");
    if (getDolGlobalString('SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER')) {
        $allmessage .= getDolGlobalString('SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER');
        if (dol_textishtml(getDolGlobalString('SCRIPT_EMAIL_UNPAID_INVOICES_CUSTOMERS_FOOTER'))) {
            $usehtml += 1;
        }
    }

    $mail = new CMailFile($subject, $sendto, $from, $allmessage, array(), array(), array(), '', '', 0, $msgishtml);

    $mail->errors_to = $errorsto;

    // Send or not email
    if ($mode == 'confirm') {
        $result = $mail->sendfile();
        if (!$result) {
            print "Error sending email ".$mail->error."\n";
            dol_syslog("Error sending email ".$mail->error."\n");
        }
    } else {
        print "No email sent (test mode)\n";
        dol_syslog("No email sent (test mode)");
        $mail->dump_mail();
        $result = 1;
    }

    unset($newlangs);
    if ($result) {
        return 1;
    } else {
        return -1;
    }
}