<commit_before><?php namespace Bkwld\Decoy\Input;

// Dependencies
use Bkwld\Library\Utils\String;
use Decoy;
use Former;
use Input;
use Str;

/**
 * Render many to many checklists and process their submittal
 */
class ManyToManyChecklist {

	// The form element prefix
	const PREFIX = '_many_to_many_';

	/**
	 * Render the form element
	 * ex: <?= Decoy::manyToManyChecklist($__data, 'events', array('blockHelp' => 'Blah blah')) ?>
	 * @param array $__data A The data passed to the view, to get at the item
	 * @param string $relationship The name of the relationship function on the model
	 * @param array $options Former key-value pairs, where the key is the function name 
	 * @return string HTML
	 */
	public function render($__data, $relationship, $options = array()) {

		// Get all the related items to THE model instance passed to the view
		if (isset($__data['item'])) $joined = $__data['item']->$relationship;

		// This element will get a special name that will get handled specially by the
		// base controller. I think Laravel won't try to save fields that begin with
		// an "_".
		$name = self::PREFIX.$relationship;

		// Get the full list of items
		$query = call_user_func(ucfirst(Str::singular($relationship)).'::ordered');

		// Create the data that Former expects
		$boxes = array();
		foreach($query->get() as $row) {

			// Create the row
			$ar = array('value' => $row->getKey(), 'name' => $name.'[]');

			// Check if it should be checked
			if (isset($joined) && $joined->contains($row->getKey())) $ar['checked'] = true;

			// Add it.  The str_replace fixes Former's auto conversion of underscores
			// into spaces.
			$boxes[str_replace('_', '&#95;', $row->title())] = $ar;
		}<commit_msg>Adding an argument to many to many checklist so the query can be modified.<commit_after><?php namespace Bkwld\Decoy\Input;

// Dependencies
use Bkwld\Library\Utils\String;
use Decoy;
use Former;
use Input;
use Str;

/**
 * Render many to many checklists and process their submittal
 */
class ManyToManyChecklist {

	// The form element prefix
	const PREFIX = '_many_to_many_';

	/**
	 * Render the form element
	 * ex: <?= Decoy::manyToManyChecklist($__data, 'events', array('blockHelp' => 'Blah blah')) ?>
	 * @param array $__data A The data passed to the view, to get at the item
	 * @param string $relationship The name of the relationship function on the model
	 * @param array $options Former key-value pairs, where the key is the function name.  Also, you
	 *                       append onto the query with a key of "query" and a callback for the value.
	 * @return string HTML
	 */
	public function render($__data, $relationship, $options = array()) {

		// Get all the related items to THE model instance passed to the view
		if (isset($__data['item'])) $joined = $__data['item']->$relationship;

		// This element will get a special name that will get handled specially by the
		// base controller. I think Laravel won't try to save fields that begin with
		// an "_".
		$name = self::PREFIX.$relationship;

		// Get the full list of items
		$query = call_user_func(ucfirst(Str::singular($relationship)).'::ordered');
		if (!empty($options['query']) && is_callable($options['query'])) {
			call_user_func($options['query'], $query);
			unset($options['query']);
		}

		// Create the data that Former expects
		$boxes = array();
		foreach($query->get() as $row) {

			// Create the row
			$ar = array('value' => $row->getKey(), 'name' => $name.'[]');

			// Check if it should be checked
			if (isset($joined) && $joined->contains($row->getKey())) $ar['checked'] = true;

			// Add it.  The str_replace fixes Former's auto conversion of underscores
			// into spaces.
			$boxes[str_replace('_', '&#95;', $row->title())] = $ar;
		}
{'fraction_non_alphanumeric': 0.14202127659574468, 'fraction_numerical': 0.0010638297872340426, 'mean_word_length': 3.7248743718592965, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 23, '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': '2003254', 'n_tokens_mistral': 1219, 'n_tokens_neox': 1102, 'n_words': 420}