示例#1
0
 public static function updateEventPackage($pack)
 {
     $pack->auth->game_id = dbconnection::queryObject("SELECT * FROM event_packages WHERE event_package_id = '{$pack->event_package_id}'")->game_id;
     $pack->auth->permission = "read_write";
     if (!editors::authenticateGameEditor($pack->auth)) {
         return new return_package(6, NULL, "Failed Authentication");
     }
     $auth = $pack->auth;
     //save for later (getEventPackagePack unsets it)
     if (!$pack->event_package_id) {
         return;
     }
     dbconnection::query("UPDATE event_packages SET " . (isset($pack->name) ? "name          = '" . addslashes($pack->name) . "', " : "") . (isset($pack->icon_media_id) ? "icon_media_id = '" . addslashes($pack->icon_media_id) . "', " : "") . "last_active = CURRENT_TIMESTAMP " . "WHERE event_package_id = '" . addslashes($pack->event_package_id) . "'");
     $reqEvents = $pack->events;
     $curEvents = events::getEventPackage($pack)->data->events;
     for ($i = 0; $i < count($reqEvents); $i++) {
         $reqEvents[$i]->game_id = $pack->auth->game_id;
         $reqEvents[$i]->event_package_id = $pack->event_package_id;
         $reqEvents[$i]->auth = $auth;
     }
     for ($i = 0; $i < count($curEvents); $i++) {
         $curEvents[$i]->game_id = $pack->auth->game_id;
         $curEvents[$i]->event_package_id = $pack->event_package_id;
         $curEvents[$i]->auth = $auth;
     }
     $eventsToDelete = array();
     $eventsToAdd = array();
     $eventsToUpdate = array();
     //find to-update and to-delete
     for ($i = 0; $i < count($curEvents); $i++) {
         $found = false;
         for ($j = 0; $j < count($reqEvents); $j++) {
             if ($curEvents[$i]->event_id == $reqEvents[$j]->event_id) {
                 $eventsToUpdate[] = $reqEvents[$j];
                 $found = true;
             }
         }
         if (!$found) {
             $eventsToDelete[] = $curEvents[$i];
         }
     }
     //find to-add
     for ($i = 0; $i < count($reqEvents); $i++) {
         $found = false;
         if ($reqEvents[$i]->event_id) {
             for ($j = 0; $j < count($curEvents); $j++) {
                 if ($reqEvents[$i]->event_id == $curEvents[$j]->event_id) {
                     $found = true;
                 }
             }
         }
         if (!$found) {
             $eventsToAdd[] = $reqEvents[$i];
         }
     }
     for ($i = 0; $i < count($eventsToDelete); $i++) {
         events::deleteEvent($eventsToDelete[$i]);
     }
     for ($i = 0; $i < count($eventsToUpdate); $i++) {
         events::updateEvent($eventsToUpdate[$i]);
     }
     for ($i = 0; $i < count($eventsToAdd); $i++) {
         events::createEvent($eventsToAdd[$i]);
     }
     games::bumpGameVersion($pack);
     return events::getEventPackage($pack);
 }