예제 #1
0
 protected function compileRules()
 {
     foreach ($this->product_data as $pdata) {
         $rules = Rule::where('product_id', $pdata->id)->get();
         $skus = Sku::where('product_id', $pdata->id)->get();
         if (!empty($rules)) {
             $this->rule_data[$pdata->id] = [];
         }
         foreach ($rules as $rule) {
             $conditions = unserialize($rule->conditions);
             if (!empty($conditions)) {
                 $compiled_conditions = [];
                 foreach ($conditions as $condition) {
                     if (is_null($condition->product_option_id) && is_null($condition->option_value_id)) {
                         $this->compileRuleCondition($condition, $skus);
                     }
                     $compiled_conditions[] = $condition;
                 }
                 //store the rule by product ID so we can refrence when compiling options
                 $this->rule_data[$rule->product_id][] = $rule;
                 $rule->conditions = serialize($conditions);
                 $rule->save();
             }
         }
     }
 }
 private function getData(User $user, BattleFilterForm $filter)
 {
     $query = (new \yii\db\Query())->select(['map_key' => 'MAX({{map}}.[[key]])', 'rule_key' => 'MAX({{rule}}.[[key]])', 'result' => '(CASE WHEN {{battle}}.[[is_win]] = TRUE THEN \'win\' ELSE \'lose\' END)', 'count' => 'COUNT(*)'])->from('battle')->innerJoin('map', '{{battle}}.[[map_id]] = {{map}}.[[id]]')->innerJoin('rule', '{{battle}}.[[rule_id]] = {{rule}}.[[id]]')->leftJoin('lobby', '{{battle}}.[[lobby_id]] = {{lobby}}.[[id]]')->leftJoin('game_mode', '{{rule}}.[[mode_id]] = {{game_mode}}.[[id]]')->leftJoin('weapon', '{{battle}}.[[weapon_id]] = {{weapon}}.[[id]]')->leftJoin('weapon_type', '{{weapon}}.[[type_id]] = {{weapon_type}}.[[id]]')->leftJoin('subweapon', '{{weapon}}.[[subweapon_id]] = {{subweapon}}.[[id]]')->leftJoin('special', '{{weapon}}.[[special_id]] = {{special}}.[[id]]')->andWhere(['{{battle}}.[[user_id]]' => $user->id])->andWhere(['in', '{{battle}}.[[is_win]]', [true, false]])->groupBy(['{{battle}}.[[map_id]]', '{{battle}}.[[rule_id]]', '{{battle}}.[[is_win]]']);
     if ($filter && !$filter->hasErrors()) {
         $this->filter($query, $filter);
     }
     $maps = Map::find()->all();
     $rules = Rule::find()->all();
     $ret = [];
     foreach ($maps as $map) {
         $tmp = [];
         foreach ($rules as $rule) {
             $tmp[$rule->key] = ['win' => 0, 'lose' => 0];
         }
         $ret[$map->key] = $tmp;
     }
     foreach ($query->createCommand()->queryAll() as $row) {
         $row = (object) $row;
         $ret[$row->map_key][$row->rule_key][$row->result] = (int) $row->count;
     }
     $maps2 = [];
     foreach ($maps as $map) {
         $maps2[$map->key] = Yii::t('app-map', $map->name);
     }
     asort($maps2);
     $rules2 = [];
     foreach ($rules as $rule) {
         $rules2[$rule->key] = Yii::t('app-rule', $rule->name);
     }
     asort($rules2);
     return ['data' => $ret, 'mapNames' => $maps2, 'ruleNames' => $rules2];
 }
예제 #3
0
 public function run()
 {
     $rules = [];
     $query = Rule::find()->innerJoinWith('mode')->andWhere(['{{game_mode}}.[[key]]' => 'gachi']);
     foreach ($query->all() as $rule) {
         $rules[$rule->id] = Yii::t('app-rule', $rule->name);
     }
     asort($rules);
     $maps = [];
     foreach (Map::find()->all() as $map) {
         $maps[$map->id] = Yii::t('app-map', $map->name);
     }
     asort($maps);
     // init data
     $data = [];
     foreach (array_keys($maps) as $mapId) {
         $data[$mapId] = [];
         foreach (array_keys($rules) as $ruleId) {
             $data[$mapId][$ruleId] = (object) ['battle_count' => 0, 'ko_count' => 0];
         }
     }
     // set data
     foreach ($this->query() as $row) {
         $ruleId = $row['rule_id'];
         $mapId = $row['map_id'];
         $data[$mapId][$ruleId]->battle_count = (int) $row['battle_count'];
         $data[$mapId][$ruleId]->ko_count = (int) $row['ko_count'];
     }
     return $this->controller->render('knockout.tpl', ['rules' => $rules, 'maps' => $maps, 'data' => $data]);
 }
예제 #4
0
 public function createCurrentData()
 {
     static $nawabari = null;
     if ($nawabari === null) {
         $nawabari = Rule::findOne(['key' => 'nawabari'])->id;
     }
     $now = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time();
     $shortCondition = sprintf('(({{battle}}.[[end_at]] IS NOT NULL) AND ({{battle}}.[[end_at]] BETWEEN %s AND %s))', Yii::$app->db->quoteValue(gmdate('Y-m-d H:i:sO', $now - 86400 + 1)), Yii::$app->db->quoteValue(gmdate('Y-m-d H:i:sO', $now)));
     $column_battle_count = "COUNT(*)";
     $column_wp = sprintf("(%s * 100.0 / NULLIF(%s, 0))", "SUM(CASE WHEN {{battle}}.[[is_win]] = TRUE THEN 1 ELSE 0 END)", "SUM(CASE WHEN {{battle}}.[[is_win]] IS NULL THEN 0 ELSE 1 END)");
     $column_wp_short = sprintf("(%s * 100.0 / NULLIF(%s, 0))", "SUM(CASE WHEN {$shortCondition} AND {{battle}}.[[is_win]] = TRUE THEN 1 ELSE 0 END)", "SUM(CASE WHEN {$shortCondition} AND {{battle}}.[[is_win]] IS NOT NULL THEN 1 ELSE 0 END)");
     $column_total_kill = sprintf("SUM(%s)", "CASE WHEN " . "{{battle}}.[[kill]] IS NOT NULL AND {{battle}}.[[death]] IS NOT NULL " . "THEN {{battle}}.[[kill]] " . "ELSE 0 END");
     $column_total_death = sprintf("SUM(%s)", "CASE WHEN {{battle}}.[[kill]] IS NOT NULL AND {{battle}}.[[death]] IS NOT NULL " . "THEN {{battle}}.[[death]] " . "ELSE 0 END");
     $column_nawabari_count = "SUM(CASE WHEN {{battle}}.[[rule_id]] = {$nawabari} THEN 1 ELSE 0 END)";
     $column_nawabari_wp = sprintf("(%s * 100.0 / NULLIF(%s, 0))", "SUM(CASE WHEN {{battle}}.[[rule_id]] = {$nawabari} AND {{battle}}.[[is_win]] = TRUE THEN 1 ELSE 0 END)", "SUM(CASE WHEN {{battle}}.[[rule_id]] = {$nawabari} AND {{battle}}.[[is_win]] IS NOT NULL THEN 1 ELSE 0 END)");
     $column_nawabari_kill = sprintf("SUM(%s)", "CASE WHEN {{battle}}.[[rule_id]] = {$nawabari} AND " . "{{battle}}.[[kill]] IS NOT NULL AND {{battle}}.[[death]] IS NOT NULL " . "THEN {{battle}}.[[kill]] " . "ELSE 0 END");
     $column_nawabari_death = sprintf("SUM(%s)", "CASE WHEN {{battle}}.[[rule_id]] = {$nawabari} AND " . "{{battle}}.[[kill]] IS NOT NULL AND {{battle}}.[[death]] IS NOT NULL " . "THEN {{battle}}.[[death]] " . "ELSE 0 END");
     $column_gachi_count = "SUM(CASE WHEN {{battle}}.[[rule_id]] <> {$nawabari} THEN 1 ELSE 0 END)";
     $column_gachi_wp = sprintf("(%s * 100.0 / NULLIF(%s, 0))", "SUM(CASE WHEN {{battle}}.[[rule_id]] <> {$nawabari} AND {{battle}}.[[is_win]] = TRUE THEN 1 ELSE 0 END)", "SUM(CASE WHEN {{battle}}.[[rule_id]] <> {$nawabari} AND {{battle}}.[[is_win]] IS NOT NULL THEN 1 ELSE 0 END)");
     $column_gachi_kill = sprintf("SUM(%s)", "CASE WHEN {{battle}}.[[rule_id]] <> {$nawabari} AND " . "{{battle}}.[[kill]] IS NOT NULL AND {{battle}}.[[death]] IS NOT NULL " . "THEN {{battle}}.[[kill]] " . "ELSE 0 END");
     $column_gachi_death = sprintf("SUM(%s)", "CASE WHEN {{battle}}.[[rule_id]] <> {$nawabari} AND " . "{{battle}}.[[kill]] IS NOT NULL AND {{battle}}.[[death]] IS NOT NULL " . "THEN {{battle}}.[[death]] " . "ELSE 0 END");
     $query = (new \yii\db\Query())->select(['battle_count' => $column_battle_count, 'wp' => $column_wp, 'wp_short' => $column_wp_short, 'total_kill' => $column_total_kill, 'total_death' => $column_total_death, 'nawabari_count' => $column_nawabari_count, 'nawabari_wp' => $column_nawabari_wp, 'nawabari_kill' => $column_nawabari_kill, 'nawabari_death' => $column_nawabari_death, 'gachi_count' => $column_gachi_count, 'gachi_wp' => $column_gachi_wp, 'gachi_kill' => $column_gachi_kill, 'gachi_death' => $column_gachi_death])->from('battle')->andWhere(['{{battle}}.[[user_id]]' => $this->user_id]);
     $this->attributes = $query->createCommand()->queryOne();
     $keys = ['battle_count', 'total_kill', 'total_death', 'nawabari_count', 'nawabari_kill', 'nawabari_death', 'gachi_count', 'gachi_kill', 'gachi_death'];
     foreach ($keys as $key) {
         $this->{$key} = (int) $this->{$key};
     }
 }
 public function init()
 {
     // actions
     // translate
     foreach ($this->actions as $actions => $name) {
         $this->actions[$actions] = Yii::t('app', $name);
     }
     // actions values
     $this->actions_values['taskdefined'] = TaskDefined::getAllIdName();
     $this->actions_values['setting'] = Setting::getAllIdName();
     $this->actions_values['rule'] = Rule::getAllIdName();
     $this->actions_values['rulevalue'] = RuleValue::getAllIdName();
     $this->actions_values['ruleextra'] = RuleExtra::getAllIdName();
     $this->actions_values['ruledate'] = RuleDate::getAllIdName();
     // values
     // translate
     foreach ($this->values as $values => $name) {
         $this->values[$values] = Yii::t('app', $name);
     }
     // values_values
     $this->values_values['taskdefined'] = TaskDefined::getAllIdName();
     $this->values_values['setting'] = Setting::getAllIdName();
     $this->values_values['rule'] = Rule::getAllIdName();
     $this->values_values['rulevalue'] = RuleValue::getAllIdName();
     $this->values_values['ruleextra'] = RuleExtra::getAllIdName();
     $this->values_values['ruledate'] = RuleDate::getAllIdName();
     //$this->values = array_merge($modelRule->values, $modelRule->actions);
     //$this->values_values = $modelRule->values;
     // create weights from 0 to 5
     for ($weight = 0; $weight <= 4; $weight++) {
         $this->weights[$weight] = $weight;
     }
     parent::init();
 }
