Exemplo n.º 1
0
Arquivo: Topic.php Projeto: kotow/work
 public function getIndexPage()
 {
     try {
         $c = new Criteria();
         $c->add(TagPeer::TAG_ID, 'website_page_index');
         $tag = TagPeer::doSelectOne($c);
         $c = new Criteria();
         $c->add(RelationPeer::ID1, $this->getId());
         $c->addJoin(RelationPeer::ID2, TagrelationPeer::ID);
         $c->add(TagrelationPeer::TAG_ID, $tag->getId());
         $relation = RelationPeer::doSelectOne($c);
         if ($relation) {
             $indexPage = Document::getDocumentInstance($relation->getId2());
             return $indexPage;
         } else {
             return null;
         }
     } catch (Exception $e) {
         throw $e;
     }
 }
Exemplo n.º 2
0
 public static function orderDocument($documentId, $up = true)
 {
     try {
         $con = Propel::getConnection();
         $con->begin();
         $c = new Criteria();
         $c->add(RelationPeer::ID2, $documentId);
         $relation = RelationPeer::doSelectOne($c);
         $c = new Criteria();
         $c->add(RelationPeer::ID1, $relation->getId1());
         if ($up) {
             $c->addDescendingOrderByColumn(RelationPeer::SORT_ORDER);
             $criterion = $c->getNewCriterion(RelationPeer::SORT_ORDER, $relation->getSortOrder(), Criteria::LESS_THAN);
         } else {
             $c->addAscendingOrderByColumn(RelationPeer::SORT_ORDER);
             $criterion = $c->getNewCriterion(RelationPeer::SORT_ORDER, $relation->getSortOrder(), Criteria::GREATER_THAN);
         }
         $c->add($criterion);
         $previousRelation = RelationPeer::doSelectOne($c);
         if ($previousRelation) {
             $previousSortOrder = $previousRelation->getSortOrder();
             $previousRelation->setSortOrder($relation->getSortOrder());
             $previousRelation->save();
             $relation->setSortOrder($previousSortOrder);
             $relation->save();
             if (sfConfig::get('sf_cache_relations')) {
                 if ($relation) {
                     self::updateRelationCache($relation->getId1());
                 }
             }
         }
         if (SF_APP == "backend" && sfConfig::get('sf_cache_trees')) {
             $user = sfContext::getInstance()->getUser();
             $moduleName = $user->getAttribute("currentModule");
             $document = Document::getDocumentInstance($documentId);
             if ($up) {
                 BackendService::updateTree($moduleName, $document, "UP");
                 //BackendService::updateTree($moduleName, $document, "UP", "right");
                 //BackendService::updateTree($moduleName, $document, "UP", "mce");
             } else {
                 BackendService::updateTree($moduleName, $document, "DOWN");
                 //BackendService::updateTree($moduleName, $document, "DOWN", "right");
                 //BackendService::updateTree($moduleName, $document, "DOWN", "mce");
             }
         }
         $con->commit();
     } catch (Exception $e) {
         $con->rollback();
         throw $e;
     }
 }
Exemplo n.º 3
0
 public static function getParentOf($id, $model = null, $createInstance = true, $useCache = true)
 {
     $parent = $parentId = null;
     try {
         $found = false;
         $load = true;
         if ($useCache) {
             $objclass = "CachedObj" . $id;
             if (!class_exists($objclass)) {
                 $cacheFile = self::getCachePath($id) . "doc" . $id . ".php";
                 if (is_readable($cacheFile)) {
                     include self::getCachePath($id) . "doc" . $id . ".php";
                 } else {
                     $load = false;
                 }
             }
             if ($load) {
                 $cachedObj = new $objclass();
                 if (method_exists($cachedObj, 'getParent')) {
                     $parentId = $cachedObj->getParent();
                     $found = true;
                 }
             }
         }
         if (!$found) {
             $c = new Criteria();
             $c->add(RelationPeer::ID2, $id);
             if ($model) {
                 $c->add(RelationPeer::DOCUMENT_MODEL1, $model);
             }
             $parent = RelationPeer::doSelectOne($c);
             if ($parent) {
                 $parentId = $parent->getId1();
             }
         }
         if ($parentId) {
             if ($createInstance) {
                 $parent = self::getDocumentInstance($parentId);
             } else {
                 $parent = $parentId;
             }
         }
         return $parent;
     } catch (Exception $e) {
         throw $e;
     }
 }