Skip to content

Instantly share code, notes, and snippets.

@Sigmus
Created January 14, 2013 13:54
Show Gist options
  • Save Sigmus/4530193 to your computer and use it in GitHub Desktop.
Save Sigmus/4530193 to your computer and use it in GitHub Desktop.
Permission
<?php
class Permission
{
public static function action($action)
{
return self::$action();
}
private static function ask()
{
list($count_limit_day,$count_did_today) = self::query('Question','questions');
if($count_limit_day - $count_did_today > 0) {
return true;
}
else {
return false;
}
}
private static function answer()
{
list($count_limit_day,$count_did_today) = self::query('Answer','answers');
if($count_limit_day - $count_did_today > 0) {
return true;
}
else {
return false;
}
}
private static function vote()
{
list($count_limit_day,$count_did_today) = self::query('Vote','votes');
if($count_limit_day - $count_did_today > 0) {
return true;
}
else {
return false;
}
}
private static function choose_best_answer()
{
//list($count_limit_day,$count_did_today) = self::query('Vote','votes');
//$count_did_today = Answer::where('choosed', '=', '1')->where('created_at', '>', date('Y-m-d') . ' 00:00:00')->where('created_at', '<', date('Y-m-d') . ' 23:59:59')->question_id;
//$count_did_todayA = $count_did_today->
$count_limit_day = Permissionslevel::where('level', '=', Session::get('ULVL'))->first()->best_answers;
if($count_limit_day - $count_did_today > 0) {
return true;
}
else {
return false;
}
}
private static function denounce()
{
list($count_limit_day,$count_did_today) = self::query('Denounce','denounces');
if($count_limit_day - $count_did_today > 0) {
return true;
}
else {
return false;
}
}
private static function query($model,$field)
{
$count_did_today = $model::where('user_id', '=', Session::get('UID'))->where('created_at', '>', date('Y-m-d') . ' 00:00:00')->where('created_at', '<', date('Y-m-d') . ' 23:59:59')->count();
$count_limit_day = Permissionslevel::where('level', '=', Session::get('ULVL'))->first()->$field;
return array($count_limit_day,$count_did_today);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment