Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SELS-TASK]Sels user robust #17

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/Activity.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ class Activity extends Model

public function user()
{

return $this->belongsTo('App\User');
}

Expand All @@ -22,8 +21,7 @@ public function createActivity($data)
'action_id'=> $data['action_id'],
'action_type'=>"App\Lesson",
'user_id'=> $data['user_id'],
'content'=> ' learned ' . $data['score'] . ' out of ' . $data['questionCount'] . ' from ' . $data['title'] ,
'content'=> ' learned ' . $data['score'] . ' out of ' . $data['questionCount'] . ' words from ' . $data['title'] ,
]);

}
}
11 changes: 2 additions & 9 deletions app/Answer.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,21 @@ class Answer extends Model

public function getChoices()
{

return $this->belongsTo('App\Choices','choice_id');

return $this->belongsTo('App\Choices','choice_id');
}

public function getQuestion()
{

return $this->belongsTo('App\Question','question_id');

return $this->belongsTo('App\Question','question_id');
}

public function lesson()
{

return $this->belongsTo('App\Lesson');

}

public function createAnswer($data)
{

Answer::create([
'choice_id' => $data['choice_id'],
'question_id' =>$data['question_id'],
Expand Down
16 changes: 15 additions & 1 deletion app/Choices.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,19 @@

class Choices extends Model
{
//
protected $fillable = [
'word', 'question_id', 'isCorrect'
];

public function question()
{
return $this->belongsTo('App\Question');

}
public function getAnswer()
{

return $this->hasOne('App\Answer','choice_id');
}

}
21 changes: 21 additions & 0 deletions app/Follower.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use App\Follower;

class Follower extends Model
{
public function actions()
{
return $this->morphMany('App\Activity', 'action');

}

public function user()
{
return $this->hasMany('App\User','follower_id');

}
}
63 changes: 59 additions & 4 deletions app/Http/Controllers/CategoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ public function store()

Category::create($attributes);

return redirect('/home');
return redirect('/category/edit');
}

public function show()
public function change()
{
$categories = Category::all();

Expand All @@ -38,13 +38,68 @@ public function edit($id)
$category->description = request('description');

$category->save();
return redirect('/category/show');
return redirect('/category/edit');
}

public function destroy($id)
{
Category::find($id)->delete();

return redirect('/category/show');
return redirect('/category/edit');
}

public function addQuestion()
{

return view('category/addQuestion');
}

public function storeQuestion(Request $request)
{
$title=$request->get('title');

$category= Category::where('title','=',$title)->first();

if($category==null){

return redirect('/home');
}
else{
$categoryId = $category->id;
Question::create([
'term'=> $request->get('question'),
'category_id'=> $categoryId,
]);
}

return redirect('/home');
}

public function addChoice()
{

return view('category/addChoice');
}

public function storeChoice(Request $request)
{
$question=$request->get('question');

$question= Question::where('term','=',$question)->first();

if($question==null){

return redirect('/home');
}
else{
$questionId = $question->id;
Choices::create([
'word'=> $request->get('choice'),
'question_id'=> $questionId,
'isCorrect'=> $request->get('isCorrect'),
]);
}

return redirect('/home');
}
}
32 changes: 29 additions & 3 deletions app/Http/Controllers/HomeController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Result;

class HomeController extends Controller
{
Expand All @@ -21,13 +22,38 @@ public function __construct()
*
* @return \Illuminate\Contracts\Support\Renderable
*/
public function index()
public function index(Request $request)
{
return view('home');
$allActivities = collect();
$followingActivities =collect();
$user = Auth()->user();
$userActivities = Auth()->user()->activity;
$followings = $user->followings;

if($user->followings){
foreach($followings as $following){
foreach($following->activity as $activity){
$allActivities->push($activity);
}
}
}

foreach($userActivities as $userActivity){

$allActivities->push($userActivity);
}

$wordsLearned = 0;
$currentUserId = auth()->user()->id;
$results= Result::where('user_id','=',$currentUserId )->get();
for($i=0;$i<$results->count();$i++){
$wordsLearned = $wordsLearned+ $results[$i]->score;
}

return view('home',compact('allActivities','wordsLearned'));
}
public function admin()
{
return view('admin');
}

}
74 changes: 74 additions & 0 deletions app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use App\Traits\UploadTrait;
use Intervention\Image\Facades\Image;


class ProfileController extends Controller
{

use UploadTrait;

public function __construct()
{
$this->middleware('auth');
}

public function index()
{
return view('auth.profile');
}

public function updateProfile(Request $request)
{
// Form validation
$request->validate([
'name' => 'required',
'profile_image' => 'required|image|mimes:jpeg,png,jpg,gif|max:2048'
]);

// Get current user
$user = User::findOrFail(auth()->user()->id);
// Set user name
$user->name = $request->input('name');

// Check if a profile image has been uploaded
if ($request->has('profile_image')) {
// Get image file
// $image = $request->file('profile_image')->resize(100,100);
// // Make a image name based on user name and current timestamp
// $name = str_slug($request->input('name')).'_'.time();
// // Define folder path
// $folder = '/uploads/images/';
// // Make a file path where image will be stored [ folder path + file name + file extension]
// $filePath = $folder . $name. '.' . $image->getClientOriginalExtension();

// // Upload image
// $this->uploadOne($image, $folder, 'public', $name);

// // Set user profile image path in database to filePath
// $user->profile_image = "/storage" . $filePath;

$photo = $request->file('profile_image');

$imagename = time().'.'.$photo->getClientOriginalExtension();

$destinationPath = public_path('\storage\thumbnail');
$thumb_img = Image::make($photo->getRealPath())->resize(100, 100);
$thumb_img->save($destinationPath."/".$imagename,80);

$destinationPath = public_path('/normal_images');
$photo->move($destinationPath, $imagename);
$user->profile_image = "/storage/thumbnail/" . $imagename;
}
// Persist user record to database
$user->save();

// Return user back and show a flash message
return redirect()->back()->with(['status' => 'Profile updated successfully.']);
}
}
Loading