Пример #1
0
 public function postGroup($id = null)
 {
     if (Input::has('id')) {
         $group = Group::find(Input::get('id'));
         if (!$group->isGroupOwner(Auth::user()->id)) {
             return Response::json($this->growlMessage('You cannot modify a group you do not own.', 'error'));
         }
         $message = "Your group has been updated!";
     } else {
         $group = new Group();
         $group->status = Group::STATUS_PENDING;
         $message = "Your group has been created! It must be approved before you can invite others to join or create documents.";
     }
     $postData = array('name', 'display_name', 'address1', 'address2', 'city', 'state', 'postal_code', 'phone_number');
     foreach ($postData as $field) {
         $group->{$field} = Input::get($field);
     }
     if ($group->validate()) {
         $group->save();
         $group->addMember(Auth::user()->id, Group::ROLE_OWNER);
         if ($group->status === Group::STATUS_PENDING) {
             Event::fire(MadisonEvent::VERIFY_REQUEST_GROUP, $group);
         }
         return Response::json($this->growlMessage($message, 'success'));
     } else {
         return Response::json($this->growlMessage($group->getErrors()->all(), 'error'), 400);
     }
 }
Пример #2
0
 public function index()
 {
     $groups = Group::orderBy('position')->get();
     $group = new Group();
     if (Request::isMethod('post')) {
         $validator = Validator::make(Request::all(), $this->rules, $this->messages);
         if ($validator->passes()) {
             $group->title = Request::input('title');
             $group->titleEng = Request::input('titleEng');
             $group->text = Request::input('text');
             $group->eng = Request::input('eng');
             $group->link = Request::input('link');
             $group->position = Request::input('position');
             $group->enabled = Request::has('enabled');
             if ($file = Request::file('photo')) {
                 $group->photo = $this->upload($file, 'photo');
             }
             if ($file = Request::file('partners')) {
                 $group->partners = $this->upload($file, 'photo');
             }
             $group->save();
             return redirect('admin/group')->with('msg', 'Агентство было успешно создано');
         } else {
             return redirect('admin/group')->withInput()->withErrors($validator);
         }
     }
     return view('admin.group', ['groups' => $groups, 'group' => $group]);
 }
Пример #3
0
 /**
  * Creates a new Group model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Group();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
Пример #4
0
 public function actionCreate()
 {
     $group = new Group();
     Yii::$app->response->format = 'json';
     if ($group->load(Yii::$app->request->post()) && $group->save()) {
         return ['errors' => '', 'data' => $this->renderPartial('@widget/views/groups/_add', ['group' => $group])];
     }
     return ['errors' => '', 'data' => $this->renderPartial('@widget/views/groups/_add', ['group' => $group])];
 }
Пример #5
0
 /**
  * Validates and stores the new User Group data.
  *
  * @author [A. Gianotto] [<snipe@snipe.net]
  * @see GroupsController::getCreate()
  * @since [v1.0]
  * @return Redirect
  */
 public function postCreate()
 {
     // create a new group instance
     $group = new Group();
     $group->name = e(Input::get('name'));
     $group->permissions = json_encode(Input::get('permission'));
     if ($group->save()) {
         return redirect()->to("admin/groups")->with('success', trans('admin/groups/message.success.create'));
     }
     return redirect()->back()->withInput()->withErrors($group->getErrors());
 }
Пример #6
0
 /**
  * 项目添加用户
  *
  * @param $projectId
  * @param $userId
  * @return bool
  */
 public static function addGroupUser($projectId, $userId)
 {
     // 是否已在组内
     $exists = Group::find()->where(['project_id' => $projectId, 'user_id' => $userId])->count();
     if ($exists) {
         return true;
     }
     $group = new Group();
     $group->attributes = ['project_id' => $projectId, 'user_id' => $userId];
     return $group->save();
 }
