Exponential 6.0.13 Exponential Enterprise Open Source CMS - PHP Class Reference

ezcontentobjectassignmenthandler.php
Go to the documentation of this file.
1 <?php
17 class eZContentObjectAssignmentHandler
18 {
19 public $CurrentVersion;
25 public function __construct( $contentObject, $contentVersion )
26 {
27 $this->CurrentObject = $contentObject;
28 $this->CurrentVersion = $contentVersion;
29 }
30
31 function nodeIDList( $selectionText )
32 {
33 $nodeList = array();
34 $items = explode( ',', trim( $selectionText ) );
35 foreach ( $items as $item )
36 {
37 $item = trim( $item );
38 if ( $item != '' )
39 {
40 $nodeID = $this->nodeID( $item );
41 if ( $nodeID !== false )
42 {
43 $nodeList[] = $nodeID;
44 }
45 }
46 }
47 return $nodeList;
48 }
49
50 function nodeID( $name )
51 {
52 if ( is_numeric( $name ) )
53 {
54 $nodeID = false;
55 $node = eZContentObjectTreeNode::fetch( $name, false, false );
56 if ( $node )
57 $nodeID = $node['node_id'];
58 return $nodeID;
59 }
60 $contentINI = eZINI::instance( 'content.ini' );
61 switch ( $name )
62 {
63 case 'root':
64 {
65 return $contentINI->variable( 'NodeSettings', 'RootNode' );
66 }
67 case 'users':
68 {
69 return $contentINI->variable( 'NodeSettings', 'UserRootNode' );
70 }
71 case 'none':
72 {
73 return false;
74 }
75 default:
76 {
77 eZDebug::writeError( "Unknown node type '$name'", __METHOD__ );
78 } break;
79 }
80 return false;
81 }
82
87 function setupAssignments( $parameters )
88 {
89 $parameters = array_merge( array( 'group-name' => false,
90 'default-variable-name' => false,
91 'specific-variable-name' => false,
92 'fallback-node-id' => false,
93 'section-id-wanted' => false ),
94 $parameters );
95 if ( !$parameters['group-name'] and
96 !$parameters['default-variable-name'] and
97 !$parameters['specific-variable-name'] )
98 return false;
99 $contentINI = eZINI::instance( 'content.ini' );
100 $defaultAssignment = $contentINI->variable( $parameters['group-name'], $parameters['default-variable-name'] );
101 $specificAssignments = $contentINI->variable( $parameters['group-name'], $parameters['specific-variable-name'] );
102 $hasAssignment = false;
103 $assignments = false;
104 $sectionIDWanted = $parameters['section-id-wanted'];
105 $sectionID = 0;
106 $contentClass = $this->CurrentObject->attribute( 'content_class' );
107 $contentClassIdentifier = $contentClass->attribute( 'identifier' );
108 $contentClassID = $contentClass->attribute( 'id' );
109 foreach ( $specificAssignments as $specificAssignment )
110 {
111 $assignmentRules = explode( ';', $specificAssignment );
112 $classMatches = $assignmentRules[0];
113 $assignments = $assignmentRules[1];
114 $mainID = false;
115 if ( isset( $assignmentRules[2] ) )
116 $mainID = $assignmentRules[2];
117 $classMatchArray = explode( ',', $classMatches );
118 foreach ( $classMatchArray as $classMatch )
119 {
120 $classMatch = trim( $classMatch );
121 if ( preg_match( "#^group_([0-9]+)$#", $classMatch, $matches ) )
122 {
123 $classGroupID = $matches[1];
124 if ( $contentClass->inGroup( $classGroupID ) )
125 {
126 $hasAssignment = true;
127 break;
128 }
129 }
130 else if ( $classMatch == $contentClassIdentifier )
131 {
132 $hasAssignment = true;
133 break;
134 }
135 else if ( $classMatch == $contentClassID )
136 {
137 $hasAssignment = true;
138 break;
139 }
140 }
141 if ( $hasAssignment )
142 break;
143 }
144 if ( !$hasAssignment )
145 {
146 $assignmentRules = explode( ';', $defaultAssignment );
147 $assignments = $assignmentRules[0];
148 $mainID = false;
149 if ( isset( $assignmentRules[1] ) )
150 $mainID = $assignmentRules[1];
151 }
152 eZDebug::writeDebug( $assignments, 'assignments' );
153 if ( $assignments )
154 {
155 if ( $mainID )
156 $mainID = $this->nodeID( $mainID );
157 $nodeList = $this->nodeIDList( $assignments );
158 eZDebug::writeDebug( $nodeList, 'nodeList' );
159 $assignmentCount = 0;
160 eZDebug::writeDebug( $this->CurrentObject->attribute( 'id' ), 'current object' );
161 eZDebug::writeDebug( $this->CurrentVersion->attribute( 'version' ), 'current version' );
162 foreach ( $nodeList as $nodeID )
163 {
164 $node = eZContentObjectTreeNode::fetch( $nodeID );
165 if ( !$node )
166 continue;
167 $parentContentObject = $node->attribute( 'object' );
168
169 eZDebug::writeDebug( "Checking for '$nodeID'" );
170 if ( $parentContentObject->checkAccess( 'create',
171 $contentClassID,
172 $parentContentObject->attribute( 'contentclass_id' ) ) == '1' )
173 {
174 eZDebug::writeDebug( "Adding to '$nodeID' and main = '$mainID'" );
175 if ( $mainID === false )
176 {
177 $isMain = ( $assignmentCount == 0 );
178 }
179 else
180 $isMain = ( $mainID == $nodeID );
181
182 /* Here we figure out the section ID in case it is needed
183 * to assign a newly created object to. */
184 if ( $sectionIDWanted and $isMain )
185 {
186 $db = eZDB::instance();
187 $query = "SELECT section_id
188 FROM ezcontentobject c, ezcontentobject_tree t
189 WHERE t.node_id = 109
190 AND t.contentobject_id = c.id";
191 $result = $db->arrayQuery( $query );
192 $sectionID = $result[0]['section_id'];
193 }
194
195 $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $this->CurrentObject->attribute( 'id' ),
196 'contentobject_version' => $this->CurrentVersion->attribute( 'version' ),
197 'parent_node' => $node->attribute( 'node_id' ),
198 'is_main' => $isMain ) );
199 $nodeAssignment->store();
200 ++$assignmentCount;
201 }
202 return $sectionID;
203 }
204
205 if ( $assignmentCount == 0 &&
206 $parameters['fallback-node-id'] )
207 {
208 $nodeAssignment = eZNodeAssignment::create( array( 'contentobject_id' => $this->CurrentObject->attribute( 'id' ),
209 'contentobject_version' => $this->CurrentVersion->attribute( 'version' ),
210 'parent_node' => $parameters['fallback-node-id'],
211 'is_main' => true ) );
212 $nodeAssignment->store();
213 ++$assignmentCount;
214 }
215 }
216 return true;
217 }
218
220
223 public $CurrentObject;
224
228 public $ContentVersion;
229 }
230
231 ?>
eZContentObjectAssignmentHandler
Handles default assignments for content objects.
Definition: ezcontentobjectassignmenthandler.php:18
eZContentObjectAssignmentHandler\__construct
__construct( $contentObject, $contentVersion)
Definition: ezcontentobjectassignmenthandler.php:25
eZContentObjectAssignmentHandler\$ContentVersion
$ContentVersion
Definition: ezcontentobjectassignmenthandler.php:228
eZContentObjectAssignmentHandler\$CurrentVersion
$CurrentVersion
Definition: ezcontentobjectassignmenthandler.php:19
eZContentObjectAssignmentHandler\$CurrentObject
$CurrentObject
Definition: ezcontentobjectassignmenthandler.php:223
eZContentObjectAssignmentHandler\nodeIDList
nodeIDList( $selectionText)
Definition: ezcontentobjectassignmenthandler.php:31
eZContentObjectAssignmentHandler\setupAssignments
setupAssignments( $parameters)
Definition: ezcontentobjectassignmenthandler.php:87
eZContentObjectAssignmentHandler\nodeID
nodeID( $name)
Definition: ezcontentobjectassignmenthandler.php:50
eZContentObjectTreeNode\fetch
static fetch( $nodeID=false, $lang=false, $asObject=true, $conditions=false)
Definition: ezcontentobjecttreenode.php:3058
eZDB\instance
static instance( $databaseImplementation=false, $databaseParameters=false, $forceNewInstance=false)
Definition: ezdb.php:117
eZDebug\writeError
static writeError( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:545
eZDebug\writeDebug
static writeDebug( $string, $label="", $backgroundClass="")
Definition: ezdebug.php:588
eZNodeAssignment\create
static create( $parameters=array())
Definition: eznodeassignment.php:193
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.