예제 #6
0
 public function run()
 {
     $response = Yii::$app->getResponse();
     $response->format = 'json';
     return array_map(function ($rule) {
         return $rule->toJsonArray();
     }, Rule::find()->with('mode')->all());
 }
예제 #7
0
 private function createSelectQueryForUpdateEntireWeapons()
 {
     $ruleNawabari = Rule::findOne(['key' => 'nawabari'])->id;
     $query = BattlePlayer::find()->innerJoinWith(['battle' => function ($q) {
         return $q->orderBy(null);
     }, 'battle.lobby', 'weapon'])->andWhere(['{{battle}}.[[is_automated]]' => true])->andWhere(['<>', '{{lobby}}.[[key]]', 'private'])->andWhere(['not', ['{{battle}}.[[is_win]]' => null]])->andWhere(['not', ['{{battle_player}}.[[kill]]' => null]])->andWhere(['not', ['{{battle_player}}.[[death]]' => null]])->andWhere(['{{battle_player}}.[[is_me]]' => false])->groupBy('{{battle}}.[[rule_id]], {{battle_player}}.[[weapon_id]]');
     // ルール別の処理を記述
     $query->andWhere(['or', ['and', ['{{battle}}.[[rule_id]]' => $ruleNawabari], ['not', ['{{battle_player}}.[[point]]' => null]], ['or', ['{{lobby}}.[[key]]' => 'standard'], ['{{lobby}}.[[key]]' => 'fest', '{{battle_player}}.[[is_my_team]]' => false]], ['or', ['and', ['=', '{{battle}}.[[is_win]]', new \yii\db\Expression('battle_player.is_my_team')], ['>', '{{battle_player}}.[[point]]', 300]], ['and', ['<>', '{{battle}}.[[is_win]]', new \yii\db\Expression('battle_player.is_my_team')], ['>', '{{battle_player}}.[[point]]', 0]]]], ['and', ['<>', '{{battle}}.[[rule_id]]', $ruleNawabari], ['not like', '{{lobby}}.[[key]]', 'squad_%', false]]]);
     $query->select(['rule_id' => '{{battle}}.[[rule_id]]', 'weapon_id' => '{{battle_player}}.[[weapon_id]]', 'players' => 'COUNT(*)', 'total_kill' => 'SUM({{battle_player}}.[[kill]])', 'total_death' => 'SUM({{battle_player}}.[[death]])', 'win_count' => sprintf('SUM(CASE %s END)', implode(' ', ['WHEN {{battle}}.[[is_win]] = TRUE AND {{battle_player}}.[[is_my_team]] = TRUE THEN 1', 'WHEN {{battle}}.[[is_win]] = FALSE AND {{battle_player}}.[[is_my_team]] = FALSE THEN 1', 'ELSE 0'])), 'total_point' => sprintf('CASE WHEN {{battle}}.[[rule_id]] <> %d THEN NULL ELSE %s END', $ruleNawabari, sprintf('SUM(CASE %s END)', implode(' ', ['WHEN {{battle_player}}.[[point]] IS NULL THEN 0', 'WHEN {{battle}}.[[is_win]] = {{battle_player}}.[[is_my_team]] THEN battle_player.point - 300', 'ELSE {{battle_player}}.[[point]]']))), 'point_available' => sprintf('CASE WHEN {{battle}}.[[rule_id]] <> %d THEN NULL ELSE %s END', $ruleNawabari, sprintf('SUM(CASE %s END)', implode(' ', ['WHEN {{battle_player}}.[[point]] IS NULL THEN 0', 'ELSE 1'])))]);
     return $query;
 }
 public function up()
 {
     $rule = [];
     // [ 'arowana' => 42, ... ]
     foreach (Rule::find()->all() as $_) {
         $rule[$_->key] = $_->id;
     }
     // 今後表記揺れが発生する可能性がある(ないけど)ので rule_id を PKEY にはしない
     $this->createTable('splapi_rule', ['id' => $this->primaryKey(), 'rule_id' => $this->integer()->notNull(), 'name' => $this->string(32)->notNull()->unique()]);
     $this->addForeignKey('fk_splapi_rule_1', 'splapi_rule', 'rule_id', 'rule', 'id');
     $this->batchInsert('splapi_rule', ['rule_id', 'name'], [[$rule['nawabari'], 'ナワバリバトル'], [$rule['area'], 'ガチエリア'], [$rule['yagura'], 'ガチヤグラ'], [$rule['hoko'], 'ガチホコ']]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Rule::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'weight' => $this->weight, 'created_at' => $this->created_at, 'updated_at' => $this->updated_at]);
     $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'description', $this->description]);
     return $dataProvider;
 }
