コード例 #1
0
 function school_count_since_date($time)
 {
     $S = new Schools();
     //Best way to connect to database?
     $conn = MongoSingleton::getMongoCon();
     $db = $conn->sublite;
     $emails = $db->emails;
     $cursor = $emails->find();
     $pattern = "/(.*)@(.*)/";
     $schools = array();
     $school_names = array();
     foreach ($cursor as $doc) {
         $success = preg_match($pattern, $doc["email"], $match);
         if ($success && $doc["_id"]->getTimestamp() > $time) {
             $schools[$match[2]] += 1;
         }
     }
     foreach ($schools as $key => $id) {
         if ($S->hasSchoolOf($key)) {
             $school_names[$S->nameOf($key)] += $id;
         } else {
             $school_names[$key] += $id;
         }
     }
     return $school_names;
 }
コード例 #2
0
 function specific_school_per_day($my_school, $number_intervals)
 {
     $conn = MongoSingleton::getMongoCon();
     $db = $conn->sublite;
     $emails = $db->emails;
     $cursor = $emails->find();
     $pattern = "/(.*)@(.*)/";
     $time_now = time() - 18000;
     $intervals = array();
     $result_array = array();
     for ($x = $number_intervals; $x > 0; $x--) {
         array_push($intervals, strtotime("today -" . ($x - 1) . " day") - 18000);
         array_push($result_array, array(date('D', strtotime("today -" . ($x - 1) . " day") - 18000), 0));
     }
     array_push($intervals, $time_now);
     //$intervals = array_map(function ($x) { return $x-46035245; } , $intervals);
     foreach ($cursor as $doc) {
         $success = preg_match($pattern, $doc["email"], $match);
         if ($success && $match[2] == $my_school) {
             $doc_time = $doc["_id"]->getTimeStamp();
             for ($i = 0; $i < $number_intervals; $i++) {
                 if ($doc_time >= $intervals[$i] and $doc_time < $intervals[$i + 1]) {
                     $result_array[$i][1]++;
                 }
             }
         }
     }
     return $result_array;
 }
コード例 #3
0
ファイル: messages.php プロジェクト: edwardshe/sublite
<?php

session_start();
include "functions.php";
include "MongoSingleton.php";
$error = "";
//to store error messages when registering
if (isset($_POST['submit'])) {
    //user submitted a form
    $message = $_POST['message'];
    $conn = MongoSingleton::getMongoCon();
    $db = $conn->sublitelite;
    $users = $db->users;
    $sender = $_SESSION['username'];
    $receiver = "test";
    if ($message != "") {
        $newMessage = array('$push' => array("messages" => array("sent" => $message, "createdAt" => new MongoDate())));
        $users->update(array("username" => $sender), $newMessage);
    }
}
?>

<!DOCTYPE html>
<html>
<head>
	<title>Messages</title>
	<link href = "style.css" rel="stylesheet" type="text/css">
</head>
<body>
<form action="" method="POST">
	<p>Message:</p>