/** 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());
 }
Esempio n. 2
0
 /**
  * Get policy.
  *
  * @param UserDao $user
  * @param ItemDao $item
  * @return false|ItempolicyuserDao
  * @throws Zend_Exception
  */
 public function getPolicy($user, $item)
 {
     if (!$user instanceof UserDao) {
         throw new Zend_Exception('Should be a user.');
     }
     if (!$item instanceof ItemDao) {
         throw new Zend_Exception('Should be an item.');
     }
     return $this->initDao('Itempolicyuser', $this->database->fetchRow($this->database->select()->where('item_id = ?', $item->getKey())->where('user_id = ?', $user->getKey())));
 }
 /**
  * Set the item of the scalar result.
  *
  * @param Validation_ScalarResultDao $scalarResult target scalar result
  * @param ItemDao $item target item
  * @throws Zend_Exception
  */
 public function setItem($scalarResult, $item)
 {
     if (!$scalarResult instanceof Validation_ScalarResultDao) {
         throw new Zend_Exception('Should be a scalar result.');
     }
     if (!$item instanceof ItemDao) {
         throw new Zend_Exception('Should be an item.');
     }
     $scalarResult->setItemId($item->getKey());
     parent::save($scalarResult);
 }
Esempio n. 4
0
 /**
  * @param  ItemDao $item_dao
  * @return void
  **/
 public function __construct(ItemDao $item_dao)
 {
     $fp = fopen(ROOT . '/data/AbstractFactory/order.csv', 'r');
     while ($data = fgetcsv($fp, 1000, ',')) {
         $order = new Order();
         $order->setId($data[0]);
         foreach (explode(',', $data[1]) as $item_id) {
             $item = $item_dao->findById($item_id);
             if (!is_null($item)) {
                 $order->addItem($item);
             }
         }
         $this->orders[$order->getId()] = $order;
     }
 }
Esempio n. 5
0
 public static function getInstance()
 {
     if (!isset(self::$instance)) {
         self::$instance = new ItemDao();
     }
     return self::$instance;
 }
 /**
  * Test getting all scalar results for a given dashboard.
  * @SuppressWarnings controlCloseCurly
  */
 public function testGetAllScores()
 {
     // Acquire the dashboard from the database
     /** @var Validation_DashboardModel $dashboardModel */
     $dashboardModel = MidasLoader::loadModel('Dashboard', 'validation');
     /** @var ItemModel $itemModel */
     $itemModel = MidasLoader::loadModel('Item');
     /** @var FolderModel $folderModel */
     $folderModel = MidasLoader::loadModel('Folder');
     $dashboardDao = $dashboardModel->load(1);
     $folderDao = $folderModel->load(1000);
     // Create additional result item
     $resultItem = null;
     $createdItems = array();
     $expected = array();
     for ($i = 0; $i < 2; ++$i) {
         $resultItem = new ItemDao();
         $resultItem->setName('img0' . $i . '.mha');
         $resultItem->setDescription('result img ' . $i);
         $resultItem->setType(0);
         $itemModel->save($resultItem);
         $createdItems[$resultItem->getKey()] = $i * 5 + 10;
         $folderModel->addItem($folderDao, $resultItem);
     }
     $expected[$folderDao->getKey()] = $createdItems;
     $dashboardModel->addResult($dashboardDao, $folderDao);
     $dashboardModel->setScores($dashboardDao, $folderDao, $createdItems);
     // Add a result folder
     $this->params['token'] = $this->_loginUsingApiKey();
     $this->params['method'] = 'midas.validation.addresultfolder';
     $this->params['dashboard_id'] = 1;
     $this->params['folder_id'] = 1001;
     $this->request->setMethod('POST');
     $resp = $this->_callJsonApi();
     $this->_assertStatusOk($resp);
     $this->assertEquals(1, $resp->data->dashboard_id);
     $this->resetAll();
     // Add a scalar result
     $this->params['token'] = $this->_loginUsingApiKeyAsAdmin();
     $this->params['method'] = 'midas.validation.setscalarresult';
     $this->params['dashboard_id'] = 1;
     $this->params['folder_id'] = 1001;
     $this->params['item_id'] = 1000;
     $this->params['value'] = 3;
     $this->request->setMethod('POST');
     $resp = $this->_callJsonApi();
     $this->_assertStatusOk($resp);
     $this->resetAll();
     // Add a scalar result
     $this->params['token'] = $this->_loginUsingApiKeyAsAdmin();
     $this->params['method'] = 'midas.validation.setscalarresult';
     $this->params['dashboard_id'] = 1;
     $this->params['folder_id'] = 1001;
     $this->params['item_id'] = 1001;
     $this->params['value'] = 7;
     $this->request->setMethod('POST');
     $resp = $this->_callJsonApi();
     $this->_assertStatusOk($resp);
     $this->resetAll();
     $this->params['method'] = 'midas.validation.getallscores';
     $this->params['dashboard_id'] = 1;
     $this->params['folder_id'] = 1001;
     $this->request->setMethod('POST');
     $resp = $this->_callJsonApi();
     $this->_assertStatusOk($resp);
     $expected[1001] = array();
     $expected[1001][1000] = 3;
     $expected[1001][1001] = 7;
     $this->assertEquals(1, $resp->data->dashboard_id);
     // Crazy looping because the json is parsed in as an object rather than
     // an array (not really a bad thing, just something to work around)
     $scores = $resp->data->scores;
     foreach ($expected as $folderId => $items) {
         foreach ($items as $itemId => $val) {
             $this->assertEquals($val, $scores->{$folderId}->{$itemId});
         }
     }
 }
