Beispiel #1
0
	/**
	 * count participants
	 */
	function update_participants_cache() {

		$sql = "SELECT COUNT(1) FROM participant WHERE area=".intval($this->id);
		$count = DB::fetchfield($sql);

		$sql = "UPDATE area SET participants=".intval($count)." WHERE id=".intval($this->id);
		DB::query($sql);

	}
/**
 * count recent comments
 */
function update_activity() {
	$sql = "SELECT * FROM proposal WHERE activity!=0 OR state IN ('draft', 'submitted', 'admitted')";
	$result = DB::query($sql);
	while ( $proposal = DB::fetch_object($result, "Proposal") ) {
		/** @var Proposal $proposal */
		$sql = "SELECT COUNT(created) + COUNT(created > now() - interval '3 day') + COUNT(created > now() - interval '1 day') FROM comment
		WHERE proposal=".intval($proposal->id)." AND created > now() - interval '7 day'";
		$activity = DB::fetchfield($sql);
		$sql = "UPDATE proposal SET activity=".intval($activity)." WHERE id=".intval($proposal->id);
		DB::query($sql);
	}
}
Beispiel #3
0
	/**
	 * count supporters and admit proposal if quorum is reached
	 */
	public function update_supporters_cache() {

		$sql = "SELECT COUNT(1) FROM supporter
			WHERE proposal=".intval($this->id)."
				AND ".$this->sql_supporter_valid();
		$this->supporters = DB::fetchfield($sql);

		if ( $this->submitted and !$this->quorum_reached and $this->supporters >= $this->quorum_required() ) {
			// admit proposal
			$this->quorum_reached = true;
			$this->state = "admitted";
			$this->update(["supporters", "quorum_reached", "state"], "admitted=now()");
			$this->issue()->proposal_admitted($this);
		} else {
			$this->update(["supporters"]);
		}

	}
Beispiel #4
0
	/**
	 * number of issues the logged in member has not yet voted on
	 *
	 * @return integer
	 */
	public function not_yet_voted_issues_count() {
		if (!Login::$member) return;
		$sql = "SELECT count(1) FROM vote_token
			JOIN issue ON issue.id = vote_token.issue AND issue.state = 'voting'
 			JOIN area ON issue.area = area.id AND area.ngroup = ".intval($this->id)."
 			LEFT JOIN vote_vote USING (token)
			WHERE vote_token.member = ".intval(Login::$member->id)."
				AND vote_vote.vote IS NULL";
		return DB::fetchfield($sql);
	}
Beispiel #5
0
	'preparation' => 0,
	'voting'      => 0,
	'counting'    => 0,
	'finished'    => 0,
	'cancelled'   => 0
);
while ( $row = DB::fetch_row($result) ) $counts[$row[0]] = $row[1];

// count issues in entry stage with proposals in different states
foreach ( array('draft', 'submitted', 'admitted') as $state ) {
	$sql = "SELECT count(DISTINCT issue.id)
		FROM issue
		JOIN area ON area.id = issue.area AND area.ngroup = ".intval($ngroup->id)."
		JOIN proposal ON proposal.issue = issue.id
		WHERE issue.state='entry' AND proposal.state='$state'";
	$counts[$state] = DB::fetchfield($sql);
}

$params = array('ngroup'=>$ngroup->id);
if ($search) $params['search'] = $search;
?>
<div class="filter proposals">
<div class="top">
	<a href="<?=URI::build($params)?>" title="<?
echo _("issues in entry, debate and voting phases");
?>" class="top<?
if ($filter=="") { ?> active<? }
?>"><?=_("open")?></a>
	<div class="mid">
		<a href="<?=URI::build($params + ['filter'=>"entry"])?>" title="<?
printf(ngettext("%d issue in entry phase", "%d issues in entry phase", $counts['entry']), $counts['entry']);
Beispiel #6
0
	/**
	 * check if a username meets the requirements
	 *
	 * @param string  $username
	 * @return boolean
	 */
	public static function check_username($username) {
		if (!$username) {
			warning(_("Please enter a username!"));
			return false;
		}
		$len = mb_strlen($username);
		if ($len < 3) {
			warning(_("The username must have at least 3 characters!"));
			return false;
		}
		if ($len > 32) {
			warning(_("The username must have not more than 32 characters!"));
			return false;
		}
		if (lefteq($username, "#")) {
			warning(_("The username must not begin with the character '#'!"));
			return false;
		}
		$sql = "SELECT COUNT(1) FROM member WHERE username="******"This username is already used by someone else. Please try a different one!"));
			return false;
		}
		return true;
	}
