Example #1
0
 public function getIndex()
 {
     $action = $_GET['action'];
     if ($action == "update") {
         $to = $_GET['to'];
         $id = $_GET['id'];
         $groupEntry = Group::find($id);
         $groupEntry->name = $to;
         $groupEntry->save();
     } else {
         if ($action == "delete") {
             $id = $_GET['id'];
             $groupEntry = Group::find($id);
             $groupEntry->delete();
         } else {
             if ($action == "insert") {
                 $name = $_GET['name'];
                 $group = new Group();
                 $group->name = $name;
                 $group->save();
             }
         }
     }
     return View::make('admin');
 }
Example #2
0
 public function destroy($id)
 {
     if (Auth::user()->is_admin) {
         $count = 0;
         $grupo = Group::find($id);
         $users = User::select('group_ids')->get();
         foreach ($users as $key => $user) {
             $u = $user->group_ids;
             $uarray = explode(',', $u);
             if (in_array($id, $uarray, true)) {
                 $count = $count + 1;
             }
         }
         if ($count > 0) {
             $field = $count == 1 ? ' ' : 's';
             $field2 = $count == 1 ? ' pertenece' : ' pertenecen';
             $message = $count . " Usuario" . $field . $field2 . " al grupo " . $grupo->name;
             Session::flash('error', $message);
             return Redirect::to('grupos/' . $id);
         } else {
             $grupo->delete();
             $message = "Grupo Eliminado con éxito";
             Session::flash('message', $message);
             return Redirect::to('grupos');
         }
     }
 }
 public static function edit($id)
 {
     self::check_logged_in();
     $group = Group::find($id);
     $members = User::all();
     $users = User::getMembers($id);
     View::make('group/edit.html', array('attributes' => $group, 'members' => $members, 'users' => $users));
 }
 /**
  * Show the form for editing the specified group.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     if (!Sentry::getUser()) {
         return Redirect::route('sessions.create');
     }
     $group = Group::find($id);
     return View::make('groups.edit', compact('group'));
 }
Example #5
0
 /**
  * Retourne le champ permission
  *
  */
 public function getPermission()
 {
     if (Auth::check()) {
         $group = Auth::user()->group;
     } else {
         $group = Group::find(2);
     }
     return Permission::whereRaw('forum_id = ? AND group_id = ?', array($this->id, $group->id))->first();
 }
Example #6
0
 public function get_show($group_id)
 {
     $modules = Group::find($group_id)->modules()->order_by('order', 'asc')->get();
     $array = array_map(function ($object) {
         return $object->to_array();
     }, $modules);
     $data = array('aaData' => $array);
     return Response::json($data);
 }
 public function approve()
 {
     if (Request::ajax()) {
         $pending = PendingGroup::find(Input::get('id'));
         Group::find($pending->group_id)->push('students_id', $pending->student_id, true);
         $pending->delete();
         return Response::json(array('code' => "00", 'stats' => MessageController::getStats()));
     }
 }
Example #8
0
 static function paginate_all($limit, $page)
 {
     $offset = $limit * ($page - 1);
     $result = Group::find('all', array('limit' => $limit, 'offset' => $offset, 'order' => 'id DESC'));
     if ($result) {
         return $result;
     } else {
         return FALSE;
     }
 }
Example #9
0
 /**
  * Fetch a single group based on the value of a given column.
  *
  * For non-unique columns, it will return the first entry found.  Returns false if no match is found.
  * @param value $value The value to find.
  * @param string $name The name of the column to match (defaults to id)
  * @return Group
  */
 public static function fetch($value, $name = "id")
 {
     if ($name == "id") {
         // Fetch by id
         return Group::find($value);
     } else {
         // Fetch by some other column name
         return Group::where($name, $value)->first();
     }
 }
