/**
  * Creates a new reporitory to store the models in
  *
  * @param $guid The
  *            guid of the gulpfile
  * @param
  *            createIfNotExists boolean to denote if the file should be created when it doesn't exists yet
  *            
  * @throws FileNotFoundException when createIfNotExists = false (by default) and the file does not exist
  *        
  * @return \compact\repository\IModelRepository
  */
 private function createDb($guid, $createIfNotExists = false)
 {
     assert(strlen($guid) > 10);
     $filepath = Context::get()->basePath('app/db/' . $guid . '.json');
     if (!$createIfNotExists && !$filepath->isFile()) {
         throw new FileNotFoundException($filepath);
     }
     return new JsonRepository(new DefaultModelConfiguration(), $filepath);
 }
 /**
  * Returns all tasks as models or all tasks for a particular gulpfile
  * 
  * @return array with models
  */
 public static function getTasks($guid = null)
 {
     if ($guid === null) {
         $file = __DIR__ . "/tasks/tasks.json";
     } else {
         $file = Context::get()->basePath('app/db/' . $guid . '.json');
     }
     $json = file_get_contents($file);
     return self::convertToModel(json_decode($json)[0]);
 }
 /**
  * Upload the file and
  * 
  * @return \compact\mvvm\impl\ViewModel
  */
 public function upload()
 {
     $options = new UploadOptions();
     $options->setMimetypes(['image/jpg', 'image/jpeg', 'image/gif', 'image/png'])->setAllowOverwrite(false)->setMaxFiles(20)->setMaxSize(5000000)->setUploadDir(Context::get()->basePath('/img/original'), true);
     $upload = new UploadManager($options);
     $view = $this->form();
     try {
         $files = $upload->upload();
         if ($files->count() > 0) {
             $file = $files->offsetGet(0);
             $view->{'imagename'} = $file->getFilename();
         }
     } catch (UploadException $ex) {
         $view->{'error'} = $ex->getMessage();
     }
     return $view;
 }
Beispiel #4
0
 /**
  * (non-PHPdoc)
  * 
  * @see \compact\IAppContext::handlers()
  */
 public function handlers(Context $ctx)
 {
     $ctx->addHandler(new Imagehandler());
 }
 /**
  * (non-PHPdoc)
  *
  * @see \compact\IAppContext::services()
  */
 public function services(Context $ctx)
 {
     if ($ctx->isLocal()) {
         $ctx->http()->getResponse()->setCORSHeaders();
     }
 }