/**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     $actions = Action::where('action', 'signed up')->get();
     foreach ($actions as $action) {
         Signup::firstOrCreate(['campaign_id' => $action->campaign_id, 'contact_id' => $action->contact_id]);
     }
 }
 public function search(Request $request)
 {
     $results = array();
     $term = $request->get('term');
     $goals = Goal::where('body', 'like', '%' . $term . '%')->orderBy('body', 'asc')->get();
     $objectives = Objective::where('body', 'like', '%' . $term . '%')->orderBy('body', 'asc')->get();
     $actions = Action::where('body', 'like', '%' . $term . '%')->orderBy('body', 'asc')->get();
     $tasks = Task::where('body', 'like', '%' . $term . '%')->orderBy('body', 'asc')->get();
     $teams = Team::where('name', 'like', '%' . $term . '%')->orderBy('name', 'asc')->get();
     $departments = Department::where('name', 'like', '%' . $term . '%')->orderBy('name', 'asc')->get();
     $users = User::where('name', 'like', '%' . $term . '%')->orderBy('name', 'asc')->get()->all();
     foreach (User::where('email', 'like', '%' . $term . '%')->orderBy('name', 'asc')->get() as $matching_user_email) {
         if (in_array($matching_user_email, $users)) {
             continue;
         }
         $users[] = $matching_user_email;
     }
     $notes = Note::where('content', 'like', '%' . $term . '%')->orderBy('content', 'asc')->get();
     $types = [$goals, $objectives, $actions, $tasks, $teams, $departments, $users, $notes];
     foreach ($types as $type) {
         foreach ($type as $result) {
             $results[] = $result;
         }
     }
     return view('search.show')->with('results', $results)->with('term', $term);
 }
 public function sendNotificationEmail(Group $group, User $user)
 {
     if ($user->verified == 1) {
         // Establish timestamp for notifications from membership data (when was an email sent for the last time?)
         $membership = \App\Membership::where('user_id', '=', $user->id)->where('group_id', "=", $group->id)->firstOrFail();
         $last_notification = $membership->notified_at;
         // find unread discussions since timestamp
         $discussions = QueryHelper::getUnreadDiscussionsSince($user->id, $group->id, $membership->notified_at);
         // find new files since timestamp
         $files = \App\File::where('updated_at', '>', $membership->notified_at)->where('group_id', "=", $group->id)->get();
         // find new members since timestamp
         $users = QueryHelper::getNewMembersSince($user->id, $group->id, $membership->notified_at);
         // find future actions until next 2 weeks, this is curently hardcoded... TODO use the mail sending interval to determine stop date
         $actions = \App\Action::where('start', '>', Carbon::now())->where('stop', '<', Carbon::now()->addWeek()->addWeek())->where('group_id', "=", $group->id)->orderBy('start')->get();
         // we only trigger mail sending if a new action has been **created** since last notfication email.
         // BUT we will send actions for the next two weeks in all cases, IF a mail must be sent
         $actions_count = \App\Action::where('created_at', '>', $membership->notified_at)->where('group_id', "=", $group->id)->count();
         // in all cases update timestamp
         $membership->notified_at = Carbon::now();
         $membership->save();
         // if we have anything, build the message and send
         // removed that : or count($users) > 0
         // because we don't want to be notified just because there is a new member
         if (count($discussions) > 0 or count($files) > 0 or $actions_count > 0) {
             Mail::send('emails.notification', ['user' => $user, 'group' => $group, 'membership' => $membership, 'discussions' => $discussions, 'files' => $files, 'users' => $users, 'actions' => $actions, 'last_notification' => $last_notification], function ($message) use($user, $group) {
                 $message->from(env('MAIL_NOREPLY', '*****@*****.**'), env('APP_NAME', 'Laravel'))->to($user->email)->subject('[' . env('APP_NAME') . '] ' . trans('messages.news_from_group_email_subject') . ' "' . $group->name . '"');
             });
             return true;
         }
         return false;
     }
 }
 /**
  * Determine if the user is authorized to make this request.
  *
  * @return bool
  */
 public function authorize()
 {
     $actionid = $this->route('id');
     if (Auth::check()) {
         return Auth::user()->id == Action::find($actionid)->userId || User::find(Auth::id())->hasRole('bpLead') || User::find(Group::find(Action::find($actionid)->group)->user_ID)->id == Auth::id();
     } else {
         return false;
     }
 }
