コード例 #1
0
ファイル: EditController.php プロジェクト: blackskaarj/webgr
 public function updateAction()
 {
     $request = $this->getRequest();
     $fishId = intval($request->getParam(Fish::COL_ID));
     $dbAdapter = Zend_Registry::get('DB_CONNECTION1');
     if ($request->isPost() and $this->form->isValid($request->getParams($fishId))) {
         $data = array(Fish::COL_SAMPLE_CODE => $this->form->getValue(Fish::COL_SAMPLE_CODE), Fish::COL_USER_ID => AuthQuery::getUserId());
         $this->fishTable->updateFishAndMetadata($this->form, $fishId, $data);
         $namespace = new Zend_Session_Namespace('default');
         $redirect = new Zend_Controller_Action_Helper_Redirector();
         if ($namespace->next != null) {
             $nextArray = $namespace->next;
             $namespace->next = null;
             $redirect->setGotoSimple($nextArray['nextAction'], $nextArray['nextController'], $nextArray['nextModul']);
         } else {
             $redirect->setGotoSimple('search', 'search', 'fish');
         }
     } else {
         $fishResult = $this->fishTable->find($fishId)->current();
         if ($fishResult != null) {
             $fishArray = $fishResult->toArray();
         } else {
             $fishArray = array();
         }
         // get meta data
         $select = $dbAdapter->select();
         $select->from(MetaDataFish::TABLE_NAME);
         $select->join(AttributeDescriptor::TABLE_NAME, MetaDataFish::TABLE_NAME . '.' . MetaDataFish::COL_ATTRIBUTE_DESCRIPTOR_ID . '=' . AttributeDescriptor::TABLE_NAME . '.ATDE_ID');
         $select->where(MetaDataFish::COL_FISH_ID . '=?', $fishId);
         $metaArray = $dbAdapter->fetchAll($select);
         $this->form->dynPopulate($metaArray, MetaDataFish::COL_VALUE, $fishArray);
         $this->view->form = $this->form;
         $this->render('form');
     }
 }
コード例 #2
0
 public function listAction()
 {
     $dbAdapter = Zend_Registry::get('DB_CONNECTION1');
     $select = $dbAdapter->select();
     $select->from(array('wt' => Workshop::TABLE_NAME), array(Workshop::COL_NAME, Workshop::COL_START_DATE, 'wt.' . Workshop::COL_ID, Workshop::COL_END_DATE, Workshop::COL_USER_ID));
     $select->join(array('vl' => ValueList::TABLE_NAME), $dbAdapter->quoteIdentifier('wt.' . Workshop::COL_LOCATION) . '=' . $dbAdapter->quoteIdentifier('vl.' . ValueList::COL_ID), array(ValueList::COL_NAME));
     $select->join(array('us' => User::TABLE_NAME), $dbAdapter->quoteIdentifier('wt.' . Workshop::COL_USER_ID) . '=' . $dbAdapter->quoteIdentifier('us.' . User::COL_ID), array(User::COL_USERNAME));
     if ($this->myws) {
         // get user id from current user
         $userId = AuthQuery::getUserId();
         //pushed the join 'part' where to extra where method
         $select->distinct();
         //left join to show ws without CEs, too
         $select->joinLeft(array('caex' => CalibrationExercise::TABLE_NAME), $dbAdapter->quoteIdentifier('wt.' . Workshop::COL_ID) . '=' . $dbAdapter->quoteIdentifier('caex.' . CalibrationExercise::COL_WORKSHOP_ID), array());
         //left join to show ws without CEs, too
         $select->joinLeft(array('part' => Participant::TABLE_NAME), $dbAdapter->quoteIdentifier('caex.' . CalibrationExercise::COL_ID) . '=' . $dbAdapter->quoteIdentifier('part.' . Participant::COL_CE_ID), array());
         //show workshops where you are participant in any CE
         $select->where('part.' . Participant::COL_USER_ID . '= ?', $userId, 'int');
         //show workshops where you are ws-manager
         $select->orWhere('wt.' . Workshop::COL_USER_ID . '= ?', $userId, 'int');
     }
     $paginator = new Ble422_Paginator_Extended($select, $this->getRequest());
     $paginator->setHeader(array(array('raw' => ValueList::COL_NAME, 'name' => 'Location'), array('raw' => Workshop::COL_NAME, 'name' => 'Workshopname'), array('raw' => Workshop::COL_START_DATE, 'name' => 'Start date'), array('raw' => Workshop::COL_END_DATE, 'name' => 'End Date'), array('raw' => User::COL_USERNAME, 'name' => 'Manager')));
     $paginator->setCurrentPageNumber($this->getRequest()->getParam('page'))->setItemCountPerPage(1000)->setPageRange(10)->orderBy($this->getRequest()->getParam('orderBy'));
     //$this->_getParam('pageRange'));
     $this->view->paginator = $paginator;
     $this->view->userRole = AuthQuery::getUserRole();
     // for the redirect from mywsAction!
     $this->render('list');
 }
