Jump to content

supersession


matt_falcon

Recommended Posts

In need to produce a component where by a data set supercedes another, and that the user always sees the superceded value.

 

For example:

 

X --> Y --> Z

 

As X is superceded by Y and then Z supercedes Y then the need to just view the latest value is onle needed, example:

 

X --> Z

 

Please can anyone help?

Link to comment
https://forums.phpfreaks.com/topic/118627-supersession/
Share on other sites

Basically we have a number of different models which usually over time get replaced byanother model, meaninf it can be super ceded several times! So the result should be that the latest model should be shown, not the first model in the supersession series, e.g. model A gets super ceded by B, then by C. Therefore model A should show model C as the supersession model, not B.

 

Please can you can

Link to comment
https://forums.phpfreaks.com/topic/118627-supersession/#findComment-611403
Share on other sites

Your question is a bit vague, but maybe this is what you are looking for?

<?php
/**
* Chain of Responsibilty
*
*/
class DataChain
{
/**
 * Internal data
 *
 * @var array
 */
private $_data = array();

/**
 * Successor DataChain
 *
 * @var DataChain
 */
private $_successor;

/**
 * Set the successor
 *
 * @param DataChain $successor
 */
public function setSuccessor(DataChain $successor)
{
	$this->_successor = $successor;
}

/**
 * Get data by key
 *
 * @param string|int $key
 */
public function get($key)
{
	if(isset($this->_data[$key]))
	{
		return $this->_data[$key];
	}
	if($this->_successor !== null)
	{
		return $this->_successor->get($key);
	}
	return null;
}

/**
 * Set data by key
 *
 * @param string|int $key
 * @param mixed $value
 */
public function set($key, $value)
{
	return $this->_data[$key] = $value;
}
}
?>

 

Edit: Probably you want this:

 

/**
 * Get data by key
 *
 * @param string|int $key
 */
public function get($key)
{
	if($this->_successor !== null)
	{
		return $this->_successor->get($key);
	}
	if(isset($this->_data[$key]))
	{
		return $this->_data[$key];
	}
	return null;
}

 

It's no longer a Chain of Responsibility (rather the reverse), but if I understand correctly, this is what you are after.

Link to comment
https://forums.phpfreaks.com/topic/118627-supersession/#findComment-611505
Share on other sites

Well the situation is that we want our users to have access to the latest model of our product, not only do we want users to be able to view old models but a link to the latest model that super cedes that old model. Hopefully that gives you a better reason to why! Again thanks for you time.

Link to comment
https://forums.phpfreaks.com/topic/118627-supersession/#findComment-611713
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.