Beispiel #5
0
 public function remove(Objective $objective)
 {
     foreach ($objective->actions as $action) {
         foreach ($action->tasks as $task) {
             Task::destroy($task->id);
         }
         Action::destroy($action->id);
     }
     Objective::destroy($objective->id);
     return redirect('/plan');
 }
 public function index(Request $request)
 {
     if ($request->has('query')) {
         $query = $request->get('query');
         // build a list of public groups and groups the user has access to
         $my_groups = Auth::user()->groups()->orderBy('name')->get();
         $my_groups_id = [];
         // using this array we can adjust the queries after to only include stuff the user has
         // might be a good idea to find a clever way to build this array of groups id :
         foreach ($my_groups as $the_group) {
             $my_groups_id[$the_group->id] = $the_group->id;
         }
         $public_groups = \App\Group::where('group_type', \App\Group::OPEN)->get();
         $public_groups_id = [];
         // using this array we can adjust the queries after to only include stuff the user has
         // might be a good idea to find a clever way to build this array of groups id :
         foreach ($public_groups as $the_group) {
             $public_groups_id[$the_group->id] = $the_group->id;
         }
         $allowed_groups = array_merge($my_groups_id, $public_groups_id);
         $groups = \App\Group::where('name', 'like', '%' . $query . '%')->orWhere('body', 'like', '%' . $query . '%')->orderBy('name')->get();
         $users = \App\User::where('name', 'like', '%' . $query . '%')->orWhere('body', 'like', '%' . $query . '%')->orderBy('name')->with('groups')->get();
         $discussions = \App\Discussion::where('name', 'like', '%' . $query . '%')->orWhere('body', 'like', '%' . $query . '%')->whereIn('group_id', $allowed_groups)->orderBy('updated_at', 'desc')->with('group')->get();
         $actions = \App\Action::where('name', 'like', '%' . $query . '%')->orWhere('body', 'like', '%' . $query . '%')->whereIn('group_id', $allowed_groups)->with('group')->orderBy('updated_at', 'desc')->get();
         $files = \App\File::where('name', 'like', '%' . $query . '%')->whereIn('group_id', $allowed_groups)->with('group')->orderBy('updated_at', 'desc')->get();
         $comments = \App\Comment::where('body', 'like', '%' . $query . '%')->with('discussion.group')->orderBy('updated_at', 'desc')->get();
         // set in advance which tab will be active on the search results page
         $groups->class = '';
         $discussions->class = '';
         $actions->class = '';
         $users->class = '';
         $comments->class = '';
         $files->class = '';
         // the order of those ifs should match the order of the tabs on the results view :-)
         if ($groups->count() > 0) {
             $groups->class = 'active';
         } elseif ($discussions->count() > 0) {
             $discussions->class = 'active';
         } elseif ($actions->count() > 0) {
             $action->class = 'active';
         } elseif ($users->count() > 0) {
             $users->class = 'active';
         } elseif ($comments->count() > 0) {
             $comments->class = 'active';
         } elseif ($files->count() > 0) {
             $files->class = 'active';
         }
         return view('search.results')->with('groups', $groups)->with('users', $users)->with('discussions', $discussions)->with('files', $files)->with('comments', $comments)->with('actions', $actions)->with('query', $query);
     }
 }
 public function addAction(Request $request, Plan $plan)
 {
     if (isset($request->add)) {
         $newaction = Action::create($request->all());
         $newaction->date = Carbon::createFromFormat("Y-m-d", $request->duedate)->toDateTimeString();
         if (isset($request->collabs)) {
             $newaction->collaborators = implode("__,__", $request->collabs);
         }
         $newaction->save();
         return view('plans.addactions')->with('plan', $plan);
     } else {
         return view('plans.addtasks')->with('plan', $plan);
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     //
     $action = Action::find($id);
     //return $gender;
     if (count($action) > 0) {
         $statusCode = 200;
         $response = ['id' => $action->id, 'Action' => $action->action];
     } else {
         $response = ["error" => "Action doesn`t exist"];
         $statusCode = 404;
     }
     return response($response, $statusCode)->header('Content-Type', 'application/json');
 }
 public function remove(Goal $goal)
 {
     if ($goal->body == "Non-Business Plan") {
         return back();
     }
     foreach ($goal->objectives as $objective) {
         foreach ($objective->actions as $action) {
             foreach ($action->tasks as $task) {
                 Task::destroy($task->id);
             }
             Action::destroy($action->id);
         }
         Objective::destroy($objective->id);
     }
     Goal::destroy($goal->id);
     return redirect('/plan');
 }
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     // open csv file from storage
     $csv = Reader::createFromPath(storage_path('import/actions.csv'));
     //get the first row, usually the CSV header
     $headers = $csv->fetchOne();
     // validate headers
     //get 25 rows starting from the 11th row
     $res = $csv->setOffset(1)->fetchAll();
     // build a nice associative array from the csv
     foreach ($res as $data) {
         foreach ($headers as $key => $header) {
             $action[$header] = $data[$key];
         }
         $actions_data[] = $action;
     }
     foreach ($actions_data as $action_data) {
         if (isset($action_data['id'])) {
             $action = \App\Action::firstOrNew(['id' => $action_data['id']]);
             $action->name = $action_data['name'];
             $action->body = $action_data['body'];
             $action->start = \Carbon\Carbon::parse($action_data['start']);
             $action->stop = \Carbon\Carbon::parse($action_data['stop']);
             $action->location = $action_data['location'];
             $action->user_id = 1;
             // create the group if not existing yet and associate it.
             if (!empty($action_data['group_id']) && !empty($action_data['group'])) {
                 $group = \App\Group::firstOrNew(['id' => $action_data['group_id'] + $this->id_offset]);
                 $group->name = $action_data['group'];
                 $group->body = 'No description';
                 $group->save();
                 $action->group()->associate($group);
                 $this->info($group->name . ' GROUP has been created/updated in db');
                 $action->save();
                 if ($action->isInvalid()) {
                     $this->error($action->getErrors());
                 } else {
                     $this->info($action->name . ' ACTION has been created/updated in db');
                 }
             }
         }
     }
 }
 public function editTaskFromComments($id, Requests\EditTaskRequest $request)
 {
     $progress = ['0' => 'Not Started', '1' => 'In Progress', '2' => 'Done'];
     $model = new Task();
     $task = Task::findOrFail($id);
     $groups = Group::lists('name', 'id');
     $users = User::lists('name', 'id');
     $bpid = $model->getBpIdFromTask($id);
     $action = Action::find($task->action_id)->description;
     $names = explode(', ', $task->collaborators);
     $selectedUsers = array();
     $selectedGroups = array();
     foreach ($names as $name) {
         if (count(User::all()->where('name', $name)) > 0) {
             array_push($selectedUsers, User::all()->where('name', $name)->first()->id);
         }
         if (count(Group::all()->where('name', $name)) > 0) {
             array_push($selectedGroups, Group::all()->where('name', $name)->first()->id);
         }
     }
     return view('editTaskComments', compact('task', 'action', 'groups', 'users', 'bpid', 'selectedUsers', 'selectedGroups', 'progress'));
 }
 public function updateAction($id, Request $request)
 {
     $collabs = "";
     $model = new Action();
     $input = $request->all();
     $actionComment = new ActionComments();
     $comments = $actionComment->getComments($id);
     $action = Action::findOrFail($id);
     $users = array();
     $roster = DB::table('rosters')->select('user_ID')->where('group_ID', '=', $action->group)->get();
     foreach ($roster as $x) {
         array_push($users, $x->user_ID);
     }
     $groupLead = User::find(Group::find($action->group)->user_ID)->id;
     if (Auth::check()) {
         $user = User::find(Auth::id());
         $permission = $user->hasRole('bpLead');
     } else {
         $permission = false;
     }
     $businessplan = $model->getBpIdFromAction($id);
     if (array_key_exists('collaborators-groups', $input)) {
         foreach ($input['collaborators-groups'] as $x) {
             $collabs .= Group::find($x)->name;
             $collabs .= ", ";
         }
     }
     if (array_key_exists('collaborators-users', $input)) {
         foreach ($input['collaborators-users'] as $x) {
             $collabs .= User::find($x)->name;
             $collabs .= ", ";
         }
     }
     $collabs = rtrim($collabs, ", ");
     $input['collaborators'] = $collabs;
     $action->update($input);
     $tasks = Task::all()->where('action_id', $id);
     return view('action', compact('comments', 'action', 'tasks', 'users', 'permission', 'groupLead', 'businessplan'));
 }
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     // 1. Create new calendar
     $vCalendar = new \Eluceo\iCal\Component\Calendar(config('app.url'));
     $vCalendar->setName(config('mobilizator.name'));
     // returns actions from the last 60 days
     $actions = \App\Action::with('group')->where('start', '>=', Carbon::now()->subDays(60))->get();
     foreach ($actions as $action) {
         // 2. Create an event
         $vEvent = new \Eluceo\iCal\Component\Event();
         $vEvent->setDtStart($action->start);
         $vEvent->setDtEnd($action->stop);
         $vEvent->setSummary($action->name);
         $vEvent->setDescription(summary($action->body), 1000);
         $vEvent->setLocation($action->location);
         $vEvent->setUrl(action('ActionController@show', [$action->group->id, $action->id]));
         $vEvent->setUseUtc(false);
         //TODO fixme
         $vCalendar->addComponent($vEvent);
     }
     return response($vCalendar->render())->header('Content-Type', 'text/calendar; charset=utf-8')->header('Content-Disposition', 'attachment; filename="cal.ics"');
 }
 public function report($id)
 {
     $campaign = Campaign::find($id);
     $summary = [];
     $actions = Action::with('contact')->forCampaign($campaign)->orderBy('contact_id')->get();
     $summary['total_sent'] = $campaign->emails->count();
     $summary['opened'] = $actions->filter(function ($action) {
         return $action->action === 'opened';
     })->count();
     $summary['more info'] = $actions->filter(function ($action) {
         return $action->action === 'more info';
     })->count();
     $summary['website_visits'] = $actions->filter(function ($action) {
         return $action->action === 'website';
     })->count();
     $summary['skipped_video'] = $actions->filter(function ($action) {
         return $action->action === 'skipped';
     })->count();
     $summary['emailed_bill'] = $actions->filter(function ($action) {
         return $action->action === 'email';
     })->count();
     $summary['youtube_channel'] = $actions->filter(function ($action) {
         return $action->action === 'youtube';
     })->count();
     $summary['unsubscribed'] = Contact::where('unsubscribe', '=', 1)->count();
     \Excel::create('Report', function ($excel) use($actions, $summary, $campaign) {
         $excel->setTitle("eMail Report for {$campaign->name}")->setCreator('Exhibit Partners Mailer Service')->setCompany('Exhibit Partners')->setDescription("A detailed report of email recipients for the {$campaign->name} email campaign");
         $excel->sheet('Summary', function ($sheet) use($summary) {
             $sheet->row(1, ['Total', 'Opened', 'Went To Page 2', 'Website Visits', 'Skipped The Video', 'Emailed Bill', 'YouTube Channel', 'Unsubscribed']);
             $sheet->row(2, [$summary['total_sent'], $summary['opened'], $summary['more info'], $summary['website_visits'], $summary['skipped_video'], $summary['emailed_bill'], $summary['youtube_channel'], $summary['unsubscribed']]);
         });
         $excel->sheet('Recipient Actions', function ($sheet) use($actions) {
             $sheet->row(1, ['Contact', 'Email', 'Action']);
             foreach ($actions as $key => $action) {
                 $sheet->row($key + 2, [$action->contact->name, $action->contact->email, $action->action]);
             }
         });
     })->download('xlsx');
 }
 public function touchActions($id)
 {
     $touch = Touch::find($id);
     $actions = Action::with('contact')->where('touch_id', '=', $touch->id)->orderBy('action')->orderBy('contact_id', 'DESC')->get(['action', 'contact_id']);
     $actions = array_map(function ($action) {
         foreach ($action['contact'] as $key => $value) {
             $action[$key] = $value;
         }
         unset($action['contact_id'], $action['id'], $action['contact'], $action['unsubscribe'], $action['client_id'], $action['updated_at'], $action['created_at'], $action['bounced']);
         return $action;
     }, $actions->toArray());
     $metrics = Excel::create("{$touch->title} Metrics", function ($excel) use($touch, $actions) {
         $excel->setTitle("Email Metrics for {$touch->title}");
         $excel->setCreator("EP-Productions");
         $excel->setCompany('Exhibit Partners');
         $excel->setDescription("Email metrics from an email campaign for {$touch->campaign}->client->name by Exhibit Partners");
         $excel->sheet('Metrics', function ($sheet) use($actions) {
             $sheet->fromArray($actions);
         });
         $excel->sheet('Bounces', function ($sheet) use($touch) {
             $bounces = $touch->bounces->toArray();
             $bounces = array_map(function ($contact) {
                 unset($contact['id'], $contact['client_id'], $contact['bounced'], $contact['unsubscribe'], $contact['updated_at'], $contact['created_at']);
                 return $contact;
             }, $bounces);
             $sheet->fromArray($bounces);
         });
         $excel->sheet('Unsubscribes', function ($sheet) use($touch) {
             $unsubscribes = $touch->unsubscribes->toArray();
             $unsubscribes = array_map(function ($contact) {
                 unset($contact['id'], $contact['client_id'], $contact['bounced'], $contact['unsubscribe'], $contact['updated_at'], $contact['created_at']);
                 return $contact;
             }, $unsubscribes);
             $sheet->fromArray($unsubscribes);
         });
     })->download('xlsx');
     return $metrics;
 }