コード例 #3
0
 public function myceAction()
 {
     //showXYZ shows links/actions
     $this->defaultNamespace->callingAction = 'ce/search/myce';
     $this->view->showStart = TRUE;
     $this->view->deleteTrainingCe = TRUE;
     $this->process(array(User::COL_ID => AuthQuery::getUserId()));
 }
コード例 #4
0
 public function createAction()
 {
     $expId = intval($this->getRequest()->getParam(Expertise::COL_ID));
     $keyId = intval($this->getRequest()->getParam(KeyTable::COL_ID));
     $expTable = new Expertise();
     $expRow = $expTable->find($expId);
     $keyTable = new KeyTable();
     $keyRow = $keyTable->find($keyId);
     if ($keyRow->count() != 0 || $expRow->count() != 0) {
         $keyArray = $keyRow->toArray();
         $expArray = $expRow->toArray();
         // create CE row
         $ceTable = new CalibrationExercise();
         $ceName = $expArray[0][Expertise::COL_SPECIES] . ' / ' . AuthQuery::getUserName();
         //TODO \r in der Datenbank
         $ceDescription = 'Area: ' . $expArray[0][Expertise::COL_AREA] . '\\r' . 'Subject: ' . $expArray[0][Expertise::COL_SUBJECT] . '\\r' . 'KeyName: ' . $keyArray[0][KeyTable::COL_NAME];
         $ceData = array(CalibrationExercise::COL_NAME => $ceName, CalibrationExercise::COL_DESCRIPTION => $ceDescription, CalibrationExercise::COL_KEY_TABLE_ID => $keyArray[0][KeyTable::COL_ID], CalibrationExercise::COL_EXPERTISE_ID => $expArray[0][Expertise::COL_ID], CalibrationExercise::COL_COMPAREABLE => 1, CalibrationExercise::COL_IS_STOPPED => 0, CalibrationExercise::COL_TRAINING => 1);
         $ceId = $ceTable->insert($ceData);
         // create participant row
         $partTable = new Participant();
         $partData = array(Participant::COL_CE_ID => $ceId, Participant::COL_USER_ID => AuthQuery::getUserId(), Participant::COL_NUMBER => 1);
         $partId = $partTable->insert($partData);
         // add all possible shown attributes
         $dbAdapter = $ceTable->getAdapter();
         $selectAttr = $dbAdapter->select();
         $selectAttr->from(AttributeDescriptor::TABLE_NAME);
         $selectAttr->orWhere(AttributeDescriptor::COL_GROUP . '=?', 'fish');
         $selectAttr->orWhere(AttributeDescriptor::COL_GROUP . '=?', 'image');
         $attrArray = $dbAdapter->fetchAll($selectAttr);
         $ceHasAttrTable = new CeHasAttributeDescriptor();
         foreach ($attrArray as $attr) {
             $attrData = array(CeHasAttributeDescriptor::COL_ATDE_ID => $attr[AttributeDescriptor::COL_ID], CeHasAttributeDescriptor::COL_CAEX_ID => $ceId);
             $ceHasAttrTable->insert($attrData);
         }
         //get images for exp/key
         $refQuery = new Default_ReferenceQuery();
         $images = $refQuery->getImages($expId, $keyId);
         // create imageset
         //			$selectImages = $dbAdapter->select();
         //			$imagesArray = $dbAdapter->fetchAll($selectImages);
         $imageSetTable = new CeHasImage();
         foreach ($images as $image) {
             $data = array(CeHasImage::COL_IMAGE_ID => $image, CeHasImage::COL_CALIBRATION_EXERCISE_ID => $ceId);
             $imageSetTable->insert($data);
         }
         //$this->render('form');
         $Redirect = new Zend_Controller_Action_Helper_Redirector();
         $Redirect->setGotoSimple('index', 'make', 'annotation', array(CalibrationExercise::COL_ID => $ceId));
     } else {
         throw new Zend_Controller_Exception('Error at craeting a new training Calibration Exercise.', 505);
     }
 }