Пример #7
0
 /**
  * Creates a new Group model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $app = \Yii::$app;
     $model = new Group();
     $render = "render";
     if ($app->request->isPjax || $app->request->isAjax) {
         $render = "renderPartial";
     }
     if ($model->load($app->request->post()) && $model->save()) {
         $model = new Group();
     }
     return $this->{$render}('form', ['model' => $model]);
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     Schema::create('groups', function (Blueprint $table) {
         $table->increments('id');
         $table->string('name');
         $table->timestamps();
         $table->softDeletes();
         $table->unsignedInteger('created_user_id')->nullable();
         $table->unsignedInteger('updated_user_id')->nullable();
         $table->unsignedInteger('deleted_user_id')->nullable();
     });
     foreach (['System', 'Admin', 'Develop', 'Guest', '*', '*', '*', '*', '*', '*'] as $key => $value) {
         $group = new Group();
         $group->name = $value;
         $group->save();
     }
 }
Пример #9
0
 public function testCascadeModel()
 {
     $user = new User(array('fullname' => 'Mukhamad Ikhsan', 'email' => '*****@*****.**', 'password' => 'rahasia'));
     $this->assertTrue($user->save());
     $group = new Group(array('name' => "Testing"));
     $this->assertTrue($group->save());
     $user->addGroup($group);
     $this->assertTrue($user->save());
     $this->assertEqual(1, count($user->groups));
     $this->assertEqual(1, count($group->members));
     $ikhsan = User::getRepository()->findOneBy(array('email' => '*****@*****.**'));
     $testing = Group::getRepository()->findOneBy(array('name' => 'Testing'));
     $this->assertEqual(1, count($ikhsan->groups));
     $this->assertEqual(1, count($testing->members));
     $user->delete();
     $group->delete();
 }
Пример #10
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function postSave(Request $request)
 {
     $input = $request->all();
     $rules = array('name' => 'required|unique:px_group');
     $validator = Validator::make($input, $rules);
     if ($validator->passes()) {
         $group = new Group();
         $group->name = $input['name'];
         $group->description = nl2br($input['description']);
         if ($group->save()) {
             return redirect('group/list')->with('status', '组 ' . $group->name . ' 添加成功');
         } else {
             return back()->withErrors('组添加失败');
         }
     } else {
         return back()->withErrors($validator);
     }
 }
Пример #11
0
 public function run()
 {
     $group = new Group();
     $group->status = Group::STATUS_ACTIVE;
     $group->name = 'Example Group';
     $group->display_name = 'Example Group Display';
     $group->address1 = '1234 Somewhere';
     $group->city = 'City';
     $group->state = 'DC';
     $group->postal_code = '12345';
     $group->phone_number = '555-555-5555';
     $group->save();
     $adminEmail = Config::get('madison.seeder.admin_email');
     $adminPassword = Config::get('madison.seeder.admin_password');
     $userEmail = Config::get('madison.seeder.user_email');
     // Login as admin to add members to group
     $credentials = array('email' => $adminEmail, 'password' => $adminPassword);
     Auth::attempt($credentials);
     $admin = User::where('email', '=', $adminEmail)->first();
     $user = User::where('email', '=', $userEmail)->first();
     $group->addMember($admin->id, Group::ROLE_OWNER);
     $group->addMember($user->id, Group::ROLE_EDITOR);
 }
Пример #12
0
 // Get a group and its users
 $app->get('/group/{id}', function ($id) {
     $group = Group::with('user')->with('users')->find($id);
     return response()->json($group);
 });
 // Get the timeline of certain group
 $app->get('/group/{id}/messages', function ($id) {
 });
 // Create a group
 $app->post('/group', function (Request $request) {
     $user = JWTAuth::parseToken()->authenticate();
     $group = new Group();
     $group->name = $request->input('name');
     $group->description = $request->input('description');
     $group->user_id = $user->id;
     $group->save();
     return response()->json($group);
 });
 // Update a group
 $app->put('/group/{id}', function () {
 });
 // Assign user to a group
 $app->post('/group/{id}/user', function (Request $request, $id) {
     $user_id = $request->input('user_id');
     $user = User::find($user_id);
     if (!$user) {
         return response()->json(['status' => 'error', 'message' => 'user-not-found']);
     }
     $group = Group::find($id);
     if (!$group) {
         return response()->json(['status' => 'error', 'message' => 'not-found']);
Пример #13
0
 function postGroupModal(Request $request, Group $group)
 {
     /* Check the input */
     $validator = Validator::make($request->all(), ['name' => 'required']);
     if ($validator->fails()) {
         return redirect('staff/group-modal/' . $group->id)->withErrors($validator);
     }
     /* Store changes into database */
     $group->name = $request->get('name');
     $group->assistant_id = $request->get('assistant_id') ?: null;
     $group->project_id = $request->get('project_id') ?: null;
     $group->remark = $request->get('remark');
     $group->save();
     return;
 }
