public function delete($con = null) { try { $con = Propel::getConnection(); $con->begin(); //deletes generic document $genericDocument = Document::getGenericDocument($this); $genericDocument->delete(); //deletes any tags for this document $c = new Criteria(); $c->add(TagrelationPeer::TAG_ID, $this->getId()); $tagRelations = TagrelationPeer::doSelect($c); foreach ($tagRelations as $tag) { $tag->delete(); } parent::delete(); $con->commit(); if (sfConfig::get('sf_cache_relations')) { Tagrelation::updateTagRelationCache(); } Document::deleteObjCache($this); return true; } catch (Exception $e) { $con->rollback(); throw $e; } }
public function executeSave() { try { $parameters = $this->getRequest()->getParameterHolder()->getAll(); $parameters['documentName'] == "Folder" ? $moduleName = "Admin" : ($moduleName = $parameters['moduleName']); $documentName = $parameters["documentName"]; $parent = Document::getDocumentInstance($parameters['parent']); if (is_numeric($parameters['id'])) { $obj = Document::getDocumentInstance($parameters['id']); $parent = Document::getParentOf($parameters['id']); } else { $obj = new $documentName(); } include_once sfConfig::get('sf_root_dir') . "/config/Schema.class.php"; $m = "get" . $documentName . "Properties"; $properties = Schema::$m(); //exit(var_dump($properties)); $imageFields = explode(",", $parameters['imageFields']); /*foreach ($parameters as $property) { $function = 'set'.$property; $obj->$function(); }*/ foreach ($parameters as $key => $value) { if (!(strpos($key, 'attr') === false) && $key != "attrRewriteUrl") { $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 = $value['year'] . '-' . $value['month'] . '-' . $value['day']; // 2009-02-09 16:10:20 if ($value['hour'] && $value['minute']) { $time = $value['hour'] . ':' . $value['minute']; $value = $date . ' ' . $time; } else { $value = $date; } } if (in_array($key, $imageFields)) { $getFunction = 'get' . $key; $imgId = $obj->{$getFunction}(); if ($imgId != $value) { $img = Document::getDocumentInstance($imgId); if ($img) { $imgExt = $img->getExtention(); @unlink(sfConfig::get('sf_root_dir') . "/www/media/upload/thumbs/" . $parameters["moduleName"] . "/" . $imgId . "-" . $key . "." . $imgExt); } } } if ($key == "Keywords") { if ($value) { $value = str_replace(',', '][', $value); $value = '[' . substr($value, 0, -1); } } $obj->{$function}($value); } if (in_array($key, $imageFields) && !empty($value)) { $image = Document::getDocumentInstance($value); if ($image) { if (empty($parameters[$key . '_thumbheight'])) { $parameters[$key . '_thumbheight'] = null; } if (empty($parameters[$key . '_thumbwidth'])) { $parameters[$key . '_thumbwidth'] = null; } $image->resizeImage($parameters["moduleName"], $parameters[$key . '_thumbheight'], $parameters[$key . '_thumbwidth'], $key); } } } if (class_exists($documentName . "I18n") && $documentName != "Listitem") { if (!($culture = $parameters["attrCulture"])) { $culture = Document::getDocumentByExclusiveTag("default_culture"); if ($culture) { $culture = $culture->getValue(); } else { throw new Exception("No default culture defined"); } } $obj->save(null, $parent, $culture); if (!$parameters["id"]) { if (class_exists($documentName . "I18n")) { BackendService::objectSave($objI8n, $obj, $documentName . "I18n"); if ($documentName == "Page") { $objI8n->setRewriteUrl($parameters["attrRewriteUrl"]); } $objI8n->setCulture($culture); $objI8n->save(null, $obj, $culture); } $request = $this->getRequest(); $request->setParameter("id", $obj->getId()); } } else { $obj->save(null, $parent); } $tags = Document::getAvailableTagsOf($moduleName, $parameters['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) { UtilsHelper::setBackendMsg("Error while saving: " . $e->getMessage(), "error"); } $this->forward(strtolower($moduleName), "edit" . $parameters['documentName']); exit; }
public function executeSave() { $hasError = false; try { $parameters = $this->getRequest()->getParameterHolder()->getAll(); $moduleName = $parameters['moduleName']; $documentName = $parameters["documentName"]; $parent = Document::getDocumentInstance($parameters['parent']); if (!$parent) { if (isset($parameters["parentModule"])) { $parent = Rootfolder::getRootfolderByModule($parameters["parentModule"]); } else { $parent = Rootfolder::getRootfolderByModule($moduleName); } } if (is_numeric($parameters['id'])) { $obj = Document::getDocumentInstance($parameters['id']); $parent = Document::getParentOf($parameters['id']); } else { $obj = new $documentName(); } include_once sfConfig::get('sf_root_dir') . "/config/Schema.class.php"; $m = "get" . $documentName . "Properties"; $properties = Schema::$m(); if (isset($parameters['imageFields'])) { $imageFields = explode(",", $parameters['imageFields']); } else { $imageFields = array(); } $contentArr = array(); foreach ($parameters as $key => $value) { // parse Content attribute/s for Page if ($documentName == "Page" && substr($key, 0, 11) == '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") { $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)) { if (array_key_exists('year', $value) && array_key_exists('month', $value)) { $date = $value['year'] . '-' . $value['month'] . '-' . $value['day']; // 2009-02-09 16:10:20 if ($value['hour'] && $value['minute']) { $time = $value['hour'] . ':' . $value['minute']; $value = $date . ' ' . $time; } else { $value = $date; } } else { $value = implode(";", $value); } } if (in_array($key, $imageFields)) { $getFunction = 'get' . $key; $imgId = $obj->{$getFunction}(); if ($imgId != $value) { $img = Document::getDocumentInstance($imgId); if ($img) { $imgExt = $img->getExtention(); @unlink(sfConfig::get('sf_root_dir') . "/www/media/upload/thumbs/" . $parameters["moduleName"] . "/" . $imgId . "-" . $key . "." . $imgExt); } } } if ($key == "Related") { // if ($value) // { // $value = '['.str_replace(';', '][', $value).']'; // } } if ($key == "Keywords") { // if ($value) // { // $value = str_replace(',', '][', $value); // $value = '['.substr($value, 0, -1); // } } $obj->{$function}($value); } } } // Page content save if ($documentName == 'Page' && count($contentArr) > 0) { // add original NON-RICHTEXT content blocks $orgContent = $obj->getContent(); $blocks = PanelService::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($moduleName, $parameters['documentName'])) { foreach ($tags as $tag) { if ($parameters['tag_id_' . $tag->getId()]) { Document::addTag($obj, $tag->getTagId(), false); } else { Document::removeTag($obj, $tag->getTagId(), false); } } Tagrelation::updateTagRelationCache(); } //UtilsHelper::setBackendMsg("Saved"); } catch (Exception $e) { $hasError = true; UtilsHelper::setBackendMsg("Error while saving: " . $e->getMessage(), "error"); } if (!$hasError) { PanelService::redirect(); exit; } }
public static function removeTag($document, $tagId, $updateCache = true) { try { $c = new Criteria(); $c->add(TagPeer::TAG_ID, $tagId); $tag = TagPeer::doSelectOne($c); $tagRelation = TagrelationPeer::retrieveByPk($document->getId(), $tag->getId()); if ($tagRelation) { $tagRelation->delete(); if ($updateCache) { Tagrelation::updateTagRelationCache(); } } } catch (Exception $e) { throw $e; } }
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 (!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(); //$imageFields = explode(",", $parameters['imageFields']); foreach ($parameters as $key => $value) { if (!(strpos($key, 'attr') === false) && $key != "attrRewriteUrl") { $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)) { //$value = implode('-', $value); $date = $value['year'] . '-' . $value['month'] . '-' . $value['day']; // 2009-02-09 16:10:20 if ($value['hour'] && $value['minute']) { $time = $value['hour'] . ':' . $value['minute']; $value = $date . ' ' . $time; } else { $value = $date; } } /*if (in_array($key, $imageFields)) { $getFunction = 'get'.$key; $imgId = $obj->$getFunction(); if ($imgId != $value) { $img = Document::getDocumentInstance($imgId); if ($img) { $imgExt = $img->getExtention(); @unlink(sfConfig::get('sf_root_dir')."/www/media/upload/thumbs/".$parameters["moduleName"]."/".$imgId."-".$key.".".$imgExt); } } }*/ if ($key == "Keywords") { if ($value) { $value = str_replace(',', '][', $value); $value = '[' . substr($value, 0, -1); } } $obj->{$function}($value); } /*if (in_array($key, $imageFields) && (!empty($value))) { $image = Document::getDocumentInstance($value); if ($image) { if (empty($parameters[$key.'_thumbheight'])) { $parameters[$key.'_thumbheight'] = null; } if (empty($parameters[$key.'_thumbwidth'])) { $parameters[$key.'_thumbwidth'] = null; } $image->resizeImage($parameters["moduleName"], $parameters[$key.'_thumbheight'], $parameters[$key.'_thumbwidth'], $key); } }*/ } if (class_exists($documentName . "I18n") && $documentName != "Listitem") { if (!($culture = $parameters["attrCulture"])) { if (SF_APP == "panel") { $culture = sfContext::getInstance()->getUser()->getCulture(); } else { $culture = Document::getDocumentByExclusiveTag("default_culture"); } if ($culture) { $culture = $culture->getValue(); } else { throw new Exception("No default culture defined"); } } $obj->save(null, $parent, $culture); if (!$parameters["id"] || SF_APP == 'panel') { if (class_exists($documentName . "I18n")) { if (SF_APP == "panel") { $objI8n = Document::getDocumentByCulture($obj, null, true); } self::objectSave($objI8n, $obj, $documentName . "I18n"); if ($documentName == "Page") { $objI8n->setRewriteUrl($parameters["attrRewriteUrl"]); } $objI8n->setCulture($culture); $objI8n->save(null, $obj, $culture); } if (SF_APP != "panel") { $request = sfContext::getInstance()->getRequest(); $request->setParameter("id", $obj->getId()); } } } else { $obj->save(null, $parent); } $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; } if (SF_APP == "panel") { self::panelRedirect(); } }
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; } }