<commit_before><?php
class myNotificationMgr
{
	const NOTIFICATION_MGR_NO_SEND = 0;
	const NOTIFICATION_MGR_SEND_ASYNCH = 1;
	const NOTIFICATION_MGR_SEND_SYNCH = 2;
	const NOTIFICATION_MGR_SEND_BOTH = 3;
	
	private $m_not_list = array ();
	private $m_not_id_list = array ();
	private $m_url ;
	private $m_params = array ();
	private $m_serialized_params;
	
	
	public function addNotification ( $notification_type , $object_data , $partner_id=null , $puser_id=null )
	{
		$index = 1 + count ( $this->m_not_list );
		$prefix = "not{$index}_";
		
		@list ( $temp_not_id  ,  $temp_not , $temp_url , $temp_params , $temp_serialized_params )= myNotificationMgr::createNotification ( $notification_type , $entry , $partner_id , $puser_id , $prefix );
		@list ( $not_id  ,  $not , $url , $params , $serialized_params )= array ( $temp_not_id  ,  $temp_not , $temp_url , $temp_params , $temp_serialized_params );
		
		$this->m_not_list[] = $not;
		$this->m_not_id_list[] = $not_id;
		if ( $this->m_url != null && $this->m_url != $url ) 
		{ // ERROR ! 
		}
		$this->m_url = $url; // assume all URLs are the same
		array_merge ( $m_params , $params ); // accumulate the params
		$this->m_serialized_params = $serialized_params;
	}
	
	public function getNotificationIds()
	{
		return $this->m_not_id_list;
	}
	
	
	public function getNotifications()
	{
		return $this->m_not_list;
	}
	
	// this map is assumed to be the request 
	public static function splitMultiNotifications ( $map , $desired_notification_prefix = null )
	{
		$debug ="";
		$signature = $map ["sig"]; // must always exist
		if ( isset ( $map["multi_notification"] ) &&   $map["multi_notification"] === "true" )
		{
			$not_data = array();
			foreach (  $map as $name => $value )
			{
				$match = preg_match ( "/^(not[^_]*)_(.*)$/" , $name , $parts );
//$debug .= "match: $match " . print_r ( $parts , true ) . "\n";				
				if ( ! $match ) continue;
				$not_name_parts = $parts[1];
				$not_property = @$parts[2];
				
				//$not_name_parts = split ( "_" , $name , 2 );
				//	$not_property = @$not_name_parts[1];
$debug .= "name: $name\n";				
				$prefix = $not_name_parts;
				if ( $desired_notification_prefix != null && $prefix == $not_prefix )
				{
					$not_data[$not_property] = $value;
				}
				else
				{
					$not_data = @$res[$prefix];
//$debug .= "3(" . print_r ( $not_data , true ) . ")";					
					if ( $nota_data == null )
					{
						$res[$prefix] = array();
						$not_data = &$res[$prefix]; 
					}
$debug .= "property: $not_property = [$value]\n";					
					$not_data[$not_property] = $value;
				}
				//$res[$prefix] = $not_data;				
			}
			
			
		}
		else
		{
			$res = $map; // return the map as-is assuming all is a sinlge notification 
		}
		
		return array ( $res , $signature  , $debug );
	}

