public function renderFrontend()
 {
     $oCriteria = DocumentQuery::create()->filterByDocumentKind('image');
     if (!Session::getSession()->isAuthenticated()) {
         $oCriteria->filterByIsProtected(false);
     }
     if ($this->iCategoryId !== null) {
         $oCriteria->filterByDocumentCategoryId($this->iCategoryId);
     }
     $aDocuments = $oCriteria->find();
     $sTemplateName = 'helpers/gallery';
     try {
         $oListTemplate = new Template($sTemplateName);
         foreach ($aDocuments as $i => $oDocument) {
             $oItemTemplate = new Template($sTemplateName . DocumentListFrontendModule::LIST_ITEM_POSTFIX);
             $oItemTemplate->replaceIdentifier('model', 'Document');
             $oItemTemplate->replaceIdentifier('counter', $i + 1);
             $oDocument->renderListItem($oItemTemplate);
             $oListTemplate->replaceIdentifierMultiple('items', $oItemTemplate);
         }
     } catch (Exception $e) {
         $oListTemplate = new Template("", null, true);
     }
     return $oListTemplate;
 }
 public function onNavigationItemChildrenCacheDetectOutdated($oNavigationItem, $oCache, $aContainer)
 {
     $bIsOutdated =& $aContainer[0];
     if (!($oNavigationItem instanceof PageNavigationItem && $oNavigationItem->getIdentifier() === 'photos')) {
         return;
     }
     if ($bIsOutdated) {
         return;
     }
     // Make sure the children are re-rendered when the items in the query are updated
     $bIsOutdated = $oCache->isOlderThan(DocumentQuery::create()->filterByDocumentKind('image')) || $oCache->isOlderThan(DocumentCategoryQuery::create()->filterByDocumentKind('image'));
 }
 public function postUp($manager)
 {
     // add the post-migration code here
     require_once $_SERVER['PWD'] . '/base/lib/inc.php';
     $oConnection = Propel::getConnection(DocumentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     Propel::disableInstancePooling();
     $stmt = DocumentPeer::doSelectStmt(DocumentQuery::create()->clearSelectColumns()->addSelectColumn('documents.id')->addSelectColumn('documents.hash'));
     foreach ($stmt->fetchAll(PDO::FETCH_NUM) as $row) {
         $iId = $row[0];
         $sHash = $row[1];
         $oConnection->exec('INSERT IGNORE INTO `document_data` (`hash`, `data`, `created_at`, `updated_at`, `created_by`, `updated_by`) VALUES ("' . $sHash . '", (SELECT `data` FROM `documents` WHERE `id` = ' . $iId . '), (SELECT `created_at` FROM `documents` WHERE `id` = ' . $iId . '), (SELECT `updated_at` FROM `documents` WHERE `id` = ' . $iId . '), (SELECT `created_by` FROM `documents` WHERE `id` = ' . $iId . '), (SELECT `updated_by` FROM `documents` WHERE `id` = ' . $iId . '))');
     }
     $stmt->closeCursor();
 }
 public function __construct($aRequestPath)
 {
     parent::__construct($aRequestPath);
     if (!isset($this->aPath[0])) {
         // Exceptions thrown in a file module’s constructor yield a UserError but that’s OK.
         throw new Exception("Error in DisplayDocumentFileModule->__construct: no key given");
     }
     $this->oSession = Session::close();
     $this->oDocument = DocumentQuery::create()->findPk(intval($this->aPath[0]));
     if ($this->oDocument === null || $this->oDocument->getIsProtected() && !$this->isAuthenticated()) {
         $oErrorPage = PageQuery::create()->findOneByName(Settings::getSetting('error_pages', 'not_found', 'error_404'));
         if ($oErrorPage) {
             LinkUtil::redirect(LinkUtil::link($oErrorPage->getLinkArray(), "FrontendManager"));
         } else {
             print "Not found";
             exit;
         }
     }
     Session::close();
 }
 public function listImages()
 {
     $oCriteria = DocumentQuery::create();
     if ($this->aDisplayedCategories !== null) {
         $oCategoriesCriterion = null;
         foreach ($this->aDisplayedCategories as $sValue) {
             $mComparison = $sValue === CriteriaListWidgetDelegate::SELECT_WITHOUT ? Criteria::ISNULL : Criteria::EQUAL;
             $sValue = $mComparison === Criteria::ISNULL ? null : $sValue;
             if ($oCategoriesCriterion === null) {
                 $oCategoriesCriterion = $oCriteria->getNewCriterion(DocumentPeer::DOCUMENT_CATEGORY_ID, $sValue, $mComparison);
             } else {
                 $oCategoriesCriterion->addOr($oCriteria->getNewCriterion(DocumentPeer::DOCUMENT_CATEGORY_ID, $sValue, $mComparison));
             }
         }
         $oCriteria->add($oCategoriesCriterion);
     }
     $oCriteria->filterByDocumentKind('image');
     // always exclude externally managed images
     $oCriteria->excludeExternallyManaged()->orderByUpdatedAt('desc');
     return WidgetJsonFileModule::jsonBaseObjects($oCriteria->find(), array('name', 'description', 'id', 'language_id'));
 }
 public static function listQuery($aOptions)
 {
     $oQuery = DocumentQuery::create()->filterByDisplayLanguage();
     if (!Session::getSession()->isAuthenticated()) {
         $oQuery->filterByIsProtected(false);
     }
     // Link categories
     $aCategories = isset($aOptions['document_categories']) ? is_array($aOptions['document_categories']) ? $aOptions['document_categories'] : array($aOptions['document_categories']) : array();
     $iCountCategories = count($aCategories);
     if ($iCountCategories > 0) {
         $oQuery->filterByDocumentCategoryId($aCategories);
     }
     // Tags
     $aTags = isset($aOptions['tags']) ? is_array($aOptions['tags']) ? $aOptions['tags'] : array($aOptions['tags']) : array();
     $bHasTags = count($aTags) > 0 && $aTags[0] !== null;
     if ($bHasTags) {
         $oQuery->filterByTagId($aTags);
     }
     // Check document kind
     if (isset($aOptions['document_kind']) && $aOptions['document_kind'] != null) {
         $oQuery->filterByDocumentKind($aOptions['document_kind']);
     }
     $sSortOrder = @$aOptions['sort_order'] === 'desc' ? 'desc' : 'asc';
     // Sort order only in case of one category and no tags
     if ($iCountCategories === 1 && $bHasTags === false) {
         if ($aOptions['sort_by'] === self::SORT_BY_SORT) {
             $oQuery->orderBySort($sSortOrder);
         }
     }
     if ($aOptions['sort_by'] === self::SORT_BY_CREATEDAT) {
         $oQuery->orderByCreatedAt($sSortOrder);
     }
     // order all entries by name, asc after priority order, this is a fallback that probably never applies
     if ($aOptions['sort_by'] !== self::SORT_BY_NAME) {
         $sSortOrder = 'asc';
     }
     return $oQuery->orderByName($sSortOrder);
 }
示例#7
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(DocumentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = DocumentQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         // referenceable behavior
         if (ReferencePeer::hasReference($this)) {
             throw new PropelException("Exception in " . __METHOD__ . ": tried removing an instance from the database even though it is still referenced.", new StillReferencedException($this));
         }
         // denyable behavior
         if (!(DocumentPeer::isIgnoringRights() || $this->mayOperate("delete"))) {
             throw new PropelException(new NotPermittedException("delete.by_role", array("role_key" => "documents")));
         }
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
示例#8
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this DocumentData is new, it will return
  * an empty collection; or if this DocumentData has previously
  * been saved, it will retrieve related Documents from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in DocumentData.
  *
  * @param Criteria $criteria optional Criteria object to narrow the query
  * @param PropelPDO $con optional connection object
  * @param string $join_behavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return PropelObjectCollection|Document[] List of Document objects
  */
 public function getDocumentsJoinUserRelatedByUpdatedBy($criteria = null, $con = null, $join_behavior = Criteria::LEFT_JOIN)
 {
     $query = DocumentQuery::create(null, $criteria);
     $query->joinWith('UserRelatedByUpdatedBy', $join_behavior);
     return $this->getDocuments($query, $con);
 }
示例#9
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      PropelPDO $con
  * @return     void
  * @throws     PropelException
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(DocumentPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $ret = $this->preDelete($con);
         if ($ret) {
             DocumentQuery::create()->filterByPrimaryKey($this->getPrimaryKey())->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
 }
 /**
  * Get the associated Document object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return Document The associated Document object.
  * @throws PropelException
  */
 public function getDocument(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->aDocument === null && $this->image_id !== null && $doQuery) {
         $this->aDocument = DocumentQuery::create()->findPk($this->image_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aDocument->addDocumentationParts($this);
            */
     }
     return $this->aDocument;
 }
示例#11
0
 /**
  * @deprecated
  * use query methods of DocumentQuery and document related query classes and query notation in general directly
  */
 public static function getDocumentsByKindAndCategory($sDocumentKind = null, $iDocumentCategory = null, $bDocumentKindIsNotInverted = true, $bExcludeExternallyManaged = true)
 {
     $oQuery = DocumentQuery::create()->joinDocumentType();
     if ($bExcludeExternallyManaged) {
         $oQuery->excludeExternallyManaged();
     }
     if ($iDocumentCategory !== null) {
         $oQuery->filterByDocumentCategory($iDocumentCategory);
     }
     if ($sDocumentKind !== null) {
         $oQuery->filterByDocumentKind($sDocumentKind, $bDocumentKindIsNotInverted);
     }
     return $oQuery->orderByName()->find();
 }
示例#12
0
 private function updateDocument($oDocument, &$aOptions, $sFileName, $iDocumentTypeId)
 {
     $oDocument->setDocumentTypeId($iDocumentTypeId);
     $oDocument->setOriginalName($aOptions['name']);
     if (!$aOptions['deny_name_override'] || !$oDocument->getName()) {
         $oDocument->setName($sFileName);
     }
     if ($oDocument->isNew()) {
         $oDocument->setLanguageId($aOptions['language_id']);
         $oDocument->setIsProtected($aOptions['is_protected']);
         if (is_numeric($aOptions['document_category_id'])) {
             $oDocument->setDocumentCategoryId($aOptions['document_category_id']);
             $oDocument->setSort(DocumentQuery::create()->filterByDocumentCategoryId($oDocument->getDocumentCategoryId())->count() + 1);
         }
     }
     // Resize image if necessary
     if ($oDocument->isImage() && $oDocument->getDocumentCategory() && $oDocument->getDocumentCategory()->getMaxWidth() != null) {
         $iMaxWidth = $oDocument->getDocumentCategory()->getMaxWidth();
         $oImage = Image::imageFromData(stream_get_contents($oDocument->getData()));
         if ($oImage->getOriginalWidth() > $iMaxWidth) {
             $oImage->setSize((int) $iMaxWidth, 200, Image::RESIZE_TO_WIDTH);
             ob_start();
             $oImage->render();
             $oDocument->setData(ob_get_contents());
             ob_end_clean();
         }
     }
 }
示例#13
0
#!/usr/bin/env php
<?php 
require dirname(__FILE__) . '/../lib/inc.php';
$sDir = realpath(@$argv[1]);
foreach (DocumentQuery::create()->find() as $oDocument) {
    $sFileName = "{$oDocument->getId()}_{$oDocument->getName()}.{$oDocument->getExtension()}";
    $rFile = @fopen("{$sDir}/{$sFileName}", 'x');
    if ($rFile === false) {
        echo "File {$sDir}/{$sFileName} exists. Ignoring\n";
        continue;
    }
    $rDocument = $oDocument->getData();
    while (!feof($rDocument) && ($sContents = fread($rDocument, 8192)) !== false) {
        fwrite($rFile, $sContents);
    }
    fclose($rFile);
    fclose($rDocument);
    echo "Exported {$sDir}/{$sFileName}\n";
}
 public function deleteDocument()
 {
     if ($this->iDocumentId === null) {
         return false;
     }
     $oDocument = DocumentQuery::create()->findPk($this->iDocumentId);
     $oDocument->delete();
     return true;
 }
 public static function getContentInfo($oLanguageObject)
 {
     if (!$oLanguageObject) {
         return null;
     }
     $aData = @unserialize(stream_get_contents($oLanguageObject->getData()));
     if (!$aData && !isset($aData[0])) {
         return null;
     }
     $aData = $aData[0];
     $oDocument = DocumentQuery::create()->findPk($aData['document_id']);
     return Util::nameForObject($oDocument);
 }
 public function getCriteria()
 {
     $oQuery = DocumentQuery::create()->joinDocumentType(null, Criteria::LEFT_JOIN)->joinDocumentData();
     if (!Session::getSession()->getUser()->getIsAdmin() || Settings::getSetting('admin', 'hide_externally_managed_document_categories', true)) {
         $oQuery->excludeExternallyManaged();
     }
     if ($this->oTagFilter && $this->oDelegateProxy->getListSettings()->getFilterColumnValue('has_tags') !== CriteriaListWidgetDelegate::SELECT_ALL) {
         $oQuery->filterByTagId($this->oDelegateProxy->getListSettings()->getFilterColumnValue('has_tags'));
     }
     return $oQuery;
 }
 private static function getDocumentsWithoutCategoryId()
 {
     return DocumentQuery::create()->filterByDocumentCategoryId(null, Criteria::ISNULL)->orderByName()->find()->toKeyValue('Id', 'Name');
 }
示例#18
0
 public static function fileLinkCallbackBe($oIdentifier)
 {
     $oDocument = DocumentQuery::create()->findPk($oIdentifier->getValue());
     if ($oDocument !== null) {
         return self::writeTagForIdentifier("a", array('href' => self::link($oDocument->getDisplayUrl())), $oIdentifier, null, $oDocument);
     } else {
         return self::writeTagForIdentifier("a", array('style' => "color: red;"), $oIdentifier, $oIdentifier->getParameter("link_text") . ' [Document missing!]');
     }
 }