当前位置: 首页>>代码示例>>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;未经允许,请勿转载。