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); } }
public function updateAction() { $ktTable = new KeyTable(); $this->form->addElement('hidden', KeyTable::COL_ID, array('required' => true)); if ($this->getRequest()->isPost()) { if ($this->form->isValid($this->getRequest()->getParams())) { $upload = $this->form->uploadElement->getTransferAdapter(); $filename = $this->form->uploadElement->getFilename(null, false); $upload->receive(); if ($upload->isReceived($filename)) { $data = array(KeyTable::COL_NAME => $this->form->getValue(KeyTable::COL_NAME), KeyTable::COL_FILENAME => $filename); $ktTable->update($data, $ktTable->getAdapter()->quoteInto(KeyTable::COL_ID . '=?', $this->form->getValue(KeyTable::COL_ID))); } $this->redirectTo('list'); } } else { //not post $keyArray = $ktTable->find($this->getRequest()->getParam(KeyTable::COL_ID))->toArray(); $this->form->populate($keyArray[0]); } $this->view->form = $this->form; $this->render('index'); }