Esempio n. 7
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);
 }
Esempio n. 8
0
 function listarEmpresa($valor = null)
 {
     $DAO = new ItemDao();
     $retorno = $DAO->Listar("SELECT id, nome FROM " . MYSQL_BASE_EMPRESAS . " WHERE ativo = 'S' AND id IN (1,3,5,6) ORDER BY nome ASC;");
     foreach ($retorno as $item) {
         if ($item['id'] == $valor) {
             echo '<option selected="selected" value="' . $item['id'] . '">' . $item['nome'] . '</option>';
         } else {
             echo '<option value="' . $item['id'] . '">' . $item['nome'] . '</option>';
         }
     }
 }
Esempio n. 9
0
 /**
  * Delete thumbnails on a given item. Called when item is about to be deleted.
  *
  * @param ItemDao $item
  */
 public function deleteByItem($item)
 {
     Zend_Registry::get('dbAdapter')->delete($this->_name, 'item_id = ' . $item->getKey());
 }
 public function __construct(ItemDao $item_dao)
 {
     $fp = fopen('order_data.txt', 'r');
     $dummy = fgets($fp, 4096);
     $this->orders = array();
     while ($buffer = fgets($fp, 4096)) {
         $order_id = trim(substr($buffer, 0, 10));
         $item_ids = trim(substr($buffer, 10));
         $order = new Order($order_id);
         foreach (split(',', $item_ids) as $item_id) {
             $item = $item_dao->findById($item_id);
             if (!is_null($item)) {
                 $order->addItem($item);
             }
         }
         $this->orders[$order->getId()] = $order;
     }
     fclose($fp);
 }
Esempio n. 11
0
 /**
  * Set a single result value.
  *
  * @param Validation_DashboardDao $dashboard target dashboard
  * @param FolderDao $folder result folder with which the value is associated
  * @param ItemDao $item item associated with the result
  * @param mixed $value scalar value representing a result
  * @return Validation_ScalarResultDao
  * @throws Zend_Exception
  */
 public function setScore($dashboard, $folder, $item, $value)
 {
     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.');
     }
     if (!$item instanceof ItemDao) {
         throw new Zend_Exception('Should be an item.');
     }
     /** @var Validation_ScalarResultModel $scalarResultModel */
     $scalarResultModel = MidasLoader::loadModel('ScalarResult', 'validation');
     $items = $folder->getItems();
     $tgtItem = null;
     foreach ($items as $curItem) {
         if ($curItem->getKey() == $item->getKey()) {
             $tgtItem = $curItem;
             break;
         }
     }
     if (!$tgtItem) {
         throw new Zend_Exception('Target item not part of result set.');
     }
     // remove a previous scalar value if there is one.
     $oldResults = $scalarResultModel->findBy('item_id', $tgtItem->getKey());
     if (count($oldResults) == 1) {
         $oldResult = $oldResults[0];
         $this->database->removeLink('scores', $dashboard, $oldResult);
     }
     /** @var Validation_ScalarResultDao $scalarResult */
     $scalarResult = MidasLoader::newDao('ScalarResultDao', 'validation');
     $scalarResult->setFolderId($folder->getKey());
     $scalarResult->setItemId($tgtItem->getKey());
     $scalarResult->setValue($value);
     $scalarResultModel->save($scalarResult);
     $this->database->link('scores', $dashboard, $scalarResult);
     return $scalarResult;
 }
Esempio n. 12
0
<?php

