مستندات phpmaker

برگه 
 of ۱
رکورد
۱
to
۲
of
۲
id
user id
subjects
category
commenrt
metod name
sample code
files
۲ ۲ ارسال پیامک Meshcut SDK

از ادیتور خارج بشه

از ادیتور خارج بشه بره پایین

MC_General::sendSms

$smsFlag = MC_General::sendSms($mobile, "پیامک ارسال شد" );

۳ ۲ کل مستندات

$isExists = MC_General::recordAlreadyExists('Users', 'mobile', $mobile);

:: php:
var_dump($rsnew);
$GLOBALS["Page"]
intval($val)
isset($val)
is_numeric($value)
array_map
is_object($data)
is_array($data)
array_is_list($data)
count($arr)
array_merge($data, $ar)
array_key_exists($item, $arr)
explode($sep, $arr) // split
implode($sep, $arr_str) // join
strlen($data) // length of string
-------------------

:: phpmaker:
>>> https://phpmaker.dev/docs/#/functions.html

ContainsString // str_contains($str ?? "", $a)
ContainsText // stripos($str, $a, $offset=0) : int|false  // indexOf
strripos  // lasrindexOf
StartsString // str_starts_with($str, $a)
EndsString // str_ends_with
SameString($str1, $str2)
FormatNumber('123456789', $pattern = "") // 123,456,789
---
Info() // write info for debug use
CurrentPage()->setSuccessMessage("")
$this->setFailureMessage("")
$this->terminate("businessticketslist")
Language()->phrase("tikanswer")
Config("config_name")
WriteJson($data)
VarToJson($val, $type = null) // "boolean", "string", "date" or "number"
ArrayToJson(array $ar)
Random($length = 8)
NewGuid()
WriteAuditLog($usr, $action, $table, $field = "", $keyvalue = "", $oldvalue = "", $newvalue = "")
RemoveHtml($str)
Get($get_name, $default = null)
Post($post_name, $default = null)
Param($name, $default = null)
ReferUrl()
AddHeader($name, $value, $replace = true)
RemoveHeader($name)
UrlBase64Decode($input)
UrlBase64Encode($input)
HtmlEncode($str)
HtmlDecode($str)
DateDiff($dateTimeBegin, $dateTimeEnd, $interval = "d") // "s": Seconds, "n": Minutes, "h": Hours, "d": Days (default), "w": Weeks, "ww": Calendar weeks, "m": Months, or "yyyy": Years
----
AllowList($tableName)
AllowView($tableName)
AllowAdd($tableName)
AllowEdit($tableName)
AllowDelete($tableName)
----
AdjustSql($val)
ExecuteQuery($sql)
ExecuteStatement($sql) // UPDATE, INSERT, or DELETE
Execute($sql, $fn = null) // SELECT + $fn called for each row
ExecuteScalar($sql)
ExecuteRow($sql)
ExecuteRows($sql)
ExecuteHtml($sql)
ExecuteJson($sql)
QueryBuilder ***
----
CurrentPageID()
CurrentPageName()
CurrentTableName()
CurrentLanguageID()
CurrentUserIP()
CurrentHost()
CurrentUrl()
CurrentDateTime()
CurrentTime()
CurrentUser()
CurrentUserName()
CurrentUserID()
CurrentParentUserID()
CurrentUserLevel()
CurrentUserLevelList()
CurrentUserPrimaryKey()
CurrentUserInfo($fldname) // CurrentUser()?->get($fldname)
FindUserByUserName($username, array $other_criteria = [])
GetUserRepository()->find($pk)
GetUserRepository()->findOneBy($criteria)
EmptyString($value) // isEmpty
EmptyValue($value) // isEmpty or null
----
IsLoggedIn()
IsLoggingIn()
IsAdmin()
IsSysAdmin()
IsDevelopment() // Config("ENVIRONMENT") == "development"
IsProduction()  // Config("ENVIRONMENT") == "production"
IsGet()
IsPost()
IsMobile() // agent is mobile
IsNumeric($value)
if (!EmptyValue($pk)) ...
CheckNumber($value)
CheckInteger($value)
CheckRange($value, $min, $max)
CheckEmail($value)
----
CreateJwt(array $values, int $expiry = 0) // Config("JWT.SECRET_KEY"), Config("JWT.ALGORITHM")
DecodeJwt(string $token)
---
if (is_object($Response)) {
    $Response->getBody()->write($json);
    $Response = $Response->withHeader("Content-Type", "application/json; charset=utf-8");
} else {
    if (!Config("DEBUG") && ob_get_length()) {
        ob_end_clean();
    }
    header("Content-Type: application/json; charset=utf-8");
}


