Forums / Developer / Opposite of eZContentObject::addLocation() ?

Opposite of eZContentObject::addLocation() ?

Author Message

Heiko Irrgang

Wednesday 09 March 2011 7:43:24 am

I can add a content object to other locations by calling:

$this->contentObject->addLocation( $NewLocationNodeID );

but how can i remove it again?

I have tried the following and it does remove... something, but the node still remains in the tree (i have deleted the cache)

public function removeLocationByNodeID( $nid ) {
$assignments = eZNodeAssignment::fetchForObject( $this->contentObject->ID );
foreach ( $assignments as $a ) {
if ( $a->ParentNode == $nid ) {
$a->purge();
}
}
}

Sebastiaan van der Vliet

Wednesday 09 March 2011 8:14:51 am

A long time ago I wrote some code to remove users from user groups. Don't know if it is still useful. $groupID would be the nodeID of the assigned node.

$object = eZContentObject::fetch( $userObjectID );
if ($object)
{
$nodeID = $object->attribute('main_node_id');
$version = $object->currentVersion();
$versionNumber = $version->attribute('version');
$newVersion = $object->createNewVersion();
//TODO: make sure this is not the main node.
$newVersion->removeAssignment($groupID);
$newVersionNr = $newVersion->attribute( 'version' );
include_once( 'lib/ezutils/classes/ezoperationhandler.php' );
$operationResult = eZOperationHandler::execute(
'content', 'publish', array(
'object_id' => $userObjectID,
'version' => $newVersionNr
)
);
}

Certified eZ publish developer with over 9 years of eZ publish experience. Available for challenging eZ publish projects as a technical consultant, project manager, trouble shooter or strategic advisor.

Damien Pobel

Wednesday 09 March 2011 1:44:36 pm

Hi,

I think the right method to use is eZContentObjectTreeNode::removeNodeFromTree(). if the node you're removing is the only assignment of a content object it also removes the associated content object, otherwise, it just removes the location.

@Sebastiaan : you're code seems a bit complicated, you don't need to create a new version to remove a location

Cheers

Damien
Planet eZ Publish.fr : http://www.planet-ezpublish.fr
Certification : http://auth.ez.no/certification/verify/372448
Publications about eZ Publish : http://pwet.fr/tags/keywords/weblog/ez_publish

Heiko Irrgang

Wednesday 09 March 2011 11:38:54 pm

thanx, removeNodeFromTree does the trick

eZ debug

Timing: Jan 18 2025 02:18:22
Script start
Timing: Jan 18 2025 02:18:22
Module start 'content'
Timing: Jan 18 2025 02:18:23
Module end 'content'
Timing: Jan 18 2025 02:18:23
Script end

Main resources:

Total runtime1.4590 sec
Peak memory usage4,096.0000 KB
Database Queries200

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0064 588.9609180.8359
Module start 'content' 0.00641.0290 769.7969600.7500
Module end 'content' 1.03540.4236 1,370.5469337.3672
Script end 1.4590  1,707.9141 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.2700210.0002
Check MTime0.00140.0985210.0001
Mysql Total
Database connection0.00100.069110.0010
Mysqli_queries0.811155.59322000.0041
Looping result0.00230.15761980.0000
Template Total1.121076.820.5605
Template load0.00180.125220.0009
Template processing1.119276.705120.5596
Template load and register function0.00020.010810.0002
states
state_id_array0.00060.043010.0006
state_identifier_array0.00070.048720.0004
Override
Cache load0.00160.1084450.0000
Sytem overhead
Fetch class attribute can translate value0.00190.128240.0005
Fetch class attribute name0.00140.099360.0002
XML
Image XML parsing0.00320.219840.0008
class_abstraction
Instantiating content class attribute0.00000.001060.0000
General
dbfile0.00330.2232340.0001
String conversion0.00000.000430.0000
Note: percentages do not add up to 100% because some accumulators overlap

CSS/JS files loaded with "ezjscPacker" during request:

CacheTypePacklevelSourceFiles
CSS0extension/community/design/community/stylesheets/ext/jquery.autocomplete.css
extension/community_design/design/suncana/stylesheets/scrollbars.css
extension/community_design/design/suncana/stylesheets/tabs.css
extension/community_design/design/suncana/stylesheets/roadmap.css
extension/community_design/design/suncana/stylesheets/content.css
extension/community_design/design/suncana/stylesheets/star-rating.css
extension/community_design/design/suncana/stylesheets/syntax_and_custom_tags.css
extension/community_design/design/suncana/stylesheets/buttons.css
extension/community_design/design/suncana/stylesheets/tweetbox.css
extension/community_design/design/suncana/stylesheets/jquery.fancybox-1.3.4.css
extension/bcsmoothgallery/design/standard/stylesheets/magnific-popup.css
extension/sevenx/design/simple/stylesheets/star_rating.css
extension/sevenx/design/simple/stylesheets/libs/fontawesome/css/all.min.css
extension/sevenx/design/simple/stylesheets/main.v02.css
extension/sevenx/design/simple/stylesheets/main.v02.res.css
JS0extension/ezjscore/design/standard/lib/yui/3.17.2/build/yui/yui-min.js
extension/ezjscore/design/standard/javascript/jquery-3.7.0.min.js
extension/community_design/design/suncana/javascript/jquery.ui.core.min.js
extension/community_design/design/suncana/javascript/jquery.ui.widget.min.js
extension/community_design/design/suncana/javascript/jquery.easing.1.3.js
extension/community_design/design/suncana/javascript/jquery.ui.tabs.js
extension/community_design/design/suncana/javascript/jquery.hoverIntent.min.js
extension/community_design/design/suncana/javascript/jquery.popmenu.js
extension/community_design/design/suncana/javascript/jScrollPane.js
extension/community_design/design/suncana/javascript/jquery.mousewheel.js
extension/community_design/design/suncana/javascript/jquery.cycle.all.js
extension/sevenx/design/simple/javascript/jquery.scrollTo.js
extension/community_design/design/suncana/javascript/jquery.cookie.js
extension/community_design/design/suncana/javascript/ezstarrating_jquery.js
extension/community_design/design/suncana/javascript/jquery.initboxes.js
extension/community_design/design/suncana/javascript/app.js
extension/community_design/design/suncana/javascript/twitterwidget.js
extension/community_design/design/suncana/javascript/community.js
extension/community_design/design/suncana/javascript/roadmap.js
extension/community_design/design/suncana/javascript/ez.js
extension/community_design/design/suncana/javascript/ezshareevents.js
extension/sevenx/design/simple/javascript/main.js

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
7content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
2content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
1content/datatype/view/ezxmltags/link.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/link.tplEdit templateOverride template
1pagelayout.tpl<No override>extension/sevenx/design/simple/templates/pagelayout.tplEdit templateOverride template
 Number of times templates used: 18
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs