public function indexAction() { $validator = new Zend_Validate_Int(); $ceId = $this->getRequest()->getParam(CalibrationExercise::COL_ID); $error = false; if ($validator->isValid($ceId)) { $dbadapter = Zend_Registry::get('DB_CONNECTION1'); $select = $dbadapter->select(); if (Default_ReferenceQuery::isParticipantInCe($ceId)) { //set CE id $namespace = new Zend_Session_Namespace('default'); $constCeId = CalibrationExercise::COL_ID; $namespace->{$constCeId} = $ceId; // Get part_id and part_role $auth = Zend_Auth::getInstance(); $storage = $auth->getStorage(); $constUserId = User::COL_ID; $userId = $storage->read()->{$constUserId}; $select->from(Participant::TABLE_NAME); $select->where(Participant::COL_USER_ID . " =?", $userId); $select->where(Participant::COL_CE_ID . " =?", $ceId); $array = $dbadapter->fetchAll($select); $constPartId = Participant::COL_ID; $namespace->{$constPartId} = $array[0][Participant::COL_ID]; $constPartRole = Participant::COL_ROLE; $namespace->{$constPartRole} = $array[0][Participant::COL_ROLE]; //Set CE-info result Object $select->reset(); $select->from(array('caex' => CalibrationExercise::TABLE_NAME)); $select->join(array('exp' => Expertise::TABLE_NAME), 'caex.' . CalibrationExercise::COL_EXPERTISE_ID . "=" . 'exp.' . Expertise::COL_ID, array()); $select->join(array('key' => KeyTable::TABLE_NAME), 'caex.' . CalibrationExercise::COL_KEY_TABLE_ID . "=" . 'key.' . KeyTable::COL_ID); $select->join(array('work' => Workshop::TABLE_NAME), 'caex.' . CalibrationExercise::COL_WORKSHOP_ID . "=" . "work." . Workshop::COL_ID, array(Workshop::COL_NAME)); $select->join(array('vali' => ValueList::TABLE_NAME), 'exp.' . Expertise::COL_SUBJECT . '=vali.' . ValueList::COL_ID, array(Expertise::COL_SUBJECT => ValueList::COL_NAME)); $select->where('caex.' . CalibrationExercise::COL_ID . "=?", $ceId); $ceArray = $dbadapter->fetchAll($select); $namespace->ceArray = $ceArray; $this->view->subject = $ceArray[0][Expertise::COL_SUBJECT]; } else { $error = true; $this->view->message = "Your are not a participant of this CE.<br>" . "Please contact one of the coordinators:<br>"; $select->from(array('caex' => CalibrationExercise::TABLE_NAME)); $select->join(array('part' => Participant::TABLE_NAME), 'caex.' . CalibrationExercise::COL_ID . '=' . 'part.' . Participant::COL_CE_ID); $select->join(array('user' => User::TABLE_NAME), 'part.' . Participant::COL_USER_ID . '=' . 'user.' . User::COL_ID); $select->where('part.' . Participant::COL_CE_ID . '=?', $ceId); $select->where('part.' . Participant::COL_ROLE . '=?', 'Coordinator'); $infoArray = $dbadapter->fetchAll($select); $this->view->error = true; if (count($infoArray) != 0) { $this->view->coordinators = $infoArray; } else { $this->view->message = "The CE doesn't exist.<br>"; $this->view->coordinators = array(); } } } else { throw new Zend_Exception('The CE id was not valid!'); } }
public function showAction() { $this->view->atDeId = $this->atDeId; $this->view->atDeName = Default_SimpleQuery::getAttributeName($this->atDeId); if (Default_ReferenceQuery::hasValueListData($this->atDeId)) { $table = new ValueList(); $select = $table->select(); $select->where(ValueList::COL_ATTRIBUTE_DESCRIPTOR_ID . "= ?", $this->atDeId, 'int'); $rowset = $table->fetchAll($select); $array = $rowset->toArray(); $this->view->list = $array; $this->render('list'); } }
public static function getCommaSeperatedValueList($atDeId) { $list = ''; if (Default_ReferenceQuery::hasValueListData($atDeId)) { $db = Zend_Db_Table_Abstract::getDefaultAdapter(); $select = $db->select(); $select->from(self::TABLE_NAME, self::COL_NAME)->where(ValueList::COL_ATTRIBUTE_DESCRIPTOR_ID . "= ?", $atDeId, 'int'); $listArray = $db->fetchAll($select); if (is_array($listArray)) { foreach ($listArray as $index => $arrayValue) { if ($index == count($listArray) - 1) { $list = $list . $arrayValue[self::COL_NAME]; } else { if ($index != 0 && $index % 5 == 0) { $list = $list . '<br />' . $arrayValue[self::COL_NAME] . ', '; } else { $list = $list . $arrayValue[self::COL_NAME] . ', '; } } } } } return $list; }
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 annotationsAction() { $select = $this->dbAdapter->select(); $select->from(array('anno' => Annotations::TABLE_NAME), array(Annotations::COL_ID, Annotations::COL_DECIMAL, Annotations::COL_GROUP, Annotations::COL_CE_HAS_IMAGE_ID)); $select->join(array('cehim' => CeHasImage::TABLE_NAME), $this->dbAdapter->quoteIdentifier('anno.' . Annotations::COL_CE_HAS_IMAGE_ID) . '=' . $this->dbAdapter->quoteIdentifier('cehim.' . CeHasImage::COL_ID), array()); $select->join(array('part' => Participant::TABLE_NAME), $this->dbAdapter->quoteIdentifier('anno.' . Annotations::COL_PART_ID) . '=' . $this->dbAdapter->quoteIdentifier('part.' . Participant::COL_ID), array(Participant::COL_NUMBER, Participant::COL_ID)); $select->join(array('im' => Image::TABLE_NAME), $this->dbAdapter->quoteIdentifier('cehim.' . CeHasImage::COL_IMAGE_ID) . '=' . $this->dbAdapter->quoteIdentifier('im.' . Image::COL_ID), array(Image::COL_ORIGINAL_FILENAME)); $select->join(array('fish' => Fish::TABLE_NAME), $this->dbAdapter->quoteIdentifier('im.' . Image::COL_FISH_ID) . '=' . $this->dbAdapter->quoteIdentifier('fish.' . Fish::COL_ID), array(Fish::COL_SAMPLE_CODE)); $constCeId = CalibrationExercise::COL_ID; $ceId = $this->getRequest()->getParam($constCeId); $filename = 'annotations_all.csv'; if ($this->getRequest()->getParam('level')) { //with a certain expertise level if ($this->getRequest()->getParam('level') != 'all') { $expertiseLevel = $this->getRequest()->getParam('level'); $select->where('part.' . Participant::COL_EXPERTISE_LEVEL . "=?", ucfirst($expertiseLevel)); $filename = 'annotations_' . $expertiseLevel . '.csv'; } else { $filename = 'annotations_all.csv'; } } if ($this->getRequest()->getParam('stock')) { //only stock assessment $select->where('part.' . Participant::COL_STOCK_ASSESSMENT . "=1"); $filename = 'annotations_stock.csv'; } $select->where('cehim.' . CeHasImage::COL_CALIBRATION_EXERCISE_ID . "=?", $ceId); $select->where('(anno.' . Annotations::COL_FINAL . "=?", 1); $select->orWhere('anno.' . Annotations::COL_GROUP . "=?)", 1); $select->order('fish.' . Fish::COL_ID); // echo $select; $annoArray = $this->dbAdapter->fetchAll($select); //get the readers $partArray = $this->getParticipantList($ceId); $this->view->ceId = $ceId; $this->view->myRequest = $this->getRequest(); if (empty($partArray)) { $this->view->noPart = TRUE; $this->render('annotations'); return; } $partCount = count($partArray); //add the group reader array_push($partArray, array(User::COL_FIRSTNAME => '', User::COL_LASTNAME => '', Participant::COL_NUMBER => 'Group', Participant::COL_ID => 0, 'Institution' => '')); //add the APE column array_push($partArray, array(User::COL_FIRSTNAME => '', User::COL_LASTNAME => '', Participant::COL_NUMBER => 'APE', Participant::COL_ID => -1, 'Institution' => '')); //add the CV column array_push($partArray, array(User::COL_FIRSTNAME => '', User::COL_LASTNAME => '', Participant::COL_NUMBER => 'CV', Participant::COL_ID => -2, 'Institution' => '')); //add the STDDEV column array_push($partArray, array(User::COL_FIRSTNAME => '', User::COL_LASTNAME => '', Participant::COL_NUMBER => 'STDDEV', Participant::COL_ID => -3, 'Institution' => '')); //add the VARIANCE column array_push($partArray, array(User::COL_FIRSTNAME => '', User::COL_LASTNAME => '', Participant::COL_NUMBER => 'VARIANCE', Participant::COL_ID => -4, 'Institution' => '')); $fishSelect = $this->dbAdapter->select(); $fishSelect->from(array('im' => Image::TABLE_NAME)); $fishSelect->join(array('fish' => Fish::TABLE_NAME), $this->dbAdapter->quoteIdentifier('fish.' . Fish::COL_ID) . '=' . $this->dbAdapter->quoteIdentifier('im.' . Image::COL_FISH_ID), array()); $fishSelect->join(array('cehim' => CeHasImage::TABLE_NAME), $this->dbAdapter->quoteIdentifier('im.' . Image::COL_ID) . '=' . $this->dbAdapter->quoteIdentifier('cehim.' . CeHasImage::COL_IMAGE_ID), array()); $fishSelect->where(CeHasImage::COL_CALIBRATION_EXERCISE_ID . "=?", $ceId); //echo '<br>'.$fishSelect; //set the imagelist $imageSelect = $this->dbAdapter->select(); $imageSelect->from(array('im' => Image::TABLE_NAME)); $imageSelect->join(array('fish' => Fish::TABLE_NAME), $this->dbAdapter->quoteIdentifier('fish.' . Fish::COL_ID) . '=' . $this->dbAdapter->quoteIdentifier('im.' . Image::COL_FISH_ID), array()); $imageSelect->join(array('cehim' => CeHasImage::TABLE_NAME), $this->dbAdapter->quoteIdentifier('im.' . Image::COL_ID) . '=' . $this->dbAdapter->quoteIdentifier('cehim.' . CeHasImage::COL_IMAGE_ID), array()); $imageSelect->where(CeHasImage::COL_CALIBRATION_EXERCISE_ID . "=?", $ceId); //echo '<br>'.$imageSelect; $imageArray = $this->dbAdapter->fetchAll($imageSelect); //prepare an array that looks like the csv-file $csvArray = array(); //prepare array header $csvArray['IMAGE'] = $partArray; foreach ($partArray as $part) { if (array_key_exists(Participant::COL_EXPERTISE_LEVEL, $part)) { if (isset($part[Participant::COL_EXPERTISE_LEVEL])) { $csvArray['Expertise level'][$part[Participant::COL_NUMBER]] = $part[Participant::COL_EXPERTISE_LEVEL]; } else { $csvArray['Expertise level'][$part[Participant::COL_NUMBER]] = '-'; } } else { $csvArray['Expertise level'][$part[Participant::COL_NUMBER]] = '-'; } if (array_key_exists(Participant::COL_EXPERTISE_LEVEL, $part)) { if ($part[Participant::COL_STOCK_ASSESSMENT] == 1) { $csvArray['Stock assessment'][$part[Participant::COL_NUMBER]] = 'yes'; } elseif ($part[Participant::COL_STOCK_ASSESSMENT] == 0) { $csvArray['Stock assessment'][$part[Participant::COL_NUMBER]] = 'no'; } else { $csvArray['Stock assessment'][$part[Participant::COL_NUMBER]] = '-'; } } else { $csvArray['Stock assessment'][$part[Participant::COL_NUMBER]] = '-'; } } foreach ($annoArray as $annoValue) { $csvArray[$annoValue[Annotations::COL_CE_HAS_IMAGE_ID]] = array(); foreach ($partArray as $partValue) { $csvArray[$annoValue[Annotations::COL_CE_HAS_IMAGE_ID]] += array($partValue[Participant::COL_ID] => "-"); } } // calculate the ape, cv etc. $selectStat = $this->dbAdapter->select(); $selectStat->from(array('anno' => Annotations::TABLE_NAME), array('SUM_ANNO' => 'sum(' . Annotations::COL_DECIMAL . ')', 'COUNT_ANNO' => 'count(' . Annotations::COL_DECIMAL . ')', 'COUNT_IMAGE' => 'count(distinct im.IMAGE_ORIGINAL_FILENAME)', 'APE' => new Zend_Db_Expr('((1/count(ANNO_DECIMAL)) * (abs(ANNO_DECIMAL - (avg(ANNO_DECIMAL)))/avg(ANNO_DECIMAL)))/count(distinct im.IMAGE_ORIGINAL_FILENAME)*100'), 'CV' => new Zend_Db_Expr('(stddev(ANNO_DECIMAL)/avg(ANNO_DECIMAL))/count(distinct im.IMAGE_ORIGINAL_FILENAME)*100'), 'STDDEV' => new Zend_Db_Expr('stddev(ANNO_DECIMAL)'), 'VARIANCE' => new Zend_Db_Expr('variance(ANNO_DECIMAL)'))); $selectStat->join(array('cehim' => CeHasImage::TABLE_NAME), $this->dbAdapter->quoteIdentifier('anno.' . Annotations::COL_CE_HAS_IMAGE_ID) . '=' . $this->dbAdapter->quoteIdentifier('cehim.' . CeHasImage::COL_ID), array()); $selectStat->join(array('part' => Participant::TABLE_NAME), $this->dbAdapter->quoteIdentifier('anno.' . Annotations::COL_PART_ID) . '=' . $this->dbAdapter->quoteIdentifier('part.' . Participant::COL_ID), array()); //get filename for displaying and imageID in case further actions $selectStat->join(array('im' => Image::TABLE_NAME), $this->dbAdapter->quoteIdentifier('cehim.' . CeHasImage::COL_IMAGE_ID) . '=' . $this->dbAdapter->quoteIdentifier('im.' . Image::COL_ID), array(Image::COL_ORIGINAL_FILENAME, Image::COL_ID)); $selectStat->join(array('fish' => Fish::TABLE_NAME), $this->dbAdapter->quoteIdentifier('im.' . Image::COL_FISH_ID) . '=' . $this->dbAdapter->quoteIdentifier('fish.' . Fish::COL_ID), array(Fish::COL_SAMPLE_CODE)); //XXX statistischen Werte auf Fisch gruppiert $selectStat->group(Fish::COL_SAMPLE_CODE); //$selectStat->group('im.' . Image::COL_ORIGINAL_FILENAME); $selectStat->where('cehim.' . CeHasImage::COL_CALIBRATION_EXERCISE_ID . "=?", $ceId); $selectStat->where('(anno.' . Annotations::COL_FINAL . "=?", 1); $selectStat->orWhere('anno.' . Annotations::COL_GROUP . "=?)", 1); if ($this->getRequest()->getParam('level')) { //with a certain expertise level if ($this->getRequest()->getParam('level') != 'all') { $expertiseLevel = $this->getRequest()->getParam('level'); $selectStat->where('part.' . Participant::COL_EXPERTISE_LEVEL . "=?", ucfirst($expertiseLevel)); } } if ($this->getRequest()->getParam('stock')) { //only stock assessment $selectStat->where('part.' . Participant::COL_STOCK_ASSESSMENT . "=1"); } //echo $selectStat; $statArray = $this->dbAdapter->fetchAll($selectStat); $fishStatArray = array(); foreach ($statArray as $stat) { $fishStatArray = $fishStatArray + array($stat[Fish::COL_SAMPLE_CODE] => array('APE' => $stat['APE'], 'CV' => $stat['CV'], 'STDDEV' => $stat['STDDEV'], 'VARIANCE' => $stat['VARIANCE'])); } // and fill in the results foreach ($annoArray as $annoValue) { if ($annoValue[Annotations::COL_GROUP] == '0') { //reader final value $csvArray[$annoValue[Annotations::COL_CE_HAS_IMAGE_ID]][$annoValue[Annotations::COL_PART_ID]] = (double) $annoValue[Annotations::COL_DECIMAL]; //$annotationsCount++; } else { //group value $csvArray[$annoValue[Annotations::COL_CE_HAS_IMAGE_ID]][0] = $annoValue[Annotations::COL_DECIMAL]; //$annotationsCount++; } $csvArray[$annoValue[Annotations::COL_CE_HAS_IMAGE_ID]][-1] = number_format($fishStatArray[$annoValue[Fish::COL_SAMPLE_CODE]]['APE'], 4, ',', ''); $csvArray[$annoValue[Annotations::COL_CE_HAS_IMAGE_ID]][-2] = number_format($fishStatArray[$annoValue[Fish::COL_SAMPLE_CODE]]['CV'], 4, ',', ''); $csvArray[$annoValue[Annotations::COL_CE_HAS_IMAGE_ID]][-3] = number_format($fishStatArray[$annoValue[Fish::COL_SAMPLE_CODE]]['STDDEV'], 4, ',', ''); $csvArray[$annoValue[Annotations::COL_CE_HAS_IMAGE_ID]][-4] = number_format($fishStatArray[$annoValue[Fish::COL_SAMPLE_CODE]]['VARIANCE'], 4, ',', ''); } //--------------------------------------------------------------------------- //get statistics per participant foreach ($partArray as $part) { $currentPartId = $part[Participant::COL_ID]; //leave out part_id <= 0, this are statistics if ($currentPartId > 0) { $sumDistMean = 0.0; $sumDistGroup = 0.0; $numberDistMean = 0; $numberDistGroup = 0; //iterate the final annos from the select foreach ($annoArray as $annoValue1) { $currentAnnoId = $annoValue1[Annotations::COL_ID]; $currentValue = NULL; $distGroup = NULL; $currentGroup = NULL; $ceHasImageId = NULL; if ($annoValue1[Annotations::COL_GROUP] == 0 && $annoValue1[Annotations::COL_PART_ID] == $currentPartId) { //annos of distinct participant $currentValue = (double) $annoValue1[Annotations::COL_DECIMAL]; //get current image foreach ($annoArray as $annoValue2) { if ($annoValue2[Annotations::COL_ID] == $currentAnnoId) { $ceHasImageId = $annoValue2[Annotations::COL_CE_HAS_IMAGE_ID]; break; } } //get group value for image in CE foreach ($annoArray as $annoValue2) { if ($annoValue2[Annotations::COL_CE_HAS_IMAGE_ID] == $ceHasImageId && $annoValue2[Annotations::COL_GROUP] == 1) { $currentGroup = (double) $annoValue2[Annotations::COL_DECIMAL]; break; } } //get readers mean for image in CE $sumValues = 0.0; $numberImageAnnotations = 0; foreach ($annoArray as $annoValue2) { $value = NULL; if ($annoValue2[Annotations::COL_CE_HAS_IMAGE_ID] == $ceHasImageId && $annoValue2[Annotations::COL_GROUP] == 0) { $value = (double) $annoValue2[Annotations::COL_DECIMAL]; $sumValues += $value; $numberImageAnnotations++; } } $mean = NULL; if ($sumValues > 0) { $mean = $sumValues / $numberImageAnnotations; } //distance of annotation to group value if (isset($currentGroup) && isset($currentValue)) { $distGroup = abs($currentValue - $currentGroup); $sumDistGroup += $distGroup; $numberDistGroup++; } else { $groupNotAvail = TRUE; $distGroup = NULL; } //distance of annotation to mean value for this image in CE if (isset($mean) && isset($currentValue)) { $distMean = abs($currentValue - $mean); $numberDistMean++; } else { $meanNotAvail = TRUE; $distMean = NULL; } $sumDistMean += $distMean; //distinct annotation of reader x } //all annos incl. group } //all participants if ($numberDistMean > 0) { $meanDistMean = $sumDistMean / $numberDistMean; $statPart[$part[Participant::COL_NUMBER]]['meanDistMean'] = number_format($meanDistMean, 4, ',', ''); } else { $statPart[$part[Participant::COL_NUMBER]]['meanDistMean'] = NULL; } if ($numberDistGroup > 0) { $meanDistGroup = $sumDistGroup / $numberDistGroup; $statPart[$part[Participant::COL_NUMBER]]['meanDistGroup'] = number_format($meanDistGroup, 4, ',', ''); } else { $statPart[$part[Participant::COL_NUMBER]]['meanDistGroup'] = NULL; } } //all "participants" incl. statistic cols } //--------------------------------------------------------------------------- foreach ($statPart as $partNo => $part) { $csvArray['Mean of distances to mean'][$partNo] = $part['meanDistMean']; $csvArray['Mean of distances to group'][$partNo] = $part['meanDistGroup']; } for ($i = 0; $i > -5; $i--) { $csvArray['Mean of distances to mean'][$i] = '-'; $csvArray['Mean of distances to group'][$i] = '-'; } $qu = new Default_ReferenceQuery(); $images = $qu->getImagesForCe($ceId); $ceHimFilenameArray = $qu->getCeHasImageFilenameArray($images); if ($this->getRequest()->getParam('as') == 'csv') { // prepare the header $csvString = 'IMAGE'; foreach ($partArray as $partValue) { $csvString .= ',' . $partValue[Participant::COL_NUMBER]; } $csvString .= "\n"; // fill in the results foreach ($csvArray as $imageId => $results) { if ($imageId != 'IMAGE') { if (is_numeric($imageId)) { $imageName = $ceHimFilenameArray[$imageId]; } else { $imageName = $imageId; } $csvString .= $imageName; foreach ($results as $decimal) { $csvString .= "," . "\"" . $decimal . "\""; } $csvString .= "\n"; } } $this->view->csvString = $csvString; $this->view->filename = $filename; // generate the download file Zend_Layout::resetMvcInstance(); $this->render('csvstring'); } else { $this->view->csvArray = $csvArray; $this->view->ceHimFilenameArray = $ceHimFilenameArray; $this->view->ceId = $ceId; } }
/** * * @param $key the subdirectory for csv and image files * @return unknown_type importImages/importFishes arrays with the IDs as key to see where dataimport eventually went wrong */ public function beginImport($key) { $this->key = $key; $this->logger = new Ble422_ArrayLogger(self::RELATIVE_PATH_IMPORT_LOGS . $this->key . '_import_log.txt'); $this->loadFromNamespace(); // foreach ($this->rowHasUniqueUploadedFile as $key => $value) { $preparedDatasets[$key] = $this->preparedDatasets[$key]; } // $importedFishes = array(); $importedImages = array(); $i = 0; $j = 0; $fishForm = new Fish_Form_Edit(); $fish = new Fish(); $imageForm = new Image_Form_Edit(); $image = new Image(); $numberCopiedFiles = 0; $dbAdapter = $fish->getAdapter(); $dbAdapter->beginTransaction(); try { //changed to local preparedDatasets to filter datasets with uploaded files used in other datasets of import foreach ($preparedDatasets as $rowNo => $dataset) { if (Default_SimpleQuery::isValueInTableColumn($dataset['fishFormDataset'][Fish::COL_SAMPLE_CODE], $fish, Fish::COL_SAMPLE_CODE, 'string')) { //get id from already existing fish dataset and go on if ($values = Default_SimpleQuery::getValuesFromTableColumnWhere($fish, Fish::COL_ID, Fish::COL_SAMPLE_CODE, $dataset['fishFormDataset'][Fish::COL_SAMPLE_CODE], 'string')) { //test for amount of values, must be 1 if (count($values) == 1) { $fishId = $values[0]; } else { throw new Zend_Exception('Error: more/less than 1 id found for fish sample code'); } } } else { //create new fish dataset $fishBaseData = array(Fish::COL_SAMPLE_CODE => $dataset['fishFormDataset'][Fish::COL_SAMPLE_CODE], Fish::COL_USER_ID => $this->userId); $fishMetaData = $dataset['fishFormDataset']; //unset($fishMetaData[Fish::COL_SAMPLE_CODE]); $fishForm->populate($fishMetaData); //insert fish $fishId = $fish->insert($fishBaseData); //now update fish with fish meta data $fish->updateFishAndMetadata($fishForm, $fishId, $fishBaseData); $importedFishes[$i][Fish::COL_ID] = $fishId; $importedFishes[$i]['sourceCsvRow'] = $rowNo; $i++; } // check wether a image shall be imported ------------------------ $qu = new Default_ReferenceQuery(); $filenames = $qu->getImageNames($dataset['fishFormDataset'][Fish::COL_SAMPLE_CODE]); //case non-sensitive foreach ($filenames as &$file) { $file = strtolower($file); } $importImageFile = false; if (!empty($filenames)) { //case non-sensitive if (in_array(strtolower($dataset['imageFormDataset'][Image::COL_ORIGINAL_FILENAME]), $filenames) != FALSE) { // Image is already in database $importImageFile = false; } else { $importImageFile = true; } } else { $importImageFile = true; } // end check ------------------------------------------------------ // import the images if ($importImageFile) { //copy file to new path and rename $completeSource = self::RELATIVE_PATH_UPLOAD_CACHE . $this->key . '/' . $dataset['imageFormDataset'][Image::COL_ORIGINAL_FILENAME]; $creator_guid = new Ble422_Guid(); $guid = $creator_guid->__toString(); $path_parts = pathinfo($completeSource); $originalFileName = $path_parts['basename']; //used later to create Image dataset $newFileNameWithGuid = $guid . '.' . strtolower($path_parts['extension']); //save extension in lower-case, needed for further processing in flex //relative path with new filename, prefix dot&slash required $completeDestination = './' . Image::RELATIVE_UPLOAD_PATH . '/' . $newFileNameWithGuid; if (!copy($completeSource, $completeDestination)) { throw new Zend_Exception("Error: copy fails, source: {$fileName}, destination: {$completeDestination}"); } $ratio = $dataset['imageFormDataset'][Image::COL_RATIO_EXTERNAL]; $this->logger->log(array('received original file' => $completeSource)); $this->logger->log(array('copied uploaded file' => $completeDestination)); $numberCopiedFiles++; //TODO write protect files //create other image files $tn_ratio = $image->processImage($completeDestination); //case sensibility: original file name is saved like spelled in CSV file $imageId = $image->insertImageDataset($completeDestination, $originalFileName, $fishId, $guid, $this->userId, $ratio, $tn_ratio); //create image base and meta datasets $imageMetaData = $dataset['imageFormDataset']; $imageForm->populate($imageMetaData); //$imageId = $image->insert($imageBaseData); $image->updateImageAndMetadata($imageForm, $imageId); $importedImages[$j]['sourceCsvRow'] = $rowNo; $importedImages[$j][Image::COL_ID] = $imageId; $importedImages[$j][Image::COL_FISH_ID] = $fishId; $importedImages[$j][Image::COL_ORIGINAL_FILENAME] = $originalFileName; $importedImages[$j]['completeDestination'] = $completeDestination; $relativePathAndFileNameWorkingCopy = './' . Image::RELATIVE_PATH_IMAGE_SHRINKED_WORKING_COPIES . '/' . $guid . '.jpg'; $relativePathAndFileNameThumbnail = './' . Image::RELATIVE_PATH_IMAGE_THUMBNAILS . '/' . $guid . '.jpg'; $importedImages[$j]['completeWorkingCopy'] = $relativePathAndFileNameWorkingCopy; $importedImages[$j]['completeThumbnail'] = $relativePathAndFileNameThumbnail; $j++; } } $dbAdapter->commit(); $this->logger->log(array('datasets committed, number of copied files into system' => $numberCopiedFiles)); $returnCode = 'success'; //delete upload cache dir Ble422_FileHelper::delete_directory(self::RELATIVE_PATH_UPLOAD_CACHE . $this->key); } catch (Exception $e) { $returnCode = 'error'; $dbAdapter->rollBack(); //delete copied/created files, else there will be orphaned files foreach ($importedImages as $image) { unlink($image['completeDestination']); unlink($image['completeWorkingCopy']); unlink($image['completeThumbnail']); } $this->logger->log(array('Error exception' => $e->getMessage()), 'ERROR, roll back of imported datasets and unsetting of files, see below'); $this->logger->log(array('Roll back of importedFishes' => $importedFishes)); $this->logger->log(array('Roll back of importedImages' => $importedImages)); //delete upload cache dir Ble422_FileHelper::delete_directory(self::RELATIVE_PATH_UPLOAD_CACHE . $this->key); echo $e->getMessage(); } $returnArray = array('returnCode' => $returnCode, 'importFishes' => $importedFishes, 'importImages' => $importedImages, 'numberCopiedFiles' => $numberCopiedFiles); $this->logger->log(array('data import' => $returnArray)); return $returnArray; }
public function mydeleterecursiveAction() { //at the moment only used for training CEs //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 $ceId = $this->getRequest()->getParam(CalibrationExercise::COL_ID); $ce = new CalibrationExercise(); $rowset = $ce->find($ceId); if (count($rowset) == 1) { $qu = new Default_ReferenceQuery(); if ($qu->isParticipantInTrainingCe($ceId)) { $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'); } }