public function searchAction() { $request = $this->getRequest(); $formValues = $this->namespace->formValues; $this->view->callingAction = $this->defaultNamespace->callingAction; // get meta data select for image and fish descriptors $metaData = new Default_MetaData(); $metaData->getSelectForGroups(FALSE); $select = $metaData->addWhereToSelect($formValues); //TODO test with multiple fish / multiple image checked attributes //changed, if images are found, but search was for fish, multiple image attributes would cause multiple entries //TODO error: only first fish without images shown due to this group; if there are many fishes without image, there is only one of them shown in list $select->group('fish.' . Fish::COL_ID); if ($this->defaultNamespace->callingAction == 'annotation/browse/byfish') { $select->joinLeft(array('vaa' => 'v_all_annotations'), 'vaa.' . CeHasImage::COL_IMAGE_ID . ' = ' . 'image.' . Image::COL_ID, array()); //auf cehas_image damit die ausgefiltert werden die keine annotationen haben $select->group('image.' . Image::COL_ID); $resultArray = Zend_Registry::get('DB_CONNECTION1')->fetchAll($select); if ($resultArray != array()) { $resultKey = new Ble422_Guid(); $this->defaultNamespace->{$resultKey} = $resultArray; $redirect = new Zend_Controller_Action_Helper_Redirector(); $redirect->setGotoSimple('start', 'browse', 'annotation', array('resultKey' => $resultKey)); } } else { //select only own fish if ($this->defaultNamespace->callingAction == 'user/edit/myfishes') { $select->where('fish.' . Fish::COL_USER_ID . ' = ?', $this->defaultNamespace->callingActionId); } //new $this->namespace->select = $select; //new /** * Pagination control */ $paginator = new Ble422_Paginator_Extended($select, $this->getRequest()); //static + dynamic header array $statArray = array(array('raw' => Fish::COL_SAMPLE_CODE, 'name' => 'Fish sample code')); $dynArray = array(); $i = 0; foreach ($metaData->fishRowSetArray as $fishAttr) { $dynInnerArray = array('raw' => 'ATDE_' . $fishAttr[AttributeDescriptor::COL_ID], 'name' => $fishAttr[AttributeDescriptor::COL_NAME] . '<br>' . $fishAttr['UNIT']); $dynArray[$i] = $dynInnerArray; $i++; } $headerArray = array_merge($statArray, $dynArray); unset($i); unset($dynArray); unset($dynInnerArray); $paginator->setHeader($headerArray); $paginator->setCurrentPageNumber($this->getRequest()->getParam('page'))->setItemCountPerPage(1000)->setPageRange(10)->orderBy($this->getRequest()->getParam('orderBy')); //$this->_getParam('pageRange')); Zend_View_Helper_PaginationControl::setDefaultViewPartial('partials/list_pagination_control.phtml'); $this->view->paginator = $paginator; $storage = Zend_Auth::getInstance()->getStorage()->read(); $constUserRole = User::COL_ROLE; $this->view->userRole = $storage->{$constUserRole}; } }
public function addimagesatrandomAction() { //$imageNamespace = new Zend_Session_Namespace('image_search'); $this->defaultNamespace->callingAction = '/ce/edit/addimagesatrandom'; $this->defaultNamespace->callingActionId = $this->callingCeId; $attribFormValues = $this->getAttriFormValues(); //-------------------------------------------------------------------------------- //from search/index $this->formImageSearch = new Image_Form_Search(); $this->formImageSearch->removeElement(Image::COL_ID); $this->formImageSearch->removeElement('save'); //$this->formImageSearch->removeElement('kind'); //$this->formImageSearch->addElement('submit', 'submit', array('label'=>'Search' )); //set all elements to required=FALSE //clear all validators $formElements = $this->formImageSearch->getElements(); foreach ($formElements as $elem) { $elem->setRequired(false); $elem->clearValidators(); } //$this->formImageSearch->setElements($formElements); //---------------------------------------------------- if ($this->formImageSearch->isValid($attribFormValues)) { $metaData = new Default_MetaData(); $metaData->getSelectForGroups(TRUE); $select = $metaData->addWhereToSelect($attribFormValues); $resultRowset = Zend_Registry::get('DB_CONNECTION1')->fetchAll($select); //TODO resultRowset is empty $imageIds = array(); foreach ($resultRowset as $rowNo => $row) { $imageIds[] = $row[Image::COL_ID]; } //delete duplicate imageIds from multiple set values $uniqueImageIds = array_unique($imageIds); //---------------------------------------------------- // //substract already assigned datasets $ceId = $this->defaultNamespace->callingActionId; $ceHasIm = new CeHasImage(); $ceHasImSet = $ceHasIm->fetchAll(CeHasImage::COL_CALIBRATION_EXERCISE_ID . '=' . $ceId); if (count($ceHasImSet) > 0) { $possibleImageIds = array(); foreach ($uniqueImageIds as $key => $id) { $alreadyAssigned = false; foreach ($ceHasImSet as $ceHasImRow) { if ($id == $ceHasImRow[CeHasImage::COL_IMAGE_ID]) { $alreadyAssigned = true; } } if (!$alreadyAssigned) { array_push($possibleImageIds, $id); } } } else { //no images assigned $possibleImageIds = $uniqueImageIds; } //---------------------------------------------------- $randomImageIds = Ble422_ArrayHelper::array_pick($possibleImageIds, $this->getRequest()->getParam("noImages")); //insert new images into ce $ceHimTable = new CeHasImage(); foreach ($randomImageIds as $imageId) { $data = array(CeHasImage::COL_CALIBRATION_EXERCISE_ID => $this->callingCeId, CeHasImage::COL_IMAGE_ID => $imageId); $ceHimTable->insert($data); } } $this->redirectTo('index'); }
public function searchAction() { $request = $this->getRequest(); $formValues = $this->namespace->formValues; $this->view->callingAction = $this->defaultNamespace->callingAction; // get meta data select for image and fish descriptors $metaData = new Default_MetaData(); $metaData->getSelectForGroups(TRUE); $select = $metaData->addWhereToSelect($formValues); if ($this->defaultNamespace->callingAction == 'annotation/browse/byimage') { unset($this->namespace->ceArray); $select->joinLeft(array('vaa' => 'v_all_annotations'), 'vaa.' . CeHasImage::COL_IMAGE_ID . ' = ' . 'image.' . Image::COL_ID, array()); //auf cehas_image damit die ausgefiltert werden die keine annotationen haben $select->where(Annotations::COL_WS_REF . "=? ", 1); $select->orWhere(Annotations::COL_FINAL . " = ? ", 1); $select->orWhere(Annotations::COL_GROUP . "=? ", 1); $select->orWhere(Annotations::COL_WEBGR_REF . "=? ", 1); $select->group('image.' . Image::COL_ID); $resultArray = Zend_Registry::get('DB_CONNECTION1')->fetchAll($select); if ($resultArray != array()) { $resultKey = new Ble422_Guid(); $this->defaultNamespace->{$resultKey} = $resultArray; $redirect = new Zend_Controller_Action_Helper_Redirector(); $redirect->setGotoSimple('start', 'browse', 'annotation', array('resultKey' => $resultKey)); } } else { //select only own images if ($this->defaultNamespace->callingAction == 'user/edit/myimages') { $select->where('image.' . Image::COL_USER_ID . ' = ?', $this->defaultNamespace->callingActionId); } //filter double datasets caused by multiple meta data //$select->group('image.'.Image::COL_ID); //get already assigned datasets for setting disabled in view if ($this->defaultNamespace->callingAction == '/ce/edit/addimages') { $ceId = $this->defaultNamespace->callingActionId; $ceHasIm = new CeHasImage(); $rowSet = $ceHasIm->fetchAll(CeHasImage::COL_CALIBRATION_EXERCISE_ID . '=' . $ceId); if (count($rowSet) > 0) { $assignedImages = array(); foreach ($rowSet as $row) { $assignedImages[$row[CeHasImage::COL_IMAGE_ID]] = TRUE; } $this->view->assignedImages = $assignedImages; } } //echo $select; /** * Pagination control */ $paginator = new Ble422_Paginator_Extended($select, $this->getRequest()); // echo $select->__toString(); // die(); //static + dynamic header array $statArray = array(array('raw' => Image::COL_ORIGINAL_FILENAME, 'name' => 'Original file name'), array('raw' => Fish::COL_SAMPLE_CODE, 'name' => 'Fish sample code'), array('raw' => Image::COL_DIM_X, 'name' => 'Width'), array('raw' => Image::COL_DIM_Y, 'name' => 'Height')); $dynArray = array(); $i = 0; foreach ($metaData->fishRowSetArray as $fishAttr) { $dynInnerArray = array('raw' => 'ATDE_' . $fishAttr[AttributeDescriptor::COL_ID], 'name' => $fishAttr[AttributeDescriptor::COL_NAME] . '<br>' . $fishAttr['UNIT']); $dynArray[$i] = $dynInnerArray; $i++; } $headerArray = array_merge($statArray, $dynArray); unset($i); unset($dynArray); unset($dynInnerArray); $i = 0; foreach ($metaData->imageRowSetArray as $imAttr) { $dynInnerArray = array('raw' => 'ATDE_' . $imAttr[AttributeDescriptor::COL_ID], 'name' => $imAttr[AttributeDescriptor::COL_NAME] . '<br>' . $imAttr['UNIT']); $dynArray[$i] = $dynInnerArray; $i++; } $headerArray = array_merge($headerArray, $dynArray); unset($i); unset($dynArray); unset($dynInnerArray); $paginator->setHeader($headerArray); $paginator->setCurrentPageNumber($this->getRequest()->getParam('page'))->setItemCountPerPage(1000)->setPageRange(10)->orderBy($this->getRequest()->getParam('orderBy')); //$this->_getParam('pageRange')); Zend_View_Helper_PaginationControl::setDefaultViewPartial('partials/list_pagination_control.phtml'); $this->view->paginator = $paginator; } }