コード例 #5
0
 public function indexAction()
 {
     $addFish = false;
     if ($this->getRequest()->isPost()) {
         $params = $this->getRequest()->getParams();
         if ($this->form->isValid($params)) {
             //TODO wenn fishsamplecode noch nicht in der datenbank,
             //dann lege fisch an mit diesem samplecode (erledigt)
             //und SPRINGE IN Fish_CreateController (am Ende des Controllers)
             //TODO mit getElement und Konstanten arbeiten
             $fishSampleCode = $this->form->getValue(Fish::COL_SAMPLE_CODE);
             $fishTable = new Fish();
             $row = $fishTable->fetchRow($fishTable->select()->where(Fish::COL_SAMPLE_CODE . '= ?', $fishSampleCode));
             if (is_null($row)) {
                 //echo 'Warnung: Fish Sample Code nicht vorhanden.';
                 $fishId = $fishTable->insert(array(Fish::COL_SAMPLE_CODE => $fishSampleCode));
                 $addFish = true;
                 $constFishId = Fish::COL_ID;
                 $fishId->{$constFishId} = $fishId;
             } else {
                 $addFish = false;
                 $fishId = $row->FISH_ID;
             }
             //TODO dateinamen mit leerzeichen
             //könnte ein problem bei der weiterverarbeitung in linux sein
             //klären,
             //ggf. akzeptieren und umwandeln oder verweigern?
             //don't call $form->getValues() - causes physical upload immediately
             //look ZFDoc 19.1.3
             //note: if using Zend_Form_Element_File (in view) you can't use new instance of Zend_File_Transfer_Adapter_Http in controller!
             // http://www.zfforums.com/zend-framework-forum-8/general-talks-12/file_transfer-illegal-uploaded-possible-attack-1737.html
             // http://www.nabble.com/Zend_File_Transfer-td19024470.html
             //solution:
             //getTransferAdapter()
             $upload = $this->form->uploadElement->getTransferAdapter();
             // Returns all known internal file informations
             $files = $upload->getFileInfo();
             $imageTable = new Image();
             $medimTable = new MetaDataImage();
             //look ZFDoc 19.3.3
             //iterates over all file elemens
             $numberImagesUploaded = 0;
             $userId = AuthQuery::getUserId();
             foreach ($files as $file => $info) {
                 /*handle only uploaded files, skip blank file elements
                 	 store original file in certain path
                 	 file is saved without excplicit temp directory with Zend Filter
                 	 image import uses temp directory instead
                 	 */
                 if (!$upload->isUploaded($file)) {
                     continue;
                 }
                 $creator_guid = new Ble422_Guid();
                 $guid = $creator_guid->__toString();
                 $fileName = $info['name'];
                 $path_parts = pathinfo($fileName);
                 $originalFileName = $path_parts['basename'];
                 //used later to create Image dataset
                 $newFileNameWithGuid = $guid . '.' . strtolower($path_parts['extension']);
                 //save extension in lower-case
                 //relative path with new filename, prefix dot&slash required
                 $completeTarget = './' . Image::RELATIVE_UPLOAD_PATH . '/' . $newFileNameWithGuid;
                 //apply filter only for uploaded file $fileName
                 $upload->addFilter('Rename', array('target' => $completeTarget, 'overwrite' => false), $fileName);
                 $upload->receive($file);
                 //TODO write protect files
                 $upload->clearFilters();
                 try {
                     $ratio = $this->form->getValue(Image::COL_RATIO_EXTERNAL);
                     $tn_ratio = $imageTable->processImage($completeTarget);
                     //ratio is filled from form
                     $imageId = $imageTable->insertImageDataset($completeTarget, $originalFileName, $fishId, $guid, $userId, $ratio, $tn_ratio);
                     $imageTable->updateImageAndMetadata($this->form, $imageId);
                     $numberImagesUploaded++;
                 } catch (Exception $e) {
                     echo "Exception: " . $e->getMessage();
                 }
             }
             Zend_Registry::set('MESSAGE', $numberImagesUploaded . ' image(s) successfully inserted');
             if ($addFish) {
                 $next = array('nextAction' => 'index', 'nextController' => 'upload', 'nextModul' => 'image');
                 $namespace = new Zend_Session_Namespace('default');
                 $namespace->next = $next;
                 $redirect = new Zend_Controller_Action_Helper_Redirector();
                 $redirect->setGotoSimple('update', 'edit', 'fish', array(Fish::COL_ID => $fishId));
             }
         } else {
             //form isn't valid
             $this->form->populate($params);
             $this->view->form = $this->form;
         }
     }
     //$this->view->form = $form;
 }
