コード例 #1
0
ファイル: slicer.php プロジェクト: JoonasMelin/BotQueue
 public function config_create()
 {
     $this->assertLoggedIn();
     $this->set('area', 'slicers');
     try {
         //load the data and check for errors.
         if ($this->args('id')) {
             $engine = new SliceEngine($this->args('id'));
             if (!$engine->isHydrated()) {
                 throw new Exception("That slice engine does not exist.");
             }
             if (!$engine->get('is_public') || !User::isAdmin()) {
                 throw new Exception("You do not have access to view this slice engine.");
             }
             $this->setTitle("Create Slice Config - " . $engine->getName());
         } else {
             $this->setTitle("Create Slice Config");
             $engine = new SliceEngine();
         }
         //setup some objects
         $config = new SliceConfig();
         // If the engine has an id, set the engine_id in the config
         if ($engine->id) {
             $config->set('engine_id', $engine->id);
         }
         $form = $this->_createSliceConfigUploadForm($config);
         if ($engine->id) {
             $form->action = $engine->getUrl() . "/createconfig";
         } else {
             $form->action = "/slicer/createconfig";
         }
         $this->set('form', $form);
         //check our form
         if ($form->checkSubmitAndValidate($this->args())) {
             //now we make it a config object
             $config->set('config_name', $form->data('config_name'));
             $file = $form->data('config_file');
             $config->set('config_data', file_get_contents($file['tmp_name']));
             $config->set('engine_id', $form->data('engine_id'));
             $config->set('user_id', User::$me->id);
             $config->set('add_date', date("Y-m-d H:i:s"));
             $config->set('edit_date', date("Y-m-d H:i:s"));
             $config->save();
             //send us to view the new engine.
             $this->forwardToUrl($config->getUrl());
         }
     } catch (Exception $e) {
         $this->setTitle("Create Slice Config - Error");
         $this->set('megaerror', $e->getMessage());
     }
 }