예제 #1
0
 public function updateRequirementPackage($pack)
 {
     if (!$pack || !$pack->game_id || !$pack->requirement_root_package_id) {
         return;
     }
     Module::query("UPDATE requirement_root_packages SET " . "game_id = '" . addslashes($pack->game_id) . "'" . ($pack->name ? ", name = '" . addslashes($pack->name) . "'" : "") . " WHERE requirement_root_package_id = '" . addslashes($pack->requirement_root_package_id) . "'");
     $sql_currentAndPacks = Module::queryArray("SELECT * FROM requirement_and_packages WHERE requirement_root_package_id = '{$pack->requirement_root_package_id}'");
     for ($i = 0; $i < count($sql_currentAndPacks); $i++) {
         $matchingAndPack = null;
         for ($j = 0; $pack->and_packages && $j < count($pack->and_packages); $j++) {
             if ($sql_currentAndPacks[$i]->requirement_and_package_id == $pack->and_packages[$j]->requirement_and_package_id) {
                 $matchingAndPack = $pack->and_packages[$j];
                 //remove from array so I can just add all remaining later
                 array_splice($pack->and_packages, $j, 1);
                 $j--;
             }
         }
         if ($matchingAndPack) {
             $matchingAndPack->requirement_root_package_id = $pack->requirement_root_package_id;
             $matchingAndPack->game_id = $pack->game_id;
             Requirements::updateRequirementAndPackage($matchingAndPack);
         } else {
             Requirements::deleteRequirementAndPackage($sql_currentAndPacks[$i]->requirement_and_package_id);
         }
     }
     for ($i = 0; $pack->and_packages && $i < count($pack->and_packages); $i++) {
         $pack->and_packages[$i]->requirement_root_package_id = $pack->requirement_root_package_id;
         $pack->and_packages[$i]->game_id = $pack->game_id;
         Requirements::createRequirementAndPackage($pack->and_packages[$i]);
     }
     return Requirements::getRequirementPackage($pack->requirement_root_package_id);
 }