require_once 'J:/enrlprc/html/kura/z-ap/ItemDto.php';
require_once 'J:/enrlprc/html/kura/z-ap/dao/ItemDao.php';
$dao = new ItemDao();
$item = new ItemDto();
echo "--------検索----------\n";
$item->setCode("");
$item->setName("");
$item->setPrice(0);
$item->setQty(0);
$item->setDetail("");
$items = array();
$items = $dao->getItem($item, 0, 0);
foreach ($items as $item) {
    echo "---------------------------------\n";
    echo 'code==>' . $item->getCode() . "\n";
    echo 'name==>' . $item->getName() . "\n";
    echo 'price==>' . $item->getPrice() . "\n";
    echo 'qty==>' . $item->getQty() . "\n";
    echo 'detail==>' . $item->getDetail() . "\n";
    echo "---------------------------------\n";
}
echo "--------削除----------\n";
$result = $dao->deleteItem(8888);
var_dump($result);
$item->setCode(8888);
$item->setName("");
$item->setPrice(0);
$item->setQty(0);
$item->setDetail("");
Esempio n. 13
0
 /**
  * Delete an itemrevision from an item, will reduce all other
  * itemrevision revision numbers appropriately.
  *
  * @param ItemDao $itemdao
  * @param ItemRevisionDao $revisiondao
  * @throws Zend_Exception
  */
 public function removeRevision($itemdao, $revisiondao)
 {
     if (!$itemdao instanceof ItemDao) {
         throw new Zend_Exception('First argument should be an item');
     }
     if (!$revisiondao instanceof ItemRevisionDao) {
         throw new Zend_Exception('Second argument should be an item revision');
     }
     if ($revisiondao->getItemId() != $itemdao->getItemId()) {
         throw new Zend_Exception('Revision needs to be associated with Item');
     }
     /** @var ItemRevisionModel $itemRevisionModel */
     $itemRevisionModel = MidasLoader::loadModel('ItemRevision');
     $lastRevisionDao = $this->getLastRevision($itemdao);
     $numRevisions = $lastRevisionDao->getRevision();
     $deletedRevisionNum = $revisiondao->getRevision();
     $itemRevisionModel->delete($revisiondao);
     // compact the revision numbers if necessary
     if ($deletedRevisionNum < $numRevisions) {
         // reach past the deleted revision, reduce each revision number by 1
         $revisions = range($deletedRevisionNum + 1, $numRevisions);
         foreach ($revisions as $revision) {
             $itemRevisionDao = $this->getRevision($itemdao, $revision);
             $itemRevisionDao->setRevision($itemRevisionDao->getRevision() - 1);
             $itemRevisionModel->save($itemRevisionDao);
         }
     }
     // reload the item and last revision now that we have updated revisions
     $itemId = $itemdao->getItemId();
     $itemdao = $this->load($itemId);
     $lastRevisionDao = $this->getLastRevision($itemdao);
     // now that we have deleted a revision, recalculate size of item
     if (empty($lastRevisionDao)) {
         $itemdao->setSizebytes(0);
     } else {
         $itemdao->setSizebytes($itemRevisionModel->getSize($lastRevisionDao));
     }
     $this->save($itemdao, true);
 }
Esempio n. 14
0
 function salvar($post, $pagina, $is_null = true)
 {
     $item = new Item();
     $DAO = new ItemDao();
     //Verifica se os campos
     if ($item->validacao($post, $is_null)) {
         $exp = explode("-", $post['item']);
         $item->setId($exp[0]);
         $item->setQuantidadeMes($post['quantidade']);
         $item->setValorMes($post['valor']);
         $item->setIntemContrato($exp[1]);
         $res = $DAO->Listar("SELECT qtd_acumulada, valor_acumulado FROM " . MYSQL_BASE_CONTRATO_ITEM . " WHERE id_contrato = 1 AND id=" . $item->getItemContrato() . " LIMIT 1");
         foreach ($res as $row) {
             $item->setQuantidadeAcumulada($row['qtd_acumulada']);
             $item->setValorAcumulado($row['valor_acumulado']);
         }
         $resultado = $DAO->Atualizar($item);
         if ($resultado == true) {
             $qtd = $item->getQuantidadeAcumulada() + $item->getQuantidadeMes();
             $valor_total = $item->getValorAcumulado() + $item->getValorMes();
             //$valor_acumulado;
             $res = $DAO->AtualizarItemContrato($qtd, $valor_total, $item->getItemContrato());
             if ($res != false) {
                 echo '<script language= "JavaScript">alert("Registro cadastrado com sucesso");</script>';
                 echo '<script language= "JavaScript">location.href="' . $pagina . '.php?id=' . $post['medicao'] . '";</script>';
             } else {
                 echo '<script language= "JavaScript">alert("Erro ao atualizar a quantidade acumulada");</script>';
             }
         } else {
             echo '<script language= "JavaScript">alert("Erro ao cadastrar, por favor entre em contato com a TI.");</script>';
         }
     } else {
         echo '<script language= "JavaScript">alert("Preencha todos os campos");</script>';
     }
 }
Esempio n. 15
0
 /**
  * Get revision.
  *
  * @param ItemDao $itemdao
  * @param int $number
  * @return false|ItemRevisionDao
  * @throws Zend_Exception
  */
 public function getRevision($itemdao, $number)
 {
     if (!$itemdao instanceof ItemDao || !$itemdao->saved) {
         throw new Zend_Exception('Error in param itemdao when getting Item revision.');
     }
     return $this->initDao('ItemRevision', $this->database->fetchRow($this->database->select()->from('itemrevision')->where('item_id = ?', $itemdao->getItemId())->where('revision = ?', $number)->limit(1)->setIntegrityCheck(false)));
 }
