Apply fixes from StyleCI

This commit is contained in:
Manish Verma
2016-12-13 13:14:54 +00:00
committed by StyleCI Bot
parent 857d3004eb
commit 88f3df2180
161 changed files with 4729 additions and 3879 deletions

View File

@@ -10,14 +10,16 @@ use App\Model\helpdesk\Settings\Company;
use App\Model\helpdesk\Settings\Email;
use App\User;
use Auth;
use Mail;
use Exception;
use Lang;
use Mail;
class PhpMailController extends Controller {
public function fetch_smtp_details($id) {
class PhpMailController extends Controller
{
public function fetch_smtp_details($id)
{
$emails = Emails::where('id', '=', $id)->first();
return $emails;
}
@@ -26,7 +28,8 @@ class PhpMailController extends Controller {
*
* @return type
*/
public function company() {
public function company()
{
$company = Company::Where('id', '=', '1')->first();
if ($company->company_name == null) {
$company = 'Support Center';
@@ -45,8 +48,9 @@ class PhpMailController extends Controller {
*
* @return type integer
*/
public function mailfrom($reg, $dept_id) {
$email_id = "";
public function mailfrom($reg, $dept_id)
{
$email_id = '';
$emails = Emails::where('department', '=', $dept_id)->first();
$email = Email::find(1);
@@ -55,17 +59,19 @@ class PhpMailController extends Controller {
} else {
$email_id = $email->sys_email;
}
return $email_id;
}
public function sendmail($from, $to, $message, $template_variables) {
public function sendmail($from, $to, $message, $template_variables)
{
$this->setQueue();
$job = new \App\Jobs\SendEmail($from, $to, $message, $template_variables);
$this->dispatch($job);
}
public function sendEmail($from, $to, $message, $template_variables) {
public function sendEmail($from, $to, $message, $template_variables)
{
$from_address = $this->fetch_smtp_details($from);
if ($from_address == null) {
throw new Exception(Lang::get('lang.system-email-not-configured'));
@@ -96,11 +102,11 @@ class PhpMailController extends Controller {
$ticket_link_with_number = $this->checkElement('ticket_link_with_number', $template_variables);
$system_from = $this->checkElement('system_from', $template_variables);
if ($system_from === "") {
if ($system_from === '') {
$system_from = $this->company();
}
$system_link = $this->checkElement('system_link', $template_variables);
if ($system_link === "") {
if ($system_link === '') {
$system_link = \Config::get('app.url');
}
$ticket_link = $this->checkElement('ticket_link', $template_variables);
@@ -113,7 +119,6 @@ class PhpMailController extends Controller {
$email_address = $this->checkElement('email_address', $template_variables);
$user = $this->checkElement('user', $template_variables);
$status = \DB::table('settings_email')->first();
$template = TemplateType::where('name', '=', $template_type)->first();
@@ -127,7 +132,7 @@ class PhpMailController extends Controller {
if ($template_data->subject) {
$subject = $template_data->subject;
if ($ticket_number != null) {
$subject = $subject . ' [#' . $ticket_number . ']';
$subject = $subject.' [#'.$ticket_number.']';
}
} else {
$subject = $message['subject'];
@@ -140,7 +145,6 @@ class PhpMailController extends Controller {
$subject = null;
}
$variables = ['{!!$user!!}', '{!!$agent!!}', '{!!$ticket_number!!}', '{!!$content!!}', '{!!$from!!}', '{!!$ticket_agent_name!!}', '{!!$ticket_client_name!!}', '{!!$ticket_client_email!!}', '{!!$ticket_body!!}', '{!!$ticket_assigner!!}', '{!!$ticket_link_with_number!!}', '{!!$system_error!!}', '{!!$agent_sign!!}', '{!!$department_sign!!}', '{!!$password_reset_link!!}', '{!!$email_address!!}', '{!!$user_password!!}', '{!!$system_from!!}', '{!!$system_link!!}', '{!!$ticket_link!!}'];
$data = [$user, $agent, $ticket_number, $content, $from, $ticket_agent_name, $ticket_client_name, $ticket_client_email, $ticket_body, $ticket_assigner, $ticket_link_with_number, $system_error, $agent_sign, $department_sign, $password_reset_link, $email_address, $user_password, $system_from, $system_link, $ticket_link];
@@ -150,20 +154,20 @@ class PhpMailController extends Controller {
$contents = $messagebody;
}
if ($template_type == 'ticket-reply-agent') {
$line = '---Reply above this line--- <br/><br/>';
$content = $line . $messagebody;
$content = $line.$messagebody;
} else {
$content = $messagebody;
}
}
$send = $this->laravelMail($recipants, $recipantname, $subject, $content, $cc, $attachment);
return $send;
}
public function setMailConfig($from_address) {
public function setMailConfig($from_address)
{
$username = $from_address->email_address;
$fromname = $from_address->email_name;
$password = $from_address->password;
@@ -180,88 +184,94 @@ class PhpMailController extends Controller {
$port = '';
}
$configs = [
'username' => $username,
'from' => ['address' => $username, 'name' => $fromname,],
'password' => $password,
'username' => $username,
'from' => ['address' => $username, 'name' => $fromname],
'password' => $password,
'encryption' => $smtpsecure,
'host' => $host,
'port' => $port,
'driver' => $protocol,
'host' => $host,
'port' => $port,
'driver' => $protocol,
];
foreach ($configs as $key => $config) {
if (is_array($config)) {
foreach ($config as $from) {
\Config::set('mail.' . $key, $config);
\Config::set('mail.'.$key, $config);
}
} else {
\Config::set('mail.' . $key, $config);
\Config::set('mail.'.$key, $config);
}
}
}
public function setServices($emailid, $protocol) {
public function setServices($emailid, $protocol)
{
$service = new \App\Model\MailJob\FaveoMail();
$services = $service->where('email_id', $emailid)->lists('value', 'key')->toArray();
$controller = new \App\Http\Controllers\Admin\helpdesk\EmailsController();
$controller->setServiceConfig($protocol, $services);
}
public function checkElement($element, $array) {
$value = "";
public function checkElement($element, $array)
{
$value = '';
if (is_array($array)) {
if (key_exists($element, $array)) {
if (array_key_exists($element, $array)) {
$value = $array[$element];
}
}
return $value;
}
public function laravelMail($to, $toname, $subject, $data, $cc, $attach) {
public function laravelMail($to, $toname, $subject, $data, $cc, $attach)
{
//dd($to, $toname, $subject, $data, $cc, $attach);
//dd(\Config::get('mail'));
//dd($attach);
$mail = Mail::send('emails.mail', ['data' => $data], function ($m) use ($to, $subject, $toname, $cc, $attach) {
$m->to($to, $toname)->subject($subject);
$m->to($to, $toname)->subject($subject);
if ($cc != null) {
foreach ($cc as $collaborator) {
//mail to collaborators
if ($cc != null) {
foreach ($cc as $collaborator) {
//mail to collaborators
$collab_user_id = $collaborator->user_id;
$user_id_collab = User::where('id', '=', $collab_user_id)->first();
$collab_email = $user_id_collab->email;
$m->cc($collab_email);
}
}
$user_id_collab = User::where('id', '=', $collab_user_id)->first();
$collab_email = $user_id_collab->email;
$m->cc($collab_email);
}
}
// $mail->addBCC($bc);
$size = count($attach);
if ($size > 0) {
for ($i = 0; $i < $size; $i++) {
if (is_array($attach) && array_key_exists($i, $attach)) {
$mode = 'normal';
if (is_array($attach[$i]) && array_key_exists('mode', $attach[$i])) {
$mode = $attach[$i]['mode'];
}
$file = $attach[$i]['file_path'];
$name = $attach[$i]['file_name'];
$mime = $attach[$i]['mime'];
$this->attachmentMode($m, $file, $name, $mime, $mode);
}
if ($size > 0) {
for ($i = 0; $i < $size; $i++) {
if (is_array($attach) && array_key_exists($i, $attach)) {
$mode = 'normal';
if (is_array($attach[$i]) && array_key_exists('mode', $attach[$i])) {
$mode = $attach[$i]['mode'];
}
$file = $attach[$i]['file_path'];
$name = $attach[$i]['file_name'];
$mime = $attach[$i]['mime'];
$this->attachmentMode($m, $file, $name, $mime, $mode);
}
});
}
}
});
if (is_object($mail) || (is_object($mail) && $mail->getStatusCode() == 200)) {
$mail = 1;
}
return $mail;
}
public function setQueue() {
public function setQueue()
{
$short = 'database';
$field = [
'driver' => 'database',
'table' => 'jobs',
'queue' => 'default',
'table' => 'jobs',
'queue' => 'default',
'expire' => 60,
];
$queue = new \App\Model\MailJob\QueueService();
@@ -274,18 +284,20 @@ class PhpMailController extends Controller {
$this->setQueueConfig($short, $field);
}
public function setQueueConfig($short, $field) {
public function setQueueConfig($short, $field)
{
\Config::set('queue.default', $short);
foreach ($field as $key => $value) {
\Config::set("queue.connections.$short.$key", $value);
}
}
public function attachmentMode($message, $file, $name, $mime, $mode) {
public function attachmentMode($message, $file, $name, $mime, $mode)
{
if ($mode == 'data') {
return $message->attachData(base64_decode($file, true), $name, ['mime' => $mime]);
}
return $message->attach($file, ['as' => $name, 'mime' => $mime]);
}
}