예제 #10
0
 public function rules()
 {
     return [[['screen_name'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'screen_name'], [['rule'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'key', 'when' => function () {
         return substr($this->rule, 0, 1) !== '@';
     }], [['rule'], 'validateGameMode', 'when' => function () {
         return substr($this->rule, 0, 1) === '@';
     }], [['map'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'key'], [['weapon'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'key', 'when' => function () {
         return !in_array(substr($this->weapon, 0, 1), ['@', '+', '*'], true);
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => WeaponType::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '@';
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Subweapon::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '+';
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Special::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '*';
     }], [['result'], 'boolean', 'trueValue' => 'win', 'falseValue' => 'lose']];
 }
예제 #11
0
 public function rules()
 {
     return [[['screen_name'], 'exist', 'targetClass' => User::className(), 'targetAttribute' => 'screen_name'], [['lobby'], 'exist', 'targetClass' => Lobby::className(), 'targetAttribute' => 'key'], [['rule'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'key', 'when' => function () {
         return substr($this->rule, 0, 1) !== '@';
     }], [['rule'], 'validateGameMode', 'when' => function () {
         return substr($this->rule, 0, 1) === '@';
     }], [['map'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'key'], [['weapon'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'key', 'when' => function () {
         return !in_array(substr($this->weapon, 0, 1), ['@', '+', '*'], true);
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => WeaponType::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '@';
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Subweapon::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '+';
     }], [['weapon'], 'validateWeapon', 'params' => ['modelClass' => Special::className()], 'when' => function () {
         return substr($this->weapon, 0, 1) === '*';
     }], [['result'], 'boolean', 'trueValue' => 'win', 'falseValue' => 'lose'], [['term'], 'in', 'range' => ['this-period', 'last-period', '24h', 'today', 'yesterday', 'term']], [['term_from', 'term_to'], 'date', 'format' => 'yyyy-M-d H:m:s']];
 }
예제 #12
0
 private function makeRules()
 {
     $ret = ['' => Yii::t('app', 'Unknown')];
     $gameModes = GameMode::find()->orderBy('[[id]] ASC')->all();
     foreach ($gameModes as $gameMode) {
         $gameModeText = Yii::t('app-rule', $gameMode->name);
         // "ナワバリバトル"
         $rules = Rule::find()->andWhere(['mode_id' => $gameMode->id])->orderBy('[[id]] ASC')->all();
         $mode = [];
         foreach ($rules as $rule) {
             $mode[$rule->id] = Yii::t('app-rule', $rule->name);
         }
         asort($mode);
         $ret[$gameModeText] = $mode;
     }
     return $ret;
 }
예제 #13
0
 private function makeRulesList()
 {
     $ret = ['' => Yii::t('app-rule', 'Any Mode')];
     $gameModes = GameMode::find()->orderBy('[[id]] ASC')->all();
     foreach ($gameModes as $gameMode) {
         $gameModeText = Yii::t('app-rule', $gameMode->name);
         // "ナワバリバトル"
         $rules = Rule::find()->andWhere(['mode_id' => $gameMode->id])->orderBy('[[id]] ASC')->all();
         $mode = [];
         if (count($rules) > 1) {
             $mode['@' . $gameMode->key] = Yii::t('app-rule', 'All of {0}', $gameModeText);
         }
         foreach ($rules as $rule) {
             $mode[$rule->key] = Yii::t('app-rule', $rule->name);
         }
         $ret[$gameModeText] = $mode;
     }
     return $ret;
 }
예제 #14
0
 public function init()
 {
     // add all task defined
     $this->job_ids['taskdefined'] = TaskDefined::getAllIdName();
     // add all task defined
     $this->job_ids['rule'] = Rule::getAllIdName();
     // translate all
     foreach ($this->job_ids as $job => $jobs) {
         foreach ($jobs as $id => $name) {
             $this->job_ids[$job][$id] = Yii::t('app', $name);
         }
     }
     // create weights
     for ($key = 0; $key < Cronjob::find()->count(); $key++) {
         $this->weights[$key] = $key;
     }
     $this->weights[$key] = $key;
     parent::init();
 }
예제 #15
0
 public static function nextUser($group_id)
 {
     $users = User::with('order')->where('group_id', '=', $group_id)->get()->sortBy(function ($user) {
         return $user->countOrders;
     });
     foreach ($users as $user) {
         $rules = Rule::forUser($user->id);
         if ($rules->count() == 0) {
             return $user;
         }
         foreach ($rules as $rule) {
             $condition = false;
             eval('$condition = ' . $rule->condition . ';');
             if (!$condition) {
                 return $user;
             }
         }
     }
 }
 public function init()
 {
     // actions
     // translate
     foreach ($this->conditions as $conditions => $name) {
         $this->conditions[$conditions] = Yii::t('app', $name);
     }
     // actions values
     $this->conditions_values['taskdefined'] = TaskDefined::getAllIdName();
     $this->conditions_values['setting'] = Setting::getAllIdName();
     $this->conditions_values['rule'] = Rule::getAllIdName();
     $this->conditions_values['rulevalue'] = RuleValue::getAllIdName();
     $this->conditions_values['ruleextra'] = RuleExtra::getAllIdName();
     $this->conditions_values['ruledate'] = RuleDate::getAllIdName();
     // equations
     // translate all equations
     foreach ($this->equations as $key => $equation) {
         $this->equations[$key] = Yii::t('app', $equation);
     }
     // key before value equations
     foreach ($this->equations as $key => $equation) {
         $this->equations[$key] = $key . ', ' . $equation;
     }
     // values
     // translate
     foreach ($this->values as $values => $name) {
         $this->values[$values] = Yii::t('app', $name);
     }
     // values_values
     $this->values_values['taskdefined'] = TaskDefined::getAllIdName();
     $this->values_values['setting'] = Setting::getAllIdName();
     $this->values_values['rule'] = Rule::getAllIdName();
     $this->values_values['rulevalue'] = RuleValue::getAllIdName();
     $this->values_values['ruleextra'] = RuleExtra::getAllIdName();
     $this->values_values['ruledate'] = RuleDate::getAllIdName();
     // create weights from 0 to 10
     for ($weight = 0; $weight <= 10; $weight++) {
         $this->weights[$weight] = $weight;
     }
     parent::init();
 }
예제 #17
0
 /**
  * Lists all Feature models.
  * @return mixed
  */
 public function actionIndex()
 {
     // $app = (new \yii\db\Query())->select(["aid"])->from('app')->groupBy("aid")->all();
     $app = Rule::find()->select(["aid"])->groupBy("aid")->with("app")->asArray()->all();
     $role = Rule::find()->select(["role_id"])->groupBy("role_id")->with("role")->asArray()->all();
     $model = Rule::find()->select(["model_id"])->groupBy("model_id")->with("model")->asArray()->all();
     $feature = Rule::find()->select(["feature_id"])->groupBy("feature_id")->with("feature")->asArray()->all();
     $scope = Rule::find()->select(["scope_id"])->groupBy("scope_id")->with("scope")->asArray()->all();
     $str = "";
     foreach ($app as $va) {
         $str .= "acl app_" . $va['aid'] . "\thdr(X-App)\t" . $va['app']['code'] . "\n";
     }
     foreach ($role as $vr) {
         $str .= "acl role_" . $vr['role_id'] . "\thdr(X-Role)\t" . $vr['role']['name'] . "\n";
     }
     foreach ($model as $vm) {
         $str .= "acl model_" . $vm['model_id'] . "\thdr(X-Model)\t" . $vm['model']['name'] . "\n";
     }
     foreach ($feature as $vf) {
         $str .= "acl feature_" . $vf['feature_id'] . "\thdr(X-Feature)\t" . $vf['feature']['name'] . "\n";
     }
     foreach ($scope as $vs) {
         $str .= "acl scope_" . $vs['scope_id'] . "\thdr(X-Scope)\t" . $vs['scope']['name'] . "\n";
     }
     $rule = Rule::find()->select(['aid', 'role_id', 'model_id', 'feature_id', 'scope_id'])->asArray()->all();
     // print_r($rule);
     foreach ($rule as $vu) {
         $str .= "use_backend dynamic\t\tif app_" . $vu['aid'] . " role_" . $vu['role_id'] . " model_" . $vu['model_id'] . " feature_" . $vu['feature_id'] . " scope_" . $vu['scope_id'] . "\n";
     }
     $file = fopen("./haproxy.cfg", "w");
     if (!$file) {
         throw new NotFoundHttpException("No such the directory or file!");
     }
     if (fwrite($file, $str) === FALSE) {
         throw new NotFoundHttpException("File is written to failure!");
     }
     fclose($file);
     echo "OK,The haproxy.cfg created successful!";
 }
예제 #18
0
 public function createCurrentData()
 {
     $db = Yii::$app->db;
     static $nawabari = null;
     if ($nawabari === null) {
         $nawabari = Rule::findOne(['key' => 'nawabari'])->id;
     }
     $condIsNawabari = sprintf('({{battle}}.[[rule_id]] = %s)', $db->quoteValue($nawabari));
     $condIsGachi = sprintf('({{battle}}.[[rule_id]] <> %s)', $db->quoteValue($nawabari));
     static $private = null;
     if ($private === null) {
         $private = Lobby::findOne(['key' => 'private'])->id;
     }
     $condIsNotPrivate = sprintf('({{battle}}.[[lobby_id]] IS NULL OR {{battle}}.[[lobby_id]] <> %s)', $db->quoteValue($private));
     $now = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time();
     $cond24Hours = sprintf('(({{battle}}.[[end_at]] IS NOT NULL) AND ({{battle}}.[[end_at]] BETWEEN %s AND %s))', $db->quoteValue(gmdate('Y-m-d H:i:sO', $now - 86400 + 1)), $db->quoteValue(gmdate('Y-m-d H:i:sO', $now)));
     $condKDPresent = sprintf('(%s)', implode(' AND ', ['{{battle}}.[[kill]] IS NOT NULL', '{{battle}}.[[death]] IS NOT NULL']));
     $column_battle_count = "COUNT(*)";
     $column_wp = sprintf('(%s * 100.0 / NULLIF(%s, 0))', sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, '{{battle}}.[[is_win]] = TRUE'])), sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, '{{battle}}.[[is_win]] IS NOT NULL'])));
     $column_wp_short = sprintf("(%s * 100.0 / NULLIF(%s, 0))", sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $cond24Hours, '{{battle}}.[[is_win]] = TRUE'])), sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $cond24Hours, '{{battle}}.[[is_win]] IS NOT NULL'])));
     $column_total_kd_battle_count = sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condKDPresent]));
     $column_total_kill = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[kill]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condKDPresent]));
     $column_total_death = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[death]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condKDPresent]));
     $column_nawabari_count = sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari]));
     $column_nawabari_wp = sprintf('(%s * 100.0 / NULLIF(%s, 0))', sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari, '{{battle}}.[[is_win]] = TRUE'])), sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari, '{{battle}}.[[is_win]] IS NOT NULL'])));
     $column_nawabari_kill = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[kill]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari, $condKDPresent]));
     $column_nawabari_death = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[death]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsNawabari, $condKDPresent]));
     $column_gachi_count = sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi]));
     $column_gachi_wp = sprintf('(%s * 100.0 / NULLIF(%s, 0))', sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi, '{{battle}}.[[is_win]] = TRUE'])), sprintf('SUM(CASE WHEN (%s) THEN 1 ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi, '{{battle}}.[[is_win]] IS NOT NULL'])));
     $column_gachi_kill = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[kill]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi, $condKDPresent]));
     $column_gachi_death = sprintf('SUM(CASE WHEN (%s) THEN {{battle}}.[[death]] ELSE 0 END)', implode(' AND ', [$condIsNotPrivate, $condIsGachi, $condKDPresent]));
     $query = (new \yii\db\Query())->select(['battle_count' => $column_battle_count, 'wp' => $column_wp, 'wp_short' => $column_wp_short, 'total_kill' => $column_total_kill, 'total_death' => $column_total_death, 'total_kd_battle_count' => $column_total_kd_battle_count, 'nawabari_count' => $column_nawabari_count, 'nawabari_wp' => $column_nawabari_wp, 'nawabari_kill' => $column_nawabari_kill, 'nawabari_death' => $column_nawabari_death, 'gachi_count' => $column_gachi_count, 'gachi_wp' => $column_gachi_wp, 'gachi_kill' => $column_gachi_kill, 'gachi_death' => $column_gachi_death])->from('battle')->andWhere(['{{battle}}.[[user_id]]' => $this->user_id]);
     $this->attributes = $query->createCommand()->queryOne();
     $keys = ['battle_count', 'total_kill', 'total_death', 'total_kd_battle_count', 'nawabari_count', 'nawabari_kill', 'nawabari_death', 'gachi_count', 'gachi_kill', 'gachi_death'];
     foreach ($keys as $key) {
         $this->{$key} = (int) $this->{$key};
     }
     return $this;
 }
