/**
  * Removes the object from those members where the user can see the object(and its corresponding parents)
  * 
  */
 static function removeObjectFromMembers(ContentDataObject $object, Contact $contact, $context_members, $members_to_remove = null, $check_permissions = true)
 {
     if (is_null($members_to_remove)) {
         $member_ids = array_flat(DB::executeAll("SELECT om.member_id FROM " . TABLE_PREFIX . "object_members om\r\n  \t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "members m ON m.id=om.member_id\r\n  \t\t\t\t\t\tINNER JOIN " . TABLE_PREFIX . "dimensions d On d.id=m.dimension_id \r\n  \t\t\t\t\t\tWHERE d.is_manageable=1 AND om.object_id = " . $object->getId()));
     } else {
         $member_ids = $members_to_remove;
     }
     $memebers_deleted_ids = array();
     foreach ($member_ids as $id) {
         $member = Members::findById($id);
         if (!$member instanceof Member) {
             continue;
         }
         if ($check_permissions) {
             //can write this object type in the member
             $can_write = $object->canAddToMember($contact, $member, $context_members);
         } else {
             $can_write = true;
         }
         if ($can_write) {
             $om = self::findById(array('object_id' => $object->getId(), 'member_id' => $id));
             if ($om instanceof ObjectMember) {
                 $om->delete();
                 $memebers_deleted_ids[] = $id;
             }
             $stop = false;
             while ($member->getParentMember() != null && !$stop) {
                 $member = $member->getParentMember();
                 $obj_member = ObjectMembers::findOne(array("conditions" => array("`object_id` = ? AND `member_id` = ? AND \r\n\t\t\t\t\t\t\t\t\t`is_optimization` = 1", $object->getId(), $member->getId())));
                 if (!is_null($obj_member)) {
                     $obj_member->delete();
                 } else {
                     $stop = true;
                 }
             }
         }
     }
     return $memebers_deleted_ids;
 }
Exemplo n.º 2
0
		/**
		 * Removes the object from those members where the user can see the object(and its corresponding parents)
		 * 
		 */
  		static function removeObjectFromMembers(ContentDataObject $object, Contact $contact, $context_members, $members_to_remove = null){
  			
  			if (is_null($members_to_remove)) {
  				$member_ids = array_flat(DB::executeAll("SELECT member_id FROM ".TABLE_PREFIX."object_members WHERE object_id = " . $object->getId()));
  			} else {
  				$member_ids = $members_to_remove;
  			}
  			
  			foreach($member_ids as $id){
				
				$member = Members::findById($id);
				if (!$member instanceof Member) continue;
				
				//can write this object type in the member
				$can_write = $object->canAddToMember($contact, $member, $context_members);
				
				
				if ($can_write){
					$om = self::findById(array('object_id' => $object->getId(), 'member_id' => $id));
					if ($om instanceof ObjectMember) {
						$om->delete();
					}
					
					$stop = false;
					while ($member->getParentMember() != null && !$stop){
						$member = $member->getParentMember();
						$obj_member = ObjectMembers::findOne(array("conditions" => array("`object_id` = ? AND `member_id` = ? AND 
									`is_optimization` = 1", $object->getId(),$member->getId())));
						if (!is_null($obj_member)) {
							$obj_member->delete();
						}
						else $stop = true;
					}
				}
			}
  		}
Exemplo n.º 3
0
 /**
  * Removes the object from those members where the user can see the object(and its corresponding parents)
  * 
  */
 static function removeObjectFromMembers(ContentDataObject $object, Contact $contact, $context_members)
 {
     $object_type_id = $object->getObjectTypeId();
     $member_ids = self::getMemberIdsbyObject($object->getId());
     foreach ($member_ids as $id) {
         $member = Members::findById($id);
         //can write this object type in the member
         $can_write = $object->canAddToMember($contact, $member, $context_members);
         if ($can_write) {
             $om = self::findById(array('object_id' => $object->getId(), 'member_id' => $id));
             $om->delete();
             $stop = false;
             while ($member->getParentMember() != null && !$stop) {
                 $member = $member->getParentMember();
                 $obj_member = ObjectMembers::findOne(array("conditions" => array("`object_id` = ? AND `member_id` = ? AND \n\t\t\t\t\t\t\t\t\t`is_optimization` = 1", $object->getId(), $member->getId())));
                 if (!is_null($obj_member)) {
                     $obj_member->delete();
                 } else {
                     $stop = true;
                 }
             }
         }
     }
 }