/** * Creates a scoreboard in a group * * @param array $groupData * @param type $name * @param type $description * @param type $alias */ public static function createGroupScoreboard(array $groupData, $name = null, $description = null, $alias = null) { if (is_null($name)) { $name = Utils::CreateRandomString(); } if (is_null($description)) { $description = Utils::CreateRandomString(); } if (is_null($alias)) { $alias = Utils::CreateRandomString(); } $request = new Request(array('auth_token' => OmegaupTestCase::login($groupData['owner']), 'group_alias' => $groupData['group']->alias, 'name' => $name, 'alias' => $alias, 'description' => $description)); $response = GroupController::apiCreateScoreboard($request); $scoreboards = GroupsScoreboardsDAO::search(new GroupsScoreboards(array('alias' => $alias))); return array('request' => $request, 'response' => $response, 'scoreboard' => $scoreboards[0]); }
/** * Creates a scoreboard in a group * * @param array $groupData * @param type $name * @param type $description * @param type $alias */ public static function createGroupScoreboard(array $groupData, $name = null, $description = null, $alias = null) { if (is_null($name)) { $name = Utils::CreateRandomString(); } if (is_null($description)) { $description = Utils::CreateRandomString(); } if (is_null($alias)) { $alias = Utils::CreateRandomString(); } $request = new Request(array("auth_token" => OmegaupTestCase::login($groupData["owner"]), "group_alias" => $groupData["group"]->alias, "name" => $name, "alias" => $alias, "description" => $description)); $response = GroupController::apiCreateScoreboard($request); $scoreboards = GroupsScoreboardsDAO::search(new GroupsScoreboards(array("alias" => $alias))); return array("request" => $request, "response" => $response, "scoreboard" => $scoreboards[0]); }
public function filterGroupControl($filterChain) { if (!isset($_GET['id'])) { throw new CHttpException(404); } /** @var Group $group */ $group = Group::model()->findByAttributes(['number' => $_GET['id']]); if (!$group) { throw new CHttpException(404, 'Данной группы не существует'); } $is_admin = Yii::app()->user->checkAccess('admin'); $is_owner = $group->owner_id == Yii::app()->user->getId(); $is_member = GroupMember::model()->findByAttributes(['group_id' => $group->id, 'user_id' => Yii::app()->user->getId()]); if (!$is_admin && !$is_owner && !$is_member) { throw new CHttpException(403, 'У вас нет доступа к данной группе'); } self::$group = $group; $filterChain->run(); }
static function addRoutes($app, $authenticateForRole) { //* /group/ routes - admin users only $app->group('/group', $authenticateForRole('admin'), function () use($app) { /* * id */ $app->map("/get/:groupId/", function ($groupId) use($app) { GroupController::getGroup($app, $groupId); })->via('GET', 'POST'); /* * group, desc */ $app->post("/insert/", function () use($app) { GroupController::addGroup($app); }); /* * id, group, desc */ $app->post("/update/:groupId/", function ($groupId) use($app) { GroupController::saveGroup($app, $groupId); }); /* * id */ $app->map("/delete/:groupId/", function ($groupId) use($app) { GroupController::deleteGroup($app, $groupId); })->via('DELETE', 'POST'); /* * roleId, groupId */ $app->post("/unassign-role/", function () use($app) { GroupController::unassignRole($app); }); /* * roleId, groupId */ $app->post("/assign-role/", function () use($app) { GroupController::assignRole($app); }); }); }
}); $routes->get('/user/:id', function ($id) { UserController::show($id); }); $routes->post('/user/:id', function ($id) { UserController::update($id); }); $routes->get('/user/:id/edit', function ($id) { UserController::edit($id); }); $routes->get('/user/:id/destroy', function ($id) { UserController::destroy($id); }); $routes->get('/group', function () { GroupController::index(); }); $routes->post('/group', function () { GroupController::store(); }); $routes->get('/group/new', function () { GroupController::create(); }); $routes->get('/group/:id', function ($id) { GroupController::show($id); }); $routes->post('/group/:id/destroy', function ($id) { GroupController::destroy($id); }); $routes->get('/group/:id/destroy', function ($id) { GroupController::destroy($id); });
/** * Details of a scoreboard * * @param Request $r */ public static function apiList(Request $r) { GroupController::validateGroup($r); $response = array(); $response["scoreboards"] = array(); try { $key = new GroupsScoreboards(array("group_id" => $r["group"]->group_id)); $scoreboards = GroupsScoreboardsDAO::search($key); foreach ($scoreboards as $scoreboard) { $response["scoreboards"][] = $scoreboard->asArray(); } } catch (Exception $ex) { throw new InvalidDatabaseOperationException($ex); } $response["status"] = "ok"; return $response; }
/** * @api {get} /activate Active User * @apiName GetUser * @apiGroup User * * @apiParam {String} sourse encrypt string. * * @apiError 400 Link Invalid. This will happen if param is not sent out. * @apiError 404 Not found. This will happen if the role id/user id/group id is not in our system. * @apiError 409 Link already activated. * @apiError 409 Link Expired. 24h. */ public static function setActive() { $app = \Slim\Slim::getInstance(); $data = $app->request->get(); if (!isset($data['source'])) { $app->halt('400', json_encode("Link is invalid.")); } $idUser = openssl_decrypt($data['source'], 'AES-256-CBC', self::$pass, 0, self::$iv); $user = User::find($idUser); if (!$user) { $app->halt('404', json_encode("Link is invalid. Please Sign Up.")); } if ($user->active) { $app->halt('409', json_encode("Link is invalid. You already activated your acount.")); } $created_at = new DateTime($user->created_at); $interval = date_create('now')->diff($created_at); if ($interval->d >= 1) { $app->halt('408', json_encode("Link expired.")); } $user->active = 1; $saved = $user->save(); if ($saved) { GroupController::activeEnroll($idUser); EmailController::newUserWelcome($idUser); return json_encode("success"); } else { $app->halt('500', json_encode("update to db error")); } }
ForumController::topics($group_id); }); $routes->get('/groups/:group_id/edit', function ($group_id) { GroupController::edit($group_id); }); $routes->post('/groups/:group_id/edit', function ($group_id) { GroupController::update($group_id); }); $routes->post('/groups/:group_id/expel/:user_id', function ($group_id, $user_id) { GroupController::expel($group_id, $user_id); }); $routes->post('/groups/:group_id/invite', function ($group_id) { GroupController::invite($group_id); }); $routes->post('/groups/:group_id/delete', function ($group_id) { GroupController::destroy($group_id); }); $routes->get('/topics/:topic_id', function ($topic_id) { ForumController::topic($topic_id); }); $routes->post('/topics/:topic_id/', function ($topic_id) { MessageController::store($topic_id); }); $routes->get('/topics/:topic_id/:message_id/edit', function ($topic_id, $message_id) { MessageController::edit($message_id, $topic_id); }); $routes->post('/topics/:topic_id/:message_id/edit', function ($topic_id, $message_id) { MessageController::update($message_id, $topic_id); }); $routes->post('/topics/:topic_id/:message_id/delete', function ($topic_id, $message_id) { MessageController::delete($message_id, $topic_id);
/** * Test add a scoreboard */ public function testCreateScoreboard() { $groupData = GroupsFactory::createGroup(); $name = Utils::CreateRandomString(); $description = Utils::CreateRandomString(); $alias = Utils::CreateRandomString(); $response = GroupController::apiCreateScoreboard(new Request(array('auth_token' => self::login($groupData['owner']), 'group_alias' => $groupData['group']->alias, 'name' => $name, 'alias' => $alias, 'description' => $description))); $this->assertEquals('ok', $response['status']); $groupScoreboards = GroupsScoreboardsDAO::search(new GroupsScoreboards(array('alias' => $alias))); $groupScoreboard = $groupScoreboards[0]; $this->assertNotNull($groupScoreboard); $this->assertEquals($description, $groupScoreboard->getDescription()); $this->assertEquals($groupData['group']->group_id, $groupScoreboard->getGroupId()); }
/** * @api {post} /managers/:idUser/transfer Transfer Content by Manager * @apiName Transfer Content by Manager * @apiGroup Manager * @apiHeader (Header) {String} X_Authorization Authorization value. * @apiParam (url Parameter) {Number} idUser User unique ID. * @apiParam {Number} idBin Bin's unique ID. * @apiParam {Number} qty qty to transfer. * @apiParam {Number} idUser User's unique ID. The change will apply to this user. * * @apiError 400 Input Invalid. This will happen if the param is missing or not the valid format. * @apiError 404 Not found. This will happen if the bin id/user id/course id/sale id is not in our system. * @apiError 401 Not authorized. This will happen if the header value is not attached. * @apiError 403 The user is not a manager yet. * * */ public static function transContent($idUser) { $app = \Slim\Slim::getInstance(); $request = $app->request->post(); $validata = $app->validata; $validator = $validata::key('idBin', $validata::digit()->notEmpty())->key('qty', $validata::digit()->notEmpty())->key('idUser', $validata::digit()->notEmpty()); if (!$validator->validate($request)) { $app->halt("400", json_encode("Input Invalid")); } if (!GroupController::isManagerOfAdmin($request['idUser'], $idUser)) { $app->halt("403", json_encode("Permission denied.")); } $bin_id = $request['idBin']; $bin = Manager_Bin::where('id', '=', $bin_id)->lockForUpdate()->first(); if (!$bin) { $app->halt("404", json_encode("manager content record does not exist")); } if ($bin->user_id != $idUser) { $app->halt("401"); } if ($bin->quantity < $request['qty']) { $app->halt("404", json_encode("No available seat found.")); } $bin->quantity = $bin->quantity - $request['qty']; $bin->save(); $new_bin = self::addToBin($bin->course_sale_id, $request['qty'], $request['idUser'], $bin->expiration_dt); $bin->transferOut()->attach($new_bin, array('sender_id' => $idUser, 'receiver_id' => $request['idUser'], 'course_sale_id' => $bin->course_sale_id, 'quantity' => $request['qty'])); }
/** * Test add a scoreboard */ public function testCreateScoreboard() { $groupData = GroupsFactory::createGroup(); $name = Utils::CreateRandomString(); $description = Utils::CreateRandomString(); $alias = Utils::CreateRandomString(); $response = GroupController::apiCreateScoreboard(new Request(array("auth_token" => self::login($groupData["owner"]), "group_alias" => $groupData["group"]->alias, "name" => $name, "alias" => $alias, "description" => $description))); $this->assertEquals("ok", $response["status"]); $groupScoreboards = GroupsScoreboardsDAO::search(new GroupsScoreboards(array("alias" => $alias))); $groupScoreboard = $groupScoreboards[0]; $this->assertNotNull($groupScoreboard); $this->assertEquals($description, $groupScoreboard->getDescription()); $this->assertEquals($groupData["group"]->group_id, $groupScoreboard->getGroupId()); }
public static function getColors($rand = null) { $color = GroupController::COLOR(new GroupController()); return is_null($rand) ? $color : $color[rand(0, 14)]; }
public static function afterPurchaseEnroll($items, $idUser) { $isAdmin = GroupController::adminCheck($idUser); foreach ($items as $key => $item) { $sale = Price::find($item->id); if (is_null($sale->length)) { $end_at = Null; } else { $date = strtotime("+" . $sale->length . " day"); $end_at = date('Y-m-d H:i:s', $date); } if (!$isAdmin) { self::enroll($item->course_id, $idUser, $end_at); } else { ManagerController::addToBin($item->id, $item->qty, $idUser, $end_at); } } }
public function actionGetgroupmenucount() { $userid = $_REQUEST['userid']; $share = ""; //$_REQUEST['share']; $tilesslider = $this->refreshtilewidget($userid, $_REQUEST['groupid'], $share, 0, 0, 1); $usergroup = $this->getGroupinfo($userid, $share); $members = GroupController::getmembersdetails($userid, $_REQUEST['groupid'], 0, 0); $memcount = count($members); $result = GroupTracking::model()->findByAttributes(array('tracker_userid' => Yii::app()->session['login']['id'], 'tracked_groupid' => $_REQUEST['groupid'], 'tracked_userid' => $userid)); if (count($result) == '0') { $results = 'Join Group'; $isgroupmem = 0; //Not a member } else { $results = 'UnJoin Group'; $isgroupmem = 1; // Member } $this->widget('TopMenu', array('userid' => $userid, 'isshare' => $share, 'alltiles' => $tilesslider['totaltilecount'], 'imgcount' => $tilesslider['imgcount'], 'videocount' => $tilesslider['videocount'], 'finaocount' => $this->getfinaoinfo($userid, $_REQUEST['groupid'], "", $share, -1, 1, 1), 'followcnt' => $this->getfollowersdetails($userid, -1, 0, 1), 'groupcnt' => $usergroup['groupcount'], 'memcount' => $memcount, 'isgroup' => $_REQUEST['groupid'], 'results_group' => $results)); }
public function totalAssignmentsByTag($arrayGroups) { $array = array(); $arrayAux = array(); $arrayAux['label'] = 'analysis'; $arrayAux['value'] = Assignment::whereIn('group_id', $arrayGroups)->whereIn('tags', array('analysis'))->count(); $arrayAux['color'] = GroupController::getColors(true); $arrayAux['highlight'] = "#FF5A5E"; array_push($array, $arrayAux); $arrayAux = array(); $arrayAux['label'] = 'database'; $arrayAux['value'] = Assignment::whereIn('group_id', $arrayGroups)->whereIn('tags', array('database'))->count(); $arrayAux['color'] = GroupController::getColors(true); $arrayAux['highlight'] = "#FF5A5E"; array_push($array, $arrayAux); $arrayAux = array(); $arrayAux['label'] = 'design'; $arrayAux['value'] = Assignment::whereIn('group_id', $arrayGroups)->whereIn('tags', array('design'))->count(); $arrayAux['color'] = GroupController::getColors(true); $arrayAux['highlight'] = "#FF5A5E"; array_push($array, $arrayAux); $arrayAux = array(); $arrayAux['label'] = 'programming'; $arrayAux['value'] = Assignment::whereIn('group_id', $arrayGroups)->whereIn('tags', array('programming'))->count(); $arrayAux['color'] = GroupController::getColors(true); $arrayAux['highlight'] = "#FF5A5E"; array_push($array, $arrayAux); $arrayAux = array(); $arrayAux['label'] = 'testing'; $arrayAux['value'] = Assignment::whereIn('group_id', $arrayGroups)->whereIn('tags', array('testing'))->count(); $arrayAux['color'] = GroupController::getColors(true); $arrayAux['highlight'] = "#FF5A5E"; array_push($array, $arrayAux); return $array; }