/** * @param array $limitationValueList * @param int $userID * @param int|bool $contentObjectID * @return string Returns "denied" or "allowed" */ function checkGroupLimitationAccess( $limitationValueList, $userID, $contentObjectID = false ) { $access = 'denied'; if ( is_array( $limitationValueList ) && is_numeric( $userID ) ) { if ( $contentObjectID !== false ) { $contentObject = eZContentObject::fetch( $contentObjectID ); } else { $contentObject = $this; } if ( is_object( $contentObject ) ) { // limitation value == 1, means "self group" if ( in_array( 1, $limitationValueList ) ) { // no need to check groups if user ownes this object $ownerID = $contentObject->attribute( 'owner_id' ); if ( $ownerID == $userID || $contentObject->attribute( 'id' ) == $userID ) { $access = 'allowed'; } else { // get parent node ids for 'user' and 'owner' $groupList = eZContentObjectTreeNode::getParentNodeIdListByContentObjectID( array( $userID, $ownerID ), true ); // find group(s) which is common for 'user' and 'owner' $commonGroup = array_intersect( $groupList[$userID], $groupList[$ownerID] ); if ( count( $commonGroup ) > 0 ) { // ok, we have at least 1 common group $access = 'allowed'; } } } } } return $access; }
/** * Unit test for eZContentObjectTreeNode::getParentNodeIDListByContentObjectID() * * @todo test with $onlyMainNode=true * @todo test with $groupByObjectID=true */ public function testGetParentNodeIdListByContentObjectID() { // Create a few containers with a few children below each $childrenIDArray = $childrenParentIDArray = array(); for ( $i = 0; $i < 3; $i++ ) { $folder = new ezpObject( 'folder', 2 ); $folder->name = "Container #{$i} for " . __FUNCTION__; $folder->publish(); $containerID = $folder->attribute( 'main_node_id' ); $containerIDArray[] = $containerID; for ( $j = 0; $j < 5; $j++ ) { $article = new ezpObject( 'article', $containerID ); $article->title = "Object #{$i}"; $article->publish(); $articleID = $article->attribute( 'id' ); $childrenIDArray[] = $articleID; $childrenParentIDArray[$articleID] = $containerID; } } // First test without grouping $parentNodeIDArray = eZContentObjectTreeNode::getParentNodeIdListByContentObjectID( $childrenIDArray, false ); $this->assertEquals( count( $childrenIDArray ), count( $parentNodeIDArray ), "count of returned items doesn't match the parameters count" ); foreach( $parentNodeIDArray as $parentNodeID ) { $this->assertTrue( in_array( $parentNodeID, $containerIDArray ), "Returned parent_node_id $parentNodeID isn't in the list of created nodes" ); } }