コード例 #6
0
ファイル: Batch.php プロジェクト: blackskaarj/webgr
 public function __construct($log = true)
 {
     $this->userId = AuthQuery::getUserId();
 }
コード例 #7
0
ファイル: EditController.php プロジェクト: blackskaarj/webgr
 public function updateAction()
 {
     $table = new Workshop();
     $request = $this->getRequest();
     $updateValues = $request->getParams();
     $wsNamespace = new Zend_Session_Namespace('workshop');
     //$this->view->WORK_ID = $updateValues[Workshop::COL_ID];
     $workId = intval($this->getRequest()->getParam(Workshop::COL_ID));
     $this->view->WORK_ID = $workId;
     //if user is not actual workshop manager, redirect
     if (!AuthQuery::getUserId() == Default_SimpleQuery::getWsManagerUserId($workId)) {
         $this->redirectTo('list', 'search', 'workshop');
         return;
     }
     if ($request->isPost()) {
         if ($this->getRequest()->getParam('save') != null) {
             //save Button clicked
             if ($this->form->isValid($updateValues)) {
                 if ($this->form->getValue('Token') == $wsNamespace->Token) {
                     $data = array(Workshop::COL_NAME => $this->form->getValue(Workshop::COL_NAME), Workshop::COL_LOCATION => $this->form->getValue(Workshop::COL_LOCATION), Workshop::COL_START_DATE => $this->form->getValue(Workshop::COL_START_DATE), Workshop::COL_END_DATE => $this->form->getValue(Workshop::COL_END_DATE), Workshop::COL_HOST_ORGANISATION => $this->form->getValue(Workshop::COL_HOST_ORGANISATION), Workshop::COL_USER_ID => $this->form->getValue(Workshop::COL_USER_ID));
                     $table->update($data, Workshop::COL_ID . " = '" . $this->form->getValue(Workshop::COL_ID) . "'");
                     $wsNamespace->unsetAll();
                     $this->redirectTo();
                 } else {
                     $this->form->reset();
                     $this->render('outOfDate');
                 }
             }
         } else {
             if ($this->getRequest()->getParam('setManager') != null) {
                 // new ws manager button clicked
                 $wsNamespace->formValues = $this->getRequest()->getParams();
                 $defaultNamespace = new Zend_Session_Namespace('default');
                 $defaultNamespace->callingAction = 'workshop/edit/update';
                 $defaultNamespace->callingActionId = $request->getParam(Workshop::COL_ID);
                 $this->redirectTo('index', 'search', 'user');
             } else {
                 // new ws manager has choosen and is loading
                 $userTable = new User();
                 $userResult = $userTable->find($this->getRequest()->getParam(Workshop::COL_USER_ID))->current();
                 if ($userResult != null) {
                     $userArray = $userResult->toArray();
                 } else {
                     $userArray = array(Workshop::COL_USER_ID => null, User::COL_USERNAME => 'not valid');
                 }
                 $valueArray = $wsNamespace->formValues;
                 $valueArray[Workshop::COL_USER_ID] = $userArray[Workshop::COL_USER_ID];
                 $valueArray[User::COL_USERNAME] = $userArray[User::COL_USERNAME];
                 $this->form->isValid($valueArray);
                 if ($this->form->getValue('Token') == null) {
                     $guid = new Ble422_guid();
                     $wsNamespace->Token = $guid->__toString();
                     $this->form->getElement('Token')->setValue($guid->__toString());
                 }
             }
         }
     } else {
         // first call load form with default values
         $rowset = $table->find($request->getParam(Workshop::COL_ID))->current();
         if ($rowset != null) {
             $this->form->setValues($rowset->toArray());
         }
         $this->form->setAction(Zend_Controller_Front::getInstance()->getBaseUrl() . "/workshop/edit/update");
         // Get part_id and part_role
         $userTable = new User();
         $userResult = $userTable->find($this->form->getValue(Workshop::COL_USER_ID))->current();
         if ($userResult != null) {
             $userArray = $userResult->toArray();
         } else {
             $userArray = array(Workshop::COL_USER_ID => null, User::COL_USERNAME => 'not valid');
         }
         $this->form->isValidPartial(array(Workshop::COL_USER_ID => $userArray[User::COL_ID], User::COL_USERNAME => $userArray[User::COL_USERNAME]));
         $guid = new Ble422_Guid();
         $wsNamespace->Token = $guid->__toString();
         $this->form->getElement('Token')->setValue($guid->__toString());
     }
 }
