Exemplo n.º 1
0
 public function getMyAnnotationsByCeHim($ceHim = 0, $state = null, $imageId = 0)
 {
     $annotationTable = new Annotations();
     $dbAdapter = $annotationTable->getAdapter();
     $select = $dbAdapter->select();
     $select->from(array('annos' => Annotations::TABLE_NAME));
     $fetch = true;
     if ($state == null) {
         $select->where(Annotations::COL_CE_HAS_IMAGE_ID . "=?", $ceHim, 'int') . $select->where(Annotations::COL_PART_ID . "=?", $this->getParticipantId(), 'int');
         $select->where(Annotations::COL_GROUP . "!=?", 1, 'int');
         $select->where(Annotations::COL_WS_REF . "!=?", 1, 'int');
         $select->where(Annotations::COL_WEBGR_REF . "!=?", 1, 'int');
     } else {
         if ($state == 'groupState') {
             $select->where(Annotations::COL_CE_HAS_IMAGE_ID . "=?", $ceHim, 'int');
             $select->where(Annotations::COL_GROUP . "=?", 1, 'int');
         } else {
             if ($state == 'ws-refState') {
                 // check for user roles
                 $storage = Zend_Auth::getInstance()->getStorage()->read();
                 $roleConst = User::COL_ROLE;
                 if ($storage->{$roleConst} == 'admin' || $storage->{$roleConst} == 'manager' || $this->getParticipantRole() == 'Coordinator') {
                     $ceTable = new CalibrationExercise();
                     $ceArray = $ceTable->find($this->getCurrentCeID())->toArray();
                     $select->join(array('ceHim' => CeHasImage::TABLE_NAME), 'annos.' . Annotations::COL_CE_HAS_IMAGE_ID . "=" . 'ceHim.' . CeHasImage::COL_ID);
                     $select->join(array('caex' => CalibrationExercise::TABLE_NAME), 'ceHim.' . CeHasImage::COL_CALIBRATION_EXERCISE_ID . "=" . 'caex.' . CalibrationExercise::COL_ID);
                     $select->join(array('im' => Image::TABLE_NAME), 'ceHim.' . CeHasImage::COL_IMAGE_ID . "=" . 'im.' . Image::COL_ID);
                     $select->where(CalibrationExercise::COL_EXPERTISE_ID . "=?", $this->namespace->ceArray[0][CalibrationExercise::COL_EXPERTISE_ID]);
                     $select->where(CalibrationExercise::COL_KEY_TABLE_ID . "=?", $this->namespace->ceArray[0][CalibrationExercise::COL_KEY_TABLE_ID]);
                     $select->where('im.' . Image::COL_ID . "=?", $imageId, 'int');
                     $select->where('caex.' . CalibrationExercise::COL_WORKSHOP_ID . "=?", $ceArray[0][CalibrationExercise::COL_WORKSHOP_ID], 'int');
                     $select->where(Annotations::COL_WS_REF . "=?", 1, 'int');
                 } else {
                     $fetch = false;
                 }
             } else {
                 if ($state == 'webgr-refState') {
                     // check for user roles
                     $storage = Zend_Auth::getInstance()->getStorage()->read();
                     $roleConst = User::COL_ROLE;
                     if ($storage->{$roleConst} == 'admin' || $storage->{$roleConst} == 'manager' || $this->getParticipantRole() == 'Coordinator') {
                         $select->join(array('ceHim' => CeHasImage::TABLE_NAME), 'annos.' . Annotations::COL_CE_HAS_IMAGE_ID . "=" . 'ceHim.' . CeHasImage::COL_ID);
                         $select->join(array('caex' => CalibrationExercise::TABLE_NAME), 'ceHim.' . CeHasImage::COL_CALIBRATION_EXERCISE_ID . "=" . 'caex.' . CalibrationExercise::COL_ID);
                         $select->join(array('im' => Image::TABLE_NAME), 'ceHim.' . CeHasImage::COL_IMAGE_ID . "=" . 'im.' . Image::COL_ID);
                         $select->where(CalibrationExercise::COL_EXPERTISE_ID . "=?", $this->namespace->ceArray[0][CalibrationExercise::COL_EXPERTISE_ID]);
                         $select->where(CalibrationExercise::COL_KEY_TABLE_ID . "=?", $this->namespace->ceArray[0][CalibrationExercise::COL_KEY_TABLE_ID]);
                         $select->where('im.' . Image::COL_ID . "=?", $imageId, 'int');
                         $select->where(Annotations::COL_WEBGR_REF . "=?", 1, 'int');
                     } else {
                         $fetch = false;
                     }
                 }
             }
         }
     }
     //return $select->__toString();
     if ($fetch) {
         return $dbAdapter->fetchAll($select);
     } else {
         return array();
     }
 }