Example #10
0
 protected function actByProduct($method, $id)
 {
     if ($id = static::idFrom($id) and $model = Product::find($id) and $model->group) {
         $group = Group::find($model->group);
         if ($group and $group = $group->root()) {
             $this->layout = '.' . substr(strrchr($method, '_'), 1);
             return $this->{$method}($group);
         }
     }
 }
 public function pageGroupAuthorization($group_id)
 {
     // Access-controlled page
     if (!$this->_app->user->checkAccess('uri_authorization_settings')) {
         $this->_app->notFound();
     }
     $group = Group::find($group_id);
     // Load all auth rules
     $rules = GroupAuth::where('group_id', $group_id)->get();
     $this->_app->render('config/authorization.twig', ["group" => $group, "rules" => $rules]);
 }
 public function inviteMember()
 {
     $email = Input::get('email');
     $newmember = User::where('email', '=', $email)->firstOrFail();
     $group = Group::find(Input::get('groupid'));
     $gmembers = unserialize($group->members);
     array_push($gmembers, $newmember->id);
     $group->members = serialize($gmembers);
     $group->save();
     return Redirect::to('g/' . $group->uid);
 }
 public function view($id)
 {
     $group = Group::find($id);
     $group->views += 1;
     $group->save();
     if (Auth::guest()) {
         $group->ismember = false;
     } else {
         $group->ismember = $this->checkmembers($id);
     }
     return View::make('group.view')->with('group', $group);
 }
Example #14
0
 public function __construct()
 {
     if (!Auth::guest()) {
         $user_id = Auth::user()->id;
         $modules = Cache::get($user_id . 'modules', function () use($user_id) {
             $group_id = Auth::user()->group_id;
             $modules = Group::find($group_id)->modules()->order_by('order', 'asc')->get();
             Cache::forever($user_id . 'modules', $modules);
             return $modules;
         });
         return View::share('navigation_modules', $modules);
     }
 }
 public function showAllAssignmentView()
 {
     if (!is_null(Input::get('group_code'))) {
         Session::put('group_code', Input::get('group_code'));
     }
     if (Session::has('group_code')) {
         $group = Group::find(new MongoId(Session::get('group_code')));
         $students = Student::whereIn('_id', $group->students_id)->get();
         return View::make('student.show_all_assignment')->with(array('group' => $group, 'assignments' => $this->evaluateAssignments($group->_id), 'students' => $students));
     } else {
         return Redirect::to(Lang::get('routes.student'));
     }
 }
Example #16
0
 public function delete($assignment = array())
 {
     if (!isset($this->id) || $this->id == '') {
         return;
     }
     $group = new Group();
     $group->categoryId = $this->id;
     $groups = $group->find();
     foreach ($groups as $item) {
         $item->categoryId = self::DEFAULT_CATEGORY_ID;
         $item->save();
     }
     parent::delete($assignment);
 }
Example #17
0
 public function isUniqueInGroup($data)
 {
     if (empty($data['code'])) {
         return true;
     }
     /* Load the Group model */
     App::import("Webzash.Model", "Group");
     $Group = new Group();
     $count = $Group->find('count', array('conditions' => array('code' => $data['code'])));
     if ($count != 0) {
         return false;
     } else {
         return true;
     }
 }
 public function countUsedMembers(Model $model, $owner_id)
 {
     App::uses('GroupLimit', 'Model');
     App::uses('Group', 'Model');
     $groupModel = new Group();
     $groupLimitModel = new GroupLimit();
     $memberCounts = $groupModel->find('list', array('fields' => array('Group.id', 'Group.active_members'), 'conditions' => array('Group.owner_id' => $owner_id)));
     $totalPaidMembers = 0;
     foreach ($memberCounts as $count) {
         if ($count - 6 > 0) {
             $totalPaidMembers += $count - 6;
         }
     }
     $limit = $groupLimitModel->findByOwnerId($owner_id);
     if (!empty($limit)) {
         $groupLimitModel->id = $limit['GroupLimit']['id'];
         $groupLimitModel->saveField('members_used', $totalPaidMembers, array('validate' => false, 'callbacks' => false, 'counterCache' => false));
     }
     return $totalPaidMembers;
 }
Example #19
0
 public static function getUsrLikeGroups($userId, $start = 0, $limit = 0)
 {
     $likes = RatingLike::find(["entityType", Group::ENTITY_TYPE, "userId", $userId])->all();
     $query = Group::find()->order_desc("id");
     if (!empty($likes)) {
         $args = [];
         $where = "[id] in (";
         for ($i = 0, $count = count($likes); $i < $count; $i++) {
             $args[] = $likes[$i]->entityId;
             $where .= '?' . ($i < $count - 1) ? "," : "";
         }
         unset($likes);
         $where .= ")";
         $query = $query->where($where, $args);
     }
     if ($start != 0 || $limit != 0) {
         return $query->range($start, $limit);
     } else {
         return $query->all();
     }
 }
