當前位置: 首頁>>代碼示例>>PHP>>正文


PHP WikiFactory::setVarByID方法代碼示例

本文整理匯總了PHP中WikiFactory::setVarByID方法的典型用法代碼示例。如果您正苦於以下問題:PHP WikiFactory::setVarByID方法的具體用法?PHP WikiFactory::setVarByID怎麽用?PHP WikiFactory::setVarByID使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在WikiFactory的用法示例。


在下文中一共展示了WikiFactory::setVarByID方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: setVarByName

 /**
  * setVarByName
  *
  * used for saving new variable value, logging changes and update city_list
  * values
  *
  * @access public
  * @author eloy@wikia
  * @static
  *
  * @param string $variable: variable name in city_variables_pool
  * @param integer $wiki: wiki id in city list
  * @param mixed $value: new value for variable
  * @param string $reason: optional reason text
  *
  * @return boolean: transaction status
  */
 public static function setVarByName($variable, $wiki, $value, $reason = null)
 {
     $oVariable = self::getVarByName($variable, $wiki);
     return WikiFactory::setVarByID($oVariable->cv_variable_id, $wiki, $value, $reason);
 }
開發者ID:Tjorriemorrie,項目名稱:app,代碼行數:22,代碼來源:WikiFactory.php

示例2: axWFactorySaveVariable

/**
 * axWFactorySaveVariable
 *
 * ajax method, save variable from form
 *
 * @author Krzysztof Krzyżaniak (eloy) <eloy@wikia-inc.com>
 * @access public
 *
 * @return string encoded in JSON format
 */
function axWFactorySaveVariable()
{
    global $wgUser, $wgRequest;
    $error = 0;
    $return = "";
    if (!$wgUser->isAllowed('wikifactory')) {
        $error++;
        $return = Wikia::errormsg("You are not allowed to change variable value");
    } else {
        $cv_id = $wgRequest->getVal('varId');
        $city_id = $wgRequest->getVal('cityid');
        $cv_name = $wgRequest->getVal('varName');
        $cv_value = $wgRequest->getVal('varValue');
        $cv_variable_type = $wgRequest->getVal('varType');
        $reason = $wgRequest->getVal('reason', null);
        $tag_name = $wgRequest->getVal('tagName');
        $tag_wiki_count = 0;
        $form_id = $wgRequest->getVal("formId", null);
        #--- check if variable is valid
        switch ($cv_variable_type) {
            case "boolean":
                if ((bool) $cv_value != $cv_value) {
                    $error++;
                    $return = Wikia::errormsg("Syntax error: value is not boolean. Variable not saved.");
                } else {
                    $return = Wikia::successmsg("Parse OK, variable saved");
                    $cv_value = (bool) $cv_value;
                }
                break;
            case "integer":
                if ((int) $cv_value != $cv_value) {
                    $error++;
                    $return = Wikia::errormsg("Syntax error: value is not integer. Variable not saved.");
                } else {
                    $return = Wikia::successmsg("Parse OK, variable saved.");
                    $cv_value = (int) $cv_value;
                }
                break;
            case "string":
                $return = Wikia::successmsg("Parse OK, variable saved.");
                break;
            default:
                $tEval = "\$__var_value = {$cv_value};";
                /**
                 * catch parse errors
                 */
                ob_start();
                if (eval($tEval) === FALSE) {
                    $error++;
                    $return = Wikia::errormsg("Syntax error, value is not valid PHP structure. Variable not saved.");
                } else {
                    $cv_value = $__var_value;
                    /**
                     * now check if it's actually array when we want array)
                     */
                    if (in_array($cv_variable_type, array("array", "struct", "hash"))) {
                        if (is_array($cv_value)) {
                            $return = Wikia::successmsg("Syntax OK (array), variable saved.");
                        } else {
                            $error++;
                            $return = Wikia::errormsg("Syntax error: value is not array. Variable not saved.");
                        }
                    } else {
                        $return = Wikia::successmsg("Parse OK, variable saved.");
                    }
                }
                ob_end_clean();
                #--- puts parse error to /dev/null
        }
        if (empty($error)) {
            $varInfo = WikiFactory::getVarById($cv_id, $city_id);
            if ($varInfo->cv_is_unique) {
                $wikis = WikiFactory::getCityIDsFromVarValue($cv_id, $cv_value, '=');
                $count = count($wikis);
                if ($count == 1 && $wikis[0] != $city_id || $count > 1) {
                    $return = Wikia::errormsg("Value of this variable need to be unique.");
                    $error++;
                }
            }
        }
        wfRunHooks('WikiFactoryVarSave::AfterErrorDetection', array($cv_id, $city_id, $cv_name, $cv_value, &$return, &$error));
        # Save to DB, but only if no errors occurred
        if (empty($error)) {
            if (!WikiFactory::setVarByID($cv_id, $city_id, $cv_value, $reason)) {
                $error++;
                $return = Wikia::errormsg("Variable not saved because of problems with database. Try again.");
            } else {
                /* the one "set" that used this is now disabled, so disabling the call until needed again
                			$tied = WikiFactory::getTiedVariables( $cv_name );
                			if( $tied ) {
//.........這裏部分代碼省略.........
開發者ID:schwarer2006,項目名稱:wikia,代碼行數:101,代碼來源:SpecialWikiFactory_ajax.php


注:本文中的WikiFactory::setVarByID方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。