Skip to content

Commit

Permalink
Merge pull request #14 from freescout-helpdesk/analysis-zDvyMJ
Browse files Browse the repository at this point in the history
Apply fixes from StyleCI
  • Loading branch information
freescout-helpdesk authored Jul 24, 2018
2 parents 371a9d5 + f5b82ad commit 0b0e743
Show file tree
Hide file tree
Showing 80 changed files with 1,098 additions and 1,071 deletions.
2 changes: 1 addition & 1 deletion app/ActivityLog.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class ActivityLog extends Activity
const DESCRIPTION_USER_LOGIN_FAILED = 'login_failed';
const DESCRIPTION_USER_PASSWORD_RESET = 'password_reset';

function getEventDescription()
public function getEventDescription()
{
switch ($this->description) {
case self::DESCRIPTION_USER_LOGIN:
Expand Down
31 changes: 16 additions & 15 deletions app/Console/Commands/CreateUser.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Console\Commands;

use Illuminate\Console\Command;
use App\User;
use Illuminate\Console\Command;

class CreateUser extends Command
{
Expand Down Expand Up @@ -39,46 +39,47 @@ public function __construct()
public function handle()
{
$class = config(
'auth.providers.' . config(
'auth.guards.' . config(
'auth.providers.'.config(
'auth.guards.'.config(
'auth.defaults.guard'
) . '.provider'
) . '.model'
).'.provider'
).'.model'
);
$user = new $class;
$user = new $class();
$fillables = ['role', 'first_name', 'last_name', 'email', 'password'];
foreach($fillables as $key => $fillable) {
foreach ($fillables as $key => $fillable) {
if ($fillable == 'password') {
$user->password = \Hash::make($this->secret(($key+1) . "/" . count($fillables) . " User $fillable"));
$user->password = \Hash::make($this->secret(($key + 1).'/'.count($fillables)." User $fillable"));
} elseif ($fillable == 'role') {
$user->$fillable = $this->ask(($key+1) . "/" . count($fillables) . " User $fillable (admin/user)", 'admin');
$user->$fillable = $this->ask(($key + 1).'/'.count($fillables)." User $fillable (admin/user)", 'admin');
if (!$user->$fillable) {
$user->$fillable = 'admin';
}

while (!in_array($user->$fillable, User::$roles)) {
$this->error("Incorrect role");
$user->$fillable = $this->ask("Please enter valid role");
$this->error('Incorrect role');
$user->$fillable = $this->ask('Please enter valid role');
}
$user->$fillable = array_flip(User::$roles)[$user->$fillable];
} else {
$user->$fillable = $this->ask(($key+1) . "/" . count($fillables) . " User $fillable");
$user->$fillable = $this->ask(($key + 1).'/'.count($fillables)." User $fillable");

if ($fillable == 'email') {
while (!filter_var($user->$fillable, FILTER_VALIDATE_EMAIL)) {
$this->error("Incorrect email address");
$user->$fillable = $this->ask("Please enter valid email address");
$this->error('Incorrect email address');
$user->$fillable = $this->ask('Please enter valid email address');
}
}
}
}
if ($this->confirm("Do you want to create the user?", true)) {
if ($this->confirm('Do you want to create the user?', true)) {
if ($user->isAdmin()) {
$user->invite_state = User::INVITE_STATE_ACTIVATED;
}
$user->save();
$this->info("User created (id: {$user->id})");
}

return true;
}
}
3 changes: 2 additions & 1 deletion app/Console/Kernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class Kernel extends ConsoleKernel
/**
* Define the application's command schedule.
*
* @param \Illuminate\Console\Scheduling\Schedule $schedule
* @param \Illuminate\Console\Scheduling\Schedule $schedule
*
* @return void
*/
protected function schedule(Schedule $schedule)
Expand Down
144 changes: 73 additions & 71 deletions app/Conversation.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,37 @@

class Conversation extends Model
{
/**
* By whom action performed (used in fields: source_via, last_reply_from)
*/
/**
* By whom action performed (used in fields: source_via, last_reply_from).
*/
const PERSON_CUSTOMER = 1;
const PERSON_USER = 2;
public static $persons = array(

public static $persons = [
self::PERSON_CUSTOMER => 'customer',
self::PERSON_USER => 'user',
);
self::PERSON_USER => 'user',
];

/**
* Max length of the preview
* Max length of the preview.
*/
const PREVIEW_MAXLENGTH = 255;

/**
* Conversation types
*/
/**
* Conversation types.
*/
const TYPE_EMAIL = 1;
const TYPE_PHONE = 2;
const TYPE_CHAT = 3; // not used

public static $types = array(
self::TYPE_EMAIL => 'email',
self::TYPE_PHONE => 'phone',
self::TYPE_CHAT => 'chat',
);
public static $types = [
self::TYPE_EMAIL => 'email',
self::TYPE_PHONE => 'phone',
self::TYPE_CHAT => 'chat',
];

/**
* Conversation statuses
* Conversation statuses.
*/
const STATUS_ACTIVE = 1;
const STATUS_PENDING = 2;
Expand All @@ -45,130 +45,129 @@ class Conversation extends Model
// Present in the API, but what does it mean?
const STATUS_OPEN = 5;

public static $statuses = array(
self::STATUS_ACTIVE => 'active',
public static $statuses = [
self::STATUS_ACTIVE => 'active',
self::STATUS_PENDING => 'pending',
self::STATUS_CLOSED => 'closed',
self::STATUS_SPAM => 'spam',
self::STATUS_CLOSED => 'closed',
self::STATUS_SPAM => 'spam',
//self::STATUS_OPEN => 'open',
);
];

/**
* https://glyphicons.bootstrapcheatsheets.com/
* https://glyphicons.bootstrapcheatsheets.com/.
*/
public static $status_icons = array(
self::STATUS_ACTIVE => 'ok',
public static $status_icons = [
self::STATUS_ACTIVE => 'ok',
self::STATUS_PENDING => 'hourglass',
self::STATUS_CLOSED => 'lock',
self::STATUS_SPAM => 'ban-circle',
self::STATUS_CLOSED => 'lock',
self::STATUS_SPAM => 'ban-circle',
//self::STATUS_OPEN => 'folder-open',
);
];

public static $status_colors = array(
self::STATUS_ACTIVE => 'success',
public static $status_colors = [
self::STATUS_ACTIVE => 'success',
self::STATUS_PENDING => 'warning',
self::STATUS_CLOSED => 'grey',
self::STATUS_SPAM => 'danger',
self::STATUS_CLOSED => 'grey',
self::STATUS_SPAM => 'danger',
//self::STATUS_OPEN => 'folder-open',
);
];

/**
* Conversation states
* Conversation states.
*/
const STATE_DRAFT = 1;
const STATE_PUBLISHED = 2;
const STATE_DELETED = 3;

public static $states = array(
self::STATE_DRAFT => 'draft',
self::STATE_PUBLISHED => 'published',
self::STATE_DELETED => 'deleted',
);

/**
* Source types (equal to thread source types)
public static $states = [
self::STATE_DRAFT => 'draft',
self::STATE_PUBLISHED => 'published',
self::STATE_DELETED => 'deleted',
];

/**
* Source types (equal to thread source types).
*/
const SOURCE_TYPE_EMAIL = 1;
const SOURCE_TYPE_WEB = 2;
const SOURCE_TYPE_API = 3;
public static $source_types = array(
self::SOURCE_TYPE_EMAIL => 'email',
self::SOURCE_TYPE_WEB => 'web',
self::SOURCE_TYPE_API => 'api',
);

public static $source_types = [
self::SOURCE_TYPE_EMAIL => 'email',
self::SOURCE_TYPE_WEB => 'web',
self::SOURCE_TYPE_API => 'api',
];

/**
* Automatically converted into Carbon dates.
*/
protected $dates = ['created_at', 'updated_at', 'last_reply_at'];

/**
* Attributes which are not fillable using fill() method
* Attributes which are not fillable using fill() method.
*/
protected $guarded = ['id', 'folder_id'];

protected static function boot()
{
parent::boot();

self::creating(function (Conversation $model)
{
$model->number = Conversation::where('mailbox_id', $model->mailbox_id)->max('number')+1;
self::creating(function (Conversation $model) {
$model->number = Conversation::where('mailbox_id', $model->mailbox_id)->max('number') + 1;
});
}

/**
* Who the conversation is assigned to (assignee)
* Who the conversation is assigned to (assignee).
*/
public function user()
{
return $this->belongsTo('App\User');
}

/**
* Get the folder to which conversation belongs
* Get the folder to which conversation belongs.
*/
public function folder()
{
return $this->belongsTo('App\Folder');
}

/**
* Get the mailbox to which conversation belongs
* Get the mailbox to which conversation belongs.
*/
public function mailbox()
{
return $this->belongsTo('App\Mailbox');
}

/**
* Get the customer associated with this conversation (primaryCustomer)
* Get the customer associated with this conversation (primaryCustomer).
*/
public function customer()
{
return $this->belongsTo('App\Customer');
}

/**
* Get conversation threads
* Get conversation threads.
*/
public function threads()
{
return $this->hasMany('App\Thread');
}

/**
* Folders containing starred conversations
* Folders containing starred conversations.
*/
public function extraFolders()
{
return $this->belongsTo('App\Customer');
}

/**
* Set preview text
*
* Set preview text.
*
* @param string $text
*/
public function setPreview($text = '')
Expand All @@ -183,22 +182,24 @@ public function setPreview($text = '')
$this->preview = mb_substr($first_thread->body, 0, self::PREVIEW_MAXLENGTH);
}
}

return $this->preview;
}

/**
* Get conversation timestamp title.
*
*
* @return string
*/
public function getDateTitle()
{
if ($this->threads_count == 1) {
$title = __("Created by :person<br/>:date", ['person' => ucfirst(__(
$title = __('Created by :person<br/>:date', ['person' => ucfirst(__(
self::$persons[$this->source_via])), 'date' => User::dateFormat($this->created_at, 'M j, Y H:i')]);
} else {
$title = __("Last reply by :person<br/>:date", ['person' => ucfirst(__(self::$persons[$this->source_via])), 'date' => User::dateFormat($this->created_at, 'M j, Y H:i')]);
$title = __('Last reply by :person<br/>:date', ['person' => ucfirst(__(self::$persons[$this->source_via])), 'date' => User::dateFormat($this->created_at, 'M j, Y H:i')]);
}

return $title;
}

Expand All @@ -209,31 +210,32 @@ public function isActive()

/**
* Get status name.
*
* @param integer $status
* @return string
*
* @param int $status
*
* @return string
*/
public static function getStatusName($status)
{
switch ($status) {
case self::STATUS_ACTIVE:
return __("Active");
return __('Active');
break;

case self::STATUS_PENDING:
return __("Pending");
return __('Pending');
break;

case self::STATUS_CLOSED:
return __("Closed");
return __('Closed');
break;

case self::STATUS_SPAM:
return __("Spam");
return __('Spam');
break;

case self::STATUS_OPEN:
return __("Open");
return __('Open');
break;

default:
Expand Down
Loading

0 comments on commit 0b0e743

Please sign in to comment.