Example #20
0
 public static function getGroupsOfCategory($categoryId, $start = 0, $limit = 0, $withSubCategory = true)
 {
     $category = Category::get($categoryId);
     if ($category == null) {
         return array();
     }
     $query = Group::find()->order_desc('id');
     if ($withSubCategory) {
         $subs = $category->children();
         $where = "[categoryId] in (?";
         $args = [$categoryId];
         for ($i = 0, $count = count($subs); $i < $count; $i++) {
             $where .= ",?";
             $args[] = $subs[$i]->id;
         }
         $where .= ')';
         $query->where($where, $args);
         unset($subs);
     }
     $groups = $start != 0 || $limit != 0 ? $query->range($start, $limit) : $query->all();
     return $groups;
 }
 public function testBelongsToManyCustom()
 {
     $user = User::create(array('name' => 'John Doe'));
     $group = $user->groups()->create(array('name' => 'Admins'));
     // Refetch
     $user = User::find($user->_id);
     $group = Group::find($group->_id);
     // Check for custom relation attributes
     $this->assertTrue(array_key_exists('users', $group->getAttributes()));
     $this->assertTrue(array_key_exists('groups', $user->getAttributes()));
     // Assert they are attached
     $this->assertTrue(in_array($group->_id, $user->groups));
     $this->assertTrue(in_array($user->_id, $group->users));
     $this->assertEquals($group->_id, $user->groups()->first()->_id);
     $this->assertEquals($user->_id, $group->users()->first()->_id);
 }
Example #22
0
 public function getUserGroups($user = null)
 {
     // If no user is specified, we assume the user context
     // should be the currently logged in user.
     if (is_null($user)) {
         $user = \Auth::User();
     }
     // Grab the users groups
     $groups = \GroupUserPivot::where('user_id', $user->id)->get();
     // Resolve the group ids and names into an array to return
     $resolved_groups = array();
     foreach ($groups as $group) {
         array_push($resolved_groups, \Group::find($group->group_id));
     }
     // Return the array we have created
     return $resolved_groups;
 }
Example #23
0
 /**
  * Processes the request to delete an existing group auth rule.
  *
  * Deletes the specified auth rule.
  * Before doing so, checks that:
  * 1. The user has permission to delete auth rules.
  * This route requires authentication (and should generally be limited to admins or the root user).
  * Request type: POST
  * @param int $auth_id the id of the group auth rule to delete.
  * @todo make this work for user-level rules as well
  */
 public function deleteAuthRule($auth_id)
 {
     $post = $this->_app->request->post();
     // Get the target rule
     $rule = GroupAuth::find($auth_id);
     // Get the alert message stream
     $ms = $this->_app->alerts;
     // Check authorization
     if (!$this->_app->user->checkAccess('delete_auth', ['rule' => $rule])) {
         $ms->addMessageTranslated("danger", "ACCESS_DENIED");
         $this->_app->halt(403);
     }
     // Get group and generate success messages
     $group = Group::find($rule->group_id);
     $ms->addMessageTranslated("success", "GROUP_AUTH_DELETION_SUCCESSFUL", ["name" => $group->name, "hook" => $rule->hook]);
     $rule->delete();
     unset($rule);
 }
<?php

