Ejemplo n.º 1
0
 /** testGetSetValue */
 public function testGetSetValue()
 {
     Zend_Registry::set('modulesEnable', $this->enabledModules);
     Zend_Registry::set('notifier', new MIDAS_Notifier(false, null));
     /** @var Validation_ScalarResultModel $scalarResultModel */
     $scalarResultModel = MidasLoader::loadModel('ScalarResult', 'validation');
     $daos = $scalarResultModel->getAll();
     $sr = $daos[0];
     $folder = new FolderDao();
     $folder->setName('result');
     $folder->setDescription('result');
     $folder->setParentId(-1);
     $this->Folder->save($folder);
     $trainingItem = new ItemDao();
     $trainingItem->setName('img00.mha');
     $trainingItem->setDescription('training img 00');
     $trainingItem->setType(0);
     $this->Item->save($trainingItem);
     $scalarResultModel->setFolder($sr, $folder);
     $scalarResultModel->setItem($sr, $trainingItem);
     $sr->setValue(90.009);
     $scalarResultModel->save($sr);
     $daos = $scalarResultModel->getAll();
     $sr = $daos[0];
     $this->assertEquals(90.009, $sr->getValue());
 }
Ejemplo n.º 2
0
 /**
  * Return a community given its root folder.
  *
  * @param FolderDao $folder
  * @return false|CommunityDao
  * @throws Zend_Exception
  */
 public function getByFolder($folder)
 {
     if (!$folder instanceof FolderDao) {
         throw new Zend_Exception('Should be a folder');
     }
     $row = $this->database->fetchRow($this->database->select()->setIntegrityCheck(false)->from('community')->where('folder_id=?', $folder->getFolderId()));
     $community = $this->initDao('Community', $row);
     return $community;
 }
Ejemplo n.º 3
0
 /**
  * Copy the permissions from the given folder to all child folders and items. Do not pass a results
  * parameter, that is for the recursive counting.
  *
  * @param FolderDao $folder folder DAO
  * @param UserDao $user user DAO
  * @param null|ProgressDao $progress progress DAO
  * @param array $results
  * @return array array('success' => number of resources whose policies were successfully changed,
  *                     'failure' => number of resources failed to change due to invalid permissions
  */
 public function applyPoliciesRecursive($folder, $user, $progress = null, $results = array('success' => 0, 'failure' => 0))
 {
     foreach ($folder->getFolders() as $subfolder) {
         if ($progress) {
             $current = $progress->getCurrent() + 1;
             $message = 'Set policies on ' . $current . ' of ' . $progress->getMaximum() . ' resources';
             $this->Progress->updateProgress($progress, $current, $message);
         }
         if (!$this->Folder->policyCheck($subfolder, $user, MIDAS_POLICY_ADMIN)) {
             ++$results['failure'];
             continue;
         }
         // delete all existing policies on the subfolder
         foreach ($subfolder->getFolderpolicygroup() as $folderPolicyGroup) {
             $this->Folderpolicygroup->delete($folderPolicyGroup);
         }
         foreach ($subfolder->getFolderpolicyuser() as $folderPolicyUser) {
             $this->Folderpolicyuser->delete($folderPolicyUser);
         }
         // copy down policies from parent folder
         foreach ($folder->getFolderpolicygroup() as $folderPolicyGroup) {
             $this->Folderpolicygroup->createPolicy($folderPolicyGroup->getGroup(), $subfolder, $folderPolicyGroup->getPolicy());
         }
         foreach ($folder->getFolderpolicyuser() as $folderPolicyUser) {
             $this->Folderpolicyuser->createPolicy($folderPolicyUser->getUser(), $subfolder, $folderPolicyUser->getPolicy());
         }
         ++$results['success'];
         $results = $this->applyPoliciesRecursive($subfolder, $user, $progress, $results);
     }
     foreach ($folder->getItems() as $item) {
         if ($progress) {
             $current = $progress->getCurrent() + 1;
             $message = 'Set policies on ' . $current . ' of ' . $progress->getMaximum() . ' resources';
             $this->Progress->updateProgress($progress, $current, $message);
         }
         if (!$this->Item->policyCheck($item, $user, MIDAS_POLICY_ADMIN)) {
             ++$results['failure'];
             continue;
         }
         // delete all existing policies on the item
         foreach ($item->getItempolicygroup() as $itemPolicyGroup) {
             $this->Itempolicygroup->delete($itemPolicyGroup);
         }
         foreach ($item->getItempolicyuser() as $itemPolicyUser) {
             $this->Itempolicyuser->delete($itemPolicyUser);
         }
         // copy down policies from parent folder
         foreach ($folder->getFolderpolicygroup() as $folderPolicyGroup) {
             $this->Itempolicygroup->createPolicy($folderPolicyGroup->getGroup(), $item, $folderPolicyGroup->getPolicy());
         }
         foreach ($folder->getFolderpolicyuser() as $folderPolicyUser) {
             $this->Itempolicyuser->createPolicy($folderPolicyUser->getUser(), $item, $folderPolicyUser->getPolicy());
         }
         ++$results['success'];
     }
     return $results;
 }
