-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathPackage.php
170 lines (162 loc) · 6.6 KB
/
Package.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
<?php
/**
* Class Package
*
* @category Worketic
*
* @package Worketic
* @author Amentotech <[email protected]>
* @license http://www.amentotech.com Amentotech
* @link http://www.amentotech.com
*/
namespace App;
use Illuminate\Database\Eloquent\Model;
use Auth;
/**
* Class Package
*
*/
class Package extends Model
{
/**
* Set slug before saving in DB
*
* @param string $value value
*
* @access public
*
* @return string
*/
public function setSlugAttribute($value)
{
if (!empty($value)) {
$temp = str_slug($value, '-');
if (!Package::all()->where('slug', $temp)->isEmpty()) {
$i = 1;
$new_slug = $temp . '-' . $i;
while (!Package::all()->where('slug', $new_slug)->isEmpty()) {
$i++;
$new_slug = $temp . '-' . $i;
}
$temp = $new_slug;
}
$this->attributes['slug'] = $temp;
}
}
/**
* Save package
*
* @param mixed $request get req attributes
*
* @return \Illuminate\Http\Response
*/
public function savePackage($request)
{
if (!empty($request)) {
$this->title = filter_var($request['package_title'], FILTER_SANITIZE_STRING);
$this->slug = filter_var($request['package_title'], FILTER_SANITIZE_STRING);
$this->subtitle = filter_var($request['package_subtitle'], FILTER_SANITIZE_STRING);
$this->cost = filter_var($request['package_price'], FILTER_SANITIZE_STRING);
$this->role_id = intval($request['roles'][0]);
if ($request->roles == '2') {
$this->options = serialize($request['employer']);
} else {
$this->options = serialize($request['freelancer']);
}
if (!empty($request->trial)) {
$this->trial = 1;
} else {
$this->trial = 0;
}
$this->badge_id = !empty($request['freelancer']['badge']) ? intval($request['freelancer']['badge']) : 0;
$old_path = Helper::PublicPath() . '/uploads/packages/temp';
if (!empty($request['uploaded_image'])) {
$filename = $request['uploaded_image'];
if (file_exists($old_path . '/' . $request['uploaded_image'])) {
$new_path = Helper::PublicPath().'/uploads/packages/';
if (!file_exists($new_path)) {
File::makeDirectory($new_path, 0755, true, true);
}
$filename = time() . '-' . $request['uploaded_image'];
rename($old_path . '/' . $request['uploaded_image'], $new_path . '/' . $filename);
rename($old_path . '/small-' . $request['uploaded_image'], $new_path . '/small-' . $filename);
rename($old_path . '/medium-' . $request['uploaded_image'], $new_path . '/medium-' . $filename);
}
$this->image = filter_var($filename, FILTER_SANITIZE_STRING);
} else {
$this->image = null;
}
return $this->save();
}
}
/**
* Update Packages
*
* @param mixed $request get req attributes
* @param int $slug get skill id
*
* @return \Illuminate\Http\Response
*/
public function updatePackage($request, $slug)
{
if (!empty($request)) {
$selected_package = self::select('id')->where('slug', $slug)->first();
$package = Self::find($selected_package->id);
if ($package->title != $request['package_title']) {
$package->slug = filter_var($request['package_title'], FILTER_SANITIZE_STRING);
}
$package->title = filter_var($request['package_title'], FILTER_SANITIZE_STRING);
$package->subtitle = filter_var($request['package_subtitle'], FILTER_SANITIZE_STRING);
$package->cost = filter_var($request['package_price'], FILTER_SANITIZE_STRING);
$package->role_id = intval($request['roles'][0]);
if ($request->roles == '2') {
$package->options = serialize($request['employer']);
} else {
$package->options = serialize($request['freelancer']);
}
$package->badge_id = !empty($request['freelancer']['badge']) ? intval($request['freelancer']['badge']) : 0;
$old_path = Helper::PublicPath() . '/uploads/packages/temp';
if (!empty($request['uploaded_image'])) {
$filename = $request['uploaded_image'];
if (file_exists($old_path . '/' . $request['uploaded_image'])) {
$new_path = Helper::PublicPath().'/uploads/packages/';
if (!file_exists($new_path)) {
File::makeDirectory($new_path, 0755, true, true);
}
$filename = time() . '-' . $request['uploaded_image'];
rename($old_path . '/' . $request['uploaded_image'], $new_path . '/' . $filename);
rename($old_path . '/small-' . $request['uploaded_image'], $new_path . '/small-' . $filename);
rename($old_path . '/medium-' . $request['uploaded_image'], $new_path . '/medium-' . $filename);
}
$package->image = filter_var($filename, FILTER_SANITIZE_STRING);
} else {
$package->image = null;
}
$package->save();
}
}
/**
* Save package
*
* @param string $role $role
*
* @return \Illuminate\Http\Response
*/
public function saveTrailPackage($role)
{
if (!empty($role)) {
if ($role == 'employer') {
$options = 'a:5:{s:4:"jobs";s:1:"5";s:13:"featured_jobs";s:1:"2";s:8:"duration";s:2:"30";s:13:"banner_option";s:4:"true";s:12:"private_chat";s:4:"true";}';
} else {
$options = 'a:6:{s:14:"no_of_connects";s:2:"10";s:12:"no_of_skills";s:1:"3";s:8:"duration";s:2:"30";s:5:"badge";N;s:13:"banner_option";s:4:"true";s:12:"private_chat";s:4:"true";}';
}
DB::table('items')->insert(
[
'title' => 'Trail'.$role, 'subtitle' => '30 Days Trial', 'slug' => 'trial-'.$role,
'cost' => 0.00, 'role_id' => $role_id, 'badge_id' => 0, 'options' => $options,
"created_at" => \Carbon\Carbon::now(), 'updated_at' => \Carbon\Carbon::now()
]
);
}
}
}