Пример #1
0
 /**
  * Create a new theme.
  * 
  * @param  array $data 
  * 
  * @return ThemeModel
  */
 public function create(array $data)
 {
     $css = $this->less->parse('bootstrap', $data['vars'], $data['custom']);
     $path = $this->saveStylesheet($data['name'], $css);
     //save theme to database
     $this->model->path = $path;
     $this->model->name = $data['name'];
     $this->model->type = $data['type'];
     $this->model->custom_less = $data['custom'];
     $this->model->user_id = Sentry::getUser()->id;
     if (!empty($vars)) {
         $this->model->modified_vars = json_encode($vars);
     }
     $this->model->save();
     return $this->model;
 }
Пример #2
0
 /**
  * Save a new template to database.
  * 
  * @return Builder\Themes\ThemesModel
  */
 public function store()
 {
     if (!$this->app['sentry']->getUser()->hasAccess('templates.create')) {
         return new Response($this->app['translator']->trans('noPermTemplateCreate'), 403);
     }
     if (!$this->input->get('name')) {
         return new Response($this->app['translator']->trans('enterNameForTemplate'), 400);
     }
     $exists = $this->model->where('user_id', Sentry::getUser()->id)->where('name', $this->input->get('name'))->first();
     if ($exists) {
         return new Response($this->app['translator']->trans('templateWithNameExists'), 400);
     }
     $rand = str_random(10);
     $this->model->user_id = Sentry::getUser()->id;
     $this->model->name = $this->input->get('name');
     $this->model->color = $this->input->get('color');
     $this->model->category = $this->input->get('category');
     $this->model->thumbnail = 'assets/images/thumbnails/templates/template-' . $rand . '.png';
     if ($this->model->save()) {
         foreach ($this->input->get('pages') as $k => $page) {
             $pModel = new \Builder\Projects\PageModel();
             foreach ($page as $name => $value) {
                 $pModel->{$name} = is_array($value) ? json_encode($value) : $value;
             }
             $this->model->pages()->save($pModel);
         }
         $model = $this->model->with('pages')->find($this->model->id);
         $model->thumbId = $rand;
         return $model;
     }
 }