Beispiel #16
0
// Info user action
$factory->defineAs(App\UserAction::class, 'info', function ($faker) use($factory) {
    $userAction = $factory->raw(\App\UserAction::class);
    $userAction['action_id'] = \App\Action::where('type', 'info')->first()->id;
    return $userAction;
});
// Wrong format user action
$factory->defineAs(\App\UserAction::class, 'wrong_format', function ($faker) use($factory) {
    $userAction = $factory->raw(\App\UserAction::class);
    $userAction['action_id'] = \App\Action::where('type', 'wrong_format')->first()->id;
    return $userAction;
});
// Not allowed user action
$factory->defineAs(\App\UserAction::class, 'not_allowed', function ($faker) use($factory) {
    $userAction = $factory->raw(\App\UserAction::class);
    $userAction['action_id'] = \App\Action::where('type', 'not_allowed')->first()->id;
    return $userAction;
});
/**
 * Generate new offer.
 */
$factory->define(App\Offer::class, function ($faker) {
    $paymillOfferId = 'offer_' . substr(str_shuffle('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'), 0, 20);
    return ['paymill_offer_id' => $paymillOfferId, 'name' => $faker->word(), 'amount' => rand(2, 9999), 'interval' => '1 MONTH', 'currency' => 'EUR'];
});
// Generate notification type
$factory->define(App\NotificationType::class, function ($faker) {
    return ['type' => $faker->numerify('rand_####'), 'name' => $faker->name()];
});
// Generate notification
$factory->define(\App\Notification::class, function ($faker) {
Beispiel #17
0
@extends('layouts.app')

@section('content')

    <div class="bs-example">
        <div class="panel panel-primary">
            <div class="panel-heading" style="background: #009FD7;"><h4 class="panel-title">{{ $team->name }}</h4></div>
            <div class="panel-body small-panel-body">
                <table class="table table-bordered table-striped table-hover">
                    <th>Actions</th>
                    <?php 
use App\Action;
$actions = Action::where('owner', 'like', '%' . $team->name . '%')->get();
?>
                    @foreach($actions as $action)
                        <tr>
                            <td><a href="/actions/show/{{ $action->id }}">{{ $action->body }}</a></td>
                        </tr>
                    @endforeach
                    <?php 
use App\Task;
$tasks = Task::where('owner', 'like', '%' . $team->name . '%')->get();
?>
                    @if(count($tasks) > 0)
                        <th>Tasks</th>
                        @foreach($tasks as $task)
                            <tr>
                                <td><a href="/actions/show/{{ $task->id }}">{{ $task->body }}</a></td>
                            </tr>
                        @endforeach
                    @endif
 /**
  * Renders a map of all users (curently)
  */
 public function map()
 {
     $users = \App\User::where('latitude', '<>', 0)->get();
     $actions = \App\Action::where('start', '>=', Carbon::now())->where('latitude', '<>', 0)->get();
     $groups = \App\Group::where('latitude', '<>', 0)->get();
     // randomize users geolocation by a few meters
     foreach ($users as $user) {
         $user->latitude = $user->latitude + mt_rand(0, 10) / 10000;
         $user->longitude = $user->longitude + mt_rand(0, 10) / 10000;
     }
     return view('dashboard.map')->with('users', $users)->with('actions', $actions)->with('groups', $groups)->with('latitude', 50.8503396)->with('longitude', 4.3517103);
 }
 function deleteAction($idbp, $id)
 {
     Action::findOrFail($id)->delete();
     return;
 }
 /**
  * Show the form for editing the specified Module.
  * @param  int $id
  * @return Response
  */
 public function edit($id)
 {
     if (!AuthcheckController::checkAuth(Sentinel::forceCheck(), ['module.update'], 'Modulos', 'alterar')) {
         return redirect()->back();
     } else {
         $module = $this->moduleRepository->find($id);
         if (empty($module)) {
             Flash::error('Module not found');
             return redirect(route('modules.index'));
         }
         $actions = \App\Action::all();
         $actionb = \DB::table('action_module')->where('module_id', $id)->get(['action_id']);
         return view('modules.edit', compact('actions'), compact('actionb'))->with('module', $module);
     }
 }
Beispiel #21
0
 public function actions($entity, $action, $entity_id, $user_id, $data = null)
 {
     $item = new Action();
     $item->action = $action;
     $item->user_id = $user_id;
     $item->entity = $entity;
     $item->type = 'info';
     $item->data = $data;
     $item->save();
 }
 /**
  * @param \App\Offer $offer
  */
 public function logBuy(\App\Offer $offer)
 {
     $action = \App\Action::where('title', '=', 'buy_offer')->get()->first();
     $this->UserModel->actions()->attach($action->id, ['points' => $action->point, 'offer_id' => $offer->id]);
     $this->levelUpIfPossible();
 }
 public function explicitrf_function(SignalsRequest $request)
 {
     $username = $request->username;
     $device = $request->device_id;
     $video_id = $request->video_id;
     $action_type = $request->action;
     $explicit_rf = $request->value;
     //check if $request->score==-1 or 0 or 1
     $record_exists = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_type)->first();
     if (empty($record_exists)) {
         $user_action = new UserAction(['username' => $username, 'device_id' => $device, 'video_id' => $video_id, 'explicit_rf' => $explicit_rf, 'action' => $action_type]);
         $user_action->save();
         $get_importance = Action::where('id', $request->action)->first();
         $importance = $get_importance->importance;
         $user_action->update(array('weight' => $explicit_rf, 'importance' => $importance));
     } else {
         $record_exists->update(array('explicit_rf' => $explicit_rf, 'weight' => $explicit_rf));
     }
     //store in the dcgs table - only used for the online experiments
     $mecanex_user = MecanexUser::where('username', $username)->first();
     $dcg_record = Dcg::where('mecanex_user_id', $mecanex_user->id)->where('video_id', $video_id);
     $dcg_record->update(array('explicit_rf' => $explicit_rf));
     //////////////calculate ku///////////////////////
     // number of all enrichments
     $video = Video::where('video_id', $video_id)->first();
     $num_all_enrichments = DB::select(DB::raw('SELECT COUNT(*) as num FROM enrichments_videos_time WHERE video_id=?'), [$video->id]);
     $num_all_enrichments = $num_all_enrichments[0]->num;
     // create list with clicked enrichments
     $get_action_id = Action::where('action', 'click enrichment')->first();
     $action_id = $get_action_id->id;
     $enrichment_click_ids = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->get(array('content_id'));
     $num_clicked_enrichments = count($enrichment_click_ids);
     // replace all database entries with one with the appropriate weight (so that the calculation can be easily done).
     // The information for what enrichments where clicked is now in the $enrichment_click_ids variable
     if ($num_clicked_enrichments != 0) {
         DB::table('user_actions')->where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->delete();
         $user_action = new UserAction(['username' => $username, 'device_id' => $device, 'video_id' => $video_id, 'action' => $action_id, 'content_id' => '1']);
         $user_action->save();
         $get_importance = Action::where('id', $action_id)->first();
         $importance = $get_importance->importance;
         $user_action->update(array('weight' => $num_clicked_enrichments / $num_all_enrichments, 'importance' => $importance));
     }
     // create list with shared enrichments
     $get_action_id = Action::where('action', 'share')->first();
     $action_id = $get_action_id->id;
     $enrichment_share_ids = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->get(array('content_id'));
     $num_shared_enrichments = count($enrichment_share_ids);
     // replace all database entries with one with the appropriate weight (so that the calculation can be easily done).
     // The information for what enrichments where clicked is now in the $enrichment_shared_ids variable
     if ($num_shared_enrichments != 0) {
         DB::table('user_actions')->where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->delete();
         $user_action = new UserAction(['username' => $username, 'device_id' => $device, 'video_id' => $video_id, 'action' => $action_id, 'content_id' => '1']);
         $user_action->save();
         $get_importance = Action::where('id', $action_id)->first();
         $importance = $get_importance->importance;
         $user_action->update(array('weight' => $num_shared_enrichments / $num_all_enrichments, 'importance' => $importance));
     }
     $k_nominator = UserAction::where('username', $username)->where('video_id', $video_id)->groupBy('username')->get(['username', DB::raw('SUM(importance*weight) as total_score')])->first();
     $query = "SELECT SUM(t1.importance ) AS total FROM (SELECT DISTINCT action, importance FROM user_actions WHERE username=:username AND video_id=:videoid) AS t1 ";
     $k_denominator = DB::select(DB::raw($query), array('username' => $username, 'videoid' => $video_id));
     //returns array
     $k = $k_nominator->total_score / $k_denominator[0]->total;
     //to [0] gia na prospelasei to 1o stoixeio tou array pou einai to object
     /////////////////////////////update weights and update profile//////////////////////////////////////////////////////////
     ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     /////////////Retrieve Terms/////////////////////////////
     //////////////retrieve terms for given video//////////////
     $video = Video::where('video_id', $request->video_id)->first();
     $threshold = 0;
     //need to appropriate set
     $results = $video->term()->where('video_score', '>', $threshold)->get(array('term_id'));
     $video_term_list = [];
     foreach ($results as $result) {
         //retrieve the terms that will be updated
         array_push($video_term_list, $result->term_id);
     }
     sort($video_term_list);
     ///////////retrieve terms for the clicked enrichments//////////////
     //		$get_actionid = Action::where('action', 'click enrichment')->first();
     //		$action_id = $get_actionid->id;
     //		$enrichment_ids = UserAction::where('username', $username)->where('video_id', $video_id)->where('action', $action_id)->get(array('content_id'));
     $enrichment_term_list = [];
     //		foreach ($enrichment_ids as $enrichment_id)
     //		{
     //
     //			//call the api and get some terms
     //			//or emulate enrichment_terms
     //			//$results=Enrichment::where('id',$enrichment_id)->get(array('term_id'))
     //			foreach($results as $result)
     //			{
     //				array_push($enrichment_term_list,$result->term_id);
     //			}
     //
     //		}
     //$enrichment_terms=array_unique($enrichment_term_list);
     $enrichment_terms = [3, 4, 7];
     //retrieve terms for the clicked ads
     $ads_terms = [4, 8, 10];
     ///Final term_list -  no need since I will update in three steps
     //		$term_list=array_merge($video_term_list,$enrichment_terms,$ads_terms);
     //		$terms=array_unique($term_list);
     ////////////////update weights of profile//////////////////////////
     $term_scores = [];
     //save all scores to get the max
     $user = MecanexUser::where('username', $username)->get()->first();
     $video = Video::where('video_id', $video_id)->get()->first();
     $link_user = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->get()->first();
     //return $video;
     //return $link_user;
     //update based on video_terms
     //return $video_term_list;
     foreach ($video_term_list as $video_term_id) {
         $temp_user = $user->term->find($video_term_id);
         $user_term_score = $temp_user->pivot->user_score;
         //get score of user
         $temp_video = $video->term->find($video_term_id);
         $video_term_score = $temp_video->pivot->video_score;
         //get score of video
         $final_score = $k * (0.8 * $video_term_score);
         foreach ($enrichment_click_ids as $enrichment_click_id) {
             $id = $enrichment_click_id->content_id;
             $enrichment = Enrichment::where('enrichment_id', $id)->get()->first();
             $temp_enrichment = $enrichment->term->find($video_term_id);
             $enrichment_term_score = $temp_enrichment->pivot->enrichment_score;
             $final_score = $final_score + $k * (0.1 / $num_clicked_enrichments * $enrichment_term_score);
         }
         foreach ($enrichment_share_ids as $enrichment_share_id) {
             $id = $enrichment_share_id->content_id;
             $enrichment = Enrichment::where('enrichment_id', $id)->get()->first();
             $temp_enrichment = $enrichment->term->find($video_term_id);
             $enrichment_term_score = $temp_enrichment->pivot->enrichment_score;
             $final_score = $final_score + $k * (0.1 / $num_shared_enrichments * $enrichment_term_score);
         }
         //update score
         $new_score = $user_term_score + $final_score;
         //ok
         $new_score = max($new_score, 0);
         // don't let negative values
         array_push($term_scores, $new_score);
         //				//store score
         $user->term()->sync([$video_term_id => ['user_score' => $new_score]], false);
     }
     //return $term_scores;
     // update matrix
     $number_video_terms = count($video_term_list);
     $link_term_scores = [];
     //save all scores to get the max
     for ($i = 0; $i <= $number_video_terms - 1; $i++) {
         for ($j = $i + 1; $j < $number_video_terms; $j++) {
             $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $video_term_list[$i])->where('term_neighbor_id', $video_term_list[$j])->get()->first();
             //return $temp_user_matrix;
             $temp_video = $video->term->find($video_term_list[$i]);
             $video_term_score1 = $temp_video->pivot->video_score;
             $temp_video = $video->term->find($video_term_list[$j]);
             $video_term_score2 = $temp_video->pivot->video_score;
             $final_score = $k * (0.8 * $video_term_score1 * $video_term_score2);
             foreach ($enrichment_click_ids as $enrichment_click_id) {
                 $id = $enrichment_click_id->content_id;
                 $enrichment = Enrichment::where('enrichment_id', $id)->get()->first();
                 $temp_enrichment = $enrichment->term->find($video_term_list[$i]);
                 $enrichment_term_score1 = $temp_enrichment->pivot->enrichment_score;
                 $temp_enrichment = $enrichment->term->find($video_term_list[$j]);
                 $enrichment_term_score2 = $temp_enrichment->pivot->enrichment_score;
                 $final_score = $final_score + $k * (0.1 / $num_clicked_enrichments * $enrichment_term_score1 * $enrichment_term_score2);
             }
             foreach ($enrichment_share_ids as $enrichment_share_id) {
                 $id = $enrichment_share_id->content_id;
                 $enrichment = Enrichment::where('enrichment_id', $id)->get()->first();
                 $temp_enrichment = $enrichment->term->find($video_term_list[$i]);
                 $enrichment_term_score1 = $temp_enrichment->pivot->enrichment_score;
                 $temp_enrichment = $enrichment->term->find($video_term_list[$j]);
                 $enrichment_term_score2 = $temp_enrichment->pivot->enrichment_score;
                 $final_score = $final_score + $k * (0.1 / $num_shared_enrichments * $enrichment_term_score1 * $enrichment_term_score2);
             }
             $new_score = $temp_user_matrix->link_score + $final_score;
             $new_score = max($new_score, 0);
             // don't let negative values
             array_push($link_term_scores, $new_score);
             $temp_user_matrix->link_score = $new_score;
             $temp_user_matrix->save();
         }
     }
     //same should be done for enrichments and ads
     //find max value and divide term values
     $max_term_value = max(max($term_scores), 1);
     if ($link_term_scores != []) {
         $max_link_term_value = max(max($link_term_scores), 1);
     }
     foreach ($video_term_list as $video_term_id) {
         $temp_user = $user->term->find($video_term_id);
         $user_term_score = $temp_user->pivot->user_score;
         //get score of user
         $temp_video = $video->term->find($video_term_id);
         $video_term_score = $temp_video->pivot->video_score;
         //get score of video
         //update score
         $new_score = $user_term_score / $max_term_value;
         //ok
         //store score
         $user->term()->sync([$video_term_id => ['user_score' => $new_score]], false);
     }
     for ($i = 0; $i <= $number_video_terms - 1; $i++) {
         for ($j = $i + 1; $j < $number_video_terms; $j++) {
             $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $video_term_list[$i])->where('term_neighbor_id', $video_term_list[$j])->get()->first();
             $old_score = $temp_user_matrix->link_score;
             $new_score = $old_score / $max_link_term_value;
             $temp_user_matrix->link_score = $new_score;
             $temp_user_matrix->save();
         }
     }
     //calculate profile
     $terms = Term::all()->count();
     for ($j = 1; $j <= $terms; $j++) {
         $profile_score = 0;
         for ($i = 1; $i <= $terms; $i++) {
             $temp_user = $user->term->find($i);
             $user_term_score = $temp_user->pivot->user_score;
             //get score of user
             if ($i == $j) {
                 $link_score = 0;
             } elseif ($i > $j) {
                 $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $j)->where('term_neighbor_id', $i)->get()->first();
                 $link_score = $temp_user_matrix->link_score;
             } else {
                 $temp_user_matrix = MecanexUserTermHomeTermNeighbour::where('mecanex_user_id', $user->id)->where('term_home_id', $i)->where('term_neighbor_id', $j)->get()->first();
                 $link_score = $temp_user_matrix->link_score;
             }
             $profile_score = $profile_score + $user_term_score * $link_score;
         }
         $user->profilescore()->sync([$j => ['profile_score' => $profile_score]], false);
     }
     DB::table('user_actions')->where('username', $username)->where('video_id', $video_id)->delete();
     $response = ["message" => 'RF Saved'];
     $statusCode = 200;
     return response($response, $statusCode)->header('Content-Type', 'application/json');
 }