예제 #19
0
 private function mapUpdateRegular()
 {
     echo "regular...\n";
     $latestPeriod = $this->getLatestPeriod(GameMode::findOne(['key' => 'regular']));
     $currntPeriod = \app\components\helpers\Battle::calcPeriod(time());
     $futureOnly = $latestPeriod >= $currntPeriod;
     $json = array_filter(array_map(function ($item) {
         $item->period = \app\components\helpers\Battle::calcPeriod(strtotime($item->start));
         return $item;
     }, $this->queryJson($futureOnly ? 'http://splapi.retrorocket.biz/regular/next_all' : 'http://splapi.retrorocket.biz/regular')->result), function ($item) use($latestPeriod) {
         return $item->period > $latestPeriod;
     });
     if (empty($json)) {
         echo "no data updated.\n";
         return;
     }
     printf("count(new_data) = %d\n", count($json));
     usort($json, function ($a, $b) {
         return $a->period - $b->period;
     });
     echo "Converting to insert data...\n";
     $map = $this->getMapTable();
     $rule_id = Rule::findOne(['key' => 'nawabari'])->id;
     $insert = [];
     foreach ($json as $item) {
         foreach ($item->maps as $mapName) {
             if (isset($map[$mapName])) {
                 $insert[] = [$item->period, $rule_id, $map[$mapName]];
             } else {
                 echo "Unknown map name: {$mapName}\n";
             }
         }
     }
     echo "inserting...\n";
     Yii::$app->db->createCommand()->batchInsert(PeriodMap::tableName(), ['period', 'rule_id', 'map_id'], $insert)->execute();
     echo "done.\n";
 }
 /**
  * Finds the Rule model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Rule the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Rule::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #21
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRule()
 {
     return $this->hasOne(Rule::className(), ['id' => 'rule_id']);
 }
예제 #22
0
 public function toBattle()
 {
     $o = new Battle();
     $o->user_id = $this->getUser()->id;
     $o->lobby_id = $this->lobby ? Lobby::findOne(['key' => $this->lobby])->id : null;
     $o->rule_id = $this->rule ? Rule::findOne(['key' => $this->rule])->id : null;
     $o->map_id = $this->map ? Map::findOne(['key' => $this->map])->id : null;
     $o->weapon_id = $this->weapon ? Weapon::findOne(['key' => $this->weapon])->id : null;
     $o->level = $this->level ? (int) $this->level : null;
     $o->level_after = $this->level_after ? (int) $this->level_after : null;
     $o->rank_id = $this->rank ? Rank::findOne(['key' => $this->rank])->id : null;
     $o->rank_after_id = $this->rank_after ? Rank::findOne(['key' => $this->rank_after])->id : null;
     $o->rank_exp = (string) $this->rank_exp != '' ? (int) $this->rank_exp : null;
     $o->rank_exp_after = (string) $this->rank_exp_after != '' ? (int) $this->rank_exp_after : null;
     $o->cash = (string) $this->cash != '' ? (int) $this->cash : null;
     $o->cash_after = (string) $this->cash_after != '' ? (int) $this->cash_after : null;
     $o->is_win = $this->result === 'win' ? true : ($this->result === 'lose' ? false : null);
     $o->rank_in_team = $this->rank_in_team ? (int) $this->rank_in_team : null;
     $o->kill = (string) $this->kill != '' ? (int) $this->kill : null;
     $o->death = (string) $this->death != '' ? (int) $this->death : null;
     $o->gender_id = $this->fest_gender === 'boy' ? 1 : ($this->fest_gender === 'girl' ? 2 : null);
     $o->fest_title_id = $this->fest_rank ? FestTitle::findOne(['key' => $this->fest_rank])->id : null;
     $o->my_team_color_hue = $this->my_team_color ? $this->my_team_color['hue'] : null;
     $o->my_team_color_rgb = $this->my_team_color ? vsprintf('%02x%02x%02x', $this->my_team_color['rgb']) : null;
     $o->his_team_color_hue = $this->his_team_color ? $this->his_team_color['hue'] : null;
     $o->his_team_color_rgb = $this->his_team_color ? vsprintf('%02x%02x%02x', $this->his_team_color['rgb']) : null;
     $o->start_at = $this->start_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->start_at) : null;
     $o->end_at = $this->end_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->end_at) : new Now();
     $o->agent_id = null;
     $o->at = new Now();
     return $o;
 }
예제 #23
0
파일: Rule.php 프로젝트: codeforest/nisam
 public static function forUser($userId)
 {
     return Rule::where('user_id', '=', $userId)->get();
 }
예제 #24
0
 public function deleteRule($id)
 {
     $user = Auth::user();
     $rule = Rule::find($id);
     $response = $rule->delete();
     return response()->json($response)->header('Access-Control-Allow-Origin', '*');
 }
예제 #25
0
 private function notHas($uid, $app)
 {
     $app = App::find()->where(['code' => $app])->asArray()->one();
     $role = RoleUser::find()->where(['uid' => $uid])->asArray()->all();
     $roleid = array();
     foreach ($role as $vr) {
         $roleid[] = $vr['rid'];
     }
     $roleid = implode(',', $roleid);
     $rule = Rule::find()->select(['aid', 'role_id', 'model_id', 'feature_id', 'scope_id'])->where("role_id not in({$roleid})")->andWhere(['aid' => $app['id']])->asArray()->all();
     $result = array();
     $unique = array();
     foreach ($rule as $k => $vu) {
         $apps = App::find()->select(['name'])->where(['id' => $vu['aid']])->asArray()->one();
         $result[$k]['app'] = $apps['name'];
         $roles = Role::find()->select(['name'])->where(['id' => $vu['role_id']])->asArray()->one();
         $result[$k]['role'] = $roles['name'];
         $model = Model::find()->select(['name'])->where(['id' => $vu['model_id']])->asArray()->one();
         $result[$k]['model'] = $model['name'];
         $feature = Feature::find()->select(['name'])->where(['id' => $vu['feature_id']])->asArray()->one();
         $result[$k]['feature'] = $feature['name'];
         $scopes = Rule::find()->select(['scope_id'])->where(['aid' => $vu['aid'], 'role_id' => $vu['role_id'], 'model_id' => $vu['model_id'], 'feature_id' => $vu['feature_id']])->asArray()->all();
         foreach ($scopes as $ks => $vs) {
             $scope = Scope::find()->select(['name', 'attribute'])->where(['id' => $vs['scope_id']])->asArray()->one();
             $result[$k]['scope'][$ks]['name'] = $scope['name'];
             $result[$k]['scope'][$ks]['attribute'] = $scope['attribute'];
         }
         $unique[$k] = $vu['aid'] . $vu['role_id'] . $model['name'] . $feature['name'];
     }
     // delete the repeat elements
     $unique = array_unique($unique);
     $res = array();
     foreach ($unique as $kq => $vq) {
         $res[] = $result[$kq];
     }
     return $res;
 }
예제 #26
0
 public function rules()
 {
     return [[['lobby_id'], 'exist', 'targetClass' => Lobby::className(), 'targetAttribute' => 'id'], [['rule_id'], 'exist', 'targetClass' => Rule::className(), 'targetAttribute' => 'id'], [['map_id'], 'exist', 'targetClass' => Map::className(), 'targetAttribute' => 'id'], [['weapon_id'], 'exist', 'targetClass' => Weapon::className(), 'targetAttribute' => 'id']];
 }
예제 #27
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getRules()
 {
     return $this->hasMany(Rule::className(), ['mode_id' => 'id']);
 }
예제 #28
0
 public function toBattle()
 {
     $user = $this->getUser();
     $o = new Battle();
     $o->user_id = $user->id;
     $o->env_id = $user->env_id;
     $o->lobby_id = $this->lobby ? Lobby::findOne(['key' => $this->lobby])->id : null;
     $o->rule_id = $this->rule ? Rule::findOne(['key' => $this->rule])->id : null;
     $o->map_id = $this->map ? Map::findOne(['key' => $this->map])->id : null;
     $o->weapon_id = $this->weapon ? Weapon::findOne(['key' => $this->weapon])->id : null;
     $o->level = $this->level ? (int) $this->level : null;
     $o->level_after = $this->level_after ? (int) $this->level_after : null;
     $o->rank_id = $this->rank ? Rank::findOne(['key' => $this->rank])->id : null;
     $o->rank_after_id = $this->rank_after ? Rank::findOne(['key' => $this->rank_after])->id : null;
     $o->rank_exp = (string) $this->rank_exp != '' ? (int) $this->rank_exp : null;
     $o->rank_exp_after = (string) $this->rank_exp_after != '' ? (int) $this->rank_exp_after : null;
     $o->cash = (string) $this->cash != '' ? (int) $this->cash : null;
     $o->cash_after = (string) $this->cash_after != '' ? (int) $this->cash_after : null;
     $o->is_win = $this->result === 'win' ? true : ($this->result === 'lose' ? false : null);
     $o->rank_in_team = $this->rank_in_team ? (int) $this->rank_in_team : null;
     $o->kill = (string) $this->kill != '' ? (int) $this->kill : null;
     $o->death = (string) $this->death != '' ? (int) $this->death : null;
     $o->gender_id = $this->gender === 'boy' ? 1 : ($this->gender === 'girl' ? 2 : null);
     $o->fest_title_id = $this->fest_title ? FestTitle::findOne(['key' => $this->fest_title])->id : null;
     $o->fest_title_after_id = $this->fest_title_after ? FestTitle::findOne(['key' => $this->fest_title_after])->id : null;
     $o->fest_exp = (string) $this->fest_exp != '' ? (int) $this->fest_exp : null;
     $o->fest_exp_after = (string) $this->fest_exp_after != '' ? (int) $this->fest_exp_after : null;
     $o->my_team_color_hue = $this->my_team_color ? $this->my_team_color['hue'] : null;
     $o->my_team_color_rgb = $this->my_team_color ? vsprintf('%02x%02x%02x', $this->my_team_color['rgb']) : null;
     $o->his_team_color_hue = $this->his_team_color ? $this->his_team_color['hue'] : null;
     $o->his_team_color_rgb = $this->his_team_color ? vsprintf('%02x%02x%02x', $this->his_team_color['rgb']) : null;
     $o->start_at = $this->start_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->start_at) : null;
     $o->end_at = $this->end_at != '' ? gmdate('Y-m-d H:i:sP', (int) $this->end_at) : new Now();
     $o->agent_id = null;
     $o->ua_custom = (string) $this->agent_custom == '' ? null : (string) $this->agent_custom;
     $o->at = new Now();
     $o->is_automated = $this->automated === 'yes';
     $o->my_point = (string) $this->my_point != '' ? (int) $this->my_point : null;
     $o->my_team_final_point = (string) $this->my_team_final_point != '' ? (int) $this->my_team_final_point : null;
     $o->his_team_final_point = (string) $this->his_team_final_point != '' ? (int) $this->his_team_final_point : null;
     $o->my_team_final_percent = (string) $this->my_team_final_percent != '' ? sprintf('%.1f', (double) $this->my_team_final_percent) : null;
     $o->his_team_final_percent = (string) $this->his_team_final_percent != '' ? sprintf('%.1f', (double) $this->his_team_final_percent) : null;
     $o->is_knock_out = $this->knock_out === 'yes' ? true : ($this->knock_out === 'no' ? false : null);
     $o->my_team_count = (string) $this->my_team_count != '' ? (int) $this->my_team_count : null;
     $o->his_team_count = (string) $this->his_team_count != '' ? (int) $this->his_team_count : null;
     $o->events = null;
     if ($this->events) {
         $o->events = json_encode($this->events, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
     }
     if ($this->gears) {
         $o->headgear_id = $this->processGear('headgear');
         $o->clothing_id = $this->processGear('clothing');
         $o->shoes_id = $this->processGear('shoes');
     }
     if ($this->isTest) {
         $now = isset($_SERVER['REQUEST_TIME']) ? $_SERVER['REQUEST_TIME'] : time();
         $o->id = 0;
         foreach ($o->attributes as $k => $v) {
             if ($v instanceof Now) {
                 $o->{$k} = gmdate('Y-m-d H:i:sP', $now);
             }
         }
     }
     return $o;
 }
예제 #29
0
 public static function getAllIdName()
 {
     return ArrayHelper::map(Rule::find()->asArray()->all(), 'id', 'name');
 }
예제 #30
0
 private function notHas($uid, $app, $feature)
 {
     $app = App::find()->select(['id', 'name'])->where(['code' => $app])->asArray()->one();
     $role = RoleUser::find()->select(['rid', 'rname'])->where(['uid' => $uid])->asArray()->all();
     $roleid = array();
     foreach ($role as $vr) {
         $roleid[] = $vr['rid'];
     }
     $roleid = implode(',', $roleid);
     $scopes = Rule::find()->select(['model_id', 'scope_id'])->where(['aid' => $app['id']])->andWhere(['feature_code' => $feature])->andWhere("role_id not in({$roleid})")->asArray()->all();
     $feature = Feature::find()->select(['name'])->where(['code' => $feature])->asArray()->one();
     // delete repeat data
     $unique = array();
     foreach ($scopes as $k => $vs) {
         $unique[$k] = $vs['model_id'] . ',' . $vs['scope_id'];
     }
     $scope = array_unique($unique);
     $result = array();
     foreach ($scope as $k => $v) {
         $result[] = $scopes[$k];
     }
     $final = array();
     foreach ($result as $k => $vu) {
         $model = Model::find()->select(['name'])->where(['id' => $vu['model_id']])->asArray()->one();
         $scope = Scope::find()->select(['name', 'attribute'])->where(['id' => $vu['scope_id']])->asArray()->one();
         $final[$k]['model'] = $model['name'];
         $final[$k]['feature'] = $feature['name'];
         $final[$k]['scope'] = $scope['name'];
         $final[$k]['scope_attribute'] = $scope['attribute'];
     }
     return $final;
 }