<commit_before><?php
/**
 * Base manager
 */
class BaseManager
{
	protected $table; // database table
	protected $class; // object class name

	function __construct() {
		global $db;
		global $safesql;
		$this->db = $db;
		$this->safesql = $safesql;
	}

	/**
	 * Get object based on id
	 *
	 * $id - array or single id
	 */
	public function get($id) {
		if (is_array($id)) {
			$objects = [];
			foreach($id as $i) {
				$objects[] = new $this->class($i);
			}
			return $objects;
		} else {
			$object = new $this->class($id);
			return $object;
		}
	}

	/**
	 * Get all objects
	 */
	public function all($limit = NULL, $order = array("id", "ASC")) {
		$params = array(
			$this->table,
			$order[0],
			$order[1],
		);

		$sql = "SELECT
					`id`
				FROM %s
				ORDER BY %s %s";

		if (!is_null($limit)) {
			$sql .= " LIMIT 0, %i";
			$params[] = $limit;
		}

		$sql = $this->safesql->query($sql, $params);

		$results = $this->db->get_results($sql);
		$objects = [];

		foreach($results as $result) {
			$objects[] = new $this->class($result->id);
		}

		return $objects;
	}

	/**
	 * Filter objects
	 *
	 * Example:
	 *
	 *	$articleManager->filter(array(
	 *		'published IS NOT NULL',
	 *		'published < NOW()'
	 *	), 20, array('published', 'ASC'));
	 */
	public function filter($filters, $limit = NULL, $order = array("id", "ASC")) {
		$filter = implode(" AND ", $filters);
		$params = array(
			$this->table,
			$filter,
			$order[0],
			$order[1],
		);

		$sql = "SELECT
					`id`
				FROM %s
				WHERE %s
				ORDER BY %s %s";

		if (!is_null($limit)) {
			$sql .= " LIMIT 0, %i";
			$params[] = $limit;
		}

		$sql = $this->safesql->query($sql, $params);

		$results = $this->db->get_results($sql);
		$objects = [];

		foreach($results as $result) {
			$objects[] = new $this->class($result->id);
		}

		return $objects;<commit_msg>Simplified base manager<commit_after><?php
/**
 * Base manager
 */
class BaseManager
{
	protected $table; // database table
	protected $class; // object class name

	function __construct() {
		global $db;
		global $safesql;
		$this->db = $db;
		$this->safesql = $safesql;
	}

	/**
	 * Get object based on id
	 *
	 * $id - array or single id
	 */
	public function get($id) {
		if (is_array($id)) {
			$objects = [];
			foreach($id as $i) {
				$objects[] = new $this->class($i);
			}
			return $objects;
		} else {
			$object = new $this->class($id);
			return $object;
		}
	}

	/**
	 * Get all objects
	 */
	public function all($limit = NULL, $order = array("id", "ASC")) {
		return $this->filter(NULL, $limit, $order);
	}

	/**
	 * Filter objects
	 *
	 * Example:
	 *
	 *	$articleManager->filter(array(
	 *		'published IS NOT NULL',
	 *		'published < NOW()'
	 *	), 20, array('published', 'ASC'));
	 */
	public function filter($filters = NULL, $limit = NULL, $order = array("id", "ASC")) {
		$sql = "SELECT
					`id`
				FROM %s";

		$params = array(
			$this->table
		);

		if (!is_null($filters)) {
			$filter = implode(" AND ", $filters);

			$sql .= " WHERE %s";
			$params[] = $filter;
		}

		$sql .= " ORDER BY %s %s";
		$params[] = $order[0];
		$params[] = $order[1];

		if (!is_null($limit)) {
			$sql .= " LIMIT 0, %i";
			$params[] = $limit;
		}

		$sql = $this->safesql->query($sql, $params);

		$results = $this->db->get_results($sql);
		$objects = [];

		foreach($results as $result) {
			$objects[] = new $this->class($result->id);
		}

		return $objects;
{'fraction_non_alphanumeric': 0.21026392961876833, 'fraction_numerical': 0.003812316715542522, 'mean_word_length': 2.7942157953281423, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 35, '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': '6112778', 'n_tokens_mistral': 1483, 'n_tokens_neox': 1262, 'n_words': 305}