Beispiel #24
0
@extends('layouts.app')

@section('content')

    <div class="bs-example">
        <div class="panel panel-primary">
            <div class="panel-heading" style="background: #009FD7;"><h4 class="panel-title">{{ $user->name }}</h4></div>
            <div class="panel-body">
                <?php 
use App\Action;
use App\Task;
use App\Department;
use App\Team;
$user_stuff = array();
$user_stuff = array_merge($user_stuff, Action::where('lead', 'like', '%' . $user->email . '%')->get()->all());
$user_stuff = array_merge($user_stuff, Action::where('collaborators', 'like', '%' . $user->email . '%')->get()->all());
$user_stuff = array_merge($user_stuff, Task::where('lead', 'like', '%' . $user->email . '%')->get()->all());
$user_stuff = array_merge($user_stuff, Task::where('collaborators', 'like', '%' . $user->email . '%')->get()->all());
$user_stuff = array_merge($user_stuff, Department::where('name', 'like', '%' . $user->department . '%')->get()->all());
?>

                <table class="table table-striped table-hover table-bordered table-responsive">
                    <tbody>
                    @foreach($user_stuff as $item)
                        <?php 
$result_class = str_replace("app\\", "", strtolower(get_class($item)));
?>
                        <tr>

                            <td><a href="/{{  $result_class }}s/show/{{ $item->id }}">{{ ucwords($result_class) }}: @if(!in_array($result_class, ["department", "team"])){{ $item->body }}@else{{ $item->name }}@endif</a></td>
                        </tr>
 public function MarkComplete(Action $action)
 {
     $action->status = "Completed";
     $action->save();
     foreach ($action->tasks as $task) {
         if ($task->status != "Completed") {
             $task->status = "Completed";
             $task->save();
         }
     }
     return back();
 }
