Lack of interest New param for model->prepareStateLimitFromConditions

  • Thread starter Thread starter ragtek
  • Start date Start date
This suggestion has been closed automatically because it did not receive enough votes over an extended period of time. If you wish to see this, please search for an open suggestion and, if you don't find any, post a new one.
R

ragtek

Guest
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";
	}
 
Upvote 0
This suggestion has been closed. Votes are no longer accepted.
Top Bottom