public function post_add() { $input = Input::all(); $rules = array('name' => 'required', 'url' => 'required|url', 'image' => 'image', 'description' => 'required'); $validation = Validator::make($input, $rules); if ($validation->passes()) { $sponsor = new Sponsor(); $sponsor->name = Input::get('name'); $sponsor->url = Input::get('url'); $sponsor->description = Input::get('description'); if (Input::hasFile('image')) { $image_name = preg_replace('/.*\\.(.+)/', $sponsor->id . ".\$1", Input::file('image')->getClientOriginalName()); Input::file('image')->move(base_path() . '/public/img/sponsor', $image_name); $sponsor->image = $image_name; } $sponsor->save(); return Redirect::to('rms/sponsors')->with('success', 'Successfully Added New Sponsor: ' . $sponsor->name); } else { return Redirect::to('rms/sponsors/add')->withErrors($validation)->withInput(); } }
public function action() { SQL::getInstance()->autocommit(false); $actionResult = SponsorSatellite::erase(); /* $sponsorsStoreInRAM = RAM::getInstance()->getObjectsForTeam(UserParameters::getUserId(), RAM::RAM_TYPE_SPONSOR); foreach ($sponsorsStoreInRAM as $sponsorInstance){ RAM::getInstance()->deleteSponsor($sponsorInstance->getId(), UserParameters::getUserId()); } */ track_stats(); // Отслеживаем производительность $energyRate = 1; $sponsorsStore = array(); $actionResult = NULL; if (!is_object($this->parameters) && !is_array($this->parameters)) { $this->parameters = str_replace('\\\\"', '', $this->parameters); $this->parameters = str_replace(']\\"', ']', $this->parameters); $this->parameters = str_replace('\\"[', '[', $this->parameters); $this->parameters = json_decode($this->parameters); } track_stats(); // Отслеживаем производительность if (!Utils::isEmpty($this->parameters) && !$actionResult instanceof ErrorPoint) { $sponsorDBResult = SponsorSatellite::getFromStoreByIds($this->parameters); $sponsorCount = count($sponsorDBResult); track_stats(); // Отслеживаем производительность if ($sponsorDBResult instanceof ErrorPoint) { $actionResult = $sponsorDBResult; } elseif ($sponsorCount) { if ($sponsorCount > GlobalParameters::SPONSORS_LIMIT) { $actionResult = new ErrorPoint(ErrorPoint::CODE_LOGIC, "Количество спонсоров превышет допустимый предел. Получено " . $sponsorCount . " спонсоров ", ErrorPoint::TYPE_SYSTEM); } else { track_stats(); // Отслеживаем производительность foreach ($sponsorDBResult as $sponsor) { $sponsorInstance = new Sponsor(); $sponsorInstance->initFromParameters($sponsor); if ($sponsorInstance->getRequiredLevel() > $this->teamProfile->getLevel()) { $actionResult = new ErrorPoint(ErrorPoint::CODE_SECURITY, "Спонсор не доступен по уровню. Уровень спонсора: " . $sponsorInstance->getRequiredLevel() . ", а у вас " . intval($this->teamProfile->getLevel()), ErrorPoint::TYPE_USER); break; } $actionResult = $sponsorInstance->save(); if ($actionResult instanceof ErrorPoint) { break; } $energyRate *= $sponsorInstance->getEnergy(); $sponsorsStore[] = $sponsorInstance; } track_stats(); // Отслеживаем производительность } } } if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); return $actionResult; } if ($energyRate < 1) { $energyRate = 1; } track_stats(); // Отслеживаем производительность $this->teamProfile->setSponsorRate($energyRate); $this->teamProfile->setMaxEnergy($energyRate * LevelsGrid::getInstance()->getBaseEnergy($this->teamProfile->getLevel())); $this->teamProfile->bindSponsors($sponsorsStore); $actionResult = $this->teamProfile->save(); if ($actionResult instanceof ErrorPoint) { SQL::getInstance()->rollback(); } else { SQL::getInstance()->commit(); } track_stats(); // Отслеживаем производительность return $actionResult; }