Beispiel #26
0
 public function run()
 {
     DB::table('actions')->delete();
     Action::create(['id' => '1', 'action' => 'play video', 'importance' => '10']);
     Action::create(['id' => '2', 'action' => 'stop video', 'importance' => '10']);
     Action::create(['id' => '3', 'action' => 'click enrichment', 'importance' => '10']);
     Action::create(['id' => '4', 'action' => 'click ad', 'importance' => '10']);
     Action::create(['id' => '5', 'action' => 'share', 'importance' => '10']);
     Action::create(['id' => '6', 'action' => 'explicit_rf', 'importance' => '20']);
 }
 /**
  * Clears the given rule from all actions, action params and transformer mappings.
  *
  * @param Rule $rule
  */
 private function clearRule(Rule $rule)
 {
     // delete all actions of rule
     // -> cascades down to actions_params
     Action::where("rule_id", $rule->rule_id)->delete();
     // delete all transformer mappings of rule
     TransformerMapping::where("rule_id", $rule->rule_id)->delete();
 }
Beispiel #28
0
@extends('layouts.app')

@section('content')

    <div class="bs-example">
        <div class="panel panel-primary">
            <div class="panel-heading" style="background: #009FD7;"><h4 class="panel-title">{{ $department->name }}</h4></div>
            <div class="panel-body small-panel-body">
                <table class="table table-bordered table-striped table-hover">
                    <th>Actions</th>
                    <?php 
use App\Action;
$actions = Action::where('owner', 'like', '%' . $department->name . '%')->get();
?>
                    @foreach($actions as $action)
                        <tr>
                            <td><a href="/actions/show/{{ $action->id }}">{{ $action->body }}</a></td>
                        </tr>
                    @endforeach
                    <th>Tasks</th>
                    <?php 
use App\Task;
$tasks = Task::where('owner', 'like', '%' . $department->name . '%')->get();
?>
                    @foreach($tasks as $task)
                        <tr>
                            <td><a href="/actions/show/{{ $task->id }}">{{ $task->body }}</a></td>
                        </tr>
                    @endforeach
                    <th>Users</th>
                    <?php 
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($project_id, $id)
 {
     $action = Action::find($id);
     $action->delete();
     flash()->success('Action has been successfully deleted!');
     return redirect()->action('ProjectsController@show', $project_id);
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function show($id)
 {
     $campaign = Campaign::find($id);
     $actions = Action::where('campaign_id', '=', $campaign->id)->groupBy('action')->select(\DB::raw('count(contact_id) as count, action'))->orderBy('count', 'DESC')->get();
     return view()->make('campaigns.show')->with(['campaign' => $campaign, 'actions' => $actions]);
 }