Esempio n. 16
0
 /**
  * Return the latest revision of a model.
  *
  * @param ItemDao $itemdao
  * @return false|ItemRevisionDao
  */
 public function getLatestRevision($itemdao)
 {
     $row = $this->database->fetchRow($this->database->select()->from($this->_name)->where('item_id=?', $itemdao->getItemId())->order('revision DESC')->limit(1));
     return $this->initDao('ItemRevision', $row);
 }
Esempio n. 17
0
 /** Import a directory recursively */
 private function _recursiveParseDirectory($path, $currentdir)
 {
     $it = new DirectoryIterator($path);
     foreach ($it as $fileInfo) {
         if ($fileInfo->isDot()) {
             continue;
         }
         // If the file/dir is not readable (permission issue)
         if (!$fileInfo->isReadable()) {
             $this->getLogger()->crit($fileInfo->getPathName() . ' cannot be imported. Not readable.');
             continue;
         }
         // If this is too slow we'll figure something out
         if ($this->_checkStopImport()) {
             return false;
         }
         if ($fileInfo->isDir()) {
             // we have a directory
             // If the the directory actually doesn't exist at this point,
             // skip it.
             if (!file_exists($fileInfo->getPathName())) {
                 continue;
             }
             // Get the files in the directory and skip the folder if it does not
             // contain any files and we aren't set to import empty directories. The
             // count($files) <= 2 is there to account for our our friends . and ..
             $files = scandir($fileInfo->getPathName());
             if (!$this->importemptydirectories && $files && count($files) <= 2) {
                 continue;
             }
             // Find if the child exists
             $child = $this->Folder->getFolderByName($currentdir, $fileInfo->getFilename());
             // If the folder does not exist, create one.
             if (!$child) {
                 $child = new FolderDao();
                 $child->setName($fileInfo->getFilename());
                 $child->setParentId($currentdir->getFolderId());
                 $child->setDateCreation(date('Y-m-d H:i:s'));
                 $child->setDescription('');
                 $this->Folder->save($child);
                 $this->Folderpolicyuser->createPolicy($this->userSession->Dao, $child, MIDAS_POLICY_ADMIN);
             }
             // Keep descending
             $this->_recursiveParseDirectory($fileInfo->getPathName(), $child);
         } else {
             // We have a file
             $this->_incrementFileProcessed();
             $newrevision = true;
             $item = $this->Folder->getItemByName($currentdir, $fileInfo->getFilename());
             if (!$item) {
                 // Create an item
                 $item = new ItemDao();
                 $item->setName($fileInfo->getFilename());
                 $item->setDescription('');
                 $item->setPrivacyStatus(MIDAS_PRIVACY_PRIVATE);
                 // Must set this flag private initially
                 $this->Item->save($item, true);
                 // Set the policy of the item
                 $this->Itempolicyuser->createPolicy($this->userSession->Dao, $item, MIDAS_POLICY_ADMIN);
                 // Add the item to the current directory
                 $this->Folder->addItem($currentdir, $item);
             }
             // Check if the bistream has been updated based on the local date
             $revision = $this->ItemRevision->getLatestRevision($item);
             if ($revision) {
                 $newrevision = false;
                 $bitstream = $this->ItemRevision->getBitstreamByName($revision, $fileInfo->getFilename());
                 $curMD5 = UtilityComponent::md5file($fileInfo->getPathName());
                 $diskFileIsNewer = strtotime($bitstream->getDate()) < filemtime($fileInfo->getPathName());
                 $md5IsDifferent = $bitstream->getChecksum() != $curMD5;
                 if (!$bitstream || $diskFileIsNewer && $md5IsDifferent) {
                     $newrevision = true;
                 }
             }
             if ($newrevision) {
                 // Create a revision for the item
                 $itemRevisionDao = new ItemRevisionDao();
                 $itemRevisionDao->setChanges('Initial revision');
                 $itemRevisionDao->setUser_id($this->userSession->Dao->getUserId());
                 $this->Item->addRevision($item, $itemRevisionDao);
                 // Add bitstreams to the revision
                 $this->getLogger()->debug('create New Bitstream');
                 $bitstreamDao = new BitstreamDao();
                 $bitstreamDao->setName($fileInfo->getFilename());
                 $bitstreamDao->setPath($fileInfo->getPathName());
                 $bitstreamDao->fillPropertiesFromPath();
                 // Set the Assetstore
                 $bitstreamDao->setAssetstoreId($this->assetstoreid);
                 // Upload the bitstream
                 $assetstoreDao = $this->Assetstore->load($this->assetstoreid);
                 $this->Component->Upload->uploadBitstream($bitstreamDao, $assetstoreDao, true);
                 $this->ItemRevision->addBitstream($itemRevisionDao, $bitstreamDao);
             }
         }
     }
     unset($it);
     return true;
 }
 /**
  * Function to create the items.
  *
  * @param int $collectionId
  * @param int $parentFolderid
  */
 private function _createFolderForItem($collectionId, $parentFolderid)
 {
     /** @var FolderModel $Folder */
     $Folder = MidasLoader::loadModel('Folder');
     /** @var ItemModel $Item */
     $Item = MidasLoader::loadModel('Item');
     /** @var ItemRevisionModel $ItemRevision */
     $ItemRevision = MidasLoader::loadModel('ItemRevision');
     /** @var GroupModel $Group */
     $Group = MidasLoader::loadModel('Group');
     /** @var AssetstoreModel $Assetstore */
     $Assetstore = MidasLoader::loadModel('Assetstore');
     /** @var FolderpolicygroupModel $Folderpolicygroup */
     $Folderpolicygroup = MidasLoader::loadModel('Folderpolicygroup');
     /** @var FolderpolicyuserModel $Folderpolicyuser */
     $Folderpolicyuser = MidasLoader::loadModel('Folderpolicyuser');
     /** @var ItempolicygroupModel $Itempolicygroup */
     $Itempolicygroup = MidasLoader::loadModel('Itempolicygroup');
     /** @var ItempolicyuserModel $Itempolicyuser */
     $Itempolicyuser = MidasLoader::loadModel('Itempolicyuser');
     /** @var UserModel $User */
     $User = MidasLoader::loadModel('User');
     $colquery = pg_query('SELECT i.item_id, mtitle.text_value AS title, mabstract.text_value AS abstract ' . 'FROM item AS i ' . 'LEFT JOIN metadatavalue AS mtitle ON (i.item_id = mtitle.item_id AND mtitle.metadata_field_id = 64) ' . 'LEFT JOIN metadatavalue AS mabstract ON (i.item_id = mabstract.item_id AND mabstract.metadata_field_id = 27) ' . 'WHERE i.owning_collection=' . $collectionId);
     while ($colquery_array = pg_fetch_array($colquery)) {
         $item_id = $colquery_array['item_id'];
         $title = $colquery_array['title'];
         // If title is empty we skip this item
         if (empty($title)) {
             continue;
         }
         $abstract = $colquery_array['abstract'];
         $folderDao = false;
         try {
             // Create the folder for the item
             $folderDao = $Folder->createFolder($title, $abstract, $parentFolderid);
             // Assign the policies to the folder as the same as the parent folder
             $folder = $Folder->load($parentFolderid);
             $policyGroup = $folder->getFolderpolicygroup();
             $policyUser = $folder->getFolderpolicyuser();
             foreach ($policyGroup as $policy) {
                 $group = $policy->getGroup();
                 $policyValue = $policy->getPolicy();
                 $Folderpolicygroup->createPolicy($group, $folderDao, $policyValue);
             }
             foreach ($policyUser as $policy) {
                 $user = $policy->getUser();
                 $policyValue = $policy->getPolicy();
                 $Folderpolicyuser->createPolicy($user, $folderDao, $policyValue);
             }
             // Add specific policies for users (not dealing with groups)
             $policyquery = pg_query('SELECT max(action_id) AS actionid, eperson.eperson_id, eperson.email
                             FROM resourcepolicy
                             LEFT JOIN eperson ON (eperson.eperson_id=resourcepolicy.eperson_id)
                              WHERE epersongroup_id IS NULL AND resource_type_id=' . MIDAS2_RESOURCE_ITEM . ' AND resource_id=' . $item_id . ' GROUP BY eperson.eperson_id, email');
             while ($policyquery_array = pg_fetch_array($policyquery)) {
                 $actionid = $policyquery_array['actionid'];
                 $email = $policyquery_array['email'];
                 if ($actionid > 1) {
                     $policyValue = MIDAS_POLICY_ADMIN;
                 } elseif ($actionid == 1) {
                     $policyValue = MIDAS_POLICY_WRITE;
                 } else {
                     $policyValue = MIDAS_POLICY_READ;
                 }
                 $userDao = $User->getByEmail($email);
                 $Folderpolicyuser->createPolicy($userDao, $folderDao, $policyValue);
             }
         } catch (Zend_Exception $e) {
             $this->getLogger()->info($e->getMessage());
             Zend_Debug::dump($e);
             // we continue
         }
         if ($folderDao) {
             // Create the item from the bitstreams
             $bitquery = pg_query('SELECT   b.bitstream_id, b.name, b.description, b.internal_id FROM bitstream AS b, item2bitstream AS i2b ' . 'WHERE i2b.bitstream_id = b.bitstream_id AND i2b.item_id=' . $item_id);
             while ($bitquery_array = pg_fetch_array($bitquery)) {
                 $filename = $bitquery_array['name'];
                 $itemdao = new ItemDao();
                 $itemdao->setName($filename);
                 // Get the number of downloads and set it
                 $itemstatsquery = pg_query('SELECT downloads from midas_resourcelog WHERE
                                   resource_id_type=' . MIDAS2_RESOURCE_ITEM . ' AND resource_id=' . $item_id);
                 $itemstats_array = pg_fetch_array($itemstatsquery);
                 if ($itemstats_array) {
                     $itemdao->setView($itemstats_array['downloads']);
                     $itemdao->setDownload($itemstats_array['downloads']);
                 }
                 $Item->save($itemdao);
                 // Just check if the group anonymous can access the item
                 $policyquery = pg_query('SELECT policy_id FROM resourcepolicy WHERE resource_type_id=' . MIDAS2_RESOURCE_ITEM . ' AND resource_id=' . $item_id . ' AND epersongroup_id=0');
                 if (pg_num_rows($policyquery) > 0) {
                     $anonymousGroup = $Group->load(MIDAS_GROUP_ANONYMOUS_KEY);
                     $Itempolicygroup->createPolicy($anonymousGroup, $itemdao, MIDAS_POLICY_READ);
                 }
                 // Add specific policies for users
                 $policyquery = pg_query('SELECT max(action_id) AS actionid, eperson.eperson_id, eperson.email
                               FROM resourcepolicy
                               LEFT JOIN eperson ON (eperson.eperson_id=resourcepolicy.eperson_id)
                                WHERE epersongroup_id IS NULL AND resource_type_id=' . MIDAS2_RESOURCE_ITEM . ' AND resource_id=' . $item_id . ' GROUP BY eperson.eperson_id, email');
                 while ($policyquery_array = pg_fetch_array($policyquery)) {
                     $actionid = $policyquery_array['actionid'];
                     $email = $policyquery_array['email'];
                     if ($actionid > 1) {
                         $policyValue = MIDAS_POLICY_ADMIN;
                     } elseif ($actionid == 1) {
                         $policyValue = MIDAS_POLICY_WRITE;
                     } else {
                         $policyValue = MIDAS_POLICY_READ;
                     }
                     $userDao = $User->getByEmail($email);
                     // Set the policy of the item
                     $Itempolicyuser->createPolicy($userDao, $itemdao, $policyValue);
                 }
                 // Add the item to the current directory
                 $Folder->addItem($folderDao, $itemdao);
                 // Create a revision for the item
                 $itemRevisionDao = new ItemRevisionDao();
                 $itemRevisionDao->setChanges('Initial revision');
                 $itemRevisionDao->setUser_id($this->userId);
                 $Item->addRevision($itemdao, $itemRevisionDao);
                 // Add the metadata
                 /** @var MetadataModel $MetadataModel */
                 $MetadataModel = MidasLoader::loadModel('Metadata');
                 //
                 $metadataquery = pg_query('SELECT metadata_field_id, text_value FROM metadatavalue WHERE item_id=' . $item_id);
                 while ($metadata_array = pg_fetch_array($metadataquery)) {
                     $text_value = $metadata_array['text_value'];
                     $metadata_field_id = $metadata_array['metadata_field_id'];
                     // Do not check 64 and 27 because they are stored as field and not metadata
                     // in MIDAS3
                     switch ($metadata_field_id) {
                         case 3:
                             $element = 'contributor';
                             $qualifier = 'author';
                             break;
                         case 11:
                             $element = 'date';
                             $qualifier = 'uploaded';
                             break;
                         case 14:
                             $element = 'date';
                             $qualifier = 'created';
                             break;
                         case 15:
                             $element = 'date';
                             $qualifier = 'issued';
                             break;
                         case 18:
                             $element = 'identifier';
                             $qualifier = 'citation';
                             break;
                         case 25:
                             $element = 'identifier';
                             $qualifier = 'uri';
                             break;
                         case 26:
                             $element = 'description';
                             $qualifier = 'general';
                             break;
                         case 28:
                             $element = 'description';
                             $qualifier = 'provenance';
                             break;
                         case 29:
                             $element = 'description';
                             $qualifier = 'sponsorship';
                             break;
                         case 39:
                             $element = 'description';
                             $qualifier = 'publisher';
                             break;
                         case 57:
                             $element = 'subject';
                             $qualifier = 'keyword';
                             break;
                         case 68:
                             $element = 'subject';
                             $qualifier = 'ocis';
                             break;
                         case 75:
                             $element = 'identifier';
                             $qualifier = 'pubmed';
                             break;
                         case 74:
                             $element = 'identifier';
                             $qualifier = 'doi';
                             break;
                         default:
                             $element = '';
                             $qualifier = '';
                     }
                     if ($element != '') {
                         $MetadataModel->addMetadataValue($itemRevisionDao, MIDAS_METADATA_TEXT, $element, $qualifier, $text_value);
                     }
                 }
                 // Add bitstreams to the revision
                 $bitstreamDao = new BitstreamDao();
                 $bitstreamDao->setName($filename);
                 // Compute the path from the internalid
                 // We are assuming only one assetstore
                 $internal_id = $bitquery_array['internal_id'];
                 $filepath = $this->midas2Assetstore . '/';
                 $filepath .= substr($internal_id, 0, 2) . '/';
                 $filepath .= substr($internal_id, 2, 2) . '/';
                 $filepath .= substr($internal_id, 4, 2) . '/';
                 $filepath .= $internal_id;
                 // Check that the file exists
                 if (file_exists($filepath)) {
                     // Upload the bitstream
                     $assetstoreDao = $Assetstore->load($this->assetstoreId);
                     $bitstreamDao->setPath($filepath);
                     $bitstreamDao->fillPropertiesFromPath();
                     $bitstreamDao->setAssetstoreId($this->assetstoreId);
                     $UploadComponent = new UploadComponent();
                     $UploadComponent->uploadBitstream($bitstreamDao, $assetstoreDao);
                     // Upload the bitstream if necessary (based on the assetstore type)
                     $ItemRevision->addBitstream($itemRevisionDao, $bitstreamDao);
                     unset($UploadComponent);
                 }
             }
         } else {
             echo 'Cannot create Folder for item: ' . $title . '<br>';
         }
     }
 }
Esempio n. 19
0
<?php

require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/ItemDto.php';
require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/dao/ItemDao.php';
require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/Util.php';
try {
    $dao = new ItemDao();
    $item = new ItemDto();
    $util = new Util();
    $code = $_POST['code'];
    $item->setCode($code);
    $item->setName("");
    $item->setPrice(0);
    $item->setQty(0);
    $item->setDetail("");
    $result = $dao->deleteItem($code);
} catch (Exception $e) {
    $error = $e->getMessage();
}
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"
	src="../javascript/jquery/jquery-2.1.4.js"></script>
<script type="text/javascript" src="zapp.js"></script>
<title>削除結果</title>
</head>
<body>
<?php 
Esempio n. 20
0
<?php

require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/ItemDto.php';
require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/dao/ItemDao.php';
require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/Util.php';
try {
    $dao = new ItemDao();
    $item = new ItemDto();
    $util = new Util();
    $bcode = $_POST['bcode'];
    $code = $_POST['code'];
    $name = $_POST['name'];
    $price = $_POST['price'];
    $qty = $_POST['qty'];
    $detail = $_POST['detail'];
    $item->setCode($code);
    $item->setName($name);
    $item->setPrice($price);
    $item->setQty($qty);
    $item->setDetail($detail);
    $result = $dao->updateItem($bcode, $item);
} catch (Exception $e) {
    $error = $e->getMessage();
}
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"
	src="../javascript/jquery/jquery-2.1.4.js"></script>
Esempio n. 21
0
<?php

require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/ItemDto.php';
require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/dao/ItemDao.php';
require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/Util.php';
try {
    $dao = new ItemDao();
    $item = new ItemDto();
    $util = new Util();
    $bcode = $_POST['code'];
    $item->setCode($bcode);
    $item->setName("");
    $item->setPrice(0);
    $item->setQty(0);
    $item->setDetail("");
    $items = array();
    $items = $dao->getItem($item, 0, 0);
} catch (Exception $e) {
    $error = $e->getMessage();
}
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>変更情報入力</title>
</head>
<body>
<?php 
if (isset($error)) {
Esempio n. 22
0
<?php

require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/ItemDto.php';
require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/dao/ItemDao.php';
require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/Util.php';
try {
    $dao = new ItemDao();
    $item = new ItemDto();
    $util = new Util();
    $code = $_POST['code'];
    $name = $_POST['name'];
    $price = $_POST['price'];
    $qty = $_POST['qty'];
    $detail = $_POST['detail'];
    $item->setCode($code);
    $item->setName($name);
    $item->setPrice($price);
    $item->setQty($qty);
    $item->setDetail($detail);
    $result = $dao->insertItem($item);
} catch (Exception $e) {
    $error = $e->getMessage();
}
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"
	src="../javascript/jquery/jquery-2.1.4.js"></script>
<script type="text/javascript" src="zapp.js"></script>
Esempio n. 23
0
 /**
  * Associate the given scalar and item.
  *
  * @param Tracker_ScalarDao $scalarDao scalar DAO
  * @param ItemDao $itemDao item DAO
  * @param string $label label
  */
 public function associateItem($scalarDao, $itemDao, $label)
 {
     $data = array('scalar_id' => $scalarDao->getKey(), 'item_id' => $itemDao->getKey(), 'label' => $label);
     $this->database->getDB()->insert('tracker_scalar2item', $data);
 }
Esempio n. 24
0
 /**
  * Test that calling removeItem from a folder deletes a non-shared item.
  */
 public function testRemoveItemDeletesNonSharedItem()
 {
     $folder = $this->Folder->createFolder('TestFolder1', 'Description', 0);
     $this->assertTrue($folder->saved);
     $item = new ItemDao();
     $item->setName('subItem');
     $item->setDescription('test item to be deleted');
     $item->setType(0);
     $this->Item->save($item);
     $this->assertTrue($item->saved);
     $this->Folder->addItem($folder, $item);
     $items = $folder->getItems();
     $this->assertEquals(1, count($items));
     $this->assertEquals($items[0]->getName(), 'subItem');
     $itemid = $items[0]->getKey();
     // Make sure item is deleted when it is removed from its only parent
     $this->Folder->removeItem($folder, $item);
     $item = $this->Item->load($itemid);
     $this->assertEquals(false, $item, 'Item should have been deleted');
 }
Esempio n. 25
0
<?php

require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/ItemDto.php';
require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/dao/ItemDao.php';
require_once '/export/home/g2sn/enrlprc/html/kura/z-ap/Util.php';
try {
    $dao = new ItemDao();
    $item = new ItemDto();
    $util = new Util();
    $code = $_POST['code'];
    $name = $_POST['name'];
    $price = $_POST['price'];
    $qty = $_POST['qty'];
    $detail = $_POST['detail'];
    $priCd = $_POST['priCd'];
    $qtyCd = $_POST['qtyCd'];
    $item->setCode($code);
    $item->setName($name);
    $item->setPrice($price);
    $item->setQty($qty);
    $item->setDetail($detail);
    $items = array();
    $items = $dao->getItem($item, $priCd, $qtyCd);
} catch (Exception $e) {
    $error = $e->getMessage();
}
header('Content-Type: text/html; charset=utf-8');
?>
<!DOCTYPE html>
<html>
<head>
Esempio n. 26
0
 /**
  * Save upload item in the database.
  *
  * @param UserDao $userDao
  * @param string $name
  * @param string $url
  * @param null|int $parent
  * @param int $sizebytes
  * @param string $checksum
  * @return ItemDao
  * @throws Zend_Exception
  */
 public function createLinkItem($userDao, $name, $url, $parent = null, $sizebytes = 0, $checksum = ' ')
 {
     /** @var ItemModel $itemModel */
     $itemModel = MidasLoader::loadModel('Item');
     /** @var FolderModel $folderModel */
     $folderModel = MidasLoader::loadModel('Folder');
     /** @var AssetstoreModel $assetstoreModel */
     $assetstoreModel = MidasLoader::loadModel('Assetstore');
     /** @var ItemRevisionModel $itemRevisionModel */
     $itemRevisionModel = MidasLoader::loadModel('ItemRevision');
     if ($userDao == null) {
         throw new Zend_Exception('Please log in');
     }
     if (is_numeric($parent)) {
         $parent = $folderModel->load($parent);
     }
     if ($parent == false || !$folderModel->policyCheck($parent, $userDao, MIDAS_POLICY_WRITE)) {
         throw new Zend_Exception('Parent permissions errors');
     }
     Zend_Loader::loadClass('ItemDao', BASE_PATH . '/core/models/dao');
     $item = new ItemDao();
     $item->setName($name);
     $item->setDescription('');
     $item->setSizebytes($sizebytes);
     $item->setType(0);
     $item->setPrivacyStatus(MIDAS_PRIVACY_PRIVATE);
     // Must set this flag private initially
     $itemModel->save($item, false);
     $folderModel->addItem($parent, $item);
     $itemModel->copyParentPolicies($item, $parent);
     Zend_Loader::loadClass('ItemRevisionDao', BASE_PATH . '/core/models/dao');
     $itemRevisionDao = new ItemRevisionDao();
     $itemRevisionDao->setChanges('Initial revision');
     $itemRevisionDao->setUser_id($userDao->getKey());
     $itemRevisionDao->setDate(date('Y-m-d H:i:s'));
     $itemRevisionDao->setLicenseId(null);
     $itemModel->addRevision($item, $itemRevisionDao);
     // Add bitstreams to the revision
     Zend_Loader::loadClass('BitstreamDao', BASE_PATH . '/core/models/dao');
     $bitstreamDao = new BitstreamDao();
     $bitstreamDao->setName($url);
     $bitstreamDao->setPath($url);
     $bitstreamDao->setMimetype('url');
     $bitstreamDao->setSizebytes($sizebytes);
     $bitstreamDao->setChecksum($checksum);
     $assetstoreDao = $assetstoreModel->getDefault();
     $bitstreamDao->setAssetstoreId($assetstoreDao->getKey());
     $itemRevisionModel->addBitstream($itemRevisionDao, $bitstreamDao);
     $this->getLogger()->debug('Link item created (' . $item->getName() . ', id=' . $item->getKey() . ')');
     return $item;
 }
Esempio n. 27
0
 public static function order(Order $order)
 {
     $item_dao = ItemDao::getInstance();
     //1.ItemDaoインスタンスを取得し、
     foreach ($order->getItems() as $order_item) {
         //2.在庫を引き当て、
         $item_dao->setAside($order_item);
     }
     OrderDao::createOrder($order);
     //3.注文結果を表示する
 }
Esempio n. 28
0
#!/usr/bin/php
<?php 
require_once 'OrderManager.class.php';
$order = new Order();
$item_dao = ItemDao::getInstance();
$order->addItem(new OrderItem($item_dao->findById(1), 2));
$order->addItem(new OrderItem($item_dao->findById(2), 1));
$order->addItem(new OrderItem($item_dao->findById(3), 3));
OrderManager::order($order);