public function save($con = null, $parent = null) { try { $con = Propel::getConnection(); $con->begin(); if (!$this->getId()) { $genDoc = Document::getGenericDocument($this); $genDoc->setPublicationStatus("WAITING"); $genDoc->save(); $this->setId($genDoc->getId()); } parent::save($con); // create relationship if (!$parent && !Document::getParentOf($this->getId())) { $parent = Rootfolder::getRootfolder($this); } Relation::saveRelation($parent, $this); $con->commit(); Document::cacheObj($this, get_class($this)); return true; } catch (Exception $e) { $con->rollback(); throw $e; } }
public function save($con = null, $parent = null) { try { $con = Propel::getConnection(); $con->begin(); if (!$this->getId()) { $this->setId(Document::getGenericDocument($this)->getId()); } parent::save($con); // create relationship if (!$parent && !Document::getParentOf($this->getId())) { $parent = Rootfolder::getRootfolder($this); } Relation::saveRelation($parent, $this); $con->commit(); if (sfConfig::get('sf_cache_relations')) { Tagrelation::updateTagRelationCache(); } Document::cacheObj($this, get_class($this)); return true; } catch (Exception $e) { $con->rollback(); throw $e; } }
public function save($con = null, $parent = null) { try { $con = Propel::getConnection(); $con->begin(); if (!$this->getId()) { $this->setId(Document::getGenericDocument($this)->getId()); } parent::save($con); // create relationship if (!$parent && !Document::getParentOf($this->getId())) { $parent = Rootfolder::getRootfolder($this); } Relation::saveRelation($parent, $this); $con->commit(); Document::cacheObj($this, get_class($this)); // get Lists object if (!$parent) { $parent = Document::getParentOf($this->getId()); } // update list cache if (get_class($parent) == "Lists") { Lists::updateListCache($parent->getListId()); } return true; } catch (Exception $e) { $con->rollback(); throw $e; } }
public function executeEditBrand() { $this->setLayout(false); $ownersArr = array('' => '--- изберете ---'); $root = Rootfolder::getRootfolderByModule('clients'); $owners = Document::getChildrenOf($root->getId(), 'Client'); foreach ($owners as $ow) { $ownersArr[$ow->getId()] = $ow->getLabel(); } $this->ownersArr = $ownersArr; $this->kindsArr = UtilsHelper::loadTrademarkTypes(); return PanelService::objectEdit('search', 'Brand', $this); }
public static function getRootfolderByModule($module) { $found = false; $searchModule = $module; if (strtolower($searchModule) == 'tag') { $searchModule = 'admin'; } $formFile = sfConfig::get('sf_root_dir') . "/config/form.xml"; if (is_readable($formFile)) { $objects = XMLParser::getXMLdataValues($formFile); foreach ($objects as $obj) { if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'open') { if (strtoupper($obj['attributes']['MODULE']) == strtoupper($searchModule)) { $found = true; break; } } } } if (!$found) { //echo "getRootfolderByModule($module): not_found!"; return null; } try { $c = new Criteria(); $c->add(RootfolderPeer::LABEL, $module); $c->addOr(RootfolderPeer::LABEL, ucfirst($module)); $rootFolder = RootfolderPeer::doSelectOne($c); if (!$rootFolder) { $rootFolder = new Rootfolder(); $rootFolder->setLabel(ucfirst($module)); $rootFolder->save(); } return $rootFolder; } catch (Exception $e) { throw $e; } }
public function save($con = null, $parent = null) { try { $con = Propel::getConnection(); $con->begin(); if (trim($this->__toString()) != "") { $this->setLabel($this->__toString()); } switch ($this->getType()) { case "admin": //case "site_admin": $this->setBackend(1); break; default: $this->setBackend(0); } if ($this->getLogin() == "") { $this->setLogin($this->getEmail()); } if (!$this->getId()) { $this->setId(Document::getGenericDocument($this)->getId()); } /*if (!$this->getPublicationStatus()) { $this->setPublicationStatus(UtilsHelper::STATUS_ACTIVE); }*/ parent::save($con); // create relationship if (!$parent && !Document::getParentOf($this->getId())) { $parent = Rootfolder::getRootfolder($this); } Relation::saveRelation($parent, $this); $con->commit(); Document::cacheObj($this, get_class($this)); return true; } catch (Exception $e) { $con->rollback(); throw $e; } }
public function executeAccountCreate() { $this->setLayout(false); //assign vars $folder = Document::getDocumentByExclusiveTag("categories_folder_" . SECTION); if ($folder) { $cats = Document::getChildrenOf($folder->getId(), "Category"); foreach ($cats as $cat) { $categories[$cat->getId()] = $cat->getlabel(); } } $first = array(0 => "all categories"); $categories = $first + $categories; $this->categories = $categories; if ($this->media) { $this->cv = $this->media; } elseif ($this->user && $this->type == "user") { $cv_id = $this->user->getCv(); $cv = Document::getDocumentInstance($cv_id); $this->cv = $cv; $accpage = Document::getDocumentByExclusiveTag("website_page_account"); if ($accpage) { $this->accountPageUrl = $accpage->getHref(false); } } if ($this->media) { $this->logo = $this->media; } elseif ($this->user && $this->type == "company") { $logo_id = $this->company->getLogo(); $logo = Document::getDocumentInstance($logo_id); $this->logo = $logo; $accpage = Document::getDocumentByExclusiveTag("website_page_account"); if ($accpage) { $this->accountPageUrl = $accpage->getHref(false); } } if ($this->getRequestParameter('submitted') == "submitted") { $new = false; $search = array(",", "/", "\\", "[", "]", "?", "!", "@", "#", "\$", "~", "&", "'", '"', "=", "-", ":", ";", "*", "%", "+", "(", ")", "{", "}", "|", "§", "<", ">", "_", "“", "�?", "„", "`"); $replace = array("", "", "", "", "", "", "", "", "", "", "", "", " ", " ", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""); $params = $this->getRequest()->getParameterHolder()->getAll(); foreach ($params as $key => $param) { if (!is_array($param)) { ${$key} = trim($param); } else { ${$key} = $param; } } if ($this->user) { if ($this->user->getLogin() == "admin") { UtilsHelper::setFlashMsg("Admin account cannot be edited in frontend"); $this->noform = true; return "Success"; } UtilsHelper::setFlashMsg("Your profile has been successfully updated", UtilsHelper::MSG_SUCCESS); } else { $new = true; $code = md5(time()); $this->user = new User(); $this->user->setBackend(0); // MAKE SURE NO ACCESS TO ADMIN IS ALLOWED $this->user->setActivationCode($code); } if ($this->type == "company") { $this->user->setFirstname($firstname); $this->user->setLastname($lastname); $this->user->setEmail($email); $this->user->setPhone($phone); if (!empty($password)) { $this->user->setPassword($password); } } ////////// GET SAVE FOLDERS ////////////// $userFolders = array(); $mediaFolders = array(); $alphaFolder = false; $mediaAlphaFolder = false; $rootfolderUser = Rootfolder::getRootfolderByModule('user'); $rootfolderMedia = Rootfolder::getRootfolderByModule('media'); if ($rootfolderUser) { $folders = Document::getChildrenOf($rootfolderUser->getId(), 'Folder'); } if ($rootfolderMedia) { $foldersMedia = Document::getChildrenOf($rootfolderMedia->getId(), 'Folder'); } foreach ($folders as $folder) { $userFolders[$folder->getLabel()] = $folder->getId(); } foreach ($foldersMedia as $folder) { $mediaFolders[$folder->getLabel()] = $folder->getId(); } $title = @str_replace($search, $replace, $firstname); $title = trim(@str_replace(' ', ' ', $title)); $title = mb_strtoupper($title); $firstLetter = mb_substr($title, 0, 1); if (array_key_exists($firstLetter, $userFolders)) { $alphaFolder = Document::getDocumentInstance($userFolders[$firstLetter]); } if (array_key_exists($firstLetter, $mediaFolders)) { $mediaAlphaFolder = Document::getDocumentInstance($mediaFolders[$firstLetter]); } if (!$alphaFolder) { $alphaFolder = new Folder(); $alphaFolder->setLabel($firstLetter); $alphaFolder->save(null, $rootfolderUser); } if (!$mediaAlphaFolder) { $mediaAlphaFolder = new Folder(); $mediaAlphaFolder->setLabel($firstLetter); $mediaAlphaFolder->save(null, $rootfolderMedia); } //////////////////////////////////////// if ($this->type == "user") { if ($this->media) { $this->user->setCv($this->media->getId()); } $this->user->setEducation($education); $jobtypes = ""; foreach ($job_types as $jt) { $jobtypes .= "|"; $jobtypes .= $jt; } $this->user->setJobType($jobtypes); $saved = $this->user->save(null, $alphaFolder); } elseif ($this->type == "company") { if (!$this->company) { $this->company = new Company(); } $company_folder = Document::getDocumentByExclusiveTag("company_folder_" . $accountType); $this->company->setLabel($label); $this->company->setAccountType($accountType); $this->company->setDescription($description); $this->company->setCountry($country); $this->company->setCity($city); $this->company->setAddress($address); $this->company->setZip($xip); $this->company->setWeb($web); if ($this->media) { $this->company->setLogo($this->media->getId()); } if ($company_folder) { $this->company->save(null, $company_folder); } else { $this->company->save(); } $saved = $this->user->save(null, $this->company); } if ($this->media) { $this->media->save(null, $mediaAlphaFolder); } if ($saved) { if ($new) { $this->user->setPublicationStatus(UtilsHelper::STATUS_WAITING); $confirmMailPage = Document::getDocumentByExclusiveTag('website_page_confirm'); if ($confirmMailPage) { $data = array(); $data["user"] = $this->user; $data["password"] = $password; $data["comfirmUrl"] = $confirmMailPage->getHref(); $data["code"] = $code; $this->getUser()->setAttribute('registrationData', $data); $body = $this->getPresentationFor("user", "registrationMail"); try { UtilsHelper::sendEmail($email, $body, "Thank you for registering with Us"); UtilsHelper::setFlashMsg("Please check your email to confirm your registration", UtilsHelper::MSG_SUCCESS); $this->noform = true; } catch (Exception $e) { UtilsHelper::setFlashMsg("There was a problem while registering our account, please try again"); if ($this->user) { $this->user->delete(); } if ($this->company) { $this->company->delete(); } if ($this->media) { $this->media->delete(); } } } } } } }
function run_generate_cache($task, $args) { ini_set("memory_limit", "2048M"); ini_set("display_errors", 1); define('SF_ROOT_DIR', sfConfig::get('sf_root_dir')); define('SF_APP', 'frontend'); define('SF_ENVIRONMENT', 'dev'); define('SF_DEBUG', false); sfConfig::set("sf_use_relations_cache", false); require_once SF_ROOT_DIR . DIRECTORY_SEPARATOR . 'apps' . DIRECTORY_SEPARATOR . SF_APP . DIRECTORY_SEPARATOR . 'config' . DIRECTORY_SEPARATOR . 'config.php'; $databaseManager = new sfDatabaseManager(); $databaseManager->initialize(); run_url_relations($task, $args); run_tags_relations($task, $args); echo_cms_title("GENERATING CACHE..."); if (!class_exists("XMLParser")) { include sfConfig::get('sf_root_dir') . "/lib/tools/XMLParser.class.php"; } if (!class_exists("FileHelper")) { include sfConfig::get('sf_root_dir') . "/lib/helper/FileHelper.php"; } //echo_cms_sep(); echo_cms("sf_cache_objects = " . sfConfig::get('sf_cache_objects')); echo_cms("sf_cache_relations = " . sfConfig::get('sf_cache_relations')); echo_cms("sf_cache_trees = " . sfConfig::get('sf_cache_trees')); //echo_cms_sep(); if (count($args) > 0) { $relationsFlag = substr($args[0], 0, 3) == "rel"; $listsFlag = substr($args[0], 0, 4) == "list"; $cacheModel = $args[0]; if (is_numeric($cacheModel)) { $obj = Document::getDocumentInstance($cacheModel); if ($obj) { $phpName = get_class($obj); } else { echo_cms_error("Object with ID=" . $cacheModel . " not found!"); exit; } } } // parse schema file to make Schema.class.php $objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/schema.xml"); $schemaFile = sfConfig::get('sf_root_dir') . "/config/Schema.class.php"; $content = $content = "<?php\n class Schema\n{\n\n"; echo_cms("Building " . $schemaFile . "... "); foreach ($objects as $obj) { if ($obj['tag'] == 'TABLE' && $obj['type'] == 'open') { $table = $obj['attributes']['PHPNAME']; if ($phpName && $phpName == $table) { $tableName = $obj['attributes']['NAME']; } $trees = explode(",", $obj['attributes']['TREE']); $content .= "\tpublic static function get" . $table . "Trees()\n\t{\n"; $content .= "\t\treturn array("; foreach ($trees as $tree) { $content .= "'" . strtolower($tree) . "', "; } $content = substr($content, 0, -2); $content .= ");\n\t}\n\n"; $content .= "\tpublic static function get" . $table . "Properties()\n\t{\n"; $content .= "\t\treturn array("; } if ($obj['tag'] == 'COLUMN' && $obj['type'] == 'complete') { $property = $obj['attributes']['NAME']; $getProperty = UtilsHelper::convertFieldName($property); $content .= "'" . $getProperty . "', "; } if ($obj['tag'] == 'TABLE' && $obj['type'] == 'close') { $content = substr($content, 0, -2); $content .= ");\n\t}\n\n"; } } $content .= "\n}"; //echo_cms_sep(); if (FileHelper::writeFile($schemaFile, $content)) { echo_cms($schemaFile . " writen successfully!"); } else { echo_cms_error("Error writing " . $schemaFile . "!"); } echo "\n"; //echo_cms_sep(); if (substr($args[0], 0, 5) == "schema") { echo_cms(" Done!"); exit; } if (!$relationsFlag && !$listsFlag) { try { if (is_numeric($cacheModel)) { $obj = array(); $obj['tag'] = 'OBJECT'; $obj['type'] = 'complete'; $obj['id'] = $cacheModel; $objects = array($obj); $exit = true; } elseif ($cacheModel) { $obj = array(); $obj['tag'] = 'OBJECT'; $obj['type'] = 'complete'; $obj['value'] = $cacheModel; $objects = array($obj); $exit = true; } else { $objects = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/config/cachedObjects.xml"); } foreach ($objects as $obj) { if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') { if ($id = $obj['id']) { $obj = Document::getDocumentInstance($id); $model = get_class($obj); $c = new Criteria(); $c->add($tableName . '.ID', $id); } else { $model = $obj['value']; $c = new Criteria(); } $classPeer = ucfirst($model) . "Peer"; //$c = new Criteria(); //$results = call_user_func(array($classPeer, 'doSelect'), $c); $peerMethod = "doSelect"; $results = call_user_func(array($classPeer, $peerMethod), $c); echo_cms(" Caching " . $model . " documents"); $ind = 0; foreach ($results as $result) { if ($ind % 20 == 0) { echo $ind . " .\r"; } else { if ($ind % 10 == 0) { echo $ind . " o\r"; } } $ind++; Document::cacheObj($result, $model, false); } echo_cms(" ====> " . $ind . " " . $model . " Document(s) cached."); //echo_cms_sep(); } } if ($exit) { exit; } } catch (Expection $e) { echo_cms_error(" Error: {$e}"); } } if (!$listsFlag) { echo "\n"; //echo_cms_sep(); echo_cms("Writing relations cache"); Relation::checkRelationCache('lock'); try { $c = new Criteria(); $c->addAscendingOrderByColumn('id1'); $c->addAscendingOrderByColumn('document_model2'); $c->addAscendingOrderByColumn('sort_order'); $relations = RelationPeer::doSelect($c); $relationsFile = sfConfig::get('sf_root_dir') . "/cache/objcache/childrenRelations.php"; echo_cms("Processing children :"); $i = 0; $content = "<?php \n"; $oldIDModel = ''; $currIDModel = ''; $idStr = ''; foreach ($relations as $relation) { $currIDModel = $relation->getId1() . ':' . $relation->getDocumentModel2(); if ($i == 0) { $oldIDModel = $currIDModel; } $i++; echo $i . "\t\t\r"; if ($currIDModel == $oldIDModel) { $idStr .= "," . $relation->getId2(); } else { $idStr = substr($idStr, 1); $content .= "\$_Rel[" . $oldId1 . "][\"" . $oldModel2 . "\"] = explode(\",\", \"" . $idStr . "\");\n"; $idStr = "," . $relation->getId2(); } $oldIDModel = $currIDModel; $oldId1 = $relation->getId1(); $oldModel2 = $relation->getDocumentModel2(); } if ($idStr) { $idStr = substr($idStr, 1); $content .= "\$_Rel[" . $oldId1 . "][\"" . $oldModel2 . "\"] = explode(\",\", \"" . $idStr . "\");\n"; } echo "\n"; $content .= "\n?>"; //echo_cms_sep(); if (FileHelper::writeFile($relationsFile, $content)) { echo_cms($relationsFile . " written successfully"); } else { echo_cms_error("Error writing " . $relationsFile . " !"); } //echo_cms_sep(); } catch (Exception $e) { echo "Error: " . $e->getMessage(); } Relation::checkRelationCache('unlock'); } if (!$relationsFlag) { echo "\n"; //echo_cms_sep(); echo_cms_title("Writing Lists cache"); $listsRootFolder = Rootfolder::getRootfolderByModule("lists"); if ($listsRootFolder) { $lists = Document::getChildrenOf($listsRootFolder->getId(), "Lists"); } foreach ($lists as $list) { $listId = $list->getListId(); echo "\t\tprocessing \"" . $listId . "\" list ..."; $listPath = sfConfig::get('sf_root_dir') . "/cache/listscache/" . $listId . ".php"; @unlink($listPath); $content = "<?php \n"; $content .= "\$listItemsForSelect = array(\n"; $items = Lists::getListitemsForSelect($listId, array(), false); foreach ($items as $key => $item) { $content .= "\"" . str_replace("\"", "\\\"", $key) . "\" => \"" . str_replace("\"", "\\\"", $item) . "\",\n"; } $content .= ");\n?>"; if (FileHelper::writeFile($listPath, $content)) { echo_cms(" Done!"); } else { echo_cms_error(" Error!"); } } //echo_cms_sep(); } sfConfig::set("sf_use_relations_cache", true); }
public static function getSiteMap($root = null, &$sitemap, $depth = 1000, $level = 1, $path = null, $getIndex = false, $getInvisible = false) { if ($level > $depth) { return array(); } $nolabel = UtilsHelper::Localize("website.frontend.nolabel"); if (!$root) { $root = Rootfolder::getRootfolderByModule("website"); if (!$root) { return; } } if (is_object($root)) { $root = $root->getId(); } $pathSet = false; if (Document::hasChildren($root)) { // $oldRelationsFlag = sfConfig::get('sf_cache_relations'); // sfConfig::set('sf_cache_relations', false); try { $children = Document::getChildrenOf($root, null, true, false); foreach ($children as $child) { // skip Urlrewrite objects if (get_class($child) == "Urlrewrite" || get_class($child) == "Media") { continue; } $href = ""; $label = $nolabel; $childId = $child->getId(); $class = get_class($child); $showItem = true; if (Document::getStatus($child) != UtilsHelper::STATUS_ACTIVE) { continue; } if (!$getIndex && Document::hasTag($child, "website_page_index")) { continue; } if (!$getInvisible) { if ($class == 'Page' && Document::hasTag($child, "website_page_nonvisible") || $class == 'Topic' && Document::hasTag($child, "website_topic_nonvisible")) { $id = $childId; $showItem = false; //continue; } } if ($showItem) { if ($class == "Page") { $type = $child->getPageType(); $secure = $child->getIsSecure(); //$label = $child->getLabel(); $label = $child->getNavigationTitle(); $href = $child->getHref(); $id = $childId; } elseif ($class == "Topic") { $label .= $child->getLabel(); // " (".$child->getLabel().")"; $indexPage = $child->getIndexPage(); $id = 0; if ($indexPage) { //$id = $indexPage->getId(); $id = $childId; $href = $indexPage->getHref(); $label = $indexPage->getLabel(); $type = $indexPage->getPageType(); // if ($type == "REFERENCE") // { // //echo "--- Topic: ".$id." ---\n"; // $pg = Document::getDocumentByCulture($indexPage->getPageId(), null, true); // get PageI18n object // if($pg) // { // $id = $pg->getId(); // $href = $pg->getHref(); // $secure = $pg->getIsSecure(); // } // } } } else { $id = $childId; $label = $child->getLabel(); } } if ($id && !$pathSet) { $path[] = $id; $pathSet = true; } else { $c = count($path); $path[$c - 1] = $id; } $sitemap[$root][$childId]['path'] = $path; $sitemap[$root][$childId]['id'] = $id; $sitemap[$root][$childId]['href'] = $href; $sitemap[$root][$childId]['label'] = $label; if (array_key_exists('secure', $sitemap[$root][$childId])) { $sitemap[$root][$childId]['secure'] = $secure; } $sitemap[$root][$childId]['level'] = $level; $sitemap[$root][$childId]['model'] = $class; $sitemap[$root][$childId]['show'] = $showItem; self::getSiteMap($child->getId(), $sitemap, $depth, $level + 1, $path, $getIndex, $getInvisible); } } catch (Exception $e) { return null; } // sfConfig::set('sf_cache_relations', $oldRelationsFlag); } return $sitemap; }
public function executeParentsTree() { $this->moduleName = $module = $this->getRequestParameter("m"); if ($p = $this->getRequestParameter('p')) { $document = Document::getDocumentInstance($p); } if (isset($document) && $document) { $class = get_class($document); } else { $class = 'Rootfolder'; } $user = $this->getUser()->getSubscriber(); $rights = PanelService::getUserRights($user, $class, $module); $this->module_rights = $rights; if ($module == "labels") { $this->tree = array('labels', $this->getRequestParameter("id")); return "Success"; } if ($module == "settings") { $this->tree = array('settings', $this->getRequestParameter("id")); return "Success"; } $id = $this->getRequestParameter('id'); if (!$id) { $id = $this->getRequestParameter('p'); } if (!$id) { $id = $this->getRequestParameter('parent'); } if (!$id) { $root = Rootfolder::getRootfolderByModule($module); if ($root) { $id = $root->getId(); } } if ($id) { $this->tree = Document::getParentsTree($id); } }
public static function getMceTree($moduleName) { $lmn = strtolower($moduleName); $moduleName = ucfirst($lmn); $htmlCacheFile = sfConfig::get('sf_root_dir') . "/cache/backend/" . $moduleName . "_mceTree.html"; if (is_readable($htmlCacheFile)) { $content = file_get_contents($htmlCacheFile); return $content; } $phpFile = sfConfig::get('sf_root_dir') . "/cache/backend/" . $moduleName . "_mceTree.php"; if (is_readable($phpFile)) { return self::makeHtmlCache($moduleName, "mce"); } $rightTree = XMLParser::getXMLdataValues(sfConfig::get('sf_root_dir') . "/apps/backend/modules/" . $lmn . "/config/mceTree.xml"); $displayedObjects = array(); foreach ($rightTree as $obj) { if ($obj['tag'] == 'OBJECT' && $obj['type'] == 'complete') { $displayedObjects[] = $obj['value']; } } $document = Rootfolder::getRootfolderByModule($moduleName); $docId = $document->getId(); $contentArr = self::makePhpArray($docId, $lmn, $displayedObjects); // make Root element $rootItem = array(); $rootItem[$docId]['id'] = $document->getId(); $rootItem[$docId]['model'] = 'rootfolder'; $rootItem[$docId]['class'] = $lmn . '_rootfolder'; $rootItem[$docId]['level'] = 0; $rootItem[$docId]['label'] = addslashes($document->getLabel()); $contentArr = array_merge($rootItem, $contentArr); return self::makePhpCache($contentArr, $moduleName, "mce"); }
public function save($con = null, $parent = null, $refreshTree = true) { try { $con = Propel::getConnection(); $con->begin(); $genericDoc = Document::getGenericDocument($this); if (!$this->getId()) { $this->setId($genericDoc->getId()); } parent::save($con); // create relationship if (!$parent) { $parent = Document::getParentOf($this->getId(), null, true, false); if (empty($parent)) { $parent = Rootfolder::getRootfolder($this); } } Relation::saveRelation($parent, $this); $con->commit(); Document::cacheObj($this, "Media", $refreshTree); return true; } catch (Exception $e) { $con->rollback(); throw $e; } }
public static function updateListCache($listId = null) { if ($listId) { $list = Lists::getListByListId($listId); $lists = array($list); } else { if ($listsRootFolder = Rootfolder::getRootfolderByModule("lists")) { $lists = Document::getChildrenOf($listsRootFolder->getId(), "Lists"); } } foreach ($lists as $list) { $listId = $list->getListId(); $listPath = sfConfig::get('sf_root_dir') . "/cache/listscache/" . $listId . ".php"; @unlink($listPath); $content = "<?php \n"; $content .= "\$listItemsForSelect = array(\n"; $items = Lists::getListitemsForSelect($listId, array(), false); foreach ($items as $key => $item) { $content .= "\"" . str_replace("\"", "\\\"", $key) . "\" => \"" . str_replace("\"", "\\\"", $item) . "\",\n"; } $content .= ");\n?>"; FileHelper::writeFile($listPath, $content); } }
public static function objectSave(&$obj, &$parent, $documentName = null) { try { $parameters = sfContext::getInstance()->getRequest()->getParameterHolder()->getAll(); if (!$documentName) { $documentName = $parameters["documentName"]; } if (!$parent) { $parent = Document::getDocumentInstance($parameters['parent']); } if (!$parent) { if (isset($parameters["parentModule"])) { $parent = Rootfolder::getRootfolderByModule($parameters["parentModule"]); } else { $parent = Rootfolder::getRootfolderByModule($moduleName); } } if (!is_object($obj)) { if (is_numeric($parameters['id']) && !$parent) { $obj = Document::getDocumentInstance($parameters['id']); $parent = Document::getParentOf($parameters['id']); $documentName = $parameters["documentName"]; } else { $obj = new $documentName(); } } include_once sfConfig::get('sf_root_dir') . "/config/Schema.class.php"; $m = "get" . $documentName . "Properties"; $properties = Schema::$m(); $contentArr = array(); foreach ($parameters as $key => $value) { // parse Content attribute/s for Page if ($documentName == "Page" && substr($key, 0, 11) == 'attrContent' && $key > 'attrContent' && in_array('Content', $properties)) { $ind = intval(substr($key, 11)); // check if creating NEW Page if ($ind == 0) { $ind = 1; } $contentArr[$parameters['contentID' . $ind]] = '<block id="' . $parameters['contentID' . $ind] . '" target="' . $parameters['contentTarget' . $ind] . '" action="richtext"><![CDATA[' . $value . ']]></block>'; } else { if (!(strpos($key, 'attr') === false) && $key != "attrRewriteUrl") { if ($value == '') { $value = null; } $key = str_replace('attr', '', $key); if ($properties && $key != "Password" && !in_array($key, $properties)) { continue; } if ($key == "Password" && empty($value)) { continue; } $function = 'set' . $key; if (is_array($value)) { // date field if (array_key_exists('year', $value) || array_key_exists('month', $value) || array_key_exists('day', $value)) { //$value = implode('-', $value); // $date = $value['year'].'-'.str_pad($value['month'], 2, "0", STR_PAD_LEFT).'-'.str_pad($value['day'], 2, "0", STR_PAD_LEFT); // 2009-02-09 16:10:20 $date = implode('-', $value); if ($value['hour'] && $value['minute']) { // if 'include_custom' is used if (empty($value['year']) || empty($value['month']) || empty($value['day']) || empty($value['hour']) || empty($value['minute'])) { $value = null; } else { $time = $value['hour'] . ':' . $value['minute']; $value = $date . ' ' . $time; } } else { // if 'include_custom' is used if (empty($value['year']) && empty($value['month']) && empty($value['day'])) { $value = null; } else { $value = $date; } } } else { $value = implode(";", $value); } } if ($key == "Related") { if ($value) { $value = '[' . str_replace(';', '][', $value) . ']'; $value = str_replace('[]', '', $value); } } if ($key == "Keywords") { if ($value) { $value = '[' . str_replace(',', '][', $value) . ']'; $value = str_replace('[]', '', $value); } } $obj->{$function}($value); } } } // Page content save if ($documentName == 'Page' && count($contentArr) > 0) { // add original NON-RICHTEXT content blocks $orgContent = $obj->getContent(); $blocks = self::get_content_blocks($orgContent); foreach ($blocks as $name => $block) { $contentArr[$name] = '<block id="' . $name . '" target="' . $block['target'] . '" action="' . $block['action'] . '"><![CDATA[' . $block['content'] . ']]></block>'; } $allBlocks = PanelService::get_all_content_blocks($orgContent); $content = ''; foreach ($allBlocks as $blockName => $blockData) { $content .= $contentArr[$blockName]; } $content = '<?xml version="1.0" encoding="UTF-8"?><blocks>' . $content . '</blocks>'; $obj->setContent($content); } if ($documentName == "Page") { $obj->setRewriteUrl($parameters["attrRewriteUrl"]); } $obj->save(null, $parent); if ($tags = Document::getAvailableTagsOf($parameters['moduleName'], $documentName)) { foreach ($tags as $tag) { if ($parameters['tag_id_' . $tag->getId()]) { Document::addTag($obj, $tag->getTagId()); } else { Document::removeTag($obj, $tag->getTagId()); } } Tagrelation::updateTagRelationCache(); } //UtilsHelper::setBackendMsg("Saved"); } catch (Exception $e) { throw $e; } }
public function executeAddSearchTemplate() { $this->setLayout(false); $root = Rootfolder::getRootfolderByModule('search'); $brands = Document::getChildrenOf($root->getId(), 'Brand'); foreach ($brands as $b) { $brandsArr[$b->getId()] = $b->getLabel(); } $this->brands = $brandsArr; $success = false; if ($objId = $this->getRequestParameter('obj_id')) { $search = Document::getDocumentInstance($objId); //var_dump($search); } else { $search = new Search(); } if ($this->getRequestParameter('submit') > '') { // check input data $request = $this->getRequest(); $params = $request->getParameterHolder()->getAll(); //var_dump($params); $brandId = $params['brand']; $brand = Document::getDocumentInstance($brandId); //var_dump($brand); $fields = array('label', 'application_number', 'register_number', 'registration_date', 'application_date', 'expires_on', 'vienna_classes', 'nice_classes', 'rights_owner', 'rights_representative', 'office_of_origin', 'designated_contracting_party'); /* $search->setLabel($params['label']); $search->setRightsOwner($params['rights_owner']); $search->setApplicationNumber($params['application_number']); $search->setRegisterNumber($params['register_number']); $search->setRegistrationDate ($params['registration_date']); $search->setApplicationDate($params['application_date']); $search->setStatus($params['status']); $search->setExpiresOn($params['expires_on']); $search->setViennaClasses($params['vienna_classes']); $search->setNiceClasses($params['nice_classes']); //$search->setrightsOwnerAddress($params['rights_owner_address']); $search->setRightsRepresentative($params['rights_representative']); //$search->setRightsRepresentativeAddress($params['rights_representative_address']); $search->setOfficeOfOrigin($params['office_of_origin']); $search->setDesignatedContractingParty($params['designated_contracting_party']); */ $notEmpty = 0; foreach ($fields as $fl) { $setter = 'set' . UtilsHelper::convertFieldName($fl); if (isset($params[$fl])) { $v = trim($params[$fl]); if ($v) { $notEmpty++; } $search->{$setter}($v); } else { $search->{$setter}(null); } } if ($notEmpty > 0) { $search->save(null, $brand); $success = true; } else { UtilsHelper::setFlashMsg('Моля, въведете критерии за търсене!', UtilsHelper::MSG_ERROR); } //var_dump($search); } $this->success = $success; $this->obj = $search; }
public function executeAddNewTrademark() { $this->setLayout(false); $this->trademarkTypes = UtilsHelper::loadTrademarkTypes(); if ($trademark = Document::getDocumentInstance($this->getRequestParameter('trademark_id'))) { if (get_class($trademark) != 'Trademark') { $trademark = null; } } if (!$trademark) { $trademark = new Trademark(); } $ownersArr = array(); $root = Rootfolder::getRootfolderByModule('clients'); $owners = Document::getChildrenOf($root->getId(), 'Client'); foreach ($owners as $ow) { $ownersArr[$ow->getId()] = $ow->getLabel(); } $this->ownersArr = $ownersArr; $success = false; if ($this->getRequestParameter('submit') > '') { // check input data $request = $this->getRequest(); $params = $request->getParameterHolder()->getAll(); //var_dump($params); $errors = false; $fields = array("label" => 'Наименование', "application_number" => 'Заявка номер', "kind" => 'Тип', "application_date" => 'Дата на заявяване', "expires_on" => 'Срок', "contestation" => 'Краен срок за опозиция', "nice_classes" => 'Класове по Ницска класификация', "rights_owner" => 'Притежател', "office_of_origin" => 'Държава на регистрация', "designated_contracting_party" => 'Държави в които е в сила'); foreach ($fields as $fl => $label) { $val = trim($params[$fl]); if ($val == '') { if ($fl == 'rights_owner') { if ($params['owner'] == '') { $errors = true; $request->setError('err' . $fl, '- ' . $label); } } else { $errors = true; $request->setError('err' . $fl, '- ' . $label); } } } $image = null; if ($errors) { UtilsHelper::setFlashMsg('Моля, въведете необходимите данни:<br>', UtilsHelper::MSG_ERROR); } else { if ($request->getFileName('image')) { try { $image = Media::upload('image', 'upload', array('image/gif', 'image/jpeg', 'image/jpg', 'image/png')); //var_dump($image); list($w, $h) = getimagesize($image->getServerAbsoluteUrl()); if ($w > $h) { $image->resizeImage("thumbs", null, 105); } else { $image->resizeImage("thumbs", 95); } } catch (Exception $e) { $errors = true; $request->setError('errImage', '- ' . UtilsHelper::Localize('media.' . $e->getMessage())); } } if ($errors) { // remove uploaded image if ($image) { $image->delete(); } UtilsHelper::setFlashMsg('Моля, коригирайте:<br>', UtilsHelper::MSG_ERROR); } } // if everithing is OK if (!$errors) { //$trademark = new Brand(); $trademark->setLabel($params['label']); $trademark->setFromSystem(1); if ($params['owner'] > '') { //$trademark->setClientId($params['owner']); $client = Document::getDocumentInstance($params['owner']); $trademark->setRightsOwner($client->getLabel()); } else { $val = trim($params['rights_owner']); $client = new Client(); $client->setLabel($val); $client->save(); //$trademark->setClientId($client->getId()); $this->client = $client; $trademark->setRightsOwner($val); } $trademark->setApplicationNumber($params['application_number']); $trademark->setRegisterNumber($params['register_number']); if ($params['registration_date']) { $trademark->setRegistrationDate($params['registration_date']); } $trademark->setKind($params['kind']); $trademark->setApplicationDate($params['application_date']); $trademark->setStatus($params['status']); $trademark->setExpiresOn($params['expires_on']); $trademark->setContestation($params['contestation']); $trademark->setPublications($params['publications']); $trademark->setViennaClasses(str_replace(' ', '', $params['vienna_classes'])); $trademark->setColors($params['colors']); $trademark->setNiceClasses(str_replace(' ', '', $params['nice_classes'])); $trademark->setRightsOwnerAddress($params['rights_owner_address']); $trademark->setRightsRepresentative($params['rights_representative']); $trademark->setRightsRepresentativeAddress($params['rights_representative_address']); $trademark->setOfficeOfOrigin($params['office_of_origin']); $trademark->setDesignatedContractingParty($params['designated_contracting_party']); if ($image) { $trademark->setImage($image->getId()); } $trademark->save(); $success = true; } } $this->trademark = $trademark; $this->success = $success; }
function InitData($project_name) { $listPageType = 'list_types'; $c = new Criteria(); $c->add(ListsPeer::LIST_ID, $listPageType); $listExist = ListsPeer::doSelectOne($c); if (!$listExist) { echo "Creating list 'list_type'...\n"; $newList = new Lists(); $newList->setLabel('List Types'); $newList->setListid($listPageType); $newList->setListtype('system'); $newList->save(); $newItem = new Listitem(); $newItem->setLabel('System list'); $newItem->setValue('system'); $newItem->save(null, $newList); $newItem = new Listitem(); $newItem->setLabel('Static list'); $newItem->setValue('static'); $newItem->save(null, $newList); $newItem = new Listitem(); $newItem->setLabel('Editable list'); $newItem->setValue('editable'); $newItem->save(null, $newList); } $listPageType = 'page_types'; $c = new Criteria(); $c->add(ListsPeer::LIST_ID, $listPageType); $listExist = ListsPeer::doSelectOne($c); if (!$listExist) { echo "Creating list 'page_types'...\n"; $newList = new Lists(); $newList->setLabel('Page Types'); $newList->setListid($listPageType); $newList->setListtype('system'); $newList->save(); $newItem = new Listitem(); $newItem->setLabel('Content page'); $newItem->setValue('CONTENT'); $newItem->save(null, $newList); $newItem = new Listitem(); $newItem->setLabel('Page reference'); $newItem->setValue('REFERENCE'); $newItem->save(null, $newList); $newItem = new Listitem(); $newItem->setLabel('External page'); $newItem->setValue('EXTERNAL'); $newItem->save(null, $newList); } $cultureType = 'culture'; $c = new Criteria(); $c->add(ListsPeer::LIST_ID, $cultureType); $listExist = ListsPeer::doSelectOne($c); if (!$listExist) { echo "Creating list 'culture'...\n"; $newList = new Lists(); $newList->setLabel('Culture'); $newList->setListid($cultureType); $newList->setListtype('system'); $newList->save(); $newItem = new Listitem(); $newItem->setLabel('english'); $newItem->setValue('en'); $newItem->save(null, $newList); /* $newItem = new Listitem(); $newItem->setLabel('български'); $newItem->setValue('bg'); $newItem->save(null, $newList);*/ } $userType = 'usertype'; $c = new Criteria(); $c->add(ListsPeer::LIST_ID, $userType); $listExist = ListsPeer::doSelectOne($c); if (!$listExist) { echo "Creating list 'user types'...\n"; $newList = new Lists(); $newList->setLabel('User Types'); $newList->setListid($userType); $newList->setListtype('system'); $newList->save(); $newItem = new Listitem(); $newItem->setLabel('Administrator (all rights)'); $newItem->setValue('admin'); $newItem->save(null, $newList); $newItem = new Listitem(); $newItem->setLabel('Editor (no access to administration modules)'); $newItem->setValue('editor'); $newItem->save(null, $newList); $newItem = new Listitem(); $newItem->setLabel('Editor (edit and save existing items)'); $newItem->setValue('restricted_editor'); $newItem->save(null, $newList); } $Mailinglist_Folder = Document::getDocumentByExclusiveTag('newsletter_folder_mailinglist'); if (!$Mailinglist_Folder) { $Newsletter_Root = Rootfolder::getRootfolderByModule('Newsletter'); $Mailinglist_Folder = new Folder(); $Mailinglist_Folder->setLabel('Mailing lists'); $Mailinglist_Folder->save(null, $Newsletter_Root); Document::addTag($Mailinglist_Folder, 'newsletter_folder_mailinglist'); } $def_site = Document::getDocumentByExclusiveTag('website_website_default'); if (!$def_site) { $website_root = Rootfolder::getRootfolderByModule('Website'); $def_site = new Website(); $def_site->setLabel(UtilsHelper::mb_ucfirst($project_name)); $def_site->save(null, $website_root); Document::addTag($def_site, 'website_website_default'); } $homePage = Document::getDocumentByExclusiveTag('website_page_home'); if (!$homePage) { $homePage = new Page(); $homePage->setLabel('Home'); $homePage->setPageType('CONTENT'); $homePage->setNavigationTitle('Home'); $homePage->setTemplate('default'); $homePage->save(null, $def_site); Document::addTag($homePage, 'website_page_home'); } }