/**
  * Returns a new signInReasonQuery object.
  *
  * @param     string $modelAlias The alias of a model in the query
  * @param   signInReasonQuery|Criteria $criteria Optional Criteria to build the query from
  *
  * @return signInReasonQuery
  */
 public static function create($modelAlias = null, $criteria = null)
 {
     if ($criteria instanceof signInReasonQuery) {
         return $criteria;
     }
     $query = new signInReasonQuery(null, null, $modelAlias);
     if ($criteria instanceof Criteria) {
         $query->mergeWith($criteria);
     }
     return $query;
 }
Example #2
0
function signin_netid($netid, $reason_id)
{
    $reason = signInReasonQuery::create()->findPK($reason_id);
    $beginOfDay = strtotime("midnight", time());
    if (!$reason) {
        return array("error" => true, "message" => "Invalid reason.");
    }
    $user = get_user($netid);
    if (!$user) {
        return array("error" => true, "message" => "Invalid NetID.");
    }
    $signins = signInQuery::create()->filterByCreatedAt(array('min' => $beginOfDay))->filterByUser($user)->find();
    $signins = $signins->toArray();
    // If the user has signed in already today...
    if (!empty($signins)) {
        // Don't let them do it again
        return array("error" => true, "message" => "You've already signed in today.");
    }
    // Otherwise, sign them in.
    $signinRecord = new signIn();
    $signinRecord->setUser($user);
    $signinRecord->setsignInReason($reason);
    $signinRecord->save();
    return array("error" => false, "message" => "Sign-in successful.");
}
Example #3
0
$app->get('/signin/:netid/:reason', function ($netid, $reason) use($app) {
    $result = signin_netid($netid, $reason);
    render_json($result);
});
$app->group('/signins', function () use($app) {
    $app->get('/today', function () use($app) {
        render_json(signins_today());
    });
    $app->get('/all', function () use($app) {
        if (!require_admin()) {
            return;
        }
        render_json(signins_all());
    });
    $app->get('/reasons', function () use($app) {
        $reasons = signInReasonQuery::create()->find();
        render_json($reasons->toArray());
    });
    $app->get('/stats', function () use($app) {
        $beginOfDay = strtotime("midnight", time());
        $stats = array();
        $stats['signinsToday'] = signInQuery::create()->filterByCreatedAt(array('min' => $beginOfDay))->count();
        $stats['uniqueUsers'] = UserQuery::create()->count();
        render_json($stats);
    });
});
$app->group('/users', function () use($app) {
    $app->get('/list', function () use($app) {
        if (!require_admin()) {
            return;
        }
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param PropelPDO $con
  * @return void
  * @throws PropelException
  * @throws Exception
  * @see        BaseObject::setDeleted()
  * @see        BaseObject::isDeleted()
  */
 public function delete(PropelPDO $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getConnection(signInReasonPeer::DATABASE_NAME, Propel::CONNECTION_WRITE);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = signInReasonQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Example #5
0
 /**
  * Get the associated signInReason object
  *
  * @param PropelPDO $con Optional Connection object.
  * @param $doQuery Executes a query to get the object if required
  * @return signInReason The associated signInReason object.
  * @throws PropelException
  */
 public function getsignInReason(PropelPDO $con = null, $doQuery = true)
 {
     if ($this->asignInReason === null && $this->reason_id !== null && $doQuery) {
         $this->asignInReason = signInReasonQuery::create()->findPk($this->reason_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->asignInReason->addsignIns($this);
            */
     }
     return $this->asignInReason;
 }