コード例 #8
0
ファイル: EditController.php プロジェクト: blackskaarj/webgr
 public function deleterecursiveAction()
 {
     //delete ce
     //delete imageset attributes -> DB on delete cascade
     //delete ce has image -> DB on delete cascade
     //delete ce has attribute desc. -> DB on delete cascade
     //delete participants -> DB on delete cascade
     //delete annotations -> DB on delete cascade
     //delete dots -> DB on delete cascade
     //auskommentiert am 14.10.2009 weil RAW DELETE in der Calibration exercise list
     //nicht immer funktionierte (wenn WS name = training exercise war)
     //stattdessen soll die cdId aus dem Request geholt werden
     //$ceId = $this->callingCeId;
     $ceId = $this->getRequest()->getParam(CalibrationExercise::COL_ID);
     $ce = new CalibrationExercise();
     if ($this->userRole == 'admin' || AuthQuery::getUserId() == Default_SimpleQuery::getWsManagerUserId(Default_SimpleQuery::getWorkshopId($ceId))) {
         $rowset = $ce->find($ceId);
         if (count($rowset) == 1) {
             $ce->delete($ce->getAdapter()->quoteInto(CalibrationExercise::COL_ID . ' = ?', $ceId));
         }
     }
     $Redirect = new Zend_Controller_Action_Helper_Redirector();
     if ($this->defaultNamespace->callingAction == 'ce/search/myce') {
         $Redirect->setGotoSimple('myce', 'search', 'ce');
     } elseif ($this->defaultNamespace->callingAction == 'ce/search/list') {
         $Redirect->setGotoSimple('list', 'search', 'ce');
     }
 }