Пример #14
0
 public function run()
 {
     ////////////////////////////////////////////////////////////////////////////////
     // creation group types ////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////
     $gt_employee = new GroupType();
     $gt_employee->name = "employee";
     $gt_employee->display_name = "Employee";
     $gt_employee->description = "this is the group type of all employees of E80";
     $gt_employee->save();
     $gt_customer = new GroupType();
     $gt_customer->name = "customer";
     $gt_customer->display_name = "Customer";
     $gt_customer->description = "this is the group type of all E80 customers";
     $gt_customer->save();
     ////////////////////////////////////////////////////////////////////////////////
     // creation groups /////////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////
     $helpdesk = new Group();
     $helpdesk->group_type_id = $gt_employee->id;
     $helpdesk->name = "e80-helpdesk";
     $helpdesk->display_name = "E80 Helpdesk";
     $helpdesk->description = "this is the group of all E80 helpdesk";
     $helpdesk->save();
     $basic_customer = new Group();
     $basic_customer->group_type_id = $gt_customer->id;
     $basic_customer->name = "basic-customer";
     $basic_customer->display_name = "Basic Customer";
     $basic_customer->description = "this is the group of E80 customers";
     $basic_customer->save();
     ////////////////////////////////////////////////////////////////////////////////
     // creation permissions ////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////
     $ticket_create = new Permission();
     $ticket_create->name = "create-tickets";
     $ticket_create->display_name = "Create Tickets";
     $ticket_create->description = "Create Tickets";
     $ticket_create->save();
     $ticket_read = new Permission();
     $ticket_read->name = "read-tickets";
     $ticket_read->display_name = "Read Tickets";
     $ticket_read->description = "Read Tickets";
     $ticket_read->save();
     $ticket_update = new Permission();
     $ticket_update->name = "update-tickets";
     $ticket_update->display_name = "Update Tickets";
     $ticket_update->description = "Update Tickets";
     $ticket_update->save();
     $ticket_delete = new Permission();
     $ticket_delete->name = "delete-tickets";
     $ticket_delete->display_name = "Delete Tickets";
     $ticket_delete->description = "Delete Tickets";
     $ticket_delete->save();
     ////////////////////////////////////////////////////////////////////////////////
     // creation roles //////////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////
     $ticket_manager = new Role();
     $ticket_manager->name = "ticket-manager";
     $ticket_manager->display_name = "Ticket Manager";
     $ticket_manager->description = "Ticket Manager";
     $ticket_manager->save();
     $ticket_viewer = new Role();
     $ticket_viewer->name = "ticket-viewer";
     $ticket_viewer->display_name = "Ticket Viewer";
     $ticket_viewer->description = "Ticket Viewer";
     $ticket_viewer->save();
     ////////////////////////////////////////////////////////////////////////////////
     // creation permission_role ////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////
     DB::table('permission_role')->insert([['role_id' => $ticket_manager->id, 'permission_id' => $ticket_create->id], ['role_id' => $ticket_manager->id, 'permission_id' => $ticket_read->id], ['role_id' => $ticket_manager->id, 'permission_id' => $ticket_update->id], ['role_id' => $ticket_manager->id, 'permission_id' => $ticket_delete->id]]);
     DB::table('permission_role')->insert([['role_id' => $ticket_viewer->id, 'permission_id' => $ticket_read->id]]);
     ////////////////////////////////////////////////////////////////////////////////
     // creation group_role /////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////
     DB::table('group_role')->insert([['group_id' => $helpdesk->id, 'role_id' => $ticket_manager->id], ['group_id' => $basic_customer->id, 'role_id' => $ticket_viewer->id]]);
 }