Ejemplo n.º 4
0
 /**
  * Get policy.
  *
  * @param UserDao $user
  * @param FolderDao $folder
  * @return false|FolderpolicyuserDao
  * @throws Zend_Exception
  */
 public function getPolicy($user, $folder)
 {
     if (!$user instanceof UserDao) {
         throw new Zend_Exception('Should be a user.');
     }
     if (!$folder instanceof FolderDao) {
         throw new Zend_Exception('Should be a folder.');
     }
     return $this->initDao('Folderpolicyuser', $this->database->fetchRow($this->database->select()->where('folder_id = ?', $folder->getKey())->where('user_id = ?', $user->getKey())));
 }
Ejemplo n.º 5
0
 /**
  * Get policy.
  *
  * @param GroupDao $group
  * @param FolderDao $folder
  * @return false|FolderpolicygroupDao
  * @throws Zend_Exception
  */
 public function getPolicy($group, $folder)
 {
     if (!$group instanceof GroupDao) {
         throw new Zend_Exception('Should be a group.');
     }
     if (!$folder instanceof FolderDao) {
         throw new Zend_Exception('Should be a folder.');
     }
     return $this->initDao('Folderpolicygroup', $this->database->fetchRow($this->database->select()->where('folder_id = ?', $folder->getKey())->where('group_id = ?', $group->getKey())));
 }
Ejemplo n.º 6
0
 /**
  * Set the folder of the scalar result.
  *
  * @param Validation_ScalarResultDao $scalarResult target scalar result
  * @param FolderDao $folder target folder
  * @throws Zend_Exception
  */
 public function setFolder($scalarResult, $folder)
 {
     if (!$scalarResult instanceof Validation_ScalarResultDao) {
         throw new Zend_Exception('Should be a scalar result.');
     }
     if (!$folder instanceof FolderDao) {
         throw new Zend_Exception('Should be a folder.');
     }
     $scalarResult->setFolderId($folder->getKey());
     parent::save($scalarResult);
 }
Ejemplo n.º 7
0
 /**
  * called from ajax.
  */
 public function importAction()
 {
     $this->requireAdminPrivileges();
     // This is necessary in order to avoid session lock and being able to run two
     // ajax requests simultaneously
     session_write_close();
     $this->nfilesprocessed = 0;
     $this->disableLayout();
     $this->disableView();
     $this->assetstores = $this->Assetstore->getAll();
     $form = $this->Form->Import->createImportForm($this->assetstores);
     if ($this->getRequest()->isPost() && !$form->isValid($_POST)) {
         echo json_encode(array('error' => $this->t('The form is invalid. Missing values.')));
         return false;
     }
     // If we just validate the form we return
     if ($this->getRequest()->getPost('validate')) {
         echo json_encode(array('stage' => 'validate'));
         return false;
     } elseif ($this->getRequest()->getPost('initialize')) {
         // Count the total number of files in the directory and return it
         $this->ntotalfiles = $this->_recursiveCountFiles($form->inputdirectory->getValue());
         echo json_encode(array('stage' => 'initialize', 'totalfiles' => $this->ntotalfiles));
         return false;
     } elseif ($this->getRequest()->isPost() && $form->isValid($_POST)) {
         $this->ntotalfiles = $this->getRequest()->getPost('totalfiles');
         // Parse the directory
         $pathName = $form->inputdirectory->getValue();
         $currentdirid = $form->importFolder->getValue();
         // we just start with te initial dir
         $currentdir = new FolderDao();
         $currentdir->setFolderId($currentdirid);
         // Set the file locations used to handle the async requests
         $this->progressfile = $this->getTempDirectory() . '/importprogress_' . $form->uploadid->getValue();
         $this->stopfile = $this->getTempDirectory() . '/importstop_' . $form->uploadid->getValue();
         $this->assetstoreid = $form->assetstore->getValue();
         $this->importemptydirectories = $form->importemptydirectories->getValue();
         try {
             if ($this->_recursiveParseDirectory($pathName, $currentdir)) {
                 echo json_encode(array('message' => $this->t('Import successful.')));
             } else {
                 echo json_encode(array('error' => $this->t('Problem occured while importing. ' . 'Check the log files or contact an ' . 'administrator.')));
             }
         } catch (Exception $e) {
             echo json_encode(array('error' => $this->t($e->getMessage())));
         }
         // Remove the temp and stop files
         UtilityComponent::safedelete($this->progressfile);
         UtilityComponent::safedelete($this->stopfile);
         return true;
     }
     echo json_encode(array('error' => $this->t('The request should be a post.')));
     return false;
 }
