| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139 |
- <?php
- /**
- * File for the optimization action.
- *
- * Implements an action function to be called from the {@see Controller}.
- *
- * @category Action
- */
- /**
- * Executes the optimization action.
- *
- * Reads the POST parameters looking for the following KEYS:
- * mail
- * pass + currentPass
- * api
- * Then it updates the selected info with the prameter vlue. Multiple
- * itemas can be updated at the same time.
- *
- * @return int|string 0 on success, negative values on error. If the API
- * key has been updated, the new key.
- * @category Action
- * @global resource Database connection.
- */
- function action(){
- global $db;
- $response = null;
- $uid = filter_input(INPUT_POST, 'uid');
- if ($uid == null){
- error_log("-1");
- return -1;
- }
- $unit = filter_input(INPUT_POST, 'unit');
- if ($uid == null){
- error_log("-2");
- return -2;
- }
- // Sets
- // TODO: Check if valid.
- // TODO: Check if compatible sets, not just size.
- $sets = [];
- foreach ($_POST["set"] as $x){
- array_push($sets, intval($x));
- }
- if (sizeof($sets) < 2 || sizeof($sets) > 3){
- error_log("-3");
- return -3;
- }
- // Main stats in even slots.
- // TODO: Check if valid.
- // TODO: Check if valid per slot
- $stats = [];
- foreach ($_POST["stat"] as $x){
- array_push($stats, intval($x));
- }
- $source = filter_input(INPUT_POST, 'source');
- if ($source == null){
- error_log("-4");
- return -4;
- }
- $tuning = filter_input(INPUT_POST, 'tuning');
- if ($tuning == null){
- error_log("-5");
- return -5;
- }
- // Get optimization id and create the view:
- $optmization_id = $uid . "-" . $unit . "-" . rand(0,1000);
- $db->query($s);
- $s = "
- SELECT *
- FROM rune
- WHERE
- uid = $uid AND
- set IN (
- ";
- foreach ($sets as $set){
- $s .= ($set . ",");
- }
- $s .= "-1) AND ";
- switch ($source){
- case 0: // Storage only
- $s .= "assigned_to IS NULL";
- break;
- case 1: // Units in no teams
- $s .= "
- (
- assigned_to IS NULL OR
- assigned_to NOT IN (SELECT DISTINCT unit FROM team_unit)
- )
- ";
- break;
- case 2: // Units in teams with 0 score
- $s .= "
- (
- assigned_to IS NULL OR
- assigned_to NOT IN (SELECT DISTINCT unit FROM team_unit) OR
- assigned_to NOT IN (
- SELECT DISTINCT unit
- FROM
- team,
- team_unit
- WHERE
- team.id = team_unit.team AND
- team.score > 0
- )
- )
- ";
- break;
- case 3: // Units with lower overall score
- // TODO
- break;
- case 4: // All runes - dont filter
- $s .= " 1 = 1 ";
- break;
- default: // Invalid options - return nothing
- $s .= " 1 = 0 ";
- }
- error_log($s);
- $response = $s;
- if ($response == null){
- return 0;
- }
- else{
- return $response;
- }
- }
- ?>
|