Beispiel #7
0
	/**
	 * count voters for all ballots
	 */
	private function update_voters_cache() {

		$sql = "SELECT id FROM ballot WHERE period=".intval($this->id);
		$result = DB::query($sql);
		while ( $row = DB::fetch_assoc($result) ) {

			$sql = "SELECT COUNT(1) FROM offlinevoter WHERE ballot=".intval($row['id']);
			$count = DB::fetchfield($sql);

			$sql = "UPDATE ballot SET voters=".intval($count)." WHERE id=".intval($row['id']);
			DB::query($sql);

		}

	}
Beispiel #8
0
	/**
	 * sum up all rating scores for a comment
	 */
	private function update_ratings_cache() {

		$sql = "SELECT SUM(score) FROM rating WHERE comment=".intval($this->id);
		$this->rating = intval( DB::fetchfield($sql) );

		$this->update(["rating"]);

	}
Beispiel #9
0
/**
 * create group and areas
 *
 * @param string  $name
 * @param object  $parent (optional)
 * @return array
 */
function create_ngroup($name, Ngroup $parent=null) {

	$ngroup = new Ngroup;
	$ngroup->id = DB::fetchfield("SELECT max(id) FROM ngroup") + 1;
	$ngroup->name = $name;
	if ($parent) $ngroup->parent = $parent->id;
	$ngroup->active = true;
	$ngroup->minimum_population = 200;
	$ngroup->minimum_quorum_votingmode = 10;
	$ngroup->create(['id', 'name', 'parent', 'active', 'minimum_population', 'minimum_quorum_votingmode']);

	$area = new Area;
	$area->ngroup = $ngroup->id;
	$area->name = "Politik";
	$area->create();
	$area2 = new Area;
	$area2->ngroup = $ngroup->id;
	$area2->name = "Innerparteiliches";
	$area2->create();

	return [$ngroup, $area];
}
Beispiel #10
0
	/**
	 * get all voting periods to which the issue may be assigned
	 *
	 * Issues, on which the voting already started, may not be postponed anymore.
	 * Issues, which were not started debating, may only be moved into periods
	 * where the debate has not yet started. Otherwise the debate time would be
	 * shorter than for other issues.
	 *
	 * This function may not be used in tests with time_warp(), because it uses static variables!
	 *
	 * @return array list of options for drop down menu or false
	 */
	public function available_periods() {

		// find out if the state may be changed
		switch ($this->state) {
		case "entry":
			// At least one proposal has to be admitted.
			$sql = "SELECT COUNT(1) FROM proposal WHERE issue=".intval($this->id)." AND state='admitted'::proposal_state";
			if ( !DB::fetchfield($sql) ) return false;
		case "debate":
		case "preparation":

			// Issues, on which the voting already started, may not be postponed anymore.
			// Issues, which were not started debating, may only be moved into periods where the debate has not yet started. Otherwise the debate time would be shorter than for other issues.

			// read options once from the database
			static $options_all = false;
			static $options_admission = false;
			if ($options_all===false) {
				$sql_period = "SELECT *, debate > now() AS debate_not_started FROM period
					WHERE ngroup=".intval($this->area()->ngroup)."
						AND voting > now()
					ORDER BY id";
				$result_period = DB::query($sql_period);
				$options_all = array();
				$options_admission = array();
				while ( $period = DB::fetch_object($result_period, "Period") ) {
					DB::to_bool($period->debate_not_started);
					$options_all[$period->id] = $period->id.": ".$period->current_phase();
					if ($period->debate_not_started) {
						$options_admission[$period->id] = $options_all[$period->id];
					}
				}
			}

			if ($this->state=="entry") {
				return $options_admission;
			} else {
				return $options_all;
			}

		}

		return false;
	}
		$member->create(['invite', 'eligible', 'verified'], ['invite_expiry'=>"now() + ".DB::esc(INVITE_EXPIRY)]);
		++$inserted;
	}
	DB::transaction_commit();

	$member->update_ngroups($ngroups);

}

// check for EOF-line
if (!$eof) {
	echo "WARNING: No EOF-line was found at the end of the file!\n";
}

// number of members
$after = DB::fetchfield("SELECT COUNT(*) FROM member");

// additional warnings
if ($after != $line) {
	echo "WARNING: The number of members ($after) is not equal to the number of lines in the CSV file ($line)!\n";
}
if ($after != ($before + $inserted) ) {
	echo "WARNING: The number of members ($after) is not equal to the number before ($before) plus the inserted ($inserted) members!\n";
}

// report
echo "Members before:    $before\n";
echo "Inserted members:  $inserted\n";
echo "Lines in CSV file: $line\n";
echo "Members:           $after\n";