Ejemplo n.º 8
0
 /**
  * Get a single set of scores for a dashboard.
  *
  * @param Validation_DashboardDao $dashboard target dashboard
  * @param FolderDao $folder folder that corresponds to the results
  * @return array array where the keys are item ids and the values are scores
  * @throws Zend_Exception
  */
 public function getScores($dashboard, $folder)
 {
     if (!$dashboard instanceof Validation_DashboardDao) {
         throw new Zend_Exception('Should be a dashboard.');
     }
     if (!$folder instanceof FolderDao) {
         throw new Zend_Exception('Should be a folder.');
     }
     $sql = $this->database->select()->setIntegrityCheck(false)->from(array('d' => 'validation_dashboard'))->join(array('j' => 'validation_dashboard2scalarresult'), 'd.dashboard_id = j.dashboard_id')->join(array('r' => 'validation_scalarresult'), 'j.scalarresult_id = r.scalarresult_id')->where('r.folder_id = ' . $folder->getKey())->where('d.dashboard_id = ' . $dashboard->getKey());
     $rowset = $this->database->fetchAll($sql);
     $results = array();
     foreach ($rowset as $row) {
         $results[$row['item_id']] = $row['value'];
     }
     return $results;
 }
Ejemplo n.º 9
0
 /**
  * Check whether an item exists with the given name in the given folder.
  * If it does, returns the existing item dao. Otherwise returns false.
  *
  * @param string $name
  * @param FolderDao $folder
  * @return false|ItemDao
  * @throws Zend_Exception
  */
 public function existsInFolder($name, $folder)
 {
     $sql = $this->database->select()->setIntegrityCheck(false)->from(array('i' => 'item'))->join(array('i2f' => 'item2folder'), 'i.item_id = i2f.item_id AND ' . $this->database->getDB()->quoteInto('i2f.folder_id = ?', $folder->getKey()), array())->where('i.name = ?', $name)->limit(1);
     return $this->initDao('Item', $this->database->fetchRow($sql));
 }
Ejemplo n.º 10
0
 /**
  * test addResult function.
  */
 public function testSetScore()
 {
     // Create training, testing, and truth folders
     $testingFolder = new FolderDao();
     $testingFolder->setName('testing');
     $testingFolder->setDescription('testing');
     $testingFolder->setParentId(-1);
     $this->Folder->save($testingFolder);
     $trainingFolder = new FolderDao();
     $trainingFolder->setName('training');
     $trainingFolder->setDescription('training');
     $trainingFolder->setParentId(-1);
     $this->Folder->save($trainingFolder);
     $truthFolder = new FolderDao();
     $truthFolder->setName('truth');
     $truthFolder->setDescription('truth');
     $truthFolder->setParentId(-1);
     $this->Folder->save($truthFolder);
     // Create result folder
     $resultFolder = new FolderDao();
     $resultFolder->setName('result');
     $resultFolder->setDescription('result');
     $resultFolder->setParentId(-1);
     $this->Folder->save($resultFolder);
     // Add items to the folders
     $trainingItem = null;
     $testingItem = null;
     $truthItem = null;
     $resultItem = null;
     for ($i = 0; $i < 3; ++$i) {
         $trainingItem = new ItemDao();
         $testingItem = new ItemDao();
         $truthItem = new ItemDao();
         $resultItem = new ItemDao();
         $trainingItem->setName('img0' . $i . '.mha');
         $testingItem->setName('img0' . $i . '.mha');
         $truthItem->setName('img0' . $i . '.mha');
         $resultItem->setName('img0' . $i . '.mha');
         $trainingItem->setDescription('training img ' . $i);
         $testingItem->setDescription('testing img ' . $i);
         $truthItem->setDescription('truth img ' . $i);
         $resultItem->setDescription('result img ' . $i);
         $trainingItem->setType(0);
         $testingItem->setType(0);
         $truthItem->setType(0);
         $resultItem->setType(0);
         $this->Item->save($trainingItem);
         $this->Item->save($testingItem);
         $this->Item->save($truthItem);
         $this->Item->save($resultItem);
         $this->Folder->addItem($trainingFolder, $trainingItem);
         $this->Folder->addItem($testingFolder, $testingItem);
         $this->Folder->addItem($truthFolder, $truthItem);
         $this->Folder->addItem($resultFolder, $resultItem);
     }
     // Acquire the dashboard from the database
     /** @var Validation_DashboardModel $dashboardModel */
     $dashboardModel = MidasLoader::loadModel('Dashboard', 'validation');
     $daos = $dashboardModel->getAll();
     $dao = $daos[0];
     // Add testing, training, and truth to the dashboard
     $dashboardModel->setTraining($dao, $trainingFolder);
     $dashboardModel->setTesting($dao, $testingFolder);
     $dashboardModel->setTruth($dao, $truthFolder);
     // Reload the dashboard and check it for consistency
     $daos = $dashboardModel->getAll();
     $dao = $daos[0];
     $dashboardModel->addResult($dao, $resultFolder);
     // Get the results
     $results = $dao->getResults();
     $firstResult = $results[2];
     $items = $firstResult->getItems();
     $values = array();
     $count = 0;
     foreach ($items as $item) {
         $values[$item->getKey()] = $count * 15;
         $dashboardModel->setScore($dao, $firstResult, $item, $count * 15);
         ++$count;
     }
     $daos = $dashboardModel->getAll();
     $dao = $daos[0];
     $this->assertEquals(3, count($dao->getScores()));
     $scores = $dashboardModel->getScores($dao, $resultFolder);
     $this->assertEquals($values, $scores);
 }