<commit_before><?php
class group extends PRIMITIVE {
	function __construct($facade) {
		parent::__construct($facade);
		$this->template = 'output.tpl';
	}
	function unknown() {
		$this->dump();		
	}
	function edit($id = 0 ,$action = 'unknown', $subid = 0, $subaction = 'unknown') {
		$this->template = 'edit.tpl';
		$g = new OBJ_GROUP($id);
		$out = array();
		$out = $g->assoc();
		if ($id == 0) {
			$method = "insert";
			$validate_id = false;
		} else {
			$method = "update";
			$validate_id = true;
		}
		switch($action) {
		case 'try':
			$out = $g->assoc();
		break;
		case 'commit':
			$descr = (isset($_POST{'descr'})) ? $_POST{'descr'} : '';
			$g->_descr = $descr;
			if ($g->$method())
				$this->success($method);
			else
				$this->fail($method);
		break;
		}
		$this->facade->smarty->assign('group',$out);
	}
	function delete($id = 0 ,$action = 'unknown', $subid = 0, $subaction = 'unknown') {
		$this->template = 'delete.tpl';
		$g = new OBJ_GROUP($id);
		$anon = new OBJ_GROUP();
		$anon->get_anon();
		if ($g->valid_id($g->_id) && $g->_id == $anon->_id) {
			$this->fail("cant remove " . ANONYMOUS_GROUP);
			return;
		}
		$out = array();
		switch ($action) {
		case 'try':
			$out = $g->assoc();
			break;
		case 'commit':
			$c = 0;
			foreach ($g->members() as $ip) {
				$ip->move_to_gid($anon->_id);
				$c++;
			}
			if ($g->delete()) {
				if ($c > 0)
					$this->say("$c member".(($c > 1) ? "s" : "" )." moved from gid $id to " . ANONYMOUS_GROUP);
				$this->success("delete: success");
			} else {
				$this->fail("delete");
			}
			break;
		}
		$this->facade->smarty->assign('group',$out);
	}
	function members($id = 0 ,$action = 'view', $subid = 0, $subaction = 'unknown') {
		$this->template = 'members.tpl';
		$anon = new OBJ_GROUP();
		$anon->get_anon();
		switch ($action) {
		case 'view':
			$g = new OBJ_GROUP($id);
			$out = array();
			$anon_memb = array();
			foreach ($g->members() as $ip) {
				array_push($out,$ip->assoc());
			}
			if ($id != $anon->_id) {
				foreach ($anon->members() as $ip) {
					array_push($anon_memb,$ip->assoc());
				}
			}
			$this->facade->smarty->assign('ips',$out);
			$this->facade->smarty->assign('group',$g->assoc());
			$this->facade->smarty->assign('anon_ips',$anon_memb);

		break;
		case 'remove':
			if ($id == $anon->_id) {
				$this->fail("$action: cant remove members from ". ANONYMOUS_GROUP);
				break;
			}
			switch($subaction) {
			case 'try':
				$ip = new OBJ_IP($subid);
				$g = new OBJ_GROUP($id);
				$this->facade->smarty->assign('group',$g->assoc());
				$this->facade->smarty->assign('ip',$ip->assoc());
			break;
			case 'commit':
				$ip = new OBJ_IP($subid);
				if ($ip->move_to_gid($anon->_id))
					$this->success($action);
				else
					$this->fail($action);
			break;
			}
		break;
		case 'add':
			$ip = new OBJ_IP($subid);
			if ($ip->move_to_gid($id))
				$this->success($action);
			else
				$this->fail($action);
		break;
		}
	}
	function dump() {
		$this->template = 'dump.tpl';
		$g = new OBJ_GROUP();
		$output = array();
		foreach ($g->getAll() as $group) {
			array_push($output,$group->assoc());<commit_msg>make some messages more informative<commit_after><?php
class group extends PRIMITIVE {
	function __construct($facade) {
		parent::__construct($facade);
		$this->template = 'output.tpl';
	}
	function unknown() {
		$this->dump();		
	}
	function edit($id = 0 ,$action = 'unknown', $subid = 0, $subaction = 'unknown') {
		$this->template = 'edit.tpl';
		$g = new OBJ_GROUP($id);
		$out = array();
		$out = $g->assoc();
		if ($id == 0) {
			$method = "insert";
			$validate_id = false;
		} else {
			$method = "update";
			$validate_id = true;
		}
		switch($action) {
		case 'try':
			$out = $g->assoc();
		break;
		case 'commit':
			$descr = (isset($_POST{'descr'})) ? $_POST{'descr'} : '';
			$g->_descr = $descr;
			if ($g->$method())
				$this->success($method);
			else
				$this->fail($method);
		break;
		}
		$this->facade->smarty->assign('group',$out);
	}
	function delete($id = 0 ,$action = 'unknown', $subid = 0, $subaction = 'unknown') {
		$this->template = 'delete.tpl';
		$g = new OBJ_GROUP($id);
		$anon = new OBJ_GROUP();
		$anon->get_anon();
		if ($g->valid_id($g->_id) && $g->_id == $anon->_id) {
			$this->fail("cant remove " . ANONYMOUS_GROUP);
			return;
		}
		$out = array();
		switch ($action) {
		case 'try':
			$out = $g->assoc();
			break;
		case 'commit':
			$c = 0;
			foreach ($g->members() as $ip) {
				$ip->move_to_gid($anon->_id);
				$c++;
			}
			if ($g->delete()) {
				$this->success("deleted group $id with " . (($c > 0) ? (($c > 1) ? "$c members" : "1 member") . "(moved to ".ANONYMOUS_GROUP.")" : "zero members"));
			} else {
				$this->fail("delete failed");
			}
			break;
		}
		$this->facade->smarty->assign('group',$out);
	}
	function members($id = 0 ,$action = 'view', $subid = 0, $subaction = 'unknown') {
		$this->template = 'members.tpl';
		$anon = new OBJ_GROUP();
		$anon->get_anon();
		switch ($action) {
		case 'view':
			$g = new OBJ_GROUP($id);
			$out = array();
			$anon_memb = array();
			foreach ($g->members() as $ip) {
				array_push($out,$ip->assoc());
			}
			if ($id != $anon->_id) {
				foreach ($anon->members() as $ip) {
					array_push($anon_memb,$ip->assoc());
				}
			}
			$this->facade->smarty->assign('ips',$out);
			$this->facade->smarty->assign('group',$g->assoc());
			$this->facade->smarty->assign('anon_ips',$anon_memb);

		break;
		case 'remove':
			if ($id == $anon->_id) {
				$this->fail("$action: cant remove objects from ". ANONYMOUS_GROUP);
				break;
			}
			switch($subaction) {
			case 'try':
				$ip = new OBJ_IP($subid);
				$g = new OBJ_GROUP($id);
				$this->facade->smarty->assign('group',$g->assoc());
				$this->facade->smarty->assign('ip',$ip->assoc());
			break;
			case 'commit':
				$ip = new OBJ_IP($subid);
				if ($ip->move_to_gid($anon->_id))
					$this->success($action);
				else
					$this->fail($action);
			break;
			}
		break;
		case 'add':
			$ip = new OBJ_IP($subid);
			if ($ip->move_to_gid($id))
				$this->success("inserted object {$ip->_id} to group $id");
			else 
				$this->fail("insert failed");
		break;
		}
	}
	function dump() {
		$this->template = 'dump.tpl';
		$g = new OBJ_GROUP();
		$output = array();
		foreach ($g->getAll() as $group) {
			array_push($output,$group->assoc());
{'fraction_non_alphanumeric': 0.23540579022306596, 'fraction_numerical': 0.0033222591362126247, 'mean_word_length': 3.2315930388219547, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 141, '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': '4043026', 'n_tokens_mistral': 2899, 'n_tokens_neox': 2469, 'n_words': 478}