/**
  * Display a paginated hitlist of information objects (top-level only)
  *
  * @param sfRequest $request
  */
 public function execute($request)
 {
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     $this->resource = QubitInformationObject::getById(QubitInformationObject::ROOT_ID);
     if (isset($this->getRoute()->resource)) {
         $this->resource = $this->getRoute()->resource;
     }
     $query = QubitSearch::getInstance()->addTerm($this->resource->id, 'parentId');
     if (isset($request->query)) {
         $query = $request->query;
     }
     $query = QubitAcl::searchFilterByRepository($query, 'read');
     $query = QubitAcl::searchFilterDrafts($query);
     $this->pager = new QubitArrayPager();
     $this->pager->hits = QubitSearch::getInstance()->getEngine()->getIndex()->find($query);
     $this->pager->setMaxPerPage($request->limit);
     $this->pager->setPage($request->page);
     $ids = array();
     foreach ($this->pager->getResults() as $hit) {
         $ids[] = $hit->getDocument()->id;
     }
     $criteria = new Criteria();
     $criteria->add(QubitInformationObject::ID, $ids, Criteria::IN);
     $this->informationObjects = QubitInformationObject::get($criteria);
 }
예제 #2
0
 public function save($connection = null)
 {
     // TODO: $cleanObject = $this->object->clean;
     $cleanObjectId = $this->__get('objectId', array('clean' => true));
     parent::save($connection);
     if ($this->indexOnSave()) {
         if ($this->objectId != $cleanObjectId && null !== QubitInformationObject::getById($cleanObjectId)) {
             QubitSearch::updateInformationObject(QubitInformationObject::getById($cleanObjectId));
         }
         if ($this->object instanceof QubitInformationObject) {
             QubitSearch::updateInformationObject($this->object);
         }
     }
     return $this;
 }
 public function execute($request)
 {
     parent::execute($request);
     $this->addFields();
     $this->title = $this->context->i18n->__('Global search/replace');
     if ($request->isMethod('post')) {
         // Make sure we have required information for search/replace
         if (empty($request->pattern) || empty($request->replacement)) {
             $this->error = $this->context->i18n->__('Both source and replacement fields are required.');
             return;
         } else {
             if (!isset($request->confirm)) {
                 $this->title = $this->context->i18n->__('Are you sure you want to replace "%1%" with "%2%" in %3%?', array('%1%' => $request->pattern, '%2%' => $request->replacement, '%3%' => sfInflector::humanize(sfInflector::underscore($request->column))));
                 return;
             }
         }
         // Process replacement on each IO
         // NB: could this be made faster by reading a batch of IDs?
         foreach ($this->pager->hits as $hit) {
             $io = QubitInformationObject::getById($hit->getDocument()->id);
             if (isset($request->allowRegex)) {
                 $pattern = '/' . strtr($request->pattern, array('/' => '\\/')) . '/';
                 if (!isset($request->caseSensitive)) {
                     $pattern .= 'i';
                 }
                 $replacement = strtr($request->replacement, array('/' => '\\/'));
                 $replaced = preg_replace($pattern, $replacement, $io->__get($request->column));
             } elseif (isset($request->caseSensitive)) {
                 $replaced = str_replace($request->pattern, $request->replacement, $io->__get($request->column));
             } else {
                 $replaced = str_ireplace($request->pattern, $request->replacement, $io->__get($request->column));
             }
             $io->__set($request->column, $replaced);
             $io->save();
         }
         // force refresh of index to keep sync
         QubitSearch::getInstance()->optimize();
         // When complete, redirect to GSR home
         $this->redirect(array('module' => 'search', 'action' => 'globalReplace'));
     }
 }
 /**
  * @see sfTask
  */
 public function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $conn = $databaseManager->getDatabase('propel')->getConnection();
     sfConfig::set('app_upload_dir', self::getUploadDir($conn));
     if (false === ($fh = fopen($arguments['filename'], 'rb'))) {
         throw new sfException('You must specify a valid filename');
     }
     $this->logSection("Load digital objects from {$arguments['filename']}...");
     // Get header (first) row
     $header = fgetcsv($fh, 1000);
     if (!in_array('information_object_id', $header) || !in_array('filename', $header)) {
         throw new sfException('Import file must contain an \'information_object_id\' and \'filename\' column');
     }
     $idKey = array_search('information_object_id', $header);
     $fileKey = array_search('filename', $header);
     // Build hash on information_object.id, with array value if information
     // object has multiple digital objects attached
     while ($item = fgetcsv($fh, 1000)) {
         if (!isset($digitalObjects[$item[$idKey]])) {
             $digitalObjects[$item[$idKey]] = $item[$fileKey];
         } else {
             if (!is_array($digitalObjects[$item[$idKey]])) {
                 $digitalObjects[$item[$idKey]] = array($digitalObjects[$item[$idKey]], $item[$fileKey]);
             } else {
                 $digitalObjects[$item[$idKey]][] = $item[$fileKey];
             }
         }
     }
     // Loop through $digitalObject hash and add digital objects to db
     foreach ($digitalObjects as $key => $item) {
         if (null === ($informationObject = QubitInformationObject::getById($key))) {
             $this->log("Invalid information_object id {$key}");
             continue;
         }
         if (!is_array($item)) {
             self::addDigitalObject($informationObject, $item, $conn);
         } else {
             // If more than one digital object linked to this information object
             for ($i = 0; $i < count($item); $i++) {
                 // Create new information objects, to maintain one-to-one
                 // relationship with digital objects
                 $informationObject = new QubitInformationObject();
                 $informationObject->parent = QubitInformationObject::getById($key);
                 $informationObject->title = basename($item[$i]);
                 $informationObject->save($conn);
                 self::addDigitalObject($informationObject, $item[$i], $conn);
             }
         }
     }
     $this->logSection('Successfully Loaded ' . self::$count . ' digital objects.');
 }
 public function execute($request)
 {
     // Default items per page
     if (!isset($request->limit)) {
         $request->limit = sfConfig::get('app_hits_per_page');
     }
     $this->form = new sfForm();
     $this->resource = $this->getRoute()->resource;
     // Check that the object exists and that it is not the root
     if (!isset($this->resource) || !isset($this->resource->parent)) {
         $this->forward404();
     }
     // Check authorization
     if (!QubitAcl::check($this->resource, 'update')) {
         QubitAcl::forwardUnauthorized();
     }
     // "parent" form field
     $this->form->setValidator('parent', new sfValidatorString(array('required' => true)));
     $this->form->setWidget('parent', new sfWidgetFormInputHidden());
     // Root is default parent
     if ($this->resource instanceof QubitInformationObject) {
         $this->form->bind($request->getGetParameters() + array('parent' => $this->context->routing->generate(null, array(QubitInformationObject::getById(QubitInformationObject::ROOT_ID), 'module' => 'informationobject'))));
     } else {
         if ($this->resource instanceof QubitTerm) {
             $this->form->bind($request->getGetParameters() + array('parent' => $this->context->routing->generate(null, array(QubitTerm::getById(QubitTerm::ROOT_ID), 'module' => 'term'))));
         }
     }
     if ($request->isMethod('post')) {
         $this->form->bind($request->getPostParameters());
         if ($this->form->isValid()) {
             $params = $this->context->routing->parse(Qubit::pathInfo($this->form->parent->getValue()));
             // In term treeview, root node links (href) to taxonomy, but it represents the term root object
             if ($this->resource instanceof QubitTerm && QubitObject::getById($params['_sf_route']->resource->id) instanceof QubitTaxonomy) {
                 $this->resource->parentId = QubitTerm::ROOT_ID;
             } else {
                 $this->resource->parentId = $params['_sf_route']->resource->id;
             }
             $this->resource->save();
             if ($request->isXmlHttpRequest()) {
                 return $this->renderText('');
             } else {
                 if ($this->resource instanceof QubitInformationObject) {
                     $this->redirect(array($this->resource, 'module' => 'informationobject'));
                 } else {
                     if ($this->resource instanceof QubitTerm) {
                         $this->redirect(array($this->resource, 'module' => 'term'));
                     }
                 }
             }
         }
     }
     $params = $this->context->routing->parse(Qubit::pathInfo($this->form->parent->getValue()));
     $this->parent = QubitObject::getById($params['_sf_route']->resource->id);
     $query = QubitSearch::getInstance()->addTerm($this->parent->slug, 'parent');
     if (isset($request->query)) {
         $query = $request->query;
     }
     $this->pager = new QubitArrayPager();
     $this->pager->hits = QubitSearch::getInstance()->getEngine()->getIndex()->find($query);
     $this->pager->setMaxPerPage($request->limit);
     $this->pager->setPage($request->page);
     $ids = array();
     foreach ($this->pager->getResults() as $hit) {
         $ids[] = $hit->getDocument()->id;
     }
     $criteria = new Criteria();
     $criteria->add(QubitObject::ID, $ids, Criteria::IN);
     $this->results = QubitObject::get($criteria);
 }
 public function save($connection = null)
 {
     // TODO: $cleanInformationObject = $this->informationObject->clean;
     $cleanInformationObjectId = $this->__get('informationObjectId', array('clean' => true));
     // Write assets to storage device
     if (0 < count($this->assets)) {
         foreach ($this->assets as $asset) {
             if (null == $this->getChecksum() || $asset->getChecksum() != $this->getChecksum()) {
                 $this->writeToFileSystem($asset);
             }
             // TODO: allow setting multiple assets for different usage types
             // (e.g. a master, thumbnail and reference image)
             break;
         }
     }
     parent::save($connection);
     // Create child objects (derivatives)
     if (0 < count($this->assets) && $this->createDerivatives) {
         if (sfConfig::get('app_explode_multipage_files') && $this->getPageCount() > 1) {
             // If DO is a compound object, then create child objects and set to
             // display as compound object (with pager)
             $this->createCompoundChildren();
             // Set parent digital object to be displayed as compound
             $this->setDisplayAsCompoundObject(1);
             // We don't need reference image because a compound will be displayed instead of it
             // But thumbnails are necessary for image flow
             $this->createThumbnail($connection);
         } else {
             // If DO is a single object, create various representations based on
             // intended usage
             $this->createRepresentations($this->usageId, $connection);
         }
     }
     // Add watermark to reference image
     if (QubitTerm::REFERENCE_ID == $this->usageId && $this->isImage() && is_readable($waterMarkPathName = sfConfig::get('sf_web_dir') . '/watermark.png') && is_file($waterMarkPathName)) {
         $filePathName = $this->getAbsolutePath();
         $command = 'composite -dissolve 15 -tile ' . $waterMarkPathName . ' ' . escapeshellarg($filePathName) . ' ' . escapeshellarg($filePathName);
         exec($command);
     }
     // Update search index for related info object
     if ($this->indexOnSave) {
         if ($this->informationObjectId != $cleanInformationObjectId && null !== QubitInformationObject::getById($cleanInformationObjectId)) {
             QubitSearch::updateInformationObject(QubitInformationObject::getById($cleanInformationObjectId));
         }
         if (isset($this->informationObject)) {
             QubitSearch::updateInformationObject($this->informationObject);
         }
     }
     return $this;
 }
  <fieldset class="collapsible collapsed" id="informationObjectArea">

    <legend><?php 
