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; } }
public static function cacheObj($document, $documentModel = null, $refreshTree = true, $parentId = null) { if (sfConfig::get('sf_cache_objects')) { // parse cachedObjects and cache objects $objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/cachedObjects.xml"); // check if documentModel is Cached $foundModel = false; if (is_null($documentModel)) { $documentModel = get_class($document); } foreach ($objects as $obj) { if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') { if ($documentModel == $obj['value']) { $foundModel = true; } } } // Caching Object if it's model is in "cachedObjects.xml" file if ($foundModel) { $docId = $document->getId(); $path = self::getCachePath($docId, true); include_once sfConfig::get('sf_root_dir') . "/config/" . "/Schema.class.php"; $m = "get" . $documentModel . "Properties"; $properties = Schema::$m(); $content = "<?php\nclass CachedObj" . $docId . "\n{\n"; $content .= "\tpublic function __getDocumentModel(){\n\t\treturn \"" . $documentModel . "\";\n\t}\n"; foreach ($properties as $getProperty) { $getter = "get" . ucfirst($getProperty); $v = $document->{$getter}(); if (is_null($v)) { $content .= "\tpublic function " . $getter . "(){\n\t\treturn NULL;\n\t}\n"; } else { if ($documentModel == "Page" && $getProperty == "Content") { $content .= "\tpublic function " . $getter . "(){\n\t\treturn \"" . str_replace(array('\\', '"'), array('\\\\', '\\"'), $v) . "\";\n\t}\n"; } else { // delete <script> tags !!! $v = preg_replace('@(<[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $v); $v = preg_replace('@(<[ \\n\\r\\t]*/[ \\n\\r\\t]*script(>|[^>]*>))@i', '', $v); $content .= "\tpublic function " . $getter . "(){\n\t\treturn \"" . str_replace(array('\\', '"'), array('\\\\', '\\"'), $v) . "\";\n\t}\n"; } } /* else { $content .= "\tpublic function ".$getter."(){\n\t\treturn ".$v.";\n\t}\n"; }*/ } if (!$parentId) { $parentId = intval(self::getParentOf($docId, null, false, false)); } $content .= "\tpublic function getParent(){\n\t\treturn {$parentId};\n\t}\n"; $content .= "}"; $cachefile = $path . "doc" . $docId . ".php"; if (file_exists($cachefile)) { unlink($cachefile); } FileHelper::writeFile($cachefile, $content); chmod($cachefile, 0777); } } // Refreshing Tree - not related to CacheObject !!! if (sfConfig::get('sf_cache_trees') && $refreshTree) { /* $modules = FileHelper::getSubElements(sfConfig::get('sf_root_dir')."/apps/backend/modules", "folder"); foreach ($modules as $module => $path) */ include_once sfConfig::get('sf_root_dir') . "/config/" . "/Schema.class.php"; $documentModel = get_class($document); $getTree = "get" . $documentModel . "Trees"; $trees = Schema::$getTree(); foreach ($trees as $module) { $module = strtolower($module); // Caching Left, Right and MCE tree BackendService::updateTree($module, $document, "UPDATE"); //BackendService::updateTree($module, $document, "UPDATE", "right"); BackendService::updateTree($module, $document, "UPDATE", "mce"); } } }