QueryBuilder()
    ->select('mobile')
       ->from('Users')
       ->join | leftJoin | rightJoin ('u', 'phonenumbers', 'p', 'p.is_primary = 1')
       ->groupBy('u.id')
       ->addGroupBy('u.createdAt')
       ->having($having)
       ->andHaving($having)
       ->orHaving($having)
       ->orderBy('u.id', 'ASC'|null || 'DESC')
       ->addOrderBy('u.id', $dir)
    ->delete('users', 'u' = null)
    ->update('counters', 'c')
        ->set('c.value', 'c.value + 1')
    ->insert('users')
       ->values(
         array(
               'name' => '?',
            'password' => '?'
          )
        )
       ->setValue('password', '?')
    ->where('u.id=:user_id')
    ->andWhere('u.is_active=1')
    ->orWhere('u.id = 2');
    ->setParameter('user_id', 1)
    ->add($part, $sqlPart, $append = false) // $part: 'select', 'from', 'set', 'where', 'groupBy', 'having' and 'orderBy'
    ->
    getQueryPart($part)
    getQueryParts()
    resetQueryPart($part)
    resetQueryParts($parts[] = null)
    resetWhere()
    resetGroupBy()
    resetHaving()
    resetOrderBy()

    getSQL() | __toString() // sql query
    executeQuery() // execute SELECT
    executeStatement() // execute + returns affected rows count
    fetchOne() // get scalar
    fetchAllNumeric() // array of numeric arrays
    fetchAllKeyValue() // KeyVal-array of [col1:col2]
    fetchFirstColumn() // array of the first column values

$stmt = $qbd->executeQuery();
if ($stmt->rowCount() > 0) {
   while ($row = $stmt->fetch()) {
      $displayResult .= $row["first_name"] . " " . $row["last_name"] . "<br>"; // in case the result returns more than one row, separated by line break
   }
   //*** your code;
}
//----------
:: Session    
$value = Session("xxx"); // Get session variable directly
Session("xxx", "value"); // Set session variable directly
$session = Session(); // Get the session helper object
$session->set("xxx", "value")->set("yyy", "value2"); // Set session variable(s)
$value = $session->get("xxx", "default" = null)
$value = $session["xxx"]; // Get session variable
$value = $session->xxx; // Get session variable
$isset = $session->isset("xxx"); // Check if a session variable is set
$exists = $session->exists("xxx"); // Check if a session variable exists
$session->delete("xxx")->delete("yyy"); // Unset session variable(s)
unset($session["xxx"]); // Unset a session variable
unset($session->xxx); // Unset a session variable
//========================

//----
:: data-ew-action
none
inline
modal
submit
//----

//::: Api_Action
$app->get('/getByProdID/{productId}', function ($request, $response, $args) {
    $productId = $args["productId"] ?? null; // Get the input value
    if ($productId !== null) {
        $response = $response->write(ExecuteScalar("SELECT UnitPrice FROM products WHERE ProductID = " . AdjustSql($productId))); // Output field value as string
        // $response = $response->withJson(ExecuteRow("SELECT * FROM products WHERE ProductID = " . AdjustSql($productId)));
    }
    return $response; // Return  Psr\Http\Message\ResponseInterface object
});
------
js:
$.get(ew.getApiUrl(["myaction", 111]), function(res) {
    console.log(res);
});
$.post('/irancodnet/myact/222?id=999', 
    $( "#testform" ).serialize(), // OR { name: "John", time: "2pm" }, 
    function(res) {
        console.log(res);
    });


//::: ListPage > Page_Load

// Enable fixed header table and set max-height to 500px
$this->setFixedHeaderTable(true, "vh-65");
// $this->setFixedHeaderTable(false); // Disable fixed header table

// hide pdf Export
$this->ExportOptions["pdf"]?->setVisible(false);
// add custom link on top
$this->ExportOptions->add("MyName")->setBody("<a class='my-class' href='#'>My Link</a>");
// add custom multiple action on top
$this->CustomActions["star"] = new ListAction("star", "Add Star", IsLoggedIn(), ACTION_AJAX, ACTION_MULTIPLE, "Add Star to selected records?", "fa fa-star ew-icon");
// action: payment_req
$this->CustomActions["payment_req"] = new ListAction("payment_req", "پرداخت", IsLoggedIn(), ACTION_AJAX, ACTION_SINGLE, "تایید و پرداخت؟", "fas fa-dollar ew-icon", "setPayment");
// action: add_star
    $rs = ["service_duration" => "999"]; // Update service_duration to '999'
    $this->CustomActions["star"] = new ListAction(
        "star",
        "Add Star",
        IsLoggedIn(),
        ACTION_AJAX,
        ACTION_SINGLE,
        "Add Star to the selected record?",
        "fa-solid fa-star ew-icon",
        "",
        fn($row) => $this->update(
            $rs, // Update service_duration to '999'
            ["id" => $row["id"]] // Update the current record only (the second argument is WHERE clause for UPDATE statement)
        ),
        "Star added successfully",
        "Failed to add star"
    );