echo __('Permissions by %1%', array('%1%' => sfConfig::get('app_ui_label_informationobject')));
?>
</legend>

    <?php 
if (0 < count($informationObjects)) {
    ?>
      <?php 
    foreach ($informationObjects as $informationObjectId => $permissions) {
        ?>
        <div class="form-item">
          <?php 
        echo get_component('aclGroup', 'aclTable', array('object' => QubitInformationObject::getById($informationObjectId), 'permissions' => $permissions, 'actions' => $basicActions));
        ?>
        </div>
      <?php 
    }
    ?>
    <?php 
}
?>

    <?php 
// Build dialog for adding new table
$tableTemplate = '<div class="form-item">';
$tableTemplate .= '<table id="acl_{objectId}">';
$tableTemplate .= '<caption/>';
$tableTemplate .= '<thead>';
                ?>
                  <em><?php 
                echo __('All %1%', array('%1%' => sfConfig::get('app_ui_label_informationobject')));
                ?>
</em>
                <?php 
            } elseif ('' != $repoId) {
                ?>
                  <?php 
                echo sfConfig::get('app_ui_label_repository') . ': ' . render_title(QubitRepository::getById($repoId));
                ?>
                <?php 
            } else {
                ?>
                  <?php 
                echo render_title(QubitInformationObject::getById($objectId));
                ?>
                <?php 
            }
            ?>
              </strong></td>
            </tr>
            <?php 
            $row = 0;
            ?>
            <?php 
            foreach ($actions as $action => $groupPermission) {
                ?>
              <tr class="<?php 
                echo 0 == @++$row % 2 ? 'even' : 'odd';
                ?>
 public static function renderYuiNodes($tree, $options = array())
 {
     ProjectConfiguration::getActive()->loadHelpers(array('Qubit', 'Text', 'Escaping'));
     $yuiTree = array();
     foreach ($tree as $key => $item) {
         $node = array();
         if ($item instanceof QubitInformationObject) {
             $label = render_title(new sfIsadPlugin($item));
             $node['label'] = truncate_text($label, 50);
             if (50 < strlen($label)) {
                 $node['title'] = esc_specialchars($label);
             }
             $node['href'] = sfContext::getInstance()->routing->generate(null, array($item, 'module' => 'informationobject'));
             $node['id'] = $item->id;
             $node['parentId'] = $item->parentId;
             $node['isLeaf'] = (string) (!$item->hasChildren());
             $node['moveUrl'] = sfContext::getInstance()->routing->generate(null, array($item, 'module' => 'default', 'action' => 'move'));
             $node['expandUrl'] = sfContext::getInstance()->routing->generate(null, array($item, 'module' => 'informationobject', 'action' => 'treeView'));
             if (isset($options['currentNode']) && $options['currentNode'] === $item) {
                 $node['style'] = 'ygtvlabel currentTextNode';
             }
         } else {
             $count = intval($item['total']) - intval($item['limit']);
             $node['label'] = sfContext::getInstance()->i18n->__('+%1% ...', array('%1%' => $count));
             $node['parentId'] = $item['parentId'];
             $node['href'] = sfContext::getInstance()->routing->generate(null, array(QubitInformationObject::getById($item['parentId']), 'module' => 'informationobject', 'action' => 'browse'));
             $node['isLeaf'] = 'true';
             $node['style'] = 'seeAllNode';
         }
         $yuiTree[] = $node;
     }
     return $yuiTree;
 }
예제 #10
0
 public function execute($request)
 {
     parent::execute($request);
     if ($request->hasParameter('csvimport')) {
         // if a parent ID is set, use that for parenting
         $parentId = $request->getParameter('parent', null);
         if (!empty($parentId)) {
             $request->getParameterHolder()->remove('parent');
         }
         // make sure we don't pass the import ID
         $request->getParameterHolder()->remove('id');
         $this->form->bind($request->getParameterHolder()->getAll());
         if ($this->form->isValid()) {
             $this->processForm();
             if (!empty($parentId)) {
                 $this->resource->parent = QubitInformationObject::getById($parentId);
             } else {
                 $this->resource->parent = QubitInformationObject::getById(QubitInformationObject::ROOT_ID);
             }
             $this->resource->save();
             return;
             // don't bother adding assets etc. for output
         }
     } elseif ($request->isMethod('post')) {
         $this->form->bind($request->getPostParameters());
         if ($this->form->isValid()) {
             $this->processForm();
             $this->resource->save();
             $this->redirect(array($this->resource, 'module' => 'informationobject'));
         }
     }
     QubitDescription::addAssets($this->response);
     QubitImageFlow::addAssets($this->response);
     QubitTreeView::addAssets($this->response);
 }
 public function execute($request)
 {
     ProjectConfiguration::getActive()->loadHelpers('Qubit');
     $uploadLimt = -1;
     $diskUsage = 0;
     $uploadFiles = array();
     $warning = null;
     $this->informationObject = QubitInformationObject::getById($request->informationObjectId);
     if (!isset($this->informationObject)) {
         $this->forward404();
     }
     // Check user authorization
     if (!QubitAcl::check($this->informationObject, 'update')) {
         throw new sfException();
     }
     $repo = $this->informationObject->getRepository(array('inherit' => true));
     if (isset($repo)) {
         $uploadLimit = $repo->uploadLimit;
         if (0 < $uploadLimit) {
             $uploadLimit *= pow(10, 9);
             // Convert to bytes
         }
         $diskUsage = $repo->getDiskUsage();
     }
     // Create tmp dir, if it doesn't exist already
     $tmpDir = sfConfig::get('sf_upload_dir') . '/tmp';
     if (!file_exists($tmpDir)) {
         mkdir($tmpDir);
         chmod($tmpDir, 0775);
     }
     foreach ($_FILES as $file) {
         if (null != $repo && 0 <= $uploadLimit && $uploadLimit < $diskUsage + $file['size']) {
             $uploadFiles = array('error' => $this->context->i18n->__('%1% upload limit of %2% GB exceeded for %3%', array('%1%' => sfConfig::get('app_ui_label_digitalobject'), '%2%' => round($uploadLimit / pow(10, 9), 2), '%4%' => $this->context->routing->generate(null, array($repo, 'module' => 'repository')), '%3%' => $repo->__toString())));
             continue;
         }
         // Get file extension
         $extension = substr($file['name'], strrpos($file['name'], '.'));
         // Get a unique file name (to avoid clashing file names)
         do {
             $uniqueString = substr(md5(time() . $file['name']), 0, 8);
             $tmpFileName = "TMP{$uniqueString}{$extension}";
             $tmpFilePath = "{$tmpDir}/{$tmpFileName}";
         } while (file_exists($tmpFilePath));
         // Thumbnail name
         $thumbName = "THB{$uniqueString}.jpg";
         $thumbPath = "{$tmpDir}/{$thumbName}";
         // Move file to web/uploads/tmp directory
         if (!move_uploaded_file($file['tmp_name'], $tmpFilePath)) {
             $errorMessage = $this->context->i18n->__('File %1% could not be moved to %2%', array('%1%' => $file['name'], '%2%' => $tmpDir));
             $uploadFiles = array('error' => $errorMessage);
             continue;
         }
         $tmpFileMd5sum = md5_file($tmpFilePath);
         $tmpFileMimeType = QubitDigitalObject::deriveMimeType($tmpFileName);
         if ($canThumbnail = QubitDigitalObject::canThumbnailMimeType($tmpFileMimeType) || QubitDigitalObject::isVideoFile($tmpFilePath)) {
             if (QubitDigitalObject::isImageFile($tmpFilePath) || 'application/pdf' == $tmpFileMimeType) {
                 $resizedObject = QubitDigitalObject::resizeImage($tmpFilePath, 150, 150);
             } else {
                 if (QubitDigitalObject::isVideoFile($tmpFilePath)) {
                     $resizedObject = QubitDigitalObject::createThumbnailFromVideo($tmpFilePath, 150, 150);
                 }
             }
             if (0 < strlen($resizedObject)) {
                 file_put_contents($thumbPath, $resizedObject);
                 chmod($thumbPath, 0644);
             }
             // Show a warning message if object couldn't be thumbnailed when it is
             // supposed to be possible
             if (!file_exists($thumbPath) && 0 >= filesize($thumbPath)) {
                 $warning = $this->context->i18n->__('File %1% could not be thumbnailed', array('%1%' => $file['name']));
             }
         } else {
             $thumbName = '../../images/' . QubitDigitalObject::getGenericIconPath($tmpFileMimeType, QubitTerm::THUMBNAIL_ID);
         }
         $uploadFiles = array('canThumbnail' => $canThumbnail, 'name' => $file['name'], 'md5sum' => $tmpFileMd5sum, 'size' => hr_filesize($file['size']), 'thumb' => $thumbName, 'tmpName' => $tmpFileName, 'warning' => $warning);
         // Keep running total of disk usage
         $diskUsage += $file['size'];
     }
     // Pass file data back to caller for processing on form submit
     $this->response->setHttpHeader('Content-Type', 'application/json; charset=utf-8');
     return $this->renderText(json_encode($uploadFiles));
 }