Exemple #1
0
 /**
  * Create export zip file for given page.
  * 
  * @param  string/int $id
  * @return boolean/string
  */
 public function page($id)
 {
     $page = $this->page->find($id);
     //fix eloquent morphTo issue with namespaced models
     if ($page) {
         $page->pageable_type = '\\Builder\\Projects\\ProjectModel';
     }
     //basic access check
     if (!$page || !$page->pageable->users()->where('users.id', $this->app['sentry']->getUser()->id)->first()) {
         return false;
     }
     if ($path = $this->createFolders($page->pageable)) {
         //create a fake project with given page so we can
         //reuse same methods as when exporting a project
         $project = new \stdClass();
         $project->pages = array($page);
         $this->createFiles($path, $project);
         return $this->zip($path, $page->id);
     }
 }
Exemple #2
0
 /**
  * Update project pages with given data.
  * 
  * @param  array  $project
  * @return void
  */
 private function updatePages(array $project)
 {
     foreach ($project['pages'] as $page) {
         //find page in db or create a new one
         if (isset($page['id'])) {
             $m = $this->page->find($page['id']);
         } else {
             $m = $this->page->newInstance();
         }
         //update the model values with the ones from input
         foreach ($page as $k => $v) {
             $m->{$k} = is_array($v) ? json_encode($v) : $v;
         }
         $m->save();
     }
 }