//::: List Page > ListOptions_Load
افزودن ستون جدید به جدول
$opt = &$this->ListOptions->add("new");
$opt->Header = "xxx";
$opt->OnLeft = true; // Link on left
$opt->moveTo(0); // Move to first column

//::: ListOptions_Rendered:
استایل به یک ستون از جدول
$this->column->CellCssStyle="background-color:yellow;";
افزودن لینک اکشن به سطر
$this->ListOptions["new"]->Body = "<a href=\"#\" onclick=\"return ew.submitAction(event, {action: 'star', method: 'ajax', msg: 'Add star?', key: " . $this->keyToJson(true) . "});\">Add Star</a>";
افزودن باز کردن مودال به سطر
- $this->ListOptions["tikanswer"]->Body = "<a class=\"btn btn-default ew-add-edit ew-add\" data-ew-action='none' title=\"پاسخ\" data-caption=\"پاسخ\" href=\"#\" onclick=\"return ew.modalDialogShow({lnk:this,btn:'null',url:'businessticketshistoryadd?showmaster=business_tickets&fk_id=".$this->id->CurrentValue."',callback: function(data) { console.log(data); }});\">".$answercaption."</a>";
- onclick="return ew.modalDialogShow({lnk:this,btn:'AddBtn',url:'<?php echo BasePath(); ?>/CategoriesAdd'});"


//::: Row_CustomAction($action, $row)
پاسخ به یک اکشن آژاکسی
if ($action == "payment_req") {
    $encryptedData = MC_General::setForOnlinePayment($total_price,'business_service_faktor',$row["id"]);
    MC_Response::echoJson(urlencode($encryptedData));
}
//========================
:: Javascript:

//::: Client Script:
:: تعریف متد / اجرا بعد از اکشن آژاکسی
:: calling after `CustomAction`
window.setPayment = function(response, status, ajaxObj) {
    if (response.status > 0) {
    // refresh table
        // $('table.ew-table').load(location.href + ' table.ew-table');
        ew.showToast('در حال اتصال به درگاه بانک ...', 'warning', 'پرداخت آنلاین');
        window.location.href = '<?php echo MC_General::$mc_pay_url ?>?token=' + response.data;
    }
    else
        ew.showToast(response.message, 'danger', 'خطا در انجام عملیات');
}
//-----------
:: تغییر رنگ دکمه وضعیت
$('.business_service_faktor_listactions button.btn-default').removeClass('btn-default').addClass('btn-sm btn-success');

:: کلاس های قابل استفاده
// bg- | text- | btn- | alert-
// primary | info | success | warning | danger || white | light | secondary | dark
// xs | sm | md | lg | xl

---
// افزودن اسکریپت به صفحه
loadjs(["meshcut/tikautils.js"]);
// افزودن اسکریپت به هدر صفحه
ew.ready("head", ew.PATH_BASE + "meshcut/form-wizard/jquery.smartWizard.js", "formwizard");
---
loadjs.ready("load", function () {
  // ***
});

// ارسال آژاکس
ew.submitAction(event, {action: 'star', method: 'ajax', msg: 'Add star?', key: {"id":18}});

ew.PATH_BASE
// نمایش پیغام
ew.showMessage("hi")
ew.showToast("content", "success", "title")
showToast(message, type, title, timer, otherOptions);
{
position : "topRight",
autoremove: false,
fade: true,
fixed: true,
image: null,
imageHeight: "25px"
}

// pdf maker:
https://www.hkvforums.com/viewtopic.php?t=57901
// Custom Templates
https://phpmaker.dev/docs/#/customscripts.html
// debug php with VS-Code
https://vrgl.ir/EK5sB
https://xdebug.org/wizard
https://marketplace.visualstudio.com/items?itemName=xdebug.php-debug
https://chromewebstore.google.com/detail/xdebug-helper/eadndfjplgieldjbigjakmdgkmoaaaoc?pli=1
// mysql رفع مشکل خطای عدم راه اندازی دیتابیس
https://developersho.com/blog/how-to-fix-xampp-error-mysql-shutdown-unexpectedly