	/**
	 * $notification_type -
	 * $puser_id - the puser_id of the kuser that caused the modification
	 * $object_data - can be either an object or an object id (if the object no longer exists
	 * $partner_id - if exists, use this (usually in case of $object_data is an id), if not - use the partner_id from the object
	 * $entry_id is optional
	 */
	public static function createNotification ( $notification_type , $object_data , $partner_id=null , $puser_id=null , $prefix=null ,
		$extra_notification_data = null, $entry_id = null )
	{
		if(!$entry_id && $object_data instanceof entry)
			$entry_id = $object_data->getId();
		
		if ( !$partner_id )
		{
			if ( $object_data instanceof BaseObject )
			{
				$partner_id = $object_data->getPartnerId() ;
			}
			else
			{
				KalturaLog::log ( "Cannot create notification [$notification_type] [$object_data] [$partner_id]" );
				return false;
			}
		}

		//		echo "[$partner_id]";<commit_msg>qnd: falcon - entitlement general fixes <commit_after><?php
class myNotificationMgr
{
	const NOTIFICATION_MGR_NO_SEND = 0;
	const NOTIFICATION_MGR_SEND_ASYNCH = 1;
	const NOTIFICATION_MGR_SEND_SYNCH = 2;
	const NOTIFICATION_MGR_SEND_BOTH = 3;
	
	private $m_not_list = array ();
	private $m_not_id_list = array ();
	private $m_url ;
	private $m_params = array ();
	private $m_serialized_params;
	
	
	public function addNotification ( $notification_type , $object_data , $partner_id=null , $puser_id=null )
	{
		$index = 1 + count ( $this->m_not_list );
		$prefix = "not{$index}_";
		
		@list ( $temp_not_id  ,  $temp_not , $temp_url , $temp_params , $temp_serialized_params )= myNotificationMgr::createNotification ( $notification_type , $entry , $partner_id , $puser_id , $prefix );
		@list ( $not_id  ,  $not , $url , $params , $serialized_params )= array ( $temp_not_id  ,  $temp_not , $temp_url , $temp_params , $temp_serialized_params );
		
		$this->m_not_list[] = $not;
		$this->m_not_id_list[] = $not_id;
		if ( $this->m_url != null && $this->m_url != $url ) 
		{ // ERROR ! 
		}
		$this->m_url = $url; // assume all URLs are the same
		array_merge ( $m_params , $params ); // accumulate the params
		$this->m_serialized_params = $serialized_params;
	}
	
	public function getNotificationIds()
	{
		return $this->m_not_id_list;
	}
	
	
	public function getNotifications()
	{
		return $this->m_not_list;
	}
	
	// this map is assumed to be the request 
	public static function splitMultiNotifications ( $map , $desired_notification_prefix = null )
	{
		$debug ="";
		$signature = $map ["sig"]; // must always exist
		if ( isset ( $map["multi_notification"] ) &&   $map["multi_notification"] === "true" )
		{
			$not_data = array();
			foreach (  $map as $name => $value )
			{
				$match = preg_match ( "/^(not[^_]*)_(.*)$/" , $name , $parts );
//$debug .= "match: $match " . print_r ( $parts , true ) . "\n";				
				if ( ! $match ) continue;
				$not_name_parts = $parts[1];
				$not_property = @$parts[2];
				
				//$not_name_parts = split ( "_" , $name , 2 );
				//	$not_property = @$not_name_parts[1];
$debug .= "name: $name\n";				
				$prefix = $not_name_parts;
				if ( $desired_notification_prefix != null && $prefix == $not_prefix )
				{
					$not_data[$not_property] = $value;
				}
				else
				{
					$not_data = @$res[$prefix];
//$debug .= "3(" . print_r ( $not_data , true ) . ")";					
					if ( $nota_data == null )
					{
						$res[$prefix] = array();
						$not_data = &$res[$prefix]; 
					}
$debug .= "property: $not_property = [$value]\n";					
					$not_data[$not_property] = $value;
				}
				//$res[$prefix] = $not_data;				
			}
			
			
		}
		else
		{
			$res = $map; // return the map as-is assuming all is a sinlge notification 
		}
		
		return array ( $res , $signature  , $debug );
	}

	/**
	 * $notification_type -
	 * $puser_id - the puser_id of the kuser that caused the modification
	 * $object_data - can be either an object or an object id (if the object no longer exists
	 * $partner_id - if exists, use this (usually in case of $object_data is an id), if not - use the partner_id from the object
	 * $entry_id is optional
	 */
	public static function createNotification ( $notification_type , $object_data , $partner_id=null , $puser_id=null , $prefix=null ,
		$extra_notification_data = null, $entry_id = null )
	{
		KalturaLog::log ( "Create notification");
		
		if(!$entry_id && $object_data instanceof entry)
			$entry_id = $object_data->getId();
		
		if ( !$partner_id )
		{
			if ( $object_data instanceof BaseObject )
			{
				$partner_id = $object_data->getPartnerId() ;
			}
			else
			{
				KalturaLog::log ( "Cannot create notification [$notification_type] [$object_data] [$partner_id]" );
				return false;
			}
		}

		//		echo "[$partner_id]";
{'fraction_non_alphanumeric': 0.1532022322614935, 'fraction_numerical': 0.0026574541589157587, 'mean_word_length': 3.254946297343132, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1556350', 'n_tokens_mistral': 3123, 'n_tokens_neox': 2687, 'n_words': 615}