Esempio n. 1
0
 /**
  * @return OpenSKOS_Db_Table_Row_Collection
  */
 protected function _getCollection()
 {
     $collectionCode = $this->getRequest()->getParam('collection');
     if (!$collectionCode) {
         throw new Zend_Controller_Action_Exception('No collection specified', 412);
     }
     $model = new OpenSKOS_Db_Table_Collections();
     $collection = $model->findByCode($collectionCode, $this->_getTenant());
     if (null === $collection) {
         throw new Zend_Controller_Action_Exception('No such collection: `' . $collectionCode . '`', 404);
     }
     return $collection;
 }
 /**
  * @return OpenSKOS_Db_Table_Row_Collection
  */
 protected function _getCollection()
 {
     $model = new OpenSKOS_Db_Table_Collections();
     if (null === ($code = $this->getRequest()->getParam('collection'))) {
         //create a new collection:
         $collection = $model->createRow(array('tenant' => $this->_tenant->code));
     } else {
         $collection = $model->findByCode($code, $this->_tenant->code);
         if (null === $collection) {
             $this->getHelper('FlashMessenger')->setNamespace('error')->addMessage(sprintf(_('Collection `%s` not found', $code)));
             $this->_helper->redirector('index');
         }
     }
     return $collection;
 }
Esempio n. 3
0
 /**
  * 
  * @param Zend_Console_Getopt $opts
  * @return OpenSKOS_Rdf_Parser
  */
 public function setOpts(Zend_Console_Getopt $opts)
 {
     try {
         $opts->parse();
     } catch (Zend_Console_Getopt_Exception $e) {
         echo str_replace('[ options ]', '[ options ] file', $e->getUsageMessage());
         throw new OpenSKOS_Rdf_Parser_Exception($e->getMessage());
     }
     if (null !== $opts->help) {
         echo str_replace('[ options ]', '[ options ] file', $opts->getUsageMessage());
         throw new OpenSKOS_Rdf_Parser_Exception('', 0);
     }
     if ($opts->status) {
         if (!in_array($opts->status, self::$statuses)) {
             throw new OpenSKOS_Rdf_Parser_Exception('Illegal `status` value, must be one of `' . implode('|', self::$statuses) . '`', 0);
         }
     }
     foreach (self::$required as $opt) {
         if (null === $this->_opts->{$opt}) {
             throw new OpenSKOS_Rdf_Parser_Exception("missing required parameter `{$opt}`");
         }
     }
     $this->_opts = $opts;
     if (null !== $this->_opts->help) {
         $this->printUsageMessageAndExit();
     }
     if (null !== $opts->limit) {
         $this->setLimit((int) $opts->limit);
     }
     if (null !== $opts->from) {
         $this->setFrom((int) $opts->from);
     }
     $this->_bootstrap();
     $files = $this->_opts->getRemainingArgs();
     if (count($files) !== 1) {
         throw new OpenSKOS_Rdf_Parser_Exception(str_replace('[ options ]', '[ options ] file', $this->_opts->getUsageMessage()));
     }
     $this->setFiles($files);
     $model = new OpenSKOS_Db_Table_Tenants();
     $tenant = $model->find($opts->tenant)->current();
     if (null === $tenant) {
         throw new OpenSKOS_Rdf_Parser_Exception("No such tenant: `{$opts->tenant}`");
     }
     $model = new OpenSKOS_Db_Table_Collections();
     if (preg_match('/^\\d+$/', $opts->collection)) {
         $collection = $model->find($opts->collection)->current();
     } else {
         $collection = $model->findByCode($opts->collection, $opts->tenant);
     }
     if (null === $collection) {
         throw new OpenSKOS_Rdf_Parser_Exception("No such collection: `{$opts->collection}`");
     } else {
         $this->_collection = $collection;
     }
     return $this;
 }