• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Lack of interest New param for model->prepareStateLimitFromConditions

R

ragtek

Guest
#1
Would it be possible to add an extraparameter to this method:
PHP:
/**
	 * Prepares state related fetch limits, based on the list of conditions.
	 * Looks for keys "deleted" and "moderated".
	 *
	 * @param array $fetchOptions
	 * @param string $table Name of the table to prefix the state and user fields with
	 * @param string $stateField Name of the field that holds the state
	 * @param string $userField Name of the field that holds the user ID
	 *
	 * @return string SQL condition to limit state
	 */
	public function prepareStateLimitFromConditions(array $fetchOptions, $table = '', $stateField = 'message_state', $userField = 'user_id')
My "problem is" that i'm having 2 tables with "own message states" (open, closed, moderated, deleted and in an other valid,moderated,deleted, needReview)

I didn't know, that i "have to" use visible, if i want to use this method, so i had to overwrite this method in my model, it's a 1:1 copy, it only have 'open' (and in the other 'valid') instead of 'visible'.

So, with an extraparam $standardState='visible' you wouldn't break anything in the current code, but 3rd party developers could use this method without overwriting in in there own model.

now:
PHP:
	public function prepareStateLimitFromConditions(array $fetchOptions, $table = '', $stateField = 'message_state', $userField = 'user_id')
	{
		$fetchOptions = array_merge(
			array(
				'deleted' => false,
				'moderated' => false
			), $fetchOptions
		);

		$stateRef = ($table ? "$table.$stateField" : $stateField);
		$userRef = ($table ? "$table.$userField" : $userField);

		$states = array("'visible'");
		$moderatedLimit = '';

		if ($fetchOptions['deleted'])
		{
			$states[] = "'deleted'";
		}

		if ($fetchOptions['moderated'])
		{
			if ($fetchOptions['moderated'] === true)
			{
				$states[] = "'moderated'";
			}
			else
			{
				$moderatedLimit = " OR ($stateRef = 'moderated' AND $userRef = " . intval($fetchOptions['moderated']) . ')';
			}
		}

		return "$stateRef IN (" . implode(',', $states) . ")$moderatedLimit";
	}
with my suggestion it would be:
PHP:
	public function prepareStateLimitFromConditions(array $fetchOptions, $table = '', $stateField = 'message_state', $userField = 'user_id', $standardState ='visible')
	{
		$fetchOptions = array_merge(
			array(
				'deleted' => false,
				'moderated' => false
			), $fetchOptions
		);

		$stateRef = ($table ? "$table.$stateField" : $stateField);
		$userRef = ($table ? "$table.$userField" : $userField);

		$states = array($standardState);
		$moderatedLimit = '';

		if ($fetchOptions['deleted'])
		{
			$states[] = "'deleted'";
		}

		if ($fetchOptions['moderated'])
		{
			if ($fetchOptions['moderated'] === true)
			{
				$states[] = "'moderated'";
			}
			else
			{
				$moderatedLimit = " OR ($stateRef = 'moderated' AND $userRef = " . intval($fetchOptions['moderated']) . ')';
			}
		}

		return "$stateRef IN (" . implode(',', $states) . ")$moderatedLimit";
	}