include_once "chain_record_define.php";
/* $obj has same named properties with group table columns. */
$obj = new Group();
$ret = $obj->find(array("order" => "id", "limit" => 1));
/* $ret is almost array (ChainTube Object) */
/* $m is a Group Model class object.       */
$m = $ret[0];
/* change title,memo property by new value */
$m->title = "new updated title";
$m->memo = "new updated memo";
/* update by title="real updated title value" */
/*           memo ="new updated memo"         */
$m->update(array("title" => "real updated title value"));
Example #25
0
 /**
  * View users list
  *
  * @param Request $request
  * @param $matches
  * @return mixed
  */
 public function users_list(Request $request, $matches)
 {
     $filter = [];
     $title = $this->lang->translate('user.list');
     // Filtering by user
     if ($request->get('group')) {
         $filter['conditions'] = ['group_id = ?', intval($request->get('group'))];
         $group = \Group::find($request->get('group'));
         if ($group) {
             $title = $this->lang->translate('user.profile.group') . ' ' . $group->name;
         }
     }
     // Ordering table
     if ($request->order) {
         $filter['order'] = $request->order;
     }
     /** @var Listing $paginator */
     $paginator = NCService::load('Paginator.Listing', [$request->page, $filter ? \User::count($filter) : \User::count()]);
     $filter = array_merge($filter, $paginator->limit());
     // Filter users
     $users = \User::all($filter);
     $users = array_map(function ($i) {
         return $i->to_array();
     }, $users);
     return $this->view->render('users/list.twig', ['title' => $title, 'users_list' => $users, 'listing' => $paginator->pages(), 'page' => $paginator->cur_page]);
 }
Example #26
0
File: Admin.php Project: eadz/chyrp
 /**
  * Function: user_settings
  * User Settings page.
  */
 public function user_settings()
 {
     if (!Visitor::current()->group->can("change_settings")) {
         show_403(__("Access Denied"), __("You do not have sufficient privileges to change settings."));
     }
     if (empty($_POST)) {
         return $this->display("user_settings", array("groups" => Group::find(array("order" => "id DESC"))));
     }
     if (!isset($_POST['hash']) or $_POST['hash'] != Config::current()->secure_hashkey) {
         show_403(__("Access Denied"), __("Invalid security key."));
     }
     $config = Config::current();
     $set = array($config->set("can_register", !empty($_POST['can_register'])), $config->set("default_group", $_POST['default_group']), $config->set("guest_group", $_POST['guest_group']));
     if (!in_array(false, $set)) {
         Flash::notice(__("Settings updated."), "/admin/?action=user_settings");
     }
 }
Example #27
0
 /**
  *
  */
 public function pagework($id)
 {
     $work = Work::find($id);
     $group = Group::find($_GET['group']);
     return View::make('pages.work')->with('work', $work)->with('group', $group)->with('title', $work->title);
 }
Example #28
0
 /**
  * Show the form for editing the specified group.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $group = Group::find($id);
     return View::make('groups.edit', compact('group'));
 }
Example #29
0
 public function delete_destroy($object_id = false)
 {
     $group = Group::find($object_id);
     $group->delete();
     return Redirect::to_action('groups@index');
 }
 static function getActions($params)
 {
     global $DB;
     $res = '';
     if (!isset($params['get'])) {
         exit;
     }
     switch ($params['get']) {
         case "type":
             $res = array('action_types' => self::getActionTypes());
             $res = json_encode($res);
             break;
         case "selection":
             switch ($params['type']) {
                 case 'Computer':
                     $query = "SELECT id, name FROM glpi_computers";
                     if (isset($params['query'])) {
                         $like = $DB->escape($params['query']);
                         $query .= " WHERE name LIKE '%{$like}'";
                     }
                     $query .= " ORDER BY name ASC";
                     $query_res = $DB->query($query);
                     $i = 0;
                     while ($row = $DB->fetch_array($query_res)) {
                         $res['action_selections'][$i]['id'] = $row['id'];
                         $res['action_selections'][$i]['name'] = $row['name'];
                         $i++;
                     }
                     $res = json_encode($res);
                     break;
                 case 'Group':
                     $like = "1";
                     if (isset($params['query'])) {
                         $like = "name LIKE '%" . $DB->escape($params['query']) . "'";
                     }
                     $group = new Group();
                     $group_datas = $group->find($like);
                     $i = 0;
                     foreach ($group_datas as $group_data) {
                         $res['action_selections'][$i]['id'] = $group_data['id'];
                         $res['action_selections'][$i]['name'] = $group_data['name'];
                         $i++;
                     }
                     $res = json_encode($res);
                     break;
                 case 'PluginFusioninventoryDeployGroup':
                     $res = PluginFusioninventoryDeployGroup::getAllDatas('action_selections');
                     break;
             }
             break;
         case "oneSelection":
             break;
         default:
             $res = '';
     }
     return $res;
 }