public function register($data) { $email_activation = $this->ci->config->item('email_activation'); $user = new User($data); $user->save(); // run insert model to write data to db if ($user->is_valid()) { //add a new users to default group $default = $this->ci->config->item('default_group'); $group_default = Group::find_by_name($default); $group = new Usersgroup(array('user_id' => $user->id, 'group_id' => $group_default->id)); $group->save(); //watch if there is a email activation if ($email_activation) { $activation_code = User::deactivate($user->id); if (!$activation_code) { return FALSE; } $data = array('identity' => $user->email, 'id' => $user->id, 'email' => $user->email, 'password' => 'password', 'activation' => $activation_code); $message = $this->ci->load->view($this->ci->config->item('email_templates') . $this->ci->config->item('email_activate'), $data, true); $this->ci->email->clear(); $this->ci->email->set_newline("\r\n"); $this->ci->email->from($this->ci->config->item('admin_email'), $this->ci->config->item('site_title')); $this->ci->email->to($user->email); $this->ci->email->subject($this->ci->config->item('site_title') . ' - ' . lang('web_auth_act')); $this->ci->email->message($message); if ($this->ci->email->send() == TRUE) { return TRUE; } else { return FALSE; } } else { return TRUE; } } if ($user->is_invalid()) { return FALSE; } }
public function join_leaveGroup() { $group_id = $_POST['groupId']; $action = $_POST['action']; $CurrentUser = Auth::User(); $user_id = $CurrentUser->id; $UsersgroupCount = Usersgroup::where('user_id', '=', $user_id)->count(); //die($action); if ($action == 'leave') { if ($UsersgroupCount > 1) { $UsersgroupCount = Usersgroup::where('user_id', '=', $user_id)->where('group_id', '=', $group_id)->delete(); die('success'); } else { die("error"); } } if ($action == 'join') { $UsersgroupCount = Usersgroup::where('user_id', '=', $user_id)->where('group_id', '=', $group_id)->delete(); $usergroup = new Usersgroup(); $usergroup->user_id = $user_id; $usergroup->group_id = $group_id; $usergroup->save(); $user_id_giver = 'null'; $feedType = 'KarmaGroup'; KarmaHelper::storeKarmacirclesfeed($user_id_giver, $user_id, $feedType, $group_id); die('success'); } }
public function delete_groups_user() { Usersgroup::delete_all(array('conditions' => array('user_id' => $this->id))); }
function test_delete_groups() { $groups_user = Usersgroup::find_by_user_id($this->m_user_id); $this->_assert_false($groups_user); }
public static function insertUserConnection($user) { $user_id = $user->id; $token = $user->token; $user_connection_data = "https://api.linkedin.com/v1/people/~/connections?id,first-name,last-name,headline,summary,industry,member-url-resources,picture-urls::(original),location,public-profile-url,site-standard-profile-request&format=json&oauth2_access_token={$token}"; //echo $user_connection_data;exit; $ch = curl_init($user_connection_data); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); $data = curl_exec($ch); curl_close($ch); $user_connection = json_decode($data); Log::alert('User connection fetch'); /* for($i=0;$i<count($user_connection->person);$i++) { print_r($user_connection->person[$i]->{'first-name'}); } */ //echo "<pre>========="; print_r($user_connection); echo "</pre>========"; die; if (!empty($user_connection->values)) { $group = new Usersgroup(); $group->user_id = $user_id; $group->group_id = 1; $group->save(); Usersconnection::where('user_id', '=', $user_id)->delete(); foreach ($user_connection->values as $key => $value) { if (!empty($value->id) && $value->id != 'private') { if (!isset($value->publicProfileUrl) || $value->publicProfileUrl == '') { $publicProfileUrl = $value->siteStandardProfileRequest->url; } else { $publicProfileUrl = $value->publicProfileUrl; } $connection = new Connection(); $connection = Connection::firstOrCreate(array('networkid' => $value->id)); if ($connection['user_id'] != '') { $Connuser = User::find($connection['user_id']); /* $Connuser->fname = @$value->firstName; $Connuser->lname = @$value->lastName;*/ $Connuser->location = @$value->location->name; $Connuser->industry = @$value->industry; $Connuser->piclink = @$value->pictureUrl; $Connuser->linkedinurl = @$publicProfileUrl; $Connuser->headline = @$value->headline; $Connuser->save(); } $connection_id = $connection['id']; $connection = connection::find($connection_id); $connection->networktype = 'linkedin'; if ($connection->user_id == '') { $connection->fname = @$value->firstName; $connection->lname = @$value->lastName; } $connection->headline = @$value->headline; $connection->industry = @$value->industry; $connection->location = @$value->location->name; $connection->piclink = @$value->pictureUrl; $connection->linkedinurl = @$publicProfileUrl; $connection->save(); $users_connections = new Usersconnection(); $users_connections->user_id = $user_id; $users_connections->connection_id = $connection_id; $users_connections->save(); $userDetail = User::find($user_id); $userDetail->totalConnectionCount = $user_connection->_total; $userDetail->save(); } } } $userDetail = User::find($user_id); if (empty($userDetail->totalConnectionCount)) { $userDetail->totalConnectionCount = 0; $userDetail->save(); } $connection = new Connection(); $connection = Connection::firstOrCreate(array('networkid' => $user['linkedinid'])); $connection_id = $connection['id']; $connection = Connection::find($connection_id); $connection->networktype = 'linkedin'; if ($connection->user_id == '') { $connection->fname = @$user['fname']; $connection->lname = @$user['lname']; } $connection->headline = @$user['headline']; $connection->industry = @$user['industry']; $connection->location = @$user['location']; $connection->piclink = @$user['piclink']; $connection->linkedinurl = @$user['linkedinurl']; $connection->user_id = $user_id; $connection->save(); return true; }
/** * Function to update profile "User Group" of particular user. * * @return In Response we will send status{success or failure}. */ public function joinLeaveGroup() { $validator = Validator::make(Request::all(), ['accessToken' => 'required', 'userId' => 'required', 'groupId' => 'required', 'groupAction' => 'required']); if ($validator->fails()) { #display error if validation fails $this->status = 'Validation fails'; $this->message = 'arguments missing'; } else { $userId = Request::get('userId'); $accesstoken = Request::get('accessToken'); $groupId = Request::get('groupId'); $action = Request::get('groupAction'); $usersgroupCount = Usersgroup::where('user_id', '=', $userId)->count(); $user = User::find($userId); $checkGroupId = Group::find($groupId); if (!empty($checkGroupId)) { if ($accesstoken == $user->site_token) { if ($action == 'leave') { if ($usersgroupCount > 1) { $usersgroupCount = Usersgroup::where('user_id', '=', $userId)->where('group_id', '=', $groupId)->delete(); $this->status = 'Success'; $this->message = 'You are successfully leave a group'; } else { $this->status = 'Failure'; $this->message = 'There is something missing'; } return Response::json(array('status' => $this->status)); } if ($action == 'join') { $usersgroupCount = Usersgroup::where('user_id', '=', $userId)->where('group_id', '=', $groupId)->delete(); $usergroup = new Usersgroup(); $usergroup->user_id = $userId; $usergroup->group_id = $groupId; $usergroup->save(); $this->status = 'Success'; $this->message = 'You are successfully join a group'; } else { $this->status = 'Failure'; $this->message = 'There is something missing'; } } else { $this->status = 'Failure'; $this->message = 'You are not a login user'; } } else { $this->status = 'Failure'; $this->message = 'Group cant exist'; } } return Response::json(array('status' => $this->status, 'message' => $this->message)); }
public function UpdateExistingUserGroup() { $users = DB::table('users')->select('id')->get(); $groups_query = DB::select(DB::raw("select id from groups")); $group = array(); foreach ($groups_query as $group_value) { $group[] = $group_value->id; } $userid = 0; $group_set = array(); foreach ($users as $val) { $searchquery = DB::select(DB::raw("select user_id,group_id from users_groups where users_groups.user_id= " . $val->id)); $usergroup_id = array(); //echo"<pre>";print_r($searchquery);echo"</pre>"; foreach ($searchquery as $vals) { $usergroup_id[] = $vals->group_id; } $set = in_array(1, $usergroup_id); if ($set == "") { $usergroup = new Usersgroup(); $usergroup->user_id = $val->id; $usergroup->group_id = 1; $usergroup->save(); } //echo"<pre>==========="; print_r($set); } }
public function deletegroup() { die; $id = Input::get('groupId'); $Usersgroupdata = Usersgroup::where('group_id', '=', $id)->get(); foreach ($Usersgroupdata as $key => $value) { $user_id = $value->user_id; $user = User::find($user_id); //$user->meeting_setting = "accept from all"; $user->meeting_setting = "accept from group only"; $user->save(); } $deleteUsersgroup = Usersgroup::where('group_id', '=', $id)->delete(); $deleteGroup = Group::where('id', '=', $id)->delete(); echo "Group " . $id . " deleted"; }