diff --git a/app/Acl/Acl.php b/app/Acl/Acl.php index aeed4a028..da9edb1bf 100644 --- a/app/Acl/Acl.php +++ b/app/Acl/Acl.php @@ -7,7 +7,8 @@ use App\Acl\Eloquent\Group; use App\Acl\Permissions; -class Acl { +class Acl +{ /** * get role list in the project. @@ -32,13 +33,11 @@ public static function getRolesByUid($project_key, $user_id) $role_ids = []; $groups = self::getBoundGroups($user_id); - foreach ($groups as $group) - { + foreach ($groups as $group) { $role_actors = Roleactor::whereRaw([ 'group_ids' => $group['id'], 'project_key' => $project_key ]) ->get([ 'role_id' ]) ->toArray(); - foreach($role_actors as $actor) - { + foreach ($role_actors as $actor) { $role_ids[] = $actor['role_id']; } } @@ -46,8 +45,7 @@ public static function getRolesByUid($project_key, $user_id) $role_actors = Roleactor::whereRaw([ 'user_ids' => $user_id, 'project_key' => $project_key ]) ->get(['role_id']) ->toArray(); - foreach($role_actors as $actor) - { + foreach ($role_actors as $actor) { $role_ids[] = $actor['role_id']; } @@ -65,44 +63,36 @@ public static function getUserIdsByPermission($permission, $project_key) { $role_ids = []; $rps = RolePermissions::whereRaw([ 'permissions' => $permission, 'project_key' => $project_key ])->get(); - foreach ($rps as $rp) - { + foreach ($rps as $rp) { $role_ids[] = $rp->role_id; } $local_role_ids = []; $local_rps = RolePermissions::whereRaw([ 'project_key' => $project_key ])->get(); - foreach ($local_rps as $rp) - { + foreach ($local_rps as $rp) { $local_role_ids[] = $rp->role_id; } $rps = RolePermissions::whereRaw([ 'permissions' => $permission, 'project_key' => '$_sys_$', 'role_id' => [ '$nin' => $local_role_ids ] ])->get(); - foreach ($rps as $rp) - { + foreach ($rps as $rp) { $role_ids[] = $rp->role_id; } $user_ids = []; $group_ids = []; $role_actors = Roleactor::whereRaw([ 'project_key' => $project_key, 'role_id' => [ '$in' => $role_ids ] ])->get(); - foreach ($role_actors as $actor) - { - if (isset($actor->user_ids) && $actor->user_ids) - { + foreach ($role_actors as $actor) { + if (isset($actor->user_ids) && $actor->user_ids) { $user_ids = array_merge($user_ids, $actor->user_ids); } - if (isset($actor->group_ids) && $actor->group_ids) - { + if (isset($actor->group_ids) && $actor->group_ids) { $group_ids = array_merge($group_ids, $actor->group_ids); } } - foreach ($group_ids as $group_id) - { + foreach ($group_ids as $group_id) { $group = Group::find($group_id); - if ($group && isset($group->users) && $group->users) - { + if ($group && isset($group->users) && $group->users) { $user_ids = array_merge($user_ids, $group->users); } } @@ -121,26 +111,23 @@ public static function getUserIdsByPermission($permission, $project_key) public static function isAllowed($user_id, $permission, $project_key) { $permissions = self::getPermissions($user_id, $project_key); - if ($permission == 'view_project') - { + if ($permission == 'view_project') { return !!$permissions; - } - else - { + } else { return in_array($permission, $permissions); } } /** - * get groups user is bound + * get groups user is bound * * @var string $user_id - * @return array + * @return array */ public static function getBoundGroups($user_id) { $groups = []; - $group_list = Group::where([ 'users' => $user_id ])->get(); + $group_list = Group::where([ 'users' => $user_id ])->get(); foreach ($group_list as $group) { $groups[] = [ 'id' => $group->id, 'name' => $group->name ]; } @@ -160,40 +147,34 @@ public static function getPermissions($user_id, $project_key) $role_actors = Roleactor::whereRaw([ 'user_ids' => $user_id, 'project_key' => $project_key ]) ->get([ 'role_id' ]) ->toArray(); - foreach($role_actors as $actor) - { + foreach ($role_actors as $actor) { $role_ids[] = $actor['role_id']; } $groups = self::getBoundGroups($user_id); - foreach ($groups as $group) - { + foreach ($groups as $group) { $role_actors = Roleactor::whereRaw([ 'group_ids' => $group['id'], 'project_key' => $project_key ]) ->get([ 'role_id' ]) ->toArray(); - foreach($role_actors as $actor) - { + foreach ($role_actors as $actor) { $role_ids[] = $actor['role_id']; } } $all_permissions = []; - foreach ($role_ids as $role_id) - { + foreach ($role_ids as $role_id) { $rp = RolePermissions::where('project_key', $project_key) ->where('role_id', $role_id) ->first(); - if (!$rp) - { + if (!$rp) { $rp = RolePermissions::where('project_key', '$_sys_$') ->where('role_id', $role_id) ->first(); } - if ($rp) - { + if ($rp) { $all_permissions = array_merge($all_permissions, $rp->permissions ?: []); } } diff --git a/app/Acl/Permissions.php b/app/Acl/Permissions.php index 8bb916277..d2fb735c5 100644 --- a/app/Acl/Permissions.php +++ b/app/Acl/Permissions.php @@ -2,8 +2,8 @@ namespace App\Acl; -class Permissions { - +class Permissions +{ const VIEW_PROJECT = 'view_project'; const MANAGE_PROJECT = 'manage_project'; @@ -85,5 +85,4 @@ public static function all() static::DELETE_SELF_WORKLOG, ]; } - } diff --git a/app/ActiveDirectory/LDAP.php b/app/ActiveDirectory/LDAP.php index 47903c46c..b2ac4bd78 100644 --- a/app/ActiveDirectory/LDAP.php +++ b/app/ActiveDirectory/LDAP.php @@ -10,41 +10,38 @@ use DB; use Exception; -class LDAP { +class LDAP +{ /** * connect ldap server. * * @var array $config - * @return array + * @return array */ public static function test($configs) { $ad = new Adldap(self::filterConnectConfigs($configs)); $ret = []; - foreach ($configs as $key => $config) - { + foreach ($configs as $key => $config) { $tmp = []; try { $provider = $ad->connect($key); } catch (Exception $e) { - $ret[$key] = [ - 'server_connect' => false, - 'user_count' => 0, - 'group_count' => 0, + $ret[$key] = [ + 'server_connect' => false, + 'user_count' => 0, + 'group_count' => 0, 'group_membership' => false ]; continue; } $tmp['server_connect'] = true; - if (!isset($config['user_object_class'])) - { + if (!isset($config['user_object_class'])) { $tmp['user_count'] = 0; - } - else - { + } else { $users = $provider ->search() ->setDn(self::getUserDn($config)) @@ -54,12 +51,9 @@ public static function test($configs) $tmp['user_count'] = count($users); } - if (!isset($config['group_object_class'])) - { + if (!isset($config['group_object_class'])) { $tmp['group_count'] = 0; - } - else - { + } else { $groups = $provider ->search() ->setDn(self::getGroupDn($config)) @@ -69,12 +63,9 @@ public static function test($configs) $tmp['group_count'] = count($groups); } - if (!isset($config['group_object_class']) || !isset($config['group_membership_attr'])) - { + if (!isset($config['group_object_class']) || !isset($config['group_membership_attr'])) { $tmp['group_memebership'] = false; - } - else - { + } else { $group = $provider ->search() ->setDn(self::getGroupDn($config)) @@ -93,15 +84,14 @@ public static function test($configs) * connect ldap server. * * @var array $config - * @return array + * @return array */ public static function sync($configs) { $ret = []; $ad = new Adldap(self::filterConnectConfigs($configs)); - foreach ($configs as $key => $config) - { + foreach ($configs as $key => $config) { $tmp = []; try { $provider = $ad->connect($key); @@ -130,33 +120,24 @@ public static function sync($configs) public static function filterConnectConfigs($configs) { $connect_configs = []; - foreach ($configs as $key => $config) - { + foreach ($configs as $key => $config) { $connect = []; $connect['domain_controllers'] = [ $config['host'] ]; $connect['port'] = $config['port']; $connect['admin_username'] = $config['admin_username']; $connect['admin_password'] = $config['admin_password']; - if (isset($config['encryption']) && $config['encryption']) - { - if ($config['encryption'] == 'ssl') - { + if (isset($config['encryption']) && $config['encryption']) { + if ($config['encryption'] == 'ssl') { $connect['use_ssl'] = true; - } - else if ($config['encryption'] == 'tls') - { + } elseif ($config['encryption'] == 'tls') { $connect['use_tls'] = true; - } - else - { + } else { $connect['use_ssl'] = false; - $connect['use_tls'] = false; + $connect['use_tls'] = false; } - } - else - { + } else { $connect['use_ssl'] = false; - $connect['use_tls'] = false; + $connect['use_tls'] = false; } $connect_configs[$key] = $connect; } @@ -167,24 +148,18 @@ public static function filterConnectConfigs($configs) /** * get user dn. * - * @return string + * @return string */ public static function getUserDN($config) { $user_dn = ''; - if (isset($config['additional_user_dn']) && $config['additional_user_dn']) - { - if (strpos($config['additional_user_dn'], $config['base_dn']) !== false) - { + if (isset($config['additional_user_dn']) && $config['additional_user_dn']) { + if (strpos($config['additional_user_dn'], $config['base_dn']) !== false) { $user_dn = $config['additional_user_dn']; - } - else - { + } else { $user_dn = $config['additional_user_dn'] . ',' . $config['base_dn']; } - } - else - { + } else { $user_dn = $config['base_dn']; } return $user_dn; @@ -193,24 +168,18 @@ public static function getUserDN($config) /** * get group dn. * - * @return string + * @return string */ public static function getGroupDN($config) { $group_dn = ''; - if (isset($config['additional_group_dn']) && $config['additional_group_dn']) - { - if (strpos($config['additional_group_dn'], $config['base_dn']) !== false) - { + if (isset($config['additional_group_dn']) && $config['additional_group_dn']) { + if (strpos($config['additional_group_dn'], $config['base_dn']) !== false) { $group_dn = $config['additional_group_dn']; - } - else - { + } else { $group_dn = $config['additional_group_dn'] . ',' . $config['base_dn']; } - } - else - { + } else { $group_dn = $config['base_dn']; } return $group_dn; @@ -219,12 +188,11 @@ public static function getGroupDN($config) /** * sync the users. * - * @return bool + * @return bool */ public static function syncUsers($provider, $directory, $config) { - if (!isset($config['user_object_class'])) - { + if (!isset($config['user_object_class'])) { return false; } @@ -237,8 +205,7 @@ public static function syncUsers($provider, $directory, $config) ->rawFilter(isset($config['user_object_filter']) ? $config['user_object_filter'] : ('(objectClass=' . $config['user_object_class'] . ')')) ->where('objectClass', $config['user_object_class']) ->get(); - foreach ($users as $user) - { + foreach ($users as $user) { $dn = $user->getDn(); $cn = $user->getFirstAttribute(strtolower($config['user_name_attr'])); $email = $user->getFirstAttribute(strtolower($config['user_email_attr'])); @@ -246,23 +213,22 @@ public static function syncUsers($provider, $directory, $config) $eloquent_user = EloquentUser::where('directory', $directory) ->where('ldap_dn', $dn) ->first(); - if ($eloquent_user) - { + if ($eloquent_user) { Sentinel::update($eloquent_user, [ 'first_name' => $cn, 'email' => $email, 'invalid_flag' => 0, 'sync_flag' => 0 ]); - } - else - { - Sentinel::register([ + } else { + Sentinel::register( + [ 'directory' => $directory, 'ldap_dn' => $dn, 'first_name' => $cn, 'email' => $email, 'password' => md5(rand(10000, 99999)) ], - true); + true + ); } } // disable the users @@ -277,12 +243,11 @@ public static function syncUsers($provider, $directory, $config) /** * sync the groups. * - * @return bool + * @return bool */ public static function syncGroups($provider, $directory, $config) { - if (!isset($config['group_object_class'])) - { + if (!isset($config['group_object_class'])) { return false; } @@ -293,8 +258,7 @@ public static function syncGroups($provider, $directory, $config) ->where('objectClass', $config['group_object_class']) ->get(); - foreach ($groups as $group) - { + foreach ($groups as $group) { $dn = $group->getDn(); $cn = $group->getFirstAttribute(strtolower($config['group_name_attr'])); $members = $group->getAttribute(strtolower($config['group_membership_attr'])); @@ -305,26 +269,22 @@ public static function syncGroups($provider, $directory, $config) ->toArray(); $user_ids = []; - if ($users) - { + if ($users) { $user_ids = array_column($users, '_id'); } $eloquent_group = Group::where('directory', $directory) ->where('ldap_dn', $dn) ->first(); - if ($eloquent_group) - { + if ($eloquent_group) { $eloquent_group ->fill([ 'name' => $cn, 'users' => $user_ids ]) ->save(); - } - else - { - Group::create([ - 'name' => $cn, - 'users' => $user_ids, - 'ldap_dn' => $dn, + } else { + Group::create([ + 'name' => $cn, + 'users' => $user_ids, + 'ldap_dn' => $dn, 'directory' => $directory ]); } } @@ -338,7 +298,7 @@ public static function syncGroups($provider, $directory, $config) * @var array $configs * @var string $username * @var string $password - * @return object + * @return object */ public static function attempt($configs, $username, $password) { @@ -347,22 +307,19 @@ public static function attempt($configs, $username, $password) $ad = new Adldap(self::filterConnectConfigs($configs)); - foreach ($configs as $key => $config) - { + foreach ($configs as $key => $config) { try { $provider = $ad->connect($key); $user = EloquentUser::where('directory', $key) ->where('email', $username) - ->first(); + ->first(); - if (!$user || !$user->ldap_dn) - { + if (!$user || !$user->ldap_dn) { continue; } - if ($provider->auth()->attempt($user->ldap_dn, $password)) - { + if ($provider->auth()->attempt($user->ldap_dn, $password)) { $pass = true; break; } diff --git a/app/Console/Commands/RemoveLogs.php b/app/Console/Commands/RemoveLogs.php index f7215d48d..ad420236c 100644 --- a/app/Console/Commands/RemoveLogs.php +++ b/app/Console/Commands/RemoveLogs.php @@ -38,20 +38,18 @@ public function __construct() public function handle() { - $durations = [ - '3m' => '3 months', - '6m' => '6 months', - '1y' => '1 year', - '2y' => '2 years', + $durations = [ + '3m' => '3 months', + '6m' => '6 months', + '1y' => '1 year', + '2y' => '2 years', ]; $log_save_duration = '6 months'; $syssetting = SysSetting::first()->toArray(); - if (isset($syssetting['properties']) && isset($syssetting['properties']['logs_save_duration'])) - { - if (isset($durations[$syssetting['properties']['logs_save_duration']])) - { + if (isset($syssetting['properties']) && isset($syssetting['properties']['logs_save_duration'])) { + if (isset($durations[$syssetting['properties']['logs_save_duration']])) { $log_save_duration = $durations[$syssetting['properties']['logs_save_duration']]; } } diff --git a/app/Console/Commands/SendEmails.php b/app/Console/Commands/SendEmails.php index 865ec26f4..20d7936fb 100644 --- a/app/Console/Commands/SendEmails.php +++ b/app/Console/Commands/SendEmails.php @@ -87,8 +87,7 @@ public function __construct() && isset($syssetting['mailserver']['smtp']['host']) && isset($syssetting['mailserver']['smtp']['port']) && isset($syssetting['mailserver']['smtp']['username']) - && isset($syssetting['mailserver']['smtp']['password'])) - { + && isset($syssetting['mailserver']['smtp']['password'])) { Config::set('mail.from', $syssetting['mailserver']['send']['from']); Config::set('mail.host', $syssetting['mailserver']['smtp']['host']); Config::set('mail.port', $syssetting['mailserver']['smtp']['port']); @@ -102,13 +101,11 @@ public function __construct() if (isset($syssetting['mailserver']) && isset($syssetting['mailserver']['send']) && isset($syssetting['mailserver']['send']['prefix']) - && $syssetting['mailserver']['send']['prefix']) - { + && $syssetting['mailserver']['send']['prefix']) { $this->mail_prefix = $syssetting['mailserver']['send']['prefix']; } - if (isset($syssetting['properties']) && isset($syssetting['properties']['http_host'])) - { + if (isset($syssetting['properties']) && isset($syssetting['properties']['http_host'])) { $this->http_host = $syssetting['properties']['http_host']; } @@ -135,8 +132,7 @@ public function getEventMap() { $map = []; $events = Events::whereRaw([ 'key' => [ '$exists' => 1 ] ])->get(); - foreach ($events as $event) - { + foreach ($events as $event) { $key = $event->key; $map[$key] = $event->id; } @@ -153,8 +149,7 @@ public function getEventMap() public function getNotifications($project_key, $event_id) { $en = EventNotifications::where([ 'project_key' => $project_key, 'event_id' => $event_id ])->first(); - if (!$en) - { + if (!$en) { $en = EventNotifications::where([ 'project_key' => '$_sys_$', 'event_id' => $event_id ])->first(); } return $en && isset($en->notifications) ? $en->notifications : []; @@ -170,15 +165,15 @@ public function getNotifications($project_key, $event_id) public function getUsersByRoleId($project_key, $role_id) { $actor = Roleactor::where([ 'project_key' => $project_key, 'role_id' => $role_id ])->first(); - if (!$actor) { return [ 'users' => [], 'groups' => [] ]; } + if (!$actor) { + return [ 'users' => [], 'groups' => [] ]; + } $user_ids = isset($actor->user_ids) && $actor->user_ids ? $actor->user_ids : []; - if (isset($actor->group_ids) && $actor->group_ids) - { + if (isset($actor->group_ids) && $actor->group_ids) { $groups = Group::find($actor->group_ids); - foreach ($groups as $group) - { + foreach ($groups as $group) { $user_ids = array_merge($user_ids, isset($group->users) ? $group->users : []); } } @@ -199,19 +194,16 @@ public function otherNoticeHandle($project, $activity) $subject = ''; $template = ''; - if ($activity['event_key'] == 'start_sprint') - { + if ($activity['event_key'] == 'start_sprint') { $sprint_no = isset($activity['data']) && isset($activity['data']['sprint_no']) ? $activity['data']['sprint_no'] : ''; - if (!$sprint_no) - { + if (!$sprint_no) { return; } $sprint = Sprint::where('project_key', $project->key) ->where('no', $sprint_no) ->first(); - if ($sprint->status !== 'active' || !isset($sprint['issues'])) - { + if ($sprint->status !== 'active' || !isset($sprint['issues'])) { return; } @@ -230,12 +222,9 @@ public function otherNoticeHandle($project, $activity) $subject = '[' . $this->mail_prefix . '] ' . $project->key . ': Sprint-' . $sprint_no . ' 启动'; $template = 'emails.sprint_start'; - } - else if ($activity['event_key'] == 'complete_sprint') - { + } elseif ($activity['event_key'] == 'complete_sprint') { $sprint_no = isset($activity['data']) && isset($activity['data']['sprint_no']) ? $activity['data']['sprint_no'] : ''; - if (!$sprint_no) - { + if (!$sprint_no) { return; } @@ -243,23 +232,20 @@ public function otherNoticeHandle($project, $activity) ->where('no', $sprint_no) ->first(); - if ($sprint->status !== 'completed') - { + if ($sprint->status !== 'completed') { return; } $completed_issues = []; $incompleted_issues = []; - if (isset($sprint->completed_issues) && $sprint->completed_issues) - { + if (isset($sprint->completed_issues) && $sprint->completed_issues) { $completed_issues = DB::collection('issue_' . $project->key) ->whereIn('no', $sprint->completed_issues) ->where('del_flg', '<>', 1) ->get(); } - if (isset($sprint->incompleted_issues) && $sprint->incompleted_issues) - { + if (isset($sprint->incompleted_issues) && $sprint->incompleted_issues) { $incompleted_issues = DB::collection('issue_' . $project->key) ->whereIn('no', $sprint->incompleted_issues) ->where('del_flg', '<>', 1) @@ -278,12 +264,9 @@ public function otherNoticeHandle($project, $activity) $subject = '[' . $this->mail_prefix . '] ' . $project->key . ': Sprint-' . $sprint_no . ' 完成'; $template = 'emails.sprint_complete'; - } - else if ($activity['event_key'] == 'release_version') - { + } elseif ($activity['event_key'] == 'release_version') { $release_version = isset($activity['data']) ? $activity['data'] : []; - if (!$release_version) - { + if (!$release_version) { return; } @@ -304,13 +287,10 @@ public function otherNoticeHandle($project, $activity) $subject = '[' . $this->mail_prefix . '] ' . $project->key . ': 版本-' . $release_version['name'] . ' 发布'; $template = 'emails.version_release'; - } - else if ($activity['event_key'] == 'create_release_version') - { + } elseif ($activity['event_key'] == 'create_release_version') { $released_issueids = isset($activity['data']['released_issues']) ? $activity['data']['released_issues'] : []; $release_version = isset($activity['data']['release_version']) ? $activity['data']['release_version'] : []; - if (!$released_issueids || !$release_version) - { + if (!$released_issueids || !$release_version) { return; } @@ -330,19 +310,18 @@ public function otherNoticeHandle($project, $activity) $subject = '[' . $this->mail_prefix . '] ' . $project->key . ': 版本-' . $release_version['name'] . ' 发布'; $template = 'emails.version_release'; - } - else if ($activity['event_key'] == 'create_wiki' || $activity['event_key'] == 'edit_wiki') - { + } elseif ($activity['event_key'] == 'create_wiki' || $activity['event_key'] == 'edit_wiki') { $wiki_id = isset($activity['data']['wiki_id']) ? $activity['data']['wiki_id'] : ''; - if (!$wiki_id) - { + if (!$wiki_id) { return; } $wiki = DB::collection('wiki_' . $project->key) ->where('_id', $wiki_id) ->first(); - if (!$wiki) { return; } + if (!$wiki) { + return; + } $data = [ 'project' => $project, @@ -355,9 +334,7 @@ public function otherNoticeHandle($project, $activity) $subject = '[' . $this->mail_prefix . '] ' . $project->key . ': Wiki-' . $wiki['name']; $template = 'emails.wiki'; - } - else - { + } else { return; } @@ -365,12 +342,11 @@ public function otherNoticeHandle($project, $activity) $to_users = EloquentUser::find(array_unique($uids)); - foreach ($to_users as $to_user) - { + foreach ($to_users as $to_user) { $from = $activity['user']['name']; $to = $to_user['email']; try { - Mail::send($template, $data, function($message) use($from, $to, $subject) { + Mail::send($template, $data, function ($message) use ($from, $to, $subject) { $message->from(Config::get('mail.from'), $from) ->to($to) ->subject($subject); @@ -396,76 +372,51 @@ public function issueNoticeHandle($project, $activity) $event_map = $this->event_map; $issue = DB::collection('issue_' . $project->key)->where('_id', $issue_id)->first(); - if (!$issue) { return; } + if (!$issue) { + return; + } $event_key = ($activity['event_key'] == 'add_file' || $activity['event_key'] == 'del_file') ? 'edit_issue' : $activity['event_key']; $event_id = isset($event_map[$event_key]) && $event_map[$event_key] ? $event_map[$event_key] : $event_key; $notifications = $this->getNotifications($project->key, $event_id); - foreach ($notifications as $notification) - { - if ('current_user' === $notification) - { + foreach ($notifications as $notification) { + if ('current_user' === $notification) { $uids[] = $activity['user']['id']; - } - else if ('reporter' === $notification) - { + } elseif ('reporter' === $notification) { $uids[] = $issue['reporter']['id']; - } - else if ('assignee' === $notification) - { - if (isset($issue['assignee']) && isset($issue['assignee']['id'])) - { + } elseif ('assignee' === $notification) { + if (isset($issue['assignee']) && isset($issue['assignee']['id'])) { $uids[] = $issue['assignee']['id']; } - } - else if ('watchers' === $notification) - { + } elseif ('watchers' === $notification) { $watchers = Watch::where('issue_id', $issue['_id']->__toString())->get(); - foreach ($watchers as $watcher) - { + foreach ($watchers as $watcher) { $uids[] = $watcher['user']['id']; } - } - else if ('project_principal' === $notification) - { + } elseif ('project_principal' === $notification) { $uids[] = $project->principal['id']; - } - else if ('module_principal' === $notification && isset($issue['module'])) - { + } elseif ('module_principal' === $notification && isset($issue['module'])) { $module = Module::find($issue['module']); - if ($module && isset($module->principal) && isset($module->principal['id'])) - { + if ($module && isset($module->principal) && isset($module->principal['id'])) { $uids[] = $module->principal['id']; } - } - else if (is_array($notification) && isset($notification['key'])) - { - if ($notification['key'] === 'user' && isset($notification['value']) && isset($notification['value']['id'])) - { + } elseif (is_array($notification) && isset($notification['key'])) { + if ($notification['key'] === 'user' && isset($notification['value']) && isset($notification['value']['id'])) { $uids[] = $notification['value']['id']; - } - else if ($notification['key'] === 'role' && isset($notification['value'])) - { + } elseif ($notification['key'] === 'role' && isset($notification['value'])) { $role_users = $this->getUsersByRoleId($project->key, $notification['value']); $uids = array_merge($uids, $role_users); - } - else if ($notification['key'] === 'single_user_field' && isset($notification['value'])) - { + } elseif ($notification['key'] === 'single_user_field' && isset($notification['value'])) { $key = $notification['value']; - if (isset($issue[$key]) && isset($issue[$key]['id'])) - { + if (isset($issue[$key]) && isset($issue[$key]['id'])) { $uids[] = $issue[$key]['id']; } - } - else if ($notification['key'] === 'multi_user_field' && isset($notification['value'])) - { + } elseif ($notification['key'] === 'multi_user_field' && isset($notification['value'])) { $key = $notification['value']; - if (isset($issue[$key]) && $issue[$key]) - { - foreach ($issue[$key] as $v) - { + if (isset($issue[$key]) && $issue[$key]) { + foreach ($issue[$key] as $v) { $uids[] = $v['id']; } } @@ -473,38 +424,29 @@ public function issueNoticeHandle($project, $activity) } } - if ($event_key == 'create_issue') - { - if (isset($issue['type']) && $issue['type']) - { + if ($event_key == 'create_issue') { + if (isset($issue['type']) && $issue['type']) { $type = Type::find($issue['type']); $issue['type'] = $type ? $type->name : '-'; } - if (isset($issue['priority']) && $issue['priority']) - { + if (isset($issue['priority']) && $issue['priority']) { $priority = Priority::where('_id', $issue['priority'])->orWhere('key', $issue['priority'])->first(); $issue['priority'] = $priority ? $priority->name : '-'; - } - else - { + } else { $issue['priority'] = '-'; } } $atWho = []; - if ($event_key == 'add_comments' or $event_key == 'edit_comments' or $event_key == 'del_comments') - { - if (isset($activity['data']) && isset($activity['data']['atWho']) && $activity['data']['atWho']) - { - foreach ($activity['data']['atWho'] as $who) - { + if ($event_key == 'add_comments' or $event_key == 'edit_comments' or $event_key == 'del_comments') { + if (isset($activity['data']) && isset($activity['data']['atWho']) && $activity['data']['atWho']) { + foreach ($activity['data']['atWho'] as $who) { $uids[] = $who['id']; $atWho[] = $who['id']; } } - if (isset($activity['data']) && isset($activity['data']['to']) && $activity['data']['to']) - { - $uids[] = $activity['data']['to']['id']; + if (isset($activity['data']) && isset($activity['data']['to']) && $activity['data']['to']) { + $uids[] = $activity['data']['to']['id']; } } @@ -518,11 +460,9 @@ public function issueNoticeHandle($project, $activity) ]; $to_users = EloquentUser::find(array_values(array_unique(array_filter($uids)))); - foreach ($to_users as $to_user) - { + foreach ($to_users as $to_user) { $new_data = $data; - if (in_array($to_user->id, $atWho)) - { + if (in_array($to_user->id, $atWho)) { $new_data['at'] = true; } @@ -530,7 +470,7 @@ public function issueNoticeHandle($project, $activity) $to = $to_user['email']; $subject = '[' . $this->mail_prefix . '](' . $project->key . '-' . $issue['no'] . ')' . (isset($issue['title']) ? $issue['title'] : '-'); try { - Mail::send('emails.issue', $new_data, function($message) use($from, $to, $subject) { + Mail::send('emails.issue', $new_data, function ($message) use ($from, $to, $subject) { $message->from(Config::get('mail.from'), $from) ->to($to) ->subject($subject); @@ -554,28 +494,25 @@ public function handle() // mark up the notice message DB::collection('mq')->where('flag', 0)->update([ 'flag' => $point ]); - if (!$this->isSmtpConfiged()) - { + if (!$this->isSmtpConfiged()) { return; } $data = DB::collection('mq')->where('flag', $point)->orderBy('_id', 'asc')->get(); - foreach ($data as $val) - { + foreach ($data as $val) { $uids = []; $project_key = $val['project_key']; $project = Project::where('key', $project_key)->first(); - if (!$project) { continue; } + if (!$project) { + continue; + } $activity = DB::collection('activity_' . $project_key)->where('_id', $val['activity_id'])->first(); - if (isset($activity['issue_id']) && $activity['issue_id']) - { + if (isset($activity['issue_id']) && $activity['issue_id']) { $this->issueNoticeHandle($project, $activity); - } - else - { + } else { $this->otherNoticeHandle($project, $activity); } diff --git a/app/Console/Commands/SnapSprint.php b/app/Console/Commands/SnapSprint.php index afb14ecf9..16a7efa9e 100644 --- a/app/Console/Commands/SnapSprint.php +++ b/app/Console/Commands/SnapSprint.php @@ -42,8 +42,7 @@ public function handle() ->where('complete_time', '>', time()) ->get(); - foreach ($active_sprints as $sprint) - { + foreach ($active_sprints as $sprint) { $project_key = $sprint->project_key; $contents = []; @@ -51,8 +50,7 @@ public function handle() $issues = DB::collection('issue_' . $project_key) ->where([ 'no' => [ '$in' => $issue_nos ] ]) ->get(); - foreach ($issues as $issue) - { + foreach ($issues as $issue) { $tmp = []; $tmp['no'] = $issue['no']; $tmp['state'] = isset($issue['state']) ? $issue['state'] : ''; @@ -62,10 +60,10 @@ public function handle() SprintDayLog::where([ 'project_key' => $project_key, 'no' => $sprint->no, 'day' => date('Y/m/d') ])->delete(); - SprintDayLog::create([ - 'project_key' => $project_key, - 'no' => $sprint->no, - 'day' => date('Y/m/d'), + SprintDayLog::create([ + 'project_key' => $project_key, + 'no' => $sprint->no, + 'day' => date('Y/m/d'), 'issues' => $contents ]); } } diff --git a/app/Console/Commands/SyncLdap.php b/app/Console/Commands/SyncLdap.php index f9bd86986..8f9110b62 100644 --- a/app/Console/Commands/SyncLdap.php +++ b/app/Console/Commands/SyncLdap.php @@ -46,13 +46,11 @@ public function handle() $directories = Directory::where('type', 'OpenLDAP') ->where('invalide_flag', '<>', 1) ->get(); - foreach($directories as $d) - { + foreach ($directories as $d) { $configs[ $d->id ] = $d->configs; } - if ($configs) - { + if ($configs) { LDAP::sync($configs); } } diff --git a/app/Console/Commands/TriggerWebhooks.php b/app/Console/Commands/TriggerWebhooks.php index 1913f18ca..b4debf249 100644 --- a/app/Console/Commands/TriggerWebhooks.php +++ b/app/Console/Commands/TriggerWebhooks.php @@ -36,23 +36,19 @@ public function handle() $timestamp = time(); $hasRun = WebhookEvents::where('flag', '<>', 0)->exists(); - if ($hasRun) - { + if ($hasRun) { return; } - while(true) - { + while (true) { WebhookEvents::where('flag', 0)->update([ 'flag' => $timestamp ]); $events = WebhookEvents::where('flag', $timestamp)->orderBy('_id', 'asc')->get(); - if ($events->isEmpty()) - { + if ($events->isEmpty()) { break; } - foreach ($events as $event) - { + foreach ($events as $event) { $header = [ 'Content-Type: application/json', 'Expect:', 'X-Actionview-Token: ' . ($event->token ?: '') ]; $this->curlPost($event->request_url, $header, $event->data ?: []); $event->delete(); @@ -94,8 +90,7 @@ public static function multiCurlPost(array $nodes, $await=5) $mh = curl_multi_init(); $chs = []; - foreach($nodes as $key => $node) - { + foreach ($nodes as $key => $node) { $chs[$key] = curl_init(); curl_setopt($chs[$key], CURLOPT_URL, isset($node['url']) ? $node['url'] : ''); @@ -115,12 +110,10 @@ public static function multiCurlPost(array $nodes, $await=5) $active = null; do { $mrc = curl_multi_exec($mh, $active); - } while($mrc == CURLM_CALL_MULTI_PERFORM); + } while ($mrc == CURLM_CALL_MULTI_PERFORM); - while ($active && $mrc == CURLM_OK) - { - if (curl_multi_select($mh) == -1) - { + while ($active && $mrc == CURLM_OK) { + if (curl_multi_select($mh) == -1) { usleep(100); } @@ -130,16 +123,12 @@ public static function multiCurlPost(array $nodes, $await=5) } $results = []; - foreach($nodes as $key => $node) - { + foreach ($nodes as $key => $node) { $tmp = []; $ecode = curl_errno($chs[$key]); - if ($ecode > 0) - { + if ($ecode > 0) { $tmp = [ 'ecode' => $ecode, 'contents' => curl_error($chs[$key]) ]; - } - else - { + } else { $tmp = [ 'ecode' => $ecode, 'contents' => curl_multi_getcontent($chs[$key]) ]; } $results[] = $tmp; diff --git a/app/Customization/Eloquent/EventNotifications.php b/app/Customization/Eloquent/EventNotifications.php index 4c845309b..6c9161537 100644 --- a/app/Customization/Eloquent/EventNotifications.php +++ b/app/Customization/Eloquent/EventNotifications.php @@ -1,6 +1,6 @@ getCode() ?: -99999; - return [ 'ecode' => $ecode, 'emsg' => $e->getMessage() ]; + return ['ecode' => $ecode, 'emsg' => $e->getMessage()]; //return parent::render($request, $e); } } diff --git a/app/Http/Controllers/AccessLogsController.php b/app/Http/Controllers/AccessLogsController.php index 53e21cd68..c468f4d6f 100644 --- a/app/Http/Controllers/AccessLogsController.php +++ b/app/Http/Controllers/AccessLogsController.php @@ -26,68 +26,54 @@ public function index(Request $request) $query = ApiAccessLogs::query(); $uid = $request->input('uid'); - if (isset($uid) && $uid) - { + if (isset($uid) && $uid) { $query = $query->where('user.id', $uid); } $method = $request->input('method'); - if (isset($method) && $method) - { + if (isset($method) && $method) { $query = $query->where('request_method', $method); } $project_key = $request->input('project_key'); - if (isset($project_key) && $project_key) - { + if (isset($project_key) && $project_key) { $query = $query->where('project_key', $project_key); } $module = $request->input('module'); - if (isset($module) && $module) - { + if (isset($module) && $module) { $query = $query->where('module', $module); } $request_time = $request->input('request_time'); - if (isset($request_time) && $request_time) - { - if (strpos($request_time, '~') !== false) - { + if (isset($request_time) && $request_time) { + if (strpos($request_time, '~') !== false) { $sections = explode('~', $request_time); - if ($sections[0]) - { + if ($sections[0]) { $query->where('requested_start_at', '>=', strtotime($sections[0]) * 1000); } - if ($sections[1]) - { + if ($sections[1]) { $query->where('requested_start_at', '<=', strtotime($sections[1] . ' 23:59:59') * 1000); } } } $url = $request->input('request_url'); - if (isset($url) && $url) - { + if (isset($url) && $url) { $query->where('request_url', 'like', '%' . $url . '%'); } $request_source_ip = $request->input('request_source_ip'); - if (isset($request_source_ip) && $request_source_ip) - { + if (isset($request_source_ip) && $request_source_ip) { $query->where('request_source_ip', $request_source_ip); } $exec_time = $request->input('exec_time'); - if (isset($exec_time) && $exec_time) - { + if (isset($exec_time) && $exec_time) { $flag = substr($exec_time, 0, 1); - if ($flag == '-') - { + if ($flag == '-') { $query->where('exec_time', '<=', abs(floatval($exec_time)) * 1000); - } - else - { + } else { $query->where('exec_time', '>=', abs(floatval($exec_time)) * 1000); } } @@ -102,8 +88,7 @@ public function index(Request $request) $logs = $query->get(); $from = $request->input('from'); - if (isset($from) && $from == 'export') - { + if (isset($from) && $from == 'export') { $this->export($logs); exit(); } @@ -121,25 +106,24 @@ public function export($logs) { set_time_limit(0); - $headers = [ - '用户', - '方法', - 'Url', - '模块', - '请求开始时间', - '请求结束时间', - '请求时长(毫秒)', - '来源IP', - 'User-Agent', - 'Body' + $headers = [ + '用户', + '方法', + 'Url', + '模块', + '请求开始时间', + '请求结束时间', + '请求时长(毫秒)', + '来源IP', + 'User-Agent', + 'Body' ]; $file_name = 'access-logs'; - Excel::create($file_name, function ($excel) use($headers, $logs) { - $excel->sheet('Sheetname', function ($sheet) use($headers, $logs) { + Excel::create($file_name, function ($excel) use ($headers, $logs) { + $excel->sheet('Sheetname', function ($sheet) use ($headers, $logs) { $sheet->appendRow($headers); - foreach ($logs as $log) - { + foreach ($logs as $log) { $tmp = []; $tmp[] = $log->user ? $log->user['name'] : ''; $tmp[] = $log->request_method ?: ''; diff --git a/app/Http/Controllers/ActivityController.php b/app/Http/Controllers/ActivityController.php index 66fc1a4b8..0351427ce 100644 --- a/app/Http/Controllers/ActivityController.php +++ b/app/Http/Controllers/ActivityController.php @@ -25,14 +25,12 @@ public function index(Request $request, $project_key) $query = DB::collection('activity_' . $project_key); $category = $request->input('category'); - if (isset($category) && $category != 'all') - { + if (isset($category) && $category != 'all') { $query->where('event_key', 'like', '%' . $category); } $offset_id = $request->input('offset_id'); - if (isset($offset_id)) - { + if (isset($offset_id)) { $query = $query->where('_id', '<', $offset_id); } @@ -41,73 +39,58 @@ public function index(Request $request, $project_key) $query->orderBy('_id', 'desc'); $limit = $request->input('limit'); - if (!isset($limit)) - { + if (!isset($limit)) { $limit = 30; } $query->take(intval($limit)); $avatars = []; $activities = $query->get(); - foreach ($activities as $key => $activity) - { - if (!array_key_exists($activity['user']['id'], $avatars)) - { + foreach ($activities as $key => $activity) { + if (!array_key_exists($activity['user']['id'], $avatars)) { $user = Sentinel::findById($activity['user']['id']); $avatars[$activity['user']['id']] = isset($user->avatar) ? $user->avatar : ''; } $activities[$key]['user']['avatar'] = $avatars[$activity['user']['id']]; - if ($activity['event_key'] == 'create_link' || $activity['event_key'] == 'del_link') - { + if ($activity['event_key'] == 'create_link' || $activity['event_key'] == 'del_link') { $activities[$key]['issue_link'] = []; - if (isset($cache_issues[$activity['issue_id']])) - { - $issue = $cache_issues[$activity['issue_id']]; - } - else - { + if (isset($cache_issues[$activity['issue_id']])) { + $issue = $cache_issues[$activity['issue_id']]; + } else { $issue = DB::collection('issue_' . $project_key)->where('_id', $activity['issue_id'])->first(); } - $activities[$key]['issue_link'][ 'src'] = [ - 'id' => $activity['issue_id'], - 'no' => $issue['no'], - 'title' => isset($issue['title']) ? $issue['title'] : '', - 'state' => isset($issue['state']) ? $issue['state'] : '', + $activities[$key]['issue_link'][ 'src'] = [ + 'id' => $activity['issue_id'], + 'no' => $issue['no'], + 'title' => isset($issue['title']) ? $issue['title'] : '', + 'state' => isset($issue['state']) ? $issue['state'] : '', 'del_flg' => isset($issue['del_flg']) ? $issue['del_flg'] : 0 ]; $activities[$key]['issue_link']['relation'] = $activity['data']['relation']; - if (isset($cache_issues[$activity['data']['dest']])) - { - $issue = $cache_issues[$activity['data']['dest']]; - } - else - { + if (isset($cache_issues[$activity['data']['dest']])) { + $issue = $cache_issues[$activity['data']['dest']]; + } else { $issue = DB::collection('issue_' . $project_key)->where('_id', $activity['data']['dest'])->first(); } - $activities[$key]['issue_link']['dest'] = [ - 'id' => $activity['data']['dest'], - 'no' => $issue['no'], - 'title' => isset($issue['title']) ? $issue['title'] : '', - 'state' => isset($issue['state']) ? $issue['state'] : '', + $activities[$key]['issue_link']['dest'] = [ + 'id' => $activity['data']['dest'], + 'no' => $issue['no'], + 'title' => isset($issue['title']) ? $issue['title'] : '', + 'state' => isset($issue['state']) ? $issue['state'] : '', 'del_flg' => isset($issue['del_flg']) ? $issue['del_flg'] : 0 ]; - } - else if (isset($activity['issue_id'])) - { - if (isset($cache_issues[$activity['issue_id']])) - { - $issue = $cache_issues[$activity['issue_id']]; - } - else - { + } elseif (isset($activity['issue_id'])) { + if (isset($cache_issues[$activity['issue_id']])) { + $issue = $cache_issues[$activity['issue_id']]; + } else { $issue = DB::collection('issue_' . $project_key)->where('_id', $activity['issue_id'])->first(); } - $activities[$key]['issue'] = [ - 'id' => $activity['issue_id'], - 'no' => $issue['no'], - 'title' => isset($issue['title']) ? $issue['title'] : '', - 'state' => isset($issue['state']) ? $issue['state'] : '', + $activities[$key]['issue'] = [ + 'id' => $activity['issue_id'], + 'no' => $issue['no'], + 'title' => isset($issue['title']) ? $issue['title'] : '', + 'state' => isset($issue['state']) ? $issue['state'] : '', 'del_flg' => isset($issue['del_flg']) ? $issue['del_flg'] : 0 ]; $cache_issues[$activity['issue_id']] = $issue; } diff --git a/app/Http/Controllers/BoardController.php b/app/Http/Controllers/BoardController.php index ebc7bd2db..549888443 100644 --- a/app/Http/Controllers/BoardController.php +++ b/app/Http/Controllers/BoardController.php @@ -28,9 +28,10 @@ public function __construct() * get user accessed board list * * @param string $project_key - * @return response + * @return response */ - public function index($project_key) { + public function index($project_key) + { // get all boards $boards = Board::Where('project_key', $project_key) ->orderBy('_id', 'asc') @@ -43,26 +44,20 @@ public function index($project_key) { $list = []; $accessed_boards = []; - foreach($access_records as $record) - { - foreach($boards as $board) - { - if ($board->id == $record->board_id) - { - $accessed_boards[] = $record->board_id; + foreach ($access_records as $record) { + foreach ($boards as $board) { + if ($board->id == $record->board_id) { + $accessed_boards[] = $record->board_id; break; } } - if (in_array($record->board_id, $accessed_boards)) - { + if (in_array($record->board_id, $accessed_boards)) { $list[] = $board; } } - foreach ($boards as $board) - { - if (!in_array($board->id, $accessed_boards)) - { + foreach ($boards as $board) { + if (!in_array($board->id, $accessed_boards)) { $list[] = $board; } } @@ -72,10 +67,8 @@ public function index($project_key) { ->orderBy('no', 'asc') ->get(); // compatible with old data - foreach ($sprints as $sprint) - { - if (!$sprint->name) - { + foreach ($sprints as $sprint) { + if (!$sprint->name) { $sprint->name = 'Sprint ' . $sprint->no; } } @@ -94,26 +87,26 @@ public function index($project_key) { return Response()->json([ 'ecode' => 0, 'data' => $list, 'options' => [ 'epics' => $epics, 'sprints' => $sprints, 'versions' => $versions, 'completed_sprint_num' => $completed_sprint_num ] ]); -/* -$example = [ - 'id' => '111', - 'name' => '1111111111', - 'type' => 'kanban', - 'query' => [ 'type' => [ '59af4ad51d41c85e9108a8a7' ], 'subtask' => true ], - 'last_access_time' => 11111111, - 'columns' => [ - [ 'no' => 1, 'name' => '待处理', 'states' => [ 'Open', 'Reopened' ] ], - [ 'no' => 2, 'name' => '处理中', 'states' => [ 'In Progess' ] ], - [ 'no' => 3, 'name' => '关闭', 'states' => [ 'Resolved', 'Closed' ] ] - ], - 'filters' => [ - [ 'no' => 1, 'id' => '11111', 'name' => '111111', 'query' => [ 'updated_at' => '1m' ] ], - [ 'no' => 2, 'id' => '22222', 'name' => '222222' ], - [ 'no' => 3, 'id' => '33333', 'name' => '333333' ], - ], -]; - return Response()->json([ 'ecode' => 0, 'data' => [ $example ] ]); -*/ + /* + $example = [ + 'id' => '111', + 'name' => '1111111111', + 'type' => 'kanban', + 'query' => [ 'type' => [ '59af4ad51d41c85e9108a8a7' ], 'subtask' => true ], + 'last_access_time' => 11111111, + 'columns' => [ + [ 'no' => 1, 'name' => '待处理', 'states' => [ 'Open', 'Reopened' ] ], + [ 'no' => 2, 'name' => '处理中', 'states' => [ 'In Progess' ] ], + [ 'no' => 3, 'name' => '关闭', 'states' => [ 'Resolved', 'Closed' ] ] + ], + 'filters' => [ + [ 'no' => 1, 'id' => '11111', 'name' => '111111', 'query' => [ 'updated_at' => '1m' ] ], + [ 'no' => 2, 'id' => '22222', 'name' => '222222' ], + [ 'no' => 3, 'id' => '33333', 'name' => '333333' ], + ], + ]; + return Response()->json([ 'ecode' => 0, 'data' => [ $example ] ]); + */ } /** @@ -125,44 +118,36 @@ public function index($project_key) { public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -11600); } $type = $request->input('type'); - if (!$type || ($type != 'kanban' && $type != 'scrum')) - { + if (!$type || ($type != 'kanban' && $type != 'scrum')) { throw new \UnexpectedValueException('the type value has error.', -11608); } - $columns = [ - [ 'no' => 1, 'name' => '开始', 'states' => [] ], + $columns = [ + [ 'no' => 1, 'name' => '开始', 'states' => [] ], [ 'no' => 2, 'name' => '处理中', 'states' => [] ], [ 'no' => 3, 'name' => '完成', 'states' => [] ], ]; $states = Provider::getStateOptions($project_key); - foreach ($states as $state) - { + foreach ($states as $state) { $state_val = $state['_id']; - if ($state['category'] === 'new') - { + if ($state['category'] === 'new') { array_push($columns[0]['states'], $state_val); - } - else if ($state['category'] === 'inprogress') - { + } elseif ($state['category'] === 'inprogress') { array_push($columns[1]['states'], $state_val); - } - else if ($state['category'] === 'completed') - { + } elseif ($state['category'] === 'completed') { array_push($columns[2]['states'], $state_val); } } // only support for kanban type, fix me - $board = Board::create([ - 'project_key' => $project_key, - 'query' => [ 'subtask' => true ], + $board = Board::create([ + 'project_key' => $project_key, + 'query' => [ 'subtask' => true ], 'columns' => $columns ] + $request->all()); return Response()->json(['ecode' => 0, 'data' => $board]); @@ -178,50 +163,42 @@ public function store(Request $request, $project_key) public function update(Request $request, $project_key, $id) { $board = Board::find($id); - if (!$board || $project_key != $board->project_key) - { + if (!$board || $project_key != $board->project_key) { throw new \UnexpectedValueException('the board does not exist or is not in the project.', -11601); } $updValues = []; $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -11600); } $updValues['name'] = $name; } $description = $request->input('description'); - if (isset($description)) - { + if (isset($description)) { $updValues['description'] = $description; } $query = $request->input('query'); - if (isset($query)) - { + if (isset($query)) { // defaultly display subtask issue $updValues['query'] = [ 'subtask' => true ] + $query; } $filters = $request->input('filters'); - if (isset($filters)) - { + if (isset($filters)) { $updValues['filters'] = $filters; } $columns = $request->input('columns'); - if (isset($columns)) - { + if (isset($columns)) { $updValues['columns'] = $columns; } $display_fields = $request->input('display_fields'); - if (isset($display_fields)) - { + if (isset($display_fields)) { $updValues['display_fields'] = $display_fields ?: []; } @@ -252,7 +229,7 @@ public function show($project_key, $id) } /** - * rank the column issues + * rank the column issues * * @param string $project_key * @param string $id @@ -261,35 +238,30 @@ public function show($project_key, $id) public function setRank(Request $request, $project_key, $id) { $current = $request->input('current') ?: ''; - if (!$current) - { + if (!$current) { throw new \UnexpectedValueException('the ranked issue not be empty.', -11603); } $up = $request->input('up') ?: -1; $down = $request->input('down') ?: -1; - if ($up == -1 && $down == -1) - { + if ($up == -1 && $down == -1) { throw new \UnexpectedValueException('the ranked position can not be empty.', -11604); } $rankmap = BoardRankMap::where([ 'board_id' => $id ])->first(); - if (!$rankmap || !isset($rankmap->rank)) - { + if (!$rankmap || !isset($rankmap->rank)) { throw new \UnexpectedValueException('the rank list is not exist.', -11605); } $rank = $rankmap->rank; $curInd = array_search($current, $rank); - if ($curInd === false) - { + if ($curInd === false) { throw new \UnexpectedValueException('the issue is not found in the rank list.', -11606); } $blocks = [ $current ]; $subtasks = Provider::getChildrenByParentNo($project_key, $current); - if ($subtasks) - { + if ($subtasks) { $rankedSubtasks = array_intersect($rank, $subtasks); $blocks = array_merge($blocks, $rankedSubtasks); } @@ -297,61 +269,48 @@ public function setRank(Request $request, $project_key, $id) // delete current issue from the rank array_splice($rank, $curInd, count($blocks)); - if ($up != -1) - { + if ($up != -1) { $upInd = array_search($up, $rank); $subtasks = Provider::getChildrenByParentNo($project_key, $up); $intersects = array_intersect($rank, $subtasks); - if ($upInd === false && !$intersects) - { + if ($upInd === false && !$intersects) { throw new \UnexpectedValueException('the ranked position is not found.', -11607); - } - else - { + } else { $realUpInd = -1; - if ($intersects) - { + if ($intersects) { $realUpInd = array_search(array_pop($intersects), $rank); - } - else - { + } else { $realUpInd = $upInd; } // insert current issue into the rank array_splice($rank, $realUpInd + 1, 0, $blocks); } - } - else - { + } else { $downInd = array_search($down, $rank); - if ($downInd !== false) - { + if ($downInd !== false) { // insert current issue into the rank array_splice($rank, $downInd, 0, $blocks); - } - else - { + } else { $subtasks = Provider::getChildrenByParentNo($project_key, $down); $intersects = array_intersect($rank, $subtasks); - if (!$intersects) - { + if (!$intersects) { throw new \UnexpectedValueException('the ranked position is not found.', -11607); } - $realDownInd = array_search(array_shift($intersects), $rank); + $realDownInd = array_search(array_shift($intersects), $rank); // insert current issue into the rank array_splice($rank, $realDownInd, 0, $blocks); } - } + } - $old_rank = BoardRankMap::where([ 'board_id' => $id ])->first(); + $old_rank = BoardRankMap::where([ 'board_id' => $id ])->first(); $old_rank && $old_rank->delete(); BoardRankMap::create([ 'board_id' => $id, 'rank' => $rank ]); - $rankmap = BoardRankMap::where([ 'board_id' => $id ])->first(); + $rankmap = BoardRankMap::where([ 'board_id' => $id ])->first(); return Response()->json([ 'ecode' => 0, 'data' => $rankmap ]); } @@ -362,15 +321,15 @@ public function setRank(Request $request, $project_key, $id) * @param string $id * @return void */ - public function recordAccess($project_key, $id) + public function recordAccess($project_key, $id) { $record = AccessBoardLog::where([ 'board_id' => $id, 'user_id' => $this->user->id ])->first(); $record && $record->delete(); - AccessBoardLog::create([ - 'project_key' => $project_key, - 'user_id' => $this->user->id, - 'board_id' => $id, + AccessBoardLog::create([ + 'project_key' => $project_key, + 'user_id' => $this->user->id, + 'board_id' => $id, 'latest_access_time' => time() ]); return Response()->json(['ecode' => 0, 'data' => [ 'id' => $id ] ]); } @@ -384,8 +343,7 @@ public function recordAccess($project_key, $id) public function destroy($project_key, $id) { $board = Board::find($id); - if (!$board || $project_key != $board->project_key) - { + if (!$board || $project_key != $board->project_key) { throw new \UnexpectedValueException('the board does not exist or is not in the project.', -11601); } @@ -397,6 +355,5 @@ public function destroy($project_key, $id) Board::destroy($id); return Response()->json(['ecode' => 0, 'data' => ['id' => $id]]); - } } diff --git a/app/Http/Controllers/CalendarController.php b/app/Http/Controllers/CalendarController.php index 13dd0e1de..3828d67c3 100644 --- a/app/Http/Controllers/CalendarController.php +++ b/app/Http/Controllers/CalendarController.php @@ -19,13 +19,13 @@ public function __construct() parent::__construct(); } - var $solar_special_days = [ + public $solar_special_days = [ '0101' => '元旦', '0501' => '劳动', '1001' => '国庆', ]; - var $lunar_special_days = [ + public $lunar_special_days = [ '0101' => '春节', '0505' => '端午', '0815' => '中秋', @@ -38,16 +38,14 @@ public function __construct() */ public function index(Request $request, $year) { - if ($year == 'current') - { - $year = date('Y'); + if ($year == 'current') { + $year = date('Y'); } - if ($year > 2038 || $year < 1970) - { - throw new \UnexpectedValueException('the assigned year has error.', -16020); + if ($year > 2038 || $year < 1970) { + throw new \UnexpectedValueException('the assigned year has error.', -16020); } - $dates = $this->getYearDates(intval($year)); + $dates = $this->getYearDates(intval($year)); return Response()->json([ 'ecode' => 0, 'data' => $dates, 'options' => [ 'year' => date('Y'), 'date' => date('Y/m/d') ] ]); } @@ -62,27 +60,22 @@ public function getYearDates($year) { $year_singulars = []; $singulars = CalendarSingular::where('year', $year)->get(); - foreach ($singulars as $val) - { + foreach ($singulars as $val) { $year_singulars[$val->date] = $val; } $dates = $this->getYearBasicDates($year); - foreach ($dates as $key => $date) - { - if (!isset($year_singulars[$date['date']])) - { + foreach ($dates as $key => $date) { + if (!isset($year_singulars[$date['date']])) { continue; } $singular_date = $year_singulars[$date['date']]; - if (isset($singular_date['type']) && $singular_date['type']) - { + if (isset($singular_date['type']) && $singular_date['type']) { $dates[$key]['type'] = $singular_date['type']; } - if (isset($singular_date['target']) && $singular_date['target']) - { + if (isset($singular_date['target']) && $singular_date['target']) { $dates[$key]['target'] = $singular_date['target']; } } @@ -105,8 +98,8 @@ private function convert2lunar($year, $month, $day) $lunar_date = sprintf('%02d', $lunar_info[4]) . sprintf('%02d', $lunar_info[5]); return [ - 'year' => $lunar_info[3], - 'month' => $lunar_info[1], + 'year' => $lunar_info[3], + 'month' => $lunar_info[1], 'day' => $lunar_info[2], 'target' => isset($this->lunar_special_days[$lunar_date]) ? $this->lunar_special_days[$lunar_date] : '', ]; @@ -121,11 +114,9 @@ private function convert2lunar($year, $month, $day) private function getYearBasicDates($year) { $dates = []; - for ($i = 1; $i <= 12; $i++) - { + for ($i = 1; $i <= 12; $i++) { $mcnt = date('t', strtotime($year . '-' . $i . '-1')); - for ($j = 1; $j <= $mcnt; $j++) - { + for ($j = 1; $j <= $mcnt; $j++) { $lunar = $this->convert2lunar($year, $i, $j); $solar_date = sprintf('%02d', $i) . sprintf('%02d', $j); @@ -148,54 +139,44 @@ private function getYearBasicDates($year) public function update(Request $request) { $start_date = $request->input('start_date'); - if (!isset($start_date) || !$start_date) - { + if (!isset($start_date) || !$start_date) { throw new \UnexpectedValueException('the start date can not be empty.', -16021); } $end_date = $request->input('end_date'); - if (!isset($end_date) || !$end_date) - { + if (!isset($end_date) || !$end_date) { throw new \UnexpectedValueException('the end date can not be empty.', -16022); } $dates = []; $start_time = strtotime($start_date); $end_time = strtotime($end_date); - for ($i = $start_time; $i <= $end_time; $i = $i + 3600 * 24) - { + for ($i = $start_time; $i <= $end_time; $i = $i + 3600 * 24) { $dates[] = date('Y/m/d', $i); } - if (!$dates) - { + if (!$dates) { throw new \UnexpectedValueException('the date range can not be empty.', -16023); } $mode = $request->input('mode'); - if (!isset($mode) || !$mode) - { + if (!isset($mode) || !$mode) { throw new \UnexpectedValueException('the operate mode can not be empty.', -16024); } - if ($mode === 'set') - { + if ($mode === 'set') { $type = $request->input('type'); - if (!isset($type) || !$type) - { + if (!isset($type) || !$type) { throw new \UnexpectedValueException('the setted type can not be empty.', -16025); } - if (!in_array($type, [ 'holiday', 'workday' ])) - { + if (!in_array($type, [ 'holiday', 'workday' ])) { throw new \UnexpectedValueException('the setted type has error.', -16026); } } CalendarSingular::whereIn('date', $dates)->delete(); - if ($mode === 'set') - { - foreach ($dates as $date) - { + if ($mode === 'set') { + foreach ($dates as $date) { CalendarSingular::create([ 'date' => $date, 'year' => intval(substr($date, 0, 4)), @@ -216,8 +197,7 @@ public function update(Request $request) public function sync(Request $request) { $year = $request->input('year'); - if (!isset($year) || !$year) - { + if (!isset($year) || !$year) { throw new \UnexpectedValueException('the sync year can not be empty.', -16027); } @@ -226,26 +206,23 @@ public function sync(Request $request) $url = 'http://www.actionview.cn:8080/actionview/api/holiday/' . $year; $res = CurlRequest::get($url); - if (!isset($res['ecode']) || $res['ecode'] != 0) - { + if (!isset($res['ecode']) || $res['ecode'] != 0) { throw new \UnexpectedValueException('failed to request the api.', -16028); } - if (!isset($res['data']) || !$res['data']) - { + if (!isset($res['data']) || !$res['data']) { throw new \UnexpectedValueException('the sync year data is empty.', -16029); } CalendarSingular::where('year', $year)->delete(); $singulars = $res['data']; - foreach ($singulars as $value) - { + foreach ($singulars as $value) { CalendarSingular::create([ 'date' => $value['date'], 'year' => $year, 'type' => isset($value['holiday']) && $value['holiday'] ? 'holiday' : 'workday' - ]); + ]); } return Response()->json([ 'ecode' => 0, 'data' => $this->getYearDates($year) ]); diff --git a/app/Http/Controllers/CommentsController.php b/app/Http/Controllers/CommentsController.php index e2c253791..5a28fabc5 100644 --- a/app/Http/Controllers/CommentsController.php +++ b/app/Http/Controllers/CommentsController.php @@ -40,14 +40,12 @@ public function index(Request $request, $project_key, $issue_id) */ public function store(Request $request, $project_key, $issue_id) { - if (!$this->isPermissionAllowed($project_key, 'add_comments')) - { + if (!$this->isPermissionAllowed($project_key, 'add_comments')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } $contents = $request->input('contents'); - if (!$contents) - { + if (!$contents) { throw new \UnexpectedValueException('the contents can not be empty.', -11200); } @@ -58,7 +56,7 @@ public function store(Request $request, $project_key, $issue_id) $id = DB::collection($table)->insertGetId(array_only($request->all(), [ 'contents', 'atWho' ]) + [ 'issue_id' => $issue_id, 'creator' => $creator, 'created_at' => time() ]); // trigger event of comments added - Event::fire(new IssueEvent($project_key, $issue_id, $creator, [ 'event_key' => 'add_comments', 'data' => array_only($request->all(), [ 'contents', 'atWho' ]) ])); + Event::fire(new IssueEvent($project_key, $issue_id, $creator, [ 'event_key' => 'add_comments', 'data' => array_only($request->all(), [ 'contents', 'atWho' ]) ])); $comments = DB::collection($table)->find($id); return Response()->json([ 'ecode' => 0, 'data' => parent::arrange($comments) ]); @@ -86,16 +84,13 @@ public function show($project_key, $id) public function update(Request $request, $project_key, $issue_id, $id) { $comments = DB::collection('comments_' . $project_key)->find($id); - if (!$comments) - { + if (!$comments) { throw new \UnexpectedValueException('the comments does not exist or is not in the project.', -11201); } $contents = $request->input('contents'); - if (isset($contents)) - { - if (!$contents) - { + if (isset($contents)) { + if (!$contents) { throw new \UnexpectedValueException('the contents can not be empty.', -11200); } } @@ -105,97 +100,72 @@ public function update(Request $request, $project_key, $issue_id, $id) $table = 'comments_' . $project_key; $user = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; $operation = $request->input('operation'); - if (isset($operation)) - { - if (!in_array($operation, [ 'addReply', 'editReply', 'delReply' ])) - { + if (isset($operation)) { + if (!in_array($operation, [ 'addReply', 'editReply', 'delReply' ])) { throw new \UnexpectedValueException('the operation is incorrect value.', -11204); } - if (!isset($comments['reply']) || !$comments['reply']) - { + if (!isset($comments['reply']) || !$comments['reply']) { $comments['reply'] = []; } - if ($operation == 'addReply') - { - if (!$this->isPermissionAllowed($project_key, 'add_comments')) - { + if ($operation == 'addReply') { + if (!$this->isPermissionAllowed($project_key, 'add_comments')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } - $reply_id = md5(microtime() . $this->user->id); + $reply_id = md5(microtime() . $this->user->id); array_push($comments['reply'], array_only($request->all(), [ 'contents', 'atWho' ]) + [ 'id' => $reply_id , 'creator' => $user, 'created_at' => time() ]); $changedComments = array_only($request->all(), [ 'contents', 'atWho' ]) + [ 'to' => $comments['creator'] ]; - } - else if ($operation == 'editReply') - { + } elseif ($operation == 'editReply') { $reply_id = $request->input('reply_id'); - if (!isset($reply_id) || !$reply_id) - { + if (!isset($reply_id) || !$reply_id) { throw new \UnexpectedValueException('the reply id can not be empty.', -11202); } - $index = $this->array_find([ 'id' => $reply_id ], $comments['reply']); - if ($index !== false) - { - if (!$this->isPermissionAllowed($project_key, 'edit_comments') && !($comments['reply'][$index]['creator']['id'] == $this->user->id && $this->isPermissionAllowed($project_key, 'edit_self_comments'))) - { + $index = $this->array_find([ 'id' => $reply_id ], $comments['reply']); + if ($index !== false) { + if (!$this->isPermissionAllowed($project_key, 'edit_comments') && !($comments['reply'][$index]['creator']['id'] == $this->user->id && $this->isPermissionAllowed($project_key, 'edit_self_comments'))) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } $comments['reply'][$index] = array_merge($comments['reply'][$index], [ 'updated_at' => time(), 'edited_flag' => 1 ] + array_only($request->all(), [ 'contents', 'atWho' ])); $changedComments = array_only($comments['reply'][$index], [ 'contents', 'atWho' ]) + [ 'to' => $comments['creator'] ]; - } - else - { + } else { throw new \UnexpectedValueException('the reply does not exist', -11203); } - } - else if ($operation == 'delReply') - { + } elseif ($operation == 'delReply') { $reply_id = $request->input('reply_id'); - if (!isset($reply_id) || !$reply_id) - { + if (!isset($reply_id) || !$reply_id) { throw new \UnexpectedValueException('the reply id can not be empty.', -11202); } - $index = $this->array_find([ 'id' => $reply_id ], $comments['reply']); - if ($index !== false) - { - if (!$this->isPermissionAllowed($project_key, 'delete_comments') && !($comments['reply'][$index]['creator']['id'] == $this->user->id && $this->isPermissionAllowed($project_key, 'delete_self_comments'))) - { + $index = $this->array_find([ 'id' => $reply_id ], $comments['reply']); + if ($index !== false) { + if (!$this->isPermissionAllowed($project_key, 'delete_comments') && !($comments['reply'][$index]['creator']['id'] == $this->user->id && $this->isPermissionAllowed($project_key, 'delete_self_comments'))) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } $changedComments = array_only($comments['reply'][$index], [ 'contents', 'atWho' ]) + [ 'to' => $comments['creator'] ]; array_splice($comments['reply'], $index, 1); - } - else - { + } else { throw new \UnexpectedValueException('the reply does not exist', -11203); } } DB::collection($table)->where('_id', $id)->update([ 'reply' => $comments['reply'] ]); - } - else - { - if (!$this->isPermissionAllowed($project_key, 'edit_comments') && !($comments['creator']['id'] == $this->user->id && $this->isPermissionAllowed($project_key, 'edit_self_comments'))) - { + } else { + if (!$this->isPermissionAllowed($project_key, 'edit_comments') && !($comments['creator']['id'] == $this->user->id && $this->isPermissionAllowed($project_key, 'edit_self_comments'))) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } - DB::collection($table)->where('_id', $id)->update([ 'updated_at' => time(), 'edited_flag' => 1 ] + array_only($request->all(), [ 'contents', 'atWho' ]) ); + DB::collection($table)->where('_id', $id)->update([ 'updated_at' => time(), 'edited_flag' => 1 ] + array_only($request->all(), [ 'contents', 'atWho' ])); $changedComments = array_only($request->all(), [ 'contents', 'atWho' ]); } - // trigger event of comments + // trigger event of comments $event_key = ''; - if (isset($operation)) - { + if (isset($operation)) { $operation === 'addReply' && $event_key = 'add_comments'; $operation === 'editReply' && $event_key = 'edit_comments'; $operation === 'delReply' && $event_key = 'del_comments'; - } - else - { + } else { $event_key = 'edit_comments'; } Event::fire(new IssueEvent($project_key, $issue_id, $user, [ 'event_key' => $event_key, 'data' => $changedComments ])); @@ -213,13 +183,11 @@ public function destroy($project_key, $issue_id, $id) { $table = 'comments_' . $project_key; $comments = DB::collection($table)->find($id); - if (!$comments) - { + if (!$comments) { throw new \UnexpectedValueException('the comments does not exist or is not in the project.', -11201); } - if (!$this->isPermissionAllowed($project_key, 'manage_project') && !($comments['creator']['id'] == $this->user->id && $this->isPermissionAllowed($project_key, 'delete_self_comments'))) - { + if (!$this->isPermissionAllowed($project_key, 'manage_project') && !($comments['creator']['id'] == $this->user->id && $this->isPermissionAllowed($project_key, 'delete_self_comments'))) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } @@ -227,7 +195,7 @@ public function destroy($project_key, $issue_id, $id) $user = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; // trigger the event of del comments - Event::fire(new IssueEvent($project_key, $issue_id, $user, [ 'event_key' => 'del_comments', 'data' => array_only($comments, [ 'contents', 'atWho' ]) ])); + Event::fire(new IssueEvent($project_key, $issue_id, $user, [ 'event_key' => 'del_comments', 'data' => array_only($comments, [ 'contents', 'atWho' ]) ])); return Response()->json(['ecode' => 0, 'data' => ['id' => $id]]); } @@ -241,10 +209,8 @@ public function destroy($project_key, $issue_id, $id) */ public function array_find($needle, $haystack) { - foreach($haystack as $key => $val) - { - if ($needle['id'] == $val['id']) - { + foreach ($haystack as $key => $val) { + if ($needle['id'] == $val['id']) { return $key; } } diff --git a/app/Http/Controllers/ConfigController.php b/app/Http/Controllers/ConfigController.php index 8f7b37243..3d1504fa0 100644 --- a/app/Http/Controllers/ConfigController.php +++ b/app/Http/Controllers/ConfigController.php @@ -22,11 +22,9 @@ class ConfigController extends Controller public function index($project_key) { $new_types = []; - $types = Provider::getTypeList($project_key); - foreach ($types as $type) - { - if (isset($type->disabled) && $type->disabled) - { + $types = Provider::getTypeList($project_key); + foreach ($types as $type) { + if (isset($type->disabled) && $type->disabled) { continue; } $type->screen = $type->screen; @@ -36,8 +34,7 @@ public function index($project_key) $priorities = Provider::getPriorityList($project_key); $roles = Provider::getRoleList($project_key); - foreach($roles as $role) - { + foreach ($roles as $role) { $role->permissions = $this->getPermissions($project_key, $role->id); } @@ -54,8 +51,7 @@ public function index($project_key) public function getPermissions($project_key, $role_id) { $rp = RolePermissions::where([ 'project_key' => $project_key, 'role_id' => $role_id ])->first(); - if (!$rp && $project_key !== '$_sys_$') - { + if (!$rp && $project_key !== '$_sys_$') { $rp = RolePermissions::where([ 'project_key' => '$_sys_$', 'role_id' => $role_id ])->first(); } return $rp && isset($rp->permissions) ? $rp->permissions : []; diff --git a/app/Http/Controllers/Controller.php b/app/Http/Controllers/Controller.php index eacf4c794..7b93a31a2 100644 --- a/app/Http/Controllers/Controller.php +++ b/app/Http/Controllers/Controller.php @@ -15,7 +15,7 @@ use Sentinel; use DB; -use MongoDB\BSON\ObjectID; +use MongoDB\BSON\ObjectID; class Controller extends BaseController { @@ -23,23 +23,26 @@ class Controller extends BaseController public function __construct() { - $this->user = Sentinel::getUser(); + } + + public function __get($property) + { + if ($property == 'user') { + return Sentinel::getUser(); + } } public function arrange($data) { - if (!is_array($data)) - { + if (!is_array($data)) { return $data; } - if (array_key_exists('_id', $data)) - { + if (array_key_exists('_id', $data)) { $data['_id'] = $data['_id'] instanceof ObjectID ? $data['_id']->__toString() : $data['_id']; } - foreach ($data as $k => $val) - { + foreach ($data as $k => $val) { $data[$k] = $this->arrange($val); } @@ -58,16 +61,13 @@ public function isPermissionAllowed($project_key, $permission, $user_id='') $uid = isset($user_id) && $user_id ? $user_id : $this->user->id; $isAllowed = Acl::isAllowed($uid, $permission, $project_key); - if (!$isAllowed && in_array($permission, [ 'view_project', 'manage_project' ])) - { - if ($this->user->email === 'admin@action.view') - { + if (!$isAllowed && in_array($permission, [ 'view_project', 'manage_project' ])) { + if ($this->user->email === 'admin@action.view') { return true; } $project = Project::where([ 'key' => $project_key ])->first(); - if ($project && isset($project->principal) && isset($project->principal['id']) && $uid === $project->principal['id']) - { + if ($project && isset($project->principal) && isset($project->principal['id']) && $uid === $project->principal['id']) { return true; } } @@ -77,33 +77,28 @@ public function isPermissionAllowed($project_key, $permission, $user_id='') /** * check if the field is used by issue. * - * @return true + * @return true */ public function isFieldUsedByIssue($project_key, $field_key, $field, $ext_info='') { - if ($field['project_key'] !== $project_key) - { - return true; + if ($field['project_key'] !== $project_key) { + return true; } - if ($project_key === '$_sys_$') - { - switch($field_key) - { + if ($project_key === '$_sys_$') { + switch ($field_key) { case 'type': return false; case 'state': case 'priority': case 'resolution': $projects = Project::all(); - foreach($projects as $project) - { + foreach ($projects as $project) { $isUsed = DB::collection('issue_' . $project->key) ->where($field_key, isset($field['key']) ? $field['key'] : $field['_id']) ->where('del_flg', '<>', 1) ->exists(); - if ($isUsed) - { + if ($isUsed) { return true; } } @@ -111,11 +106,8 @@ public function isFieldUsedByIssue($project_key, $field_key, $field, $ext_info=' default: return true; } - } - else - { - switch($field_key) - { + } else { + switch ($field_key) { case 'type': case 'state': case 'priority': @@ -131,16 +123,14 @@ public function isFieldUsedByIssue($project_key, $field_key, $field, $ext_info=' ->where('del_flg', '<>', 1) ->exists(); case 'version': - if (!$ext_info) - { + if (!$ext_info) { return false; } $vid = $field['_id']; return DB::collection('issue_' . $project_key) ->where(function ($query) use ($vid, $ext_info) { - foreach ($ext_info as $key => $vf) - { + foreach ($ext_info as $key => $vf) { $query->orWhere($vf['key'], $vid); } }) @@ -181,171 +171,113 @@ public function getIssueQueryWhere($project_key, $query) $all_fields = array_merge($fields ? $fields->toArray() : [], $special_fields); // convert into key-type array $key_type_fields = []; - foreach ($all_fields as $key => $val) - { + foreach ($all_fields as $key => $val) { $key_type_fields[$val['key']] = $val['type']; } // get the query where value $where = array_only($query, array_column($all_fields, 'key')); $and = []; - foreach ($where as $key => $val) - { - if ($key === 'no') - { + foreach ($where as $key => $val) { + if ($key === 'no') { $and[] = [ 'no' => intval($val) ]; - } - else if ($key === 'title') - { - if (is_numeric($val) && strpos($val, '.') === false) - { + } elseif ($key === 'title') { + if (is_numeric($val) && strpos($val, '.') === false) { $and[] = [ '$or' => [ [ 'no' => $val + 0 ], [ 'title' => [ '$regex' => $val ] ] ] ]; - } - else if (strpos($val, ',') !== false) - { + } elseif (strpos($val, ',') !== false) { $nos = explode(',', $val); $new_nos = []; - foreach ($nos as $no) - { - if ($no && is_numeric($no)) - { + foreach ($nos as $no) { + if ($no && is_numeric($no)) { $new_nos[] = $no + 0; } } $and[] = [ '$or' => [ [ 'no' => [ '$in' => $new_nos ] ], [ 'title' => [ '$regex' => $val ] ] ] ]; - } - else - { + } else { $and[] = [ 'title' => [ '$regex' => $val ] ]; } - } - else if ($key === 'sprints') - { + } elseif ($key === 'sprints') { $and[] = [ 'sprints' => $val + 0 ]; - } - else if ($key_type_fields[$key] === 'SingleUser') - { + } elseif ($key_type_fields[$key] === 'SingleUser') { $users = explode(',', $val); - if (in_array('me', $users)) - { + if (in_array('me', $users)) { array_push($users, $this->user->id); } $and[] = [ $key . '.' . 'id' => [ '$in' => $users ] ]; - } - else if ($key_type_fields[$key] === 'MultiUser') - { + } elseif ($key_type_fields[$key] === 'MultiUser') { $or = []; $vals = explode(',', $val); - foreach ($vals as $v) - { + foreach ($vals as $v) { $or[] = [ $key . '_ids' => $v == 'me' ? $this->user->id : $v ]; } $and[] = [ '$or' => $or ]; - } - else if (in_array($key_type_fields[$key], [ 'Select', 'SingleVersion', 'RadioGroup' ])) - { + } elseif (in_array($key_type_fields[$key], [ 'Select', 'SingleVersion', 'RadioGroup' ])) { $and[] = [ $key => [ '$in' => explode(',', $val) ] ]; - } - else if (in_array($key_type_fields[$key], [ 'MultiSelect', 'MultiVersion', 'CheckboxGroup' ])) - { + } elseif (in_array($key_type_fields[$key], [ 'MultiSelect', 'MultiVersion', 'CheckboxGroup' ])) { $or = []; $vals = explode(',', $val); - foreach ($vals as $v) - { + foreach ($vals as $v) { $or[] = [ $key => $v ]; } $and[] = [ '$or' => $or ]; - } - else if (in_array($key_type_fields[$key], [ 'Duration', 'DatePicker', 'DateTimePicker' ])) - { - if (strpos($val, '~') !== false) - { + } elseif (in_array($key_type_fields[$key], [ 'Duration', 'DatePicker', 'DateTimePicker' ])) { + if (strpos($val, '~') !== false) { $sections = explode('~', $val); - if ($sections[0]) - { + if ($sections[0]) { $and[] = [ $key => [ '$gte' => strtotime($sections[0]) ] ]; } - if ($sections[1]) - { + if ($sections[1]) { $and[] = [ $key => [ '$lte' => strtotime($sections[1] . ' 23:59:59') ] ]; } - } - else if (in_array($val, [ '0d', '0w', '0m', '0y' ])) - { - if ($val == '0d') - { + } elseif (in_array($val, [ '0d', '0w', '0m', '0y' ])) { + if ($val == '0d') { $and[] = [ $key => [ '$gte' => strtotime(date('Y-m-d')), '$lte' => strtotime(date('Y-m-d') . ' 23:59:59') ] ]; - } - else if ($val == '0w') - { + } elseif ($val == '0w') { $and[] = [ $key => [ '$gte' => mktime(0, 0, 0, date('m'), date('d') - date('w') + 1, date('Y')), '$lte' => mktime(23, 59, 59, date('m'), date('d') - date('w') + 7, date('Y')) ] ]; - } - else if ($val == '0m') - { + } elseif ($val == '0m') { $and[] = [ $key => [ '$gte' => mktime(0, 0, 0, date('m'), 1, date('Y')), '$lte' => mktime(23, 59, 59, date('m'), date('t'), date('Y')) ] ]; - } - else - { + } else { $and[] = [ $key => [ '$gte' => mktime(0, 0, 0, 1, 1, date('Y')), '$lte' => mktime(23, 59, 59, 12, 31, date('Y')) ] ]; } - } - else - { + } else { $unitMap = [ 'w' => 'week', 'm' => 'month', 'y' => 'year' ]; $unit = substr($val, -1); - if (in_array($unit, [ 'w', 'm', 'y' ])) - { + if (in_array($unit, [ 'w', 'm', 'y' ])) { $direct = substr($val, 0, 1); $val = abs(substr($val, 0, -1)); - if ($direct === '-') - { + if ($direct === '-') { $and[] = [ $key => [ '$lt' => strtotime(date('Ymd', strtotime('-' . $val . ' ' . $unitMap[$unit]))) ] ]; - } - else - { + } else { $and[] = [ $key => [ '$gte' => strtotime(date('Ymd', strtotime('-' . $val . ' ' . $unitMap[$unit]))) ] ]; } } } - } - else if (in_array($key_type_fields[$key], [ 'Text', 'TextArea', 'Url' ])) - { + } elseif (in_array($key_type_fields[$key], [ 'Text', 'TextArea', 'Url' ])) { $and[] = [ $key => [ '$regex' => $val ] ]; - } - else if (in_array($key_type_fields[$key], [ 'Number', 'Integer' ])) - { - if (strpos($val, '~') !== false) - { + } elseif (in_array($key_type_fields[$key], [ 'Number', 'Integer' ])) { + if (strpos($val, '~') !== false) { $sections = explode('~', $val); - if ($sections[0]) - { + if ($sections[0]) { $and[] = [ $key => [ '$gte' => $sections[0] + 0 ] ]; } - if ($sections[1]) - { + if ($sections[1]) { $and[] = [ $key => [ '$lte' => $sections[1] + 0 ] ]; } } - } - else if ($key_type_fields[$key] === 'TimeTracking') - { - if (strpos($val, '~') !== false) - { + } elseif ($key_type_fields[$key] === 'TimeTracking') { + if (strpos($val, '~') !== false) { $sections = explode('~', $val); - if ($sections[0]) - { + if ($sections[0]) { $and[] = [ $key . '_m' => [ '$gte' => $this->ttHandleInM($sections[0]) ] ]; } - if ($sections[1]) - { + if ($sections[1]) { $and[] = [ $key . '_m' => [ '$lte' => $this->ttHandleInM($sections[1]) ] ]; } } } } - if (isset($query['watcher']) && $query['watcher']) - { + if (isset($query['watcher']) && $query['watcher']) { $watcher = $query['watcher'] === 'me' ? $this->user->id : $query['watcher']; $watched_issues = Watch::where('project_key', $project_key) @@ -355,8 +287,7 @@ public function getIssueQueryWhere($project_key, $query) $watched_issue_ids = array_column($watched_issues, 'issue_id'); $watchedIds = []; - foreach ($watched_issue_ids as $id) - { + foreach ($watched_issue_ids as $id) { $watchedIds[] = new ObjectID($id); } $and[] = [ '_id' => [ '$in' => $watchedIds ] ]; diff --git a/app/Http/Controllers/DirectoryController.php b/app/Http/Controllers/DirectoryController.php index 7cca94f2e..749dec5cf 100644 --- a/app/Http/Controllers/DirectoryController.php +++ b/app/Http/Controllers/DirectoryController.php @@ -32,10 +32,8 @@ public function __construct() public function index(Request $request) { $directories = Directory::all()->toArray(); - foreach($directories as $k => $d) - { - if (isset($d['configs']) && $d['configs'] && isset($d['configs']['admin_password'])) - { + foreach ($directories as $k => $d) { + if (isset($d['configs']) && $d['configs'] && isset($d['configs']['admin_password'])) { unset($directories[$k]['configs']['admin_password']); } } @@ -50,40 +48,34 @@ public function index(Request $request) */ public function store(Request $request) { - if (!($name = $request->input('name'))) - { + if (!($name = $request->input('name'))) { throw new \UnexpectedValueException('the name can not be empty.', -10300); } $configs = []; - if (!($host = $request->input('host'))) - { + if (!($host = $request->input('host'))) { throw new \UnexpectedValueException('the host can not be empty.', -10301); } $configs['host'] = $host; - if (!($port = $request->input('port'))) - { + if (!($port = $request->input('port'))) { throw new \UnexpectedValueException('the port can not be empty.', -10302); } $configs['port'] = intval($port); $configs['encryption'] = $request->input('encryption') ?: ''; - if (!($admin_username = $request->input('admin_username'))) - { + if (!($admin_username = $request->input('admin_username'))) { throw new \UnexpectedValueException('the username can not be empty.', -10303); } $configs['admin_username'] = $admin_username; - if (!($admin_password = $request->input('admin_password'))) - { + if (!($admin_password = $request->input('admin_password'))) { throw new \UnexpectedValueException('the user password can not be empty.', -10304); } $configs['admin_password'] = $admin_password; - if (!($base_dn = $request->input('base_dn'))) - { + if (!($base_dn = $request->input('base_dn'))) { throw new \UnexpectedValueException('the base_dn can not be empty.', -10305); } $configs['base_dn'] = $base_dn; @@ -91,51 +83,43 @@ public function store(Request $request) $configs['additional_user_dn'] = $request->input('additional_user_dn') ?: ''; $configs['additional_group_dn'] = $request->input('additional_group_dn') ?: ''; - if (!($user_object_class = $request->input('user_object_class'))) - { + if (!($user_object_class = $request->input('user_object_class'))) { throw new \UnexpectedValueException('the user object class can not be empty.', -10306); } $configs['user_object_class'] = $user_object_class; - if (!($user_object_filter = $request->input('user_object_filter'))) - { + if (!($user_object_filter = $request->input('user_object_filter'))) { throw new \UnexpectedValueException('the user object filter can not be empty.', -10307); } $configs['user_object_filter'] = $user_object_filter; - if (!($user_name_attr = $request->input('user_name_attr'))) - { + if (!($user_name_attr = $request->input('user_name_attr'))) { throw new \UnexpectedValueException('the user name attributte can not be empty.', -10308); } $configs['user_name_attr'] = $user_name_attr; - if (!($user_email_attr = $request->input('user_email_attr'))) - { + if (!($user_email_attr = $request->input('user_email_attr'))) { throw new \UnexpectedValueException('the user email attributte can not be empty.', -10309); } $configs['user_email_attr'] = $user_email_attr; - if (!($group_object_class = $request->input('group_object_class'))) - { + if (!($group_object_class = $request->input('group_object_class'))) { throw new \UnexpectedValueException('the group object class can not be empty.', -10310); } $configs['group_object_class'] = $group_object_class; - if (!($group_object_filter = $request->input('group_object_filter'))) - { + if (!($group_object_filter = $request->input('group_object_filter'))) { throw new \UnexpectedValueException('the group object filter can not be empty.', -10311); } $configs['group_object_filter'] = $group_object_filter; - if (!($group_name_attr = $request->input('group_name_attr'))) - { + if (!($group_name_attr = $request->input('group_name_attr'))) { throw new \UnexpectedValueException('the group name attributte can not be empty.', -10312); } $configs['group_name_attr'] = $group_name_attr; - if (!($group_membership_attr = $request->input('group_membership_attr'))) - { + if (!($group_membership_attr = $request->input('group_membership_attr'))) { throw new \UnexpectedValueException('the group membership attributte can not be empty.', -10313); } $configs['group_membership_attr'] = $group_membership_attr; @@ -153,8 +137,7 @@ public function store(Request $request) public function show($id) { $directory = Directory::find($id); - if (!$directory) - { + if (!$directory) { throw new \UnexpectedValueException('the directory does not exist.', -10314); } return Response()->json([ 'ecode' => 0, 'data' => $directory ]); @@ -170,18 +153,15 @@ public function show($id) public function update(Request $request, $id) { $directory = Directory::find($id); - if (!$directory) - { + if (!$directory) { throw new \UnexpectedValueException('the directory does not exist.', -10314); } $updValues = []; $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -10300); } $updValues['name'] = $name; @@ -190,161 +170,130 @@ public function update(Request $request, $id) $configs = []; $host = $request->input('host'); - if (isset($host)) - { - if (!$host) - { + if (isset($host)) { + if (!$host) { throw new \UnexpectedValueException('the host can not be empty.', -10301); } $configs['host'] = $host; } - $port = $request->input('port'); - if (isset($port)) - { - if (!$port) - { + $port = $request->input('port'); + if (isset($port)) { + if (!$port) { throw new \UnexpectedValueException('the port can not be empty.', -10302); } $configs['port'] = intval($port); } $encryption = $request->input('encryption'); - if (isset($encryption)) - { + if (isset($encryption)) { $configs['encryption'] = $encryption; } $admin_username = $request->input('admin_username'); - if (isset($admin_username)) - { - if (!$admin_username) - { + if (isset($admin_username)) { + if (!$admin_username) { throw new \UnexpectedValueException('the username can not be empty.', -10303); } $configs['admin_username'] = $admin_username; } $admin_password = $request->input('admin_password'); - if (isset($admin_password)) - { - if (!$admin_password) - { + if (isset($admin_password)) { + if (!$admin_password) { throw new \UnexpectedValueException('the user password can not be empty.', -10304); } $configs['admin_password'] = $admin_password; } $base_dn = $request->input('base_dn'); - if (isset($base_dn)) - { - if (!$base_dn) - { + if (isset($base_dn)) { + if (!$base_dn) { throw new \UnexpectedValueException('the base_dn can not be empty.', -10305); } $configs['base_dn'] = $base_dn; } $additional_user_dn = $request->input('additional_user_dn'); - if (isset($additional_user_dn)) - { + if (isset($additional_user_dn)) { $configs['additional_user_dn'] = $additional_user_dn; } $additional_group_dn = $request->input('additional_group_dn'); - if (isset($additional_group_dn)) - { + if (isset($additional_group_dn)) { $configs['additional_group_dn'] = $additional_group_dn; } $user_object_class = $request->input('user_object_class'); - if (isset($user_object_class)) - { - if (!$user_object_class) - { + if (isset($user_object_class)) { + if (!$user_object_class) { throw new \UnexpectedValueException('the user object class can not be empty.', -10306); } $configs['user_object_class'] = $user_object_class; } $user_object_filter = $request->input('user_object_filter'); - if (isset($user_object_filter)) - { - if (!$user_object_filter) - { + if (isset($user_object_filter)) { + if (!$user_object_filter) { throw new \UnexpectedValueException('the user object filter can not be empty.', -10307); } $configs['user_object_filter'] = $user_object_filter; } $user_name_attr = $request->input('user_name_attr'); - if (isset($user_name_attr)) - { - if (!$user_name_attr) - { + if (isset($user_name_attr)) { + if (!$user_name_attr) { throw new \UnexpectedValueException('the user name attributte can not be empty.', -10308); } $configs['user_name_attr'] = $user_name_attr; } $user_email_attr = $request->input('user_email_attr'); - if (isset($user_email_attr)) - { - if (!$user_email_attr) - { + if (isset($user_email_attr)) { + if (!$user_email_attr) { throw new \UnexpectedValueException('the user email attributte can not be empty.', -10309); } $configs['user_email_attr'] = $user_email_attr; } $group_object_class = $request->input('group_object_class'); - if (isset($group_object_class)) - { - if (!$group_object_class) - { + if (isset($group_object_class)) { + if (!$group_object_class) { throw new \UnexpectedValueException('the group object class can not be empty.', -10310); } $configs['group_object_class'] = $group_object_class; } $group_object_filter = $request->input('group_object_filter'); - if (isset($group_object_filter)) - { - if (!$group_object_filter) - { + if (isset($group_object_filter)) { + if (!$group_object_filter) { throw new \UnexpectedValueException('the group object filter can not be empty.', -10311); } $configs['group_object_filter'] = $group_object_filter; } $group_name_attr = $request->input('group_name_attr'); - if (isset($group_name_attr)) - { - if (!$group_name_attr) - { + if (isset($group_name_attr)) { + if (!$group_name_attr) { throw new \UnexpectedValueException('the group name attributte can not be empty.', -10312); } $configs['group_name_attr'] = $group_name_attr; } $group_membership_attr = $request->input('group_membership_attr'); - if (isset($group_membership_attr)) - { - if (!$group_membership_attr) - { + if (isset($group_membership_attr)) { + if (!$group_membership_attr) { throw new \UnexpectedValueException('the group membership attributte can not be empty.', -10313); } $configs['group_membership_attr'] = $group_membership_attr; } - if ($configs) - { + if ($configs) { $updValues['configs'] = isset($directory->configs) ? array_merge($directory->configs ?: [], $configs) : $configs; } $invalid_flag = $request->input('invalid_flag'); - if (isset($invalid_flag)) - { + if (isset($invalid_flag)) { $updValues['invalid_flag'] = intval($invalid_flag); } @@ -370,22 +319,19 @@ public function destroy($id) ini_set('max_execution_time', '0'); $directory = Directory::find($id); - if (!$directory) - { + if (!$directory) { throw new \UnexpectedValueException('the directory does not exist.', -10314); } // delete the related groups $groups = Group::where('directory', $id)->get(); - foreach ($groups as $group) - { + foreach ($groups as $group) { $group->delete(); Event::fire(new DelGroupEvent($group->id)); } $users = EloquentUser::where('directory', $id)->get(); - foreach ($users as $user) - { + foreach ($users as $user) { $user->delete(); Event::fire(new DelUserEvent($user->id)); } @@ -400,14 +346,13 @@ public function destroy($id) * @param int $id * @return \Illuminate\Http\Response */ - public function test($id) + public function test($id) { ini_set('memory_limit', '-1'); ini_set('max_execution_time', '0'); $directory = Directory::find($id); - if (!$directory) - { + if (!$directory) { throw new \UnexpectedValueException('the directory does not exist.', -10201); } @@ -425,14 +370,13 @@ public function test($id) * @param int $id * @return \Illuminate\Http\Response */ - public function sync($id) + public function sync($id) { ini_set('memory_limit', '-1'); ini_set('max_execution_time', '0'); $directory = Directory::find($id); - if (!$directory) - { + if (!$directory) { throw new \UnexpectedValueException('the directory does not exist.', -10314); } @@ -442,16 +386,11 @@ public function sync($id) $ret = LDAP::sync($configs); $sync_info = array_pop($ret); - if (!$sync_info['connect']) - { + if (!$sync_info['connect']) { throw new \UnexpectedValueException('the connect server failed.', -10315); - } - else if (!$sync_info['user']) - { + } elseif (!$sync_info['user']) { throw new \UnexpectedValueException('the user sync failed.', -10316); - } - else if (!$sync_info['group']) - { + } elseif (!$sync_info['group']) { throw new \UnexpectedValueException('the group sync failed.', -10317); } diff --git a/app/Http/Controllers/DocumentController.php b/app/Http/Controllers/DocumentController.php index d4ab03dd1..40b0652b1 100644 --- a/app/Http/Controllers/DocumentController.php +++ b/app/Http/Controllers/DocumentController.php @@ -24,13 +24,11 @@ class DocumentController extends Controller public function searchPath(Request $request, $project_key) { $s = $request->input('s'); - if (!$s) - { + if (!$s) { return Response()->json(['ecode' => 0, 'data' => []]); } - if ($s === '/') - { + if ($s === '/') { return Response()->json(['ecode' => 0, 'data' => [ [ 'id' => '0', 'name' => '/' ] ] ]); } @@ -40,8 +38,7 @@ public function searchPath(Request $request, $project_key) ->where('name', 'like', '%' . $s . '%'); $moved_path = $request->input('moved_path'); - if (isset($moved_path) && $moved_path) - { + if (isset($moved_path) && $moved_path) { $query->where('pt', '<>', $moved_path); $query->where('_id', '<>', $moved_path); } @@ -49,22 +46,18 @@ public function searchPath(Request $request, $project_key) $directories = $query->take(20)->get(['name', 'pt']); $ret = []; - foreach ($directories as $d) - { + foreach ($directories as $d) { $parents = []; $path = ''; $ps = DB::collection('document_' . $project_key) ->whereIn('_id', $d['pt']) ->get([ 'name' ]); - foreach ($ps as $val) - { + foreach ($ps as $val) { $parents[$val['_id']->__toString()] = $val['name']; } - foreach ($d['pt'] as $pid) - { - if (isset($parents[$pid])) - { + foreach ($d['pt'] as $pid) { + if (isset($parents[$pid])) { $path .= '/' . $parents[$pid]; } } @@ -83,18 +76,17 @@ public function searchPath(Request $request, $project_key) public function getDirChildren(Request $request, $project_key, $directory) { $sub_dirs = DB::collection('document_' . $project_key) - ->where('parent', $directory) + ->where('parent', $directory) ->where('d', 1) ->where('del_flag', '<>', 1) ->get(); - $res = []; - foreach ($sub_dirs as $val) - { - $res[] = [ 'id' => $val['_id']->__toString(), 'name' => $val['name'] ]; + $res = []; + foreach ($sub_dirs as $val) { + $res[] = [ 'id' => $val['_id']->__toString(), 'name' => $val['name'] ]; } - return Response()->json([ 'ecode' => 0, 'data' => $res ]); + return Response()->json([ 'ecode' => 0, 'data' => $res ]); } /** @@ -107,37 +99,33 @@ public function getDirTree(Request $request, $project_key) $dt = [ 'id' => '0', 'name' => '根目录' ]; $curdir = $request->input('currentdir'); - if (!$curdir) - { + if (!$curdir) { $curdir = '0'; } $pt = [ '0' ]; - if ($curdir !== '0') - { + if ($curdir !== '0') { $node = DB::collection('document_' . $project_key) ->where('_id', $curdir) - ->first(); + ->first(); - if ($node) - { - $pt = $node['pt']; - array_push($pt, $curdir); + if ($node) { + $pt = $node['pt']; + array_push($pt, $curdir); } } - foreach($pt as $val) - { + foreach ($pt as $val) { $sub_dirs = DB::collection('document_' . $project_key) ->where('parent', $val) - ->where('d', 1) - ->where('del_flag', '<>', 1) - ->get(); + ->where('d', 1) + ->where('del_flag', '<>', 1) + ->get(); - $this->addChildren2Tree($dt, $val, $sub_dirs); + $this->addChildren2Tree($dt, $val, $sub_dirs); } - return Response()->json([ 'ecode' => 0, 'data' => $dt ]); + return Response()->json([ 'ecode' => 0, 'data' => $dt ]); } /** @@ -151,26 +139,19 @@ public function getDirTree(Request $request, $project_key) public function addChildren2Tree(&$dt, $parent_id, $sub_dirs) { $new_dirs = []; - foreach($sub_dirs as $val) - { + foreach ($sub_dirs as $val) { $new_dirs[] = [ 'id' => $val['_id']->__toString(), 'name' => $val['name'] ]; } - if ($dt['id'] == $parent_id) - { + if ($dt['id'] == $parent_id) { $dt['children'] = $new_dirs; return true; - } - else - { - if (isset($dt['children']) && $dt['children']) - { + } else { + if (isset($dt['children']) && $dt['children']) { $children_num = count($dt['children']); - for ($i = 0; $i < $children_num; $i++) - { + for ($i = 0; $i < $children_num; $i++) { $res = $this->addChildren2Tree($dt['children'][$i], $parent_id, $sub_dirs); - if ($res === true) - { + if ($res === true) { return true; } } @@ -187,7 +168,7 @@ public function addChildren2Tree(&$dt, $parent_id, $sub_dirs) public function getOptions(Request $request, $project_key) { $uploaders = DB::collection('document_' . $project_key) - ->where('del_flag', '<>' , 1) + ->where('del_flag', '<>', 1) ->distinct('uploader') ->get([ 'uploader' ]); @@ -206,22 +187,19 @@ public function index(Request $request, $project_key, $directory) $query = DB::collection('document_' . $project_key); $uploader_id = $request->input('uploader_id'); - if (isset($uploader_id) && $uploader_id) - { + if (isset($uploader_id) && $uploader_id) { $mode = 'search'; $query->where('uploader.id', $uploader_id); } $name = $request->input('name'); - if (isset($name) && $name) - { + if (isset($name) && $name) { $mode = 'search'; $query = $query->where('name', 'like', '%' . $name . '%'); } $uploaded_at = $request->input('uploaded_at'); - if (isset($uploaded_at) && $uploaded_at) - { + if (isset($uploaded_at) && $uploaded_at) { $mode = 'search'; $unitMap = [ 'w' => 'week', 'm' => 'month', 'y' => 'year' ]; $unit = substr($uploaded_at, -1); @@ -229,14 +207,10 @@ public function index(Request $request, $project_key, $directory) $query->where('uploaded_at', '>=', strtotime(date('Ymd', strtotime('-' . $val . ' ' . $unitMap[$unit])))); } - if ($directory !== '0') - { + if ($directory !== '0') { $query = $query->where($mode === 'search' ? 'pt' : 'parent', $directory); - } - else - { - if ($mode === 'list') - { + } else { + if ($mode === 'list') { $query = $query->where('parent', $directory); } } @@ -249,31 +223,24 @@ public function index(Request $request, $project_key, $directory) $documents = $query->get(); $path = []; - if ($directory === '0') - { + if ($directory === '0') { $path[] = [ 'id' => '0', 'name' => 'root' ]; - } - else - { + } else { $path[] = [ 'id' => '0', 'name' => 'root' ]; $d = DB::collection('document_' . $project_key) ->where('_id', $directory) ->first(); - if ($d && isset($d['pt'])) - { + if ($d && isset($d['pt'])) { $parents = []; $ps = DB::collection('document_' . $project_key) ->whereIn('_id', $d['pt']) ->get([ 'name' ]); - foreach ($ps as $val) - { + foreach ($ps as $val) { $parents[$val['_id']->__toString()] = $val['name']; } - foreach ($d['pt'] as $pid) - { - if (isset($parents[$pid])) - { + foreach ($d['pt'] as $pid) { + if (isset($parents[$pid])) { $path[] = [ 'id' => $pid, 'name' => $parents[$pid] ]; } } @@ -296,28 +263,24 @@ public function createFolder(Request $request, $project_key) $insValues = []; $parent = $request->input('parent'); - if (!isset($parent)) - { + if (!isset($parent)) { throw new \UnexpectedValueException('the parent directory can not be empty.', -11905); } $insValues['parent'] = $parent; - if ($parent !== '0') - { + if ($parent !== '0') { $isExists = DB::collection('document_' . $project_key) ->where('_id', $parent) ->where('d', 1) ->where('del_flag', '<>', 1) ->exists(); - if (!$isExists) - { + if (!$isExists) { throw new \UnexpectedValueException('the parent directory does not exist.', -11906); } } $name = $request->input('name'); - if (!isset($name) || !$name) - { + if (!isset($name) || !$name) { throw new \UnexpectedValueException('the name can not be empty.', -11900); } $insValues['name'] = $name; @@ -328,8 +291,7 @@ public function createFolder(Request $request, $project_key) ->where('d', 1) ->where('del_flag', '<>', 1) ->exists(); - if ($isExists) - { + if ($isExists) { throw new \UnexpectedValueException('the name cannot be repeated.', -11901); } @@ -353,12 +315,9 @@ public function createFolder(Request $request, $project_key) public function getParentTree($project_key, $directory) { $pt = []; - if ($directory === '0') - { + if ($directory === '0') { $pt = [ '0' ]; - } - else - { + } else { $d = DB::collection('document_' . $project_key) ->where('_id', $directory) ->first(); @@ -378,8 +337,7 @@ public function getParentTree($project_key, $directory) public function update(Request $request, $project_key, $id) { $name = $request->input('name'); - if (!isset($name) || !$name) - { + if (!isset($name) || !$name) { throw new \UnexpectedValueException('the name can not be empty.', -11900); } @@ -387,46 +345,35 @@ public function update(Request $request, $project_key, $id) ->where('_id', $id) ->where('del_flag', '<>', 1) ->first(); - if (!$old_document) - { + if (!$old_document) { throw new \UnexpectedValueException('the object does not exist.', -11902); } - if (isset($old_document['d']) && $old_document['d'] === 1) - { - if (!$this->isPermissionAllowed($project_key, 'manage_project')) - { + if (isset($old_document['d']) && $old_document['d'] === 1) { + if (!$this->isPermissionAllowed($project_key, 'manage_project')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } - } - else - { - if (!$this->isPermissionAllowed($project_key, 'manage_project') && $old_document['uploader']['id'] !== $this->user->id) - { + } else { + if (!$this->isPermissionAllowed($project_key, 'manage_project') && $old_document['uploader']['id'] !== $this->user->id) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } } - if ($old_document['name'] !== $name) - { + if ($old_document['name'] !== $name) { $query = DB::collection('document_' . $project_key) ->where('parent', $old_document['parent']) ->where('name', $name) ->where('del_flag', '<>', 1); - if (isset($old_document['d']) && $old_document['d'] === 1) - { + if (isset($old_document['d']) && $old_document['d'] === 1) { $query->where('d', 1); - } - else - { + } else { $query->where('d', '<>', 1); } $isExists = $query->exists(); - if ($isExists) - { + if ($isExists) { throw new \UnexpectedValueException('the name cannot be repeated.', -11901); } } @@ -447,14 +394,12 @@ public function update(Request $request, $project_key, $id) public function move(Request $request, $project_key) { $id = $request->input('id'); - if (!isset($id) || !$id) - { + if (!isset($id) || !$id) { throw new \UnexpectedValueException('the move object can not be empty.', -11911); } $dest_path = $request->input('dest_path'); - if (!isset($dest_path)) - { + if (!isset($dest_path)) { throw new \UnexpectedValueException('the dest directory can not be empty.', -11912); } @@ -462,36 +407,28 @@ public function move(Request $request, $project_key) ->where('_id', $id) ->where('del_flag', '<>', 1) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the move object does not exist.', -11913); } - if (isset($document['d']) && $document['d'] === 1) - { - if (!$this->isPermissionAllowed($project_key, 'manage_project')) - { + if (isset($document['d']) && $document['d'] === 1) { + if (!$this->isPermissionAllowed($project_key, 'manage_project')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } - } - else - { - if (!$this->isPermissionAllowed($project_key, 'manage_project') && $document['uploader']['id'] !== $this->user->id) - { + } else { + if (!$this->isPermissionAllowed($project_key, 'manage_project') && $document['uploader']['id'] !== $this->user->id) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } } $dest_directory = []; - if ($dest_path !== '0') - { + if ($dest_path !== '0') { $dest_directory = DB::collection('document_' . $project_key) ->where('_id', $dest_path) ->where('d', 1) ->where('del_flag', '<>', 1) ->first(); - if (!$dest_directory) - { + if (!$dest_directory) { throw new \UnexpectedValueException('the dest directory does not exist.', -11914); } } @@ -502,8 +439,7 @@ public function move(Request $request, $project_key) ->where('d', isset($document['d']) && $document['d'] === 1 ? '=' : '<>', 1) ->where('del_flag', '<>', 1) ->exists(); - if ($isExists) - { + if ($isExists) { throw new \UnexpectedValueException('the name cannot be repeated.', -11901); } @@ -512,23 +448,20 @@ public function move(Request $request, $project_key) $updValues['pt'] = array_merge(isset($dest_directory['pt']) ? $dest_directory['pt'] : [], [$dest_path]); DB::collection('document_' . $project_key)->where('_id', $id)->update($updValues); - if (isset($document['d']) && $document['d'] === 1) - { + if (isset($document['d']) && $document['d'] === 1) { $subs = DB::collection('document_' . $project_key) ->where('pt', $id) ->where('del_flag', '<>', 1) ->get(); - foreach ($subs as $sub) - { - $pt = isset($sub['pt']) ? $sub['pt'] : []; - $pind = array_search($id, $pt); - if ($pind !== false) - { - $tail = array_slice($pt, $pind); - $pt = array_merge($updValues['pt'], $tail); - DB::collection('document_' . $project_key)->where('_id', $sub['_id']->__toString())->update(['pt' => $pt]); - } - } + foreach ($subs as $sub) { + $pt = isset($sub['pt']) ? $sub['pt'] : []; + $pind = array_search($id, $pt); + if ($pind !== false) { + $tail = array_slice($pt, $pind); + $pt = array_merge($updValues['pt'], $tail); + DB::collection('document_' . $project_key)->where('_id', $sub['_id']->__toString())->update(['pt' => $pt]); + } + } } $document = DB::collection('document_' . $project_key)->where('_id', $id)->first(); @@ -547,30 +480,23 @@ public function destroy($project_key, $id) $document = DB::collection('document_' . $project_key) ->where('_id', $id) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the object does not exist.', -11902); } - if (isset($document['d']) && $document['d'] === 1) - { - if (!$this->isPermissionAllowed($project_key, 'manage_project')) - { + if (isset($document['d']) && $document['d'] === 1) { + if (!$this->isPermissionAllowed($project_key, 'manage_project')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } - } - else - { - if (!$this->isPermissionAllowed($project_key, 'manage_project') && $document['uploader']['id'] !== $this->user->id) - { + } else { + if (!$this->isPermissionAllowed($project_key, 'manage_project') && $document['uploader']['id'] !== $this->user->id) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } } DB::collection('document_' . $project_key)->where('_id', $id)->update([ 'del_flag' => 1 ]); - if (isset($document['d']) && $document['d'] === 1) - { + if (isset($document['d']) && $document['d'] === 1) { DB::collection('document_' . $project_key)->whereRaw([ 'pt' => $id ])->update([ 'del_flag' => 1 ]); } @@ -589,35 +515,30 @@ public function upload(Request $request, $project_key, $directory) { set_time_limit(0); - if (!is_writable(config('filesystems.disks.local.root', '/tmp'))) - { + if (!is_writable(config('filesystems.disks.local.root', '/tmp'))) { throw new \UnexpectedValueException('the user has not the writable permission to the directory.', -15103); } - if ($directory !== '0') - { + if ($directory !== '0') { $isExists = DB::collection('document_' . $project_key) ->where('_id', $directory) ->where('d', 1) ->where('del_flag', '<>', 1) ->exists(); - if (!$isExists) - { + if (!$isExists) { throw new \UnexpectedValueException('the parent directory does not exist.', -11905); } } $fields = array_keys($_FILES); $field = array_pop($fields); - if (empty($_FILES) || $_FILES[$field]['error'] > 0) - { + if (empty($_FILES) || $_FILES[$field]['error'] > 0) { throw new \UnexpectedValueException('upload file errors.', -11903); } $basename = md5(microtime() . $_FILES[$field]['name']); $sub_save_path = config('filesystems.disks.local.root', '/tmp') . '/' . substr($basename, 0, 2) . '/'; - if (!is_dir($sub_save_path)) - { + if (!is_dir($sub_save_path)) { @mkdir($sub_save_path); } @@ -627,41 +548,32 @@ public function upload(Request $request, $project_key, $directory) $data = []; $thumbnail_size = 190; - if (in_array($_FILES[$field]['type'], [ 'image/jpeg', 'image/jpg', 'image/png', 'image/gif' ])) - { + if (in_array($_FILES[$field]['type'], [ 'image/jpeg', 'image/jpg', 'image/png', 'image/gif' ])) { $size = getimagesize($filename); - $width = $size[0]; $height = $size[1]; + $width = $size[0]; + $height = $size[1]; $scale = $width < $height ? $height : $width; $thumbnails_width = floor($thumbnail_size * $width / $scale); $thumbnails_height = floor($thumbnail_size * $height / $scale); $thumbnails_filename = $filename . '_thumbnails'; - if ($scale <= $thumbnail_size) - { + if ($scale <= $thumbnail_size) { @copy($filename, $thumbnails_filename); - } - else if ($_FILES[$field]['type'] == 'image/jpeg' || $_FILES[$field]['type'] == 'image/jpg') - { + } elseif ($_FILES[$field]['type'] == 'image/jpeg' || $_FILES[$field]['type'] == 'image/jpg') { $src_image = imagecreatefromjpeg($filename); $dst_image = imagecreatetruecolor($thumbnails_width, $thumbnails_height); imagecopyresized($dst_image, $src_image, 0, 0, 0, 0, $thumbnails_width, $thumbnails_height, $width, $height); imagejpeg($dst_image, $thumbnails_filename); - } - else if ($_FILES[$field]['type'] == 'image/png') - { + } elseif ($_FILES[$field]['type'] == 'image/png') { $src_image = imagecreatefrompng($filename); $dst_image = imagecreatetruecolor($thumbnails_width, $thumbnails_height); imagecopyresized($dst_image, $src_image, 0, 0, 0, 0, $thumbnails_width, $thumbnails_height, $width, $height); imagepng($dst_image, $thumbnails_filename); - } - else if ($_FILES[$field]['type'] == 'image/gif') - { + } elseif ($_FILES[$field]['type'] == 'image/gif') { $src_image = imagecreatefromgif($filename); $dst_image = imagecreatetruecolor($thumbnails_width, $thumbnails_height); imagecopyresized($dst_image, $src_image, 0, 0, 0, 0, $thumbnails_width, $thumbnails_height, $width, $height); imagegif($dst_image, $thumbnails_filename); - } - else - { + } else { @copy($filename, $thumbnails_filename); } $data['thumbnails_index'] = $basename . '_thumbnails'; @@ -672,22 +584,19 @@ public function upload(Request $request, $project_key, $directory) $fname = $_FILES[$field]['name']; $extname = ''; $segments = explode('.', $fname); - if (count($segments) > 1) - { + if (count($segments) > 1) { $extname = '.' . array_pop($segments); $fname = implode('.', $segments); } $i = 1; - while(true) - { + while (true) { $isExists = DB::collection('document_' . $project_key) ->where('parent', $directory) ->where('name', $fname . ($i < 2 ? '' : ('(' . $i . ')')) . $extname) ->where('d', '<>', 1) ->where('del_flag', '<>', 1) ->exists(); - if (!$isExists) - { + if (!$isExists) { break; } $i++; @@ -724,15 +633,13 @@ public function downloadThumbnails(Request $request, $project_key, $id) $document = DB::collection('document_' . $project_key) ->where('_id', $id) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the object does not exist.', -11902); } $filepath = config('filesystems.disks.local.root', '/tmp') . '/' . substr($document['index'], 0, 2); $filename = $filepath . '/' . $document['thumbnails_index']; - if (!file_exists($filename)) - { + if (!file_exists($filename)) { throw new \UnexpectedValueException('file does not exist.', -11904); } @@ -754,17 +661,13 @@ public function download(Request $request, $project_key, $id) $document = DB::collection('document_' . $project_key) ->where('_id', $id) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the object does not exist.', -11902); } - if (isset($document['d']) && $document['d'] === 1) - { + if (isset($document['d']) && $document['d'] === 1) { $this->downloadFolder($project_key, $document['name'], $id); - } - else - { + } else { $this->downloadFile($document['name'], $document['index']); } } @@ -778,7 +681,7 @@ public function download(Request $request, $project_key, $id) */ public function downloadFolder($project_key, $name, $directory) { - setlocale(LC_ALL, 'zh_CN.UTF-8'); + setlocale(LC_ALL, 'zh_CN.UTF-8'); $basepath = '/tmp/' . md5($this->user->id . microtime()); @mkdir($basepath); @@ -810,18 +713,13 @@ public function contructFolder($project_key, $fullpath, $id) ->where('parent', $id) ->where('del_flag', '<>', 1) ->get(); - foreach ($documents as $doc) - { - if (isset($doc['d']) && $doc['d'] === 1) - { + foreach ($documents as $doc) { + if (isset($doc['d']) && $doc['d'] === 1) { $this->contructFolder($project_key, $fullpath . '/' . $doc['name'], $doc['_id']->__toString()); - } - else - { + } else { $filepath = config('filesystems.disks.local.root', '/tmp') . '/' . substr($doc['index'], 0, 2); $filename = $filepath . '/' . $doc['index']; - if (file_exists($filename)) - { + if (file_exists($filename)) { @copy($filename, $fullpath . '/' . $doc['name']); } } @@ -839,8 +737,7 @@ public function downloadFile($name, $index) { $filepath = config('filesystems.disks.local.root', '/tmp') . '/' . substr($index, 0, 2); $filename = $filepath . '/' . $index; - if (!file_exists($filename)) - { + if (!file_exists($filename)) { throw new \UnexpectedValueException('file does not exist.', -11904); } diff --git a/app/Http/Controllers/EpicController.php b/app/Http/Controllers/EpicController.php index 7c80e27f1..fb551a0f5 100644 --- a/app/Http/Controllers/EpicController.php +++ b/app/Http/Controllers/EpicController.php @@ -35,16 +35,14 @@ public function index(Request $request, $project_key) $columns = isset($board->columns) ? $board->columns : []; $all_states = []; - foreach ($columns as $column) - { + foreach ($columns as $column) { $all_states = array_merge($all_states, isset($column['states']) ? $column['states'] : []); } $last_column = array_pop($columns); $completed_states = isset($last_column['states']) ? $last_column['states'] : []; $epics = Epic::where([ 'project_key' => $project_key ])->orderBy('sn', 'asc')->get(); - foreach ($epics as $epic) - { + foreach ($epics as $epic) { $epic->is_used = $this->isFieldUsedByIssue($project_key, 'epic', $epic->toArray()); $completed_issue_cnt = $incompleted_issue_cnt = $inestimable_issue_cnt = 0; @@ -53,18 +51,12 @@ public function index(Request $request, $project_key) ->where('epic', $epic->id) ->where('del_flg', '<>', 1) ->get(['state']); - foreach ($issues as $issue) - { - if (in_array($issue['state'], $completed_states)) - { + foreach ($issues as $issue) { + if (in_array($issue['state'], $completed_states)) { $completed_issue_cnt++; - } - else if (in_array($issue['state'], $all_states)) - { + } elseif (in_array($issue['state'], $all_states)) { $incompleted_issue_cnt++; - } - else - { + } else { $inestimable_issue_cnt++; } } @@ -85,19 +77,16 @@ public function index(Request $request, $project_key) public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -11800); } $bgColor = $request->input('bgColor'); - if (!$bgColor) - { + if (!$bgColor) { throw new \UnexpectedValueException('the bgColor can not be empty.', -11801); } - if (Provider::isEpicExisted($project_key, $name)) - { + if (Provider::isEpicExisted($project_key, $name)) { throw new \UnexpectedValueException('epic name cannot be repeated', -11802); } @@ -129,31 +118,25 @@ public function show($project_key, $id) public function update(Request $request, $project_key, $id) { $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -11800); } } $bgColor = $request->input('bgColor'); - if (isset($bgColor)) - { - if (!$bgColor) - { + if (isset($bgColor)) { + if (!$bgColor) { throw new \UnexpectedValueException('the bgColor can not be empty.', -11801); } } $epic = Epic::find($id); - if (!$epic || $project_key != $epic->project_key) - { + if (!$epic || $project_key != $epic->project_key) { throw new \UnexpectedValueException('the epic does not exist or is not in the project.', -11803); } - if ($epic->name !== $name && Provider::isEpicExisted($project_key, $name)) - { + if ($epic->name !== $name && Provider::isEpicExisted($project_key, $name)) { throw new \UnexpectedValueException('epic name cannot be repeated', -11802); } @@ -172,14 +155,11 @@ public function handle(Request $request, $project_key) { // set epic sort. $sequence_epics = $request->input('sequence'); - if (isset($sequence_epics)) - { + if (isset($sequence_epics)) { $i = 1; - foreach ($sequence_epics as $epic_id) - { + foreach ($sequence_epics as $epic_id) { $epic = Epic::find($epic_id); - if (!$epic || $epic->project_key != $project_key) - { + if (!$epic || $epic->project_key != $project_key) { continue; } $epic->sn = $i++; @@ -200,42 +180,31 @@ public function handle(Request $request, $project_key) public function delete(Request $request, $project_key, $id) { $epic = Epic::find($id); - if (!$epic || $project_key != $epic->project_key) - { + if (!$epic || $project_key != $epic->project_key) { throw new \UnexpectedValueException('the epic does not exist or is not in the project.', -11803); } $operate_flg = $request->input('operate_flg'); - if (!isset($operate_flg) || $operate_flg === '0') - { + if (!isset($operate_flg) || $operate_flg === '0') { $is_used = $this->isFieldUsedByIssue($project_key, 'epic', $epic->toArray()); - if ($is_used) - { + if ($is_used) { throw new \UnexpectedValueException('the epic has been used by some issues.', -11804); } - } - else if ($operate_flg === '1') - { + } elseif ($operate_flg === '1') { $swap_epic = $request->input('swap_epic'); - if (!isset($swap_epic) || !$swap_epic) - { + if (!isset($swap_epic) || !$swap_epic) { throw new \UnexpectedValueException('the swap epic cannot be empty.', -11806); } $sepic = Epic::find($swap_epic); - if (!$sepic || $project_key != $sepic->project_key) - { + if (!$sepic || $project_key != $sepic->project_key) { throw new \UnexpectedValueException('the swap epic does not exist or is not in the project.', -11807); } $this->updIssueEpic($project_key, $id, $swap_epic); - } - else if ($operate_flg === '2') - { + } elseif ($operate_flg === '2') { $this->updIssueEpic($project_key, $id, ''); - } - else - { + } else { throw new \UnexpectedValueException('the operation has error.', -11805); } @@ -268,8 +237,7 @@ public function updIssueEpic($project_key, $source, $dest) ->where('del_flg', '<>', 1) ->get(); - foreach ($issues as $issue) - { + foreach ($issues as $issue) { $updValues = []; $updValues['epic'] = $dest; diff --git a/app/Http/Controllers/EventsController.php b/app/Http/Controllers/EventsController.php index fc4273d30..6106d43d8 100644 --- a/app/Http/Controllers/EventsController.php +++ b/app/Http/Controllers/EventsController.php @@ -20,27 +20,22 @@ class EventsController extends Controller public function index($project_key) { $events = Provider::getEventList($project_key); - foreach ($events as $key => $event) - { + foreach ($events as $key => $event) { $event->notifications = $this->getNotifications($project_key, $event['_id']); } - $roles = Provider::getRoleList($project_key, ['name']); + $roles = Provider::getRoleList($project_key, ['name']); $users = Provider::getUserList($project_key); $single_user_fields = []; $multi_user_fields = []; $fields = Provider::getFieldList($project_key); - foreach ($fields as $field) - { - if ($field->type === 'SingleUser') - { + foreach ($fields as $field) { + if ($field->type === 'SingleUser') { $single_user_fields[] = [ 'id' => $field->key, 'name' => $field->name ]; - } - else if ($field->type === 'MultiUser') - { + } elseif ($field->type === 'MultiUser') { $multi_user_fields[] = [ 'id' => $field->key, 'name' => $field->name ]; - } + } } return Response()->json(['ecode' => 0, 'data' => $events, 'options' => [ 'roles' => $roles, 'users' => $users, 'single_user_fields' => $single_user_fields, 'multi_user_fields' => $multi_user_fields ]]); @@ -55,13 +50,11 @@ public function index($project_key) public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12800); } - if (Provider::isEventExisted($project_key, $name)) - { + if (Provider::isEventExisted($project_key, $name)) { throw new \UnexpectedValueException('event name cannot be repeated', -12801); } @@ -91,20 +84,16 @@ public function show($project_key, $id) public function update(Request $request, $project_key, $id) { $event = Events::find($id); - if (!$event || $project_key != $event->project_key) - { + if (!$event || $project_key != $event->project_key) { throw new \UnexpectedValueException('the event does not exist or is not in the project.', -12802); } $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12800); } - if ($event->name !== $name && Provider::isEventExisted($project_key, $name)) - { + if ($event->name !== $name && Provider::isEventExisted($project_key, $name)) { throw new \UnexpectedValueException('event name cannot be repeated', -12801); } } @@ -125,8 +114,7 @@ public function update(Request $request, $project_key, $id) public function destroy($project_key, $id) { $event = Events::find($id); - if (!$event || $project_key != $event->project_key) - { + if (!$event || $project_key != $event->project_key) { throw new \UnexpectedValueException('the event does not exist or is not in the project.', -12802); } @@ -147,14 +135,12 @@ public function destroy($project_key, $id) public function setNotify(Request $request, $project_key, $id) { $event = Events::find($id); - if (!$event || ($event->project_key != '$_sys_$' && $project_key != $event->project_key)) - { + if (!$event || ($event->project_key != '$_sys_$' && $project_key != $event->project_key)) { throw new \UnexpectedValueException('the event does not exist or is not in the project.', -12802); } $notifications = $request->input('notifications'); - if (isset($notifications)) - { + if (isset($notifications)) { $en = EventNotifications::where([ 'project_key' => $project_key, 'event_id' => $id ])->first(); $en && $en->delete(); @@ -166,17 +152,16 @@ public function setNotify(Request $request, $project_key, $id) } /** - * get notifications by project_key and eventid. + * get notifications by project_key and eventid. * * @param string $project_key * @param string $event_id - * @return array + * @return array */ public function getNotifications($project_key, $event_id) { $en = EventNotifications::where([ 'project_key' => $project_key, 'event_id' => $event_id ])->first(); - if (!$en && $project_key !== '$_sys_$') - { + if (!$en && $project_key !== '$_sys_$') { $en = EventNotifications::where([ 'project_key' => '$_sys_$', 'event_id' => $event_id ])->first(); } return $en && isset($en->notifications) ? $en->notifications : []; diff --git a/app/Http/Controllers/ExcelTrait.php b/app/Http/Controllers/ExcelTrait.php index a09844b5b..79935a350 100644 --- a/app/Http/Controllers/ExcelTrait.php +++ b/app/Http/Controllers/ExcelTrait.php @@ -12,24 +12,25 @@ trait ExcelTrait */ public function trimExcel($data) { - if (!is_array($data)) - { + if (!is_array($data)) { return []; } // trim the cell value - foreach($data as $k1 => $val) - { - foreach($val as $k2 => $val2) - { + foreach ($data as $k1 => $val) { + foreach ($val as $k2 => $val2) { $data[$k1][$k2] = trim($val2); } } // delete the empty row - $data = array_filter($data, function($v) { return array_filter($v); }); + $data = array_filter($data, function ($v) { + return array_filter($v); + }); // delete the empty column - $data = array_filter($this->rotate($data), function($v) { return array_filter($v); }); + $data = array_filter($this->rotate($data), function ($v) { + return array_filter($v); + }); // rotate the array $data = $this->rotate($data); @@ -37,7 +38,7 @@ public function trimExcel($data) } /** - * arrange the data + * arrange the data * * @param array $data * @param array $fields @@ -48,55 +49,44 @@ public function arrangeExcel($data, $fields) $data = $this->trimExcel($data); $header_index = 0; - while(true) - { + while (true) { $header = array_shift($data); - if (!$header) - { + if (!$header) { throw new \UnexpectedValueException('表头定位错误。', -11142); } - if (is_array($header)) - { - if (in_array($header[0], $fields)) - { + if (is_array($header)) { + if (in_array($header[0], $fields)) { break; } - if (++$header_index > 5) - { + if (++$header_index > 5) { throw new \UnexpectedValueException('表头定位错误。', -11142); } } } // the first row is used for the issue keys - if (array_search('', $header) !== false) - { + if (array_search('', $header) !== false) { throw new \UnexpectedValueException('表头不能有空值。', -11143); } // check the header title - if (count($header) !== count(array_unique($header))) - { + if (count($header) !== count(array_unique($header))) { throw new \UnexpectedValueException('表头不能有重复列。', -11144); } $field_keys = []; - foreach($header as $field) - { + foreach ($header as $field) { $tmp = array_search($field, $fields); - if ($tmp === false) - { + if ($tmp === false) { throw new \UnexpectedValueException('表头有不明确列。', -11145); } $field_keys[] = $tmp; } $new_data = []; - foreach ($data as $item) - { + foreach ($data as $item) { $tmp = []; - foreach ($item as $key => $val) - { + foreach ($item as $key => $val) { $tmp[$field_keys[$key]] = $val; } $new_data[] = $tmp; @@ -106,7 +96,7 @@ public function arrangeExcel($data, $fields) } /** - * rotate the matrix + * rotate the matrix * * @param array $matrix * @return array @@ -114,10 +104,8 @@ public function arrangeExcel($data, $fields) public function rotate(array $matrix) { $ret = []; - foreach($matrix as $val) - { - foreach($val as $k => $val2) - { + foreach ($matrix as $val) { + foreach ($val as $k => $val2) { $ret[$k][] = $val2; } } diff --git a/app/Http/Controllers/ExternalUsersController.php b/app/Http/Controllers/ExternalUsersController.php index ba7956c9f..cc133281a 100644 --- a/app/Http/Controllers/ExternalUsersController.php +++ b/app/Http/Controllers/ExternalUsersController.php @@ -34,28 +34,23 @@ public function handle(Request $request, $project_key) $data = []; $user = $request->input('user'); - if (!isset($user) || !$user) - { + if (!isset($user) || !$user) { throw new \UnexpectedValueException('the user cannot be empty.', -16000); } $data['user'] = $user; $mode = $request->input('mode'); - if (!isset($mode) || !$mode) - { + if (!isset($mode) || !$mode) { throw new \UnexpectedValueException('the mode cannot be empty.', -16001); } - if (!in_array($mode, [ 'use', 'resetPwd', 'enable', 'disable' ])) - { + if (!in_array($mode, [ 'use', 'resetPwd', 'enable', 'disable' ])) { throw new \UnexpectedValueException('the mode value has error.', -16002); } $data['status'] = $mode == 'disable' ? 'disabled' : 'enabled'; - if ($mode == 'use' || $mode == 'resetPwd') - { + if ($mode == 'use' || $mode == 'resetPwd') { $pwd = $request->input('pwd'); - if (!isset($pwd) || !$pwd) - { + if (!isset($pwd) || !$pwd) { throw new \UnexpectedValueException('the password cannot be empty.', -16003); } $data['pwd'] = $pwd; @@ -66,8 +61,7 @@ public function handle(Request $request, $project_key) $external_user = ExternalUsers::where('project_key', $project_key) ->where('user', $user) ->first(); - if (!$external_user) - { + if (!$external_user) { $external_user = new ExternalUsers; } diff --git a/app/Http/Controllers/FieldController.php b/app/Http/Controllers/FieldController.php index 4374f8921..407365e35 100644 --- a/app/Http/Controllers/FieldController.php +++ b/app/Http/Controllers/FieldController.php @@ -19,32 +19,32 @@ class FieldController extends Controller { private $special_fields = [ - 'id', - 'type', - 'state', - 'reporter', - 'modifier', - 'created_at', - 'updated_at', - 'resolved_at', - 'closed_at', - 'regression_times', + 'id', + 'type', + 'state', + 'reporter', + 'modifier', + 'created_at', + 'updated_at', + 'resolved_at', + 'closed_at', + 'regression_times', 'his_resolvers', 'resolved_logs', - 'no', - 'schema', - 'parent_id', - 'parent', - 'links', - 'subtasks', - 'entry_id', - 'definition_id', - 'comments_num', - 'worklogs_num', - 'gitcommits_num', - 'sprint', - 'sprints', - 'filter', + 'no', + 'schema', + 'parent_id', + 'parent', + 'links', + 'subtasks', + 'entry_id', + 'definition_id', + 'comments_num', + 'worklogs_num', + 'gitcommits_num', + 'sprint', + 'sprints', + 'filter', 'from', 'from_kanban_id', 'limit', @@ -76,23 +76,23 @@ class FieldController extends Controller ]; private $all_types = [ - 'Tags', - 'Integer', - 'Number', - 'Text', - 'TextArea', - 'Select', - 'MultiSelect', - 'RadioGroup', - 'CheckboxGroup', - 'DatePicker', - 'DateTimePicker', - 'TimeTracking', - 'File', - 'SingleVersion', - 'MultiVersion', - 'SingleUser', - 'MultiUser', + 'Tags', + 'Integer', + 'Number', + 'Text', + 'TextArea', + 'Select', + 'MultiSelect', + 'RadioGroup', + 'CheckboxGroup', + 'DatePicker', + 'DateTimePicker', + 'TimeTracking', + 'File', + 'SingleVersion', + 'MultiVersion', + 'SingleUser', + 'MultiUser', 'Url' ]; /** @@ -103,8 +103,7 @@ class FieldController extends Controller public function index($project_key) { $fields = Provider::getFieldList($project_key); - foreach ($fields as $field) - { + foreach ($fields as $field) { $field->screens = Screen::whereRaw([ 'field_ids' => $field->id ]) ->orderBy('project_key', 'asc') ->get(['project_key', 'name']) @@ -112,7 +111,7 @@ public function index($project_key) $field->is_used = !!($field->screens); - $field->screens = array_filter($field->screens, function($item) use($project_key) { + $field->screens = array_filter($field->screens, function ($item) use ($project_key) { return $item['project_key'] === $project_key || $item['project_key'] === '$_sys_$'; }); } @@ -129,79 +128,62 @@ public function index($project_key) public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name cannot be empty.', -12200); } $key = $request->input('key'); - if (!$key) - { + if (!$key) { throw new \InvalidArgumentException('field key cannot be empty.', -12201); } - if (in_array($key, $this->special_fields)) - { + if (in_array($key, $this->special_fields)) { throw new \InvalidArgumentException('field key has been used by system.', -12202); } - if (Provider::isFieldKeyExisted($project_key, $key)) - { + if (Provider::isFieldKeyExisted($project_key, $key)) { throw new \InvalidArgumentException('field key cannot be repeated.', -12203); } $type = $request->input('type'); - if (!$type) - { + if (!$type) { throw new \UnexpectedValueException('the type cannot be empty.', -12204); } - if ($type === 'TimeTracking' && Provider::isFieldKeyExisted($project_key, $key . '_m')) - { + if ($type === 'TimeTracking' && Provider::isFieldKeyExisted($project_key, $key . '_m')) { throw new \InvalidArgumentException('field key cannot be repeated.', -12203); } - if ($type === 'MultiUser' && Provider::isFieldKeyExisted($project_key, $key . '_ids')) - { + if ($type === 'MultiUser' && Provider::isFieldKeyExisted($project_key, $key . '_ids')) { throw new \UnexpectedValueException('the type cannot be empty.', -12204); } - if (!in_array($type, $this->all_types)) - { + if (!in_array($type, $this->all_types)) { throw new \UnexpectedValueException('the type is incorrect type.', -12205); } $optionTypes = [ 'Select', 'MultiSelect', 'RadioGroup', 'CheckboxGroup' ]; - if (in_array($type, $optionTypes)) - { + if (in_array($type, $optionTypes)) { $optionValues = $request->input('optionValues') ?: []; - foreach ($optionValues as $key => $val) - { - if (!isset($val['name']) || !$val['name']) - { + foreach ($optionValues as $key => $val) { + if (!isset($val['name']) || !$val['name']) { continue; } $optionValues[$key]['id'] = md5(microtime() . $val['name']); } $defaultValue = $request->input('defaultValue') ?: ''; - if ($defaultValue) - { + if ($defaultValue) { $defaults = is_array($defaultValue) ? $defaultValue : explode(',', $defaultValue); $options = array_column($optionValues, 'id'); - if ('MultiSelect' === $type || 'CheckboxGroup' === $type) - { + if ('MultiSelect' === $type || 'CheckboxGroup' === $type) { $defaultValue = array_values(array_intersect($defaults, $options)); - } - else - { + } else { $defaultValue = implode(',', array_intersect($defaults, $options)); } } $field = Field::create([ 'project_key' => $project_key, 'optionValues' => $optionValues, 'defaultValue' => $defaultValue ] + $request->all()); - } - else - { + } else { $field = Field::create([ 'project_key' => $project_key ] + $request->all()); } return Response()->json(['ecode' => 0, 'data' => $field]); @@ -236,55 +218,41 @@ public function show($project_key, $id) public function update(Request $request, $project_key, $id) { $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12200); } } $field = Field::find($id); - if (!$field || $project_key != $field->project_key) - { + if (!$field || $project_key != $field->project_key) { throw new \UnexpectedValueException('the field does not exist or is not in the project.', -12206); } $updValues = []; $optionTypes = [ 'Select', 'MultiSelect', 'RadioGroup', 'CheckboxGroup' ]; - if (in_array($field->type, $optionTypes)) - { + if (in_array($field->type, $optionTypes)) { $optionValues = $request->input('optionValues'); $defaultValue = $request->input('defaultValue'); - if (isset($optionValues) || isset($defaultValue)) - { - if (isset($optionValues)) - { - if (isset($field->optionValues) && $field->optionValues) - { + if (isset($optionValues) || isset($defaultValue)) { + if (isset($optionValues)) { + if (isset($field->optionValues) && $field->optionValues) { $old_option_ids = array_column($field->optionValues, 'id'); - } - else - { + } else { $old_option_ids = []; } - foreach ($optionValues as $key => $val) - { - if (!isset($val['name']) || !$val['name']) - { + foreach ($optionValues as $key => $val) { + if (!isset($val['name']) || !$val['name']) { continue; } - if (!isset($val['id']) || !in_array($val['id'], $old_option_ids)) - { + if (!isset($val['id']) || !in_array($val['id'], $old_option_ids)) { $optionValues[$key]['id'] = md5(microtime() . $val['name']); } } - } - else - { + } else { $optionValues = $field->optionValues ?: []; } $updValues['optionValues'] = $optionValues; @@ -292,12 +260,9 @@ public function update(Request $request, $project_key, $id) $options = array_column($optionValues, 'id'); $defaultValue = isset($defaultValue) ? $defaultValue : ($field->defaultValue ?: ''); $defaults = is_array($defaultValue) ? $defaultValue : explode(',', $defaultValue); - if ('MultiSelect' === $field->type || 'CheckboxGroup' === $field->type) - { + if ('MultiSelect' === $field->type || 'CheckboxGroup' === $field->type) { $defaultValue = array_values(array_intersect($defaults, $options)); - } - else - { + } else { $defaultValue = implode(',', array_intersect($defaults, $options)); } $updValues['defaultValue'] = $defaultValue; @@ -305,27 +270,22 @@ public function update(Request $request, $project_key, $id) } $mmTypes = [ 'Number', 'Integer' ]; - if (in_array($field->type, $mmTypes)) - { + if (in_array($field->type, $mmTypes)) { $maxValue = $request->input('maxValue'); - if (isset($maxValue)) - { + if (isset($maxValue)) { $updValues['maxValue'] = ($maxValue === '' ? '' : ($maxValue + 0)); } $minValue = $request->input('minValue'); - if (isset($minValue)) - { + if (isset($minValue)) { $updValues['minValue'] = ($minValue === '' ? '' : ($minValue + 0)); } } $mlTypes = [ 'Text', 'TextArea' ]; - if (in_array($field->type, $mlTypes)) - { + if (in_array($field->type, $mlTypes)) { $maxLength = $request->input('maxLength'); - if (isset($maxLength)) - { + if (isset($maxLength)) { $updValues['maxLength'] = ($maxLength === '' ? '' : intval($maxLength)); } } @@ -346,19 +306,16 @@ public function update(Request $request, $project_key, $id) public function destroy($project_key, $id) { $field = Field::find($id); - if (!$field || $project_key != $field->project_key) - { + if (!$field || $project_key != $field->project_key) { throw new \UnexpectedValueException('the field does not exist or is not in the project.', -12206); } - if (in_array($field->key, $this->sys_fields)) - { + if (in_array($field->key, $this->sys_fields)) { throw new \UnexpectedValueException('the field is built in the system.', -12208); } $isUsed = Screen::whereRaw([ 'field_ids' => $id ])->exists(); - if ($isUsed) - { + if ($isUsed) { throw new \UnexpectedValueException('the field has been used in screen.', -12207); } @@ -375,23 +332,20 @@ public function destroy($project_key, $id) */ public function viewUsedInProject($project_key, $id) { - if ($project_key !== '$_sys_$') - { + if ($project_key !== '$_sys_$') { return Response()->json(['ecode' => 0, 'data' => [] ]); } $res = []; $projects = Project::all(); - foreach($projects as $project) - { + foreach ($projects as $project) { $screens = Screen::where('field_ids', $id) ->where('project_key', '<>', '$_sys_$') ->where('project_key', $project->key) ->get([ 'id', 'name' ]) ->toArray(); - if ($screens) - { + if ($screens) { $res[] = [ 'key' => $project->key, 'name' => $project->name, 'status' => $project->status, 'screens' => $screens ]; } } diff --git a/app/Http/Controllers/FileController.php b/app/Http/Controllers/FileController.php index ca2158f2b..d137ded80 100644 --- a/app/Http/Controllers/FileController.php +++ b/app/Http/Controllers/FileController.php @@ -24,24 +24,21 @@ public function upload(Request $request, $project_key) { set_time_limit(0); - if (!is_writable(config('filesystems.disks.local.root', '/tmp'))) - { + if (!is_writable(config('filesystems.disks.local.root', '/tmp'))) { throw new \UnexpectedValueException('the user has not the writable permission to the directory.', -15103); } $thumbnail_size = 190; - $fields = array_keys($_FILES); + $fields = array_keys($_FILES); $field = array_pop($fields); - if (empty($_FILES) || $_FILES[$field]['error'] > 0) - { + if (empty($_FILES) || $_FILES[$field]['error'] > 0) { throw new \UnexpectedValueException('upload file errors.', -15101); } $basename = md5(microtime() . $_FILES[$field]['name']); $sub_save_path = config('filesystems.disks.local.root', '/tmp') . '/' . substr($basename, 0, 2) . '/'; - if (!is_dir($sub_save_path)) - { + if (!is_dir($sub_save_path)) { @mkdir($sub_save_path); } $filename = '/tmp/' . $basename; @@ -50,42 +47,33 @@ public function upload(Request $request, $project_key) $data['name'] = $_FILES[$field]['name']; $data['size'] = $_FILES[$field]['size']; $data['type'] = $_FILES[$field]['type']; - $data['index'] = $basename; - if (in_array($_FILES[$field]['type'], [ 'image/jpeg', 'image/jpg', 'image/png', 'image/gif' ])) - { + $data['index'] = $basename; + if (in_array($_FILES[$field]['type'], [ 'image/jpeg', 'image/jpg', 'image/png', 'image/gif' ])) { $size = getimagesize($filename); - $width = $size[0]; $height = $size[1]; + $width = $size[0]; + $height = $size[1]; $scale = $width < $height ? $height : $width; $thumbnails_width = floor($thumbnail_size * $width / $scale); $thumbnails_height = floor($thumbnail_size * $height / $scale); $thumbnails_filename = $filename . '_thumbnails'; - if ($scale <= $thumbnail_size) - { + if ($scale <= $thumbnail_size) { @copy($filename, $thumbnails_filename); - } - else if ($_FILES[$field]['type'] == 'image/jpeg' || $_FILES[$field]['type'] == 'image/jpg') - { + } elseif ($_FILES[$field]['type'] == 'image/jpeg' || $_FILES[$field]['type'] == 'image/jpg') { $src_image = imagecreatefromjpeg($filename); $dst_image = imagecreatetruecolor($thumbnails_width, $thumbnails_height); imagecopyresized($dst_image, $src_image, 0, 0, 0, 0, $thumbnails_width, $thumbnails_height, $width, $height); imagejpeg($dst_image, $thumbnails_filename); - } - else if ($_FILES[$field]['type'] == 'image/png') - { + } elseif ($_FILES[$field]['type'] == 'image/png') { $src_image = imagecreatefrompng($filename); $dst_image = imagecreatetruecolor($thumbnails_width, $thumbnails_height); imagecopyresized($dst_image, $src_image, 0, 0, 0, 0, $thumbnails_width, $thumbnails_height, $width, $height); imagepng($dst_image, $thumbnails_filename); - } - else if ($_FILES[$field]['type'] == 'image/gif') - { + } elseif ($_FILES[$field]['type'] == 'image/gif') { $src_image = imagecreatefromgif($filename); $dst_image = imagecreatetruecolor($thumbnails_width, $thumbnails_height); imagecopyresized($dst_image, $src_image, 0, 0, 0, 0, $thumbnails_width, $thumbnails_height, $width, $height); imagegif($dst_image, $thumbnails_filename); - } - else - { + } else { @copy($filename, $thumbnails_filename); } $data['thumbnails_index'] = $basename . '_thumbnails'; @@ -98,8 +86,7 @@ public function upload(Request $request, $project_key) $file = File::create($data); $issue_id = $request->input('issue_id'); - if (isset($issue_id) && $issue_id) - { + if (isset($issue_id) && $issue_id) { Event::fire(new FileUploadEvent($project_key, $issue_id, $field, $file->id, $data['uploader'])); } @@ -118,8 +105,7 @@ public function downloadThumbnail(Request $request, $project_key, $id) $filepath = config('filesystems.disks.local.root', '/tmp') . '/' . substr($file->index, 0, 2); $filename = $filepath . '/' . $file->thumbnails_index; - if (!file_exists($filename)) - { + if (!file_exists($filename)) { throw new \UnexpectedValueException('file does not exist.', -15100); } @@ -136,16 +122,14 @@ public function download(Request $request, $project_key, $id) { set_time_limit(0); - $file = File::find($id); - if (!$file || $file->del_flg == 1) - { + $file = File::find($id); + if (!$file || $file->del_flg == 1) { throw new \UnexpectedValueException('file does not exist.', -15100); } $filepath = config('filesystems.disks.local.root', '/tmp') . '/' . substr($file->index, 0, 2); $filename = $filepath . '/' . $file->index; - if (!file_exists($filename)) - { + if (!file_exists($filename)) { throw new \UnexpectedValueException('file does not exist.', -15100); } @@ -160,14 +144,12 @@ public function download(Request $request, $project_key, $id) public function getAvatar(Request $request) { $fid = $request->input('fid'); - if (!isset($fid) || !$fid) - { + if (!isset($fid) || !$fid) { throw new \UnexpectedValueException('the avatar file id cannot empty.', -15100); } $filename = config('filesystems.disks.local.root', '/tmp') . '/avatar/' . $fid; - if (!file_exists($filename)) - { + if (!file_exists($filename)) { throw new \UnexpectedValueException('the avatar file does not exist.', -15100); } @@ -190,32 +172,26 @@ public function delete(Request $request, $project_key, $id) // throw new \UnexpectedValueException('file does not exist.', -15100); //} - if ($file && !$this->isPermissionAllowed($project_key, 'remove_file') && !($this->isPermissionAllowed($project_key, 'remove_self_file') && $file->uploader['id'] == $this->user->id)) - { + if ($file && !$this->isPermissionAllowed($project_key, 'remove_file') && !($this->isPermissionAllowed($project_key, 'remove_self_file') && $file->uploader['id'] == $this->user->id)) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } $issue_id = $request->input('issue_id'); $field_key = $request->input('field_key'); - if (isset($issue_id) && $issue_id && isset($field_key) && $field_key) - { + if (isset($issue_id) && $issue_id && isset($field_key) && $field_key) { $user = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; Event::fire(new FileDelEvent($project_key, $issue_id, $field_key, $id, $user)); } // logically deleted - if ($file) - { + if ($file) { $file->fill([ 'del_flg' => 1 ])->save(); } $issue = DB::collection('issue_' . $project_key)->where('_id', $issue_id)->first(); - if (array_search($id, $issue[$field_key]) === false) - { + if (array_search($id, $issue[$field_key]) === false) { return Response()->json(['ecode' => 0, 'data' => ['id' => $id]]); - } - else - { + } else { throw new \UnexpectedValueException('file deletion failed.', -15102); } } @@ -230,15 +206,13 @@ public function uploadTmpFile(Request $request) { set_time_limit(0); - if (empty($_FILES) || $_FILES['file']['error'] > 0) - { + if (empty($_FILES) || $_FILES['file']['error'] > 0) { throw new \UnexpectedValueException('upload file errors.', -15101); } $basename = md5(microtime() . $_FILES['file']['name']); $sub_save_path = config('filesystems.disks.local.root', '/tmp') . '/' . substr($basename, 0, 2) . '/'; - if (!is_dir($sub_save_path)) - { + if (!is_dir($sub_save_path)) { @mkdir($sub_save_path); } $filename = '/tmp/' . $basename; diff --git a/app/Http/Controllers/GroupController.php b/app/Http/Controllers/GroupController.php index 98d07a31a..dbc88c913 100644 --- a/app/Http/Controllers/GroupController.php +++ b/app/Http/Controllers/GroupController.php @@ -31,11 +31,9 @@ public function search(Request $request) { $s = $request->input('s'); $groups = []; - if ($s) - { + if ($s) { $groups = Group::Where('name', 'like', '%' . $s . '%') ->get([ 'name' ]); - } return Response()->json([ 'ecode' => 0, 'data' => $groups ]); } @@ -49,13 +47,11 @@ public function index(Request $request) { $query = Group::where('name', '<>', ''); - if ($name = $request->input('name')) - { + if ($name = $request->input('name')) { $query->where('name', 'like', '%' . $name . '%'); } - if ($directory = $request->input('directory')) - { + if ($directory = $request->input('directory')) { $query->where('directory', $directory); } @@ -67,8 +63,7 @@ public function index(Request $request) $query = $query->skip($page_size * ($page - 1))->take($page_size); $groups = $query->get([ 'name', 'users', 'directory' ]); - foreach ($groups as $group) - { + foreach ($groups as $group) { $group->users = EloquentUser::find($group->users ?: []); } @@ -84,8 +79,7 @@ public function index(Request $request) public function store(Request $request) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -10200); } @@ -102,8 +96,7 @@ public function store(Request $request) public function show($id) { $group = Group::find($id); - if (!$group) - { + if (!$group) { throw new \UnexpectedValueException('the group does not exist.', -10201); } $group->users = EloquentUser::find($group->users); @@ -122,28 +115,23 @@ public function update(Request $request, $id) { $updValues = []; $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -10201); } $updValues['name'] = $name; } $user_ids = $request->input('users'); - if (isset($user_ids)) - { + if (isset($user_ids)) { $updValues['users'] = $user_ids ?: []; } $group = Group::find($id); - if (!$group) - { + if (!$group) { throw new \UnexpectedValueException('the group does not exist.', -10201); } - if (isset($group->diectory) && $group->directory && $group->diectory != 'self') - { + if (isset($group->diectory) && $group->directory && $group->diectory != 'self') { throw new \UnexpectedValueException('the group come from external directroy.', -10203); } @@ -161,12 +149,10 @@ public function update(Request $request, $id) public function destroy($id) { $group = Group::find($id); - if (!$group) - { + if (!$group) { throw new \UnexpectedValueException('the group does not exist.', -10201); } - if (isset($group->diectory) && $group->directory && $group->diectory != 'self') - { + if (isset($group->diectory) && $group->directory && $group->diectory != 'self') { throw new \UnexpectedValueException('the group come from external directroy.', -10203); } @@ -183,19 +169,15 @@ public function destroy($id) public function delMultiGroups(Request $request) { $ids = $request->input('ids'); - if (!isset($ids) || !$ids) - { + if (!isset($ids) || !$ids) { throw new \InvalidArgumentException('the selected groups cannot been empty.', -10201); } $deleted_ids = []; - foreach ($ids as $id) - { + foreach ($ids as $id) { $group = Group::find($id); - if ($group) - { - if (isset($group->diectory) && $group->directory && $group->diectory != 'self') - { + if ($group) { + if (isset($group->diectory) && $group->directory && $group->diectory != 'self') { continue; } $group->delete(); diff --git a/app/Http/Controllers/IssueController.php b/app/Http/Controllers/IssueController.php index a2f55b356..2b28eb3d6 100644 --- a/app/Http/Controllers/IssueController.php +++ b/app/Http/Controllers/IssueController.php @@ -47,46 +47,36 @@ class IssueController extends Controller public function index(Request $request, $project_key) { $where = $this->getIssueQueryWhere($project_key, $request->all()); - $query = DB::collection('issue_' . $project_key)->whereRaw($where); + $query = DB::collection('issue_' . $project_key)->whereRaw($where); $from = $request->input('from'); $from_kanban_id = $request->input('from_kanban_id'); - if (isset($from) && in_array($from, [ 'kanban', 'active_sprint', 'backlog' ]) && isset($from_kanban_id) && $from_kanban_id) - { + if (isset($from) && in_array($from, [ 'kanban', 'active_sprint', 'backlog' ]) && isset($from_kanban_id) && $from_kanban_id) { $board = Board::find($from_kanban_id); - if ($board && isset($board->query) && $board->query) - { + if ($board && isset($board->query) && $board->query) { $global_query = $this->getIssueQueryWhere($project_key, $board->query); $query->whereRaw($global_query); } - if ($from === 'kanban') - { + if ($from === 'kanban') { $query->where(function ($query) { $query->whereRaw([ 'resolve_version' => [ '$exists' => 0 ] ])->orWhere('resolve_version', ''); }); - } - else if ($from === 'active_sprint' || $from === 'backlog') - { + } elseif ($from === 'active_sprint' || $from === 'backlog') { $active_sprint_issues = []; $active_sprint = Sprint::where('project_key', $project_key)->where('status', 'active')->first(); - if ($from === 'active_sprint' && !$active_sprint) - { + if ($from === 'active_sprint' && !$active_sprint) { Response()->json([ 'ecode' => 0, 'data' => []]); - } - else if ($active_sprint && isset($active_sprint['issues']) && $active_sprint['issues']) - { + } elseif ($active_sprint && isset($active_sprint['issues']) && $active_sprint['issues']) { $active_sprint_issues = $active_sprint['issues']; } $last_column_states = []; - if ($board && isset($board->columns)) - { + if ($board && isset($board->columns)) { $board_columns = $board->columns; $last_column = array_pop($board_columns) ?: []; - if ($last_column && isset($last_column['states']) && $last_column['states']) - { - $last_column_states = $last_column['states']; + if ($last_column && isset($last_column['states']) && $last_column['states']) { + $last_column_states = $last_column['states']; } } @@ -100,11 +90,9 @@ public function index(Request $request, $project_key) $total = $query->count(); $orderBy = $request->input('orderBy') ?: ''; - if ($orderBy) - { + if ($orderBy) { $orderBy = explode(',', $orderBy); - foreach ($orderBy as $val) - { + foreach ($orderBy as $val) { $val = explode(' ', trim($val)); $field = array_shift($val); $sort = array_pop($val) ?: 'asc'; @@ -120,16 +108,14 @@ public function index(Request $request, $project_key) $query = $query->skip($page_size * ($page - 1))->take($page_size); $issues = $query->get(); - if (isset($from) && $from == 'export') - { + if (isset($from) && $from == 'export') { $export_fields = $request->input('export_fields'); $this->export($project_key, isset($export_fields) ? explode(',', $export_fields) : [], $issues); exit(); } $watched_issue_ids = []; - if (!isset($from) || !$from) - { + if (!isset($from) || !$from) { $watched_issues = Watch::where('project_key', $project_key) ->where('user.id', $this->user->id) ->get() @@ -139,54 +125,42 @@ public function index(Request $request, $project_key) $cache_parents = []; $issue_ids = []; - foreach ($issues as $key => $issue) - { + foreach ($issues as $key => $issue) { $issue_ids[] = $issue['_id']->__toString(); // set issue watching flag - if (in_array($issue['_id']->__toString(), $watched_issue_ids)) - { + if (in_array($issue['_id']->__toString(), $watched_issue_ids)) { $issues[$key]['watching'] = true; } // get the parent issue - if (isset($issue['parent_id']) && $issue['parent_id']) - { - if (isset($cache_parents[$issue['parent_id']]) && $cache_parents[$issue['parent_id']]) - { + if (isset($issue['parent_id']) && $issue['parent_id']) { + if (isset($cache_parents[$issue['parent_id']]) && $cache_parents[$issue['parent_id']]) { $issues[$key]['parent'] = $cache_parents[$issue['parent_id']]; - } - else - { + } else { $parent = DB::collection('issue_' . $project_key)->where('_id', $issue['parent_id'])->first(); $issues[$key]['parent'] = $parent ? array_only($parent, [ '_id', 'title', 'no', 'type', 'state' ]) : []; $cache_parents[$issue['parent_id']] = $issues[$key]['parent']; } } - if (!isset($from)) - { + if (!isset($from)) { $issues[$key]['hasSubtasks'] = DB::collection('issue_' . $project_key)->where('parent_id', $issue['_id']->__toString())->exists(); } } - if ($issues && isset($from) && in_array($from, [ 'kanban', 'active_sprint', 'backlog', 'his_sprint' ])) - { + if ($issues && isset($from) && in_array($from, [ 'kanban', 'active_sprint', 'backlog', 'his_sprint' ])) { $filter = $request->input('filter') ?: ''; $issues = $this->arrangeIssues($project_key, $issues, $from, $from_kanban_id, $filter === 'all'); } $options = [ 'total' => $total, 'sizePerPage' => $page_size ]; - if (isset($from) && $from == 'gantt') - { - foreach ($issues as $key => $issue) - { - if (!isset($issue['parent_id']) || !$issue['parent_id'] || in_array($issue['parent_id'], $issue_ids)) - { + if (isset($from) && $from == 'gantt') { + foreach ($issues as $key => $issue) { + if (!isset($issue['parent_id']) || !$issue['parent_id'] || in_array($issue['parent_id'], $issue_ids)) { continue; } - if (isset($issue['parent']) && $issue['parent']) - { + if (isset($issue['parent']) && $issue['parent']) { $issues[] = $issue['parent']; $issue_ids[] = $issue['parent_id']; } @@ -194,8 +168,7 @@ public function index(Request $request, $project_key) $singulars = CalendarSingular::all(); $new_singulars = []; - foreach ($singulars as $singular) - { + foreach ($singulars as $singular) { $tmp = []; $tmp['notWorking'] = $singular->type == 'holiday' ? 1 : 0; $tmp['date'] = $singular->date; @@ -217,44 +190,32 @@ public function search(Request $request, $project_key) { $query = DB::collection('issue_' . $project_key)->where('del_flg', '<>', 1); - if ($s = $request->input('s')) - { - if (is_numeric($s) && strpos($s, '.') === false) - { + if ($s = $request->input('s')) { + if (is_numeric($s) && strpos($s, '.') === false) { $query->where(function ($query) use ($s) { $query->where('no', $s + 0)->orWhere('title', 'like', '%' . $s . '%'); }); - } - else - { + } else { $query->where('title', 'like', '%' . $s . '%'); } } $type = $request->input('type'); - if (isset($type)) - { - if ($type == 'standard') - { - $query->where(function ($query) { + if (isset($type)) { + if ($type == 'standard') { + $query->where(function ($query) { $query->where('parent_id', '')->orWhereNull('parent_id')->orWhere('parent_id', 'exists', false); }); - - } - else if ($type == 'subtask') - { - $query->where(function ($query) { + } elseif ($type == 'subtask') { + $query->where(function ($query) { $query->where('parent_id', 'exists', true)->where('parent_id', '<>', '')->whereNotNull('parent_id'); }); } } - if ($limit = $request->input('limit')) - { + if ($limit = $request->input('limit')) { $limit = intval($limit) < 10 ? 10 : intval($limit); - } - else - { + } else { $limit = 10; } @@ -272,66 +233,49 @@ public function search(Request $request, $project_key) public function store(Request $request, $project_key) { $issue_type = $request->input('type'); - if (!$issue_type) - { + if (!$issue_type) { throw new \UnexpectedValueException('the issue type can not be empty.', -11100); } $schema = Provider::getSchemaByType($issue_type); - if (!$schema) - { + if (!$schema) { throw new \UnexpectedValueException('the schema of the type is not existed.', -11101); } - if (!$this->requiredCheck($schema, $request->all(), 'create')) - { + if (!$this->requiredCheck($schema, $request->all(), 'create')) { throw new \UnexpectedValueException('the required field is empty.', -11121); } // handle timetracking $insValues = []; - foreach ($schema as $field) - { + foreach ($schema as $field) { $fieldValue = $request->input($field['key']); - if (!isset($fieldValue) || !$fieldValue) - { + if (!isset($fieldValue) || !$fieldValue) { continue; } - if ($field['type'] == 'TimeTracking') - { - if (!$this->ttCheck($fieldValue)) - { + if ($field['type'] == 'TimeTracking') { + if (!$this->ttCheck($fieldValue)) { throw new \UnexpectedValueException('the format of timetracking is incorrect.', -11102); } $insValues[$field['key']] = $this->ttHandle($fieldValue); $insValues[$field['key'] . '_m'] = $this->ttHandleInM($insValues[$field['key']]); - } - else if ($field['type'] == 'DatePicker' || $field['type'] == 'DateTimePicker') - { - if ($this->isTimestamp($fieldValue) === false) - { + } elseif ($field['type'] == 'DatePicker' || $field['type'] == 'DateTimePicker') { + if ($this->isTimestamp($fieldValue) === false) { throw new \UnexpectedValueException('the format of datepicker field is incorrect.', -11122); } - } - else if ($field['type'] == 'SingleUser') - { + } elseif ($field['type'] == 'SingleUser') { $user_info = Sentinel::findById($fieldValue); - if ($user_info) - { + if ($user_info) { $insValues[$field['key']] = [ 'id' => $fieldValue, 'name' => $user_info->first_name, 'email' => $user_info->email ]; } - } - else if ($field['type'] == 'MultiUser') - { + } elseif ($field['type'] == 'MultiUser') { $user_ids = $fieldValue; $new_user_ids = []; $insValues[$field['key']] = []; - foreach ($user_ids as $uid) - { + foreach ($user_ids as $uid) { $user_info = Sentinel::findById($uid); - if ($user_info) - { + if ($user_info) { array_push($insValues[$field['key']], [ 'id' => $uid, 'name' => $user_info->first_name, 'email' => $user_info->email ]); $new_user_ids[] = $uid; } @@ -343,54 +287,44 @@ public function store(Request $request, $project_key) // handle assignee $assignee = []; $assignee_id = $request->input('assignee'); - if (!$assignee_id) - { + if (!$assignee_id) { $module_ids = $request->input('module'); - if ($module_ids) - { + if ($module_ids) { //$module_ids = explode(',', $module_ids); $module = Provider::getModuleById($module_ids[0]); - if (isset($module['defaultAssignee']) && $module['defaultAssignee'] === 'modulePrincipal') - { + if (isset($module['defaultAssignee']) && $module['defaultAssignee'] === 'modulePrincipal') { $assignee2 = $module['principal'] ?: ''; $assignee_id = isset($assignee2['id']) ? $assignee2['id'] : ''; - } - else if (isset($module['defaultAssignee']) && $module['defaultAssignee'] === 'projectPrincipal') - { + } elseif (isset($module['defaultAssignee']) && $module['defaultAssignee'] === 'projectPrincipal') { $assignee2 = Provider::getProjectPrincipal($project_key) ?: ''; - $assignee_id = isset($assignee2['id']) ? $assignee2['id'] : ''; + $assignee_id = isset($assignee2['id']) ? $assignee2['id'] : ''; } } } - if ($assignee_id) - { - if ($assignee_id != $this->user->id && !$this->isPermissionAllowed($project_key, 'assigned_issue', $assignee_id)) - { + if ($assignee_id) { + if ($assignee_id != $this->user->id && !$this->isPermissionAllowed($project_key, 'assigned_issue', $assignee_id)) { return Response()->json(['ecode' => -11118, 'emsg' => 'the assigned user has not assigned-issue permission.']); } $user_info = Sentinel::findById($assignee_id); - if ($user_info) - { + if ($user_info) { $assignee = [ 'id' => $assignee_id, 'name' => $user_info->first_name, 'email' => $user_info->email ]; } } - if (!$assignee) - { + if (!$assignee) { $assignee = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; } $insValues['assignee'] = $assignee; - //$priority = $request->input('priority'); + //$priority = $request->input('priority'); //if (!isset($priority) || !$priority) //{ // $insValues['priority'] = Provider::getDefaultPriority($project_key); //} - $resolution = $request->input('resolution'); - if (!isset($resolution) || !$resolution) - { - $insValues['resolution'] = 'Unresolved'; + $resolution = $request->input('resolution'); + if (!isset($resolution) || !$resolution) { + $insValues['resolution'] = 'Unresolved'; } // get reporter(creator) @@ -401,7 +335,7 @@ public function store(Request $request, $project_key) $max_no = DB::collection($table)->count() + 1; $insValues['no'] = $max_no; - // workflow initialize + // workflow initialize $workflow = $this->initializeWorkflow($issue_type); $insValues = $insValues + $workflow; @@ -418,8 +352,7 @@ public function store(Request $request, $project_key) Event::fire(new IssueEvent($project_key, $id->__toString(), $insValues['reporter'], [ 'event_key' => 'create_issue' ])); // create the Labels for project - if (isset($insValues['labels']) && $insValues['labels']) - { + if (isset($insValues['labels']) && $insValues['labels']) { $this->createLabels($project_key, $insValues['labels']); } @@ -430,7 +363,7 @@ public function store(Request $request, $project_key) * initialize the workflow by type. * * @param int $type - * @return array + * @return array */ public function initializeWorkflow($type) { @@ -460,31 +393,25 @@ public function show($project_key, $id) { $issue = DB::collection('issue_' . $project_key)->where('_id', $id)->first(); $schema = Provider::getSchemaByType($issue['type']); - if (!$schema) - { + if (!$schema) { throw new \UnexpectedValueException('the schema of the type is not existed.', -11101); } - if (isset($issue['assignee']['id'])) - { + if (isset($issue['assignee']['id'])) { $user = Sentinel::findById($issue['assignee']['id']); $issue['assignee']['avatar'] = isset($user->avatar) ? $user->avatar : ''; } - foreach ($schema as $field) - { - if ($field['type'] === 'File' && isset($issue[$field['key']]) && $issue[$field['key']]) - { - foreach ($issue[$field['key']] as $key => $fid) - { + foreach ($schema as $field) { + if ($field['type'] === 'File' && isset($issue[$field['key']]) && $issue[$field['key']]) { + foreach ($issue[$field['key']] as $key => $fid) { $issue[$field['key']][$key] = File::find($fid); } } } // get avaliable actions for wf - if (isset($issue['entry_id']) && $issue['entry_id']) - { + if (isset($issue['entry_id']) && $issue['entry_id']) { try { $wf = new Workflow($issue['entry_id']); $issue['wfactions'] = $wf->getAvailableActions([ 'project_key' => $project_key, 'issue_id' => $id, 'caller' => $this->user->id ]); @@ -492,21 +419,16 @@ public function show($project_key, $id) $issue['wfactions'] = []; } - foreach ($issue['wfactions'] as $key => $action) - { - if (isset($action['screen']) && $action['screen'] && $action['screen'] != 'comments') - { + foreach ($issue['wfactions'] as $key => $action) { + if (isset($action['screen']) && $action['screen'] && $action['screen'] != 'comments') { $issue['wfactions'][$key]['schema'] = Provider::getSchemaByScreenId($project_key, $issue['type'], $action['screen']); } } } - if (isset($issue['parent_id']) && $issue['parent_id']) - { + if (isset($issue['parent_id']) && $issue['parent_id']) { $issue['parent'] = DB::collection('issue_' . $project_key)->where('_id', $issue['parent_id'])->first(['no', 'type', 'title', 'state']); - } - else - { + } else { $issue['hasSubtasks'] = DB::collection('issue_' . $project_key)->where('parent_id', $id)->exists(); } @@ -515,24 +437,17 @@ public function show($project_key, $id) $issue['links'] = []; $links = DB::collection('linked')->where('src', $id)->orWhere('dest', $id)->where('del_flg', '<>', 1)->orderBy('created_at', 'asc')->get(); $link_fields = ['_id', 'no', 'type', 'title', 'state']; - foreach ($links as $link) - { - if ($link['src'] == $id) - { + foreach ($links as $link) { + if ($link['src'] == $id) { $link['src'] = array_only($issue, $link_fields); - } - else - { + } else { $src_issue = DB::collection('issue_' . $project_key)->where('_id', $link['src'])->first(); $link['src'] = array_only($src_issue, $link_fields); } - if ($link['dest'] == $id) - { + if ($link['dest'] == $id) { $link['dest'] = array_only($issue, $link_fields); - } - else - { + } else { $dest_issue = DB::collection('issue_' . $project_key)->where('_id', $link['dest'])->first(); $link['dest'] = array_only($dest_issue, $link_fields); } @@ -541,8 +456,7 @@ public function show($project_key, $id) $issue['watchers'] = array_column(Watch::where('issue_id', $id)->orderBy('_id', 'desc')->get()->toArray(), 'user'); - if (Watch::where('issue_id', $id)->where('user.id', $this->user->id)->exists()) - { + if (Watch::where('issue_id', $id)->where('user.id', $this->user->id)->exists()) { $issue['watching'] = true; } @@ -550,11 +464,9 @@ public function show($project_key, $id) $comments = DB::collection('comments_' . $project_key) ->where('issue_id', $id) ->get(); - foreach($comments as $comment) - { + foreach ($comments as $comment) { $comments_num += 1; - if (isset($comment['reply'])) - { + if (isset($comment['reply'])) { $comments_num += count($comment['reply']); } } @@ -584,10 +496,8 @@ public function wfactions($project_key, $id) $wf = new Workflow($issue['entry_id']); $wfactions = $wf->getAvailableActions([ 'project_key' => $project_key, 'issue_id' => $id, 'caller' => $this->user->id ], true); - foreach ($wfactions as $key => $action) - { - if (isset($action['screen']) && $action['screen']) - { + foreach ($wfactions as $key => $action) { + if (isset($action['screen']) && $action['screen']) { $wfactions[$key]['schema'] = Provider::getSchemaByScreenId($project_key, $issue['type'], $action['screen']); } } @@ -626,8 +536,7 @@ public function getOptions($project_key) // get project sprints $new_sprints = []; $sprints = Provider::getSprintList($project_key); - foreach ($sprints as $sprint) - { + foreach ($sprints as $sprint) { $new_sprints[] = [ 'no' => $sprint['no'], 'name' => $sprint['name'] ]; } // get defined fields @@ -641,26 +550,26 @@ public function getOptions($project_key) // get issue link relations $relations = $this->getLinkRelations(); - return Response()->json([ - 'ecode' => 0, - 'data' => parent::arrange([ - 'users' => $users, - 'assignees' => $assignees, - 'types' => $types, - 'states' => $states, - 'resolutions' => $resolutions, - 'priorities' => $priorities, - 'modules' => $modules, - 'labels' => $labels, - 'versions' => $versions, + return Response()->json([ + 'ecode' => 0, + 'data' => parent::arrange([ + 'users' => $users, + 'assignees' => $assignees, + 'types' => $types, + 'states' => $states, + 'resolutions' => $resolutions, + 'priorities' => $priorities, + 'modules' => $modules, + 'labels' => $labels, + 'versions' => $versions, 'epics' => $epics, 'sprints' => $new_sprints, - 'filters' => $filters, - 'display_columns' => $display_columns, - 'timetrack' => $timetrack, - 'relations' => $relations, - 'fields' => $fields - ]) + 'filters' => $filters, + 'display_columns' => $display_columns, + 'timetrack' => $timetrack, + 'relations' => $relations, + 'fields' => $fields + ]) ]); } @@ -676,51 +585,42 @@ public function setAssignee(Request $request, $project_key, $id) { $table = 'issue_' . $project_key; $issue = DB::collection($table)->find($id); - if (!$issue) - { + if (!$issue) { throw new \UnexpectedValueException('the issue does not exist or is not in the project.', -11103); } - if (!$this->isPermissionAllowed($project_key, 'assign_issue')) - { + if (!$this->isPermissionAllowed($project_key, 'assign_issue')) { return Response()->json(['ecode' => -11116, 'emsg' => 'the current user has not assign-issue permission.']); } - $updValues = []; $assignee = []; + $updValues = []; + $assignee = []; $assignee_id = $request->input('assignee'); - if (!isset($assignee_id) || !$assignee_id) - { + if (!isset($assignee_id) || !$assignee_id) { throw new \UnexpectedValueException('the issue assignee cannot be empty.', -11104); } - if ($assignee_id === 'me') - { - if (!$this->isPermissionAllowed($project_key, 'assigned_issue')) - { + if ($assignee_id === 'me') { + if (!$this->isPermissionAllowed($project_key, 'assigned_issue')) { return Response()->json(['ecode' => -11117, 'emsg' => 'the current user has not assigned-issue permission.']); } $assignee = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; $updValues['assignee'] = $assignee; - } - else - { - if (!$this->isPermissionAllowed($project_key, 'assigned_issue', $assignee_id)) - { + } else { + if (!$this->isPermissionAllowed($project_key, 'assigned_issue', $assignee_id)) { return Response()->json(['ecode' => -11118, 'emsg' => 'the assigned user has not assigned-issue permission.']); } $user_info = Sentinel::findById($assignee_id); - if ($user_info) - { + if ($user_info) { $assignee = [ 'id' => $assignee_id, 'name' => $user_info->first_name, 'email' => $user_info->email ]; $updValues['assignee'] = $assignee; } } // issue assignee has no change. - if ($assignee['id'] === $issue['assignee']['id']) - { + if ($assignee['id'] === $issue['assignee']['id']) { return $this->show($project_key, $id); } @@ -746,21 +646,18 @@ public function setAssignee(Request $request, $project_key, $id) */ public function setLabels(Request $request, $project_key, $id) { - if (!$this->isPermissionAllowed($project_key, 'edit_issue')) - { + if (!$this->isPermissionAllowed($project_key, 'edit_issue')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } $labels = $request->input('labels'); - if (!isset($labels)) - { + if (!isset($labels)) { return $this->show($project_key, $id); } $table = 'issue_' . $project_key; $issue = DB::collection($table)->find($id); - if (!$issue) - { + if (!$issue) { throw new \UnexpectedValueException('the issue does not exist or is not in the project.', -11103); } @@ -775,8 +672,7 @@ public function setLabels(Request $request, $project_key, $id) // trigger event of issue edited Event::fire(new IssueEvent($project_key, $id, $updValues['modifier'], [ 'event_key' => 'edit_issue', 'snap_id' => $snap_id ])); // create the Labels for project - if ($labels) - { + if ($labels) { $this->createLabels($project_key, $labels); } @@ -796,14 +692,12 @@ public function createLabels($project_key, $labels) $project_labels = Labels::where('project_key', $project_key) ->whereIn('name', $labels) ->get(); - foreach ($project_labels as $label) - { + foreach ($project_labels as $label) { $created_labels[] = $label->name; } // get uncreated labels $new_labels = array_diff($labels, $created_labels); - foreach ($new_labels as $label) - { + foreach ($new_labels as $label) { Labels::create([ 'project_key' => $project_key, 'name' => $label ]); } return true; @@ -819,21 +713,14 @@ public function createLabels($project_key, $labels) */ public function requiredCheck($schema, $data, $mode='create') { - foreach ($schema as $field) - { - if (isset($field['required']) && $field['required']) - { - if ($mode == 'update') - { - if (isset($data[$field['key']]) && !$data[$field['key']] && $data[$field['key']] !== 0) - { + foreach ($schema as $field) { + if (isset($field['required']) && $field['required']) { + if ($mode == 'update') { + if (isset($data[$field['key']]) && !$data[$field['key']] && $data[$field['key']] !== 0) { return false; } - } - else - { - if (!isset($data[$field['key']]) || !$data[$field['key']] && $data[$field['key']] !== 0) - { + } else { + if (!isset($data[$field['key']]) || !$data[$field['key']] && $data[$field['key']] !== 0) { return false; } } @@ -848,14 +735,11 @@ public function requiredCheck($schema, $data, $mode='create') * @param int $timestamp * @return bool */ - public function isTimestamp($timestamp) + public function isTimestamp($timestamp) { - if(strtotime(date('Y-m-d H:i:s', $timestamp)) === $timestamp) - { + if (strtotime(date('Y-m-d H:i:s', $timestamp)) === $timestamp) { return $timestamp; - } - else - { + } else { return false; } } @@ -870,14 +754,10 @@ public function getValidKeysBySchema($schema=[]) { $valid_keys = array_merge(array_column($schema, 'key'), [ 'type', 'assignee', 'labels', 'parent_id', 'resolution', 'priority', 'progress', 'expect_start_time', 'expect_compete_time' ]); - foreach ($schema as $field) - { - if ($field['type'] == 'MultiUser') - { + foreach ($schema as $field) { + if ($field['type'] == 'MultiUser') { $valid_keys[] = $field['key'] . '_ids'; - } - else if ($field['type'] == 'TimeTracking') - { + } elseif ($field['type'] == 'TimeTracking') { $valid_keys[] = $field['key'] . '_m'; } } @@ -895,79 +775,60 @@ public function getValidKeysBySchema($schema=[]) */ public function update(Request $request, $project_key, $id) { - if (!$this->isPermissionAllowed($project_key, 'edit_issue') && !$this->isPermissionAllowed($project_key, 'exec_workflow')) - { + if (!$this->isPermissionAllowed($project_key, 'edit_issue') && !$this->isPermissionAllowed($project_key, 'exec_workflow')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } - if (!$request->all()) - { - return $this->show($project_key, $id); + if (!$request->all()) { + return $this->show($project_key, $id); } $table = 'issue_' . $project_key; $issue = DB::collection($table)->find($id); - if (!$issue) - { + if (!$issue) { throw new \UnexpectedValueException('the issue does not exist or is not in the project.', -11103); } $schema = Provider::getSchemaByType($request->input('type') ?: $issue['type']); - if (!$schema) - { + if (!$schema) { throw new \UnexpectedValueException('the schema of the type is not existed.', -11101); } - if (!$this->requiredCheck($schema, $request->all(), 'update')) - { + if (!$this->requiredCheck($schema, $request->all(), 'update')) { throw new \UnexpectedValueException('the required field is empty.', -11121); } // handle timetracking $updValues = []; - foreach ($schema as $field) - { + foreach ($schema as $field) { $fieldValue = $request->input($field['key']); - if (!isset($fieldValue) || !$fieldValue) - { + if (!isset($fieldValue) || !$fieldValue) { continue; } - if ($field['type'] == 'TimeTracking') - { - if (!$this->ttCheck($fieldValue)) - { + if ($field['type'] == 'TimeTracking') { + if (!$this->ttCheck($fieldValue)) { throw new \UnexpectedValueException('the format of timetracking field is incorrect.', -11102); } $updValues[$field['key']] = $this->ttHandle($fieldValue); $updValues[$field['key'] . '_m'] = $this->ttHandleInM($updValues[$field['key']]); - } - else if ($field['type'] == 'DatePicker' || $field['type'] == 'DateTimePicker') - { - if ($this->isTimestamp($fieldValue) === false) - { + } elseif ($field['type'] == 'DatePicker' || $field['type'] == 'DateTimePicker') { + if ($this->isTimestamp($fieldValue) === false) { throw new \UnexpectedValueException('the format of datepicker field is incorrect.', -11122); } - } - else if ($field['type'] == 'SingleUser') - { + } elseif ($field['type'] == 'SingleUser') { $user_info = Sentinel::findById($fieldValue); - if ($user_info) - { + if ($user_info) { $updValues[$field['key']] = [ 'id' => $fieldValue, 'name' => $user_info->first_name, 'email' => $user_info->email ]; } - } - else if ($field['type'] == 'MultiUser') - { + } elseif ($field['type'] == 'MultiUser') { $user_ids = $fieldValue; $updValues[$field['key']] = []; $new_user_ids = []; - foreach ($user_ids as $uid) - { + foreach ($user_ids as $uid) { $user_info = Sentinel::findById($uid); - if ($user_info) - { + if ($user_info) { array_push($updValues[$field['key']], [ 'id' => $uid, 'name' => $user_info->first_name, 'email' => $user_info->email ]); } $new_user_ids[] = $uid; @@ -977,16 +838,13 @@ public function update(Request $request, $project_key, $id) } $assignee_id = $request->input('assignee'); - if ($assignee_id) - { - if ((!isset($issue['assignee']) || (isset($issue['assignee']) && $assignee_id != $issue['assignee']['id'])) && !$this->isPermissionAllowed($project_key, 'assigned_issue', $assignee_id)) - { + if ($assignee_id) { + if ((!isset($issue['assignee']) || (isset($issue['assignee']) && $assignee_id != $issue['assignee']['id'])) && !$this->isPermissionAllowed($project_key, 'assigned_issue', $assignee_id)) { return Response()->json(['ecode' => -11118, 'emsg' => 'the assigned user has not assigned-issue permission.']); } $user_info = Sentinel::findById($assignee_id); - if ($user_info) - { + if ($user_info) { $assignee = [ 'id' => $assignee_id, 'name' => $user_info->first_name, 'email' => $user_info->email ]; $updValues['assignee'] = $assignee; } @@ -994,8 +852,7 @@ public function update(Request $request, $project_key, $id) $valid_keys = $this->getValidKeysBySchema($schema); $updValues = $updValues + array_only($request->all(), $valid_keys); - if (!$updValues) - { + if (!$updValues) { return $this->show($project_key, $id); } @@ -1009,12 +866,11 @@ public function update(Request $request, $project_key, $id) // trigger event of issue edited Event::fire(new IssueEvent($project_key, $id, $updValues['modifier'], [ 'event_key' => 'edit_issue', 'snap_id' => $snap_id ])); // create the Labels for project - if (isset($updValues['labels']) && $updValues['labels']) - { + if (isset($updValues['labels']) && $updValues['labels']) { $this->createLabels($project_key, $updValues['labels']); } - return $this->show($project_key, $id); + return $this->show($project_key, $id); } /** @@ -1031,8 +887,7 @@ public function destroy($project_key, $id) ->where('_id', $id) ->where('del_flg', '<>', 1) ->first(); - if (!$issue) - { + if (!$issue) { throw new \UnexpectedValueException('the issue does not exist or is not in the project.', -11103); } @@ -1044,8 +899,7 @@ public function destroy($project_key, $id) ->where('parent_id', $id) ->where('del_flg', '<>', 1) ->get(); - foreach ($subtasks as $subtask) - { + foreach ($subtasks as $subtask) { $sub_id = $subtask['_id']->__toString(); DB::collection($table)->where('_id', $sub_id)->update([ 'del_flg' => 1 ]); @@ -1060,7 +914,7 @@ public function destroy($project_key, $id) DB::collection('linked')->where('src', $id)->orWhere('dest', $id)->delete(); // delete this issue DB::collection($table)->where('_id', $id)->update([ 'del_flg' => 1 ]); - // trigger event of issue deleted + // trigger event of issue deleted Event::fire(new IssueEvent($project_key, $id, $user, [ 'event_key' => 'del_issue' ])); return Response()->json(['ecode' => 0, 'data' => [ 'ids' => $ids ]]); @@ -1086,13 +940,11 @@ public function getIssueFilters($project_key) public function saveIssueFilter(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -11105); } - if (UserIssueFilters::whereRaw([ 'name' => $name, 'user' => $this->user->id, 'project_key' => $project_key ])->exists()) - { + if (UserIssueFilters::whereRaw([ 'name' => $name, 'user' => $this->user->id, 'project_key' => $project_key ])->exists()) { throw new \UnexpectedValueException('filter name cannot be repeated', -11106); } @@ -1101,32 +953,25 @@ public function saveIssueFilter(Request $request, $project_key) $res = UserIssueFilters::where('project_key', $project_key) ->where('user', $this->user->id) ->first(); - if ($res) - { + if ($res) { $filters = isset($res['filters']) ? $res['filters'] : []; - foreach($filters as $filter) - { - if (isset($filter['name']) && $filter['name'] === $name) - { + foreach ($filters as $filter) { + if (isset($filter['name']) && $filter['name'] === $name) { throw new \UnexpectedValueException('filter name cannot be repeated', -11106); } } array_push($filters, [ 'id' => md5(microtime()), 'name' => $name, 'query' => $query ]); $res->filters = $filters; $res->save(); - } - else - { + } else { $filters = Provider::getDefaultIssueFilters(); - foreach($filters as $filter) - { - if (isset($filter['name']) && $filter['name'] === $name) - { + foreach ($filters as $filter) { + if (isset($filter['name']) && $filter['name'] === $name) { throw new \UnexpectedValueException('filter name cannot be repeated', -11106); } } array_push($filters, [ 'id' => md5(microtime()), 'name' => $name, 'query' => $query ]); - UserIssueFilters::create([ 'project_key' => $project_key, 'user' => $this->user->id, 'filters' => $filters ]); + UserIssueFilters::create([ 'project_key' => $project_key, 'user' => $this->user->id, 'filters' => $filters ]); } return $this->getIssueFilters($project_key); } @@ -1170,8 +1015,7 @@ public function resetDisplayColumns(Request $request, $project_key) ->delete(); $delete_from_project = $request->input('delete_from_project') ?: false; - if ($delete_from_project && $this->isPermissionAllowed($project_key, 'manage_project')) - { + if ($delete_from_project && $this->isPermissionAllowed($project_key, 'manage_project')) { ProjectIssueListColumns::where('project_key', $project_key)->delete(); } @@ -1189,15 +1033,12 @@ public function setDisplayColumns(Request $request, $project_key) $column_keys = []; $new_columns = []; $columns = $request->input('columns') ?: []; - foreach ($columns as $column) - { - if (!isset($column['key'])) - { + foreach ($columns as $column) { + if (!isset($column['key'])) { continue; } - if (in_array($column['key'], $column_keys)) - { + if (in_array($column['key'], $column_keys)) { continue; } $column_keys[] = $column['key']; @@ -1207,29 +1048,22 @@ public function setDisplayColumns(Request $request, $project_key) $res = UserIssueListColumns::where('project_key', $project_key) ->where('user', $this->user->id) ->first(); - if ($res) - { + if ($res) { $res->columns = $new_columns; $res->column_keys = $column_keys; $res->save(); - } - else - { - UserIssueListColumns::create([ 'project_key' => $project_key, 'user' => $this->user->id, 'column_keys' => $column_keys, 'columns' => $new_columns ]); + } else { + UserIssueListColumns::create([ 'project_key' => $project_key, 'user' => $this->user->id, 'column_keys' => $column_keys, 'columns' => $new_columns ]); } $save_for_project = $request->input('save_for_project') ?: false; - if ($save_for_project && $this->isPermissionAllowed($project_key, 'manage_project')) - { + if ($save_for_project && $this->isPermissionAllowed($project_key, 'manage_project')) { $res = ProjectIssueListColumns::where('project_key', $project_key)->first(); - if ($res) - { + if ($res) { $res->columns = $new_columns; $res->column_keys = $column_keys; $res->save(); - } - else - { + } else { ProjectIssueListColumns::create([ 'project_key' => $project_key, 'column_keys' => $column_keys, 'columns' => $new_columns ]); } } @@ -1246,37 +1080,29 @@ public function setDisplayColumns(Request $request, $project_key) public function editFilters(Request $request, $project_key) { $sequence = $request->input('sequence'); - if (isset($sequence)) - { + if (isset($sequence)) { $old_filters = Provider::getDefaultIssueFilters(); $res = UserIssueFilters::where('project_key', $project_key) ->where('user', $this->user->id) ->first(); - if ($res) - { + if ($res) { $old_filters = isset($res->filters) ? $res->filters : []; } $new_filters = []; - foreach ($sequence as $id) - { - foreach ($old_filters as $filter) - { - if ($filter['id'] === $id) - { + foreach ($sequence as $id) { + foreach ($old_filters as $filter) { + if ($filter['id'] === $id) { $new_filters[] = $filter; break; } } } - if ($res) - { + if ($res) { $res->filters = $new_filters; $res->save(); - } - else - { - UserIssueFilters::create([ 'project_key' => $project_key, 'user' => $this->user->id, 'filters' => $new_filters ]); + } else { + UserIssueFilters::create([ 'project_key' => $project_key, 'user' => $this->user->id, 'filters' => $new_filters ]); } } return $this->getIssueFilters($project_key); @@ -1308,93 +1134,74 @@ public function getHistory(Request $request, $project_key, $id) { $changedRecords = []; $records = DB::collection('issue_his_' . $project_key)->where('issue_id', $id)->orderBy('_id', 'asc')->get(); - foreach ($records as $i => $item) - { - if ($i == 0) - { + foreach ($records as $i => $item) { + if ($i == 0) { $changedRecords[] = [ 'operation' => 'create', 'operator' => $item['operator'], 'operated_at' => $item['operated_at'] ]; - } - else - { + } else { $changed_items = []; $changed_items['operation'] = 'modify'; $changed_items['operated_at'] = $item['operated_at']; $changed_items['operator'] = $item['operator']; - $diff_items = []; $diff_keys = []; + $diff_items = []; + $diff_keys = []; $after_data = $item['data']; $before_data = $records[$i - 1]['data']; - foreach ($after_data as $key => $val) - { - if (!isset($before_data[$key]) || $val !== $before_data[$key]) - { + foreach ($after_data as $key => $val) { + if (!isset($before_data[$key]) || $val !== $before_data[$key]) { $tmp = []; $tmp['field'] = isset($val['name']) ? $val['name'] : ''; $tmp['after_value'] = isset($val['value']) ? $val['value'] : ''; $tmp['before_value'] = isset($before_data[$key]) && isset($before_data[$key]['value']) ? $before_data[$key]['value'] : ''; - if (is_array($tmp['after_value']) && is_array($tmp['before_value'])) - { + if (is_array($tmp['after_value']) && is_array($tmp['before_value'])) { $diff1 = array_diff($tmp['after_value'], $tmp['before_value']); $diff2 = array_diff($tmp['before_value'], $tmp['after_value']); $tmp['after_value'] = implode(',', $diff1); $tmp['before_value'] = implode(',', $diff2); - } - else - { - if (is_array($tmp['after_value'])) - { + } else { + if (is_array($tmp['after_value'])) { $tmp['after_value'] = implode(',', $tmp['after_value']); } - if (is_array($tmp['before_value'])) - { + if (is_array($tmp['before_value'])) { $tmp['before_value'] = implode(',', $tmp['before_value']); } } - $diff_items[] = $tmp; - $diff_keys[] = $key; + $diff_items[] = $tmp; + $diff_keys[] = $key; } } - foreach ($before_data as $key => $val) - { - if (array_search($key, $diff_keys) !== false) - { + foreach ($before_data as $key => $val) { + if (array_search($key, $diff_keys) !== false) { continue; } - if (!isset($after_data[$key]) || $val !== $after_data[$key]) - { + if (!isset($after_data[$key]) || $val !== $after_data[$key]) { $tmp = []; $tmp['field'] = isset($val['name']) ? $val['name'] : ''; $tmp['before_value'] = isset($val['value']) ? $val['value'] : ''; $tmp['after_value'] = isset($after_data[$key]) && isset($after_data[$key]['value']) ? $after_data[$key]['value'] : ''; - if (is_array($tmp['after_value']) && is_array($tmp['before_value'])) - { + if (is_array($tmp['after_value']) && is_array($tmp['before_value'])) { $diff1 = array_diff($tmp['after_value'], $tmp['before_value']); $diff2 = array_diff($tmp['before_value'], $tmp['after_value']); $tmp['after_value'] = implode(',', $diff1); $tmp['before_value'] = implode(',', $diff2); - } - else - { - if (is_array($tmp['after_value'])) - { + } else { + if (is_array($tmp['after_value'])) { $tmp['after_value'] = implode(',', $tmp['after_value']); } - if (is_array($tmp['before_value'])) - { + if (is_array($tmp['before_value'])) { $tmp['before_value'] = implode(',', $tmp['before_value']); } } - $diff_items[] = $tmp; + $diff_items[] = $tmp; } } - if ($diff_items) - { + if ($diff_items) { $changed_items['data'] = $diff_items; $changedRecords[] = $changed_items; } @@ -1402,8 +1209,7 @@ public function getHistory(Request $request, $project_key, $id) } $sort = ($request->input('sort') === 'asc') ? 'asc' : 'desc'; - if ($sort === 'desc') - { + if ($sort === 'desc') { $changedRecords = array_reverse($changedRecords); } @@ -1421,8 +1227,7 @@ public function getHistory(Request $request, $project_key, $id) public function doAction(Request $request, $project_key, $id, $workflow_id) { $action_id = $request->input('action_id'); - if (!$action_id) - { + if (!$action_id) { throw new Exception('the executed action has error.', -11115); } @@ -1430,9 +1235,9 @@ public function doAction(Request $request, $project_key, $id, $workflow_id) $entry = new Workflow($workflow_id); $entry->doAction($action_id, [ 'project_key' => $project_key, 'issue_id' => $id, 'caller' => $this->user->id ] + array_only($request->all(), [ 'comments' ])); } catch (Exception $e) { - throw new Exception('the executed action has error.', -11115); + throw new Exception('the executed action has error.', -11115); } - return $this->show($project_key, $id); + return $this->show($project_key, $id); } /** @@ -1449,16 +1254,13 @@ public function watch(Request $request, $project_key, $id) $cur_user = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; $flag = $request->input('flag'); - if (isset($flag) && $flag) - { + if (isset($flag) && $flag) { Watch::create([ 'project_key' => $project_key, 'issue_id' => $id, 'user' => $cur_user ]); - // trigger event of issue watched + // trigger event of issue watched Event::fire(new IssueEvent($project_key, $id, $cur_user, [ 'event_key' => 'watched_issue' ])); - } - else - { + } else { $flag = false; - // trigger event of issue watched + // trigger event of issue watched Event::fire(new IssueEvent($project_key, $id, $cur_user, [ 'event_key' => 'unwatched_issue' ])); } @@ -1477,37 +1279,29 @@ public function resetState(Request $request, $project_key, $id) $updValues = []; $assignee_id = $request->input('assignee'); - if (isset($assignee_id)) - { - if ($assignee_id) - { - if (!$this->isPermissionAllowed($project_key, 'assigned_issue', $assignee_id)) - { + if (isset($assignee_id)) { + if ($assignee_id) { + if (!$this->isPermissionAllowed($project_key, 'assigned_issue', $assignee_id)) { return Response()->json(['ecode' => -11118, 'emsg' => 'the assigned user has not assigned-issue permission.']); } $user_info = Sentinel::findById($assignee_id); - if ($user_info) - { + if ($user_info) { $assignee = [ 'id' => $assignee_id, 'name' => $user_info->first_name, 'email' => $user_info->email ]; $updValues['assignee'] = $assignee; } - } - else - { + } else { throw new \UnexpectedValueException('the issue assignee cannot be empty.', -11104); } } $resolution = $request->input('resolution'); - if (isset($resolution) && $resolution) - { + if (isset($resolution) && $resolution) { $updValues['resolution'] = $resolution; } $issue = DB::collection('issue_' . $project_key)->where('_id', $id)->first(); - if (!$issue) - { + if (!$issue) { throw new \UnexpectedValueException('the issue does not exist or is not in the project.', -11103); } @@ -1539,26 +1333,22 @@ public function resetState(Request $request, $project_key, $id) public function copy(Request $request, $project_key) { $title = $request->input('title'); - if (!$title) - { + if (!$title) { throw new \UnexpectedValueException('the issue title cannot be empty.', -11108); } $src_id = $request->input('source_id'); - if (!isset($src_id) || !$src_id) - { + if (!isset($src_id) || !$src_id) { throw new \UnexpectedValueException('the copied issue id cannot be empty.', -11109); } $src_issue = DB::collection('issue_' . $project_key)->where('_id', $src_id)->first(); - if (!$src_issue ) - { + if (!$src_issue) { throw new \UnexpectedValueException('the copied issue does not exist or is not in the project.', -11103); } $schema = Provider::getSchemaByType($src_issue['type']); - if (!$schema) - { + if (!$schema) { throw new \UnexpectedValueException('the schema of the type is not existed.', -11101); } @@ -1570,31 +1360,24 @@ public function copy(Request $request, $project_key) $insValues['reporter'] = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; $assignee_id = $request->input('assignee'); - if (isset($assignee_id)) - { - if ($assignee_id) - { - if (!$this->isPermissionAllowed($project_key, 'assigned_issue', $assignee_id)) - { + if (isset($assignee_id)) { + if ($assignee_id) { + if (!$this->isPermissionAllowed($project_key, 'assigned_issue', $assignee_id)) { return Response()->json(['ecode' => -11118, 'emsg' => 'the assigned user has not assigned-issue permission.']); } $user_info = Sentinel::findById($assignee_id); - if ($user_info) - { + if ($user_info) { $assignee = [ 'id' => $assignee_id, 'name' => $user_info->first_name, 'email' => $user_info->email ]; $insValues['assignee'] = $assignee; } - } - else - { + } else { throw new \UnexpectedValueException('the issue assignee cannot be empty.', -11104); } } $resolution = $request->input('resolution'); - if (isset($resolution) && $resolution) - { + if (isset($resolution) && $resolution) { $insValues['resolution'] = $resolution; } @@ -1615,9 +1398,9 @@ public function copy(Request $request, $project_key) Provider::snap2His($project_key, $id, $schema); // create link of clone Linked::create([ 'src' => $src_id, 'relation' => 'is cloned by', 'dest' => $id->__toString(), 'creator' => $insValues['reporter'] ]); - // trigger event of issue created + // trigger event of issue created Event::fire(new IssueEvent($project_key, $id->__toString(), $insValues['reporter'], [ 'event_key' => 'create_issue' ])); - // trigger event of link created + // trigger event of link created Event::fire(new IssueEvent($project_key, $src_id, $insValues['reporter'], [ 'event_key' => 'create_link', 'data' => [ 'relation' => 'is cloned by', 'dest' => $id->__toString() ] ])); return $this->show($project_key, $id->__toString()); @@ -1635,36 +1418,30 @@ public function convert(Request $request, $project_key, $id) { $table = 'issue_' . $project_key; $issue = DB::collection($table)->find($id); - if (!$issue) - { + if (!$issue) { throw new \UnexpectedValueException('the issue does not exist or is not in the project.', -11103); } $type = $request->input('type'); - if (!isset($type) || !$type) - { + if (!isset($type) || !$type) { throw new \UnexpectedValueException('the issue type cannot be empty.', -11100); } $parent_id = $request->input('parent_id'); - if (!isset($parent_id)) - { + if (!isset($parent_id)) { $parent_id = ''; } $updValues = []; - if ($parent_id) - { - // standard convert to subtask + if ($parent_id) { + // standard convert to subtask $hasSubtasks = DB::collection($table)->where('parent_id', $id)->exists(); - if ($hasSubtasks) - { + if ($hasSubtasks) { throw new \UnexpectedValueException('the issue can not convert to subtask.', -11114); } $parent_issue = DB::collection($table)->find($parent_id); - if (!$parent_issue) - { + if (!$parent_issue) { throw new \UnexpectedValueException('the dest parent issue does not exist or is not in the project.', -11110); } } @@ -1678,10 +1455,9 @@ public function convert(Request $request, $project_key, $id) // add to histroy table $snap_id = Provider::snap2His($project_key, $id, null, [ 'parent_id', 'type' ]); // trigger event of issue moved - Event::fire(new IssueEvent($project_key, $id, $updValues['modifier'], [ 'event_key' => 'edit_issue', 'snap_id' => $snap_id ] )); + Event::fire(new IssueEvent($project_key, $id, $updValues['modifier'], [ 'event_key' => 'edit_issue', 'snap_id' => $snap_id ])); return $this->show($project_key, $id); - } /** @@ -1696,24 +1472,20 @@ public function move(Request $request, $project_key, $id) { $table = 'issue_' . $project_key; $issue = DB::collection($table)->find($id); - if (!$issue) - { + if (!$issue) { throw new \UnexpectedValueException('the issue does not exist or is not in the project.', -11103); } - $parent_id = $request->input('parent_id'); - if (!isset($parent_id) || !$parent_id) - { + $parent_id = $request->input('parent_id'); + if (!isset($parent_id) || !$parent_id) { throw new \UnexpectedValueException('the dest parent cannot be empty.', -11111); } $parent_issue = DB::collection($table)->find($parent_id); - if (!$parent_issue) - { + if (!$parent_issue) { throw new \UnexpectedValueException('the dest parent issue does not exist or is not in the project.', -11110); } - if ($parent_id === $issue['parent_id']) - { + if ($parent_id === $issue['parent_id']) { return $this->show($project_key, $id); } @@ -1738,38 +1510,34 @@ public function move(Request $request, $project_key, $id) * @param string $project_key * @return \Illuminate\Http\Response */ - public function release(Request $request, $project_key) + public function release(Request $request, $project_key) { - $ids = $request->input('ids'); - if (!$ids) - { + $ids = $request->input('ids'); + if (!$ids) { throw new \UnexpectedValueException('the released issues cannot be empty.', -11132); } $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the released version cannot be empty.', -11131); } $isExisted = Version::where('project_key', $project_key) ->where('name', $name) ->exists(); - if ($isExisted) - { + if ($isExisted) { throw new \UnexpectedValueException('the released version has been existed.', -11133); } $user = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; $version = Version::create([ 'project_key' => $project_key, 'user' => $user, 'status' => 'released', 'released_time' => time() ] + $request->all()); - foreach ($ids as $id) - { + foreach ($ids as $id) { DB::collection('issue_' . $project_key)->where('_id', $id)->update([ 'resolve_version' => $version->id ]); // add to histroy table $snap_id = Provider::snap2His($project_key, $id, null, [ 'resolve_version' ]); // trigger event of issue moved - Event::fire(new IssueEvent($project_key, $id, $user, [ 'event_key' => 'edit_issue', 'snap_id' => $snap_id ] )); + Event::fire(new IssueEvent($project_key, $id, $user, [ 'event_key' => 'edit_issue', 'snap_id' => $snap_id ])); } $isSendMsg = $request->input('isSendMsg') && true; @@ -1781,21 +1549,18 @@ public function release(Request $request, $project_key) /** * get timetrack setting. * - * @return array + * @return array */ - function getTimeTrackSetting() + public function getTimeTrackSetting() { $options = [ 'w2d' => 5, 'd2h' => 8 ]; $setting = SysSetting::first(); - if ($setting && isset($setting->properties)) - { - if (isset($setting->properties['week2day'])) - { + if ($setting && isset($setting->properties)) { + if (isset($setting->properties['week2day'])) { $options['w2d'] = $setting->properties['week2day']; } - if (isset($setting->properties['day2hour'])) - { + if (isset($setting->properties['day2hour'])) { $options['d2h'] = $setting->properties['day2hour']; } } @@ -1807,7 +1572,7 @@ function getTimeTrackSetting() * * @return array */ - function getLinkRelations() + public function getLinkRelations() { $relations = [ [ 'id' => 'blocks', 'out' => 'blocks', 'in' => 'is blocked by' ], @@ -1826,30 +1591,22 @@ function getLinkRelations() */ public function classifyIssues($issues) { - if (!$issues) { return []; } + if (!$issues) { + return []; + } $classified_issues = []; - foreach ($issues as $issue) - { - if (isset($issue['parent']) && $issue['parent']) - { - if (isset($classified_issues[$issue['parent']['no']]) && $classified_issues[$issue['parent']['no']]) - { + foreach ($issues as $issue) { + if (isset($issue['parent']) && $issue['parent']) { + if (isset($classified_issues[$issue['parent']['no']]) && $classified_issues[$issue['parent']['no']]) { $classified_issues[$issue['parent']['no']][] = $issue; - } - else - { + } else { $classified_issues[$issue['parent']['no']] = [ $issue ]; } - } - else - { - if (isset($classified_issues[$issue['no']]) && $classified_issues[$issue['no']]) - { + } else { + if (isset($classified_issues[$issue['no']]) && $classified_issues[$issue['no']]) { array_unshift($classified_issues[$issue['no']], $issue); - } - else - { + } else { $classified_issues[$issue['no']] = [ $issue ]; } } @@ -1867,15 +1624,12 @@ public function classifyIssues($issues) public function addAvatar(&$issues) { $cache_avatars = []; - foreach ($issues as $key => $issue) - { - if (!isset($issue['assignee']) || !isset($issue['assignee']['id'])) - { + foreach ($issues as $key => $issue) { + if (!isset($issue['assignee']) || !isset($issue['assignee']['id'])) { continue; } //get assignee avatar for kanban - if (!array_key_exists($issue['assignee']['id'], $cache_avatars)) - { + if (!array_key_exists($issue['assignee']['id'], $cache_avatars)) { $user = Sentinel::findById($issue['assignee']['id']); $cache_avatars[$issue['assignee']['id']] = isset($user->avatar) ? $user->avatar : ''; } @@ -1893,10 +1647,8 @@ public function addAvatar(&$issues) public function flatIssues($classified_issues) { $issues = []; - foreach ($classified_issues as $some) - { - foreach ($some as $one) - { + foreach ($classified_issues as $some) { + foreach ($some as $one) { $issues[] = $one; } } @@ -1911,12 +1663,11 @@ public function flatIssues($classified_issues) * @param string $from * @param string $from_board_id * @param bool $isUpdRank - * @return array + * @return array */ public function arrangeIssues($project_key, $issues, $from, $from_board_id, $isUpdRank=false) { - if ($from === 'his_sprint') - { + if ($from === 'his_sprint') { $this->addAvatar($issues); return $issues; } @@ -1926,20 +1677,17 @@ public function arrangeIssues($project_key, $issues, $from, $from_board_id, $isU // whether the board is ranked $rankmap = BoardRankMap::where([ 'board_id' => $from_board_id ])->first(); - if (!$rankmap) - { + if (!$rankmap) { $issues = $this->flatIssues($classified_issues); $rank = []; - foreach ($issues as $issue) - { + foreach ($issues as $issue) { $rank[] = $issue['no']; } BoardRankMap::create([ 'board_id' => $from_board_id, 'rank' => $rank ]); - if ($from === 'active_sprint') - { + if ($from === 'active_sprint') { $issues = $this->sprintFilter($project_key, $issues); } @@ -1947,110 +1695,89 @@ public function arrangeIssues($project_key, $issues, $from, $from_board_id, $isU return $issues; } - $sub2parent_map = []; - foreach ($issues as $issue) - { - if (isset($issue['parent']) && $issue['parent']) - { + $sub2parent_map = []; + foreach ($issues as $issue) { + if (isset($issue['parent']) && $issue['parent']) { $sub2parent_map[$issue['no']] = $issue['parent']['no']; } } - $rank = $rankmap->rank; - foreach ($classified_issues as $no => $some) - { - if (count($some) <= 1) { continue; } + $rank = $rankmap->rank; + foreach ($classified_issues as $no => $some) { + if (count($some) <= 1) { + continue; + } $group_issues = []; - foreach ($some as $one) - { + foreach ($some as $one) { $group_issues[$one['no']] = $one; } $sorted_group_issues = []; - foreach ($rank as $val) - { - if (isset($group_issues[$val])) - { + foreach ($rank as $val) { + if (isset($group_issues[$val])) { $sorted_group_issues[$val] = $group_issues[$val]; } } - foreach ($group_issues as $no2 => $issue) - { - if (!isset($sorted_group_issues[$no2])) - { + foreach ($group_issues as $no2 => $issue) { + if (!isset($sorted_group_issues[$no2])) { $sorted_group_issues[$no2] = $issue; } } $classified_issues[$no] = array_values($sorted_group_issues); - // prevent the sort confusion + // prevent the sort confusion $parentInd = 0; - foreach ($classified_issues[$no] as $sk => $si) - { - if ($si['no'] === $no) - { + foreach ($classified_issues[$no] as $sk => $si) { + if ($si['no'] === $no) { $parentInd = $sk; break; } } - if ($parentInd > 0) - { + if ($parentInd > 0) { $pi = array_splice($classified_issues[$no], $parentInd, 1); array_unshift($classified_issues[$no], array_pop($pi)); } } $sorted_issues = []; - foreach ($rank as $val) - { - if (isset($classified_issues[$val]) && $classified_issues[$val]) - { - $sorted_issues[$val] = $classified_issues[$val]; - } - else - { - if (isset($sub2parent_map[$val]) && $sub2parent_map[$val]) - { + foreach ($rank as $val) { + if (isset($classified_issues[$val]) && $classified_issues[$val]) { + $sorted_issues[$val] = $classified_issues[$val]; + } else { + if (isset($sub2parent_map[$val]) && $sub2parent_map[$val]) { $parent = $sub2parent_map[$val]; - if (!isset($sorted_issues[$parent])) - { - $sorted_issues[$parent] = $classified_issues[$parent]; + if (!isset($sorted_issues[$parent])) { + $sorted_issues[$parent] = $classified_issues[$parent]; } } } } // append some issues which is ranked - foreach ($classified_issues as $key => $val) - { - if (!isset($sorted_issues[$key])) - { + foreach ($classified_issues as $key => $val) { + if (!isset($sorted_issues[$key])) { $sorted_issues[$key] = $val; } } // convert array to ordered array - $issues = $this->flatIssues($sorted_issues); + $issues = $this->flatIssues($sorted_issues); - if ($isUpdRank) - { + if ($isUpdRank) { $new_rank = []; - foreach ($issues as $issue) - { + foreach ($issues as $issue) { $new_rank[] = $issue['no']; } - if (array_diff_assoc($new_rank, $rank) || array_diff_assoc($rank, $new_rank)) - { + if (array_diff_assoc($new_rank, $rank) || array_diff_assoc($rank, $new_rank)) { $rankmap = BoardRankMap::where('board_id', $from_board_id)->first(); $rankmap && $rankmap->update([ 'rank' => $new_rank ]); } } - if ($from === 'active_sprint') - { + if ($from === 'active_sprint') { $issues = $this->sprintFilter($project_key, $issues); } @@ -2070,24 +1797,21 @@ public function sprintFilter($project_key, $issues) $active_sprint_issues = []; $active_sprint_issue_nos = []; $active_sprint = Sprint::where('project_key', $project_key)->where('status', 'active')->first(); - if ($active_sprint && isset($active_sprint->issues) && $active_sprint->issues) - { + if ($active_sprint && isset($active_sprint->issues) && $active_sprint->issues) { $active_sprint_issue_nos = $active_sprint->issues; } - foreach($issues as $issue) - { - if (in_array($issue['no'], $active_sprint_issue_nos)) - { + foreach ($issues as $issue) { + if (in_array($issue['no'], $active_sprint_issue_nos)) { $active_sprint_issues[] = $issue; - } + } } return $active_sprint_issues; } /** - * get some options for export + * get some options for export * * @param string $project_key * @return array @@ -2096,69 +1820,59 @@ public function getOptionsForExport($project_key) { $types = []; $type_list = Provider::getTypeList($project_key); - foreach ($type_list as $type) - { + foreach ($type_list as $type) { $types[$type->id] = $type->name; } $states = []; $state_list = Provider::getStateOptions($project_key); - foreach ($state_list as $state) - { + foreach ($state_list as $state) { $states[$state['_id']] = $state['name']; } $resolutions = []; $resolution_list = Provider::getResolutionOptions($project_key); - foreach ($resolution_list as $resolution) - { + foreach ($resolution_list as $resolution) { $resolutions[$resolution['_id']] = $resolution['name']; } $priorities = []; $priority_list = Provider::getPriorityOptions($project_key); - foreach ($priority_list as $priority) - { + foreach ($priority_list as $priority) { $priorities[$priority['_id']] = $priority['name']; } $versions = []; $version_list = Provider::getVersionList($project_key); - foreach($version_list as $version) - { + foreach ($version_list as $version) { $versions[$version->id] = $version->name; } $modules = []; $module_list = Provider::getModuleList($project_key); - foreach ($module_list as $module) - { + foreach ($module_list as $module) { $modules[$module->id] = $module->name; } $epics = []; $epic_list = Provider::getEpicList($project_key); - foreach ($epic_list as $epic) - { + foreach ($epic_list as $epic) { $epics[$epic['_id']] = $epic['name']; } $sprints = []; $sprint_list = Provider::getSprintList($project_key); - foreach ($sprint_list as $sprint) - { + foreach ($sprint_list as $sprint) { $sprints[$sprint['no']] = $sprint['name']; } $fields = []; $field_list = Provider::getFieldList($project_key); - foreach ($field_list as $field) - { + foreach ($field_list as $field) { $tmp = []; $tmp['name'] = $field->name; $tmp['type'] = $field->type; - if (isset($field->optionValues)) - { + if (isset($field->optionValues)) { $tmp['optionValues'] = $field->optionValues; } $fields[$field->key] = $tmp; @@ -2187,7 +1901,6 @@ public function getOptionsForExport($project_key) 'sprints' => $sprints, 'fields' => $fields, ]; - } /** @@ -2200,40 +1913,34 @@ public function imports(Request $request, $project_key) { set_time_limit(0); - if (!($fid = $request->input('fid'))) - { + if (!($fid = $request->input('fid'))) { throw new \UnexpectedValueException('导入文件ID不能为空。', -11140); } $pattern = $request->input('pattern'); - if (!isset($pattern)) - { + if (!isset($pattern)) { $pattern = '1'; } $file = config('filesystems.disks.local.root', '/tmp') . '/' . substr($fid, 0, 2) . '/' . $fid; - if (!file_exists($file)) - { + if (!file_exists($file)) { throw new \UnexpectedValueException('获取导入文件失败。', -11141); } $err_msgs = []; $fatal_err_msgs = []; - Excel::load($file, function($reader) use($project_key, $pattern, &$err_msgs, &$fatal_err_msgs) { + Excel::load($file, function ($reader) use ($project_key, $pattern, &$err_msgs, &$fatal_err_msgs) { $reader = $reader->getSheet(0); $data = $reader->toArray(); - if (!$data) - { + if (!$data) { $fatal_err_msgs = $err_msgs = '文件内容不能为空。'; return; } $new_fields = []; $fields = Provider::getFieldList($project_key); - foreach($fields as $field) - { - if ($field->type !== 'File') - { + foreach ($fields as $field) { + if ($field->type !== 'File') { $new_fields[$field->key] = $field->name; } } @@ -2251,27 +1958,18 @@ public function imports(Request $request, $project_key) // arrange the excel data $data = $this->arrangeExcel($data, $fields); - foreach ($data as $val) - { - if (!isset($val['title']) && !isset($val['type'])) - { + foreach ($data as $val) { + if (!isset($val['title']) && !isset($val['type'])) { $fatal_err_msgs = $err_msgs = '主题列和类型列没找到。'; - } - else if (!isset($val['title'])) - { + } elseif (!isset($val['title'])) { $fatal_err_msgs = $err_msgs = '主题列没找到。'; - } - else if (!isset($val['type'])) - { + } elseif (!isset($val['type'])) { $fatal_err_msgs = $err_msgs = '类型列没找到。'; - } - else if (!$val['title']) - { + } elseif (!$val['title']) { $fatal_err_msgs = $err_msgs = '主题列不能有空值。'; } - if ($err_msgs) - { + if ($err_msgs) { return; } } @@ -2280,8 +1978,7 @@ public function imports(Request $request, $project_key) $new_types = []; $standard_type_ids = []; $types = Provider::getTypeList($project_key); - foreach ($types as $type) - { + foreach ($types as $type) { $tmp = []; $tmp['id'] = $type->id; $tmp['name'] = $type->name; @@ -2289,8 +1986,7 @@ public function imports(Request $request, $project_key) $tmp['workflow'] = $type->workflow; $tmp['schema'] = Provider::getSchemaByType($type->id); $new_types[$type->name] = $tmp; - if ($tmp['type'] == 'standard') - { + if ($tmp['type'] == 'standard') { $standard_type_ids[] = $tmp['id']; } } @@ -2299,8 +1995,7 @@ public function imports(Request $request, $project_key) // get the state option $new_priorities = []; $priorities = Provider::getPriorityOptions($project_key); - foreach($priorities as $priority) - { + foreach ($priorities as $priority) { $new_priorities[$priority['name']] = $priority['_id']; } $priorities = $new_priorities; @@ -2308,8 +2003,7 @@ public function imports(Request $request, $project_key) // get the state option $new_states = []; $states = Provider::getStateOptions($project_key); - foreach($states as $state) - { + foreach ($states as $state) { $new_states[$state['name']] = $state['_id']; } $states = $new_states; @@ -2317,15 +2011,13 @@ public function imports(Request $request, $project_key) // get the state option $new_resolutions = []; $resolutions = Provider::getResolutionOptions($project_key); - foreach($resolutions as $resolution) - { + foreach ($resolutions as $resolution) { $new_resolutions[$resolution['name']] = $resolution['_id']; } $resolutions = $new_resolutions; // initialize the error msg - foreach ($data as $val) - { + foreach ($data as $val) { $err_msgs[$val['title']] = []; $fatal_err_msgs[$val['title']] = []; } @@ -2334,91 +2026,63 @@ public function imports(Request $request, $project_key) $standard_issues = []; $subtask_issues = []; - foreach ($data as $value) - { + foreach ($data as $value) { $issue = []; $cur_title = $issue['title'] = $value['title']; - if (!$value['type']) - { + if (!$value['type']) { $fatal_err_msgs[$cur_title][] = $err_msgs[$cur_title][] = '类型列不能有空值。'; continue; - } - else if (!isset($types[$value['type']])) - { + } elseif (!isset($types[$value['type']])) { $fatal_err_msgs[$cur_title][] = $err_msgs[$cur_title][] = '类型列值匹配失败。'; continue; - } - else - { + } else { $issue['type'] = $types[$value['type']]['id']; } - if ($types[$value['type']]['type'] === 'subtask' && (!isset($value['parent']) || !$value['parent'])) - { + if ($types[$value['type']]['type'] === 'subtask' && (!isset($value['parent']) || !$value['parent'])) { $fatal_err_msgs[$cur_title][] = $err_msgs[$cur_title][] = '父级任务列不能为空。'; - } - else - { + } else { $issue['parent'] = $value['parent']; } - if (isset($value['priority']) && $value['priority']) - { - if (!isset($priorities[$value['priority']]) || !$priorities[$value['priority']]) - { + if (isset($value['priority']) && $value['priority']) { + if (!isset($priorities[$value['priority']]) || !$priorities[$value['priority']]) { $err_msgs[$cur_title][] = '优先级列值匹配失败。'; - } - else - { + } else { $issue['priority'] = $priorities[$value['priority']]; } } - if (isset($value['state']) && $value['state']) - { - if (!isset($states[$value['state']]) || !$states[$value['state']]) - { + if (isset($value['state']) && $value['state']) { + if (!isset($states[$value['state']]) || !$states[$value['state']]) { $err_msgs[$cur_title][] = '状态列值匹配失败。'; - } - else - { + } else { $issue['state'] = $states[$value['state']]; $workflow = $types[$value['type']]['workflow']; - if (!in_array($issue['state'], $workflow['state_ids'])) - { + if (!in_array($issue['state'], $workflow['state_ids'])) { $err_msgs[$cur_title][] = '状态列值不在相应流程里。'; } } } - if (isset($value['resolution']) && $value['resolution']) - { - if (!isset($resolutions[$value['resolution']]) || !$resolutions[$value['resolution']]) - { + if (isset($value['resolution']) && $value['resolution']) { + if (!isset($resolutions[$value['resolution']]) || !$resolutions[$value['resolution']]) { $err_msgs[$cur_title][] = '解决结果列值匹配失败。'; - } - else - { + } else { $issue['resolution'] = $resolutions[$value['resolution']]; } } $user_relate_fields = [ 'assignee' => '经办人', 'reporter' => '报告者', 'resolver' => '解决者', 'closer' => '关闭时间' ]; - foreach ($user_relate_fields as $uk => $uv) - { - if (isset($value[$uk]) && $value[$uk]) - { + foreach ($user_relate_fields as $uk => $uv) { + if (isset($value[$uk]) && $value[$uk]) { $tmp_user = EloquentUser::where('first_name', $value[$uk])->first(); - if (!$tmp_user) - { + if (!$tmp_user) { $err_msgs[$cur_title][] = $uv . '列用户不存在。'; - } - else - { + } else { $issue[$uk] = [ 'id' => $tmp_user->id, 'name' => $tmp_user->first_name, 'email' => $tmp_user->email ]; - if ($uk == 'resolver') - { + if ($uk == 'resolver') { $issue['his_resolvers'] = [ $tmp_user->id ]; } } @@ -2426,43 +2090,32 @@ public function imports(Request $request, $project_key) } $time_relate_fields = [ 'created_at' => '创建时间', 'resolved_at' => '解决时间', 'closed_at' => '关闭时间', 'updated_at' => '更新时间' ]; - foreach ($time_relate_fields as $tk => $tv) - { - if (isset($value[$tk]) && $value[$tk]) - { + foreach ($time_relate_fields as $tk => $tv) { + if (isset($value[$tk]) && $value[$tk]) { $stamptime = strtotime($value[$tk]); - if ($stamptime === false) - { + if ($stamptime === false) { $err_msgs[$cur_title][] = $tv . '列值格式错误。'; - } - else - { + } else { $issue[$tk] = $stamptime; } } } $schema = $types[$value['type']]['schema']; - foreach ($schema as $field) - { - if (isset($field['required']) && $field['required'] && (!isset($value[$field['key']]) || !$value[$field['key']])) - { + foreach ($schema as $field) { + if (isset($field['required']) && $field['required'] && (!isset($value[$field['key']]) || !$value[$field['key']])) { $err_msgs[$cur_title][] = $fields[$field['key']] . '列值不能为空。'; continue; } - if (isset($value[$field['key']]) && $value[$field['key']]) - { + if (isset($value[$field['key']]) && $value[$field['key']]) { $field_key = $field['key']; $field_value = $value[$field['key']]; - } - else - { + } else { continue; } - if (in_array($field_key, [ 'priority', 'resolution', 'assignee' ])) - { + if (in_array($field_key, [ 'priority', 'resolution', 'assignee' ])) { continue; } @@ -2476,139 +2129,94 @@ public function imports(Request $request, $project_key) // } // $issue['sprints'] = $new_sprints; //} - if ($field_key == 'labels') - { + if ($field_key == 'labels') { $issue['labels'] = []; - foreach (explode(',', $field_value) as $val) - { - if (trim($val)) - { - $issue['labels'][] = trim($val); + foreach (explode(',', $field_value) as $val) { + if (trim($val)) { + $issue['labels'][] = trim($val); } } $issue['labels'] = array_values(array_unique($issue['labels'])); - } - else if ($field['type'] === 'SingleUser' || $field_key === 'assignee') - { + } elseif ($field['type'] === 'SingleUser' || $field_key === 'assignee') { $tmp_user = EloquentUser::where('first_name', $field_value)->first(); - if (!$tmp_user) - { + if (!$tmp_user) { $err_msgs[$cur_title][] = $fields[$field_key] . '列用户不存在。'; - } - else - { + } else { $issue[$field_key] = [ 'id' => $tmp_user->id, 'name' => $tmp_user->first_name, 'email' => $tmp_user->email ]; } - } - else if ($field['type'] === 'MultiUser') - { + } elseif ($field['type'] === 'MultiUser') { $issue[$field_key] = []; $issue[$field_key . '_ids'] = []; - foreach(explode(',', $field_value) as $val) - { - if (!trim($val)) - { + foreach (explode(',', $field_value) as $val) { + if (!trim($val)) { continue; } $tmp_user = EloquentUser::where('first_name', trim($val))->first(); - if (!$tmp_user) - { + if (!$tmp_user) { $err_msgs[$cur_title][] = $fields[$field_key] . '列用户不存在。'; - } - else if (!in_array($tmp_user->id, $issue[$field_key . '_ids'])) - { + } elseif (!in_array($tmp_user->id, $issue[$field_key . '_ids'])) { $issue[$field_key][] = [ 'id' => $tmp_user->id, 'name' => $tmp_user->first_name, 'email' => $tmp_user->email ]; $issue[$field_key . '_ids'][] = $tmp_user->id; } } - } - else if (in_array($field['type'], [ 'Select', 'RadioGroup', 'SingleVersion' ])) - { - foreach ($field['optionValues'] as $val) - { - if ($val['name'] === $field_value) - { + } elseif (in_array($field['type'], [ 'Select', 'RadioGroup', 'SingleVersion' ])) { + foreach ($field['optionValues'] as $val) { + if ($val['name'] === $field_value) { $issue[$field_key] = $val['id']; break; } } - if (!isset($issue[$field_key])) - { + if (!isset($issue[$field_key])) { $err_msgs[$cur_title][] = $fields[$field_key] . '列值匹配失败。'; } - } - else if (in_array($field['type'], [ 'MultiSelect', 'CheckboxGroup', 'MultiVersion' ])) - { + } elseif (in_array($field['type'], [ 'MultiSelect', 'CheckboxGroup', 'MultiVersion' ])) { $issue[$field_key] = []; - foreach (explode(',', $field_value) as $val) - { + foreach (explode(',', $field_value) as $val) { $val = trim($val); - if (!$val) - { + if (!$val) { continue; } $isMatched = false; - foreach ($field['optionValues'] as $val2) - { - if ($val2['name'] === $val) - { + foreach ($field['optionValues'] as $val2) { + if ($val2['name'] === $val) { $issue[$field_key][] = $val2['id']; $isMatched = true; break; } } - if (!$isMatched) - { + if (!$isMatched) { $err_msgs[$cur_title][] = $fields[$field_key] . '列值匹配失败。'; } } $issue[$field_key] = array_values(array_unique($issue[$field_key])); - } - else if (in_array($field['type'], [ 'DatePicker', 'DatetimePicker' ])) - { + } elseif (in_array($field['type'], [ 'DatePicker', 'DatetimePicker' ])) { $stamptime = strtotime($field_value); - if ($stamptime === false) - { + if ($stamptime === false) { $err_msgs[$cur_title][] = $fields[$field_key] . '列值格式错误。'; - } - else - { + } else { $issue[$field_key] = $stamptime; } - } - else if ($field['type'] === 'TimeTracking') - { - if (!$this->ttCheck($field_value)) - { + } elseif ($field['type'] === 'TimeTracking') { + if (!$this->ttCheck($field_value)) { $err_msgs[$cur_title][] = $fields[$field_key] . '列值格式错误。'; - } - else - { + } else { $issue[$field_key] = $this->ttHandle($field_value); $issue[$field_key . '_m'] = $this->ttHandleInM($issue[$field_key]); } - } - else if ($field['type'] === 'Number') - { + } elseif ($field['type'] === 'Number') { $issue[$field_key] = floatval($field_value); - } - else - { + } else { $issue[$field_key] = $field_value; } } - if ($types[$value['type']]['type'] === 'subtask') - { + if ($types[$value['type']]['type'] === 'subtask') { $subtask_issues[] = $issue; - } - else - { + } else { $standard_titles[] = $issue['title']; - if (isset($issue['parent'])) - { + if (isset($issue['parent'])) { unset($issue['parent']); } $standard_issues[] = $issue; @@ -2616,49 +2224,37 @@ public function imports(Request $request, $project_key) } $new_subtask_issues = []; - foreach ($standard_titles as $title) - { + foreach ($standard_titles as $title) { $new_subtask_issues[$title] = []; } - foreach ($subtask_issues as $issue) - { - $parent_issues = array_filter($standard_issues, function($v) use ($issue) { return $v['title'] === $issue['parent']; }); - if (count($parent_issues) > 1) - { + foreach ($subtask_issues as $issue) { + $parent_issues = array_filter($standard_issues, function ($v) use ($issue) { + return $v['title'] === $issue['parent']; + }); + if (count($parent_issues) > 1) { $fatal_err_msgs[$issue['title']][] = $err_msgs[$issue['title']][] = '找到多个父级任务。'; - } - else if (count($parent_issues) == 1) - { + } elseif (count($parent_issues) == 1) { $parent_issue = array_pop($parent_issues); - if (isset($issue['parent'])) - { + if (isset($issue['parent'])) { unset($issue['parent']); } $new_subtask_issues[$parent_issue['title']][] = $issue; - } - else - { + } else { $parent_issues = DB::table('issue_' . $project_key) ->where('title', $issue['parent']) ->whereIn('type', $standard_type_ids) ->where('del_flg', '<>', 1) ->get(); - if (count($parent_issues) > 1) - { + if (count($parent_issues) > 1) { $fatal_err_msgs[$issue['title']][] = $err_msgs[$issue['title']][] = '找到多个父级任务。'; - } - else if (count($parent_issues) == 1) - { + } elseif (count($parent_issues) == 1) { $parent_issue = array_pop($parent_issues); - if (isset($issue['parent'])) - { + if (isset($issue['parent'])) { unset($issue['parent']); } $new_subtask_issues[] = $issue + [ 'parent_id' => $parent_issue['_id']->__toString() ]; - } - else - { + } else { $fatal_err_msgs[$issue['title']][] = $err_msgs[$issue['title']][] = '父级任务不存在。'; } } @@ -2667,43 +2263,33 @@ public function imports(Request $request, $project_key) $err_msgs = array_filter($err_msgs); $fatal_err_msgs = array_filter($fatal_err_msgs); - if ($pattern == '2') - { - if ($fatal_err_msgs) - { + if ($pattern == '2') { + if ($fatal_err_msgs) { return; } - } - else if ($err_msgs) - { + } elseif ($err_msgs) { return; } $new_types = []; - foreach($types as $type) - { + foreach ($types as $type) { $new_types[$type['id']] = $type; } $types = $new_types; - foreach ($subtask_issues as $issue) - { - if (isset($issue['parent_id']) && $issue['parent_id']) - { + foreach ($subtask_issues as $issue) { + if (isset($issue['parent_id']) && $issue['parent_id']) { $this->importIssue($project_key, $issue, $types[$issue['type']]['schema'], $types[$issue['type']]['workflow']); } } - foreach ($standard_issues as $issue) - { + foreach ($standard_issues as $issue) { $id = $this->importIssue($project_key, $issue, $types[$issue['type']]['schema'], $types[$issue['type']]['workflow']); - if (!isset($subtask_issues[$issue['title']]) || !$subtask_issues[$issue['title']]) - { + if (!isset($subtask_issues[$issue['title']]) || !$subtask_issues[$issue['title']]) { continue; } - foreach ($subtask_issues[$issue['title']] as $sub_issue) - { + foreach ($subtask_issues[$issue['title']] as $sub_issue) { $sub_issue['parent_id'] = $id; $this->importIssue($project_key, $sub_issue, $types[$sub_issue['type']]['schema'], $types[$sub_issue['type']]['workflow']); } @@ -2712,68 +2298,55 @@ public function imports(Request $request, $project_key) $emsgs = ''; - if ($pattern == '2') - { + if ($pattern == '2') { $emsgs = array_filter($fatal_err_msgs); - } - else - { + } else { $emsgs = array_filter($err_msgs); } - if ($emsgs) - { + if ($emsgs) { return Response()->json([ 'ecode' => -11146, 'emsg' => $emsgs ]); - } - else - { + } else { return Response()->json([ 'ecode' => 0, 'emsg' => '' ]); } } /** - * import the issue into the project + * import the issue into the project * * @param string $project_key * @param array $data * @param array $schema - * @return string id + * @return string id */ public function importIssue($project_key, $data, $schema, $workflow) { $table = 'issue_' . $project_key; $insValues = $data; - if (!isset($insValues['resolution']) || !$insValues['resolution']) - { + if (!isset($insValues['resolution']) || !$insValues['resolution']) { $insValues['resolution'] = 'Unresolved'; } $max_no = DB::collection($table)->count() + 1; $insValues['no'] = $max_no; - if (!isset($insValues['assignee']) || !$insValues['assignee']) - { + if (!isset($insValues['assignee']) || !$insValues['assignee']) { $insValues['assignee'] = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; } // get reporter(creator) - if (!isset($insValues['reporter']) || !$insValues['reporter']) - { + if (!isset($insValues['reporter']) || !$insValues['reporter']) { $insValues['reporter'] = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; } - if (!isset($insValues['created_at']) || !$insValues['created_at']) - { + if (!isset($insValues['created_at']) || !$insValues['created_at']) { $insValues['created_at'] = time(); } - if (!isset($data['state']) || !$data['state']) - { + if (!isset($data['state']) || !$data['state']) { $wf = $this->initializeWorkflow($data['type']); $insValues += $wf; - } - else if (in_array($data['state'], $workflow->state_ids ?: [])) - { + } elseif (in_array($data['state'], $workflow->state_ids ?: [])) { $wf = $this->initializeWorkflowForImport($workflow, $data['state']); $insValues += $wf; } @@ -2786,8 +2359,7 @@ public function importIssue($project_key, $data, $schema, $workflow) // trigger event of issue created Event::fire(new IssueEvent($project_key, $id, $insValues['reporter'], [ 'event_key' => 'create_issue' ])); - if (isset($insValues['labels']) && $insValues['labels']) - { + if (isset($insValues['labels']) && $insValues['labels']) { $this->createLabels($project_key, $insValues['labels']); } @@ -2810,16 +2382,13 @@ public function initializeWorkflowForImport($wf_definition, $state) $steps = isset($wf_contents['steps']) && $wf_contents['steps'] ? $wf_contents['steps'] : []; $fake_step = []; - foreach($steps as $step) - { - if (isset($step['state']) && $step['state'] == $state) - { + foreach ($steps as $step) { + if (isset($step['state']) && $step['state'] == $state) { $fake_step = $step; break; } } - if (!$fake_step) - { + if (!$fake_step) { return []; } @@ -2833,196 +2402,133 @@ public function initializeWorkflowForImport($wf_definition, $state) } /** - * export xls for issue list + * export xls for issue list * * @param string $project_key * @param array $export_fields * @param array $issues * @return void */ - public function export($project_key, $export_fields, $issues) + public function export($project_key, $export_fields, $issues) { set_time_limit(0); $options = $this->getOptionsForExport($project_key); - foreach ($options as $key => $val) - { + foreach ($options as $key => $val) { $$key = $val; } - foreach ($export_fields as $key => $field) - { - if (!array_key_exists($field, $fields)) - { + foreach ($export_fields as $key => $field) { + if (!array_key_exists($field, $fields)) { unset($export_fields[$key]); } } $export_fields = array_values($export_fields); $headers = []; - foreach ($export_fields as $fk) - { + foreach ($export_fields as $fk) { $headers[] = isset($fields[$fk]) && $fields[$fk] ? $fields[$fk]['name'] : ''; } $new_issues = []; - foreach ($issues as $issue) - { + foreach ($issues as $issue) { $tmp = []; - foreach ($export_fields as $fk) - { - if (!isset($issue[$fk]) || (!$issue[$fk] && $issue[$fk] !== 0)) - { + foreach ($export_fields as $fk) { + if (!isset($issue[$fk]) || (!$issue[$fk] && $issue[$fk] !== 0)) { $tmp[] = ''; continue; } - if (in_array($fk, [ 'assignee', 'reporter', 'closer', 'resolver' ])) - { + if (in_array($fk, [ 'assignee', 'reporter', 'closer', 'resolver' ])) { $tmp[] = isset($issue[$fk]['name']) ? $issue[$fk]['name'] : ''; - } - else if ($fk == 'module') - { + } elseif ($fk == 'module') { $new_modules = []; $module_ids = []; - if (is_array($issue[$fk])) - { + if (is_array($issue[$fk])) { $module_ids = $issue[$fk]; - } - else - { + } else { $module_ids = explode(',', $issue[$fk]); } - foreach ($module_ids as $id) - { - if (!isset($modules[$id]) || !$modules[$id]) - { + foreach ($module_ids as $id) { + if (!isset($modules[$id]) || !$modules[$id]) { continue; } $new_modules[] = $modules[$id]; } $tmp[] = implode(',', $new_modules); - } - else if ($fk == 'type') - { + } elseif ($fk == 'type') { $tmp[] = isset($types[$issue[$fk]]) && $types[$issue[$fk]] ? $types[$issue[$fk]] : ''; - } - else if ($fk == 'priority') - { + } elseif ($fk == 'priority') { $tmp[] = isset($priorities[$issue[$fk]]) && $priorities[$issue[$fk]] ? $priorities[$issue[$fk]] : ''; - } - else if ($fk == 'state') - { + } elseif ($fk == 'state') { $tmp[] = isset($states[$issue[$fk]]) && $states[$issue[$fk]] ? $states[$issue[$fk]] : ''; - } - else if ($fk == 'resolution') - { + } elseif ($fk == 'resolution') { $tmp[] = isset($resolutions[$issue[$fk]]) && $resolutions[$issue[$fk]] ? $resolutions[$issue[$fk]] : ''; - } - else if ($fk == 'epic') - { + } elseif ($fk == 'epic') { $tmp[] = isset($epics[$issue[$fk]]) && $epics[$issue[$fk]] ? $epics[$issue[$fk]] : ''; - } - else if ($fk == 'sprints') - { + } elseif ($fk == 'sprints') { $new_sprints = []; - foreach ($issue[$fk] as $sn) - { - if (isset($sprints[$sn])) - { + foreach ($issue[$fk] as $sn) { + if (isset($sprints[$sn])) { $new_sprints[] = $sprints[$sn]; } } $tmp[] = implode(',', $new_sprints); - } - else if ($fk == 'labels') - { + } elseif ($fk == 'labels') { $tmp[] = implode(',', $issue[$fk]); - } - else if ($fk == 'progress') - { + } elseif ($fk == 'progress') { $tmp[] = $issue[$fk] . '%'; - } - else if (isset($fields[$fk]) && $fields[$fk]) - { - if ($fields[$fk]['type'] == 'DateTimePicker') - { + } elseif (isset($fields[$fk]) && $fields[$fk]) { + if ($fields[$fk]['type'] == 'DateTimePicker') { $tmp[] = date('Y-m-d H:i:s', $issue[$fk]); - } - else if ($fields[$fk]['type'] == 'DatePicker') - { + } elseif ($fields[$fk]['type'] == 'DatePicker') { $tmp[] = date('Y-m-d', $issue[$fk]); - } - else if ($fields[$fk]['type'] == 'SingleVersion' || $fields[$fk]['type'] == 'MultiVersion') - { + } elseif ($fields[$fk]['type'] == 'SingleVersion' || $fields[$fk]['type'] == 'MultiVersion') { $new_versions = []; $version_ids = []; - if (is_array($issue[$fk])) - { + if (is_array($issue[$fk])) { $version_ids = $issue[$fk]; - } - else - { + } else { $version_ids = explode(',', $issue[$fk]); } - foreach ($version_ids as $id) - { - if (isset($versions[$id]) && $versions[$id]) - { + foreach ($version_ids as $id) { + if (isset($versions[$id]) && $versions[$id]) { $new_versions[] = $versions[$id]; } } $tmp[] = implode(',', $new_versions); - } - else if ($fields[$fk]['type'] == 'SingleUser') - { + } elseif ($fields[$fk]['type'] == 'SingleUser') { $tmp[] = isset($issue[$fk]['name']) ? $issue[$fk]['name'] : ''; - } - else if ($fields[$fk]['type'] == 'MultiUser') - { + } elseif ($fields[$fk]['type'] == 'MultiUser') { $new_users = []; - foreach ($issue[$fk] as $user) - { - if (isset($user['name']) && $user['name']) - { + foreach ($issue[$fk] as $user) { + if (isset($user['name']) && $user['name']) { $new_users[] = $user['name']; } } $tmp[] = implode(',', $new_users); - } - else - { - if (isset($fields[$fk]['optionValues']) && $fields[$fk]['optionValues']) - { + } else { + if (isset($fields[$fk]['optionValues']) && $fields[$fk]['optionValues']) { $tmpOptions = []; - foreach ($fields[$fk]['optionValues'] as $ov) - { + foreach ($fields[$fk]['optionValues'] as $ov) { $tmpOptions[$ov['id']] = $ov['name']; } $ov_ids = []; - if (is_array($issue[$fk])) - { - $ov_ids = $issue[$fk]; - } - else - { - $ov_ids = explode(',', $issue[$fk]); + if (is_array($issue[$fk])) { + $ov_ids = $issue[$fk]; + } else { + $ov_ids = explode(',', $issue[$fk]); } $ov_names = []; - foreach ($ov_ids as $ovid) - { - $ov_names[] = isset($tmpOptions[$ovid]) ? $tmpOptions[$ovid] : ''; + foreach ($ov_ids as $ovid) { + $ov_names[] = isset($tmpOptions[$ovid]) ? $tmpOptions[$ovid] : ''; } $tmp[] = implode(',', array_filter($ov_names)); - } - else - { + } else { $tmp[] = (string)$issue[$fk]; } } - } - else - { + } else { $tmp[] = (string)$issue[$fk]; } } @@ -3030,11 +2536,10 @@ public function export($project_key, $export_fields, $issues) } $file_name = $project_key . '-issues'; - Excel::create($file_name, function ($excel) use($headers, $new_issues) { - $excel->sheet('Sheetname', function ($sheet) use($headers, $new_issues) { + Excel::create($file_name, function ($excel) use ($headers, $new_issues) { + $excel->sheet('Sheetname', function ($sheet) use ($headers, $new_issues) { $sheet->appendRow($headers); - foreach ($new_issues as $issue) - { + foreach ($new_issues as $issue) { $sheet->appendRow($issue); } }); @@ -3051,26 +2556,19 @@ public function export($project_key, $export_fields, $issues) public function batchHandle(Request $request, $project_key) { $method = $request->input('method'); - if ($method == 'update') - { + if ($method == 'update') { $data = $request->input('data'); - if (!$data || !isset($data['ids']) || !$data['ids'] || !is_array($data['ids']) || !isset($data['values']) || !$data['values'] || !is_array($data['values'])) - { + if (!$data || !isset($data['ids']) || !$data['ids'] || !is_array($data['ids']) || !isset($data['values']) || !$data['values'] || !is_array($data['values'])) { throw new \UnexpectedValueException('the batch params has errors.', -11124); } return $this->batchUpdate($project_key, $data['ids'], $data['values']); - } - else if ($method == 'delete') - { + } elseif ($method == 'delete') { $data = $request->input('data'); - if (!$data || !isset($data['ids']) || !$data['ids'] || !is_array($data['ids'])) - { + if (!$data || !isset($data['ids']) || !$data['ids'] || !is_array($data['ids'])) { throw new \UnexpectedValueException('the batch params has errors.', -11124); } return $this->batchDelete($project_key, $data['ids']); - } - else - { + } else { throw new \UnexpectedValueException('the batch method has errors.', -11125); } } @@ -3084,22 +2582,19 @@ public function batchHandle(Request $request, $project_key) */ public function batchDelete($project_key, $ids) { - if (!$this->isPermissionAllowed($project_key, 'delete_issue')) - { + if (!$this->isPermissionAllowed($project_key, 'delete_issue')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } $user = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; $table = 'issue_' . $project_key; - foreach ($ids as $id) - { + foreach ($ids as $id) { $issue = DB::collection($table) ->where('_id', $id) ->where('del_flg', '<>', 1) ->first(); - if (!$issue) - { + if (!$issue) { continue; } @@ -3108,8 +2603,7 @@ public function batchDelete($project_key, $ids) ->where('parent_id', $id) ->where('del_flg', '<>', 1) ->get(); - foreach ($subtasks as $subtask) - { + foreach ($subtasks as $subtask) { $sub_id = $subtask['_id']->__toString(); DB::collection($table)->where('_id', $sub_id)->update([ 'del_flg' => 1 ]); @@ -3125,7 +2619,7 @@ public function batchDelete($project_key, $ids) // delete this issue DB::collection($table)->where('_id', $id)->update([ 'del_flg' => 1 ]); - // trigger event of issue deleted + // trigger event of issue deleted Event::fire(new IssueEvent($project_key, $id, $user, [ 'event_key' => 'del_issue' ])); } @@ -3142,23 +2636,19 @@ public function batchDelete($project_key, $ids) */ public function batchUpdate($project_key, $ids, $values) { - if (!$this->isPermissionAllowed($project_key, 'edit_issue')) - { + if (!$this->isPermissionAllowed($project_key, 'edit_issue')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } $schemas = []; $updValues = []; - if (isset($values['type'])) - { - if (!$values['type']) - { + if (isset($values['type'])) { + if (!$values['type']) { throw new \UnexpectedValueException('the issue type can not be empty.', -11100); } - if (!($schemas[$values['type']] = Provider::getSchemaByType($values['type']))) - { + if (!($schemas[$values['type']] = Provider::getSchemaByType($values['type']))) { throw new \UnexpectedValueException('the schema of the type is not existed.', -11101); } @@ -3167,75 +2657,53 @@ public function batchUpdate($project_key, $ids, $values) $new_fields = []; $fields = Provider::getFieldList($project_key); - foreach($fields as $field) - { + foreach ($fields as $field) { $new_fields[$field->key] = $field; } $fields = $new_fields; - foreach ($values as $key => $val) - { - if (!isset($fields[$key]) || $fields[$key]->type == 'File') - { + foreach ($values as $key => $val) { + if (!isset($fields[$key]) || $fields[$key]->type == 'File') { continue; } $field = $fields[$key]; - if ($field->type == 'DateTimePicker' || $field->type == 'DatePicker') - { - if ($val && $this->isTimestamp($val) === false) - { + if ($field->type == 'DateTimePicker' || $field->type == 'DatePicker') { + if ($val && $this->isTimestamp($val) === false) { throw new \UnexpectedValueException('the format of datepicker field is incorrect.', -11122); } $updValues[$key] = $val; - } - else if ($field->type == 'TimeTracking') - { - if ($val && !$this->ttCheck($val)) - { + } elseif ($field->type == 'TimeTracking') { + if ($val && !$this->ttCheck($val)) { throw new \UnexpectedValueException('the format of timetracking field is incorrect.', -11102); } $updValues[$key] = $this->ttHandle($val); $updValues[$key . '_m'] = $this->ttHandleInM($updValues[$key]); - } - else if ($key == 'assignee' || $field->type == 'SingleUser') - { + } elseif ($key == 'assignee' || $field->type == 'SingleUser') { $user_info = Sentinel::findById($val); - if ($user_info) - { + if ($user_info) { $updValues[$key] = [ 'id' => $val, 'name' => $user_info->first_name, 'email' => $user_info->email ]; } - } - else if ($field->type == 'MultiUser') - { + } elseif ($field->type == 'MultiUser') { $user_ids = $val; $updValues[$key] = []; $new_user_ids = []; - foreach ($user_ids as $uid) - { + foreach ($user_ids as $uid) { $user_info = Sentinel::findById($uid); - if ($user_info) - { + if ($user_info) { array_push($updValues[$key], [ 'id' => $uid, 'name' => $user_info->first_name, 'email' => $user_info->email ]); } $new_user_ids[] = $uid; } $updValues[$key . '_ids'] = $new_user_ids; - } - else if ($field->type === 'Number' || $field->type === 'Integer') - { - if ($val === '') - { + } elseif ($field->type === 'Number' || $field->type === 'Integer') { + if ($val === '') { $updValues[$key] = ''; - } - else - { + } else { $updValues[$key] = $field->type === 'Number' ? floatVal($val) : intVal($val); } - } - else - { + } else { $updValues[$key] = $val; } } @@ -3244,31 +2712,24 @@ public function batchUpdate($project_key, $ids, $values) $updValues['updated_at'] = time(); $table = 'issue_' . $project_key; - foreach ($ids as $id) - { + foreach ($ids as $id) { $issue = DB::collection($table)->find($id); - if (!$issue) - { + if (!$issue) { continue; } $schema = []; $type = isset($values['type']) ? $values['type'] : $issue['type']; - if (!isset($schemas[$type])) - { - if (!($schemas[$type] = $schema = Provider::getSchemaByType($type))) - { + if (!isset($schemas[$type])) { + if (!($schemas[$type] = $schema = Provider::getSchemaByType($type))) { continue; } - } - else - { + } else { $schema = $schemas[$type]; } $valid_keys = $this->getValidKeysBySchema($schema); - if (!array_only($updValues, $valid_keys)) - { + if (!array_only($updValues, $valid_keys)) { continue; } @@ -3282,11 +2743,10 @@ public function batchUpdate($project_key, $ids, $values) } // create the Labels for project - if (isset($updValues['labels']) && $updValues['labels']) - { + if (isset($updValues['labels']) && $updValues['labels']) { $this->createLabels($project_key, $updValues['labels']); } - return Response()->json([ 'ecode' => 0, 'data' => [ 'ids' => $ids ] ]); + return Response()->json([ 'ecode' => 0, 'data' => [ 'ids' => $ids ] ]); } } diff --git a/app/Http/Controllers/LabelsController.php b/app/Http/Controllers/LabelsController.php index a4b652e7a..c55573a95 100644 --- a/app/Http/Controllers/LabelsController.php +++ b/app/Http/Controllers/LabelsController.php @@ -30,8 +30,7 @@ public function __construct() public function index(Request $request, $project_key) { $labels = Labels::where([ 'project_key' => $project_key ])->orderBy('_id', 'asc')->get(); - foreach ($labels as $key => $label) - { + foreach ($labels as $key => $label) { $label->is_used = $this->isFieldUsedByIssue($project_key, 'labels', $label->toArray()); $completed_issue_cnt = $incompleted_issue_cnt = 0; @@ -61,13 +60,11 @@ public function index(Request $request, $project_key) public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -16100); } - if (Provider::isLabelExisted($project_key, $name)) - { + if (Provider::isLabelExisted($project_key, $name)) { throw new \UnexpectedValueException('label name cannot be repeated', -16102); } @@ -85,27 +82,22 @@ public function store(Request $request, $project_key) public function update(Request $request, $project_key, $id) { $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -16100); } } $label = Labels::find($id); - if (!$label || $project_key != $label->project_key) - { + if (!$label || $project_key != $label->project_key) { throw new \UnexpectedValueException('the label does not exist or is not in the project.', -16103); } - if ($label->name !== $name && Provider::isLabelExisted($project_key, $name)) - { + if ($label->name !== $name && Provider::isLabelExisted($project_key, $name)) { throw new \UnexpectedValueException('label name cannot be repeated', -16102); } - if ($label->name !== $name) - { + if ($label->name !== $name) { $this->updIssueLabels($project_key, $label->name, $name); } @@ -124,42 +116,31 @@ public function update(Request $request, $project_key, $id) public function delete(Request $request, $project_key, $id) { $label = Labels::find($id); - if (!$label || $project_key != $label->project_key) - { + if (!$label || $project_key != $label->project_key) { throw new \UnexpectedValueException('the label does not exist or is not in the project.', -16103); } $operate_flg = $request->input('operate_flg'); - if (!isset($operate_flg) || $operate_flg === '0') - { + if (!isset($operate_flg) || $operate_flg === '0') { $is_used = $this->isFieldUsedByIssue($project_key, 'labels', $label->toArray()); - if ($is_used) - { + if ($is_used) { throw new \UnexpectedValueException('the label has been used by some issues.', -16104); } - } - else if ($operate_flg === '1') - { + } elseif ($operate_flg === '1') { $swap_label = $request->input('swap_label'); - if (!isset($swap_label) || !$swap_label) - { + if (!isset($swap_label) || !$swap_label) { throw new \UnexpectedValueException('the swap label cannot be empty.', -16106); } $slabel = Labels::find($swap_label); - if (!$slabel || $project_key != $slabel->project_key) - { + if (!$slabel || $project_key != $slabel->project_key) { throw new \UnexpectedValueException('the swap label does not exist or is not in the project.', -16107); } $this->updIssueLabels($project_key, $label->name, $slabel->name); - } - else if ($operate_flg === '2') - { + } elseif ($operate_flg === '2') { $this->updIssueLabels($project_key, $label->name, ''); - } - else - { + } else { throw new \UnexpectedValueException('the operation has error.', -16105); } @@ -192,22 +173,16 @@ public function updIssueLabels($project_key, $source, $dest) ->where('del_flg', '<>', 1) ->get(); - foreach ($issues as $issue) - { + foreach ($issues as $issue) { $updValues = []; $newLabels = []; - foreach ($issue['labels'] as $label) - { - if ($source == $label) - { - if ($dest) - { + foreach ($issue['labels'] as $label) { + if ($source == $label) { + if ($dest) { $newLabels[] = $dest; } - } - else - { + } else { $newLabels[] = $label; } } diff --git a/app/Http/Controllers/LinkController.php b/app/Http/Controllers/LinkController.php index 6e929fe14..a9b75c2dc 100644 --- a/app/Http/Controllers/LinkController.php +++ b/app/Http/Controllers/LinkController.php @@ -30,8 +30,7 @@ public function store(Request $request, $project_key) { $values = []; $src = $request->input('src'); - if (!$src) - { + if (!$src) { throw new \UnexpectedValueException('the src issue value can not be empty.', -11151); } $values['src'] = $src; @@ -44,8 +43,7 @@ public function store(Request $request, $project_key) $values['relation'] = $relation; $dest = $request->input('dest'); - if (!$dest) - { + if (!$dest) { throw new \UnexpectedValueException('the dest issue value can not be empty.', -11152); } $values['dest'] = $dest; @@ -53,8 +51,7 @@ public function store(Request $request, $project_key) $values['creator'] = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; $isExists = Linked::whereRaw([ 'src' => $src, 'dest' => $dest ])->exists(); - if ($isExists || Linked::whereRaw([ 'dest' => $src, 'src' => $dest ])->exists()) - { + if ($isExists || Linked::whereRaw([ 'dest' => $src, 'src' => $dest ])->exists()) { throw new \UnexpectedValueException('the relation of two issues has been exists.', -11154); } @@ -68,7 +65,7 @@ public function store(Request $request, $project_key) $link['src'] = array_only($src_issue, ['_id', 'no', 'type', 'title', 'state']); $dest_issue = DB::collection('issue_' . $project_key)->where('_id', $dest)->first(); - $link['dest'] = array_only($dest_issue, ['_id', 'no', 'type', 'title', 'state']); + $link['dest'] = array_only($dest_issue, ['_id', 'no', 'type', 'title', 'state']); // trigger event of issue linked Event::fire(new IssueEvent($project_key, $src, $values['creator'], [ 'event_key' => 'create_link', 'data' => [ 'dest' => $dest, 'relation' => $relation ]])); @@ -85,8 +82,7 @@ public function store(Request $request, $project_key) public function destroy($project_key, $id) { $link = Linked::find($id); - if (!$link) - { + if (!$link) { throw new \UnexpectedValueException('the link does not exist or is not in the project.', -11155); } diff --git a/app/Http/Controllers/ModuleController.php b/app/Http/Controllers/ModuleController.php index d64b9f452..4d7e3e84e 100644 --- a/app/Http/Controllers/ModuleController.php +++ b/app/Http/Controllers/ModuleController.php @@ -31,9 +31,8 @@ public function __construct() public function index($project_key) { $modules = Module::whereRaw([ 'project_key' => $project_key ])->orderBy('sn', 'asc')->get(); - foreach ($modules as $module) - { - $module->is_used = $this->isFieldUsedByIssue($project_key, 'module', $module->toArray()); + foreach ($modules as $module) { + $module->is_used = $this->isFieldUsedByIssue($project_key, 'module', $module->toArray()); } $users = Provider::getUserList($project_key); return Response()->json([ 'ecode' => 0, 'data' => $modules, 'options' => [ 'users' => $users ] ]); @@ -48,29 +47,26 @@ public function index($project_key) public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -11400); } - if (Module::whereRaw([ 'name' => $name ])->exists()) - { + if (Module::whereRaw([ 'name' => $name ])->exists()) { throw new \UnexpectedValueException('module name cannot be repeated', -11401); } $principal = []; $principal_id = $request->input('principal'); - if (isset($principal_id)) - { + if (isset($principal_id)) { $user_info = Sentinel::findById($principal_id); $principal = [ 'id' => $principal_id, 'name' => $user_info->first_name ]; } $creator = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; - $module = Module::create([ - 'project_key' => $project_key, - 'principal' => $principal, - 'sn' => time(), + $module = Module::create([ + 'project_key' => $project_key, + 'principal' => $principal, + 'sn' => time(), 'creator' => $creator ] + $request->all()); // trigger event of version added @@ -103,39 +99,29 @@ public function show($project_key, $id) public function update(Request $request, $project_key, $id) { $module = Module::find($id); - if (!$module || $module->project_key != $project_key) - { + if (!$module || $module->project_key != $project_key) { throw new \UnexpectedValueException('the module does not exist or is not in the project.', -11402); } $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -11400); } - if ($module->name !== $name && Module::whereRaw([ 'name' => $name ])->exists()) - { + if ($module->name !== $name && Module::whereRaw([ 'name' => $name ])->exists()) { throw new \UnexpectedValueException('module name cannot be repeated', -11401); } } $principal_id = $request->input('principal'); - if (isset($principal_id)) - { - if ($principal_id) - { + if (isset($principal_id)) { + if ($principal_id) { $user_info = Sentinel::findById($principal_id); $principal = [ 'id' => $principal_id, 'name' => $user_info->first_name ]; - } - else - { + } else { $principal = []; } - } - else - { + } else { $principal = isset($module['principal']) ? $module['principal'] : []; } @@ -158,57 +144,43 @@ public function update(Request $request, $project_key, $id) public function delete(Request $request, $project_key, $id) { $module = Module::find($id); - if (!$module || $project_key != $module->project_key) - { + if (!$module || $project_key != $module->project_key) { throw new \UnexpectedValueException('the module does not exist or is not in the project.', -11402); } $operate_flg = $request->input('operate_flg'); - if (!isset($operate_flg) || $operate_flg === '0') - { + if (!isset($operate_flg) || $operate_flg === '0') { $is_used = $this->isFieldUsedByIssue($project_key, 'module', $module->toArray()); - if ($is_used) - { + if ($is_used) { throw new \UnexpectedValueException('the module has been used by some issues.', -11403); } - } - else if ($operate_flg === '1') - { + } elseif ($operate_flg === '1') { $swap_module = $request->input('swap_module'); - if (!isset($swap_module) || !$swap_module) - { + if (!isset($swap_module) || !$swap_module) { throw new \UnexpectedValueException('the swap module cannot be empty.', -11405); } $smodule = Module::find($swap_module); - if (!$smodule || $project_key != $smodule->project_key) - { + if (!$smodule || $project_key != $smodule->project_key) { throw new \UnexpectedValueException('the swap module does not exist or is not in the project.', -11406); } $this->updIssueModule($project_key, $id, $swap_module); - } - else if ($operate_flg === '2') - { + } elseif ($operate_flg === '2') { $this->updIssueModule($project_key, $id, ''); - } - else - { + } else { throw new \UnexpectedValueException('the operation has error.', -11404); } Module::destroy($id); - // trigger event of module deleted + // trigger event of module deleted //$cur_user = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; //Event::fire(new ModuleEvent($project_key, $cur_user, [ 'event_key' => 'del_module', 'data' => $module->name ])); - if ($operate_flg === '1') - { + if ($operate_flg === '1') { return $this->show($project_key, $request->input('swap_module')); - } - else - { + } else { return Response()->json(['ecode' => 0, 'data' => [ 'id' => $id ]]); } } @@ -228,24 +200,18 @@ public function updIssueModule($project_key, $source, $dest) ->where('del_flg', '<>', 1) ->get(); - foreach ($issues as $issue) - { + foreach ($issues as $issue) { $updValues = []; - if (is_string($issue['module'])) - { - if ($issue['module'] === $source) - { + if (is_string($issue['module'])) { + if ($issue['module'] === $source) { $updValues['module'] = $dest; } - } - else if (is_array($issue['module'])) - { + } elseif (is_array($issue['module'])) { $updValues['module'] = array_values(array_filter(array_unique(str_replace($source, $dest, $issue['module'])))); } - if ($updValues) - { + if ($updValues) { $updValues['modifier'] = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; $updValues['updated_at'] = time(); @@ -270,14 +236,11 @@ public function handle(Request $request, $project_key) { // set module sort. $sequence_modules = $request->input('sequence') ?: []; - if ($sequence_modules) - { + if ($sequence_modules) { $i = 1; - foreach ($sequence_modules as $module_id) - { + foreach ($sequence_modules as $module_id) { $module = Module::find($module_id); - if (!$module || $module->project_key != $project_key) - { + if (!$module || $module->project_key != $project_key) { continue; } $module->sn = $i++; diff --git a/app/Http/Controllers/MysettingController.php b/app/Http/Controllers/MysettingController.php index ad2d0fa18..9c022110b 100644 --- a/app/Http/Controllers/MysettingController.php +++ b/app/Http/Controllers/MysettingController.php @@ -1,5 +1,6 @@ user->id); $avatar_save_path = config('filesystems.disks.local.root', '/tmp') . '/avatar/'; - if (!is_dir($avatar_save_path)) - { + if (!is_dir($avatar_save_path)) { @mkdir($avatar_save_path); } $filename = '/tmp/' . $basename; $data = $request->input('data'); - if (!$data) - { + if (!$data) { throw new \UnexpectedValueException('the uploaded avatar file can not be empty.', -15006); } file_put_contents($filename, base64_decode($data)); $fileinfo = getimagesize($filename); - if ($fileinfo['mime'] == 'image/jpeg' || $fileinfo['mime'] == 'image/jpg' || $fileinfo['mime'] == 'image/png' || $fileinfo['mime'] == 'image/gif') - { + if ($fileinfo['mime'] == 'image/jpeg' || $fileinfo['mime'] == 'image/jpg' || $fileinfo['mime'] == 'image/png' || $fileinfo['mime'] == 'image/gif') { $size = getimagesize($filename); - $width = $size[0]; $height = $size[1]; + $width = $size[0]; + $height = $size[1]; $scale = $width < $height ? $height : $width; $thumbnails_width = floor(150 * $width / $scale); $thumbnails_height = floor(150 * $height / $scale); $thumbnails_filename = $filename . '_thumbnails'; - if ($scale <= 150) - { + if ($scale <= 150) { @copy($filename, $thumbnails_filename); - } - else if ($fileinfo['mime'] == 'image/jpeg' || $fileinfo['mime'] == 'image/jpg') - { + } elseif ($fileinfo['mime'] == 'image/jpeg' || $fileinfo['mime'] == 'image/jpg') { $src_image = imagecreatefromjpeg($filename); $dst_image = imagecreatetruecolor($thumbnails_width, $thumbnails_height); imagecopyresized($dst_image, $src_image, 0, 0, 0, 0, $thumbnails_width, $thumbnails_height, $width, $height); imagejpeg($dst_image, $thumbnails_filename); - } - else if ($fileinfo['mime'] == 'image/png') - { + } elseif ($fileinfo['mime'] == 'image/png') { $src_image = imagecreatefrompng($filename); $dst_image = imagecreatetruecolor($thumbnails_width, $thumbnails_height); imagecopyresized($dst_image, $src_image, 0, 0, 0, 0, $thumbnails_width, $thumbnails_height, $width, $height); imagepng($dst_image, $thumbnails_filename); - } - else if ($fileinfo['mime'] == 'image/gif') - { + } elseif ($fileinfo['mime'] == 'image/gif') { $src_image = imagecreatefromgif($filename); $dst_image = imagecreatetruecolor($thumbnails_width, $thumbnails_height); imagecopyresized($dst_image, $src_image, 0, 0, 0, 0, $thumbnails_width, $thumbnails_height, $width, $height); imagegif($dst_image, $thumbnails_filename); - } - else - { + } else { @copy($filename, $thumbnails_filename); } @rename($thumbnails_filename, $avatar_save_path . $basename); - } - else - { + } else { throw new \UnexpectedValueException('the avatar file type has errors.', -15007); } $user = Sentinel::findById($this->user->id); - if (!$user) - { + if (!$user) { throw new \UnexpectedValueException('the user is not existed.', -15000); } $user->fill([ 'avatar' => $basename ])->save(); - return $this->show(); + return $this->show(); } /** @@ -99,24 +86,19 @@ public function show() $data = []; $user = Sentinel::findById($this->user->id); - if (!$user) - { + if (!$user) { throw new \UnexpectedValueException('the user is not existed.', -15000); } $data['accounts'] = $user; $user_setting = UserSetting::where('user_id', $this->user->id)->first(); - if ($user_setting && isset($user_setting->notifications)) - { + if ($user_setting && isset($user_setting->notifications)) { $data['notifications'] = $user_setting->notifications; - } - else - { + } else { $data['notifications'] = [ 'mail_notify' => true ]; } - if ($user_setting && isset($user_setting->favorites)) - { + if ($user_setting && isset($user_setting->favorites)) { $data['favorites'] = $user_setting->favorites; } @@ -132,33 +114,28 @@ public function show() public function resetPwd(Request $request) { $password = $request->input('password'); - if (!$password) - { + if (!$password) { throw new \UnexpectedValueException('the old password can not be empty.', -15001); } $user = Sentinel::findById($this->user->id); - if (!$user) - { + if (!$user) { throw new \UnexpectedValueException('the user is not existed.', -15000); } $credentials = [ 'email' => $this->user->email, 'password' => $password ]; $valid = Sentinel::validateCredentials($user, $credentials); - if (!$valid) - { + if (!$valid) { throw new \UnexpectedValueException('the old password is not correct.', -15002); } $new_password = $request->input('new_password'); - if (!$new_password) - { + if (!$new_password) { throw new \UnexpectedValueException('the password can not be empty.', -15003); } $valid = Sentinel::validForUpdate($user, [ 'password' => $new_password ]); - if (!$valid) - { + if (!$valid) { throw new \UnexpectedValueException('resetting the password fails.', -15004); } //$user->password = password_hash($new_password, PASSWORD_DEFAULT); @@ -176,36 +153,30 @@ public function resetPwd(Request $request) public function updAccounts(Request $request) { $user = Sentinel::findById($this->user->id); - if (!$user) - { + if (!$user) { throw new \UnexpectedValueException('the user is not existed.', -15000); } $first_name = $request->input('first_name'); - if (isset($first_name)) - { - if (!$first_name) - { + if (isset($first_name)) { + if (!$first_name) { throw new \UnexpectedValueException('the name can not be empty.', -15005); } $user->first_name = $first_name; } $department = $request->input('department'); - if (isset($department)) - { + if (isset($department)) { $user->department = $department; } $position = $request->input('position'); - if (isset($position)) - { + if (isset($position)) { $user->position = $position; } $bind_email = $request->input('bind_email'); - if (isset($bind_email)) - { + if (isset($bind_email)) { $user->bind_email = $bind_email; } @@ -225,18 +196,14 @@ public function setNotifications(Request $request) $notifications = $request->all(); $user_setting = UserSetting::where('user_id', $this->user->id)->first(); - if ($user_setting) - { + if ($user_setting) { $new_notifications = $user_setting->notifications; - foreach ($notifications as $key => $value) - { + foreach ($notifications as $key => $value) { $new_notifications[$key] = $value; } $user_setting->fill([ 'notifications' => $new_notifications ])->save(); - } - else - { + } else { UserSetting::create([ 'user_id' => $this->user->id, 'notifications' => $notifications ]); } @@ -256,18 +223,14 @@ public function setFavorites(Request $request) $favorites = $request->all(); $user_setting = UserSetting::where(user_id, $this->user->id)->first(); - if ($user_setting) - { + if ($user_setting) { $new_favorites = $user_setting->favorites; - foreach ($favorites as $key => $value) - { + foreach ($favorites as $key => $value) { $new_favorites[$key] = $value; } $user_setting->fill([ 'favorites' => $new_favorites ])->save(); - } - else - { + } else { UserSetting::create([ 'user_id' => $this->user->id, 'favorites' => $favorites ]); } diff --git a/app/Http/Controllers/PriorityController.php b/app/Http/Controllers/PriorityController.php index 0facce5a8..85146219c 100644 --- a/app/Http/Controllers/PriorityController.php +++ b/app/Http/Controllers/PriorityController.php @@ -24,9 +24,8 @@ class PriorityController extends Controller public function index($project_key) { $priorities = Provider::getPriorityList($project_key); - foreach ($priorities as $key => $priority) - { - $priorities[$key]['is_used'] = $this->isFieldUsedByIssue($project_key, 'priority', $priority); + foreach ($priorities as $key => $priority) { + $priorities[$key]['is_used'] = $this->isFieldUsedByIssue($project_key, 'priority', $priority); } return Response()->json(['ecode' => 0, 'data' => $priorities]); } @@ -40,13 +39,11 @@ public function index($project_key) public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12600); } - if (Provider::isPriorityExisted($project_key, $name)) - { + if (Provider::isPriorityExisted($project_key, $name)) { throw new \UnexpectedValueException('priority name cannot be repeated', -12601); } @@ -82,25 +79,20 @@ public function show($project_key, $id) public function update(Request $request, $project_key, $id) { $priority = Priority::find($id); - if (!$priority || $project_key != $priority->project_key) - { + if (!$priority || $project_key != $priority->project_key) { throw new \UnexpectedValueException('the priority does not exist or is not in the project.', -12602); } - if (isset($priority->key) && $priority->key) - { + if (isset($priority->key) && $priority->key) { throw new \UnexpectedValueException('the priority is built in the system.', -12604); } $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12600); } - if ($priority->name !== $name && Provider::isPriorityExisted($project_key, $name)) - { + if ($priority->name !== $name && Provider::isPriorityExisted($project_key, $name)) { throw new \UnexpectedValueException('priority name cannot be repeated', -12601); } } @@ -120,8 +112,7 @@ public function update(Request $request, $project_key, $id) public function destroy($project_key, $id) { $priority = Priority::find($id); - if (!$priority || $project_key != $priority->project_key) - { + if (!$priority || $project_key != $priority->project_key) { throw new \UnexpectedValueException('the priority does not exist or is not in the project.', -12602); } @@ -130,35 +121,32 @@ public function destroy($project_key, $id) // throw new \UnexpectedValueException('the priority is built in the system.', -12604); //} - $isUsed = $this->isFieldUsedByIssue($project_key, 'priority', $priority->toArray()); - if ($isUsed) - { + $isUsed = $this->isFieldUsedByIssue($project_key, 'priority', $priority->toArray()); + if ($isUsed) { throw new \UnexpectedValueException('the priority has been used in issue.', -12603); } Priority::destroy($id); $priority_property = PriorityProperty::Where('project_key', $project_key)->first(); - if ($priority_property) - { - $properties = []; - if ($priority_property->defaultValue == $id) - { - $properties['defaultValue'] = ''; - } - if ($priority_property->sequence && in_array($id, $priority_property->sequence)) - { - $sequence = []; - foreach ($priority_property->sequence as $val) - { - if ($val == $id) { continue; } - $sequence[] = $val; - } - $properties['sequence'] = $sequence; - } + if ($priority_property) { + $properties = []; + if ($priority_property->defaultValue == $id) { + $properties['defaultValue'] = ''; + } + if ($priority_property->sequence && in_array($id, $priority_property->sequence)) { + $sequence = []; + foreach ($priority_property->sequence as $val) { + if ($val == $id) { + continue; + } + $sequence[] = $val; + } + $properties['sequence'] = $sequence; + } - $priority_property->fill($properties); - $priority_property->save(); + $priority_property->fill($properties); + $priority_property->save(); } // trigger to change priority field config @@ -174,12 +162,9 @@ public function destroy($project_key, $id) */ public function handle(Request $request, $project_key) { - if ($project_key === '$_sys_$') - { + if ($project_key === '$_sys_$') { return $this->handleSys($request, $project_key); - } - else - { + } else { return $this->handleProject($request, $project_key); } } @@ -195,27 +180,22 @@ public function handleProject(Request $request, $project_key) $properties = []; // set priority sort. $sequence = $request->input('sequence'); - if (isset($sequence)) - { + if (isset($sequence)) { $properties['sequence'] = $sequence; } // set default value $defaultValue = $request->input('defaultValue'); - if (isset($defaultValue)) - { + if (isset($defaultValue)) { $properties['defaultValue'] = $defaultValue; } $priority_property = PriorityProperty::Where('project_key', $project_key)->first(); - if ($priority_property) - { - $priority_property->fill($properties); - $priority_property->save(); - } - else - { - PriorityProperty::create([ 'project_key' => $project_key ] + $properties); + if ($priority_property) { + $priority_property->fill($properties); + $priority_property->save(); + } else { + PriorityProperty::create([ 'project_key' => $project_key ] + $properties); } return Response()->json(['ecode' => 0, 'data' => [ 'sequence' => $sequence ?: null, 'default' => $defaultValue ?: null ]]); @@ -231,14 +211,11 @@ public function handleSys(Request $request, $project_key) { // set type sort. $sequence = $request->input('sequence'); - if (isset($sequence)) - { + if (isset($sequence)) { $i = 1; - foreach ($sequence as $priority_id) - { + foreach ($sequence as $priority_id) { $priority = Priority::find($priority_id); - if (!$priority || $priority->project_key != $project_key) - { + if (!$priority || $priority->project_key != $project_key) { continue; } $priority->sn = $i++; @@ -248,24 +225,18 @@ public function handleSys(Request $request, $project_key) // set default value $default_priority_id = $request->input('defaultValue'); - if (isset($default_priority_id)) - { + if (isset($default_priority_id)) { $priority = Priority::find($default_priority_id); - if (!$priority || $priority->project_key != $project_key) - { + if (!$priority || $priority->project_key != $project_key) { throw new \UnexpectedValueException('the priority does not exist or is not in the project.', -12602); } $priorities = Priority::where('project_key', $project_key)->get(); - foreach ($priorities as $priority) - { - if ($priority->id == $default_priority_id) - { + foreach ($priorities as $priority) { + if ($priority->id == $default_priority_id) { $priority->default = true; $priority->save(); - } - else if (isset($priority->default)) - { + } elseif (isset($priority->default)) { $priority->unset('default'); } } @@ -281,21 +252,18 @@ public function handleSys(Request $request, $project_key) */ public function viewUsedInProject($project_key, $id) { - if ($project_key !== '$_sys_$') - { + if ($project_key !== '$_sys_$') { return Response()->json(['ecode' => 0, 'data' => [] ]); } $res = []; $projects = Project::all(); - foreach($projects as $project) - { + foreach ($projects as $project) { $count = DB::collection('issue_' . $project->key) ->where('priority', $id) ->where('del_flg', '<>', 1) ->count(); - if ($count > 0) - { + if ($count > 0) { $res[] = [ 'key' => $project->key, 'name' => $project->name, 'status' => $project->status, 'issue_count' => $count ]; } } diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index f0ed18b8d..3055de73c 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -58,19 +58,19 @@ public function recent(Request $request) $new_accessed_pkeys = array_unique(array_intersect($accessed_pkeys, $pkeys)); $projects = []; - foreach ($new_accessed_pkeys as $pkey) - { + foreach ($new_accessed_pkeys as $pkey) { $project = Project::where('key', $pkey)->first(); - if (!$project || $project->status === 'closed') - { + if (!$project || $project->status === 'closed') { continue; } $projects[] = [ 'key' => $project->key, 'name' => $project->name ]; - if (count($projects) >= 5) { break; } + if (count($projects) >= 5) { + break; + } } - return Response()->json([ 'ecode' => 0, 'data' => $projects ]); + return Response()->json([ 'ecode' => 0, 'data' => $projects ]); } /** @@ -92,64 +92,52 @@ public function myproject(Request $request) $pkeys = array_values(array_unique(array_column($user_projects, 'project_key'))); $offset_key = $request->input('offset_key'); - if (isset($offset_key)) - { + if (isset($offset_key)) { $ind = array_search($offset_key, $pkeys); - if ($ind === false) - { + if ($ind === false) { $pkeys = []; - } - else - { - $pkeys = array_slice($pkeys, $ind + 1); + } else { + $pkeys = array_slice($pkeys, $ind + 1); } } $limit = $request->input('limit'); - if (!isset($limit)) - { + if (!isset($limit)) { $limit = 36; } $limit = intval($limit); $status = $request->input('status'); - if (!isset($status)) - { + if (!isset($status)) { $status = 'all'; } $name = $request->input('name'); $projects = []; - foreach ($pkeys as $pkey) - { + foreach ($pkeys as $pkey) { $query = Project::where('key', $pkey); - if ($name) - { + if ($name) { $query->where(function ($query) use ($name) { $query->where('key', 'like', '%' . $name . '%')->orWhere('name', 'like', '%' . $name . '%'); }); } - if ($status != 'all') - { + if ($status != 'all') { $query = $query->where('status', $status); } $project = $query->first(); - if (!$project) - { + if (!$project) { continue; } $projects[] = $project->toArray(); - if (count($projects) >= $limit) - { + if (count($projects) >= $limit) { break; } } - foreach ($projects as $key => $project) - { + foreach ($projects as $key => $project) { $projects[$key]['principal']['nameAndEmail'] = $project['principal']['name'] . '(' . $project['principal']['email'] . ')'; } @@ -169,8 +157,7 @@ public function getOptions(Request $request) $principals = Project::distinct('principal')->get([ 'principal' ])->toArray(); $newPrincipals = []; - foreach ($principals as $principal) - { + foreach ($principals as $principal) { $tmp = []; $tmp['id'] = $principal['id']; $tmp['name'] = $principal['name']; @@ -189,16 +176,14 @@ public function getOptions(Request $request) public function createIndex(Request $request, $id) { $project = Project::find($id); - if (!$project) - { + if (!$project) { throw new \UnexpectedValueException('the project does not exist.', -14006); } - if ($project->principal['id'] !== $this->user->id && !$this->user->hasAccess('sys_admin')) - { + if ($project->principal['id'] !== $this->user->id && !$this->user->hasAccess('sys_admin')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } - Schema::collection('issue_' . $project->key, function($col) { + Schema::collection('issue_' . $project->key, function ($col) { $col->index('type'); $col->index('state'); $col->index('resolution'); @@ -214,19 +199,19 @@ public function createIndex(Request $request, $id) $col->index('assignee.id'); $col->index('reporter.id'); }); - Schema::collection('activity_' . $project->key, function($col) { + Schema::collection('activity_' . $project->key, function ($col) { $col->index('event_key'); }); - Schema::collection('comments_' . $project->key, function($col) { + Schema::collection('comments_' . $project->key, function ($col) { $col->index('issue_id'); }); - Schema::collection('issue_his_' . $project->key, function($col) { + Schema::collection('issue_his_' . $project->key, function ($col) { $col->index('issue_id'); }); - Schema::collection('document_' . $project->key, function($col) { + Schema::collection('document_' . $project->key, function ($col) { $col->index('parent'); }); - Schema::collection('wiki_' . $project->key, function($col) { + Schema::collection('wiki_' . $project->key, function ($col) { $col->index('parent'); }); @@ -241,20 +226,17 @@ public function createIndex(Request $request, $id) public function createMultiIndex(Request $request) { $ids = $request->input('ids'); - if (!isset($ids) || !$ids) - { + if (!isset($ids) || !$ids) { throw new \InvalidArgumentException('the selected projects cannot been empty.', -14007); } - foreach ($ids as $id) - { + foreach ($ids as $id) { $project = Project::find($id); - if (!$project) - { + if (!$project) { continue; } - Schema::collection('issue_' . $project->key, function($col) { + Schema::collection('issue_' . $project->key, function ($col) { $col->index('type'); $col->index('state'); $col->index('resolution'); @@ -269,19 +251,19 @@ public function createMultiIndex(Request $request) $col->index('assignee.id'); $col->index('reporter.id'); }); - Schema::collection('activity_' . $project->key, function($col) { + Schema::collection('activity_' . $project->key, function ($col) { $col->index('event_key'); }); - Schema::collection('comments_' . $project->key, function($col) { + Schema::collection('comments_' . $project->key, function ($col) { $col->index('issue_id'); }); - Schema::collection('issue_his_' . $project->key, function($col) { + Schema::collection('issue_his_' . $project->key, function ($col) { $col->index('issue_id'); }); - Schema::collection('document_' . $project->key, function($col) { + Schema::collection('document_' . $project->key, function ($col) { $col->index('parent'); }); - Schema::collection('wiki_' . $project->key, function($col) { + Schema::collection('wiki_' . $project->key, function ($col) { $col->index('parent'); }); } @@ -296,20 +278,17 @@ public function createMultiIndex(Request $request) public function updMultiStatus(Request $request) { $ids = $request->input('ids'); - if (!isset($ids) || !$ids) - { + if (!isset($ids) || !$ids) { throw new \InvalidArgumentException('the selected projects cannot been empty.', -14007); } $status = $request->input('status'); - if (!isset($status) || !$status) - { + if (!isset($status) || !$status) { throw new \InvalidArgumentException('the status cannot be empty.', -14008); } $newIds = []; - foreach ($ids as $id) - { + foreach ($ids as $id) { $newIds[] = new ObjectID($id); } @@ -328,8 +307,7 @@ public function search(Request $request) $query = DB::collection('project'); $s = $request->input('s'); - if (isset($s) && $s) - { + if (isset($s) && $s) { $query->where(function ($query) use ($s) { $query->where('key', 'like', '%' . $s . '%')->orWhere('name', 'like', '%' . $s . '%'); }); @@ -350,20 +328,17 @@ public function index(Request $request) $query = DB::collection('project'); $principal_id = $request->input('principal_id'); - if (isset($principal_id) && $principal_id) - { + if (isset($principal_id) && $principal_id) { $query = $query->where('principal.id', $principal_id); } $status = $request->input('status'); - if (isset($status) && $status !== 'all') - { + if (isset($status) && $status !== 'all') { $query = $query->where('status', $status); } $name = $request->input('name'); - if (isset($name) && $name) - { + if (isset($name) && $name) { $query->where(function ($query) use ($name) { $query->where('key', 'like', '%' . $name . '%')->orWhere('name', 'like', '%' . $name . '%'); }); @@ -378,8 +353,7 @@ public function index(Request $request) $page = $request->input('page') ?: 1; $query = $query->skip($page_size * ($page - 1))->take($page_size); $projects = $query->get([ 'name', 'key', 'description', 'status', 'principal' ]); - foreach ($projects as $key => $project) - { + foreach ($projects as $key => $project) { $projects[$key]['principal']['nameAndEmail'] = $project['principal']['name'] . '(' . $project['principal']['email'] . ')'; } @@ -395,50 +369,41 @@ public function index(Request $request) public function store(Request $request) { $syssetting = SysSetting::first(); - $allow_create_project = isset($syssetting->properties['allow_create_project']) ? $syssetting->properties['allow_create_project'] : 0; - if ($allow_create_project !== 1 && !$this->user->hasAccess('sys_admin')) - { + $allow_create_project = isset($syssetting->properties['allow_create_project']) ? $syssetting->properties['allow_create_project'] : 0; + if ($allow_create_project !== 1 && !$this->user->hasAccess('sys_admin')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } $insValues = []; $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -14000); } $insValues['name'] = $name; $key = $request->input('key'); - if (!$key) - { + if (!$key) { throw new \InvalidArgumentException('project key cannot be empty.', -14001); } - if (Project::Where('key', $key)->exists()) - { + if (Project::Where('key', $key)->exists()) { throw new \InvalidArgumentException('project key has been taken.', -14002); } $insValues['key'] = $key; $principal = $request->input('principal'); - if (!isset($principal) || !$principal) - { + if (!isset($principal) || !$principal) { $insValues['principal'] = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; - } - else - { + } else { $principal_info = Sentinel::findById($principal); - if (!$principal_info) - { + if (!$principal_info) { throw new \InvalidArgumentException('the user is not exists.', -14003); } $insValues['principal'] = [ 'id' => $principal_info->id, 'name' => $principal_info->first_name, 'email' => $principal_info->email ]; } $description = $request->input('description'); - if (isset($description) && $description) - { + if (isset($description) && $description) { $insValues['description'] = $description; } @@ -453,8 +418,7 @@ public function store(Request $request) // trigger add user to usrproject Event::fire(new AddUserToRoleEvent([ $insValues['principal']['id'] ], $key)); - if (isset($project->principal)) - { + if (isset($project->principal)) { $project->principal = array_merge($insValues['principal'], [ 'nameAndEmail' => $insValues['principal']['name'] . '(' . $insValues['principal']['email'] . ')' ]); } @@ -466,13 +430,12 @@ public function store(Request $request) * * @param string $key * @param int $id - * @return + * @return */ public function initialize($key) { $types = Type::where('project_key', '$_sys_$')->get()->toArray(); - foreach ($types as $type) - { + foreach ($types as $type) { Type::create(array_only($type, [ 'name', 'abb', 'screen_id', 'workflow_id', 'sn', 'type', 'disabled', 'default' ]) + [ 'project_key' => $key ]); } } @@ -486,20 +449,17 @@ public function initialize($key) public function show($key) { $project = Project::where('key', $key)->first(); - if (!$project) - { + if (!$project) { return Response()->json(['ecode' => -14004, 'emsg' => 'the project does not exist.']); } - if ($project->status !== 'active') - { + if ($project->status !== 'active') { return Response()->json(['ecode' => -14009, 'emsg' => 'the project has been closed.']); } // get action allow of the project. $permissions = Acl::getPermissions($this->user->id, $project->key); - if ($this->user->id === $project->principal['id'] || $this->user->email === 'admin@action.view') - { + if ($this->user->id === $project->principal['id'] || $this->user->email === 'admin@action.view') { !in_array('view_project', $permissions) && $permissions[] = 'view_project'; !in_array('manage_project', $permissions) && $permissions[] = 'manage_project'; } @@ -533,8 +493,7 @@ public function show($key) //$types = Provider::getTypeListExt($project->key, [ 'assignee' => $users, 'state' => $states, 'resolution' => $resolutions, 'priority' => $priorities, 'version' => $versions, 'module' => $modules ]); // record the project access date - if (in_array('view_project', $permissions)) - { + if (in_array('view_project', $permissions)) { AccessProjectLog::where('project_key', $key) ->where('user_id', $this->user->id) ->delete(); @@ -555,60 +514,49 @@ public function update(Request $request, $id) { $updValues = []; $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -14000); } $updValues['name'] = $name; } // check is user is available $principal = $request->input('principal'); - if (isset($principal)) - { - if (!$principal) - { + if (isset($principal)) { + if (!$principal) { throw new \InvalidArgumentException('the principal must be appointed.', -14005); } $principal_info = Sentinel::findById($principal); - if (!$principal_info) - { + if (!$principal_info) { throw new \InvalidArgumentException('the user is not exists.', -14003); } - $updValues['principal'] = [ 'id' => $principal_info->id, 'name' => $principal_info->first_name, 'email' => $principal_info->email ]; + $updValues['principal'] = [ 'id' => $principal_info->id, 'name' => $principal_info->first_name, 'email' => $principal_info->email ]; } $description = $request->input('description'); - if (isset($description)) - { + if (isset($description)) { $updValues['description'] = $description; } $status = $request->input('status'); - if (isset($status) && in_array($status, [ 'active', 'closed' ])) - { + if (isset($status) && in_array($status, [ 'active', 'closed' ])) { $updValues['status'] = $status; } $project = Project::find($id); - if (!$project) - { + if (!$project) { throw new \UnexpectedValueException('the project does not exist.', -14004); } - if ($project->principal['id'] !== $this->user->id && !$this->user->hasAccess('sys_admin')) - { + if ($project->principal['id'] !== $this->user->id && !$this->user->hasAccess('sys_admin')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } $old_principal = $project->principal; $project->fill($updValues)->save(); - if (isset($principal)) - { - if ($old_principal['id'] != $principal) - { + if (isset($principal)) { + if ($old_principal['id'] != $principal) { Event::fire(new AddUserToRoleEvent([ $principal ], $project->key)); Event::fire(new DelUserFromRoleEvent([ $old_principal['id'] ], $project->key)); } @@ -625,9 +573,8 @@ public function update(Request $request, $id) */ public function destroy($id) { - $project = Project::find($id); - if (!$project) - { + $project = Project::find($id); + if (!$project) { throw new \UnexpectedValueException('the project does not exist.', -14004); } @@ -636,16 +583,14 @@ public function destroy($id) $unrelated_cols = [ 'system.indexes', 'users', 'persistences', 'throttle', 'project' ]; // delete releted table $collections = DB::listCollections(); - foreach ($collections as $col) - { + foreach ($collections as $col) { $col_name = $col->getName(); if (strpos($col_name, 'issue_') === 0 || strpos($col_name, 'activity_') === 0 || strpos($col_name, 'comments_') === 0 || strpos($col_name, 'document_') === 0 || strpos($col_name, 'wiki_') === 0 || - in_array($col_name, $unrelated_cols)) - { + in_array($col_name, $unrelated_cols)) { continue; } @@ -666,14 +611,14 @@ public function destroy($id) } /** - * check if project key has been taken + * check if project key has been taken * * @param string $key * @return \Illuminate\Http\Response */ public function checkKey($key) { - $isExisted = Project::Where('key', $key)->exists(); + $isExisted = Project::Where('key', $key)->exists(); return Response()->json([ 'ecode' => 0, 'data' => [ 'flag' => $isExisted ? '2' : '1' ] ]); } } diff --git a/app/Http/Controllers/ReportController.php b/app/Http/Controllers/ReportController.php index 101e8f434..cc88d3e79 100644 --- a/app/Http/Controllers/ReportController.php +++ b/app/Http/Controllers/ReportController.php @@ -24,35 +24,35 @@ class ReportController extends Controller private $default_filters = [ 'issues' => [ - [ 'id' => 'all_by_type', 'name' => '全部问题/按类型', 'query' => [ 'stat_x' => 'type', 'stat_y' => 'type' ] ], - [ 'id' => 'unresolved_by_assignee', 'name' => '未解决的/按经办人', 'query' => [ 'stat_x' => 'assignee', 'stat_y' => 'assignee', 'resolution' => 'Unresolved' ] ], - [ 'id' => 'unresolved_by_priority', 'name' => '未解决的/按优先级', 'query' => [ 'stat_x' => 'priority', 'stat_y' => 'priority', 'resolution' => 'Unresolved' ] ], - [ 'id' => 'unresolved_by_module', 'name' => '未解决的/按模块', 'query' => [ 'stat_x' => 'module', 'stat_y' => 'module', 'resolution' => 'Unresolved' ] ] - ], + [ 'id' => 'all_by_type', 'name' => '全部问题/按类型', 'query' => [ 'stat_x' => 'type', 'stat_y' => 'type' ] ], + [ 'id' => 'unresolved_by_assignee', 'name' => '未解决的/按经办人', 'query' => [ 'stat_x' => 'assignee', 'stat_y' => 'assignee', 'resolution' => 'Unresolved' ] ], + [ 'id' => 'unresolved_by_priority', 'name' => '未解决的/按优先级', 'query' => [ 'stat_x' => 'priority', 'stat_y' => 'priority', 'resolution' => 'Unresolved' ] ], + [ 'id' => 'unresolved_by_module', 'name' => '未解决的/按模块', 'query' => [ 'stat_x' => 'module', 'stat_y' => 'module', 'resolution' => 'Unresolved' ] ] + ], 'worklog' => [ - [ 'id' => 'all', 'name' => '全部填报', 'query' => [] ], - [ 'id' => 'in_one_month', 'name' => '过去一个月的', 'query' => [ 'recorded_at' => '1m' ] ], - [ 'id' => 'active_sprint', 'name' => '当前活动Sprint', 'query' => [] ], - [ 'id' => 'latest_completed_sprint', 'name' => '最近已完成Sprint', 'query' => [] ], - //[ 'id' => 'will_release_version', 'name' => '最近要发布版本', 'query' => [] ], - //[ 'id' => 'latest_released_version', 'name' => '最近已发布版本', 'query' => [] ], - ], + [ 'id' => 'all', 'name' => '全部填报', 'query' => [] ], + [ 'id' => 'in_one_month', 'name' => '过去一个月的', 'query' => [ 'recorded_at' => '1m' ] ], + [ 'id' => 'active_sprint', 'name' => '当前活动Sprint', 'query' => [] ], + [ 'id' => 'latest_completed_sprint', 'name' => '最近已完成Sprint', 'query' => [] ], + //[ 'id' => 'will_release_version', 'name' => '最近要发布版本', 'query' => [] ], + //[ 'id' => 'latest_released_version', 'name' => '最近已发布版本', 'query' => [] ], + ], 'timetracks' => [ - [ 'id' => 'all', 'name' => '全部问题', 'query' => [] ], - [ 'id' => 'unresolved', 'name' => '未解决的', 'query' => [ 'resolution' => 'Unresolved' ] ], - [ 'id' => 'active_sprint', 'name' => '当前活动Sprint', 'query' => [] ], - [ 'id' => 'latest_completed_sprint', 'name' => '最近已完成Sprint', 'query' => [] ], - //[ 'id' => 'will_release_version', 'name' => '最近要发布版本', 'query' => [] ], - //[ 'id' => 'latest_released_version', 'name' => '最近已发布版本', 'query' => [] ], - ], + [ 'id' => 'all', 'name' => '全部问题', 'query' => [] ], + [ 'id' => 'unresolved', 'name' => '未解决的', 'query' => [ 'resolution' => 'Unresolved' ] ], + [ 'id' => 'active_sprint', 'name' => '当前活动Sprint', 'query' => [] ], + [ 'id' => 'latest_completed_sprint', 'name' => '最近已完成Sprint', 'query' => [] ], + //[ 'id' => 'will_release_version', 'name' => '最近要发布版本', 'query' => [] ], + //[ 'id' => 'latest_released_version', 'name' => '最近已发布版本', 'query' => [] ], + ], 'regressions' => [ - [ 'id' => 'all', 'name' => '已解决问题', 'query' => [] ], - [ 'id' => 'active_sprint', 'name' => '当前活动Sprint', 'query' => [] ], - [ 'id' => 'latest_completed_sprint', 'name' => '最近已完成Sprint', 'query' => [] ], + [ 'id' => 'all', 'name' => '已解决问题', 'query' => [] ], + [ 'id' => 'active_sprint', 'name' => '当前活动Sprint', 'query' => [] ], + [ 'id' => 'latest_completed_sprint', 'name' => '最近已完成Sprint', 'query' => [] ], ], 'trend' => [ - [ 'id' => 'day_in_one_month', 'name' => '问题每日变化趋势', 'query' => [ 'stat_time' => '1m' ] ], - [ 'id' => 'week_in_two_months', 'name' => '问题每周变化趋势', 'query' => [ 'stat_time' => '2m', 'interval' => 'week' ] ], + [ 'id' => 'day_in_one_month', 'name' => '问题每日变化趋势', 'query' => [ 'stat_time' => '1m' ] ], + [ 'id' => 'week_in_two_months', 'name' => '问题每周变化趋势', 'query' => [ 'stat_time' => '2m', 'interval' => 'week' ] ], ] ]; @@ -71,16 +71,13 @@ public function index($project_key) $res = ReportFilters::where('project_key', $project_key) ->where('user', $this->user->id) ->get(); - foreach($res as $v) - { - if (isset($v['filters'])) - { + foreach ($res as $v) { + if (isset($v['filters'])) { $filters[$v['mode']] = $v['filters']; } } - foreach($filters as $mode => $some_filters) - { + foreach ($filters as $mode => $some_filters) { $filters[$mode] = $this->convFilters($project_key, $some_filters); } @@ -95,64 +92,44 @@ public function index($project_key) */ public function convFilters($project_key, $filters) { - foreach($filters as $key => $filter) - { - if ($filter['id'] === 'active_sprint') - { + foreach ($filters as $key => $filter) { + if ($filter['id'] === 'active_sprint') { $sprint = Sprint::where('project_key', $project_key) ->where('status', 'active') ->first(); - if ($sprint) - { + if ($sprint) { $filters[$key]['query'] = [ 'sprints' => $sprint->no ]; - } - else - { + } else { unset($filters[$key]); } - } - else if ($filter['id'] === 'latest_completed_sprint') - { + } elseif ($filter['id'] === 'latest_completed_sprint') { $sprint = Sprint::where('project_key', $project_key) ->where('status', 'completed') ->orderBy('no', 'desc') ->first(); - if ($sprint) - { + if ($sprint) { $filters[$key]['query'] = [ 'sprints' => $sprint->no ]; - } - else - { + } else { unset($filters[$key]); } - } - else if ($filter['id'] === 'will_release_version') - { + } elseif ($filter['id'] === 'will_release_version') { $version = Version::where('project_key', $project_key) ->where('status', 'unreleased') ->orderBy('name', 'asc') ->first(); - if ($version) - { + if ($version) { $filters[$key]['query'] = [ 'resolve_version' => $version->id ]; - } - else - { + } else { unset($filters[$key]); } - } - else if ($filter['id'] === 'latest_released_version') - { + } elseif ($filter['id'] === 'latest_released_version') { $version = Version::where('project_key', $project_key) ->where('status', 'released') ->orderBy('name', 'desc') ->first(); - if ($version) - { + if ($version) { $filters[$key]['query'] = [ 'resolve_version' => $version->id ]; - } - else - { + } else { unset($filters[$key]); } } @@ -169,19 +146,17 @@ public function convFilters($project_key, $filters) */ public function getSomeFilters($project_key, $mode) { - if (!in_array($mode, $this->mode_enum)) - { + if (!in_array($mode, $this->mode_enum)) { throw new \UnexpectedValueException('the mode value is error.', -11851); } - $filters = isset($this->default_filters[$mode]) ? $this->default_filters[$mode] : []; + $filters = isset($this->default_filters[$mode]) ? $this->default_filters[$mode] : []; $res = ReportFilters::where('project_key', $project_key) ->where('mode', $mode) ->where('user', $this->user->id) - ->first(); - if ($res) - { + ->first(); + if ($res) { $filters = isset($res->filters) ? $res->filters : []; } @@ -197,20 +172,17 @@ public function getSomeFilters($project_key, $mode) */ public function saveFilter(Request $request, $project_key, $mode) { - if (!in_array($mode, $this->mode_enum)) - { + if (!in_array($mode, $this->mode_enum)) { throw new \UnexpectedValueException('the mode value is error.', -11851); } $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -11852); } $query = $request->input('query'); - if (!isset($query)) - { + if (!isset($query)) { throw new \UnexpectedValueException('the query can not be empty.', -11853); } @@ -218,18 +190,15 @@ public function saveFilter(Request $request, $project_key, $mode) ->where('mode', $mode) ->where('user', $this->user->id) ->first(); - if ($res) - { + if ($res) { $filters = isset($res['filters']) ? $res['filters'] : []; array_push($filters, [ 'id' => md5(microtime()), 'name' => $name, 'query' => $query ]); $res->filters = $filters; $res->save(); - } - else - { + } else { $filters = $this->default_filters[$mode]; array_push($filters, [ 'id' => md5(microtime()), 'name' => $name, 'query' => $query ]); - ReportFilters::create([ 'project_key' => $project_key, 'mode' => $mode, 'user' => $this->user->id, 'filters' => $filters ]); + ReportFilters::create([ 'project_key' => $project_key, 'mode' => $mode, 'user' => $this->user->id, 'filters' => $filters ]); } return $this->getSomeFilters($project_key, $mode); @@ -244,8 +213,7 @@ public function saveFilter(Request $request, $project_key, $mode) */ public function resetSomeFilters(Request $request, $project_key, $mode) { - if (!in_array($mode, $this->mode_enum)) - { + if (!in_array($mode, $this->mode_enum)) { throw new \UnexpectedValueException('the mode value is error.', -11851); } @@ -265,46 +233,37 @@ public function resetSomeFilters(Request $request, $project_key, $mode) */ public function editSomeFilters(Request $request, $project_key, $mode) { - if (!in_array($mode, $this->mode_enum)) - { + if (!in_array($mode, $this->mode_enum)) { throw new \UnexpectedValueException('the mode value is error.', -11851); } $sequence = $request->input('sequence'); - if (isset($sequence)) - { - $old_filters = $this->default_filters[$mode]; + if (isset($sequence)) { + $old_filters = $this->default_filters[$mode]; $res = ReportFilters::where('project_key', $project_key) ->where('mode', $mode) ->where('user', $this->user->id) ->first(); - if ($res) - { + if ($res) { $old_filters = isset($res->filters) ? $res->filters : []; } $new_filters = []; - foreach ($sequence as $id) - { - foreach ($old_filters as $filter) - { - if ($filter['id'] === $id) - { + foreach ($sequence as $id) { + foreach ($old_filters as $filter) { + if ($filter['id'] === $id) { $new_filters[] = $filter; break; } } } - if ($res) - { + if ($res) { $res->filters = $new_filters; $res->save(); - } - else - { - ReportFilters::create([ 'project_key' => $project_key, 'mode' => $mode, 'user' => $this->user->id, 'filters' => $new_filters ]); + } else { + ReportFilters::create([ 'project_key' => $project_key, 'mode' => $mode, 'user' => $this->user->id, 'filters' => $new_filters ]); } } @@ -322,18 +281,14 @@ public function getWorklogWhere($project_key, $options) $where = []; $issue_id = isset($options['issue_id']) ? $options['issue_id'] : ''; - if ($issue_id) - { + if ($issue_id) { $where['issue_id'] = $issue_id; - } - else - { + } else { $issue_ids = []; $query = DB::collection('issue_' . $project_key)->whereRaw($this->getIssueQueryWhere($project_key, $options)); $issues = $query->get([ '_id' ]); - foreach ($issues as $issue) - { + foreach ($issues as $issue) { $issue_ids[] = $issue['_id']->__toString(); } $where['issue_id'] = [ '$in' => $issue_ids ]; @@ -341,44 +296,32 @@ public function getWorklogWhere($project_key, $options) $cond = []; $recorded_at = isset($options['recorded_at']) ? $options['recorded_at'] : ''; - if ($recorded_at) - { - if (strpos($recorded_at, '~') !== false) - { + if ($recorded_at) { + if (strpos($recorded_at, '~') !== false) { $sections = explode('~', $recorded_at); - if ($sections[0]) - { + if ($sections[0]) { $cond['$gte'] = strtotime($sections[0]); } - if ($sections[1]) - { + if ($sections[1]) { $cond['$lte'] = strtotime($sections[1] . ' 23:59:59'); } - if ($cond) - { + if ($cond) { $where['recorded_at'] = $cond; } - } - else - { + } else { $unitMap = [ 'w' => 'week', 'm' => 'month', 'y' => 'year' ]; $unit = substr($recorded_at, -1); - if (in_array($unit, [ 'w', 'm', 'y' ])) - { + if (in_array($unit, [ 'w', 'm', 'y' ])) { $direct = substr($recorded_at, 0, 1); $val = abs(substr($recorded_at, 0, -1)); $time_val = strtotime(date('Ymd', strtotime('-' . $val . ' ' . $unitMap[$unit]))); - if ($direct === '-') - { + if ($direct === '-') { $cond['$lt'] = $time_val; - } - else - { + } else { $cond['$gte'] = $time_val; } - if ($cond) - { + if ($cond) { $where['recorded_at'] = $cond; } } @@ -386,28 +329,23 @@ public function getWorklogWhere($project_key, $options) } $recorder = isset($options['recorder']) ? $options['recorder'] : ''; - if ($recorder) - { + if ($recorder) { $where['recorder.id'] = $recorder; } $sprint_no = isset($options['sprints']) ? $options['sprints'] : ''; - if ($sprint_no) - { + if ($sprint_no) { $sprint = Sprint::where('project_key', $project_key)->where('no', intval($sprint_no))->first(); $sprint_start_time = strtotime(date('Ymd', $sprint->start_time)); - if (!isset($cond['$gte']) || $cond['$gte'] < $sprint_start_time) - { + if (!isset($cond['$gte']) || $cond['$gte'] < $sprint_start_time) { $cond['$gte'] = $sprint_start_time; } - if (isset($sprint->real_complete_time) && $sprint->real_complete_time > 0) - { + if (isset($sprint->real_complete_time) && $sprint->real_complete_time > 0) { $sprint_complet_time = strtotime(date('Ymd', $sprint->real_complete_time) . ' 23:59:59'); - if (!isset($cond['$lte']) || $cond['$lte'] > $sprint_complet_time) - { - $cond['$lte'] = $sprint_complet_time; + if (!isset($cond['$lte']) || $cond['$lte'] > $sprint_complet_time) { + $cond['$lte'] = $sprint_complet_time; } } @@ -456,14 +394,13 @@ public function getWorklogList(Request $request, $project_key) $pipeline[] = [ '$group' => [ '_id' => '$issue_id', 'value' => [ '$sum' => '$spend_m' ] ] ]; - $ret = DB::collection('worklog')->raw(function($col) use($pipeline) { + $ret = DB::collection('worklog')->raw(function ($col) use ($pipeline) { return $col->aggregate($pipeline); }); $new_results = []; $results = iterator_to_array($ret); - foreach ($results as $k => $r) - { + foreach ($results as $k => $r) { $tmp = []; $tmp['total_value'] = $r['value']; $issue = DB::collection('issue_' . $project_key) @@ -475,10 +412,11 @@ public function getWorklogList(Request $request, $project_key) $tmp['state'] = $issue['state']; $tmp['type'] = $issue['type']; $new_results[] = $tmp; - } - usort($new_results, function ($a, $b) { return $a['no'] <= $b['no']; }); + usort($new_results, function ($a, $b) { + return $a['no'] <= $b['no']; + }); return Response()->json([ 'ecode' => 0, 'data' => $new_results ]); } @@ -496,29 +434,24 @@ public function getWorklogs(Request $request, $project_key) $where = $this->getWorklogWhere($project_key, $request->all()); $pipeline[] = [ '$match' => $where ]; - $pipeline[] = [ '$group' => [ '_id' => '$recorder.id', 'value' => [ '$sum' => '$spend_m' ] ] ]; + $pipeline[] = [ '$group' => [ '_id' => '$recorder.id', 'value' => [ '$sum' => '$spend_m' ] ] ]; - $ret = DB::collection('worklog')->raw(function($col) use($pipeline) { + $ret = DB::collection('worklog')->raw(function ($col) use ($pipeline) { return $col->aggregate($pipeline); }); $others_val = 0; $results = iterator_to_array($ret); $new_results = []; - foreach ($results as $r) - { + foreach ($results as $r) { $user = Sentinel::findById($r['_id']); - if ($user) - { + if ($user) { $new_results[] = [ 'user' => [ 'id' => $user->id, 'name' => $user->first_name ], 'value' => $r['value'] ]; - } - else - { + } else { $others_val += $r['value']; } } - if ($others_val > 0) - { + if ($others_val > 0) { $new_results[] = [ 'user' => [ 'id' => 'other', 'name' => '' ], 'value' => $other_val ]; } @@ -539,10 +472,8 @@ public function getTimetracksDetail(Request $request, $project_key, $issue_id) ->orderBy('recorded_at', 'desc') ->get(); - foreach($worklogs as $worklog) - { - if (!isset($worklog->spend_m) || !$worklog->spend_m) - { + foreach ($worklogs as $worklog) { + if (!isset($worklog->spend_m) || !$worklog->spend_m) { $worklog->spend_m = $this->ttHandleInM($worklog->spend ?: ''); } } @@ -550,18 +481,17 @@ public function getTimetracksDetail(Request $request, $project_key, $issue_id) return Response()->json(['ecode' => 0, 'data' => $worklogs ]); } - /* get timetracks report by project_key. - * - * @param string $project_key - * @return \Illuminate\Http\Response - */ + /* get timetracks report by project_key. + * + * @param string $project_key + * @return \Illuminate\Http\Response + */ public function getTimetracks(Request $request, $project_key) { $where = $this->getIssueQueryWhere($project_key, $request->all()); $scale = $request->input('scale'); - if ($scale === 'only') - { + if ($scale === 'only') { $where['$and'][] = [ 'original_estimate' => [ '$exists' => 1, '$ne' => '' ] ]; } @@ -569,8 +499,7 @@ public function getTimetracks(Request $request, $project_key) $issues = $query->orderBy('no', 'desc')->take(10000)->get(); $new_issues = []; - foreach($issues as $issue) - { + foreach ($issues as $issue) { $issue_id = $issue['_id']->__toString(); $tmp['id'] = $issue_id; @@ -587,22 +516,16 @@ public function getTimetracks(Request $request, $project_key) ->where('issue_id', $issue_id) ->orderBy('recorded_at', 'asc') ->get(); - foreach($worklogs as $log) - { - $this_spend_m = isset($log['spend_m']) ? $log['spend_m'] : $this->ttHandleInM(isset($log['spend']) ? $log['spend'] : ''); - $spend_m += $this_spend_m; - if ($log['adjust_type'] == '1') - { + foreach ($worklogs as $log) { + $this_spend_m = isset($log['spend_m']) ? $log['spend_m'] : $this->ttHandleInM(isset($log['spend']) ? $log['spend'] : ''); + $spend_m += $this_spend_m; + if ($log['adjust_type'] == '1') { $left_m = $left_m === '' ? '' : $left_m - $this_spend_m; - } - else if ($log['adjust_type'] == '3') - { + } elseif ($log['adjust_type'] == '3') { $leave_estimate = isset($log['leave_estimate']) ? $log['leave_estimate'] : ''; $leave_estimate_m = isset($log['leave_estimate_m']) ? $log['leave_estimate_m'] : $this->ttHandleInM($leave_estimate); $left_m = $leave_estimate_m; - } - else if ($log['adjust_type'] == '4') - { + } elseif ($log['adjust_type'] == '4') { $cut = isset($log['cut']) ? $log['cut'] : ''; $cut_m = isset($log['cut_m']) ? $log['cut_m'] : $this->ttHandleInM($cut); $left_m = $left_m === '' ? '' : $left_m - $cut_m; @@ -625,7 +548,7 @@ public function getTimetracks(Request $request, $project_key) * * @param string $interval * @param number $star_stat_time - * @param number $end_stat_time + * @param number $end_stat_time * @return \Illuminate\Http\Response */ public function getInitializedTrendData($interval, $start_stat_time, $end_stat_time) @@ -633,40 +556,29 @@ public function getInitializedTrendData($interval, $start_stat_time, $end_stat_t // initialize the results $results = []; $t = $end_stat_time; - if ($interval == 'month') - { - $t = strtotime(date('Y/m/t', $end_stat_time)); - } - else if ($interval == 'week') - { + if ($interval == 'month') { + $t = strtotime(date('Y/m/t', $end_stat_time)); + } elseif ($interval == 'week') { $n = date('N', $end_stat_time); $t = strtotime(date('Y/m/d', $end_stat_time) . ' +' . (7 - $n) . ' day'); - } - else - { + } else { $t = strtotime(date('Y/m/d', $end_stat_time)); } $i = 0; $days = []; - while($t >= $start_stat_time && $i < 100) - { + while ($t >= $start_stat_time && $i < 100) { $tmp = [ 'new' => 0, 'resolved' => 0, 'closed' => 0 ]; $y = date('Y', $t); $m = date('m', $t); $d = date('d', $t); - if ($interval == 'month') - { + if ($interval == 'month') { $tmp['category'] = date('Y/m', $t); $t = mktime(0, 0, 0, $m - 1, $d, $y); - } - else if ($interval == 'week') - { + } elseif ($interval == 'week') { $tmp['category'] = date('Y/m/d', $t - 6 * 24 * 3600); $t = mktime(0, 0, 0, $m, $d - 7, $y); - } - else - { + } else { $tmp['category'] = date('Y/m/d', $t); $days[] = $tmp['category']; @@ -679,13 +591,10 @@ public function getInitializedTrendData($interval, $start_stat_time, $end_stat_t $i++; } - if ($days) - { + if ($days) { $singulars = CalendarSingular::where([ 'date' => [ '$in' => $days ] ])->get(); - foreach ($singulars as $singular) - { - if (isset($results[$singular->day])) - { + foreach ($singulars as $singular) { + if (isset($results[$singular->day])) { $results[$singular->day]['notWorking'] = $singular->type == 'holiday' ? 1 : 0; } } @@ -703,72 +612,58 @@ public function getInitializedTrendData($interval, $start_stat_time, $end_stat_t */ public function getTrends(Request $request, $project_key) { - $interval = $request->input('interval') ?: 'day'; - if (!in_array($interval, [ 'day', 'week', 'month' ])) - { - throw new \UnexpectedValueException('the name can not be empty.', -11852); - } + $interval = $request->input('interval') ?: 'day'; + if (!in_array($interval, [ 'day', 'week', 'month' ])) { + throw new \UnexpectedValueException('the name can not be empty.', -11852); + } - $is_accu = $request->input('is_accu') === '1' ? true : false; + $is_accu = $request->input('is_accu') === '1' ? true : false; - $project = Project::where('key', $project_key)->first(); - if (!$project) - { - throw new \UnexpectedValueException('the project is not exists.', -11850); - } + $project = Project::where('key', $project_key)->first(); + if (!$project) { + throw new \UnexpectedValueException('the project is not exists.', -11850); + } - $start_stat_time = strtotime($project->created_at); - $end_stat_time = time(); + $start_stat_time = strtotime($project->created_at); + $end_stat_time = time(); - $where = $this->getIssueQueryWhere($project_key, $request->all()); + $where = $this->getIssueQueryWhere($project_key, $request->all()); $stat_time = $request->input('stat_time'); - if (isset($stat_time) && $stat_time) - { + if (isset($stat_time) && $stat_time) { $or = []; - if (strpos($stat_time, '~') !== false) - { + if (strpos($stat_time, '~') !== false) { $cond = []; $sections = explode('~', $stat_time); - if ($sections[0]) - { + if ($sections[0]) { $cond['$gte'] = strtotime($sections[0]); $start_stat_time = max([ $start_stat_time, $cond['$gte'] ]); } - if ($sections[1]) - { + if ($sections[1]) { $cond['$lte'] = strtotime($sections[1] . ' 23:59:59'); $end_stat_time = min([ $end_stat_time, $cond['$lte'] ]); } - if ($cond) - { + if ($cond) { $or[] = [ 'created_at' => $cond ]; $or[] = [ 'resolved_at' => $cond ]; $or[] = [ 'closed_at' => $cond ]; } - } - else - { + } else { $unitMap = [ 'w' => 'week', 'm' => 'month', 'y' => 'year' ]; $unit = substr($stat_time, -1); - if (in_array($unit, [ 'w', 'm', 'y' ])) - { + if (in_array($unit, [ 'w', 'm', 'y' ])) { $direct = substr($stat_time, 0, 1); $val = abs(substr($stat_time, 0, -1)); $time_val = strtotime(date('Ymd', strtotime('-' . $val . ' ' . $unitMap[$unit]))); $cond = []; - if ($direct === '-') - { + if ($direct === '-') { $cond['$lt'] = $time_val; $end_stat_time = min([ $end_stat_time, $cond['$lt'] ]); - } - else - { + } else { $cond['$gte'] = $time_val; $start_stat_time = max([ $start_stat_time, $cond['$gte'] ]); } - if ($cond) - { + if ($cond) { $or[] = [ 'created_at' => $cond ]; $or[] = [ 'resolved_at' => $cond ]; $or[] = [ 'closed_at' => $cond ]; @@ -776,13 +671,10 @@ public function getTrends(Request $request, $project_key) } } - if (!$is_accu && $or) - { - $where['$and'][] = [ '$or' => $or ]; - } - else - { - $where['$and'][] = [ 'created_at' => [ '$lte' => $end_stat_time ] ]; + if (!$is_accu && $or) { + $where['$and'][] = [ '$or' => $or ]; + } else { + $where['$and'][] = [ 'created_at' => [ '$lte' => $end_stat_time ] ]; } } @@ -791,68 +683,50 @@ public function getTrends(Request $request, $project_key) $query = DB::collection('issue_' . $project_key)->whereRaw($where); $issues = $query->get([ 'created_at', 'resolved_at', 'closed_at' ]); - foreach ($issues as $issue) - { - if (isset($issue['created_at']) && $issue['created_at']) - { - $created_date = $this->convDate($interval, $issue['created_at']);; - if ($is_accu) - { - foreach($results as $key => $val) - { - if ($key >= $created_date) - { + foreach ($issues as $issue) { + if (isset($issue['created_at']) && $issue['created_at']) { + $created_date = $this->convDate($interval, $issue['created_at']); + ; + if ($is_accu) { + foreach ($results as $key => $val) { + if ($key >= $created_date) { $results[$key]['new'] += 1; } } - } - else if (isset($results[$created_date]) && $issue['created_at'] >= $start_stat_time) - { + } elseif (isset($results[$created_date]) && $issue['created_at'] >= $start_stat_time) { $results[$created_date]['new'] += 1; } } - if (isset($issue['resolved_at']) && $issue['resolved_at']) - { + if (isset($issue['resolved_at']) && $issue['resolved_at']) { $resolved_date = $this->convDate($interval, $issue['resolved_at']); - if ($is_accu) - { - foreach($results as $key => $val) - { - if ($key >= $resolved_date) - { + if ($is_accu) { + foreach ($results as $key => $val) { + if ($key >= $resolved_date) { $results[$key]['resolved'] += 1; } } - } - else if (isset($results[$resolved_date]) && $issue['resolved_at'] >= $start_stat_time) - { + } elseif (isset($results[$resolved_date]) && $issue['resolved_at'] >= $start_stat_time) { $results[$resolved_date]['resolved'] += 1; } } - if (isset($issue['closed_at']) && $issue['closed_at']) - { + if (isset($issue['closed_at']) && $issue['closed_at']) { $closed_date = $this->convDate($interval, $issue['closed_at']); - if ($is_accu) - { - foreach($results as $key => $val) - { - if ($key >= $closed_date) - { + if ($is_accu) { + foreach ($results as $key => $val) { + if ($key >= $closed_date) { $results[$key]['closed'] += 1; } } - } - else if (isset($results[$closed_date]) && $issue['closed_at'] >= $start_stat_time) - { + } elseif (isset($results[$closed_date]) && $issue['closed_at'] >= $start_stat_time) { $results[$closed_date]['closed'] += 1; } } } - return Response()->json([ - 'ecode' => 0, - 'data' => array_values($results), - 'options' => [ 'trend_start_stat_date' => date('Y/m/d', $start_stat_time), 'trend_end_stat_date' => date('Y/m/d', $end_stat_time) ] + return Response()->json([ + 'ecode' => 0, + 'data' => array_values($results), + 'options' => [ 'trend_start_stat_date' => date('Y/m/d', $start_stat_time), 'trend_end_stat_date' => date('Y/m/d', $end_stat_time) ] ]); } @@ -861,119 +735,85 @@ public function getTrends(Request $request, $project_key) * * @param string $interval * @param number $at - * @return string + * @return string */ public function convDate($interval, $at) { - if ($interval === 'week') - { + if ($interval === 'week') { $n = date('N', $at); - return date('Y/m/d', $at - ($n - 1) * 24 * 3600); - } - else if ($interval === 'month') - { - return date('Y/m', $at); - } - else - { - return date('Y/m/d', $at); + return date('Y/m/d', $at - ($n - 1) * 24 * 3600); + } elseif ($interval === 'month') { + return date('Y/m', $at); + } else { + return date('Y/m/d', $at); } } public function arrangeRegressionData($data, $project_key, $dimension) { - if (!$dimension) - { + if (!$dimension) { return $data; } $results = []; - if (in_array($dimension, ['reporter', 'assignee', 'resolver', 'closer'])) - { - foreach ($data as $value) - { + if (in_array($dimension, ['reporter', 'assignee', 'resolver', 'closer'])) { + foreach ($data as $value) { $tmp = []; $tmp['ones'] = $value['ones']; $tmp['gt_ones'] = $value['gt_ones']; $tmp['category'] = $value['name']; $results[] = $tmp; } - } - else if (in_array($dimension, ['type', 'priority', 'module', 'resolve_version', 'epic'])) - { - if ($dimension === 'module') - { + } elseif (in_array($dimension, ['type', 'priority', 'module', 'resolve_version', 'epic'])) { + if ($dimension === 'module') { $modules = Provider::getModuleList($project_key, ['name']); - foreach ($modules as $m) - { - foreach ($data as $key => $val) - { - if ($key === $m->id) - { + foreach ($modules as $m) { + foreach ($data as $key => $val) { + if ($key === $m->id) { $val['category'] = $m->name; $results[$m->id] = $val; break; } } } - } - else if ($dimension === 'resolve_version') - { + } elseif ($dimension === 'resolve_version') { $versions = Provider::getVersionList($project_key, ['name']); - foreach ($versions as $v) - { - foreach ($data as $key => $val) - { - if ($key === $v->id) - { + foreach ($versions as $v) { + foreach ($data as $key => $val) { + if ($key === $v->id) { $val['category'] = $v->name; $results[$key] = $val; break; } } } - } - else if ($dimension === 'type') - { + } elseif ($dimension === 'type') { $types = Provider::getTypeList($project_key, ['name']); - foreach ($types as $v) - { - foreach ($data as $key => $val) - { - if ($key === $v->id) - { + foreach ($types as $v) { + foreach ($data as $key => $val) { + if ($key === $v->id) { $val['category'] = $v->name; $results[$key] = $val; break; } } - } - } - else if ($dimension === 'priority') - { + } + } elseif ($dimension === 'priority') { $priorities = Provider::getPriorityOptions($project_key, ['name']); - foreach ($priorities as $v) - { - foreach ($data as $key => $val) - { - if ($key === $v['_id']) - { + foreach ($priorities as $v) { + foreach ($data as $key => $val) { + if ($key === $v['_id']) { $val['category'] = $v['name']; $results[$key] = $val; break; } } } - } - else if ($dimension === 'epic') - { + } elseif ($dimension === 'epic') { $epics = Provider::getEpicList($project_key, ['name']); - foreach ($epics as $v) - { - foreach ($data as $key => $val) - { - if ($key === $v['_id']) - { + foreach ($epics as $v) { + foreach ($data as $key => $val) { + if ($key === $v['_id']) { $val['category'] = $v['name']; $results[$key] = $val; break; @@ -983,7 +823,7 @@ public function arrangeRegressionData($data, $project_key, $dimension) } //$others = [ 'ones' => [], 'gt_ones' => [], 'category' => 'others' ]; - //foreach ($data as $key => $val) + //foreach ($data as $key => $val) //{ // if (!isset($results[$key])) // { @@ -996,44 +836,30 @@ public function arrangeRegressionData($data, $project_key, $dimension) //{ // $results['others'] = $others; //} - } - else if ($dimension === 'sprints') - { - foreach ($data as $key => $val) - { + } elseif ($dimension === 'sprints') { + foreach ($data as $key => $val) { $tmp = []; $tmp['ones'] = $val['ones']; $tmp['gt_ones'] = $val['gt_ones']; $tmp['category'] = 'Sprint ' . $key; $results[] = $tmp; - } - } - else if ($dimension === 'labels') - { - foreach ($data as $key => $val) - { + } + } elseif ($dimension === 'labels') { + foreach ($data as $key => $val) { $tmp = []; $tmp['ones'] = $val['ones']; $tmp['gt_ones'] = $val['gt_ones']; $tmp['category'] = $key; $results[] = $tmp; - } - } - else - { + } + } else { $fields = Provider::getFieldList($project_key); - foreach ($fields as $field) - { - if ($field->key === $dimension) - { - if (isset($field->optionValues) && $field->optionValues) - { - foreach($field->optionValues as $v) - { - foreach ($data as $key => $val) - { - if ($key === $v['id']) - { + foreach ($fields as $field) { + if ($field->key === $dimension) { + if (isset($field->optionValues) && $field->optionValues) { + foreach ($field->optionValues as $v) { + foreach ($data as $key => $val) { + if ($key === $v['id']) { $val['category'] = $v['name']; $results[$key] = $val; break; @@ -1060,12 +886,10 @@ public function getRegressions(Request $request, $project_key) $his_resolvers = $request->input('his_resolvers') ? explode(',', $request->input('his_resolvers')) : []; $or = []; - foreach ($his_resolvers as $resolver) - { + foreach ($his_resolvers as $resolver) { $or[] = [ 'his_resolvers' => $resolver ]; } - if ($or) - { + if ($or) { $where['$and'][] = [ '$or' => $or ]; } @@ -1073,55 +897,42 @@ public function getRegressions(Request $request, $project_key) $sprint_start_time = $sprint_complete_time = 0; $sprint_no = $request->input('sprint') ?: ''; - if ($sprint_no) - { + if ($sprint_no) { $sprint = Sprint::where('project_key', $project_key)->where('no', intval($sprint_no))->first(); $sprint_start_time = strtotime(date('Ymd', $sprint->start_time)); - if (isset($sprint->real_complete_time) && $sprint->real_complete_time > 0) - { + if (isset($sprint->real_complete_time) && $sprint->real_complete_time > 0) { $sprint_complete_time = $sprint->real_complete_time; } } $dimension = $request->input('stat_dimension') ?: ''; - if ($dimension) - { + if ($dimension) { $results = []; - } - else - { + } else { $results = [ 'ones' => [], 'gt_ones' => [] ]; } $results = []; $query = DB::collection('issue_' . $project_key)->whereRaw($where); $issues = $query->orderBy('no', 'desc')->take(1000)->get(); - foreach($issues as $issue) - { + foreach ($issues as $issue) { $no = $issue['no']; $regression_times = $issue['regression_times']; $resolved_logs = isset($issue['resolved_logs']) ? $issue['resolved_logs'] : []; - if ($sprint_start_time > 0) - { + if ($sprint_start_time > 0) { $tmp_log = []; - foreach($resolved_logs as $rl) - { - if ($rl['at'] > $sprint_start_time && ($sprint_complete_time <= 0 || $rl['at'] < $sprint_complete_time)) - { - if ($his_resolvers && !in_array($rl['user']['id'], $his_resolvers)) - { + foreach ($resolved_logs as $rl) { + if ($rl['at'] > $sprint_start_time && ($sprint_complete_time <= 0 || $rl['at'] < $sprint_complete_time)) { + if ($his_resolvers && !in_array($rl['user']['id'], $his_resolvers)) { continue; - } - else - { + } else { $tmp_log[] = $rl; } } } - if (!$tmp_log) - { + if (!$tmp_log) { continue; } @@ -1129,112 +940,73 @@ public function getRegressions(Request $request, $project_key) $regression_times = count($tmp_log); } - if ($dimension == 'resolver') - { + if ($dimension == 'resolver') { $log_cnt = count($resolved_logs); $tmp_uids = []; - foreach ($resolved_logs as $key => $log) - { + foreach ($resolved_logs as $key => $log) { $uid = $log['user']['id']; - if (in_array($uid, $tmp_uids)) - { + if (in_array($uid, $tmp_uids)) { continue; - } - else - { + } else { $tmp_uids[] = $uid; } - if (!isset($results[$uid])) - { + if (!isset($results[$uid])) { $results[$uid] = [ 'ones' => [], 'gt_ones' => [], 'name' => isset($log['user']['name']) ? $log['user']['name'] : '' ]; } - if ($regression_times > 1) - { - if ($key == $log_cnt - 1) - { + if ($regression_times > 1) { + if ($key == $log_cnt - 1) { $results[$uid]['ones'][] = $no; - } - else - { + } else { $results[$uid]['gt_ones'][] = $no; } - } - else - { + } else { $results[$uid]['ones'][] = $no; } } - } - else if ($dimension) - { + } elseif ($dimension) { $dimension_values = isset($issue[$dimension]) ? $issue[$dimension] : ''; - if ($dimension_values && is_array($dimension_values)) - { - if (isset($dimension_values['id'])) - { - if (!isset($results[$dimension_values['id']])) - { + if ($dimension_values && is_array($dimension_values)) { + if (isset($dimension_values['id'])) { + if (!isset($results[$dimension_values['id']])) { $results[$dimension_values['id']] = [ 'ones' => [], 'gt_ones' => [], 'name' => isset($dimension_values['name']) ? $dimension_values['name'] : '' ]; } - if ($regression_times > 1) - { + if ($regression_times > 1) { $results[$dimension_values['id']]['gt_ones'][] = $no; - } - else - { + } else { $results[$dimension_values['id']]['ones'][] = $no; } - } - else - { - foreach($dimension_values as $val) - { - if (!isset($results[$val])) - { + } else { + foreach ($dimension_values as $val) { + if (!isset($results[$val])) { $results[$val] = [ 'ones' => [], 'gt_ones' => [] ]; } - if ($regression_times > 1) - { + if ($regression_times > 1) { $results[$val]['gt_ones'][] = $no; - } - else - { + } else { $results[$val]['ones'][] = $no; } - } + } } - } - else if ($dimension_values) - { - if (!isset($results[$dimension_values])) - { + } elseif ($dimension_values) { + if (!isset($results[$dimension_values])) { $results[$dimension_values] = [ 'ones' => [], 'gt_ones' => [] ]; } - if ($regression_times > 1) - { + if ($regression_times > 1) { $results[$dimension_values]['gt_ones'][] = $no; - } - else - { + } else { $results[$dimension_values]['ones'][] = $no; } } - } - else - { - if (!isset($results[0])) - { + } else { + if (!isset($results[0])) { $results[0] = [ 'ones' => [], 'gt_ones' => [] ]; } - if ($regression_times > 1) - { + if ($regression_times > 1) { $results[0]['gt_ones'][] = $no; - } - else - { + } else { $results[0]['ones'][] = $no; } } @@ -1246,7 +1018,7 @@ public function getRegressions(Request $request, $project_key) * * @param string $project_key * @param string $dimension - * @return array + * @return array */ public function initXYData($project_key, $dimension) { @@ -1256,48 +1028,42 @@ public function initXYData($project_key, $dimension) case 'type': $types = Provider::getTypeList($project_key, ['name']); - foreach ($types as $key => $value) - { + foreach ($types as $key => $value) { $results[$value->id] = [ 'name' => $value->name, 'nos' => [] ]; } break; case 'priority': $priorities = Provider::getPriorityOptions($project_key, ['name']); - foreach ($priorities as $key => $value) - { + foreach ($priorities as $key => $value) { $results[$value['_id']] = [ 'name' => $value['name'], 'nos' => [] ]; } break; case 'state': $states = Provider::getStateOptions($project_key, ['name']); - foreach ($states as $key => $value) - { + foreach ($states as $key => $value) { $results[$value['_id']] = [ 'name' => $value['name'], 'nos' => [] ]; } break; case 'resolution': $resolutions = Provider::getResolutionOptions($project_key, ['name']); - foreach ($resolutions as $key => $value) - { + foreach ($resolutions as $key => $value) { $results[$value['_id']] = [ 'name' => $value['name'], 'nos' => [] ]; } break; case 'module': $modules = Provider::getModuleList($project_key, ['name']); - foreach ($modules as $key => $value) - { + foreach ($modules as $key => $value) { $results[$value->id] = [ 'name' => $value->name, 'nos' => [] ]; } break; case 'resolve_version': $versions = Provider::getVersionList($project_key, ['name']); - foreach ($versions as $key => $value) - { + foreach ($versions as $key => $value) { $results[$value->id] = [ 'name' => $value->name, 'nos' => [] ]; } $results = array_reverse($results); @@ -1305,33 +1071,27 @@ public function initXYData($project_key, $dimension) case 'epic': $epics = Provider::getEpicList($project_key, ['name']); - foreach ($epics as $key => $value) - { + foreach ($epics as $key => $value) { $results[$value['_id']] = [ 'name' => $value['name'], 'nos' => [] ]; } - break; + break; case 'sprints': $sprints = Sprint::where('project_key', $project_key) ->whereIn('status', [ 'active', 'completed' ]) ->orderBy('no', 'asc') ->get(); - foreach($sprints as $s) - { + foreach ($sprints as $s) { $results[$s->no] = [ 'name' => 'Sprint' . $s->no, 'nos' => [] ]; } break; default: $fields = Provider::getFieldList($project_key); - foreach ($fields as $field) - { - if ($field->key === $dimension) - { - if (isset($field->optionValues) && $field->optionValues) - { - foreach($field->optionValues as $val) - { + foreach ($fields as $field) { + if ($field->key === $dimension) { + if (isset($field->optionValues) && $field->optionValues) { + foreach ($field->optionValues as $val) { $results[$val['id']] = [ 'name' => $val['name'], 'nos' => [] ]; } } @@ -1354,8 +1114,7 @@ public function initXYData($project_key, $dimension) public function getIssues(Request $request, $project_key) { $X = $request->input('stat_x') ?: ''; - if (!$X) - { + if (!$X) { throw new \UnexpectedValueException('the currentX can not be empty.', -11855); } //$X = $X === 'sprint' ? 'sprints' : $X; @@ -1366,12 +1125,9 @@ public function getIssues(Request $request, $project_key) $XYData = []; $YAxis = []; - if ($X === $Y || !$Y) - { + if ($X === $Y || !$Y) { $XYData[$X] = $this->initXYData($project_key, $X); - } - else - { + } else { $XYData[$X] = $this->initXYData($project_key, $X); $XYData[$Y] = $this->initXYData($project_key, $Y); } @@ -1380,52 +1136,36 @@ public function getIssues(Request $request, $project_key) $query = DB::collection('issue_' . $project_key)->whereRaw($where); $issues = $query->orderBy('no', 'desc')->take(10000)->get(); - foreach($issues as $issue) - { - foreach ($XYData as $dimension => $z) - { - if (!isset($issue[$dimension]) || !$issue[$dimension]) - { + foreach ($issues as $issue) { + foreach ($XYData as $dimension => $z) { + if (!isset($issue[$dimension]) || !$issue[$dimension]) { continue; } $issue_vals = []; - if (is_string($issue[$dimension])) - { - if (strpos($issue[$dimension], ',') !== false) - { + if (is_string($issue[$dimension])) { + if (strpos($issue[$dimension], ',') !== false) { $issue_vals = explode(',', $issue[$dimension]); - } - else - { + } else { $issue_vals = [ $issue[$dimension] ]; } - } - else if (is_array($issue[$dimension])) - { + } elseif (is_array($issue[$dimension])) { $issue_vals = $issue[$dimension]; - if (isset($issue[$dimension]['id'])) - { + if (isset($issue[$dimension]['id'])) { $issue_vals = [ $issue[$dimension] ]; } } - foreach ($issue_vals as $issue_val) - { + foreach ($issue_vals as $issue_val) { $tmpv = $issue_val; - if (is_array($issue_val) && isset($issue_val['id'])) - { + if (is_array($issue_val) && isset($issue_val['id'])) { $tmpv = $issue_val['id']; } - if (isset($z[$tmpv])) - { + if (isset($z[$tmpv])) { $XYData[$dimension][$tmpv]['nos'][] = $issue['no']; - } - else if ((is_array($issue_val) && isset($issue_val['id'])) || $dimension === 'labels') - { - if ($dimension === $Y && $X !== $Y) - { + } elseif ((is_array($issue_val) && isset($issue_val['id'])) || $dimension === 'labels') { + if ($dimension === $Y && $X !== $Y) { $YAxis[$tmpv] = isset($issue[$dimension]['name']) ? $issue[$dimension]['name'] : $tmpv; } @@ -1436,47 +1176,34 @@ public function getIssues(Request $request, $project_key) } $results = []; - if ($X === $Y || !$Y) - { - foreach ($XYData[$X] as $key => $value) - { + if ($X === $Y || !$Y) { + foreach ($XYData[$X] as $key => $value) { $results[] = [ 'id' => $key, 'name' => $value['name'], 'cnt' => count($value['nos']) ]; } - } - else - { - foreach ($XYData[$X] as $key => $value) - { + } else { + foreach ($XYData[$X] as $key => $value) { $results[$key] = [ 'id' => $key, 'name' => $value['name'], 'y' => [] ]; $x_cnt = 0; - if ($YAxis) - { - foreach ($YAxis as $yai => $yav) - { - if (isset($XYData[$Y][$yai])) - { + if ($YAxis) { + foreach ($YAxis as $yai => $yav) { + if (isset($XYData[$Y][$yai])) { $y_cnt = count(array_intersect($value['nos'], $XYData[$Y][$yai]['nos'])); $results[$key]['y'][] = [ 'id' => $yai, 'name' => $yav, 'cnt' => $y_cnt ]; $x_cnt += $y_cnt; - } - else - { + } else { $results[$key]['y'][] = [ 'id' => $yai, 'name' => yav, 'cnt' => 0 ]; } } - } - else - { - foreach ($XYData[$Y] as $key2 => $value2) - { + } else { + foreach ($XYData[$Y] as $key2 => $value2) { $y_cnt = count(array_intersect($value['nos'], $value2['nos'])); $results[$key]['y'][] = [ 'id' => $key2, 'name' => $value2['name'], 'cnt' => $y_cnt ]; $x_cnt += $y_cnt; } - } - $results[$key]['cnt'] = $x_cnt; + } + $results[$key]['cnt'] = $x_cnt; } } diff --git a/app/Http/Controllers/ResolutionController.php b/app/Http/Controllers/ResolutionController.php index 9c6686886..3432ea2ef 100644 --- a/app/Http/Controllers/ResolutionController.php +++ b/app/Http/Controllers/ResolutionController.php @@ -24,8 +24,7 @@ class ResolutionController extends Controller public function index($project_key) { $resolutions = Provider::getResolutionList($project_key); - foreach ($resolutions as $key => $resolution) - { + foreach ($resolutions as $key => $resolution) { $resolutions[$key]['is_used'] = $this->isFieldUsedByIssue($project_key, 'resolution', $resolution); } return Response()->json(['ecode' => 0, 'data' => $resolutions]); @@ -40,13 +39,11 @@ public function index($project_key) public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12500); } - if (Provider::isResolutionExisted($project_key, $name)) - { + if (Provider::isResolutionExisted($project_key, $name)) { throw new \UnexpectedValueException('resolution name cannot be repeated', -12501); } @@ -82,25 +79,20 @@ public function show($project_key, $id) public function update(Request $request, $project_key, $id) { $resolution = Resolution::find($id); - if (!$resolution || $project_key != $resolution->project_key) - { + if (!$resolution || $project_key != $resolution->project_key) { throw new \UnexpectedValueException('the resolution does not exist or is not in the project.', -12502); } - if (isset($resolution->key) && $resolution->key) - { + if (isset($resolution->key) && $resolution->key) { throw new \UnexpectedValueException('the resolution is built in the system.', -12504); } $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12500); } - if ($resolution->name !== $name && Provider::isResolutionExisted($project_key, $name)) - { + if ($resolution->name !== $name && Provider::isResolutionExisted($project_key, $name)) { throw new \UnexpectedValueException('resolution name cannot be repeated', -12501); } } @@ -120,45 +112,40 @@ public function update(Request $request, $project_key, $id) public function destroy($project_key, $id) { $resolution = Resolution::find($id); - if (!$resolution || $project_key != $resolution->project_key) - { + if (!$resolution || $project_key != $resolution->project_key) { throw new \UnexpectedValueException('the resolution does not exist or is not in the project.', -12502); } - if (isset($resolution->key) && in_array($resolution->key, [ 'Unresolved', 'Fixed' ])) - { + if (isset($resolution->key) && in_array($resolution->key, [ 'Unresolved', 'Fixed' ])) { throw new \UnexpectedValueException('the resolution is built in the system.', -12504); } $isUsed = $this->isFieldUsedByIssue($project_key, 'resolution', $resolution->toArray()); - if ($isUsed) - { + if ($isUsed) { throw new \UnexpectedValueException('the resolution has been used in issue.', -12503); } Resolution::destroy($id); $resolution_property = ResolutionProperty::Where('project_key', $project_key)->first(); - if ($resolution_property) - { - $properties = []; - if ($resolution_property->defaultValue == $id) - { - $properties['defaultValue'] = ''; - } - if ($resolution_property->sequence && in_array($id, $resolution_property->sequence)) - { - $sequence = []; - foreach ($resolution_property->sequence as $val) - { - if ($val == $id) { continue; } - $sequence[] = $val; - } - $properties['sequence'] = $sequence; - } + if ($resolution_property) { + $properties = []; + if ($resolution_property->defaultValue == $id) { + $properties['defaultValue'] = ''; + } + if ($resolution_property->sequence && in_array($id, $resolution_property->sequence)) { + $sequence = []; + foreach ($resolution_property->sequence as $val) { + if ($val == $id) { + continue; + } + $sequence[] = $val; + } + $properties['sequence'] = $sequence; + } - $resolution_property->fill($properties); - $resolution_property->save(); + $resolution_property->fill($properties); + $resolution_property->save(); } // trigger to change resolution field config @@ -174,12 +161,9 @@ public function destroy($project_key, $id) */ public function handle(Request $request, $project_key) { - if ($project_key === '$_sys_$') - { + if ($project_key === '$_sys_$') { return $this->handleSys($request, $project_key); - } - else - { + } else { return $this->handleProject($request, $project_key); } } @@ -195,27 +179,22 @@ public function handleProject(Request $request, $project_key) $properties = []; // set resolution sort. $sequence = $request->input('sequence'); - if (isset($sequence)) - { + if (isset($sequence)) { $properties['sequence'] = $sequence; } // set default value $defaultValue = $request->input('defaultValue'); - if (isset($defaultValue)) - { + if (isset($defaultValue)) { $properties['defaultValue'] = $defaultValue; } $resolution_property = ResolutionProperty::Where('project_key', $project_key)->first(); - if ($resolution_property) - { - $resolution_property->fill($properties); - $resolution_property->save(); - } - else - { - ResolutionProperty::create([ 'project_key' => $project_key ] + $properties); + if ($resolution_property) { + $resolution_property->fill($properties); + $resolution_property->save(); + } else { + ResolutionProperty::create([ 'project_key' => $project_key ] + $properties); } return Response()->json(['ecode' => 0, 'data' => [ 'sequence' => $sequence ?: null, 'default' => $defaultValue ?: null ]]); @@ -231,14 +210,11 @@ public function handleSys(Request $request, $project_key) { // set type sort. $sequence = $request->input('sequence'); - if (isset($sequence)) - { + if (isset($sequence)) { $i = 1; - foreach ($sequence as $resolution_id) - { + foreach ($sequence as $resolution_id) { $resolution = Resolution::find($resolution_id); - if (!$resolution || $resolution->project_key != $project_key) - { + if (!$resolution || $resolution->project_key != $project_key) { continue; } $resolution->sn = $i++; @@ -248,24 +224,18 @@ public function handleSys(Request $request, $project_key) // set default value $default_resolution_id = $request->input('defaultValue'); - if (isset($default_resolution_id)) - { + if (isset($default_resolution_id)) { $resolution = Resolution::find($default_resolution_id); - if (!$resolution || $resolution->project_key != $project_key) - { + if (!$resolution || $resolution->project_key != $project_key) { throw new \UnexpectedValueException('the resolution does not exist or is not in the project.', -12502); } $resolutions = Resolution::where('project_key', $project_key)->get(); - foreach ($resolutions as $resolution) - { - if ($resolution->id == $default_resolution_id) - { + foreach ($resolutions as $resolution) { + if ($resolution->id == $default_resolution_id) { $resolution->default = true; $resolution->save(); - } - else if (isset($resolution->default)) - { + } elseif (isset($resolution->default)) { $resolution->unset('default'); } } @@ -281,21 +251,18 @@ public function handleSys(Request $request, $project_key) */ public function viewUsedInProject($project_key, $id) { - if ($project_key !== '$_sys_$') - { + if ($project_key !== '$_sys_$') { return Response()->json(['ecode' => 0, 'data' => [] ]); } $res = []; $projects = Project::all(); - foreach($projects as $project) - { + foreach ($projects as $project) { $count = DB::collection('issue_' . $project->key) ->where('resolution', $id) ->where('del_flg', '<>', 1) ->count(); - if ($count > 0) - { + if ($count > 0) { $res[] = [ 'key' => $project->key, 'name' => $project->name, 'status' => $project->status, 'issue_count' => $count ]; } } diff --git a/app/Http/Controllers/RoleController.php b/app/Http/Controllers/RoleController.php index 80781c1ed..deccb695b 100644 --- a/app/Http/Controllers/RoleController.php +++ b/app/Http/Controllers/RoleController.php @@ -32,28 +32,21 @@ class RoleController extends Controller public function index($project_key) { $roles = Provider::getRoleList($project_key)->toArray(); - foreach ($roles as $key => $role) - { - if ($project_key === '$_sys_$') - { + foreach ($roles as $key => $role) { + if ($project_key === '$_sys_$') { $actor = Roleactor::where('role_id', $role['_id'])->first(); - if ($actor && ($actor->user_ids || $actor->group_ids)) - { + if ($actor && ($actor->user_ids || $actor->group_ids)) { $roles[$key]['is_used'] = true; } - } - else - { + } else { $user_groups = $this->getGroupsAndUsers($project_key, $role['_id']); $roles[$key]['users'] = $user_groups['users']; $roles[$key]['groups'] = $user_groups['groups']; - if (isset($role['user_ids'])) - { + if (isset($role['user_ids'])) { unset($roles[$key]['user_ids']); } - if (isset($role['group_ids'])) - { + if (isset($role['group_ids'])) { unset($roles[$key]['group_ids']); } } @@ -72,25 +65,21 @@ public function index($project_key) public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12700); } $permissions = $request->input('permissions'); - if (isset($permissions)) - { + if (isset($permissions)) { $allPermissions = Acl::getAllPermissions(); - if (array_diff($permissions, $allPermissions)) - { + if (array_diff($permissions, $allPermissions)) { throw new \UnexpectedValueException('the illegal permission.', -12701); } } $role = Role::create($request->all() + [ 'project_key' => $project_key ]); - if (isset($permissions) && $role) - { + if (isset($permissions) && $role) { RolePermissions::create([ 'project_key' => $project_key, 'role_id' => $role->id, 'permissions' => $permissions ]); $role->permissions = $permissions; } @@ -120,8 +109,7 @@ public function show($project_key, $id) public function setActor(Request $request, $project_key, $id) { $new_user_ids = $request->input('users'); - if (isset($new_user_ids)) - { + if (isset($new_user_ids)) { $actor = Roleactor::where([ 'project_key' => $project_key, 'role_id' => $id ])->first(); $old_user_ids = $actor && $actor->user_ids ? $actor->user_ids : []; @@ -152,8 +140,7 @@ public function setActor(Request $request, $project_key, $id) public function setGroupActor(Request $request, $project_key, $id) { $new_group_ids = $request->input('groups'); - if (isset($new_group_ids)) - { + if (isset($new_group_ids)) { $actor = Roleactor::where([ 'project_key' => $project_key, 'role_id' => $id ])->first(); $old_group_ids = $actor && $actor->group_ids ? $actor->group_ids : []; @@ -184,25 +171,20 @@ public function setGroupActor(Request $request, $project_key, $id) public function update(Request $request, $project_key, $id) { $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12700); } } $role = Role::find($id); - if (!$role || $project_key != $role->project_key) - { + if (!$role || $project_key != $role->project_key) { throw new \UnexpectedValueException('the role does not exist or is not in the project.', -12702); } $permissions = $request->input('permissions'); - if (isset($permissions)) - { + if (isset($permissions)) { $allPermissions = Acl::getAllPermissions(); - if (array_diff($permissions, $allPermissions)) - { + if (array_diff($permissions, $allPermissions)) { throw new \UnexpectedValueException('the illegal permission.', -12701); } $role->permissions = $permissions; @@ -222,32 +204,24 @@ public function update(Request $request, $project_key, $id) public function destroy($project_key, $id) { $role = Role::find($id); - if (!$role || $project_key != $role->project_key) - { + if (!$role || $project_key != $role->project_key) { throw new \UnexpectedValueException('the role does not exist or is not in the project.', -12702); } - if ($project_key === '$_sys_$') - { + if ($project_key === '$_sys_$') { $actors = Roleactor::where('role_id', $role->id)->get(); - foreach($actors as $actor) - { - if ($actor->user_ids || $actor->group_ids) - { + foreach ($actors as $actor) { + if ($actor->user_ids || $actor->group_ids) { throw new \UnexpectedValueException('the role has been used in some projects.', -12703); } } - foreach($actors as $actor) - { + foreach ($actors as $actor) { $actor->delete(); } - } - else - { + } else { $actor = Roleactor::where([ 'project_key' => $project_key, 'role_id' => $id ])->first(); - if ($actor) - { - $user_ids = isset($actor->user_ids) ? $actor->user_ids : []; + if ($actor) { + $user_ids = isset($actor->user_ids) ? $actor->user_ids : []; $user_ids && Event::fire(new DelUserFromRoleEvent($user_ids, $project_key)); $group_ids = isset($actor->group_ids) ? $actor->group_ids : []; $group_ids && Event::fire(new DelGroupFromRoleEvent($group_ids, $project_key)); @@ -294,26 +268,25 @@ public function setGroups($project_key, $role_id, $gids) * * @param string $project_key * @param string $role_id - * @return array + * @return array */ public function getGroupsAndUsers($project_key, $role_id) { $actor = Roleactor::where([ 'project_key' => $project_key, 'role_id' => $role_id ])->first(); - if (!$actor) { return [ 'users' => [], 'groups' => [] ]; } + if (!$actor) { + return [ 'users' => [], 'groups' => [] ]; + } $new_users = []; - if (isset($actor->user_ids) && $actor->user_ids) - { + if (isset($actor->user_ids) && $actor->user_ids) { $users = EloquentUser::find($actor->user_ids); - foreach ($users as $user) - { + foreach ($users as $user) { $new_users[] = [ 'id' => $user->id, 'name' => $user->first_name, 'email' => $user->email, 'nameAndEmail' => $user->first_name . '('. $user->email . ')' ]; } } $new_groups = []; - if (isset($actor->group_ids) && $actor->group_ids) - { + if (isset($actor->group_ids) && $actor->group_ids) { $new_groups = Group::find($actor->group_ids)->toArray(); } @@ -321,7 +294,7 @@ public function getGroupsAndUsers($project_key, $role_id) } /** - * set permissions + * set permissions * * @param string $project_key * @param string $role_id @@ -330,17 +303,14 @@ public function getGroupsAndUsers($project_key, $role_id) public function setPermissions(Request $request, $project_key, $id) { $role = Role::find($id); - if (!$role || ($role->project_key != '$_sys_$' && $project_key != $role->project_key)) - { + if (!$role || ($role->project_key != '$_sys_$' && $project_key != $role->project_key)) { throw new \UnexpectedValueException('the role does not exist or is not in the project.', -12702); } $permissions = $request->input('permissions'); - if (isset($permissions)) - { + if (isset($permissions)) { $allPermissions = Acl::getAllPermissions(); - if (array_diff($permissions, $allPermissions)) - { + if (array_diff($permissions, $allPermissions)) { throw new \UnexpectedValueException('the illegal permission.', -12701); } @@ -364,8 +334,7 @@ public function setPermissions(Request $request, $project_key, $id) public function getPermissions($project_key, $role_id) { $rp = RolePermissions::where([ 'project_key' => $project_key, 'role_id' => $role_id ])->first(); - if (!$rp && $project_key !== '$_sys_$') - { + if (!$rp && $project_key !== '$_sys_$') { $rp = RolePermissions::where([ 'project_key' => '$_sys_$', 'role_id' => $role_id ])->first(); } return $rp && isset($rp->permissions) ? $rp->permissions : []; @@ -398,22 +367,19 @@ public function reset($project_key, $role_id) */ public function viewUsedInProject($project_key, $id) { - if ($project_key !== '$_sys_$') - { + if ($project_key !== '$_sys_$') { return Response()->json(['ecode' => 0, 'data' => [] ]); } $res = []; $projects = Project::all(); - foreach($projects as $project) - { + foreach ($projects as $project) { $roleactor = Roleactor::where('role_id', $id) ->where('project_key', '<>', '$_sys_$') ->where('project_key', $project->key) ->first(); - if ($roleactor && ($roleactor->user_ids || $roleactor->group_ids)) - { + if ($roleactor && ($roleactor->user_ids || $roleactor->group_ids)) { $res[] = [ 'key' => $project->key, 'name' => $project->name, 'status' => $project->status ]; } } diff --git a/app/Http/Controllers/ScreenController.php b/app/Http/Controllers/ScreenController.php index 821ad0f2c..b245af596 100644 --- a/app/Http/Controllers/ScreenController.php +++ b/app/Http/Controllers/ScreenController.php @@ -23,24 +23,20 @@ class ScreenController extends Controller public function index($project_key) { $screens = Provider::getScreenList($project_key, [ 'name', 'project_key', 'schema', 'description' ]); - foreach ($screens as $screen) - { + foreach ($screens as $screen) { $workflows = Definition::whereRaw([ 'screen_ids' => $screen->id ]) ->orderBy('project_key', 'asc') ->get([ 'project_key', 'name' ]) ->toArray(); $screen->workflows = $workflows; - if ($workflows) - { + if ($workflows) { $screen->is_used = true; - } - else - { - $screen->is_used = Type::where('screen_id', $screen->id)->exists(); + } else { + $screen->is_used = Type::where('screen_id', $screen->id)->exists(); } - $screen->workflows = array_filter($workflows, function($item) use($project_key) { + $screen->workflows = array_filter($workflows, function ($item) use ($project_key) { return $item['project_key'] === $project_key || $item['project_key'] === '$_sys_$'; }); } @@ -58,20 +54,16 @@ public function index($project_key) public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12300); } $source_id = $request->input('source_id'); - if (isset($source_id) && $source_id) - { + if (isset($source_id) && $source_id) { $source_screen = Screen::find($source_id); $schema = $source_screen->schema; - $field_ids = $source_screen->field_ids; - } - else - { + $field_ids = $source_screen->field_ids; + } else { $field_ids = $request->input('fields') ?: []; $required_field_ids = $request->input('required_fields') ?: []; // create screen schema @@ -110,38 +102,29 @@ public function show($project_key, $id) public function update(Request $request, $project_key, $id) { $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12300); } } $screen = Screen::find($id); - if (!$screen || $project_key != $screen->project_key) - { + if (!$screen || $project_key != $screen->project_key) { throw new \UnexpectedValueException('the screen does not exist or is not in the project.', -12301); } // when screen fields change, re-generate schema $field_ids = $request->input('fields'); - if (isset($field_ids)) - { + if (isset($field_ids)) { $mapFields = []; - foreach ($screen->schema as $field) - { + foreach ($screen->schema as $field) { $mapFields[$field['_id']] = $field; } $new_schema = []; - foreach ($field_ids as $field_id) - { - if (array_key_exists($field_id, $mapFields)) - { + foreach ($field_ids as $field_id) { + if (array_key_exists($field_id, $mapFields)) { $new_schema[] = $mapFields[$field_id]; - } - else - { + } else { $new_schema[] = Field::Find($field_id, ['name', 'key', 'type', 'defaultValue', 'optionValues', 'minValue', 'maxValue', 'maxLength'])->toArray(); } } @@ -151,17 +134,12 @@ public function update(Request $request, $project_key, $id) // when required fields change, re-generate schema $required_field_ids = $request->input('required_fields'); - if (isset($required_field_ids)) - { + if (isset($required_field_ids)) { $new_schema = []; - foreach ($screen->schema as $field) - { - if (in_array($field['_id'], $required_field_ids ?: [])) - { + foreach ($screen->schema as $field) { + if (in_array($field['_id'], $required_field_ids ?: [])) { $field['required'] = true; - } - else - { + } else { unset($field['required']); } $new_schema[] = $field; @@ -182,20 +160,17 @@ public function update(Request $request, $project_key, $id) public function destroy($project_key, $id) { $screen = Screen::find($id); - if (!$screen || $project_key != $screen->project_key) - { + if (!$screen || $project_key != $screen->project_key) { throw new \UnexpectedValueException('the screen does not exist or is not in the project.', -12301); } $isUsed = Type::where('screen_id', $id)->exists(); - if ($isUsed) - { + if ($isUsed) { throw new \UnexpectedValueException('the screen has been bound to type.', -12302); } $isUsed = Definition::whereRaw([ 'screen_ids' => $id ])->exists(); - if ($isUsed) - { + if ($isUsed) { throw new \UnexpectedValueException('the screen has been used in workflow.', -12303); } @@ -213,15 +188,12 @@ public function destroy($project_key, $id) public function createSchema(array $field_ids, array $required_field_ids) { $schema = []; - foreach ($field_ids as $field_id) - { + foreach ($field_ids as $field_id) { $new_field = Field::Find($field_id, ['name', 'key', 'type', 'applyToTypes', 'defaultValue', 'optionValues'])->toArray(); - if (!$new_field) - { + if (!$new_field) { continue; } - if (in_array($field_id, $required_field_ids)) - { + if (in_array($field_id, $required_field_ids)) { $new_field['required'] = true; } $schema[] = $new_field; @@ -236,16 +208,14 @@ public function createSchema(array $field_ids, array $required_field_ids) */ public function viewUsedInProject($project_key, $id) { - if ($project_key !== '$_sys_$') - { + if ($project_key !== '$_sys_$') { return Response()->json(['ecode' => 0, 'data' => [] ]); } $res = []; $projects = Project::all(); - foreach($projects as $project) - { - $types = Type::where('screen_id', $id) + foreach ($projects as $project) { + $types = Type::where('screen_id', $id) ->where('project_key', '<>', '$_sys_$') ->where('project_key', $project->key) ->get([ 'id', 'name' ]) @@ -257,8 +227,7 @@ public function viewUsedInProject($project_key, $id) ->get([ 'id', 'name' ]) ->toArray(); - if ($types || $workflows) - { + if ($types || $workflows) { $tmp = [ 'key' => $project->key, 'name' => $project->name, 'status' => $project->status ]; $tmp['types'] = $types ?: []; $tmp['workflows'] = $workflows ?: []; diff --git a/app/Http/Controllers/SessionController.php b/app/Http/Controllers/SessionController.php index d3bd52f15..f9ffcddab 100644 --- a/app/Http/Controllers/SessionController.php +++ b/app/Http/Controllers/SessionController.php @@ -32,70 +32,58 @@ public function create(Request $request) { $email = $request->input('email'); $password = $request->input('password'); - if (!$email || !$password) - { + if (!$email || !$password) { throw new \UnexpectedValueException('email or password cannot be empty.', -10003); } $setting = SysSetting::first(); - if (strpos($email, '@') === false) - { - if ($setting && isset($setting->properties) && isset($setting->properties['login_mail_domain'])) - { - $email = $email . '@' . $setting->properties['login_mail_domain']; + if (strpos($email, '@') === false) { + if ($setting && isset($setting->properties) && isset($setting->properties['login_mail_domain'])) { + $email = $email . '@' . $setting->properties['login_mail_domain']; } } try { - if (!($setting && isset($setting->properties) && isset($setting->properties['enable_login_protection']) && $setting->properties['enable_login_protection'] === 1)) - { + if (!($setting && isset($setting->properties) && isset($setting->properties['enable_login_protection']) && $setting->properties['enable_login_protection'] === 1)) { Sentinel::removeCheckpoint('throttle'); } $user = Sentinel::authenticate([ 'email' => $email, 'password' => $password ]); } catch (ThrottlingException $e) { - // throttle error. + // throttle error. throw new Exception($e->getMessage(), -10004); } catch (NotActivatedException $e) { throw new Exception('the user is not activated.', -10005); } // ldap authenticate - if (!$user) - { + if (!$user) { $configs = []; $directories = Directory::where('type', 'OpenLDAP') ->where('invalid_flag', '<>', 1) ->get(); - foreach ($directories as $d) - { + foreach ($directories as $d) { $configs[$d->id] = $d->configs ?: []; } - if ($configs) - { + if ($configs) { $user = LDAP::attempt($configs, $email, $password); } } - if ($user) - { - if ($user->invalid_flag == 1) - { + if ($user) { + if ($user->invalid_flag == 1) { throw new Exception('the user is disabed.', -10006); } Sentinel::login($user); $latest_access_project = $this->getLatestAccessProject($user->id); - if ($latest_access_project) - { + if ($latest_access_project) { $user->latest_access_project = $latest_access_project->key; } return Response()->json([ 'ecode' => 0, 'data' => [ 'user' => $user ] ]); - } - else - { + } else { return Response()->json([ 'ecode' => -10000, 'data' => [] ]); } } @@ -104,21 +92,19 @@ public function create(Request $request) * get the latest project. * * @param string $uid - * @return Object + * @return Object */ public function getLatestAccessProject($uid) { - // get latest access project + // get latest access project $latest_access_project = AccessProjectLog::where('user_id', $uid) ->where('latest_access_time', '>', time() - 2 * 7 * 24 * 3600) ->orderBy('latest_access_time', 'desc') ->first(); - if ($latest_access_project) - { + if ($latest_access_project) { $project = Project::where('key', $latest_access_project->project_key)->first(); - if ($project && $project->status === 'active') - { + if ($project && $project->status === 'active') { return $project; } } @@ -134,17 +120,13 @@ public function getLatestAccessProject($uid) public function getSess(Request $request) { $user = Sentinel::getUser(); - if ($user) - { + if ($user) { $latest_access_project = $this->getLatestAccessProject($user->id); - if ($latest_access_project) - { + if ($latest_access_project) { $user->latest_access_project = $latest_access_project->key; } return Response()->json([ 'ecode' => 0, 'data' => [ 'user' => $user ] ]); - } - else - { + } else { return Response()->json([ 'ecode' => -10001, 'data' => [ 'user' => [] ] ]); } } diff --git a/app/Http/Controllers/SprintController.php b/app/Http/Controllers/SprintController.php index 8c5051ccf..6b6077fe0 100644 --- a/app/Http/Controllers/SprintController.php +++ b/app/Http/Controllers/SprintController.php @@ -40,12 +40,12 @@ public function index($project_key) public function store(Request $request, $project_key) { $sprint_count = Sprint::where('project_key', $project_key)->count(); - $sprint = Sprint::create([ - 'project_key' => $project_key, - 'no' => $sprint_count + 1, + $sprint = Sprint::create([ + 'project_key' => $project_key, + 'no' => $sprint_count + 1, 'name' => 'Sprint ' . ($sprint_count + 1), - 'status' => 'waiting', - 'issues' => [] + 'status' => 'waiting', + 'issues' => [] ]); return Response()->json(['ecode' => 0, 'data' => $this->getValidSprintList($project_key)]); } @@ -58,59 +58,48 @@ public function store(Request $request, $project_key) public function moveIssue(Request $request, $project_key) { $issue_no = $request->input('issue_no'); - if (!$issue_no) - { + if (!$issue_no) { throw new \UnexpectedValueException('the moved issue cannot be empty', -11700); } $src_sprint_no = $request->input('src_sprint_no'); - if (!isset($src_sprint_no)) - { + if (!isset($src_sprint_no)) { throw new \UnexpectedValueException('the src sprint of moved issue cannot be empty', -11701); } $src_sprint_no = intval($src_sprint_no); $dest_sprint_no = $request->input('dest_sprint_no'); - if (!isset($dest_sprint_no)) - { + if (!isset($dest_sprint_no)) { throw new \UnexpectedValueException('the dest sprint of moved issue cannot be empty', -11702); } $dest_sprint_no = intval($dest_sprint_no); - if ($src_sprint_no > 0) - { - $src_sprint = Sprint::where('project_key', $project_key)->where('no', $src_sprint_no)->first(); - if (!in_array($issue_no, $src_sprint->issues ?: [])) - { + if ($src_sprint_no > 0) { + $src_sprint = Sprint::where('project_key', $project_key)->where('no', $src_sprint_no)->first(); + if (!in_array($issue_no, $src_sprint->issues ?: [])) { throw new \UnexpectedValueException('the moved issue cannot be found in the src sprint', -11703); } - if ($src_sprint->status == 'completed') - { + if ($src_sprint->status == 'completed') { throw new \UnexpectedValueException('the moved issue cannot be moved into or moved out of the completed sprint', -11706); } $src_sprint->fill([ 'issues' => array_values(array_diff($src_sprint->issues, [ $issue_no ]) ?: []) ])->save(); - if ($src_sprint->status == 'active') - { + if ($src_sprint->status == 'active') { $this->popSprint($project_key, $issue_no, $src_sprint_no); } } - if ($dest_sprint_no > 0) - { + if ($dest_sprint_no > 0) { $dest_sprint = Sprint::where('project_key', $project_key)->where('no', $dest_sprint_no)->first(); - if (in_array($issue_no, $dest_sprint->issues ?: [])) - { + if (in_array($issue_no, $dest_sprint->issues ?: [])) { throw new \UnexpectedValueException('the moved issue has been in the dest sprint', -11704); } - if ($dest_sprint->status == 'completed') - { + if ($dest_sprint->status == 'completed') { throw new \UnexpectedValueException('the moved issue cannot be moved into or moved out of the completed sprint', -11706); } $dest_sprint->fill([ 'issues' => array_values(array_merge($dest_sprint->issues ?: [], [ $issue_no ])) ])->save(); - if ($dest_sprint->status == 'active') - { + if ($dest_sprint->status == 'active') { $this->pushSprint($project_key, $issue_no, $dest_sprint_no); } } @@ -127,8 +116,7 @@ public function moveIssue(Request $request, $project_key) public function show($project_key, $no) { $sprint = Sprint::where('project_key', $project_key)->where('no', intval($no))->first(); - if (!$sprint->name) - { + if (!$sprint->name) { $sprint->name = 'Sprint ' . $sprint->no; } @@ -144,8 +132,7 @@ public function show($project_key, $no) */ public function publish(Request $request, $project_key, $no) { - if (!$no) - { + if (!$no) { throw new \UnexpectedValueException('the published sprint cannot be empty', -11705); } $no = intval($no); @@ -153,8 +140,7 @@ public function publish(Request $request, $project_key, $no) $active_sprint_exists = Sprint::where('project_key', $project_key) ->where('status', 'active') ->exists(); - if ($active_sprint_exists) - { + if ($active_sprint_exists) { throw new \UnexpectedValueException('the active sprint has been exists.', -11706); } @@ -162,56 +148,45 @@ public function publish(Request $request, $project_key, $no) ->where('status', 'waiting') ->where('no', '<', $no) ->exists(); - if ($before_waiting_sprint_exists) - { + if ($before_waiting_sprint_exists) { throw new \UnexpectedValueException('the more first sprint has been exists.', -11707); } $sprint = Sprint::where('project_key', $project_key) ->where('no', $no) ->first(); - if (!$sprint || $project_key != $sprint->project_key) - { + if (!$sprint || $project_key != $sprint->project_key) { throw new \UnexpectedValueException('the sprint does not exist or is not in the project.', -11708); } $updValues = [ 'status' => 'active' ]; $start_time = $request->input('start_time'); - if (isset($start_time) && $start_time) - { + if (isset($start_time) && $start_time) { $updValues['start_time'] = $start_time; - } - else - { + } else { throw new \UnexpectedValueException('the sprint start time cannot be empty.', -11709); } $complete_time = $request->input('complete_time'); - if (isset($complete_time) && $complete_time) - { + if (isset($complete_time) && $complete_time) { $updValues['complete_time'] = $complete_time; - } - else - { + } else { throw new \UnexpectedValueException('the sprint complete time cannot be empty.', -11710); } $name = $request->input('name'); - if (isset($name) && $name) - { + if (isset($name) && $name) { $updValues['name'] = $name; } $description = $request->input('description'); - if (isset($description) && $description) - { + if (isset($description) && $description) { $updValues['description'] = $description; } $kanban_id = $request->input('kanban_id'); - if (!isset($kanban_id) || !$kanban_id) - { + if (!isset($kanban_id) || !$kanban_id) { throw new \UnexpectedValueException('the kanban id cannot be empty', -11717); } @@ -222,8 +197,7 @@ public function publish(Request $request, $project_key, $no) $sprint->fill($updValues)->save(); - foreach ($new_issues['issues'] as $issue_no) - { + foreach ($new_issues['issues'] as $issue_no) { $this->pushSprint($project_key, $issue_no, $no); } @@ -243,29 +217,25 @@ public function publish(Request $request, $project_key, $no) */ public function update(Request $request, $project_key, $no) { - if (!$no) - { + if (!$no) { throw new \UnexpectedValueException('the updated sprint cannot be empty', -11718); } $no = intval($no); $sprint = Sprint::where('project_key', $project_key)->where('no', $no)->first(); - if (!$sprint || $project_key != $sprint->project_key) - { + if (!$sprint || $project_key != $sprint->project_key) { throw new \UnexpectedValueException('the sprint does not exist or is not in the project.', -11708); } $updValues = []; $name = $request->input('name'); - if (isset($name) && $name) - { + if (isset($name) && $name) { $updValues['name'] = $name; } $description = $request->input('description'); - if (isset($description) && $description) - { + if (isset($description) && $description) { $updValues['description'] = $description; } @@ -283,52 +253,45 @@ public function update(Request $request, $project_key, $no) */ public function complete(Request $request, $project_key, $no) { - if (!$no) - { + if (!$no) { throw new \UnexpectedValueException('the completed sprint cannot be empty', -11711); } $no = intval($no); $sprint = Sprint::where('project_key', $project_key)->where('no', $no)->first(); - if (!$sprint || $project_key != $sprint->project_key) - { + if (!$sprint || $project_key != $sprint->project_key) { throw new \UnexpectedValueException('the sprint does not exist or is not in the project.', -11708); } - if (!isset($sprint->status) || $sprint->status != 'active') - { + if (!isset($sprint->status) || $sprint->status != 'active') { throw new \UnexpectedValueException('the completed sprint must be active.', -11712); } $completed_issues = $request->input('completed_issues') ?: []; - if (array_diff($completed_issues, $sprint->issues)) - { + if (array_diff($completed_issues, $sprint->issues)) { throw new \UnexpectedValueException('the completed sprint issues have errors.', -11713); } $incompleted_issues = array_values(array_diff($sprint->issues, $completed_issues)); $valid_incompleted_issues = DB::collection('issue_' . $project_key)->whereIn('no', $incompleted_issues)->where('del_flg', '<>', 1)->get([ 'no' ]); - if ($valid_incompleted_issues) - { - $valid_incompleted_issues = array_column($valid_incompleted_issues, 'no'); - $incompleted_issues = array_values(array_intersect($incompleted_issues, $valid_incompleted_issues)); + if ($valid_incompleted_issues) { + $valid_incompleted_issues = array_column($valid_incompleted_issues, 'no'); + $incompleted_issues = array_values(array_intersect($incompleted_issues, $valid_incompleted_issues)); } - $updValues = [ - 'status' => 'completed', - 'real_complete_time' => time(), + $updValues = [ + 'status' => 'completed', + 'real_complete_time' => time(), 'completed_issues' => $completed_issues, - 'incompleted_issues' => $incompleted_issues + 'incompleted_issues' => $incompleted_issues ]; $sprint->fill($updValues)->save(); - if ($incompleted_issues) - { + if ($incompleted_issues) { $next_sprint = Sprint::where('project_key', $project_key)->where('status', 'waiting')->orderBy('no', 'asc')->first(); - if ($next_sprint) - { + if ($next_sprint) { $issues = !isset($next_sprint->issues) || !$next_sprint->issues ? [] : $next_sprint->issues; $issues = array_merge($incompleted_issues, $issues); $next_sprint->fill([ 'issues' => $issues ])->save(); @@ -350,28 +313,23 @@ public function complete(Request $request, $project_key, $no) */ public function destroy($project_key, $no) { - if (!$no) - { + if (!$no) { throw new \UnexpectedValueException('the deleted sprint cannot be empty', -11714); } $no = intval($no); $sprint = Sprint::where('project_key', $project_key)->where('no', $no)->first(); - if (!$sprint || $project_key != $sprint->project_key) - { + if (!$sprint || $project_key != $sprint->project_key) { throw new \UnexpectedValueException('the sprint does not exist or is not in the project.', -11708); } - if ($sprint->status == 'completed' || $sprint->status == 'active') - { + if ($sprint->status == 'completed' || $sprint->status == 'active') { throw new \UnexpectedValueException('the active or completed sprint cannot be removed.', -11715); } - if (isset($sprint->issues) && $sprint->issues) - { + if (isset($sprint->issues) && $sprint->issues) { $next_sprint = Sprint::where('project_key', $project_key)->where('no', '>', $no)->first(); - if ($next_sprint) - { + if ($next_sprint) { $issues = !isset($next_sprint->issues) || !$next_sprint->issues ? [] : $next_sprint->issues; $issues = array_merge($sprint->issues, $issues); $next_sprint->fill([ 'issues' => $issues ])->save(); @@ -389,7 +347,7 @@ public function destroy($project_key, $no) * get waiting or active sprint list. * * @param string $project_key - * @return array + * @return array */ public function getValidSprintList($project_key) { @@ -398,10 +356,8 @@ public function getValidSprintList($project_key) ->orderBy('no', 'asc') ->get(); - foreach ($sprints as $sprint) - { - if (!$sprint->name) - { + foreach ($sprints as $sprint) { + if (!$sprint->name) { $sprint->name = 'Sprint ' . $sprint->no; } } @@ -415,19 +371,17 @@ public function getValidSprintList($project_key) * @param string $project_key * @param string $issue_no * @param string $sprint_no - * @return void + * @return void */ public function pushSprint($project_key, $issue_no, $sprint_no) { $issue = DB::collection('issue_' . $project_key)->where('no', $issue_no)->first(); - if (!$issue) - { + if (!$issue) { return; } $sprints = []; - if (isset($issue['sprints']) && $issue['sprints']) - { + if (isset($issue['sprints']) && $issue['sprints']) { $sprints = $issue['sprints']; } array_push($sprints, $sprint_no); @@ -441,19 +395,17 @@ public function pushSprint($project_key, $issue_no, $sprint_no) * @param string $project_key * @param string $issue_no * @param string $sprint_no - * @return void + * @return void */ public function popSprint($project_key, $issue_no, $sprint_no) { $issue = DB::collection('issue_' . $project_key)->where('no', $issue_no)->first(); - if (!$issue) - { + if (!$issue) { return; } $sprints = []; - if (isset($issue['sprints']) && $issue['sprints']) - { + if (isset($issue['sprints']) && $issue['sprints']) { $sprints = $issue['sprints']; } $new_sprints = array_diff($sprints, [ $sprint_no ]); @@ -461,37 +413,35 @@ public function popSprint($project_key, $issue_no, $sprint_no) DB::collection('issue_' . $project_key)->where('no', $issue_no)->update(['sprints' => $new_sprints]); } - /** - * get the last column state of the kanban. - * - * @param string $kanban_id - * @return array - */ + /** + * get the last column state of the kanban. + * + * @param string $kanban_id + * @return array + */ public function getLastColumnStates($kanban_id) { // remaining start $last_column_states = []; $board = Board::find($kanban_id); - if ($board && isset($board->columns)) - { + if ($board && isset($board->columns)) { $board_columns = $board->columns; $last_column = array_pop($board_columns) ?: []; - if ($last_column && isset($last_column['states']) && $last_column['states']) - { + if ($last_column && isset($last_column['states']) && $last_column['states']) { $last_column_states = $last_column['states']; } } - return $last_column_states; + return $last_column_states; } - /** - * get sprint original state. - * - * @param string $project_key - * @param array $issue_nos - * @param string $kanban_id - * @return array - */ + /** + * get sprint original state. + * + * @param string $project_key + * @param array $issue_nos + * @param string $kanban_id + * @return array + */ public function filterIssues($project_key, $issue_nos, $kanban_id) { // get the kanban last column states @@ -504,8 +454,7 @@ public function filterIssues($project_key, $issue_nos, $kanban_id) ->where([ 'no' => [ '$in' => $issue_nos ] ]) ->where([ 'state' => [ '$nin' => $last_column_states ] ]) ->get(); - foreach ($issues as $issue) - { + foreach ($issues as $issue) { $new_issue_nos[] = $issue['no']; $origin_issues[] = [ @@ -517,22 +466,21 @@ public function filterIssues($project_key, $issue_nos, $kanban_id) return [ 'issues' => $new_issue_nos, 'origin_issues' => $origin_issues ]; } - /** - * get sprint original state. - * - * @param string $project_key - * @param array $issue_nos - * @return array - */ + /** + * get sprint original state. + * + * @param string $project_key + * @param array $issue_nos + * @return array + */ public function getOriginIssues($project_key, $issue_nos) { $origin_issues = []; $issues = DB::collection('issue_' . $project_key)->where([ 'no' => [ '$in' => $issue_nos ] ])->get(); - foreach ($issues as $issue) - { - $origin_issues[] = [ - 'no' => $issue['no'], - 'state' => isset($issue['state']) ? $issue['state'] : '', + foreach ($issues as $issue) { + $origin_issues[] = [ + 'no' => $issue['no'], + 'state' => isset($issue['state']) ? $issue['state'] : '', 'story_points' => isset($issue['story_points']) ? $issue['story_points'] : 0 ]; } return $origin_issues; @@ -550,37 +498,31 @@ public function getLog(Request $request, $project_key, $sprint_no) $sprint_no = intval($sprint_no); $kanban_id = $request->input('kanban_id'); - if (!$kanban_id) - { + if (!$kanban_id) { throw new \UnexpectedValueException('the kanban id cannot be empty', -11717); } $sprint = Sprint::where('project_key', $project_key) ->where('no', $sprint_no) ->first(); - if (!$sprint) - { + if (!$sprint) { throw new \UnexpectedValueException('the sprint does not exist or is not in the project.', -11708); } $origin_issue_count = 0; - if (isset($sprint->origin_issues)) - { - $origin_issue_count = count($sprint->origin_issues); + if (isset($sprint->origin_issues)) { + $origin_issue_count = count($sprint->origin_issues); } $origin_story_points = 0; - if (isset($sprint->origin_issues)) - { - foreach ($sprint->origin_issues as $val) - { - $origin_story_points += $val['story_points']; + if (isset($sprint->origin_issues)) { + foreach ($sprint->origin_issues as $val) { + $origin_story_points += $val['story_points']; } } - $workingDays = $this->getWorkingDay($sprint->start_time, $sprint->complete_time); + $workingDays = $this->getWorkingDay($sprint->start_time, $sprint->complete_time); $workingDayNum = 0; - foreach ($workingDays as $val) - { + foreach ($workingDays as $val) { $workingDayNum += $val; } @@ -591,17 +533,15 @@ public function getLog(Request $request, $project_key, $sprint_no) $story_points_guideline[] = [ 'day' => '', 'value' => $origin_story_points ]; $tmp_issue_count = $origin_issue_count; $tmp_story_points = $origin_story_points; - foreach ($workingDays as $day => $flag) - { - if ($flag === 1) - { + foreach ($workingDays as $day => $flag) { + if ($flag === 1) { $tmp_issue_count = max([ round($tmp_issue_count - $origin_issue_count / $workingDayNum, 2), 0 ]); $tmp_story_points = max([ round($tmp_story_points - $origin_story_points / $workingDayNum, 2), 0 ]); } $issue_count_guideline[] = [ 'day' => substr($day, 5), 'value' => $tmp_issue_count, 'notWorking' => ($flag + 1) % 2 ]; $story_points_guideline[] = [ 'day' => substr($day, 5), 'value' => $tmp_story_points, 'notWorking' => ($flag + 1) % 2 ]; } - // guideline end + // guideline end // remaining start $last_column_states = $this->getLastColumnStates($kanban_id); @@ -613,23 +553,20 @@ public function getLog(Request $request, $project_key, $sprint_no) $issue_count_remaining = []; $story_points_remaining = []; - $issue_count_remaining[] = [ 'day' => '', 'value' => $origin_issue_count ]; - $story_points_remaining[] = [ 'day' => '', 'value' => $origin_story_points ]; - foreach($sprint_day_log as $daylog) - { + $issue_count_remaining[] = [ 'day' => '', 'value' => $origin_issue_count ]; + $story_points_remaining[] = [ 'day' => '', 'value' => $origin_story_points ]; + foreach ($sprint_day_log as $daylog) { $incompleted_issue_num = 0; $incompleted_story_points = 0; - $issues = isset($daylog->issues) ? $daylog->issues : []; - foreach ($issues as $issue) - { - if (!in_array($issue['state'], $last_column_states)) - { + $issues = isset($daylog->issues) ? $daylog->issues : []; + foreach ($issues as $issue) { + if (!in_array($issue['state'], $last_column_states)) { $incompleted_issue_num++; $incompleted_story_points += isset($issue['story_points']) ? $issue['story_points'] : 0; - } + } } - $issue_count_remaining[] = [ 'day' => substr($daylog->day, 5), 'value' => $incompleted_issue_num, 'notWorking' => isset($workingDays[$daylog->day]) ? ($workingDays[$daylog->day] + 1) % 2 : 0 ]; - $story_points_remaining[] = [ 'day' => substr($daylog->day, 5), 'value' => $incompleted_story_points, 'notWorking' => isset($workingDays[$daylog->day]) ? ($workingDays[$daylog->day] + 1) % 2 : 0 ]; + $issue_count_remaining[] = [ 'day' => substr($daylog->day, 5), 'value' => $incompleted_issue_num, 'notWorking' => isset($workingDays[$daylog->day]) ? ($workingDays[$daylog->day] + 1) % 2 : 0 ]; + $story_points_remaining[] = [ 'day' => substr($daylog->day, 5), 'value' => $incompleted_story_points, 'notWorking' => isset($workingDays[$daylog->day]) ? ($workingDays[$daylog->day] + 1) % 2 : 0 ]; } // remaining start @@ -647,8 +584,7 @@ public function getWorkingDay($start_time, $end_time) { $days = []; $tmp_time = $start_time; - while ($tmp_time < $end_time) - { + while ($tmp_time < $end_time) { $day = date('Y/m/d', $tmp_time); $days[] = $day; @@ -659,40 +595,31 @@ public function getWorkingDay($start_time, $end_time) } $singulars = CalendarSingular::where([ 'date' => [ '$in' => $days ] ])->get(); - foreach ($singulars as $singular) - { + foreach ($singulars as $singular) { $tmp = $singular->date; $workingDays[$tmp] = $singular->type == 'holiday' ? 0 : 1; } return $workingDays; } - public function t2m($val, $options) + public function t2m($val, $options) { $w2d = isset($options['w2d']) ? $options['w2d'] : 5; $d2h = isset($options['d2h']) ? $options['d2h'] : 8; $total = 0; $tmp = explode(' ', $val); - foreach ($tmp as $v) - { + foreach ($tmp as $v) { $t = substr($v, 0, strlen($v) - 1); $u = substr($v, -1); - if ($u == 'w' || $u == 'W') - { + if ($u == 'w' || $u == 'W') { $total += $total + $t * $w2d * $d2h; - } - else if ($u == 'd' || $u == 'D') - { + } elseif ($u == 'd' || $u == 'D') { $total += $t * $d2h * 60; - } - else if ($u == 'h' || $u == 'H') - { + } elseif ($u == 'h' || $u == 'H') { $total += $t * 60; - } - else - { + } else { $total += $t; } } @@ -703,14 +630,12 @@ public function getRemainingTime($issue_no) { $origin_estimate_time = 0; $issue = DB::where('no', $issue_no)->first(); - if (isset($issue['original_estimate'])) - { + if (isset($issue['original_estimate'])) { $origin_estimate_time = $issue['original_estimate']; } $leave_estimate_m = $this->t2m($origin_estimate_time); - if ($leave_estimate_m <= 0) - { + if ($leave_estimate_m <= 0) { return 0; } @@ -719,21 +644,15 @@ public function getRemainingTime($issue_no) ->orderBy('recorded_at', 'asc') ->get(); - foreach ($worklogs as $worklog) - { - if (!isset($worklog['spend'])) - { + foreach ($worklogs as $worklog) { + if (!isset($worklog['spend'])) { continue; } - if (isset($worklog['adjust_type'])) - { - if ($worklog['adjust_type'] == 1) - { + if (isset($worklog['adjust_type'])) { + if ($worklog['adjust_type'] == 1) { $spend_m = $this->t2m($worklog['spend']); $leave_estimate_m = $leave_estimate_m - $spend_m; - } - else if ($worklog['adjust_type'] == 3) - { + } elseif ($worklog['adjust_type'] == 3) { $leave_estimate_m = $this->t2m(isset($worklog['cut']) ? $worklog['cut'] : 0); } } diff --git a/app/Http/Controllers/StateController.php b/app/Http/Controllers/StateController.php index b169ce0ff..a1da8f4ee 100644 --- a/app/Http/Controllers/StateController.php +++ b/app/Http/Controllers/StateController.php @@ -22,24 +22,20 @@ class StateController extends Controller public function index($project_key) { $states = Provider::getStateList($project_key); - foreach ($states as $key => $state) - { + foreach ($states as $key => $state) { $workflows = Definition::whereRaw([ 'state_ids' => isset($state['key']) ? $state['key'] : $state['_id'] ]) ->orderBy('project_key', 'asc') ->get([ 'project_key', 'name' ]) ->toArray(); $states[$key]['workflows'] = $workflows; - if ($workflows) - { + if ($workflows) { $states[$key]['is_used'] = true; - } - else - { - $states[$key]['is_used'] = $this->isFieldUsedByIssue($project_key, 'state', $state); + } else { + $states[$key]['is_used'] = $this->isFieldUsedByIssue($project_key, 'state', $state); } - $states[$key]['workflows'] = array_filter($workflows, function($item) use($project_key) { + $states[$key]['workflows'] = array_filter($workflows, function ($item) use ($project_key) { return $item['project_key'] === $project_key || $item['project_key'] === '$_sys_$'; }); } @@ -55,19 +51,16 @@ public function index($project_key) public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12400); } $category = $request->input('category'); - if (!$category) - { + if (!$category) { throw new \UnexpectedValueException('the category can not be empty.', -12405); } - if (Provider::isStateExisted($project_key, $name)) - { + if (Provider::isStateExisted($project_key, $name)) { throw new \UnexpectedValueException('state name cannot be repeated', -12401); } @@ -101,32 +94,26 @@ public function show($project_key, $id) public function update(Request $request, $project_key, $id) { $state = State::find($id); - if (!$state || $project_key != $state->project_key) - { + if (!$state || $project_key != $state->project_key) { throw new \UnexpectedValueException('the state does not exist or is not in the project.', -12402); } - if (isset($state->key) && $state->key) - { + if (isset($state->key) && $state->key) { throw new \UnexpectedValueException('the state is built in the system.', -12406); } $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12400); } - if ($state->name !== $name && Provider::isStateExisted($project_key, $name)) - { + if ($state->name !== $name && Provider::isStateExisted($project_key, $name)) { throw new \UnexpectedValueException('state name cannot be repeated', -12401); } } $category = $request->input('category'); - if (!$category) - { + if (!$category) { throw new \UnexpectedValueException('the category can not be empty.', -12405); } @@ -143,25 +130,21 @@ public function update(Request $request, $project_key, $id) public function destroy($project_key, $id) { $state = State::find($id); - if (!$state || $project_key != $state->project_key) - { + if (!$state || $project_key != $state->project_key) { throw new \UnexpectedValueException('the state does not exist or is not in the project.', -12402); } - if (isset($state->key) && $state->key) - { + if (isset($state->key) && $state->key) { throw new \UnexpectedValueException('the state is built in the system.', -12406); } - $isUsed = $this->isFieldUsedByIssue($project_key, 'state', $state->toArray()); - if ($isUsed) - { + $isUsed = $this->isFieldUsedByIssue($project_key, 'state', $state->toArray()); + if ($isUsed) { throw new \UnexpectedValueException('the state has been used in issue.', -12403); } $isUsed = Definition::whereRaw([ 'state_ids' => isset($state->key) ? $state->key : $id ])->exists(); - if ($isUsed) - { + if ($isUsed) { throw new \UnexpectedValueException('the state has been used in workflow.', -12404); } @@ -177,12 +160,9 @@ public function destroy($project_key, $id) */ public function handle(Request $request, $project_key) { - if ($project_key === '$_sys_$') - { + if ($project_key === '$_sys_$') { return $this->handleSys($request, $project_key); - } - else - { + } else { return $this->handleProject($request, $project_key); } } @@ -198,20 +178,16 @@ public function handleProject(Request $request, $project_key) $properties = []; // set state sort. $sequence = $request->input('sequence'); - if (isset($sequence)) - { + if (isset($sequence)) { $properties['sequence'] = $sequence; } $state_property = StateProperty::Where('project_key', $project_key)->first(); - if ($state_property) - { - $state_property->fill($properties); - $state_property->save(); - } - else - { - StateProperty::create([ 'project_key' => $project_key ] + $properties); + if ($state_property) { + $state_property->fill($properties); + $state_property->save(); + } else { + StateProperty::create([ 'project_key' => $project_key ] + $properties); } return Response()->json(['ecode' => 0, 'data' => [ 'sequence' => $sequence ]]); @@ -227,14 +203,11 @@ public function handleSys(Request $request, $project_key) { // set type sort. $sequence = $request->input('sequence'); - if (isset($sequence)) - { + if (isset($sequence)) { $i = 1; - foreach ($sequence as $state_id) - { + foreach ($sequence as $state_id) { $state = State::find($state_id); - if (!$state || $state->project_key != $project_key) - { + if (!$state || $state->project_key != $project_key) { continue; } $state->sn = $i++; @@ -252,15 +225,13 @@ public function handleSys(Request $request, $project_key) */ public function viewUsedInProject($project_key, $id) { - if ($project_key !== '$_sys_$') - { + if ($project_key !== '$_sys_$') { return Response()->json(['ecode' => 0, 'data' => [] ]); } $res = []; $projects = Project::all(); - foreach($projects as $project) - { + foreach ($projects as $project) { $count = DB::collection('issue_' . $project->key) ->where('state', $id) ->where('del_flg', '<>', 1) @@ -272,8 +243,7 @@ public function viewUsedInProject($project_key, $id) ->get([ 'id', 'name' ]) ->toArray(); - if ($count > 0 || $workflows) - { + if ($count > 0 || $workflows) { $tmp = [ 'key' => $project->key, 'name' => $project->name, 'status' => $project->status ]; $tmp['issue_count'] = $count > 0 ? $count : 0; $tmp['workflows'] = $workflows ?: []; diff --git a/app/Http/Controllers/SummaryController.php b/app/Http/Controllers/SummaryController.php index 1ced97f7e..3e59b1e0e 100644 --- a/app/Http/Controllers/SummaryController.php +++ b/app/Http/Controllers/SummaryController.php @@ -24,11 +24,9 @@ public function getTopFourFilters($project_key) { $filters = Provider::getIssueFilters($project_key, $this->user->id); $filters = array_slice($filters, 0, 4); - foreach ($filters as $key => $filter) - { + foreach ($filters as $key => $filter) { $query = []; - if (isset($filter['query']) && $filter['query']) - { + if (isset($filter['query']) && $filter['query']) { $query = $filter['query']; } @@ -56,8 +54,7 @@ public function getPulseData($project_key) // initialize the pulse data $t = strtotime('-2 week'); - while($t <= time()) - { + while ($t <= time()) { $ymd = date('Y/m/d', $t); $trend[$ymd] = [ 'new' => 0, 'resolved' => 0, 'closed' => 0 ]; $t += 24 * 3600; @@ -73,38 +70,30 @@ public function getPulseData($project_key) ->where('del_flg', '<>', 1) ->get([ 'created_at', 'resolved_at', 'closed_at' ]); - foreach ($issues as $issue) - { - if (isset($issue['created_at']) && $issue['created_at']) - { + foreach ($issues as $issue) { + if (isset($issue['created_at']) && $issue['created_at']) { $created_date = date('Y/m/d', $issue['created_at']); - if (isset($trend[$created_date])) - { + if (isset($trend[$created_date])) { $trend[$created_date]['new'] += 1; } } - if (isset($issue['resolved_at']) && $issue['resolved_at']) - { + if (isset($issue['resolved_at']) && $issue['resolved_at']) { $resolved_date = date('Y/m/d', $issue['resolved_at']); - if (isset($trend[$resolved_date])) - { + if (isset($trend[$resolved_date])) { $trend[$resolved_date]['resolved'] += 1; } } - if (isset($issue['closed_at']) && $issue['closed_at']) - { + if (isset($issue['closed_at']) && $issue['closed_at']) { $closed_date = date('Y/m/d', $issue['closed_at']); - if (isset($trend[$closed_date])) - { + if (isset($trend[$closed_date])) { $trend[$closed_date]['closed'] += 1; } } } $new_trend = []; - foreach ($trend as $key => $val) - { + foreach ($trend as $key => $val) { $new_trend[] = [ 'day' => $key ] + $val; } return $new_trend; @@ -122,30 +111,25 @@ public function index($project_key) // the two weeks issuepulse $trend = $this->getPulseData($project_key); - $types = Provider::getTypeList($project_key); + $types = Provider::getTypeList($project_key); $optPriorities = []; - $priorities = Provider::getPriorityList($project_key); - foreach ($priorities as $priority) - { - if (isset($priority['key'])) - { + $priorities = Provider::getPriorityList($project_key); + foreach ($priorities as $priority) { + if (isset($priority['key'])) { $optPriorities[$priority['key']] = $priority['name']; - } - else - { + } else { $optPriorities[$priority['_id']] = $priority['name']; } } $optModules = []; $modules = Provider::getModuleList($project_key); - foreach ($modules as $module) - { + foreach ($modules as $module) { $optModules[$module->id] = $module->name; } - //$users = Provider::getUserList($project_key); + //$users = Provider::getUserList($project_key); $issues = DB::collection('issue_' . $project_key) ->where('created_at', '>=', strtotime(date('Ymd', strtotime('-1 week')))) @@ -153,10 +137,8 @@ public function index($project_key) ->get([ 'type' ]); $new_issues = [ 'total' => 0 ]; - foreach ($issues as $issue) - { - if (!isset($new_issues[$issue['type']])) - { + foreach ($issues as $issue) { + if (!isset($new_issues[$issue['type']])) { $new_issues[$issue['type']] = 0; } $new_issues[$issue['type']] += 1; @@ -170,10 +152,8 @@ public function index($project_key) ->get([ 'type' ]); $closed_issues = [ 'total' => 0 ]; - foreach ($issues as $issue) - { - if (!isset($closed_issues[$issue['type']])) - { + foreach ($issues as $issue) { + if (!isset($closed_issues[$issue['type']])) { $closed_issues[$issue['type']] = 0; } $closed_issues['total'] += 1; @@ -181,15 +161,11 @@ public function index($project_key) } $new_percent = $closed_percent = 0; - if ($new_issues['total'] > 0 || $closed_issues['total'] > 0) - { + if ($new_issues['total'] > 0 || $closed_issues['total'] > 0) { $new_percent = $new_issues['total'] * 100 / ($new_issues['total'] + $closed_issues['total']); - if ($new_percent > 0 && $new_percent < 1) - { + if ($new_percent > 0 && $new_percent < 1) { $new_percent = 1; - } - else - { + } else { $new_percent = floor($new_percent); } $closed_percent = 100 - $new_percent; @@ -205,20 +181,16 @@ public function index($project_key) $users = []; $assignee_unresolved_issues = []; - foreach ($issues as $issue) - { - if (!isset($issue['assignee']) || !$issue['assignee']) - { + foreach ($issues as $issue) { + if (!isset($issue['assignee']) || !$issue['assignee']) { continue; } $users[$issue['assignee']['id']] = $issue['assignee']['name']; - if (!isset($assignee_unresolved_issues[$issue['assignee']['id']][$issue['type']])) - { + if (!isset($assignee_unresolved_issues[$issue['assignee']['id']][$issue['type']])) { $assignee_unresolved_issues[$issue['assignee']['id']][$issue['type']] = 0; } - if (!isset($assignee_unresolved_issues[$issue['assignee']['id']]['total'])) - { + if (!isset($assignee_unresolved_issues[$issue['assignee']['id']]['total'])) { $assignee_unresolved_issues[$issue['assignee']['id']]['total'] = 0; } $assignee_unresolved_issues[$issue['assignee']['id']][$issue['type']] += 1; @@ -227,23 +199,17 @@ public function index($project_key) $assignee_unresolved_issues = $this->calPercent($assignee_unresolved_issues); $priority_unresolved_issues = []; - foreach ($issues as $issue) - { - if (!isset($issue['priority']) || !$issue['priority']) - { + foreach ($issues as $issue) { + if (!isset($issue['priority']) || !$issue['priority']) { $priority_id = '-1'; - } - else - { - $priority_id = isset($optPriorities[$issue['priority']]) ? $issue['priority'] : '-1'; + } else { + $priority_id = isset($optPriorities[$issue['priority']]) ? $issue['priority'] : '-1'; } - if (!isset($priority_unresolved_issues[$priority_id][$issue['type']])) - { + if (!isset($priority_unresolved_issues[$priority_id][$issue['type']])) { $priority_unresolved_issues[$priority_id][$issue['type']] = 0; } - if (!isset($priority_unresolved_issues[$priority_id]['total'])) - { + if (!isset($priority_unresolved_issues[$priority_id]['total'])) { $priority_unresolved_issues[$priority_id]['total'] = 0; } $priority_unresolved_issues[$priority_id][$issue['type']] += 1; @@ -251,10 +217,8 @@ public function index($project_key) } $sorted_priority_unresolved_issues = []; - foreach ($optPriorities as $key => $val) - { - if (isset($priority_unresolved_issues[$key])) - { + foreach ($optPriorities as $key => $val) { + if (isset($priority_unresolved_issues[$key])) { $sorted_priority_unresolved_issues[$key] = $priority_unresolved_issues[$key]; } } @@ -265,35 +229,26 @@ public function index($project_key) $sorted_priority_unresolved_issues = $this->calPercent($sorted_priority_unresolved_issues); $module_unresolved_issues = []; - foreach ($issues as $issue) - { + foreach ($issues as $issue) { $module_ids = []; - if (!isset($issue['module']) || !$issue['module']) - { + if (!isset($issue['module']) || !$issue['module']) { $module_ids = [ '-1' ]; - } - else - { + } else { $ms = is_string($issue['module']) ? explode(',', $issue['module']) : $issue['module']; - foreach ($ms as $m) - { + foreach ($ms as $m) { $module_ids[] = isset($optModules[$m]) ? $m : '-1'; } $module_ids = array_unique($module_ids); } - foreach ($module_ids as $module_id) - { - if (count($module_ids) > 1 && $module_id === '-1') - { + foreach ($module_ids as $module_id) { + if (count($module_ids) > 1 && $module_id === '-1') { continue; } - if (!isset($module_unresolved_issues[$module_id][$issue['type']])) - { + if (!isset($module_unresolved_issues[$module_id][$issue['type']])) { $module_unresolved_issues[$module_id][$issue['type']] = 0; } - if (!isset($module_unresolved_issues[$module_id]['total'])) - { + if (!isset($module_unresolved_issues[$module_id]['total'])) { $module_unresolved_issues[$module_id]['total'] = 0; } $module_unresolved_issues[$module_id][$issue['type']] += 1; @@ -302,10 +257,8 @@ public function index($project_key) } $sorted_module_unresolved_issues = []; - foreach ($optModules as $key => $val) - { - if (isset($module_unresolved_issues[$key])) - { + foreach ($optModules as $key => $val) { + if (isset($module_unresolved_issues[$key])) { $sorted_module_unresolved_issues[$key] = $module_unresolved_issues[$key]; } } @@ -315,73 +268,64 @@ public function index($project_key) $sorted_module_unresolved_issues = $this->calPercent($sorted_module_unresolved_issues); - return Response()->json([ - 'ecode' => 0, - 'data' => [ + return Response()->json([ + 'ecode' => 0, + 'data' => [ 'filters' => $filters, 'trend' => $trend, - 'new_issues' => $new_issues, - 'closed_issues' => $closed_issues, - 'assignee_unresolved_issues' => $assignee_unresolved_issues, - 'priority_unresolved_issues' => $sorted_priority_unresolved_issues, - 'module_unresolved_issues' => $sorted_module_unresolved_issues ], - 'options' => [ - 'types' => $types, - 'users' => $users, - 'priorities' => $optPriorities, - 'modules' => $optModules, - 'twoWeeksAgo' => date('m/d', strtotime('-2 week')) - ] + 'new_issues' => $new_issues, + 'closed_issues' => $closed_issues, + 'assignee_unresolved_issues' => $assignee_unresolved_issues, + 'priority_unresolved_issues' => $sorted_priority_unresolved_issues, + 'module_unresolved_issues' => $sorted_module_unresolved_issues ], + 'options' => [ + 'types' => $types, + 'users' => $users, + 'priorities' => $optPriorities, + 'modules' => $optModules, + 'twoWeeksAgo' => date('m/d', strtotime('-2 week')) + ] ]); } - function calPercent($arr) + public function calPercent($arr) { $total = 0; $counts = []; $quotients = []; $remainders = []; - foreach ($arr as $key => $val) - { + foreach ($arr as $key => $val) { $counts[$key] = isset($val['total']) && $val['total'] ? $val['total'] : 0; $total += $counts[$key]; } - foreach ($counts as $key => $count) - { + foreach ($counts as $key => $count) { $quotient = $count * 100 / $total; - if ($quotient > 0 && $quotient <= 1) - { + if ($quotient > 0 && $quotient <= 1) { $quotients[$key] = 1; - } - else - { + } else { $quotients[$key] = floor($quotient); } $remainders[$key] = ($count * 100) % $total; } $sum = array_sum($quotients); - if ($sum < 100) - { + if ($sum < 100) { $less = 100 - $sum; arsort($remainders); $i = 1; - foreach ($remainders as $key => $remainder) - { + foreach ($remainders as $key => $remainder) { $quotients[$key] += 1; - if ($i >= $less) - { + if ($i >= $less) { break; } $i++; } } - foreach ($arr as $key => $val) - { + foreach ($arr as $key => $val) { $arr[$key]['percent'] = $quotients[$key]; } return $arr; diff --git a/app/Http/Controllers/SyssettingController.php b/app/Http/Controllers/SyssettingController.php index 41e44a392..5be6ed115 100644 --- a/app/Http/Controllers/SyssettingController.php +++ b/app/Http/Controllers/SyssettingController.php @@ -32,11 +32,10 @@ public function __construct() public function show() { $syssetting = SysSetting::first()->toArray(); - if (isset($syssetting['mailserver']) - && isset($syssetting['mailserver']['smtp']) - && isset($syssetting['mailserver']['smtp']['password']) - && $syssetting['mailserver']['smtp']['password']) - { + if (isset($syssetting['mailserver']) + && isset($syssetting['mailserver']['smtp']) + && isset($syssetting['mailserver']['smtp']['password']) + && $syssetting['mailserver']['smtp']['password']) { $syssetting['mailserver']['smtp']['password'] = '******'; } return Response()->json([ 'ecode' => 0, 'data' => $syssetting ]); @@ -54,44 +53,36 @@ public function update(Request $request) $updValues = []; $properties = $request->input('properties'); - if (isset($properties)) - { + if (isset($properties)) { $updValues['properties'] = $properties; } $mailserver = isset($syssetting->mailserver) ? $syssetting->mailserver : []; $smtp = $request->input('smtp'); - if (isset($smtp)) - { - if (!isset($smtp['password']) || !$smtp['password']) - { + if (isset($smtp)) { + if (!isset($smtp['password']) || !$smtp['password']) { $smtp['password'] = $mailserver && isset($mailserver['smtp']) && isset($mailserver['smtp']['password']) ? $mailserver['smtp']['password'] : ''; } $updValues['mailserver'] = array_merge($mailserver, [ 'smtp' => $smtp ]); } $mail_send = $request->input('mail_send'); - if (isset($mail_send)) - { + if (isset($mail_send)) { $updValues['mailserver'] = array_merge($mailserver, [ 'send' => $mail_send ]); } $sysroles = $request->input('sysroles'); - if (isset($sysroles)) - { + if (isset($sysroles)) { $updValues['sysroles'] = $sysroles; - if (isset($syssetting->sysroles) && isset($syssetting->sysroles['sys_admin'])) - { + if (isset($syssetting->sysroles) && isset($syssetting->sysroles['sys_admin'])) { $old_sys_admins = $syssetting->sysroles['sys_admin']; - } - else - { - $old_sys_admins = []; + } else { + $old_sys_admins = []; } $old_sys_admin_ids = array_column($old_sys_admins, 'id'); $new_sys_admins = isset($sysroles['sys_admin']) ? $sysroles['sys_admin'] : []; - $new_sys_admin_ids = array_column($new_sys_admins, 'id'); + $new_sys_admin_ids = array_column($new_sys_admins, 'id'); $added_user_ids = array_diff($new_sys_admin_ids, $old_sys_admin_ids) ?: []; $deleted_user_ids = array_diff($old_sys_admin_ids, $new_sys_admin_ids) ?: []; @@ -101,7 +92,7 @@ public function update(Request $request) $syssetting->fill($updValues)->save(); - return $this->show(); + return $this->show(); } /** @@ -110,18 +101,16 @@ public function update(Request $request) * @param string $type * @param array $added_user_ids * @param array $deleted_user_ids - * @return void + * @return void */ public function handleUserPermission($permission, $added_user_ids, $deleted_user_ids) { - foreach($added_user_ids as $uid) - { - $user = Sentinel::findById($uid); + foreach ($added_user_ids as $uid) { + $user = Sentinel::findById($uid); $user->addPermission($permission)->save(); } - foreach($deleted_user_ids as $uid) - { - $user = Sentinel::findById($uid); + foreach ($deleted_user_ids as $uid) { + $user = Sentinel::findById($uid); $user->removePermission($permission)->save(); } } @@ -135,8 +124,7 @@ public function handleUserPermission($permission, $added_user_ids, $deleted_user public function resetPwd(Request $request) { $pwd = $request->input('send_auth_pwd'); - if (!isset($pwd) || !$pwd) - { + if (!isset($pwd) || !$pwd) { throw new \UnexpectedValueException('the name cannot be empty.', -12200); } @@ -148,7 +136,7 @@ public function resetPwd(Request $request) } /** - * send the test mail + * send the test mail * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response @@ -156,18 +144,16 @@ public function resetPwd(Request $request) public function sendTestMail(Request $request) { $to = $request->input('to'); - if (!isset($to) || !$to) - { + if (!isset($to) || !$to) { throw new \UnexpectedValueException('the mail recipients cannot be empty.', -15201); } $subject = $request->input('subject'); - if (!isset($subject) || !$subject) - { + if (!isset($subject) || !$subject) { throw new \UnexpectedValueException('the mail subject cannot be empty.', -15202); } - $syssetting = SysSetting::first()->toArray(); + $syssetting = SysSetting::first()->toArray(); if (!isset($syssetting['mailserver']) || !$syssetting['mailserver'] || !isset($syssetting['mailserver']['send']) || !$syssetting['mailserver']['send'] || !isset($syssetting['mailserver']['smtp']) || !$syssetting['mailserver']['smtp'] @@ -175,8 +161,7 @@ public function sendTestMail(Request $request) || !isset($syssetting['mailserver']['smtp']['host']) || !$syssetting['mailserver']['smtp']['host'] || !isset($syssetting['mailserver']['smtp']['port']) || !$syssetting['mailserver']['smtp']['port'] || !isset($syssetting['mailserver']['smtp']['username']) || !$syssetting['mailserver']['smtp']['username'] - || !isset($syssetting['mailserver']['smtp']['password']) || !$syssetting['mailserver']['smtp']['password']) - { + || !isset($syssetting['mailserver']['smtp']['password']) || !$syssetting['mailserver']['smtp']['password']) { throw new \UnexpectedValueException('the mail server config params have error.', -15203); } @@ -195,12 +180,12 @@ public function sendTestMail(Request $request) $subject = '[' . $prefix . ']' . $subject; try { - Mail::send('emails.test', $data, function($message) use($to, $subject) { + Mail::send('emails.test', $data, function ($message) use ($to, $subject) { $message->from(Config::get('mail.from'), 'master') ->to($to) ->subject($subject); }); - } catch (Exception $e){ + } catch (Exception $e) { throw new Exception('send mail failed.', -15200); } @@ -208,7 +193,7 @@ public function sendTestMail(Request $request) } /** - * add admin user, will be removed + * add admin user, will be removed * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response @@ -217,6 +202,7 @@ public function addAdmin(Request $request, $id) { $user = Sentinel::findById($id); $user->addPermission('sys_admin')->save(); - echo 'ok!'; exit; + echo 'ok!'; + exit; } } diff --git a/app/Http/Controllers/TimeTrackTrait.php b/app/Http/Controllers/TimeTrackTrait.php index 17040d486..2c520a558 100644 --- a/app/Http/Controllers/TimeTrackTrait.php +++ b/app/Http/Controllers/TimeTrackTrait.php @@ -15,20 +15,16 @@ public function ttCheck($ttString) { $ttString = strtolower(trim($ttString)); $ttValues = explode(' ', $ttString); - foreach ($ttValues as $ttValue) - { - if (!$ttValue) - { + foreach ($ttValues as $ttValue) { + if (!$ttValue) { continue; } $lastChr = substr($ttValue, -1); - if ($lastChr !== 'w' && $lastChr !== 'd' && $lastChr !== 'h' && $lastChr !== 'm') - { + if ($lastChr !== 'w' && $lastChr !== 'd' && $lastChr !== 'h' && $lastChr !== 'm') { return false; } $ttNum = substr($ttValue, 0, -1); - if ($ttNum && !is_numeric($ttNum)) - { + if ($ttNum && !is_numeric($ttNum)) { return false; } } @@ -42,21 +38,17 @@ public function ttCheck($ttString) */ public function ttHandleInM($ttString) { - if (!$ttString) - { + if (!$ttString) { return ''; } $W2D = 5; $D2H = 8; $setting = SysSetting::first(); - if ($setting && isset($setting->properties)) - { - if (isset($setting->properties['week2day'])) - { + if ($setting && isset($setting->properties)) { + if (isset($setting->properties['week2day'])) { $W2D = $setting->properties['week2day']; } - if (isset($setting->properties['day2hour'])) - { + if (isset($setting->properties['day2hour'])) { $D2H = $setting->properties['day2hour']; } } @@ -66,28 +58,19 @@ public function ttHandleInM($ttString) $tt_in_min = 0; $ttString = strtolower(trim($ttString)); $ttValues = explode(' ', $ttString); - foreach ($ttValues as $ttValue) - { - if (!$ttValue) - { + foreach ($ttValues as $ttValue) { + if (!$ttValue) { continue; } $lastChr = substr($ttValue, -1); $ttNum = substr($ttValue, 0, -1) === '' ? 1 : substr($ttValue, 0, -1); - if ($lastChr == 'w') - { + if ($lastChr == 'w') { $tt_in_min += $ttNum * $W2M; - } - else if ($lastChr == 'd') - { + } elseif ($lastChr == 'd') { $tt_in_min += $ttNum * $D2M; - } - else if ($lastChr == 'h') - { + } elseif ($lastChr == 'h') { $tt_in_min += $ttNum * $H2M; - } - else if ($lastChr == 'm') - { + } elseif ($lastChr == 'm') { $tt_in_min += $ttNum; } } @@ -101,22 +84,18 @@ public function ttHandleInM($ttString) */ public function ttHandle($ttString) { - if (!$ttString) - { + if (!$ttString) { return ''; } $W2D = 5; $D2H = 8; $setting = SysSetting::first(); - if ($setting && isset($setting->properties)) - { - if (isset($setting->properties['week2day'])) - { + if ($setting && isset($setting->properties)) { + if (isset($setting->properties['week2day'])) { $W2D = $setting->properties['week2day']; } - if (isset($setting->properties['day2hour'])) - { + if (isset($setting->properties['day2hour'])) { $D2H = $setting->properties['day2hour']; } } @@ -126,66 +105,49 @@ public function ttHandle($ttString) $tt_in_min = 0; $ttString = strtolower(trim($ttString)); $ttValues = explode(' ', $ttString); - foreach ($ttValues as $ttValue) - { - if (!$ttValue) - { + foreach ($ttValues as $ttValue) { + if (!$ttValue) { continue; } $lastChr = substr($ttValue, -1); $ttNum = substr($ttValue, 0, -1) === '' ? 1 : abs(substr($ttValue, 0, -1)); - if ($lastChr == 'w') - { + if ($lastChr == 'w') { $tt_in_min += $ttNum * $W2M; - } - else if ($lastChr == 'd') - { + } elseif ($lastChr == 'd') { $tt_in_min += $ttNum * $D2M; - } - else if ($lastChr == 'h') - { + } elseif ($lastChr == 'h') { $tt_in_min += $ttNum * $H2M; - } - else if ($lastChr == 'm') - { + } elseif ($lastChr == 'm') { $tt_in_min += $ttNum; } } $newTT = []; $new_remain_min = ceil($tt_in_min); - if ($new_remain_min >= 0) - { + if ($new_remain_min >= 0) { $new_weeknum = floor($tt_in_min / $W2M); - if ($new_weeknum > 0) - { + if ($new_weeknum > 0) { $newTT[] = $new_weeknum . 'w'; } } $new_remain_min = $tt_in_min % $W2M; - if ($new_remain_min >= 0) - { + if ($new_remain_min >= 0) { $new_daynum = floor($new_remain_min / $D2M); - if ($new_daynum > 0) - { + if ($new_daynum > 0) { $newTT[] = $new_daynum . 'd'; } } $new_remain_min = $new_remain_min % $D2M; - if ($new_remain_min >= 0) - { + if ($new_remain_min >= 0) { $new_hournum = floor($new_remain_min / $H2M); - if ($new_hournum > 0) - { + if ($new_hournum > 0) { $newTT[] = $new_hournum . 'h'; } } $new_remain_min = $new_remain_min % $H2M; - if ($new_remain_min > 0) - { + if ($new_remain_min > 0) { $newTT[] = $new_remain_min . 'm'; } - if (!$newTT) - { + if (!$newTT) { $newTT[] = '0m'; } return (substr($ttString, 0, 1) == '-' ? '-' : '') . implode(' ', $newTT); diff --git a/app/Http/Controllers/TypeController.php b/app/Http/Controllers/TypeController.php index 722e24c1a..d12f2c96a 100644 --- a/app/Http/Controllers/TypeController.php +++ b/app/Http/Controllers/TypeController.php @@ -22,8 +22,7 @@ class TypeController extends Controller public function index($project_key) { $types = Type::where([ 'project_key' => $project_key ])->orderBy('sn', 'asc')->get(); - foreach ($types as $type) - { + foreach ($types as $type) { $type->is_used = $this->isFieldUsedByIssue($project_key, 'type', $type->toArray()); } @@ -43,21 +42,18 @@ public function index($project_key) public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12000); } $abb = $request->input('abb'); - if (!$abb) - { + if (!$abb) { throw new \UnexpectedValueException('the abb can not be empty.', -12002); } // check screen_id $screen_id = $request->input('screen_id'); - if (!$screen_id) - { + if (!$screen_id) { throw new \UnexpectedValueException('the related screen can not be empty.', -12004); } //if (Screen::find($screen_id)->project_key != $project_key) @@ -67,18 +63,15 @@ public function store(Request $request, $project_key) // check workflow_id, workflow is too required? fix me $workflow_id = $request->input('workflow_id'); - if (!$workflow_id) - { + if (!$workflow_id) { throw new \UnexpectedValueException('the related workflow can not be empty.', -12005); } - if (Provider::isTypeExisted($project_key, $name)) - { + if (Provider::isTypeExisted($project_key, $name)) { throw new \UnexpectedValueException('type name cannot be repeated', -12001); } - if (Provider::isTypeAbbExisted($project_key, $abb)) - { + if (Provider::isTypeAbbExisted($project_key, $abb)) { throw new \UnexpectedValueException('type abb cannot be repeated', -12003); } @@ -117,27 +110,22 @@ public function show($project_key, $id) public function update(Request $request, $project_key, $id) { $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12000); } } $abb = $request->input('abb'); - if (isset($abb)) - { - if (!$abb) - { + if (isset($abb)) { + if (!$abb) { throw new \UnexpectedValueException('the abb can not be empty.', -12001); } } // check screen_id $screen_id = $request->input('screen_id'); - if (isset($screen_id) && !$screen_id) - { + if (isset($screen_id) && !$screen_id) { throw new \UnexpectedValueException('the related screen can not be empty.', -12004); } //if (Screen::find($screen_id)->project_key != $project_key) @@ -147,8 +135,7 @@ public function update(Request $request, $project_key, $id) // check workflow_id $workflow_id = $request->input('workflow_id'); - if (isset($workflow_id) && !$workflow_id) - { + if (isset($workflow_id) && !$workflow_id) { throw new \UnexpectedValueException('the related workflow can not be empty.', -12005); } //if (Definition::find($workflow_id)->project_key != $project_key) @@ -157,27 +144,23 @@ public function update(Request $request, $project_key, $id) //} $type = Type::find($id); - if (!$type || $project_key != $type->project_key) - { + if (!$type || $project_key != $type->project_key) { throw new \UnexpectedValueException('the type does not exist or is not in the project.', -12006); } - if ($type->name !== $name && Provider::isTypeExisted($project_key, $name)) - { + if ($type->name !== $name && Provider::isTypeExisted($project_key, $name)) { throw new \UnexpectedValueException('type name cannot be repeated', -12001); } $abb = $request->input('abb'); - if ($type->abb !== $abb && Provider::isTypeAbbExisted($project_key, $abb)) - { + if ($type->abb !== $abb && Provider::isTypeAbbExisted($project_key, $abb)) { throw new \UnexpectedValueException('type abb cannot be repeated', -12003); } $defaults = []; $disabled = $request->input('disabled'); - if (isset($disabled) && $type->default === true) - { - $defaults['default'] = false; + if (isset($disabled) && $type->default === true) { + $defaults['default'] = false; } $type->fill($defaults + $request->except(['project_key', 'type']))->save(); @@ -197,14 +180,12 @@ public function update(Request $request, $project_key, $id) public function destroy($project_key, $id) { $type = Type::find($id); - if (!$type || $project_key != $type->project_key) - { + if (!$type || $project_key != $type->project_key) { throw new \UnexpectedValueException('the type does not exist or is not in the project.', -12006); } - $isUsed = $this->isFieldUsedByIssue($project_key, 'type', $type->toArray()); - if ($isUsed) - { + $isUsed = $this->isFieldUsedByIssue($project_key, 'type', $type->toArray()); + if ($isUsed) { throw new \UnexpectedValueException('the type has been used in issue.', -12007); } @@ -222,14 +203,11 @@ public function handle(Request $request, $project_key) { // set type sort. $sequence_types = $request->input('sequence'); - if (isset($sequence_types)) - { + if (isset($sequence_types)) { $i = 1; - foreach ($sequence_types as $type_id) - { + foreach ($sequence_types as $type_id) { $type = Type::find($type_id); - if (!$type || $type->project_key != $project_key) - { + if (!$type || $type->project_key != $project_key) { continue; } $type->sn = $i++; @@ -239,24 +217,18 @@ public function handle(Request $request, $project_key) // set default value $default_type_id = $request->input('defaultValue'); - if (isset($default_type_id)) - { + if (isset($default_type_id)) { $type = Type::find($default_type_id); - if (!$type || $type->project_key != $project_key) - { + if (!$type || $type->project_key != $project_key) { throw new \UnexpectedValueException('the type does not exist or is not in the project.', -12006); } $types = Type::where('project_key', $project_key)->get(); - foreach ($types as $type) - { - if ($type->id == $default_type_id) - { + foreach ($types as $type) { + if ($type->id == $default_type_id) { $type->default = true; $type->save(); - } - else if (isset($type->default)) - { + } elseif (isset($type->default)) { $type->unset('default'); } } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index bef573347..5b5c56ede 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -15,7 +15,7 @@ use Maatwebsite\Excel\Facades\Excel; use Cartalyst\Sentinel\Users\EloquentUser; use Sentinel; -use Activation; +use Activation; use App\System\Eloquent\SysSetting; use App\System\Eloquent\ResetPwdCode; @@ -41,25 +41,21 @@ public function search(Request $request) { $s = $request->input('s'); $users = []; - if ($s) - { + if ($s) { $search_users = EloquentUser::Where('first_name', 'like', '%' . $s . '%') ->orWhere('email', 'like', '%' . $s . '%') ->get([ 'first_name', 'last_name', 'email', 'invalid_flag' ]); $i = 0; - foreach ($search_users as $key => $user) - { - if ((isset($user->invalid_flag) && $user->invalid_flag === 1) || Activation::completed($user) === false || $user->email === 'admin@action.view') - { + foreach ($search_users as $key => $user) { + if ((isset($user->invalid_flag) && $user->invalid_flag === 1) || Activation::completed($user) === false || $user->email === 'admin@action.view') { continue; } $users[$i]['id'] = $user->id; $users[$i]['name'] = $user->first_name ?: ''; $users[$i]['email'] = $user->email; - if (++$i >= 10) - { + if (++$i >= 10) { break; } } @@ -76,24 +72,20 @@ public function index(Request $request) { $query = EloquentUser::where('email', '<>', '')->where('email', '<>', 'admin@action.view'); - if ($name = $request->input('name')) - { + if ($name = $request->input('name')) { $query->where(function ($query) use ($name) { $query->where('email', 'like', '%' . $name . '%')->orWhere('name', 'like', '%' . $name . '%'); }); } - if ($group_id = $request->input('group')) - { + if ($group_id = $request->input('group')) { $group = Group::find($group_id); - if ($group) - { + if ($group) { $query->whereIn('_id', $group->users ?: []); } } - if ($directory = $request->input('directory')) - { + if ($directory = $request->input('directory')) { $query->where('directory', $directory); } @@ -108,8 +100,7 @@ public function index(Request $request) $all_users = $query->get([ 'first_name', 'last_name', 'email', 'phone', 'directory', 'invalid_flag' ]); $users = []; - foreach ($all_users as $user) - { + foreach ($all_users as $user) { $tmp = []; $tmp['id'] = $user->id; $tmp['first_name'] = $user->first_name; @@ -121,7 +112,7 @@ public function index(Request $request) $users[] = $tmp; } - return Response()->json([ 'ecode' => 0, 'data' => $users, 'options' => [ 'total' => $total, 'sizePerPage' => $page_size, 'groups' => Group::all(), 'directories' => Directory::all() ] ]); + return Response()->json([ 'ecode' => 0, 'data' => $users, 'options' => [ 'total' => $total, 'sizePerPage' => $page_size, 'groups' => Group::all(), 'directories' => Directory::all() ] ]); } /** @@ -132,23 +123,19 @@ public function index(Request $request) */ public function register(Request $request) { - if (!($first_name = $request->input('first_name'))) - { + if (!($first_name = $request->input('first_name'))) { throw new \UnexpectedValueException('the name can not be empty.', -10100); } - if (!($email = $request->input('email'))) - { + if (!($email = $request->input('email'))) { throw new \UnexpectedValueException('the email can not be empty.', -10101); } - if (Sentinel::findByCredentials([ 'email' => $email ])) - { + if (Sentinel::findByCredentials([ 'email' => $email ])) { throw new \InvalidArgumentException('the email has already been registered.', -10102); } - if (!$password = $request->input('password')) - { + if (!$password = $request->input('password')) { throw new \UnexpectedValueException('the password can not be empty.', -10103); } @@ -164,18 +151,15 @@ public function register(Request $request) */ public function store(Request $request) { - if (!($first_name = $request->input('first_name'))) - { + if (!($first_name = $request->input('first_name'))) { throw new \UnexpectedValueException('the name can not be empty.', -10100); } - if (!($email = $request->input('email'))) - { + if (!($email = $request->input('email'))) { throw new \UnexpectedValueException('the email can not be empty.', -10101); } - if (Sentinel::findByCredentials([ 'email' => $email ])) - { + if (Sentinel::findByCredentials([ 'email' => $email ])) { throw new \InvalidArgumentException('email has already existed.', -10102); } @@ -195,60 +179,46 @@ public function store(Request $request) */ public function imports(Request $request) { - if (!($fid = $request->input('fid'))) - { + if (!($fid = $request->input('fid'))) { throw new \UnexpectedValueException('the user file ID can not be empty.', -11140); } $pattern = $request->input('pattern'); - if (!isset($pattern)) - { + if (!isset($pattern)) { $pattern = '1'; } $file = config('filesystems.disks.local.root', '/tmp') . '/' . substr($fid, 0, 2) . '/' . $fid; - if (!file_exists($file)) - { + if (!file_exists($file)) { throw new \UnexpectedValueException('the file cannot be found.', -11141); } - Excel::load($file, function($reader) use($pattern) { + Excel::load($file, function ($reader) use ($pattern) { $reader = $reader->getSheet(0); $data = $reader->toArray(); $fields = [ 'first_name' => '姓名', 'email' => '邮箱', 'phone' => '手机号' ]; $data = $this->arrangeExcel($data, $fields); - foreach ($data as $value) - { - if (!isset($value['first_name']) || !$value['first_name']) - { + foreach ($data as $value) { + if (!isset($value['first_name']) || !$value['first_name']) { throw new \UnexpectedValueException('there is empty value in the name column', -10110); } - if (!isset($value['email']) || !$value['email']) - { + if (!isset($value['email']) || !$value['email']) { throw new \UnexpectedValueException('there is empty value in the email column', -10111); } } - foreach ($data as $value) - { + foreach ($data as $value) { $old_user = Sentinel::findByCredentials([ 'email' => $value['email'] ]); - if ($old_user) - { - if ($pattern == '1') - { + if ($old_user) { + if ($pattern == '1') { continue; + } else { + Sentinel::update($old_user, $value + [ 'password' => 'actionview' ]); } - else - { - Sentinel::update($old_user, $value + [ 'password' => 'actionview' ]); - } - - } - else - { + } else { Sentinel::register($value + [ 'password' => 'actionview' ], true); } } @@ -278,23 +248,18 @@ public function show($id) public function update(Request $request, $id) { $first_name = $request->input('first_name'); - if (isset($first_name)) - { - if (!$first_name) - { + if (isset($first_name)) { + if (!$first_name) { throw new \UnexpectedValueException('the name can not be empty.', -10100); } } $email = $request->input('email'); - if (isset($email)) - { - if (!$email) - { + if (isset($email)) { + if (!$email) { throw new \UnexpectedValueException('the email can not be empty.', -10101); } - if ($user = Sentinel::findByCredentials([ 'email' => $email ])) - { + if ($user = Sentinel::findByCredentials([ 'email' => $email ])) { if ($user->id !== $id) { throw new \InvalidArgumentException('email has already existed.', -10102); } @@ -302,18 +267,15 @@ public function update(Request $request, $id) } $user = Sentinel::findById($id); - if (!$user) - { + if (!$user) { throw new \UnexpectedValueException('the user does not exist.', -10106); } - if (isset($user->diectory) && $user->directory && $user->diectory != 'self') - { + if (isset($user->diectory) && $user->directory && $user->diectory != 'self') { throw new \UnexpectedValueException('the user come from external directroy.', -10109); } $valid = Sentinel::validForUpdate($user, array_only($request->all(), ['first_name', 'email', 'phone', 'invalid_flag'])); - if (!$valid) - { + if (!$valid) { throw new \UnexpectedValueException('updating the user does fails.', -10107); } @@ -332,12 +294,10 @@ public function update(Request $request, $id) public function destroy($id) { $user = Sentinel::findById($id); - if (!$user) - { + if (!$user) { throw new \UnexpectedValueException('the user does not exist.', -10106); } - if (isset($user->diectory) && $user->directory && $user->diectory != 'self') - { + if (isset($user->diectory) && $user->directory && $user->diectory != 'self') { throw new \UnexpectedValueException('the user come from external directroy.', -10109); } @@ -354,19 +314,15 @@ public function destroy($id) public function delMultiUsers(Request $request) { $ids = $request->input('ids'); - if (!isset($ids) || !$ids) - { + if (!isset($ids) || !$ids) { throw new \InvalidArgumentException('the selected users cannot been empty.', -10108); } $deleted_ids = []; - foreach ($ids as $id) - { + foreach ($ids as $id) { $user = Sentinel::findById($id); - if ($user) - { - if (isset($user->directory) && $user->directory && $user->directory != 'self') - { + if ($user) { + if (isset($user->directory) && $user->directory && $user->directory != 'self') { continue; } @@ -386,21 +342,17 @@ public function delMultiUsers(Request $request) public function InvalidateMultiUsers(Request $request) { $ids = $request->input('ids'); - if (!isset($ids) || !$ids) - { + if (!isset($ids) || !$ids) { throw new \InvalidArgumentException('the selected users cannot been empty.', -10108); } $flag = $request->input('flag') ?: 1; $new_ids = []; - foreach ($ids as $id) - { + foreach ($ids as $id) { $user = Sentinel::findById($id); - if ($user) - { - if (isset($user->directory) && $user->directory && $user->directory != 'self') - { + if ($user) { + if (isset($user->directory) && $user->directory && $user->directory != 'self') { continue; } Sentinel::update($user, [ 'invalid_flag' => $flag ]); @@ -420,14 +372,12 @@ public function InvalidateMultiUsers(Request $request) public function renewPwd(Request $request, $id) { $user = Sentinel::findById($id); - if (!$user) - { + if (!$user) { throw new \UnexpectedValueException('the user does not exist.', -10106); } $valid = Sentinel::validForUpdate($user, [ 'password' => 'actionview' ]); - if (!$valid) - { + if (!$valid) { throw new \UnexpectedValueException('updating the user does fails.', -10107); } @@ -444,50 +394,38 @@ public function renewPwd(Request $request, $id) public function sendMailForResetpwd(Request $request) { $email = $request->input('email'); - if (!isset($email) || !$email) - { + if (!isset($email) || !$email) { throw new \UnexpectedValueException('the email can not be empty.', -10019); } $obscured_email = $sendto_email = $email; $last_reset_times = ResetPwdCode::where('requested_at', '>=', time() - 10 * 60)->count(); - if ($last_reset_times >= 10) - { + if ($last_reset_times >= 10) { throw new \UnexpectedValueException('sending the email is too often.', -10016); } $last_reset_times = ResetPwdCode::where('requested_at', '>=', time() - 10 * 60)->where('email', $email)->count(); - if ($last_reset_times >= 3) - { + if ($last_reset_times >= 3) { throw new \UnexpectedValueException('sending the email is too often.', -10016); } $user = Sentinel::findByCredentials([ 'email' => $email ]); - if (!$user) - { + if (!$user) { throw new \UnexpectedValueException('the user is not exists.', -10010); - } - else if ($user->invalid_flag === 1) - { + } elseif ($user->invalid_flag === 1) { throw new \UnexpectedValueException('the user has been disabled.', -10011); - } - else if ($user->directory && $user->directory != 'self') - { + } elseif ($user->directory && $user->directory != 'self') { throw new \UnexpectedValueException('the user is external sync user.', -10012); } - if ($email === 'admin@action.view') - { - if (isset($user->bind_email) && $user->bind_email) - { + if ($email === 'admin@action.view') { + if (isset($user->bind_email) && $user->bind_email) { $sendto_email = $user->bind_email; $sections = explode('@', $user->bind_email); $sections[0] = substr($sections[0], 0, 1) . '***' . substr($sections[0], -1, 1); $obscured_email = implode('@', $sections); - } - else - { + } else { throw new \UnexpectedValueException('the related email is not bound.', -10013); } } @@ -527,36 +465,32 @@ public function sendMail($to, $data) && isset($syssetting['mailserver']['smtp']['host']) && isset($syssetting['mailserver']['smtp']['port']) && isset($syssetting['mailserver']['smtp']['username']) - && isset($syssetting['mailserver']['smtp']['password'])) - { + && isset($syssetting['mailserver']['smtp']['password'])) { Config::set('mail.from', $syssetting['mailserver']['send']['from']); Config::set('mail.host', $syssetting['mailserver']['smtp']['host']); Config::set('mail.port', $syssetting['mailserver']['smtp']['port']); Config::set('mail.encryption', isset($syssetting['mailserver']['smtp']['encryption']) && $syssetting['mailserver']['smtp']['encryption'] ? $syssetting['mailserver']['smtp']['encryption'] : null); Config::set('mail.username', $syssetting['mailserver']['smtp']['username']); Config::set('mail.password', $syssetting['mailserver']['smtp']['password']); - } - else - { + } else { throw new \UnexpectedValueException('the smtp server is not configured.', -10014); } $mail_prefix = 'ActionView'; if (isset($syssetting['mailserver']['send']['prefix']) - && $syssetting['mailserver']['send']['prefix']) - { + && $syssetting['mailserver']['send']['prefix']) { $mail_prefix = $syssetting['mailserver']['send']['prefix']; } $subject = '[' . $mail_prefix . ']重置密码'; try { - Mail::send('emails.resetpwdlink', $data, function($message) use($to, $subject) { + Mail::send('emails.resetpwdlink', $data, function ($message) use ($to, $subject) { $message->from(Config::get('mail.from'), 'master') ->to($to) ->subject($subject); }); - } catch (Exception $e){ + } catch (Exception $e) { throw new Exception('send mail failed.', -15200); } } @@ -570,38 +504,28 @@ public function sendMail($to, $data) public function showResetpwd(Request $request) { $code = $request->input('code'); - if (!isset($code) || !$code) - { + if (!isset($code) || !$code) { throw new \UnexpectedValueException('the link is not exists.', -10018); } $reset_code = ResetPwdCode::where('code', $code)->first(); - if (!$reset_code) - { + if (!$reset_code) { throw new \UnexpectedValueException('the link is not exists.', -10018); } - if ($reset_code->invalid_flag == 1) - { + if ($reset_code->invalid_flag == 1) { throw new \UnexpectedValueException('the link has been invalid.', -10020); - } - else if ($reset_code->expired_at < time()) - { + } elseif ($reset_code->expired_at < time()) { throw new \UnexpectedValueException('the link has been expired.', -10017); } $email = $reset_code->email; $user = Sentinel::findByCredentials([ 'email' => $email ]); - if (!$user) - { + if (!$user) { throw new \UnexpectedValueException('the user is not exists.', -10010); - } - else if ($user->invalid_flag === 1) - { + } elseif ($user->invalid_flag === 1) { throw new \UnexpectedValueException('the user has been disabled.', -10011); - } - else if ($user->directory && $user->directory != 'self') - { + } elseif ($user->directory && $user->directory != 'self') { throw new \UnexpectedValueException('the user is external sync user.', -10012); } @@ -617,50 +541,38 @@ public function showResetpwd(Request $request) public function doResetpwd(Request $request) { $code = $request->input('code'); - if (!isset($code) || !$code) - { + if (!isset($code) || !$code) { throw new \UnexpectedValueException('the link is not exists.', -10018); } $password = $request->input('password'); - if (!isset($password) || !$password) - { + if (!isset($password) || !$password) { throw new \UnexpectedValueException('the password can not be empty.', -10103); } $reset_code = ResetPwdCode::where('code', $code)->first(); - if (!$reset_code) - { + if (!$reset_code) { throw new \UnexpectedValueException('the link is not exists.', -10018); } - if ($reset_code->invalid_flag == 1) - { + if ($reset_code->invalid_flag == 1) { throw new \UnexpectedValueException('the link has been invalid.', -10020); - } - else if ($reset_code->expired_at < time()) - { + } elseif ($reset_code->expired_at < time()) { throw new \UnexpectedValueException('the link has been expired.', -10017); } $email = $reset_code->email; $user = Sentinel::findByCredentials([ 'email' => $email ]); - if (!$user) - { + if (!$user) { throw new \UnexpectedValueException('the user is not exsits.', -10010); - } - else if ($user->invalid_flag === 1) - { + } elseif ($user->invalid_flag === 1) { throw new \UnexpectedValueException('the user has been disabled.', -10011); - } - else if ($user->directory && $user->directory != 'self') - { + } elseif ($user->directory && $user->directory != 'self') { throw new \UnexpectedValueException('the user is external sync user.', -10012); } $valid = Sentinel::validForUpdate($user, [ 'password' => $password ]); - if (!$valid) - { + if (!$valid) { throw new \UnexpectedValueException('updating the user does fails.', -10107); } @@ -679,15 +591,15 @@ public function doResetpwd(Request $request) */ public function downloadUserTpl(Request $request) { - $output = fopen('php://output', 'w') or die("can't open php://output"); + $output = fopen('php://output', 'w') or die("can't open php://output"); header("Content-type:text/csv;charset=utf-8"); header("Content-Disposition:attachment;filename=import-user-template.csv"); - fputcsv($output, [ 'name', 'email', 'phone' ]); - fputcsv($output, [ 'Tom', 'tom@actionview.cn', '13811111111' ]); - fputcsv($output, [ 'Alice', 'alice@actionview.cn', '13611111111' ]); - fclose($output) or die("can't close php://output"); + fputcsv($output, [ 'name', 'email', 'phone' ]); + fputcsv($output, [ 'Tom', 'tom@actionview.cn', '13811111111' ]); + fputcsv($output, [ 'Alice', 'alice@actionview.cn', '13611111111' ]); + fclose($output) or die("can't close php://output"); exit; } } diff --git a/app/Http/Controllers/VersionController.php b/app/Http/Controllers/VersionController.php index aea0a03d0..23c0f6cee 100644 --- a/app/Http/Controllers/VersionController.php +++ b/app/Http/Controllers/VersionController.php @@ -45,8 +45,7 @@ public function index(Request $request, $project_key) $versions = $query->get(); $version_fields = $this->getVersionFields($project_key); - foreach ($versions as $version) - { + foreach ($versions as $version) { $unresolved_cnt = DB::collection('issue_' . $project_key) ->where('resolution', 'Unresolved') ->where('del_flg', '<>', 1) @@ -69,19 +68,17 @@ public function index(Request $request, $project_key) } /** - * get all fields related with versiob + * get all fields related with versiob * - * @return array + * @return array */ public function getVersionFields($project_key) { $version_fields = []; // get all project fields $fields = Provider::getFieldList($project_key)->toArray(); - foreach ($fields as $field) - { - if ($field['type'] === 'SingleVersion' || $field['type'] === 'MultiVersion') - { + foreach ($fields as $field) { + if ($field['type'] === 'SingleVersion' || $field['type'] === 'MultiVersion') { $version_fields[] = [ 'type' => $field['type'], 'key' => $field['key'] ]; } } @@ -97,18 +94,15 @@ public function getVersionFields($project_key) public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -11500); } - if (Version::whereRaw([ 'name' => $name, 'project_key' => $project_key ])->exists()) - { + if (Version::whereRaw([ 'name' => $name, 'project_key' => $project_key ])->exists()) { throw new \UnexpectedValueException('version name cannot be repeated', -11501); } - if ($request->input('start_time') && $request->input('end_time') && $request->input('start_time') > $request->input('end_time')) - { + if ($request->input('start_time') && $request->input('end_time') && $request->input('start_time') > $request->input('end_time')) { throw new \UnexpectedValueException('start-time must less then end-time', -11502); } @@ -144,12 +138,9 @@ public function show($project_key, $id) ->count(); $version->all_cnt = $all_cnt; - if ($version->all_cnt > 0) - { + if ($version->all_cnt > 0) { $version->is_used = true; - } - else - { + } else { $version_fields = $this->getVersionFields($project_key); $version->is_used = $this->isFieldUsedByIssue($project_key, 'version', $version->toArray(), $version_fields); } @@ -167,40 +158,32 @@ public function show($project_key, $id) public function release(Request $request, $project_key, $id) { $version = Version::find($id); - if (!$version || $version->project_key != $project_key) - { + if (!$version || $version->project_key != $project_key) { throw new \UnexpectedValueException('the version does not exist or is not in the project.', -11503); } $status = $request->input('status'); - if (isset($status)) - { + if (isset($status)) { $status_list = ['released', 'unreleased', 'archived']; - if (!in_array($status, $status_list)) - { + if (!in_array($status, $status_list)) { throw new \UnexpectedValueException('the status value has error.', -11505); } - } - else - { + } else { throw new \UnexpectedValueException('the status value cannot be empty.', -11506); } $version->fill(['status' => $status, 'released_time' => time()])->save(); $operate_flg = $request->input('operate_flg'); - if (isset($operate_flg) && $operate_flg === '1') - { + if (isset($operate_flg) && $operate_flg === '1') { $swap_version = $request->input('swap_version'); - if (!isset($swap_version) || !$swap_version) - { + if (!isset($swap_version) || !$swap_version) { throw new \UnexpectedValueException('the swap version cannot be empty.', -11513); } $this->updIssueResolveVersion($project_key, $id, $swap_version); } - if ($status === 'released') - { + if ($status === 'released') { $isSendMsg = $request->input('isSendMsg') && true; $cur_user = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; Event::fire(new VersionEvent($project_key, $cur_user, [ 'event_key' => 'release_version', 'isSendMsg' => $isSendMsg, 'data' => Version::find($id)->toArray() ])); @@ -219,36 +202,30 @@ public function release(Request $request, $project_key, $id) public function update(Request $request, $project_key, $id) { $version = Version::find($id); - if (!$version || $version->project_key != $project_key) - { + if (!$version || $version->project_key != $project_key) { throw new \UnexpectedValueException('the version does not exist or is not in the project.', -11503); } $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -11500); } - if ($version->name !== $name && Version::whereRaw([ 'name' => $name, 'project_key' => $project_key ])->exists()) - { + if ($version->name !== $name && Version::whereRaw([ 'name' => $name, 'project_key' => $project_key ])->exists()) { throw new \UnexpectedValueException('version name cannot be repeated', -11501); } } $start_time = $request->input('start_time') ? $request->input('start_time') : $version->start_time; $end_time = $request->input('end_time') ? $request->input('end_time') : $version->end_time; - if ($start_time > $end_time) - { + if ($start_time > $end_time) { throw new \UnexpectedValueException('start-time must be less then end-time', -11502); } $updValues = []; $updValues = array_only($request->all(), [ 'name', 'start_time', 'end_time', 'description', 'status' ]); - if (!$updValues) - { + if (!$updValues) { return $this->show($project_key, $id); } @@ -273,23 +250,19 @@ public function merge(Request $request, $project_key) { $source = $request->input('source'); $source_version = Version::find($source); - if (!$source_version || $source_version->project_key != $project_key) - { + if (!$source_version || $source_version->project_key != $project_key) { throw new \UnexpectedValueException('the source version does not exist or is not in the project.', -11507); } - if ($source_version->status === 'archived') - { + if ($source_version->status === 'archived') { throw new \UnexpectedValueException('the source version has been archived.', -11508); } $dest = $request->input('dest'); $dest_version = Version::find($dest); - if (!$dest_version || $dest_version->project_key != $project_key) - { + if (!$dest_version || $dest_version->project_key != $project_key) { throw new \UnexpectedValueException('the dest version does not exist or is not in the project.', -11509); } - if ($dest_version->status === 'archived') - { + if ($dest_version->status === 'archived') { throw new \UnexpectedValueException('the source version has been archived.', -11510); } // update the issue related version info @@ -311,7 +284,7 @@ public function merge(Request $request, $project_key) * @param string $project_key * @param string $source * @param string $dest - * @return void + * @return void */ public function updIssueResolveVersion($project_key, $source, $dest) { @@ -319,8 +292,7 @@ public function updIssueResolveVersion($project_key, $source, $dest) ->where('resolve_version', 'Unresolved') ->where('del_flg', '<>', 1) ->get(); - foreach ($issues as $issue) - { + foreach ($issues as $issue) { $updValues['resolve_version'] = $dest; $updValues['modifier'] = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; $updValues['updated_at'] = time(); @@ -341,45 +313,36 @@ public function updIssueResolveVersion($project_key, $source, $dest) * @param string $project_key * @param string $source * @param string $dest - * @return void + * @return void */ public function updIssueVersion($project_key, $source, $dest) { $version_fields = $this->getVersionFields($project_key); $issues = DB::collection('issue_' . $project_key) ->where(function ($query) use ($source, $version_fields) { - foreach ($version_fields as $key => $vf) - { + foreach ($version_fields as $key => $vf) { $query->orWhere($vf['key'], $source); } }) ->where('del_flg', '<>', 1) ->get(); - foreach ($issues as $issue) - { + foreach ($issues as $issue) { $updValues = []; - foreach($version_fields as $key => $vf) - { - if (!isset($issue[$vf['key']])) - { + foreach ($version_fields as $key => $vf) { + if (!isset($issue[$vf['key']])) { continue; } - if (is_string($issue[$vf['key']])) - { - if ($issue[$vf['key']] === $source) - { + if (is_string($issue[$vf['key']])) { + if ($issue[$vf['key']] === $source) { $updValues[$vf['key']] = $dest; } - } - else if (is_array($issue[$vf['key']])) - { + } elseif (is_array($issue[$vf['key']])) { $updValues[$vf['key']] = array_values(array_filter(array_unique(str_replace($source, $dest, $issue[$vf['key']])))); } } - if ($updValues) - { + if ($updValues) { $updFields = array_keys($updValues); $updValues['modifier'] = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; @@ -407,43 +370,32 @@ public function updIssueVersion($project_key, $source, $dest) public function delete(Request $request, $project_key, $id) { $version = Version::find($id); - if (!$version || $version->project_key != $project_key) - { + if (!$version || $version->project_key != $project_key) { throw new \UnexpectedValueException('the version does not exist or is not in the project.', -11503); } $operate_flg = $request->input('operate_flg'); - if (!isset($operate_flg) || $operate_flg === '0') - { + if (!isset($operate_flg) || $operate_flg === '0') { $version_fields = $this->getVersionFields($project_key); $is_used = $this->isFieldUsedByIssue($project_key, 'version', $version->toArray(), $version_fields); - if ($is_used) - { + if ($is_used) { throw new \UnexpectedValueException('the version has been used by some issues.', -11511); } - } - else if ($operate_flg === '1') - { + } elseif ($operate_flg === '1') { $swap_version = $request->input('swap_version'); - if (!isset($swap_version) || !$swap_version) - { + if (!isset($swap_version) || !$swap_version) { throw new \UnexpectedValueException('the swap version cannot be empty.', -11513); - } + } $sversion = Version::find($swap_version); - if (!$sversion || $sversion->project_key != $project_key) - { + if (!$sversion || $sversion->project_key != $project_key) { throw new \UnexpectedValueException('the swap version does not exist or is not in the project.', -11514); } $this->updIssueVersion($project_key, $id, $swap_version); - } - else if ($operate_flg === '2') - { + } elseif ($operate_flg === '2') { $this->updIssueVersion($project_key, $id, ''); - } - else - { + } else { throw new \UnexpectedValueException('the operation has error.', -11512); } @@ -453,12 +405,9 @@ public function delete(Request $request, $project_key, $id) $cur_user = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; Event::fire(new VersionEvent($project_key, $cur_user, [ 'event_key' => 'del_version', 'data' => $version->toArray() ])); - if ($operate_flg === '1') - { + if ($operate_flg === '1') { return $this->show($project_key, $request->input('swap_version')); - } - else - { + } else { return Response()->json(['ecode' => 0, 'data' => [ 'id' => $id ]]); } } diff --git a/app/Http/Controllers/WebhookController.php b/app/Http/Controllers/WebhookController.php index da0daf70c..7d3fe211c 100644 --- a/app/Http/Controllers/WebhookController.php +++ b/app/Http/Controllers/WebhookController.php @@ -23,57 +23,44 @@ class WebhookController extends Controller */ public function exec($type, $project_key) { - - if (!in_array($type, ['gitlab', 'github'])) - { + if (!in_array($type, ['gitlab', 'github'])) { return Response()->json([ 'ecode' => -2, 'emsg' => 'the request url has error.' ]); } $external_user = ExternalUsers::where('project_key', $project_key) ->where('user', $type) ->first(); - if (!$external_user) - { + if (!$external_user) { return Response()->json([ 'ecode' => -3, 'emsg' => 'the user has not been used.' ]); - } - else if ($external_user->status !== 'enabled') - { + } elseif ($external_user->status !== 'enabled') { return Response()->json([ 'ecode' => -4, 'emsg' => 'the user has been disabled.' ]); } $payload = file_get_contents('php://input'); - if ($type === 'gitlab') - { - if ($_SERVER['HTTP_X_GITLAB_EVENT'] !== 'Push Hook') - { + if ($type === 'gitlab') { + if ($_SERVER['HTTP_X_GITLAB_EVENT'] !== 'Push Hook') { return Response()->json([ 'ecode' => -5, 'emsg' => 'the event has error.' ]); } $token = $external_user->pwd ?: ''; - if (!$token || $token !== $_SERVER['HTTP_X_GITLAB_TOKEN']) - { + if (!$token || $token !== $_SERVER['HTTP_X_GITLAB_TOKEN']) { return Response()->json([ 'ecode' => -1, 'emsg' => 'the token has error.' ]); } $push = new GitLabPush(json_decode($payload, true)); $push->insCommits($project_key); - } - else if ($type === 'github') - { - if ($_SERVER['HTTP_X_GITHUB_EVENT'] !== 'push') - { + } elseif ($type === 'github') { + if ($_SERVER['HTTP_X_GITHUB_EVENT'] !== 'push') { return Response()->json([ 'ecode' => -5, 'emsg' => 'the event has error.' ]); } $token = $external_user->pwd ?: ''; - if (!$token) - { + if (!$token) { return Response()->json([ 'ecode' => -1, 'emsg' => 'the token can not be empty.' ]); } $signature = 'sha1=' . hash_hmac('sha1', $payload, $token); - if ($signature !== $_SERVER['HTTP_X_HUB_SIGNATURE']) - { + if ($signature !== $_SERVER['HTTP_X_HUB_SIGNATURE']) { return Response()->json([ 'ecode' => -1, 'emsg' => 'the token has error.' ]); } diff --git a/app/Http/Controllers/WebhooksController.php b/app/Http/Controllers/WebhooksController.php index a573b1758..f3c0068ad 100644 --- a/app/Http/Controllers/WebhooksController.php +++ b/app/Http/Controllers/WebhooksController.php @@ -33,8 +33,7 @@ public function store(Request $request, $project_key) { $insValues = []; - if (!($request_url = $request->input('request_url'))) - { + if (!($request_url = $request->input('request_url'))) { throw new \UnexpectedValueException('the request url can not be empty.', -16010); } $insValues['request_url'] = $request_url; @@ -45,13 +44,11 @@ public function store(Request $request, $project_key) //} $insValues['events'] = $request->input('events') ?: []; - if ($token = $request->input('token')) - { + if ($token = $request->input('token')) { $insValues['token'] = $token; } - if ($ssl = $request->input('ssl')) - { + if ($ssl = $request->input('ssl')) { $insValues['ssl'] = $ssl; } @@ -69,19 +66,16 @@ public function store(Request $request, $project_key) public function update(Request $request, $project_key, $id) { $webhook = Webhooks::find($id); - if (!$webhook || $project_key != $webhook->project_key) - { + if (!$webhook || $project_key != $webhook->project_key) { throw new \UnexpectedValueException('the webhook does not exist or is not in the project.', -16011); } $updValues = []; - if ($status = $request->input('status')) - { + if ($status = $request->input('status')) { $updValues['status'] = $status; } - if ($updValues) - { + if ($updValues) { $webhook->fill($updValues)->save(); } @@ -97,8 +91,7 @@ public function update(Request $request, $project_key, $id) public function destroy($project_key, $id) { $webhook = Webhooks::find($id); - if (!$webhook || $project_key != $webhook->project_key) - { + if (!$webhook || $project_key != $webhook->project_key) { throw new \UnexpectedValueException('the webhook does not exist or is not in the project.', -16011); } diff --git a/app/Http/Controllers/WikiController.php b/app/Http/Controllers/WikiController.php index 9aa13304b..af43bf3b6 100644 --- a/app/Http/Controllers/WikiController.php +++ b/app/Http/Controllers/WikiController.php @@ -23,13 +23,11 @@ class WikiController extends Controller public function searchPath(Request $request, $project_key) { $s = $request->input('s'); - if (!$s) - { + if (!$s) { return Response()->json(['ecode' => 0, 'data' => []]); } - if ($s === '/') - { + if ($s === '/') { return Response()->json(['ecode' => 0, 'data' => [ [ 'id' => '0', 'name' => '/' ] ] ]); } @@ -39,8 +37,7 @@ public function searchPath(Request $request, $project_key) ->where('name', 'like', '%' . $s . '%'); $moved_path = $request->input('moved_path'); - if (isset($moved_path) && $moved_path) - { + if (isset($moved_path) && $moved_path) { $query->where('pt', '<>', $moved_path); $query->where('_id', '<>', $moved_path); } @@ -48,22 +45,18 @@ public function searchPath(Request $request, $project_key) $directories = $query->take(20)->get(['name', 'pt']); $ret = []; - foreach ($directories as $d) - { + foreach ($directories as $d) { $parents = []; $path = ''; $ps = DB::collection('wiki_' . $project_key) ->whereIn('_id', $d['pt']) ->get([ 'name' ]); - foreach ($ps as $val) - { + foreach ($ps as $val) { $parents[$val['_id']->__toString()] = $val['name']; } - foreach ($d['pt'] as $pid) - { - if (isset($parents[$pid])) - { + foreach ($d['pt'] as $pid) { + if (isset($parents[$pid])) { $path .= '/' . $parents[$pid]; } } @@ -87,13 +80,12 @@ public function getDirChildren(Request $request, $project_key, $directory) ->get(); $res = []; - foreach ($sub_dirs as $val) - { - $res[] = [ - 'id' => $val['_id']->__toString(), + foreach ($sub_dirs as $val) { + $res[] = [ + 'id' => $val['_id']->__toString(), 'name' => $val['name'], - 'd' => isset($val['d']) ? $val['d'] : 0, - 'parent' => isset($val['parent']) ? $val['parent'] : '' + 'd' => isset($val['d']) ? $val['d'] : 0, + 'parent' => isset($val['parent']) ? $val['parent'] : '' ]; } @@ -110,30 +102,25 @@ public function getDirTree(Request $request, $project_key) $dt = [ 'id' => '0', 'name' => '根目录', 'd' => 1 ]; $curnode = $request->input('currentnode'); - if (!$curnode) - { + if (!$curnode) { $curnode = '0'; } $pt = [ '0' ]; - if ($curnode !== '0') - { + if ($curnode !== '0') { $node = DB::collection('wiki_' . $project_key) ->where('_id', $curnode) ->first(); - if ($node) - { + if ($node) { $pt = $node['pt']; - if (isset($node['d']) && $node['d'] == 1) - { + if (isset($node['d']) && $node['d'] == 1) { array_push($pt, $curnode); } } } - foreach($pt as $val) - { + foreach ($pt as $val) { $sub_dirs = DB::collection('wiki_' . $project_key) ->where('parent', $val) ->where('del_flag', '<>', 1) @@ -156,31 +143,24 @@ public function getDirTree(Request $request, $project_key) public function addChildren2Tree(&$dt, $parent_id, $sub_dirs) { $new_dirs = []; - foreach($sub_dirs as $val) - { - $new_dirs[] = [ - 'id' => $val['_id']->__toString(), - 'name' => $val['name'], - 'd' => isset($val['d']) ? $val['d'] : 0, - 'parent' => isset($val['parent']) ? $val['parent'] : '' + foreach ($sub_dirs as $val) { + $new_dirs[] = [ + 'id' => $val['_id']->__toString(), + 'name' => $val['name'], + 'd' => isset($val['d']) ? $val['d'] : 0, + 'parent' => isset($val['parent']) ? $val['parent'] : '' ]; } - if ($dt['id'] == $parent_id) - { + if ($dt['id'] == $parent_id) { $dt['children'] = $new_dirs; return true; - } - else - { - if (isset($dt['children']) && $dt['children']) - { + } else { + if (isset($dt['children']) && $dt['children']) { $children_num = count($dt['children']); - for ($i = 0; $i < $children_num; $i++) - { + for ($i = 0; $i < $children_num; $i++) { $res = $this->addChildren2Tree($dt['children'][$i], $parent_id, $sub_dirs); - if ($res === true) - { + if ($res === true) { return true; } } @@ -201,15 +181,13 @@ public function index(Request $request, $project_key, $directory) $query = DB::collection('wiki_' . $project_key); $name = $request->input('name'); - if (isset($name) && $name) - { + if (isset($name) && $name) { $mode = 'search'; $query = $query->where('name', 'like', '%' . $name . '%'); } $updated_at = $request->input('updated_at'); - if (isset($updated_at) && $updated_at) - { + if (isset($updated_at) && $updated_at) { $mode = 'search'; $query->where(function ($query) use ($updated_at) { $unitMap = [ 'w' => 'week', 'm' => 'month', 'y' => 'year' ]; @@ -220,14 +198,10 @@ public function index(Request $request, $project_key, $directory) }); } - if ($directory !== '0') - { + if ($directory !== '0') { $query = $query->where($mode === 'search' ? 'pt' : 'parent', $directory); - } - else - { - if ($mode === 'list') - { + } else { + if ($mode === 'list') { $query = $query->where('parent', $directory); } } @@ -241,27 +215,20 @@ public function index(Request $request, $project_key, $directory) $path = []; $home = []; - if ($directory === '0') - { + if ($directory === '0') { $path[] = [ 'id' => '0', 'name' => 'root' ]; - if ($mode === 'list') - { - foreach ($documents as $doc) - { - if ((!isset($doc['d']) || $doc['d'] != 1) && strtolower($doc['name']) === 'home') - { + if ($mode === 'list') { + foreach ($documents as $doc) { + if ((!isset($doc['d']) || $doc['d'] != 1) && strtolower($doc['name']) === 'home') { $home = $doc; } } } - } - else - { + } else { $d = DB::collection('wiki_' . $project_key) ->where('_id', $directory) ->first(); - if ($d && isset($d['pt'])) - { + if ($d && isset($d['pt'])) { $path = $this->getPathTreeDetail($project_key, $d['pt']); } $path[] = [ 'id' => $directory, 'name' => $d['name'] ]; @@ -280,16 +247,12 @@ public function index(Request $request, $project_key, $directory) public function create(Request $request, $project_key) { $d = $request->input('d'); - if (isset($d) && $d == 1) - { - if (!$this->isPermissionAllowed($project_key, 'manage_project')) - { + if (isset($d) && $d == 1) { + if (!$this->isPermissionAllowed($project_key, 'manage_project')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } return $this->createFolder($request, $project_key); - } - else - { + } else { return $this->createDoc($request, $project_key); } } @@ -306,28 +269,24 @@ public function createDoc(Request $request, $project_key) $insValues = []; $parent = $request->input('parent'); - if (!isset($parent)) - { + if (!isset($parent)) { throw new \UnexpectedValueException('the parent directory can not be empty.', -11950); } $insValues['parent'] = $parent; - if ($parent !== '0') - { + if ($parent !== '0') { $isExists = DB::collection('wiki_' . $project_key) ->where('_id', $parent) ->where('d', 1) ->where('del_flag', '<>', 1) ->exists(); - if (!$isExists) - { + if (!$isExists) { throw new \UnexpectedValueException('the parent directory does not exist.', -11951); } } $name = $request->input('name'); - if (!isset($name) || !$name) - { + if (!isset($name) || !$name) { throw new \UnexpectedValueException('the name can not be empty.', -11952); } $insValues['name'] = $name; @@ -338,14 +297,12 @@ public function createDoc(Request $request, $project_key) ->where('d', '<>', 1) ->where('del_flag', '<>', 1) ->exists(); - if ($isExists) - { + if ($isExists) { throw new \UnexpectedValueException('the name cannot be repeated.', -11953); } $contents = $request->input('contents'); - if (isset($contents) && $contents) - { + if (isset($contents) && $contents) { $insValues['contents'] = $contents; } @@ -373,28 +330,24 @@ public function createFolder(Request $request, $project_key) $insValues = []; $parent = $request->input('parent'); - if (!isset($parent)) - { + if (!isset($parent)) { throw new \UnexpectedValueException('the parent directory can not be empty.', -11950); } $insValues['parent'] = $parent; - if ($parent !== '0') - { + if ($parent !== '0') { $isExists = DB::collection('wiki_' . $project_key) ->where('_id', $parent) ->where('d', 1) ->where('del_flag', '<>', 1) ->exists(); - if (!$isExists) - { + if (!$isExists) { throw new \UnexpectedValueException('the parent directory does not exist.', -11951); } } $name = $request->input('name'); - if (!isset($name) || !$name) - { + if (!isset($name) || !$name) { throw new \UnexpectedValueException('the name can not be empty.', -11952); } $insValues['name'] = $name; @@ -405,8 +358,7 @@ public function createFolder(Request $request, $project_key) ->where('d', 1) ->where('del_flag', '<>', 1) ->exists(); - if ($isExists) - { + if ($isExists) { throw new \UnexpectedValueException('the name cannot be repeated.', -11953); } @@ -433,17 +385,15 @@ public function checkin(Request $request, $project_key, $id) ->where('_id', $id) ->where('del_flag', '<>', 1) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the object does not exist.', -11954); } - if (isset($document['checkin']) && $document['checkin']) - { + if (isset($document['checkin']) && $document['checkin']) { throw new \UnexpectedValueException('the object has been locked.', -11955); } - $checkin = []; + $checkin = []; $checkin['user'] = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; $checkin['at'] = time(); @@ -464,13 +414,11 @@ public function checkout(Request $request, $project_key, $id) ->where('_id', $id) ->where('del_flag', '<>', 1) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the object does not exist.', -11954); } - if (isset($document['checkin']) && !((isset($document['checkin']['user']) && $document['checkin']['user']['id'] == $this->user->id) || $this->isPermissionAllowed($project_key, 'manage_project'))) - { + if (isset($document['checkin']) && !((isset($document['checkin']['user']) && $document['checkin']['user']['id'] == $this->user->id) || $this->isPermissionAllowed($project_key, 'manage_project'))) { throw new \UnexpectedValueException('the object cannot been unlocked.', -11956); } @@ -491,20 +439,15 @@ public function getPathTreeDetail($project_key, $pt) $ps = DB::collection('wiki_' . $project_key) ->whereIn('_id', $pt) ->get([ 'name' ]); - foreach ($ps as $val) - { + foreach ($ps as $val) { $parents[$val['_id']->__toString()] = $val['name']; } $path = []; - foreach ($pt as $pid) - { - if ($pid === '0') - { + foreach ($pt as $pid) { + if ($pid === '0') { $path[] = [ 'id' => '0', 'name' => 'root' ]; - } - else if (isset($parents[$pid])) - { + } elseif (isset($parents[$pid])) { $path[] = [ 'id' => $pid, 'name' => $parents[$pid] ]; } } @@ -520,12 +463,9 @@ public function getPathTreeDetail($project_key, $pt) public function getPathTree($project_key, $directory) { $pt = []; - if ($directory === '0') - { + if ($directory === '0') { $pt = [ '0' ]; - } - else - { + } else { $d = DB::collection('wiki_' . $project_key) ->where('_id', $directory) ->first(); @@ -548,8 +488,7 @@ public function show(Request $request, $project_key, $id) ->where('_id', $id) ->where('del_flag', '<>', 1) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the object does not exist.', -11954); } @@ -560,14 +499,12 @@ public function show(Request $request, $project_key, $id) $newest['version'] = $document['version']; $v = $request->input('v'); - if (isset($v) && intval($v) != $document['version']) - { + if (isset($v) && intval($v) != $document['version']) { $w = DB::collection('wiki_version_' . $project_key) ->where('wid', $id) - ->where('version', intval($v)) + ->where('version', intval($v)) ->first(); - if (!$w) - { + if (!$w) { throw new \UnexpectedValueException('the version does not exist.', -11957); } @@ -600,8 +537,7 @@ public function show(Request $request, $project_key, $id) public function update(Request $request, $project_key, $id) { $name = $request->input('name'); - if (!isset($name) || !$name) - { + if (!isset($name) || !$name) { throw new \UnexpectedValueException('the name can not be empty.', -11952); } @@ -609,66 +545,50 @@ public function update(Request $request, $project_key, $id) ->where('_id', $id) ->where('del_flag', '<>', 1) ->first(); - if (!$old_document) - { + if (!$old_document) { throw new \UnexpectedValueException('the object does not exist.', -11954); } - if (isset($old_document['d']) && $old_document['d'] === 1) - { - if (!$this->isPermissionAllowed($project_key, 'manage_project')) - { + if (isset($old_document['d']) && $old_document['d'] === 1) { + if (!$this->isPermissionAllowed($project_key, 'manage_project')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } - } - else - { - if (isset($old_document['checkin']) && isset($old_document['checkin']['user']) && $old_document['checkin']['user']['id'] !== $this->user->id) - { + } else { + if (isset($old_document['checkin']) && isset($old_document['checkin']['user']) && $old_document['checkin']['user']['id'] !== $this->user->id) { throw new \UnexpectedValueException('the object has been locked.', -11955); } } $updValues = []; - if ($old_document['name'] !== $name) - { + if ($old_document['name'] !== $name) { $query = DB::collection('wiki_' . $project_key) ->where('parent', $old_document['parent']) ->where('name', $name) ->where('del_flag', '<>', 1); - if (isset($old_document['d']) && $old_document['d'] === 1) - { + if (isset($old_document['d']) && $old_document['d'] === 1) { $query->where('d', 1); - } - else - { + } else { $query->where('d', '<>', 1); } $isExists = $query->exists(); - if ($isExists) - { + if ($isExists) { throw new \UnexpectedValueException('the name cannot be repeated.', -11953); } $updValues['name'] = $name; } - if (!isset($old_document['d']) || $old_document['d'] !== 1) - { + if (!isset($old_document['d']) || $old_document['d'] !== 1) { $contents = $request->input('contents'); - if (isset($contents) && $contents) - { + if (isset($contents) && $contents) { $updValues['contents'] = $contents; } - if (isset($old_document['version']) && $old_document['version']) - { + if (isset($old_document['version']) && $old_document['version']) { $updValues['version'] = $old_document['version'] + 1; - } - else - { + } else { $updValues['version'] = 2; } } @@ -678,20 +598,17 @@ public function update(Request $request, $project_key, $id) DB::collection('wiki_' . $project_key)->where('_id', $id)->update($updValues); // record the version - if (!isset($old_document['d']) || $old_document['d'] !== 1) - { + if (!isset($old_document['d']) || $old_document['d'] !== 1) { // unlock the wiki - DB::collection('wiki_' . $project_key)->where('_id', $id)->unset('checkin'); - // record versions + DB::collection('wiki_' . $project_key)->where('_id', $id)->unset('checkin'); + // record versions $this->recordVersion($project_key, $old_document); $isSendMsg = $request->input('isSendMsg') && true; Event::fire(new WikiEvent($project_key, $updValues['editor'], [ 'event_key' => 'edit_wiki', 'isSendMsg' => $isSendMsg, 'data' => [ 'wiki_id' => $id ] ])); return $this->show($request, $project_key, $id); - } - else - { + } else { $document = DB::collection('wiki_' . $project_key)->where('_id', $id)->first(); return Response()->json(['ecode' => 0, 'data' => parent::arrange($document)]); } @@ -726,20 +643,17 @@ public function recordVersion($project_key, $document) public function copy(Request $request, $project_key) { $id = $request->input('id'); - if (!isset($id) || !$id) - { + if (!isset($id) || !$id) { throw new \UnexpectedValueException('the copy object can not be empty.', -11960); } $name = $request->input('name'); - if (!isset($name) || !$name) - { + if (!isset($name) || !$name) { throw new \UnexpectedValueException('the name can not be empty.', -11952); } $dest_path = $request->input('dest_path'); - if (!isset($dest_path)) - { + if (!isset($dest_path)) { throw new \UnexpectedValueException('the dest directory can not be empty.', -11961); } @@ -748,21 +662,18 @@ public function copy(Request $request, $project_key) ->where('d', '<>', 1) ->where('del_flag', '<>', 1) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the copy object does not exist.', -11962); } $dest_directory = []; - if ($dest_path !== '0') - { + if ($dest_path !== '0') { $dest_directory = DB::collection('wiki_' . $project_key) ->where('_id', $dest_path) ->where('d', 1) ->where('del_flag', '<>', 1) ->first(); - if (!$dest_directory) - { + if (!$dest_directory) { throw new \UnexpectedValueException('the dest directory does not exist.', -11963); } } @@ -773,8 +684,7 @@ public function copy(Request $request, $project_key) ->where('d', '<>', 1) ->where('del_flag', '<>', 1) ->exists(); - if ($isExists) - { + if ($isExists) { throw new \UnexpectedValueException('the name cannot be repeated.', -11953); } @@ -794,7 +704,7 @@ public function copy(Request $request, $project_key) $insValues['creator'] = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; $insValues['created_at'] = time(); - $new_id = DB::collection('wiki_' . $project_key)->insertGetId($insValues); + $new_id = DB::collection('wiki_' . $project_key)->insertGetId($insValues); $document = DB::collection('wiki_' . $project_key)->where('_id', $new_id)->first(); return Response()->json(['ecode' => 0, 'data' => parent::arrange($document)]); @@ -810,14 +720,12 @@ public function copy(Request $request, $project_key) public function move(Request $request, $project_key) { $id = $request->input('id'); - if (!isset($id) || !$id) - { + if (!isset($id) || !$id) { throw new \UnexpectedValueException('the move object can not be empty.', -11964); } $dest_path = $request->input('dest_path'); - if (!isset($dest_path)) - { + if (!isset($dest_path)) { throw new \UnexpectedValueException('the dest directory can not be empty.', -11965); } @@ -825,29 +733,24 @@ public function move(Request $request, $project_key) ->where('_id', $id) ->where('del_flag', '<>', 1) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the move object does not exist.', -11966); } - if (isset($document['d']) && $document['d'] === 1) - { - if (!$this->isPermissionAllowed($project_key, 'manage_project')) - { + if (isset($document['d']) && $document['d'] === 1) { + if (!$this->isPermissionAllowed($project_key, 'manage_project')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } } $dest_directory = []; - if ($dest_path !== '0') - { + if ($dest_path !== '0') { $dest_directory = DB::collection('wiki_' . $project_key) ->where('_id', $dest_path) ->where('d', 1) ->where('del_flag', '<>', 1) ->first(); - if (!$dest_directory) - { + if (!$dest_directory) { throw new \UnexpectedValueException('the dest directory does not exist.', -11967); } } @@ -858,8 +761,7 @@ public function move(Request $request, $project_key) ->where('d', isset($document['d']) && $document['d'] === 1 ? '=' : '<>', 1) ->where('del_flag', '<>', 1) ->exists(); - if ($isExists) - { + if ($isExists) { throw new \UnexpectedValueException('the name cannot be repeated.', -11953); } @@ -868,23 +770,20 @@ public function move(Request $request, $project_key) $updValues['pt'] = array_merge(isset($dest_directory['pt']) ? $dest_directory['pt'] : [], [$dest_path]); DB::collection('wiki_' . $project_key)->where('_id', $id)->update($updValues); - if (isset($document['d']) && $document['d'] === 1) - { + if (isset($document['d']) && $document['d'] === 1) { $subs = DB::collection('wiki_' . $project_key) ->where('pt', $id) ->where('del_flag', '<>', 1) ->get(); - foreach ($subs as $sub) - { - $pt = isset($sub['pt']) ? $sub['pt'] : []; - $pind = array_search($id, $pt); - if ($pind !== false) - { - $tail = array_slice($pt, $pind); - $pt = array_merge($updValues['pt'], $tail); - DB::collection('wiki_' . $project_key)->where('_id', $sub['_id']->__toString())->update(['pt' => $pt]); - } - } + foreach ($subs as $sub) { + $pt = isset($sub['pt']) ? $sub['pt'] : []; + $pind = array_search($id, $pt); + if ($pind !== false) { + $tail = array_slice($pt, $pind); + $pt = array_merge($updValues['pt'], $tail); + DB::collection('wiki_' . $project_key)->where('_id', $sub['_id']->__toString())->update(['pt' => $pt]); + } + } } $document = DB::collection('wiki_' . $project_key)->where('_id', $id)->first(); @@ -903,23 +802,19 @@ public function destroy($project_key, $id) $document = DB::collection('wiki_' . $project_key) ->where('_id', $id) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the object does not exist.', -11954); } - if (isset($document['d']) && $document['d'] === 1) - { - if (!$this->isPermissionAllowed($project_key, 'manage_project')) - { + if (isset($document['d']) && $document['d'] === 1) { + if (!$this->isPermissionAllowed($project_key, 'manage_project')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } } DB::collection('wiki_' . $project_key)->where('_id', $id)->update([ 'del_flag' => 1 ]); - if (isset($document['d']) && $document['d'] === 1) - { + if (isset($document['d']) && $document['d'] === 1) { DB::collection('wiki_' . $project_key)->whereRaw([ 'pt' => $id ])->update([ 'del_flag' => 1 ]); } @@ -942,15 +837,13 @@ public function upload(Request $request, $project_key, $wid) { set_time_limit(0); - if (!is_writable(config('filesystems.disks.local.root', '/tmp'))) - { + if (!is_writable(config('filesystems.disks.local.root', '/tmp'))) { throw new \UnexpectedValueException('the user has not the writable permission to the directory.', -15103); } $fields = array_keys($_FILES); $field = array_pop($fields); - if (empty($_FILES) || $_FILES[$field]['error'] > 0) - { + if (empty($_FILES) || $_FILES[$field]['error'] > 0) { throw new \UnexpectedValueException('upload file errors.', -11959); } @@ -958,22 +851,21 @@ public function upload(Request $request, $project_key, $wid) ->where('_id', $wid) ->where('del_flag', '<>', 1) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the object does not exist.', -11954); } $basename = md5(microtime() . $_FILES[$field]['name']); $sub_save_path = config('filesystems.disks.local.root', '/tmp') . '/' . substr($basename, 0, 2) . '/'; - if (!is_dir($sub_save_path)) - { + if (!is_dir($sub_save_path)) { @mkdir($sub_save_path); } move_uploaded_file($_FILES[$field]['tmp_name'], $sub_save_path . $basename); $data = []; - $data['name'] = $_FILES[$field]['name'];; + $data['name'] = $_FILES[$field]['name']; + ; $data['size'] = $_FILES[$field]['size']; $data['type'] = $_FILES[$field]['type']; $data['id'] = $data['index'] = $basename; @@ -982,8 +874,7 @@ public function upload(Request $request, $project_key, $wid) $data['uploaded_at'] = time(); $attachments = []; - if (isset($document['attachments']) && $document['attachments']) - { + if (isset($document['attachments']) && $document['attachments']) { $attachments = $document['attachments']; } @@ -1007,21 +898,17 @@ public function remove(Request $request, $project_key, $wid, $fid) ->where('_id', $wid) ->where('del_flag', '<>', 1) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the object does not exist.', -11954); } - if (!isset($document['attachments']) || !$document['attachments']) - { + if (!isset($document['attachments']) || !$document['attachments']) { throw new \UnexpectedValueException('the file does not exist.', -11958); } $new_attachments = []; - foreach ($document['attachments'] as $a) - { - if ($a['id'] !== $fid) - { + foreach ($document['attachments'] as $a) { + if ($a['id'] !== $fid) { $new_attachments[] = $a; } } @@ -1046,13 +933,11 @@ public function download2(Request $request, $project_key, $wid) ->where('_id', $wid) ->where('del_flag', '<>', 1) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the object does not exist.', -11954); } - if (!isset($document['attachments']) || !$document['attachments']) - { + if (!isset($document['attachments']) || !$document['attachments']) { throw new \UnexpectedValueException('the file does not exist.', -11958); } @@ -1076,28 +961,23 @@ public function download(Request $request, $project_key, $wid, $fid) ->where('_id', $wid) ->where('del_flag', '<>', 1) ->first(); - if (!$document) - { + if (!$document) { throw new \UnexpectedValueException('the object does not exist.', -11954); } - if (!isset($document['attachments']) || !$document['attachments']) - { + if (!isset($document['attachments']) || !$document['attachments']) { throw new \UnexpectedValueException('the file does not exist.', -11958); } $isExists = false; - foreach ($document['attachments'] as $file) - { - if (isset($file['id']) && $file['id'] === $fid) - { + foreach ($document['attachments'] as $file) { + if (isset($file['id']) && $file['id'] === $fid) { $isExists = true; break; } } - if (!$isExists) - { + if (!$isExists) { throw new \UnexpectedValueException('the file does not exist.', -11958); } @@ -1113,7 +993,7 @@ public function download(Request $request, $project_key, $wid, $fid) */ public function downloadFolder($name, $attachments) { - setlocale(LC_ALL, 'zh_CN.UTF-8'); + setlocale(LC_ALL, 'zh_CN.UTF-8'); $basepath = '/tmp/' . md5($this->user->id . microtime()); @mkdir($basepath); @@ -1121,12 +1001,10 @@ public function downloadFolder($name, $attachments) $fullpath = $basepath . '/' . $name; @mkdir($fullpath); - foreach ($attachments as $attachment) - { + foreach ($attachments as $attachment) { $filepath = config('filesystems.disks.local.root', '/tmp') . '/' . substr($attachment['index'], 0, 2); $filename = $filepath . '/' . $attachment['index']; - if (file_exists($filename)) - { + if (file_exists($filename)) { @copy($filename, $fullpath . '/' . $attachment['name']); } } @@ -1151,8 +1029,7 @@ public function downloadFile($name, $index) { $filepath = config('filesystems.disks.local.root', '/tmp') . '/' . substr($index, 0, 2); $filename = $filepath . '/' . $index; - if (!file_exists($filename)) - { + if (!file_exists($filename)) { throw new \UnexpectedValueException('file does not exist.', -11958); } diff --git a/app/Http/Controllers/WorkflowController.php b/app/Http/Controllers/WorkflowController.php index 39ffc7ef7..565f7c993 100644 --- a/app/Http/Controllers/WorkflowController.php +++ b/app/Http/Controllers/WorkflowController.php @@ -22,9 +22,8 @@ class WorkflowController extends Controller public function index($project_key) { $workflows = Provider::getWorkflowList($project_key, [ 'name', 'project_key', 'description', 'latest_modified_time', 'latest_modifier', 'steps' ]); - foreach ($workflows as $workflow) - { - $workflow->is_used = Type::where('workflow_id', $workflow->id)->exists(); + foreach ($workflows as $workflow) { + $workflow->is_used = Type::where('workflow_id', $workflow->id)->exists(); } return Response()->json([ 'ecode' => 0, 'data' => $workflows ]); @@ -39,31 +38,30 @@ public function index($project_key) public function store(Request $request, $project_key) { $name = $request->input('name'); - if (!$name) - { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12100); } $contents = $request->input('contents'); - if (isset($contents) && $contents) - { + if (isset($contents) && $contents) { $latest_modifier = [ 'id' => $this->user->id, 'name' => $this->user->first_name ]; $latest_modified_time = date('Y-m-d H:i:s'); $state_ids = Workflow::getStates($contents); $screen_ids = Workflow::getScreens($contents); $steps = Workflow::getStepNum($contents); - } - else - { - $latest_modifier = []; $latest_modified_time = ''; $state_ids = []; $screen_ids = []; $steps = 0; + } else { + $latest_modifier = []; + $latest_modified_time = ''; + $state_ids = []; + $screen_ids = []; + $steps = 0; } $source_id = $request->input('source_id'); - if (isset($source_id) && $source_id) - { + if (isset($source_id) && $source_id) { $source_definition = Definition::find($source_id); $latest_modifier = [ 'id' => $this->user->id, 'name' => $this->user->first_name ]; - $latest_modified_time = date('Y-m-d H:i:s'); + $latest_modified_time = date('Y-m-d H:i:s'); $state_ids = $source_definition->state_ids; $screen_ids = $source_definition->screen_ids; $steps = $source_definition->steps; @@ -83,12 +81,9 @@ public function store(Request $request, $project_key) public function preview(Request $request, $project_key, $id) { $workflow = Definition::find($id); - if ($workflow) - { + if ($workflow) { return Response()->json([ 'ecode' => 0, 'data' => $workflow ]); - } - else - { + } else { throw new \UnexpectedValueException('the workflow does not exist or is not in the project.', -12101); } } @@ -102,8 +97,7 @@ public function preview(Request $request, $project_key, $id) public function show(Request $request, $project_key, $id) { $workflow = Definition::find($id); - if (!$workflow || $project_key != $workflow->project_key) - { + if (!$workflow || $project_key != $workflow->project_key) { throw new \UnexpectedValueException('the workflow does not exist or is not in the project.', -12101); } @@ -127,22 +121,18 @@ public function show(Request $request, $project_key, $id) public function update(Request $request, $project_key, $id) { $name = $request->input('name'); - if (isset($name)) - { - if (!$name) - { + if (isset($name)) { + if (!$name) { throw new \UnexpectedValueException('the name can not be empty.', -12100); } } $workflow = Definition::find($id); - if (!$workflow || $project_key != $workflow->project_key) - { + if (!$workflow || $project_key != $workflow->project_key) { throw new \UnexpectedValueException('the workflow does not exist or is not in the project.', -12101); } $contents = $request->input('contents'); - if (isset($contents)) - { + if (isset($contents)) { $latest_modifier = [ 'id' => $this->user->id, 'name' => $this->user->first_name ]; $latest_modified_time = date('Y-m-d H:i:s'); @@ -166,14 +156,12 @@ public function update(Request $request, $project_key, $id) public function destroy($project_key, $id) { $workflow = Definition::find($id); - if (!$workflow || $project_key != $workflow->project_key) - { + if (!$workflow || $project_key != $workflow->project_key) { throw new \UnexpectedValueException('the workflow does not exist or is not in the project.', -12101); } $isUsed = Type::where('workflow_id', $id)->exists(); - if ($isUsed) - { + if ($isUsed) { throw new \UnexpectedValueException('the workflow has been bound to type.', -12102); } @@ -188,23 +176,20 @@ public function destroy($project_key, $id) */ public function viewUsedInProject($project_key, $id) { - if ($project_key !== '$_sys_$') - { + if ($project_key !== '$_sys_$') { return Response()->json(['ecode' => 0, 'data' => [] ]); } $res = []; $projects = Project::all(); - foreach($projects as $project) - { + foreach ($projects as $project) { $types = Type::where('workflow_id', $id) ->where('project_key', '<>', '$_sys_$') ->where('project_key', $project->key) ->get([ 'id', 'name' ]) ->toArray(); - if ($types) - { + if ($types) { $res[] = [ 'key' => $project->key, 'name' => $project->name, 'status' => $project->status, 'types' => $types ]; } } diff --git a/app/Http/Controllers/WorklogController.php b/app/Http/Controllers/WorklogController.php index d15ff321a..dc0f16b52 100644 --- a/app/Http/Controllers/WorklogController.php +++ b/app/Http/Controllers/WorklogController.php @@ -13,7 +13,6 @@ class WorklogController extends Controller { - use TimeTrackTrait; /** @@ -47,57 +46,47 @@ public function store(Request $request, $project_key, $issue_id) $values = []; $spend = $request->input('spend'); - if (!$spend) - { + if (!$spend) { throw new \UnexpectedValueException('the spend-time can not be empty.', -11300); } - if (!$this->ttCheck($spend)) - { + if (!$this->ttCheck($spend)) { throw new \UnexpectedValueException('the format of spend-time is incorrect.', -11301); } $values['spend'] = $this->ttHandle($spend); $values['spend_m'] = $this->ttHandleInM($spend); $started_at = $request->input('started_at'); - if (!$started_at) - { + if (!$started_at) { throw new \UnexpectedValueException('the start time can not be empty.', -11302); } $values['started_at'] = $started_at; $adjust_type = $request->input('adjust_type'); - if (!in_array($adjust_type, ['1', '2', '3', '4'])) - { + if (!in_array($adjust_type, ['1', '2', '3', '4'])) { throw new \UnexpectedValueException('the adjust-type value is incorrect.', -11303); } $values['adjust_type'] = $adjust_type; - if ($adjust_type == '3') - { + if ($adjust_type == '3') { $leave_estimate = $request->input('leave_estimate'); - if (!$leave_estimate) - { + if (!$leave_estimate) { throw new \UnexpectedValueException('the leave-estimate-time can not be empty.', -11304); } - if (!$this->ttCheck($leave_estimate)) - { + if (!$this->ttCheck($leave_estimate)) { throw new \UnexpectedValueException('the format of leave-estimate-time is incorrect.', -11305); } $values['leave_estimate'] = $this->ttHandle($leave_estimate); $values['leave_estimate_m'] = $this->ttHandleInM($values['leave_estimate']); } - if ($adjust_type == '4') - { + if ($adjust_type == '4') { $cut = $request->input('cut'); - if (!$cut) - { + if (!$cut) { throw new \UnexpectedValueException('the cut-time can not be empty.', -11306); } - if (!$this->ttCheck($cut)) - { + if (!$this->ttCheck($cut)) { throw new \UnexpectedValueException('the format of cut-time is incorrect.', -11307); } $values['cut'] = $this->ttHandle($cut); @@ -147,26 +136,21 @@ public function show($project_key, $id) public function update(Request $request, $project_key, $issue_id, $id) { $worklog = Worklog::find($id); - if (!$worklog || $project_key != $worklog->project_key || $issue_id != $worklog->issue_id) - { + if (!$worklog || $project_key != $worklog->project_key || $issue_id != $worklog->issue_id) { throw new \UnexpectedValueException('the worklog does not exist or is not in the issue or is not in the project.', -11309); } - if (!$this->isPermissionAllowed($project_key, 'edit_worklog') && !($worklog->recorder['id'] == $this->user->id && $this->isPermissionAllowed($project_key, 'edit_self_worklog'))) - { + if (!$this->isPermissionAllowed($project_key, 'edit_worklog') && !($worklog->recorder['id'] == $this->user->id && $this->isPermissionAllowed($project_key, 'edit_self_worklog'))) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } $values = []; $spend = $request->input('spend'); - if (isset($spend)) - { - if (!$spend) - { + if (isset($spend)) { + if (!$spend) { throw new \UnexpectedValueException('the spend-time can not be empty.', -11300); } - if (!$this->ttCheck($spend)) - { + if (!$this->ttCheck($spend)) { throw new \UnexpectedValueException('the format of spend-time is incorrect.', -11301); } $values['spend'] = $this->ttHandle($spend); @@ -174,48 +158,37 @@ public function update(Request $request, $project_key, $issue_id, $id) } $started_at = $request->input('started_at'); - if (isset($started_at)) - { - if (!$started_at) - { + if (isset($started_at)) { + if (!$started_at) { throw new \UnexpectedValueException('the start time can not be empty.', -11302); } $values['started_at'] = $started_at; } $adjust_type = $request->input('adjust_type'); - if (isset($adjust_type)) - { - if (!in_array($adjust_type, ['1', '2', '3', '4'])) - { + if (isset($adjust_type)) { + if (!in_array($adjust_type, ['1', '2', '3', '4'])) { throw new \UnexpectedValueException('the adjust-type value is incorrect.', -11303); } $values['adjust_type'] = $adjust_type; - if ($adjust_type == '3') - { + if ($adjust_type == '3') { $leave_estimate = $request->input('leave_estimate'); - if (!$leave_estimate) - { + if (!$leave_estimate) { throw new \UnexpectedValueException('the leave-estimate-time can not be empty.', -11304); } - if (!$this->ttCheck($leave_estimate)) - { + if (!$this->ttCheck($leave_estimate)) { throw new \UnexpectedValueException('the format of leave-estimate-time is incorrect.', -11305); } $values['leave_estimate'] = $this->ttHandle($leave_estimate); $values['leave_estimate_m'] = $this->ttHandleInM($values['leave_estimate']); - } - else if ($adjust_type == '4') - { + } elseif ($adjust_type == '4') { $cut = $request->input('cut'); - if (!$cut) - { + if (!$cut) { throw new \UnexpectedValueException('the cut-time can not be empty.', -11306); } - if (!$this->ttCheck($cut)) - { + if (!$this->ttCheck($cut)) { throw new \UnexpectedValueException('the format of cut-time is incorrect.', -11307); } $values['cut'] = $this->ttHandle($cut); @@ -224,13 +197,12 @@ public function update(Request $request, $project_key, $issue_id, $id) } $comments = $request->input('comments'); - if (isset($comments)) - { + if (isset($comments)) { $values['comments'] = $comments ?: ''; } $worklog->fill([ 'edited_flag' => 1 ] + array_except($values, [ 'recorder', 'recorded_at' ]))->save(); - // trigger event of worklog edited + // trigger event of worklog edited $worklog = Worklog::find($id); $cur_user = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; Event::fire(new IssueEvent($project_key, $issue_id, $cur_user, [ 'event_key' => 'edit_worklog', 'data' => $worklog->toArray() ])); @@ -247,19 +219,17 @@ public function update(Request $request, $project_key, $issue_id, $id) public function destroy($project_key, $issue_id, $id) { $worklog = Worklog::find($id); - if (!$worklog || $project_key != $worklog->project_key || $issue_id != $worklog->issue_id) - { + if (!$worklog || $project_key != $worklog->project_key || $issue_id != $worklog->issue_id) { throw new \UnexpectedValueException('the worklog does not exist or is not in the issue or is not in the project.', -11309); } - if (!$this->isPermissionAllowed($project_key, 'delete_worklog') && !($worklog->recorder['id'] == $this->user->id && $this->isPermissionAllowed($project_key, 'delete_self_worklog'))) - { + if (!$this->isPermissionAllowed($project_key, 'delete_worklog') && !($worklog->recorder['id'] == $this->user->id && $this->isPermissionAllowed($project_key, 'delete_self_worklog'))) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } Worklog::destroy($id); - // trigger event of worklog deleted + // trigger event of worklog deleted $cur_user = [ 'id' => $this->user->id, 'name' => $this->user->first_name, 'email' => $this->user->email ]; Event::fire(new IssueEvent($project_key, $issue_id, $cur_user, [ 'event_key' => 'del_worklog', 'data' => $worklog->toArray() ])); diff --git a/app/Http/Middleware/AccessLogs.php b/app/Http/Middleware/AccessLogs.php index 11be062b4..39d345a88 100644 --- a/app/Http/Middleware/AccessLogs.php +++ b/app/Http/Middleware/AccessLogs.php @@ -8,7 +8,7 @@ use Sentinel; use App\System\Eloquent\ApiAccessLogs; -class AccessLogs +class AccessLogs { /** * Handle an incoming request. @@ -19,45 +19,41 @@ class AccessLogs */ public function handle($request, Closure $next) { - $start_at = floor(microtime(true) * 1000); + $start_at = floor(microtime(true) * 1000); $response = $next($request); - $current_at = floor(microtime(true) * 1000); - $user = Sentinel::getUser(); - if (!$user) - { + $current_at = floor(microtime(true) * 1000); + $user = Sentinel::getUser(); + if (!$user) { return $response; } $request_method = $request->method(); - $request_url = $request->getRequestUri(); + $request_url = $request->getRequestUri(); $module = $project_key = ''; $matches = []; - if (preg_match("/^\/api\/project\/([^\/]+)\/([^\/\?]+)(.*)/i", $request_url, $matches)) - { - $project_key = $matches[1]; - $module = $matches[2]; - } - else if ($request_method == 'POST' && strpos($request_url, '/api/session') !== false) - { + if (preg_match("/^\/api\/project\/([^\/]+)\/([^\/\?]+)(.*)/i", $request_url, $matches)) { + $project_key = $matches[1]; + $module = $matches[2]; + } elseif ($request_method == 'POST' && strpos($request_url, '/api/session') !== false) { $module = 'login'; } - ApiAccessLogs::create([ - 'user' => [ 'id' => $user->id, 'name' => $user->first_name, 'email' => $user->email ], - 'project_key' => $project_key, - 'module' => $module, - 'requested_start_at' => $start_at, - 'requested_end_at' => $current_at, - 'exec_time' => $current_at - $start_at, - 'request_source_ip' => $request->ip(), - 'request_url' => $request_url, - 'request_user_agent' => $request->header('USER_AGENT'), - 'request_method' => $request_method, - 'request_body' => in_array($request_method, [ 'PUT', 'POST' ]) ? array_except($request->all(), [ 'password', 'new_password', 'token', 'pwd', 'admin_password' ]) : [], - 'response_status' => $response->getstatusCode(), - ]); + ApiAccessLogs::create([ + 'user' => [ 'id' => $user->id, 'name' => $user->first_name, 'email' => $user->email ], + 'project_key' => $project_key, + 'module' => $module, + 'requested_start_at' => $start_at, + 'requested_end_at' => $current_at, + 'exec_time' => $current_at - $start_at, + 'request_source_ip' => $request->ip(), + 'request_url' => $request_url, + 'request_user_agent' => $request->header('USER_AGENT'), + 'request_method' => $request_method, + 'request_body' => in_array($request_method, [ 'PUT', 'POST' ]) ? array_except($request->all(), [ 'password', 'new_password', 'token', 'pwd', 'admin_password' ]) : [], + 'response_status' => $response->getstatusCode(), + ]); return $response; } diff --git a/app/Http/Middleware/ArrangeResponseData.php b/app/Http/Middleware/ArrangeResponseData.php index b1debc572..5fe7222ff 100644 --- a/app/Http/Middleware/ArrangeResponseData.php +++ b/app/Http/Middleware/ArrangeResponseData.php @@ -7,7 +7,7 @@ use MongoDB\BSON\ObjectID; -class ArrangeResponseData +class ArrangeResponseData { /** * Handle an incoming request. @@ -20,8 +20,7 @@ public function handle($request, Closure $next) { $response = $next($request); - if ($response instanceof JsonResponse) - { + if ($response instanceof JsonResponse) { $old_data = $response->getData(true); $new_data = $this->arrange($old_data); $response->setData($new_data); @@ -38,22 +37,18 @@ public function handle($request, Closure $next) */ public function arrange($data) { - if (!is_array($data)) - { + if (!is_array($data)) { return $data; } - if (array_key_exists('_id', $data)) - { + if (array_key_exists('_id', $data)) { $data['id'] = $data['_id'] instanceof ObjectID ? $data['_id']->__toString() : $data['_id']; unset($data['_id']); } - foreach ($data as $k => $val) - { + foreach ($data as $k => $val) { $data[$k] = $this->arrange($val); } return $data; } - } diff --git a/app/Http/Middleware/Authorize.php b/app/Http/Middleware/Authorize.php index 345d90a74..9b10c6a67 100644 --- a/app/Http/Middleware/Authorize.php +++ b/app/Http/Middleware/Authorize.php @@ -7,7 +7,7 @@ use Closure; use Sentinel; -class Authorize +class Authorize { /** * Handle an incoming request. @@ -19,13 +19,11 @@ class Authorize public function handle($request, Closure $next) { $setting = SysSetting::first(); - if (!($setting && isset($setting->properties) && isset($setting->properties['enable_login_protection']) && $setting->properties['enable_login_protection'] === 1)) - { + if (!($setting && isset($setting->properties) && isset($setting->properties['enable_login_protection']) && $setting->properties['enable_login_protection'] === 1)) { Sentinel::removeCheckpoint('throttle'); } - if (! $user = Sentinel::check()) - { + if (! $user = Sentinel::check()) { return Response()->json([ 'ecode' => -10001, 'data' => '' ]); } return $next($request); diff --git a/app/Http/Middleware/Privilege.php b/app/Http/Middleware/Privilege.php index e27fe7fab..80f50e46f 100644 --- a/app/Http/Middleware/Privilege.php +++ b/app/Http/Middleware/Privilege.php @@ -20,28 +20,20 @@ class Privilege public function handle($request, Closure $next, $permission) { // global permission check - if ($permission === 'sys_admin') - { - if (! $this->globalCheck('sys_admin')) - { + if ($permission === 'sys_admin') { + if (! $this->globalCheck('sys_admin')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } - } - else if ($permission === 'view_project') - { - if ($request->isMethod('get')) - { - if (! $this->projectCheck($request, 'view_project')) - { + } elseif ($permission === 'view_project') { + if ($request->isMethod('get')) { + if (! $this->projectCheck($request, 'view_project')) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } } } // project permission check - else - { - if (! $this->projectCheck($request, $permission)) - { + else { + if (! $this->projectCheck($request, $permission)) { return Response()->json(['ecode' => -10002, 'emsg' => 'permission denied.']); } } @@ -90,24 +82,19 @@ public function projectCheck($request, $permission) $user = Sentinel::getUser(); $project_key = $request->project_key; - if ($project_key === '$_sys_$') - { + if ($project_key === '$_sys_$') { return $user->hasAccess([ 'sys_admin' ]); } $isAllowed = Acl::isAllowed($user->id, $permission, $project_key); - if (!$isAllowed) - { - if ($permission === 'manage_project' || $permission === 'view_project') - { - if ($user->email === 'admin@action.view') - { - return true; + if (!$isAllowed) { + if ($permission === 'manage_project' || $permission === 'view_project') { + if ($user->email === 'admin@action.view') { + return true; } $project = Project::where('key', $project_key)->first(); - if ($project && isset($project->principal) && isset($project->principal['id']) && $project->principal['id'] === $user->id) - { + if ($project && isset($project->principal) && isset($project->principal['id']) && $project->principal['id'] === $user->id) { return true; } } diff --git a/app/Http/Middleware/TrimStrings.php b/app/Http/Middleware/TrimStrings.php index 89eaaaae7..e1bb30aa2 100644 --- a/app/Http/Middleware/TrimStrings.php +++ b/app/Http/Middleware/TrimStrings.php @@ -5,7 +5,7 @@ use Illuminate\Http\JsonResponse; use Closure; -class TrimStrings +class TrimStrings { /** * Handle an incoming request. @@ -17,10 +17,8 @@ class TrimStrings public function handle($request, Closure $next) { $params = $request->all(); - foreach ($params as $k => $v) - { - if (is_string($v)) - { + foreach ($params as $k => $v) { + if (is_string($v)) { $request->offsetSet($k, trim($v)); } } diff --git a/app/Http/routes.php b/app/Http/routes.php index f9dae69d3..c8a2fadda 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -135,9 +135,9 @@ }); Route::group([ 'prefix' => $api_prefix . '/project/{project_key}', 'middleware' => [ 'can', 'privilege:view_project' ] ], function () { - // project summary + // project summary Route::get('summary', 'SummaryController@index'); - // config summary + // config summary Route::get('config', 'ConfigController@index'); // project activity Route::get('activity', 'ActivityController@index'); @@ -150,7 +150,7 @@ Route::post('version/{id}/release', 'VersionController@release'); Route::post('version/{id}/delete', 'VersionController@delete'); Route::resource('version', 'VersionController'); - // project report + // project report Route::get('report/index', 'ReportController@index'); Route::get('report/trend', 'ReportController@getTrends'); Route::get('report/worklog', 'ReportController@getWorklogs'); @@ -165,7 +165,7 @@ Route::post('report/{mode}/filter', 'ReportController@saveFilter'); // project team Route::get('team', 'RoleController@index'); - // preview the workflow chart + // preview the workflow chart Route::get('workflow/{id}/preview', 'WorkflowController@preview'); Route::get('issue/options', 'IssueController@getOptions'); diff --git a/app/Listeners/ActivityAddListener.php b/app/Listeners/ActivityAddListener.php index 3014b7106..1e6b4ceed 100644 --- a/app/Listeners/ActivityAddListener.php +++ b/app/Listeners/ActivityAddListener.php @@ -19,7 +19,7 @@ use DB; -class ActivityAddListener +class ActivityAddListener { /** * Create the event listener. @@ -40,26 +40,18 @@ public function handle(Event $event) { // this activity_id is used for notice - if ($event instanceof FileUploadEvent) - { + if ($event instanceof FileUploadEvent) { $activity_id = $this->addFileActivity($event->project_key, $event->issue_id, $event->user, $event->file_id, 'add_file'); $this->putMQ($event->project_key, $activity_id); - } - else if ($event instanceof FileDelEvent) - { + } elseif ($event instanceof FileDelEvent) { $activity_id = $this->addFileActivity($event->project_key, $event->issue_id, $event->user, $event->file_id, 'del_file'); $this->putMQ($event->project_key, $activity_id); - } - else if ($event instanceof IssueEvent) - { + } elseif ($event instanceof IssueEvent) { $activity_id = $this->addIssueActivity($event->project_key, $event->issue_id, $event->user, $event->param); $this->putMQ($event->project_key, $activity_id); - } - else if ($event instanceof VersionEvent || $event instanceof SprintEvent || $event instanceof WikiEvent) - { + } elseif ($event instanceof VersionEvent || $event instanceof SprintEvent || $event instanceof WikiEvent) { $activity_id = $this->addProjectActivity($event->project_key, $event->user, $event->param); - if (isset($event->param['isSendMsg']) && $event->param['isSendMsg']) - { + if (isset($event->param['isSendMsg']) && $event->param['isSendMsg']) { $this->putMQ($event->project_key, $activity_id); } } @@ -78,8 +70,7 @@ public function handle(Event $event) public function addFileActivity($project_key, $issue_id, $user, $file_id, $event_key) { $file_info = File::find($file_id); - if (!$file_info || $file_info->del_flg == 1) - { + if (!$file_info || $file_info->del_flg == 1) { return; } @@ -116,38 +107,30 @@ public function addIssueActivity($project_key, $issue_id, $user, $param) { $info = []; - if (isset($param['snap_id']) && $param['snap_id']) - { - $diff_items = []; $diff_keys = []; + if (isset($param['snap_id']) && $param['snap_id']) { + $diff_items = []; + $diff_keys = []; $snaps = DB::collection('issue_his_' . $project_key)->where('issue_id', $issue_id)->orderBy('_id', 'desc')->get(); - foreach ($snaps as $i => $snap) - { - if ($snap['_id']->__toString() != $param['snap_id']) - { + foreach ($snaps as $i => $snap) { + if ($snap['_id']->__toString() != $param['snap_id']) { continue; } $after_data = $snap['data']; $before_data = $snaps[$i + 1]['data']; - foreach ($after_data as $key => $val) - { - if (!isset($before_data[$key]) || $val !== $before_data[$key]) - { + foreach ($after_data as $key => $val) { + if (!isset($before_data[$key]) || $val !== $before_data[$key]) { $tmp = []; $tmp['field'] = isset($val['name']) ? $val['name'] : ''; $tmp['after_value'] = isset($val['value']) ? $val['value'] : ''; $tmp['before_value'] = isset($before_data[$key]) && isset($before_data[$key]['value']) ? $before_data[$key]['value'] : ''; - if (is_array($tmp['after_value']) && is_array($tmp['before_value'])) - { + if (is_array($tmp['after_value']) && is_array($tmp['before_value'])) { $diff1 = array_diff($tmp['after_value'], $tmp['before_value']); $tmp['after_value'] = implode(',', $diff1); - } - else - { - if (is_array($tmp['after_value'])) - { + } else { + if (is_array($tmp['after_value'])) { $tmp['after_value'] = implode(',', $tmp['after_value']); } } @@ -156,27 +139,20 @@ public function addIssueActivity($project_key, $issue_id, $user, $param) } } - foreach ($before_data as $key => $val) - { - if (array_search($key, $diff_keys) !== false) - { + foreach ($before_data as $key => $val) { + if (array_search($key, $diff_keys) !== false) { continue; } - if (!isset($after_data[$key]) || $val !== $after_data[$key]) - { + if (!isset($after_data[$key]) || $val !== $after_data[$key]) { $tmp = []; $tmp['field'] = isset($val['name']) ? $val['name'] : ''; $tmp['before_value'] = isset($val['value']) ? $val['value'] : ''; $tmp['after_value'] = isset($after_data[$key]) && isset($after_data[$key]['value']) ? $after_data[$key]['value'] : ''; - if (is_array($tmp['after_value']) && is_array($tmp['before_value'])) - { + if (is_array($tmp['after_value']) && is_array($tmp['before_value'])) { $diff1 = array_diff($tmp['after_value'], $tmp['before_value']); $tmp['after_value'] = implode(',', $diff1); - } - else - { - if (is_array($tmp['after_value'])) - { + } else { + if (is_array($tmp['after_value'])) { $tmp['after_value'] = implode(',', $tmp['after_value']); } } @@ -185,15 +161,12 @@ public function addIssueActivity($project_key, $issue_id, $user, $param) } break; } - if ($diff_items) - { + if ($diff_items) { // insert activity into db. $info = [ 'issue_id' => $issue_id, 'event_key' => $param['event_key'], 'user' => $user, 'data' => $diff_items, 'created_at' => time() ]; return DB::collection('activity_' . $project_key)->insertGetId($info); } - } - else - { + } else { $info = [ 'issue_id' => $issue_id, 'event_key' => $param['event_key'], 'user' => $user, 'data' => isset($param['data']) ? $param['data'] : '', 'created_at' => time() ]; return DB::collection('activity_' . $project_key)->insertGetId($info); } @@ -209,8 +182,7 @@ public function addIssueActivity($project_key, $issue_id, $user, $param) */ public function putMQ($project_key, $activity_id) { - if (!$activity_id) - { + if (!$activity_id) { return; } $info = [ 'project_key' => $project_key, 'activity_id' => $activity_id->__toString(), 'flag' => 0, 'created_at' => time() ]; diff --git a/app/Listeners/FieldConfigChangeListener.php b/app/Listeners/FieldConfigChangeListener.php index f2cc9f01c..f17e6e618 100644 --- a/app/Listeners/FieldConfigChangeListener.php +++ b/app/Listeners/FieldConfigChangeListener.php @@ -37,12 +37,9 @@ public function __construct() */ public function handle(Event $event) { - if ($event instanceof FieldChangeEvent) - { + if ($event instanceof FieldChangeEvent) { $this->updateSchema($event->field_id, 1); - } - else if ($event instanceof FieldDeleteEvent) - { + } elseif ($event instanceof FieldDeleteEvent) { $this->updateSchema($event->field_id, 2); $this->updateDisplayColumns($event->project_key, $event->field_key); $this->updateKanbanDisplayFields($event->project_key, $event->field_key); @@ -60,25 +57,21 @@ public function handle(Event $event) public function updateSchema($field_id, $flag) { $screens = Screen::whereRaw([ 'field_ids' => $field_id ])->get([ 'schema' ]); - foreach ($screens as $screen) - { + foreach ($screens as $screen) { $new_schema = []; - foreach ($screen->schema as $field) - { - if ($field['_id'] != $field_id) - { + foreach ($screen->schema as $field) { + if ($field['_id'] != $field_id) { $new_schema[] = $field; continue; } - if ($flag == 1) - { + if ($flag == 1) { $new_field = Field::Find($field_id, ['name', 'key', 'type', 'applyToTypes', 'defaultValue', 'optionValues', 'minValue', 'maxValue', 'maxLength'])->toArray(); - if (isset($field['required']) && $field['required']) - { + if (isset($field['required']) && $field['required']) { $new_field['required'] = true; } - $new_schema[] = $new_field;; + $new_schema[] = $new_field; + ; } } $screen->schema = $new_schema; @@ -97,33 +90,23 @@ public function updateSchema($field_id, $flag) public function unsetIssueVal($project_key, $field_key, $field_type) { $res = []; - if ($project_key === '$_sys_$') - { + if ($project_key === '$_sys_$') { $projects = Project::all(); - foreach($projects as $project) - { + foreach ($projects as $project) { DB::collection('issue_' . $project->key)->whereRaw([ $field_key => [ '$exists' => 1 ] ])->unset($field_key); - if ($field_type === 'MultiUser') - { + if ($field_type === 'MultiUser') { DB::collection('issue_' . $project->key)->whereRaw([ $field_key . '_ids' => [ '$exists' => 1 ] ])->unset($field_key . '_ids'); - } - else if ($field_type === 'TimeTracking') - { + } elseif ($field_type === 'TimeTracking') { DB::collection('issue_' . $project->key)->whereRaw([ $field_key . '_m' => [ '$exists' => 1 ] ])->unset($field_key . '_m'); } } - } - else - { + } else { DB::collection('issue_' . $project_key)->whereRaw([ $field_key => [ '$exists' => 1 ] ])->unset($field_key); - if ($field_type === 'MultiUser') - { + if ($field_type === 'MultiUser') { DB::collection('issue_' . $project_key)->whereRaw([ $field_key . '_ids' => [ '$exists' => 1 ] ])->unset($field_key . '_ids'); - } - else if ($field_type === 'TimeTracking') - { + } elseif ($field_type === 'TimeTracking') { DB::collection('issue_' . $project_key)->whereRaw([ $field_key . '_m' => [ '$exists' => 1 ] ])->unset($field_key . '_m'); } } @@ -139,22 +122,16 @@ public function unsetIssueVal($project_key, $field_key, $field_type) public function updateKanbanDisplayFields($project_key, $field_key) { $res = []; - if ($project_key === '$_sys_$') - { + if ($project_key === '$_sys_$') { $res = Board::whereRaw([ 'display_fields' => $field_key ])->get(); - } - else - { + } else { $res = Board::whereRaw([ 'display_fields' => $field_key, 'project_key' => $project_key ])->get(); } - foreach ($res as $value) - { + foreach ($res as $value) { $new_fields = []; $display_fields = isset($value->display_fields) ? $value->display_fields : []; - foreach ($display_fields as $val) - { - if ($val === $field_key) - { + foreach ($display_fields as $val) { + if ($val === $field_key) { continue; } @@ -176,23 +153,17 @@ public function updateKanbanDisplayFields($project_key, $field_key) public function updateDisplayColumns($project_key, $field_key) { $res = []; - if ($project_key === '$_sys_$') - { + if ($project_key === '$_sys_$') { $res = UserIssueListColumns::whereRaw([ 'column_keys' => $field_key ])->get(); - } - else - { + } else { $res = UserIssueListColumns::whereRaw([ 'column_keys' => $field_key, 'project_key' => $project_key ])->get(); } - foreach ($res as $value) - { + foreach ($res as $value) { $new_columns = []; $column_keys = []; $columns = isset($value->columns) ? $value->columns : []; - foreach ($columns as $column) - { - if ($column['key'] === $field_key) - { + foreach ($columns as $column) { + if ($column['key'] === $field_key) { continue; } @@ -205,23 +176,17 @@ public function updateDisplayColumns($project_key, $field_key) $value->save(); } - if ($project_key === '$_sys_$') - { + if ($project_key === '$_sys_$') { $res = ProjectIssueListColumns::whereRaw([ 'column_keys' => $field_key ])->get(); - } - else - { + } else { $res = ProjectIssueListColumns::whereRaw([ 'column_keys' => $field_key, 'project_key' => $project_key ])->get(); } - foreach ($res as $value) - { + foreach ($res as $value) { $new_columns = []; $column_keys = []; $columns = isset($value->columns) ? $value->columns : []; - foreach ($columns as $column) - { - if ($column['key'] === $field_key) - { + foreach ($columns as $column) { + if ($column['key'] === $field_key) { continue; } diff --git a/app/Listeners/FileChangeListener.php b/app/Listeners/FileChangeListener.php index 9a4559f53..02a32e359 100644 --- a/app/Listeners/FileChangeListener.php +++ b/app/Listeners/FileChangeListener.php @@ -11,7 +11,7 @@ use DB; -class FileChangeListener +class FileChangeListener { /** * Create the event listener. @@ -30,12 +30,9 @@ public function __construct() */ public function handle(Event $event) { - if ($event instanceof FileUploadEvent) - { + if ($event instanceof FileUploadEvent) { $this->updIssueField($event->project_key, $event->issue_id, $event->field_key, $event->file_id, $event->user, 1); - } - else if ($event instanceof FileDelEvent) - { + } elseif ($event instanceof FileDelEvent) { $this->updIssueField($event->project_key, $event->issue_id, $event->field_key, $event->file_id, $event->user, 2); } } @@ -54,23 +51,16 @@ public function updIssueField($project_key, $issue_id, $field_key, $file_id, $us $table = 'issue_' . $project_key; $issue = DB::collection($table)->where('_id', $issue_id)->first(); - if (!isset($issue[$field_key]) || !is_array($issue[$field_key])) - { + if (!isset($issue[$field_key]) || !is_array($issue[$field_key])) { $issue[$field_key] = []; } - if ($flag == 1) - { + if ($flag == 1) { array_push($issue[$field_key], $file_id); - } - else - { + } else { $index = array_search($file_id, $issue[$field_key]); - if ($index !== false) - { + if ($index !== false) { array_splice($issue[$field_key], $index, 1); - } - else - { + } else { return; } } diff --git a/app/Listeners/GroupDelListener.php b/app/Listeners/GroupDelListener.php index 7286e90ab..9b353bf73 100644 --- a/app/Listeners/GroupDelListener.php +++ b/app/Listeners/GroupDelListener.php @@ -11,7 +11,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -class GroupDelListener +class GroupDelListener { /** * Create the event listener. @@ -44,14 +44,11 @@ public function handle(Event $event) public function delGroupFromRole($group_id) { $roleactors = Roleactor::whereRaw([ 'group_ids' => $group_id ])->get([ 'group_ids', 'user_ids' ]); - foreach ($roleactors as $roleactor) - { + foreach ($roleactors as $roleactor) { $new_group_ids = []; $old_group_ids = isset($roleactor->group_ids) ? $roleactor->group_ids : []; - foreach ($old_group_ids as $gid) - { - if ($gid != $group_id) - { + foreach ($old_group_ids as $gid) { + if ($gid != $group_id) { $new_group_ids[] = $gid; } } @@ -70,8 +67,7 @@ public function delGroupFromRole($group_id) public function delGroupProject($group_id) { $links = UserGroupProject::where('ug_id', $group_id)->get(); - foreach ($links as $link) - { + foreach ($links as $link) { $link->delete(); } } diff --git a/app/Listeners/GroupRoleSetListener.php b/app/Listeners/GroupRoleSetListener.php index 27043d4ea..ac7e39098 100644 --- a/app/Listeners/GroupRoleSetListener.php +++ b/app/Listeners/GroupRoleSetListener.php @@ -10,7 +10,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -class GroupRoleSetListener +class GroupRoleSetListener { /** * Create the event listener. @@ -30,12 +30,9 @@ public function __construct() */ public function handle(Event $event) { - if ($event instanceof AddGroupToRoleEvent) - { + if ($event instanceof AddGroupToRoleEvent) { $this->linkGroupWithProject($event->group_ids, $event->project_key); - } - else if ($event instanceof DelGroupFromRoleEvent) - { + } elseif ($event instanceof DelGroupFromRoleEvent) { $this->unlinkGroupWithProject($event->group_ids, $event->project_key); } } @@ -49,15 +46,11 @@ public function handle(Event $event) */ public function linkGroupWithProject($group_ids, $project_key) { - foreach ($group_ids as $group_id) - { + foreach ($group_ids as $group_id) { $link = UserGroupProject::where('ug_id', $group_id)->where('project_key', $project_key)->first(); - if ($link) - { + if ($link) { $link->increment('link_count'); - } - else - { + } else { UserGroupProject::create([ 'ug_id' => $group_id, 'project_key' => $project_key, 'type' => 'group', 'link_count' => 1 ]); } } @@ -72,11 +65,9 @@ public function linkGroupWithProject($group_ids, $project_key) */ public function unlinkGroupWithProject($group_ids, $project_key) { - foreach ($group_ids as $group_id) - { + foreach ($group_ids as $group_id) { $link = UserGroupProject::where('ug_id', $group_id)->where('project_key', $project_key)->first(); - if ($link) - { + if ($link) { $link->decrement('link_count'); } } diff --git a/app/Listeners/NoticeAddListener.php b/app/Listeners/NoticeAddListener.php index 0c7333b58..8a9b71191 100644 --- a/app/Listeners/NoticeAddListener.php +++ b/app/Listeners/NoticeAddListener.php @@ -11,7 +11,7 @@ use DB; -class NoticeAddListener +class NoticeAddListener { /** * Create the event listener. @@ -32,16 +32,11 @@ public function handle(Event $event) { // this activity_id is used for notice - if ($event instanceof FileUploadEvent) - { + if ($event instanceof FileUploadEvent) { $this->putMQ($event->project_key, $event->issue_id, $event->user, [ 'event_key' => 'add_file', 'data' => $event->file_id ]); - } - else if ($event instanceof FileDelEvent) - { + } elseif ($event instanceof FileDelEvent) { $this->putMQ($event->project_key, $event->issue_id, $event->user, [ 'event_key' => 'add_file', 'data' => $event->file_id ]); - } - else if ($event instanceof IssueEvent) - { + } elseif ($event instanceof IssueEvent) { $this->putMQ($event->project_key, $event->issue_id, $event->user, $event->param); } } @@ -58,6 +53,6 @@ public function putMQ($project_key, $issue_id, $user, $param) { $info = [ 'project_key' => $project_key, 'issue_id' => $issue_id, 'event_key' => $param['event_key'], 'user' => $user, 'data' => isset($param['data']) ? $param['data'] : '', 'created_at' => time() ]; - DB::collection('mq')->insert($info); + DB::collection('mq')->insert($info); } } diff --git a/app/Listeners/PropertyConfigChangeListener.php b/app/Listeners/PropertyConfigChangeListener.php index 53aec9e03..93c9edfda 100644 --- a/app/Listeners/PropertyConfigChangeListener.php +++ b/app/Listeners/PropertyConfigChangeListener.php @@ -1,6 +1,7 @@ updateField('resolution', $event->project_key); - } - else if ($event instanceof PriorityConfigChangeEvent) - { + } elseif ($event instanceof PriorityConfigChangeEvent) { $this->updateField('priority', $event->project_key); } } @@ -48,35 +46,28 @@ public function handle(Event $event) * update the field. * * @param string $field_key - * @param string $project_key + * @param string $project_key * @return void */ public function updateField($field_key, $project_key) { $field = Field::whereRaw([ 'key' => $field_key, 'project_key' => $project_key ])->first(); - if (!$field) - { + if (!$field) { return; } // get resolution or priority list for optionValues and defaultValue - $optionValues = []; $defalutValue = ''; - if ($field_key == 'resolution') - { + $optionValues = []; + $defalutValue = ''; + if ($field_key == 'resolution') { $properties = Resolution::whereRaw([ 'project_key' => $project_key ])->orderBy('sn', 'asc')->get(); - } - else if ($field_key == 'priority') - { + } elseif ($field_key == 'priority') { $properties = Priority::whereRaw([ 'project_key' => $project_key ])->orderBy('sn', 'asc')->get(); - } - else - { + } else { return; } - foreach ($properties as $property) - { + foreach ($properties as $property) { $optionValues[] = [ 'id' => $property->id, 'name' => $property->name ]; - if ($property->default) - { + if ($property->default) { $defaultValue = $property->id; } } diff --git a/app/Listeners/UserDelListener.php b/app/Listeners/UserDelListener.php index 0c5cc2356..858b67250 100644 --- a/app/Listeners/UserDelListener.php +++ b/app/Listeners/UserDelListener.php @@ -2,15 +2,12 @@ namespace App\Listeners; -use App\Events\Event; -use App\Acl\Eloquent\Roleactor; use App\Acl\Eloquent\Group; +use App\Acl\Eloquent\Roleactor; +use App\Events\Event; use App\Project\Eloquent\UserGroupProject; -use Illuminate\Queue\InteractsWithQueue; -use Illuminate\Contracts\Queue\ShouldQueue; - -class UserDelListener +class UserDelListener { /** * Create the event listener. @@ -43,15 +40,12 @@ public function handle(Event $event) */ public function delUserFromRole($user_id) { - $roleactors = Roleactor::whereRaw([ 'user_ids' => $user_id ])->get([ 'user_ids', 'group_ids' ]); - foreach ($roleactors as $roleactor) - { + $roleactors = Roleactor::whereRaw(['user_ids' => $user_id])->get(['user_ids', 'group_ids']); + foreach ($roleactors as $roleactor) { $new_user_ids = []; $old_user_ids = isset($roleactor->user_ids) ? $roleactor->user_ids : []; - foreach ($old_user_ids as $uid) - { - if ($uid != $user_id) - { + foreach ($old_user_ids as $uid) { + if ($uid != $user_id) { $new_user_ids[] = $uid; } } @@ -62,27 +56,24 @@ public function delUserFromRole($user_id) } /** - * del user from group + * del user from group * * @param string $user_id * @return void */ public function delUserFromGroup($user_id) { - $groups = Group::whereRaw([ 'user_ids' => $user_id ])->get([ 'user_ids' ]); - foreach ($groups as $group) - { - $new_user_ids = []; - $old_user_ids = isset($group->user_ids) ? $group->user_ids : []; - foreach ($old_user_ids as $uid) - { - if ($uid != $user_id) - { - $new_user_ids[] = $uid; - } - } - $group->user_ids = $new_user_ids; - $group->save(); + $groups = Group::whereRaw(['user_ids' => $user_id])->get(['user_ids']); + foreach ($groups as $group) { + $new_user_ids = []; + $old_user_ids = isset($group->user_ids) ? $group->user_ids : []; + foreach ($old_user_ids as $uid) { + if ($uid != $user_id) { + $new_user_ids[] = $uid; + } + } + $group->user_ids = $new_user_ids; + $group->save(); } } @@ -94,9 +85,8 @@ public function delUserFromGroup($user_id) */ public function delUserProject($user_id) { - $links = UserGroupProject::where('ug_id', $user_id)->get([ 'user_id' ]); - foreach ($links as $link) - { + $links = UserGroupProject::where('ug_id', $user_id)->get(['user_id']); + foreach ($links as $link) { $link->delete(); } } diff --git a/app/Listeners/UserRoleSetListener.php b/app/Listeners/UserRoleSetListener.php index 63627ba63..c94ed5f4f 100644 --- a/app/Listeners/UserRoleSetListener.php +++ b/app/Listeners/UserRoleSetListener.php @@ -10,7 +10,7 @@ use Illuminate\Queue\InteractsWithQueue; use Illuminate\Contracts\Queue\ShouldQueue; -class UserRoleSetListener +class UserRoleSetListener { /** * Create the event listener. @@ -30,12 +30,9 @@ public function __construct() */ public function handle(Event $event) { - if ($event instanceof AddUserToRoleEvent) - { + if ($event instanceof AddUserToRoleEvent) { $this->linkUserWithProject($event->user_ids, $event->project_key); - } - else if ($event instanceof DelUserFromRoleEvent) - { + } elseif ($event instanceof DelUserFromRoleEvent) { $this->unlinkUserWithProject($event->user_ids, $event->project_key); } } @@ -49,15 +46,11 @@ public function handle(Event $event) */ public function linkUserWithProject($user_ids, $project_key) { - foreach ($user_ids as $user_id) - { + foreach ($user_ids as $user_id) { $link = UserGroupProject::where('ug_id', $user_id)->where('project_key', $project_key)->first(); - if ($link) - { + if ($link) { $link->increment('link_count'); - } - else - { + } else { UserGroupProject::create([ 'ug_id' => $user_id, 'project_key' => $project_key, 'type' => 'user', 'link_count' => 1 ]); } } @@ -72,11 +65,9 @@ public function linkUserWithProject($user_ids, $project_key) */ public function unlinkUserWithProject($user_ids, $project_key) { - foreach ($user_ids as $user_id) - { + foreach ($user_ids as $user_id) { $link = UserGroupProject::where('ug_id', $user_id)->where('project_key', $project_key)->first(); - if ($link) - { + if ($link) { $link->decrement('link_count'); } } diff --git a/app/Listeners/WebhooksRequestListener.php b/app/Listeners/WebhooksRequestListener.php index 0da0c31d6..5e5b9ca26 100644 --- a/app/Listeners/WebhooksRequestListener.php +++ b/app/Listeners/WebhooksRequestListener.php @@ -1,5 +1,6 @@ project_key; $webhooks = Webhooks::where('project_key', $project_key)->where('status', 'enabled')->get(); - foreach ($webhooks as $webhook) - { + foreach ($webhooks as $webhook) { $events = isset($webhook->events) && $webhook->events ? $webhook->events : []; - if (in_array($event_key, $events) && $webhook->request_url) - { + if (in_array($event_key, $events) && $webhook->request_url) { $this->push2WebhookEvents($event, $webhook->request_url, $webhook->token ?: ''); } } @@ -52,10 +51,8 @@ public function push2WebhookEvents(Event $event, $request_url, $token='') $project_key = $event->project_key; $user = $event->user; - if ($event instanceof IssueEvent) - { - if (!isset($event->issue_id)) - { + if ($event instanceof IssueEvent) { + if (!isset($event->issue_id)) { return; } @@ -65,18 +62,14 @@ public function push2WebhookEvents(Event $event, $request_url, $token='') $data['event'] = $event_key; unset($data['_id']); - if ($event_key == 'add_worklog' || $event_key == 'edit_worklog') - { + if ($event_key == 'add_worklog' || $event_key == 'edit_worklog') { $data['worklog'] = $event->param['data']; } $header = [ 'Content-Type: application/json', 'Expect:', 'X-Actionview-Token: ' . ($token ?: '') ]; CurlRequest::post($request_url, $header, $data, 1); - } - else if ($event instanceof VersionEvent) - { - if (!isset($event->param['data'])) - { + } elseif ($event instanceof VersionEvent) { + if (!isset($event->param['data'])) { return; } diff --git a/app/Project/Eloquent/Epic.php b/app/Project/Eloquent/Epic.php index 24f0cb6eb..ea60be495 100644 --- a/app/Project/Eloquent/Epic.php +++ b/app/Project/Eloquent/Epic.php @@ -1,6 +1,6 @@ where('user', $user_id) - ->first(); - if ($res) - { + ->first(); + if ($res) { $filters = isset($res->filters) ? $res->filters : []; } return $filters; @@ -95,9 +95,8 @@ public static function getIssueFilters($project_key, $user_id) */ public static function getDefaultDisplayColumns($project_key) { - $res = ProjectIssueListColumns::where('project_key', $project_key)->first(); - if ($res) - { + $res = ProjectIssueListColumns::where('project_key', $project_key)->first(); + if ($res) { $columns = isset($res->columns) ? $res->columns : []; return $columns; } @@ -123,9 +122,8 @@ public static function getIssueDisplayColumns($project_key, $user_id) $columns = self::getDefaultDisplayColumns($project_key); $res = UserIssueListColumns::where('project_key', $project_key) ->where('user', $user_id) - ->first(); - if ($res) - { + ->first(); + if ($res) { $columns = isset($res->columns) ? $res->columns : []; } return $columns; @@ -136,7 +134,7 @@ public static function getIssueDisplayColumns($project_key, $user_id) * * @param string $project_key * @param array $fields - * @return collection + * @return collection */ public static function getStateList($project_key, $fields=[]) { @@ -148,11 +146,9 @@ public static function getStateList($project_key, $fields=[]) ->toArray(); $stateProperty = StateProperty::Where('project_key', $project_key)->first(); - if ($stateProperty) - { - if ($sequence = $stateProperty->sequence) - { - $func = function($v1, $v2) use ($sequence) { + if ($stateProperty) { + if ($sequence = $stateProperty->sequence) { + $func = function ($v1, $v2) use ($sequence) { $i1 = array_search($v1['_id'], $sequence); $i1 = $i1 !== false ? $i1 : 998; $i2 = array_search($v2['_id'], $sequence); @@ -178,8 +174,7 @@ public static function getStateOptions($project_key) $states = self::getStateList($project_key); $options = []; - foreach ($states as $state) - { + foreach ($states as $state) { $tmp = []; $tmp['_id'] = isset($state['key']) && $state['key'] ? $state['key'] : $state['_id']; $tmp['name'] = isset($state['name']) ? trim($state['name']) : ''; @@ -203,8 +198,7 @@ public static function getLabelOptions($project_key) $labels = Labels::Where('project_key', $project_key) ->orderBy('_id', 'desc') ->get(); - foreach ($labels as $label) - { + foreach ($labels as $label) { $options[] = [ 'name' => $label->name, 'bgColor' => $label->bgColor ?: '' ]; } @@ -216,7 +210,7 @@ public static function getLabelOptions($project_key) * * @param string $project_key * @param array $fields - * @return collection + * @return collection */ public static function getEventList($project_key, $fields=[]) { @@ -237,13 +231,11 @@ public static function getEventList($project_key, $fields=[]) */ public static function getEventOptions($project_key) { - $events = self::getEventList($project_key); + $events = self::getEventList($project_key); $options = []; - foreach ($events as $event) - { - if (!isset($event->apply) || $event->apply !== 'workflow') - { + foreach ($events as $event) { + if (!isset($event->apply) || $event->apply !== 'workflow') { continue; } @@ -260,15 +252,13 @@ public static function getEventOptions($project_key) * get default priority. * * @param string $project_key - * @return string + * @return string */ public static function getDefaultPriority($project_key) { $priorityProperty = PriorityProperty::Where('project_key', $project_key)->first(); - if ($priorityProperty) - { - if ($defaultValue = $priorityProperty->defaultValue) - { + if ($priorityProperty) { + if ($defaultValue = $priorityProperty->defaultValue) { return $defaultValue; } } @@ -278,7 +268,7 @@ public static function getDefaultPriority($project_key) ->first(); $default = $priority && isset($priority->key) && $priority->key ? $priority->key : $priority->id; - return $default; + return $default; } /** @@ -298,11 +288,9 @@ public static function getPriorityList($project_key, $fields=[]) ->toArray(); $priorityProperty = PriorityProperty::Where('project_key', $project_key)->first(); - if ($priorityProperty) - { - if ($sequence = $priorityProperty->sequence) - { - $func = function($v1, $v2) use ($sequence) { + if ($priorityProperty) { + if ($sequence = $priorityProperty->sequence) { + $func = function ($v1, $v2) use ($sequence) { $i1 = array_search($v1['_id'], $sequence); $i1 = $i1 !== false ? $i1 : 998; $i2 = array_search($v2['_id'], $sequence); @@ -312,16 +300,11 @@ public static function getPriorityList($project_key, $fields=[]) usort($priorities, $func); } - if ($defaultValue = $priorityProperty->defaultValue) - { - foreach($priorities as $key => $val) - { - if ($val['_id'] == $defaultValue) - { + if ($defaultValue = $priorityProperty->defaultValue) { + foreach ($priorities as $key => $val) { + if ($val['_id'] == $defaultValue) { $priorities[$key]['default'] = true; - } - else if (isset($val['default'])) - { + } elseif (isset($val['default'])) { unset($priorities[$key]['default']); } } @@ -342,17 +325,14 @@ public static function getPriorityOptions($project_key) $priorities = self::getPriorityList($project_key); $options = []; - foreach ($priorities as $priority) - { + foreach ($priorities as $priority) { $tmp = []; $tmp['_id'] = isset($priority['key']) && $priority['key'] ? $priority['key'] : $priority['_id']; $tmp['name'] = isset($priority['name']) ? trim($priority['name']) : ''; - if (isset($priority['default'])) - { + if (isset($priority['default'])) { $tmp['default'] = $priority['default']; } - if (isset($priority['color'])) - { + if (isset($priority['color'])) { $tmp['color'] = $priority['color']; } $options[] = $tmp; @@ -364,15 +344,13 @@ public static function getPriorityOptions($project_key) * get default resolution. * * @param string $project_key - * @return string + * @return string */ public static function getDefaultResolution($project_key) { $resolutionProperty = ResolutionProperty::Where('project_key', $project_key)->first(); - if ($resolutionProperty) - { - if ($defaultValue = $resolutionProperty->defaultValue) - { + if ($resolutionProperty) { + if ($defaultValue = $resolutionProperty->defaultValue) { return $defaultValue; } } @@ -402,11 +380,9 @@ public static function getResolutionList($project_key, $fields=[]) ->toArray(); $resolutionProperty = ResolutionProperty::Where('project_key', $project_key)->first(); - if ($resolutionProperty) - { - if ($sequence = $resolutionProperty->sequence) - { - $func = function($v1, $v2) use ($sequence) { + if ($resolutionProperty) { + if ($sequence = $resolutionProperty->sequence) { + $func = function ($v1, $v2) use ($sequence) { $i1 = array_search($v1['_id'], $sequence); $i1 = $i1 !== false ? $i1 : 998; $i2 = array_search($v2['_id'], $sequence); @@ -416,16 +392,11 @@ public static function getResolutionList($project_key, $fields=[]) usort($resolutions, $func); } - if ($defaultValue = $resolutionProperty->defaultValue) - { - foreach($resolutions as $key => $val) - { - if ($val['_id'] == $defaultValue) - { + if ($defaultValue = $resolutionProperty->defaultValue) { + foreach ($resolutions as $key => $val) { + if ($val['_id'] == $defaultValue) { $resolutions[$key]['default'] = true; - } - else if (isset($val['default'])) - { + } elseif (isset($val['default'])) { unset($resolutions[$key]['default']); } } @@ -439,20 +410,18 @@ public static function getResolutionList($project_key, $fields=[]) * get resolution options. * * @param string $project_key - * @return array + * @return array */ public static function getResolutionOptions($project_key) { $resolutions = self::getResolutionList($project_key); $options = []; - foreach ($resolutions as $resolution) - { + foreach ($resolutions as $resolution) { $tmp = []; $tmp['_id'] = isset($resolution['key']) && $resolution['key'] ? $resolution['key'] : $resolution['_id']; $tmp['name'] = isset($resolution['name']) ? trim($resolution['name']) : ''; - if (isset($resolution['default'])) - { + if (isset($resolution['default'])) { $tmp['default'] = $resolution['default']; } $options[] = $tmp; @@ -563,23 +532,17 @@ public static function getUserList($project_key) $user_ids = []; $group_ids = []; - foreach ($user_group_ids as $value) - { - if (isset($value->type) && $value->type === 'group') - { + foreach ($user_group_ids as $value) { + if (isset($value->type) && $value->type === 'group') { $group_ids[] = $value->ug_id; - } - else - { + } else { $user_ids[] = $value->ug_id; } } - if ($group_ids) - { + if ($group_ids) { $groups = Group::find($group_ids); - foreach($groups as $group) - { + foreach ($groups as $group) { $user_ids = array_merge($user_ids, isset($group->users) && $group->users ? $group->users : []); } } @@ -587,10 +550,8 @@ public static function getUserList($project_key) $user_list = []; $users = EloquentUser::find($user_ids); - foreach ($users as $user) - { - if (isset($user->invalid_flag) && $user->invalid_flag === 1) - { + foreach ($users as $user) { + if (isset($user->invalid_flag) && $user->invalid_flag === 1) { continue; } $user_list[] = ['id' => $user->id, 'name' => $user->first_name, 'email' => $user->email ]; @@ -610,11 +571,9 @@ public static function getAssignedUsers($project_key) $user_ids = Acl::getUserIdsByPermission('assigned_issue', $project_key); $user_list = []; - $users = EloquentUser::find($user_ids); - foreach ($users as $user) - { - if (isset($user->invalid_flag) && $user->invalid_flag === 1) - { + $users = EloquentUser::find($user_ids); + foreach ($users as $user) { + if (isset($user->invalid_flag) && $user->invalid_flag === 1) { continue; } $user_list[] = [ 'id' => $user->id, 'name' => $user->first_name, 'email' => $user->email ]; @@ -661,7 +620,7 @@ public static function getModuleList($project_key, $fields=[]) * check if type has existed. * * @param string $project_key - * @param string $name + * @param string $name * @return bool */ public static function isTypeExisted($project_key, $name) @@ -677,7 +636,7 @@ public static function isTypeExisted($project_key, $name) * check if type abb has existed. * * @param string $project_key - * @param string $abb + * @param string $abb * @return bool */ public static function isTypeAbbExisted($project_key, $abb) @@ -693,7 +652,7 @@ public static function isTypeAbbExisted($project_key, $abb) * check if state has existed. * * @param string $project_key - * @param string $name + * @param string $name * @return bool */ public static function isStateExisted($project_key, $name) @@ -752,10 +711,8 @@ public static function isFieldKeyExisted($project_key, $key) $fields = Field::Where('project_key', '$_sys_$') ->orWhere('project_key', $project_key) ->get(); - foreach ($fields as $field) - { - if ($field->key === $key || ($field->type === 'MutiUser' && $field->key . '_ids' === $key) || ($field->type === 'TimeTracking' && $field->key . '_m' === $key)) - { + foreach ($fields as $field) { + if ($field->key === $key || ($field->type === 'MutiUser' && $field->key . '_ids' === $key) || ($field->type === 'TimeTracking' && $field->key . '_m' === $key)) { return true; } } @@ -781,22 +738,20 @@ public static function isEventExisted($project_key, $name) } /** - * get issue type schema + * get issue type schema * * @param string $project_key - * @return array + * @return array */ public static function getTypeListExt($project_key, $options) { $typeOptions = []; $types = self::getTypeList($project_key); - foreach ($types as $key => $type) - { - $schema = self::_repairSchema($project_key, $type->id, $type->screen && $type->screen->schema ? $type->screen->schema : [] , $options); + foreach ($types as $key => $type) { + $schema = self::_repairSchema($project_key, $type->id, $type->screen && $type->screen->schema ? $type->screen->schema : [], $options); $tmp = [ 'id' => $type->id, 'name' => $type->name, 'abb' => $type->abb, 'disabled' => $type->disabled && true, 'type' => $type->type == 'subtask' ? 'subtask' : 'standard', 'schema' => $schema ]; - if ($type->default) - { + if ($type->default) { $tmp['default'] = true; } $typeOptions[] = $tmp; @@ -813,66 +768,47 @@ public static function getTypeListExt($project_key, $options) private static function _repairSchema($project_key, $issue_type, $schema, $options) { $new_schema = []; - foreach ($schema as $key => $val) - { - if (isset($val['applyToTypes'])) - { - if ($val['applyToTypes'] && !in_array($issue_type, explode(',', $val['applyToTypes'] ?: ''))) - { + foreach ($schema as $key => $val) { + if (isset($val['applyToTypes'])) { + if ($val['applyToTypes'] && !in_array($issue_type, explode(',', $val['applyToTypes'] ?: ''))) { continue; } unset($val['applyToTypes']); } - if ($val['type'] == 'SingleVersion' || $val['type'] == 'MultiVersion') - { - if (!isset($options['version'])) - { + if ($val['type'] == 'SingleVersion' || $val['type'] == 'MultiVersion') { + if (!isset($options['version'])) { $options['version'] = self::getVersionList($project_key); } $val['optionValues'] = self::pluckFields($options['version'], ['_id', 'name']); - } - else if ($val['type'] == 'SingleUser' || $val['type'] == 'MultiUser') - { + } elseif ($val['type'] == 'SingleUser' || $val['type'] == 'MultiUser') { $val['optionValues'] = self::pluckFields($options['user'], ['id', 'name', 'email']); - foreach ($val['optionValues'] as $k => $v) - { + foreach ($val['optionValues'] as $k => $v) { $val['optionValues'][$k]['name'] = $v['name'] . '(' . $v['email'] . ')'; unset($val['optionValues'][$k]['email']); } - } - else if ($val['key'] == 'assignee') - { + } elseif ($val['key'] == 'assignee') { $val['optionValues'] = self::pluckFields($options['assignee'], ['id', 'name', 'email']); - foreach ($val['optionValues'] as $k => $v) - { + foreach ($val['optionValues'] as $k => $v) { $val['optionValues'][$k]['name'] = $v['name'] . '(' . $v['email'] . ')'; unset($val['optionValues'][$k]['email']); } - } - else if ($val['key'] == 'labels') - { + } elseif ($val['key'] == 'labels') { $couple_labels = []; - foreach ($options['labels'] as $label) - { + foreach ($options['labels'] as $label) { $couple_labels[] = [ 'id' => $label['name'], 'name' => $label['name'] ]; } $val['optionValues'] = $couple_labels; - } - else if (array_key_exists($val['key'], $options)) - { + } elseif (array_key_exists($val['key'], $options)) { $val['optionValues'] = self::pluckFields($options[$val['key']], ['_id', 'name']); - foreach ($options[$val['key']] as $key2 => $val2) - { - if (isset($val2['default']) && $val2['default']) - { + foreach ($options[$val['key']] as $key2 => $val2) { + if (isset($val2['default']) && $val2['default']) { $val['defaultValue'] = $val2['_id']; break; } } } - if (isset($val['_id'])) - { + if (isset($val['_id'])) { unset($val['_id']); } $new_schema[] = $val; @@ -885,16 +821,14 @@ private static function _repairSchema($project_key, $issue_type, $schema, $optio * * @param array $srcData * @param array $fields - * @return array + * @return array */ public static function pluckFields($srcData, $fields) { $destData = []; - foreach ($srcData as $val) - { + foreach ($srcData as $val) { $tmp = []; - foreach ($fields as $field) - { + foreach ($fields as $field) { if ($field === '_id') { if (isset($val[$field]) && $val[$field] instanceof ObjectID) { $tmp['id'] = $val[$field]->__toString(); @@ -906,7 +840,7 @@ public static function pluckFields($srcData, $fields) } } $destData[] = $tmp; - } + } return $destData; } @@ -915,7 +849,7 @@ public static function pluckFields($srcData, $fields) * * @param string $project_key * @param string $mid - * @return array + * @return array */ public static function getModuleById($mid) { @@ -944,8 +878,7 @@ public static function getWorkflowByType($type_id) public static function getSchemaByType($type_id) { $type = Type::find($type_id); - if (!$type) - { + if (!$type) { return []; } @@ -966,8 +899,7 @@ public static function getSchemaByType($type_id) public static function getSchemaByScreenId($project_key, $type, $screen_id) { $screen = Screen::find($screen_id); - if (!$screen) - { + if (!$screen) { return []; } return self::getScreenSchema($project_key, $type, $screen); @@ -984,89 +916,63 @@ public static function getScreenSchema($project_key, $type_id, $screen) $new_schema = []; $versions = null; $users = null; - foreach ($screen->schema ?: [] as $key => $val) - { - if (isset($val['applyToTypes'])) - { - if ($val['applyToTypes'] && !in_array($type_id, explode(',', $val['applyToTypes'] ?: ''))) - { + foreach ($screen->schema ?: [] as $key => $val) { + if (isset($val['applyToTypes'])) { + if ($val['applyToTypes'] && !in_array($type_id, explode(',', $val['applyToTypes'] ?: ''))) { continue; } unset($val['applyToTypes']); } - if ($val['key'] == 'assignee') - { + if ($val['key'] == 'assignee') { $users = self::getAssignedUsers($project_key); - foreach ($users as $key => $user) - { + foreach ($users as $key => $user) { $users[$key]['name'] = $user['name'] . '(' . $user['email'] . ')'; - } + } $val['optionValues'] = self::pluckFields($users, ['id', 'name']); - } - else if ($val['key'] == 'resolution') - { + } elseif ($val['key'] == 'resolution') { $resolutions = self::getResolutionOptions($project_key); $val['optionValues'] = self::pluckFields($resolutions, ['_id', 'name']); - foreach ($resolutions as $key2 => $val2) - { - if (isset($val2['default']) && $val2['default']) - { + foreach ($resolutions as $key2 => $val2) { + if (isset($val2['default']) && $val2['default']) { $val['defaultValue'] = $val2['_id']; break; } } - } - else if ($val['key'] == 'priority') - { + } elseif ($val['key'] == 'priority') { $priorities = self::getPriorityOptions($project_key); $val['optionValues'] = self::pluckFields($priorities, ['_id', 'name']); - foreach ($priorities as $key2 => $val2) - { - if (isset($val2['default']) && $val2['default']) - { + foreach ($priorities as $key2 => $val2) { + if (isset($val2['default']) && $val2['default']) { $val['defaultValue'] = $val2['_id']; break; } } - } - else if ($val['key'] == 'module') - { + } elseif ($val['key'] == 'module') { $modules = self::getModuleList($project_key); $val['optionValues'] = self::pluckFields($modules, ['_id', 'name']); - } - else if ($val['key'] == 'epic') - { + } elseif ($val['key'] == 'epic') { $epics = self::getEpicList($project_key); $val['optionValues'] = self::pluckFields($epics, ['_id', 'name', 'bgColor']); - } - else if ($val['key'] == 'labels') - { + } elseif ($val['key'] == 'labels') { $labels = self::getLabelOptions($project_key); $couple_labels = []; - foreach ($labels as $label) - { + foreach ($labels as $label) { $couple_labels[] = [ 'id' => $label['name'], 'name' => $label['name'] ]; } $val['optionValues'] = $couple_labels; - } - else if ($val['type'] == 'SingleVersion' || $val['type'] == 'MultiVersion') - { + } elseif ($val['type'] == 'SingleVersion' || $val['type'] == 'MultiVersion') { $versions === null && $versions = self::getVersionList($project_key); $val['optionValues'] = self::pluckFields($versions, ['_id', 'name']); - } - else if ($val['type'] == 'SingleUser' || $val['type'] == 'MultiUser') - { + } elseif ($val['type'] == 'SingleUser' || $val['type'] == 'MultiUser') { $users === null && $users = self::getUserList($project_key); - foreach ($users as $key => $user) - { + foreach ($users as $key => $user) { $users[$key]['name'] = $user['name'] . '(' . $user['email'] . ')'; } $val['optionValues'] = self::pluckFields($users, ['id', 'name']); } - if (isset($val['_id'])) - { + if (isset($val['_id'])) { unset($val['_id']); } @@ -1091,262 +997,183 @@ public static function snap2His($project_key, $issue_id, $schema = [], $change_f $issue = DB::collection('issue_' . $project_key)->where('_id', $issue_id)->first(); $latest_ver_issue = DB::collection('issue_his_' . $project_key)->where('issue_id', $issue_id)->orderBy('_id', 'desc')->first(); - if ($latest_ver_issue) - { + if ($latest_ver_issue) { $snap_data = $latest_ver_issue['data']; - } - else - { + } else { $snap_data = []; } // fetch the schema data - if (!$schema) - { + if (!$schema) { $schema = []; - if ($change_fields) - { + if ($change_fields) { $out_schema_fields = [ 'type', 'state', 'resolution', 'priority', 'assignee', 'labels', 'parent_id', 'progress', 'expect_start_time', 'expect_complete_time' ]; - if (array_diff($change_fields, $out_schema_fields)) - { + if (array_diff($change_fields, $out_schema_fields)) { $schema = self::getSchemaByType($issue['type']); } - } - else - { + } else { $schema = self::getSchemaByType($issue['type']); } } - foreach ($schema as $field) - { - if (in_array($field['key'], [ 'assignee', 'progress' ]) || ($change_fields && !in_array($field['key'], $change_fields))) - { + foreach ($schema as $field) { + if (in_array($field['key'], [ 'assignee', 'progress' ]) || ($change_fields && !in_array($field['key'], $change_fields))) { continue; } - if (isset($issue[$field['key']])) - { + if (isset($issue[$field['key']])) { $val = []; $val['name'] = $field['name']; - if ($field['type'] === 'SingleUser' || $field['type'] === 'MultiUser') - { - if ($field['type'] === 'SingleUser') - { + if ($field['type'] === 'SingleUser' || $field['type'] === 'MultiUser') { + if ($field['type'] === 'SingleUser') { $val['value'] = $issue[$field['key']] ? $issue[$field['key']]['name'] : $issue[$field['key']]; - } - else - { + } else { $tmp_users = []; - if ($issue[$field['key']]) - { - foreach ($issue[$field['key']] as $tmp_user) - { + if ($issue[$field['key']]) { + foreach ($issue[$field['key']] as $tmp_user) { $tmp_users[] = $tmp_user['name']; } } $val['value'] = implode(',', $tmp_users); } - } - else if (isset($field['optionValues']) && $field['optionValues']) - { + } elseif (isset($field['optionValues']) && $field['optionValues']) { $opv = []; - if (!is_array($issue[$field['key']])) - { + if (!is_array($issue[$field['key']])) { $fieldValues = explode(',', $issue[$field['key']]); - } - else - { + } else { $fieldValues = $issue[$field['key']]; } - foreach ($field['optionValues'] as $ov) - { - if (in_array($ov['id'], $fieldValues)) - { + foreach ($field['optionValues'] as $ov) { + if (in_array($ov['id'], $fieldValues)) { $opv[] = $ov['name']; } } $val['value'] = implode(',', $opv); - } - else if ($field['type'] == 'File') - { + } elseif ($field['type'] == 'File') { $val['value'] = []; - foreach ($issue[$field['key']] as $fid) - { + foreach ($issue[$field['key']] as $fid) { $file = File::find($fid); array_push($val['value'], $file->name); } - } - else if ($field['type'] == 'DatePicker' || $field['type'] == 'DateTimePicker') - { + } elseif ($field['type'] == 'DatePicker' || $field['type'] == 'DateTimePicker') { $val['value'] = $issue[$field['key']] ? date($field['type'] == 'DatePicker' ? 'Y/m/d' : 'Y/m/d H:i:s', $issue[$field['key']]) : $issue[$field['key']]; - } - else - { + } else { $val['value'] = $issue[$field['key']]; } - //$val['type'] = $field['type']; + //$val['type'] = $field['type']; $snap_data[$field['key']] = $val; } } // special fields handle - if (in_array('type', $change_fields) || !isset($snap_data['type'])) - { + if (in_array('type', $change_fields) || !isset($snap_data['type'])) { $type = Type::find($issue['type']); $snap_data['type'] = [ 'value' => isset($type->name) ? $type->name : '', 'name' => '类型' ]; } - if (isset($issue['priority'])) - { - if ($issue['priority']) - { - if (in_array('priority', $change_fields) || !isset($snap_data['priority'])) - { + if (isset($issue['priority'])) { + if ($issue['priority']) { + if (in_array('priority', $change_fields) || !isset($snap_data['priority'])) { $priority = Priority::Where('key', $issue['priority'])->orWhere('_id', $issue['priority'])->first(); $snap_data['priority'] = [ 'value' => isset($priority->name) ? $priority->name : '', 'name' => '优先级' ]; } - } - else - { + } else { $snap_data['priority'] = [ 'value' => '', 'name' => '优先级' ]; } } - if (isset($issue['state'])) - { - if ($issue['state']) - { - if (in_array('state', $change_fields) || !isset($snap_data['state'])) - { + if (isset($issue['state'])) { + if ($issue['state']) { + if (in_array('state', $change_fields) || !isset($snap_data['state'])) { $state = State::Where('key', $issue['state'])->orWhere('_id', $issue['state'])->first(); $snap_data['state'] = [ 'value' => isset($state->name) ? $state->name : '', 'name' => '状态' ]; } - } - else - { + } else { $snap_data['state'] = [ 'value' => '', 'name' => '状态' ]; } } - if (isset($issue['resolution'])) - { - if ($issue['resolution']) - { - if (in_array('resolution', $change_fields) || !isset($snap_data['resolution'])) - { + if (isset($issue['resolution'])) { + if ($issue['resolution']) { + if (in_array('resolution', $change_fields) || !isset($snap_data['resolution'])) { $resolution = Resolution::Where('key', $issue['resolution'])->orWhere('_id', $issue['resolution'])->first(); $snap_data['resolution'] = [ 'value' => isset($resolution->name) ? $resolution->name : '', 'name' => '解决结果' ]; } - } - else - { + } else { $snap_data['resolution'] = [ 'value' => '', 'name' => '解决结果' ]; } } - if (isset($issue['assignee'])) - { - if ($issue['assignee']) - { - if (in_array('assignee', $change_fields) || !isset($snap_data['assignee'])) - { + if (isset($issue['assignee'])) { + if ($issue['assignee']) { + if (in_array('assignee', $change_fields) || !isset($snap_data['assignee'])) { $snap_data['assignee'] = [ 'value' => $issue['assignee']['name'], 'name' => '经办人' ]; } - } - else - { + } else { $snap_data['assignee'] = [ 'value' => '', 'name' => '经办人' ]; } } // labels - if (isset($issue['labels'])) - { - if ($issue['labels']) - { - if (in_array('labels', $change_fields) || !isset($snap_data['labels'])) - { + if (isset($issue['labels'])) { + if ($issue['labels']) { + if (in_array('labels', $change_fields) || !isset($snap_data['labels'])) { $snap_data['labels'] = [ 'value' => implode(',', $issue['labels']), 'name' => '标签' ]; } - } - else - { + } else { $snap_data['labels'] = [ 'value' => '', 'name' => '标签' ]; } } // special fields handle - if (isset($issue['parent_id'])) - { - if ($issue['parent_id']) - { - if (in_array('parent_id', $change_fields) || !isset($snap_data['parent_id'])) - { + if (isset($issue['parent_id'])) { + if ($issue['parent_id']) { + if (in_array('parent_id', $change_fields) || !isset($snap_data['parent_id'])) { $parent = DB::collection('issue_' . $project_key)->where('_id', $issue['parent_id'])->first(['no', 'title']); $snap_data['parent'] = [ 'value' => $parent['no'] . ' - ' . $parent['title'], 'name' => '父任务' ]; } - } - else - { + } else { $snap_data['parent'] = [ 'value' => '', 'name' => '父任务' ]; } } - if (isset($issue['progress'])) - { - if ($issue['progress'] || $issue['progress'] === 0) - { - if (in_array('progress', $change_fields) || !isset($snap_data['progress'])) - { + if (isset($issue['progress'])) { + if ($issue['progress'] || $issue['progress'] === 0) { + if (in_array('progress', $change_fields) || !isset($snap_data['progress'])) { $snap_data['progress'] = [ 'value' => $issue['progress'] . '%', 'name' => '进度' ]; } - } - else - { + } else { $snap_data['progress'] = [ 'value' => '', 'name' => '进度' ]; } } - if (isset($issue['expect_start_time'])) - { - if ($issue['expect_start_time']) - { - if (in_array('expect_start_time', $change_fields) || !isset($snap_data['expect_start_time'])) - { + if (isset($issue['expect_start_time'])) { + if ($issue['expect_start_time']) { + if (in_array('expect_start_time', $change_fields) || !isset($snap_data['expect_start_time'])) { $snap_data['expect_start_time'] = [ 'value' => date('Y/m/d', $issue['expect_start_time']), 'name' => '期望开始时间' ]; } - } - else - { + } else { $snap_data['expect_start_time'] = [ 'value' => '', 'name' => '期望开始时间' ]; } } - if (isset($issue['expect_complete_time'])) - { - if ($issue['expect_complete_time']) - { - if (in_array('expect_complete_time', $change_fields) || !isset($snap_data['expect_complete_time'])) - { + if (isset($issue['expect_complete_time'])) { + if ($issue['expect_complete_time']) { + if (in_array('expect_complete_time', $change_fields) || !isset($snap_data['expect_complete_time'])) { $snap_data['expect_complete_time'] = [ 'value' => date('Y/m/d', $issue['expect_complete_time']), 'name' => '期望完成时间' ]; } - } - else - { + } else { $snap_data['expect_complete_time'] = [ 'value' => '', 'name' => '期望完成时间' ]; } } - if (!isset($snap_data['created_at'])) - { + if (!isset($snap_data['created_at'])) { $snap_data['created_at'] = $issue['created_at']; } - if (!isset($snap_data['reporter'])) - { + if (!isset($snap_data['reporter'])) { $snap_data['reporter'] = $issue['reporter']; } @@ -1372,7 +1199,7 @@ public static function isIssueExisted($project_key, $issue_id) } /** - * get all subtasks of the parent + * get all subtasks of the parent * * @param string $project_key * @param string $parent_no @@ -1381,12 +1208,13 @@ public static function isIssueExisted($project_key, $issue_id) public static function getChildrenByParentNo($project_key, $parent_no) { $parent = DB::collection('issue_' . $project_key)->where('no', $parent_no)->first(); - if (!$parent) { return []; } + if (!$parent) { + return []; + } $children = []; $subtasks = DB::collection('issue_' . $project_key)->where('parent_id', $parent['_id']->__toString())->get(['no']); - foreach ($subtasks as $subtask) - { + foreach ($subtasks as $subtask) { $children[] = $subtask['no']; } return $children; @@ -1439,10 +1267,8 @@ public static function getSprintList($project_key, $fields=[]) ->get($fields) ->toArray(); - foreach($sprints as $key => $sprint) - { - if (!isset($sprint['name'])) - { + foreach ($sprints as $key => $sprint) { + if (!isset($sprint['name'])) { $sprints[$key]['name'] = 'Sprint ' . $sprint['no']; } } @@ -1466,4 +1292,3 @@ public static function isLabelExisted($project_key, $name) return $isExisted; } } - diff --git a/app/Providers/RouteServiceProvider.php b/app/Providers/RouteServiceProvider.php index bde08819a..63d41d58d 100644 --- a/app/Providers/RouteServiceProvider.php +++ b/app/Providers/RouteServiceProvider.php @@ -2,8 +2,8 @@ namespace App\Providers; -use Illuminate\Routing\Router; use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider; +use Illuminate\Routing\Router; class RouteServiceProvider extends ServiceProvider { diff --git a/app/Utils/CurlRequest.php b/app/Utils/CurlRequest.php index 0b9c595fb..6f8b00bd9 100644 --- a/app/Utils/CurlRequest.php +++ b/app/Utils/CurlRequest.php @@ -2,7 +2,8 @@ namespace App\Utils; -class CurlRequest { +class CurlRequest +{ /** * The curl get request. @@ -18,8 +19,7 @@ public static function get($url, $header=[], $await=5) curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); - if (!$header) - { + if (!$header) { $header = [ 'Content-Type: application/json', 'Expect:' ]; } curl_setopt($ch, CURLOPT_HTTPHEADER, $header); @@ -50,8 +50,7 @@ public static function post($url, $header=[], $data=[], $await=5) curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); - if (!$header) - { + if (!$header) { $header = [ 'Content-Type: application/json', 'Expect:' ]; } curl_setopt($ch, CURLOPT_HTTPHEADER, $header); diff --git a/app/Utils/File.php b/app/Utils/File.php index 5cf4c7c3e..80e7706be 100644 --- a/app/Utils/File.php +++ b/app/Utils/File.php @@ -2,9 +2,9 @@ namespace App\Utils; -class File { - - static function download($filename, $displayname) +class File +{ + public static function download($filename, $displayname) { header("Content-type: application/octet-stream"); header("Accept-Ranges: bytes"); @@ -14,8 +14,7 @@ static function download($filename, $displayname) $fp = fopen($filename, 'rb'); ob_end_clean(); ob_start(); - while(!feof($fp)) - { + while (!feof($fp)) { $chunk_size = 1024 * 8; echo fread($fp, $chunk_size); ob_flush(); diff --git a/app/Utils/Lunar.php b/app/Utils/Lunar.php index 27468524c..bf7f7d3a6 100644 --- a/app/Utils/Lunar.php +++ b/app/Utils/Lunar.php @@ -55,26 +55,30 @@ class Lunar * @param month 公历-月 * @param date 公历-日 */ - function convertSolarToLunar($year, $month, $date) { + public function convertSolarToLunar($year, $month, $date) + { //debugger; $yearData = $this->lunarInfo[$year-$this->MIN_YEAR]; - if($year==$this->MIN_YEAR&&$month <= 2 && $date <= 9){ + if ($year==$this->MIN_YEAR&&$month <= 2 && $date <= 9) { return array(1891,'正月','初一','辛卯',1,1,'兔'); } return $this->getLunarByBetween($year, $this->getDaysBetweenSolar($year, $month, $date, $yearData[1], $yearData[2])); } - function convertSolarMonthToLunar($year,$month, $date) { + public function convertSolarMonthToLunar($year, $month, $date) + { $yearData = $this->lunarInfo[$year - $this->MIN_YEAR]; - if($year == $this->MIN_YEAR && $month <= 2&&$date <=9 ){ + if ($year == $this->MIN_YEAR && $month <= 2&&$date <=9) { return array(1891,'正月','初一','辛卯',1,1,'兔'); } $month_days_ary = array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31); $dd = $month_days_ary[$month]; - if($this->isLeapYear($year) && $month == 2) $dd++; + if ($this->isLeapYear($year) && $month == 2) { + $dd++; + } $lunar_ary = array(); for ($i = 1; $i < $dd; $i++) { - $array = $this->getLunarByBetween($year,$this->getDaysBetweenSolar($year, $month, $i, $yearData[1], $yearData[2])); + $array = $this->getLunarByBetween($year, $this->getDaysBetweenSolar($year, $month, $i, $yearData[1], $yearData[2])); $array[] = $year . '-' . $month . '-' . $i; $lunar_ary[$i] = $array; } @@ -86,7 +90,8 @@ function convertSolarMonthToLunar($year,$month, $date) { * @param month 阴历-月,闰月处理:例如如果当年闰五月,那么第二个五月就传六月,相当于阴历有13个月,只是有的时候第13个月的天数为0 * @param date 阴历-日 */ - function convertLunarToSolar($year, $month, $date){ + public function convertLunarToSolar($year, $month, $date) + { $yearData = $this->lunarInfo[$year - $this->MIN_YEAR]; $between = $this->getDaysBetweenLunar($year, $month, $date); $res = mktime(0, 0, 0, $yearData[1], $yearData[2], $year); @@ -101,14 +106,16 @@ function convertLunarToSolar($year, $month, $date){ * 判断是否是闰年 * @param year */ - function isLeapYear($year){ + public function isLeapYear($year) + { return (($year % 4 == 0 && $year % 100 != 0) || ($year % 400 == 0)); } /** * 获取干支纪年 * @param year */ - function getLunarYearName($year){ + public function getLunarYearName($year) + { $sky = array('庚','辛','壬','癸','甲','乙','丙','丁','戊','己'); $earth = array('申','酉','戌','亥','子','丑','寅','卯','辰','巳','午','未'); $year = $year.''; @@ -118,7 +125,8 @@ function getLunarYearName($year){ * 根据阴历年获取生肖 * @param year 阴历年 */ - function getYearZodiac($year){ + public function getYearZodiac($year) + { $zodiac = array('猴','鸡','狗','猪','鼠','牛','虎','兔','龙','蛇','马','羊'); return $zodiac[$year % 12]; } @@ -127,7 +135,8 @@ function getYearZodiac($year){ * @param year 阳历-年 * @param month 阳历-月 */ - function getSolarMonthDays($year, $month){ + public function getSolarMonthDays($year, $month) + { $monthHash = array('1' => 31,'2' => $this->isLeapYear($year) ? 29 : 28,'3' => 31,'4' => 30,'5' => 31,'6' => 30,'7' => 31,'8' => 31,'9' => 30,'10' => 31,'11' => 30,'12' => 31); return $monthHash["$month"]; } @@ -136,7 +145,8 @@ function getSolarMonthDays($year, $month){ * @param year 阴历-年 * @param month 阴历-月,从一月开始 */ - function getLunarMonthDays($year, $month){ + public function getLunarMonthDays($year, $month) + { $monthData = $this->getLunarMonths($year); return $monthData[$month - 1]; } @@ -144,18 +154,19 @@ function getLunarMonthDays($year, $month){ * 获取阴历每月的天数的数组 * @param year */ - function getLunarMonths($year){ + public function getLunarMonths($year) + { $yearData = $this->lunarInfo[$year - $this->MIN_YEAR]; $leapMonth = $yearData[0]; $bit = decbin($yearData[3]); for ($i = 0; $i < strlen($bit);$i ++) { $bitArray[$i] = substr($bit, $i, 1); } - for($k=0,$klen=16-count($bitArray);$k<$klen;$k++){ + for ($k=0,$klen=16-count($bitArray);$k<$klen;$k++) { array_unshift($bitArray, '0'); } $bitArray = array_slice($bitArray, 0, ($leapMonth == 0 ? 12 : 13)); - for($i = 0; $i < count($bitArray); $i++){ + for ($i = 0; $i < count($bitArray); $i++) { $bitArray[$i] = $bitArray[$i] + 29; } return $bitArray; @@ -164,22 +175,24 @@ function getLunarMonths($year){ * 获取农历每年的天数 * @param year 农历年份 */ - function getLunarYearDays($year){ + public function getLunarYearDays($year) + { $yearData = $this->lunarInfo[$year-$this->MIN_YEAR]; $monthArray = $this->getLunarYearMonths($year); $len = count($monthArray); return ($monthArray[$len-1] == 0 ? $monthArray[$len-2] : $monthArray[$len-1]); } - function getLunarYearMonths($year){ + public function getLunarYearMonths($year) + { //debugger; $monthData = $this->getLunarMonths($year); $res=array(); $temp=0; $yearData = $this->lunarInfo[$year - $this->MIN_YEAR]; $len = ($yearData[0] == 0 ? 12 : 13); - for($i = 0; $i < $len; $i++){ + for ($i = 0; $i < $len; $i++) { $temp=0; - for($j = 0; $j <= $i; $j++){ + for ($j = 0; $j <= $i; $j++) { $temp+=$monthData[$j]; } array_push($res, $temp); @@ -190,7 +203,8 @@ function getLunarYearMonths($year){ * 获取闰月 * @param year 阴历年份 */ - function getLeapMonth($year){ + public function getLeapMonth($year) + { $yearData = $this->lunarInfo[$year - $this->MIN_YEAR]; return $yearData[0]; } @@ -200,10 +214,11 @@ function getLeapMonth($year){ * @param month * @param date */ - function getDaysBetweenLunar($year, $month, $date){ + public function getDaysBetweenLunar($year, $month, $date) + { $yearMonth = $this->getLunarMonths($year); $res = 0; - for($i = 1; $i < $month; $i++){ + for ($i = 1; $i < $month; $i++) { $res += $yearMonth[$i-1]; } $res += $date - 1; @@ -217,7 +232,8 @@ function getDaysBetweenLunar($year, $month, $date){ * @param dmonth 阴历正月对应的阳历月份 * @param ddate 阴历初一对应的阳历天数 */ - function getDaysBetweenSolar($year, $cmonth, $cdate, $dmonth, $ddate){ + public function getDaysBetweenSolar($year, $cmonth, $cdate, $dmonth, $ddate) + { $a = mktime(0, 0, 0, $cmonth, $cdate, $year); $b = mktime(0, 0, 0, $dmonth, $ddate, $year); return ceil(($a - $b) / 24 / 3600); @@ -227,7 +243,8 @@ function getDaysBetweenSolar($year, $cmonth, $cdate, $dmonth, $ddate){ * @param year 阳历年 * @param between 天数 */ - function getLunarByBetween($year,$between){ + public function getLunarByBetween($year, $between) + { //debugger; $lunarArray = array(); $yearMonth = array(); @@ -235,21 +252,21 @@ function getLunarByBetween($year,$between){ $e = 0; $leapMonth = 0; $m = ''; - if($between == 0){ + if ($between == 0) { array_push($lunarArray, $year, '正月', '初一'); $t = 1; $e = 1; - }else{ + } else { $year = $between > 0 ? $year : ($year - 1); $yearMonth = $this->getLunarYearMonths($year); $leapMonth = $this->getLeapMonth($year); $between = $between > 0 ? $between : ($this->getLunarYearDays($year) + $between); - for ($i = 0; $i < 13; $i++){ + for ($i = 0; $i < 13; $i++) { if ($between == $yearMonth[$i]) { $t = $i + 2; $e = 1; break; - } else if ($between<$yearMonth[$i]) { + } elseif ($between<$yearMonth[$i]) { $t=$i+1; $e=$between-(empty($yearMonth[$i-1])?0:$yearMonth[$i-1])+1; break; @@ -266,7 +283,8 @@ function getLunarByBetween($year,$between){ return $lunarArray; } //转换成中文年份 - function toYear($year){ + public function toYear($year) + { $arr = array("零", "一", "二", "三", "四", "五", "六", "七", "八", "九"); $year_arr = str_split($year); $str = $arr[$year_arr[0]].$arr[$year_arr[1]].$arr[$year_arr[2]].$arr[$year_arr[3]]; @@ -277,23 +295,24 @@ function toYear($year){ * @param num 数字 * @param isMonth 是否是月份的数字 */ - function getCapitalNum($num, $isMonth){ + public function getCapitalNum($num, $isMonth) + { $isMonth = $isMonth || false; $dateHash = array('0'=>'','1'=>'一','2'=>'二','3'=>'三','4'=>'四','5'=>'五','6'=>'六','7'=>'七','8'=>'八','9'=>'九','10'=>'十 '); $monthHash = array('0'=>'','1'=>'正月','2'=>'二月','3'=>'三月','4'=>'四月','5'=>'五月','6'=>'六月','7'=>'七月','8'=>'八月','9'=>'九月','10'=>'十月','11'=>'冬月','12'=>'腊月'); $res = ''; - if($isMonth){ + if ($isMonth) { $res = $monthHash[$num]; - }else{ - if($num<=10) { + } else { + if ($num<=10) { $res = '初'.$dateHash[$num]; - } else if ($num > 10 && $num < 20){ + } elseif ($num > 10 && $num < 20) { $res = '十'.$dateHash[$num - 10]; - } else if ($num==20){ + } elseif ($num==20) { $res = "二十"; - } else if ($num > 20 && $num < 30){ + } elseif ($num > 20 && $num < 30) { $res = "廿".$dateHash[$num - 20]; - } else if ($num == 30){ + } elseif ($num == 30) { $res = "三十"; } } diff --git a/app/WebHook/GitHubPush.php b/app/WebHook/GitHubPush.php index b8242b574..d9cacd567 100644 --- a/app/WebHook/GitHubPush.php +++ b/app/WebHook/GitHubPush.php @@ -5,7 +5,7 @@ use App\WebHook\GitPush; use Cartalyst\Sentinel\Users\EloquentUser; -class GitHubPush extends GitPush +class GitHubPush extends GitPush { /** @@ -16,33 +16,31 @@ class GitHubPush extends GitPush */ public function parse($data) { - // set the repo + // set the repo $repo = []; $repo['name'] = $data['repository']['name']; $repo['homepage'] = $data['repository']['html_url']; $this->repo = $repo; // set the branch $this->branch = isset($data['ref']) ? substr($data['ref'], 11) : ''; // refs/heads/ - // get the pusher + // get the pusher $user_name = isset($data['pusher']) && isset($data['pusher']['user_name']) ? $data['pusher']['user_name'] : ''; $user_email = isset($data['pusher']) && isset($data['pusher']['user_email']) ? $data['pusher']['user_email'] : ''; $user = [ 'name' => $user_name, 'email' => $user_email ]; - if ($user_email) - { - $user2 = EloquentUser::where('email', $user_email)->first(); - if ($user2) - { - $user['id'] = $user2->id; + if ($user_email) { + $user2 = EloquentUser::where('email', $user_email)->first(); + if ($user2) { + $user['id'] = $user2->id; $user['name'] = $user2->first_name; - $user['email'] = $user2->email; - } + $user['email'] = $user2->email; + } } $this->pusher = $user; // set the commits $this->commits = isset($data['commits']) ? $data['commits'] : []; // get the after $this->after = isset($data['after']) ? $data['after'] : ''; - // get the before + // get the before $this->before = isset($data['before']) ? $data['before'] : ''; } @@ -54,40 +52,35 @@ public function parse($data) */ public function arrangeCommit($commit) { - $new_commit = []; + $new_commit = []; $new_commit['repo'] = $this->getRepo(); $new_commit['branch'] = $this->getBranch(); $new_commit['pusher'] = $this->getPusher(); $new_commit['pushed_at'] = time(); - $new_commit['sha'] = isset($commit['id']) ? $commit['id'] : ''; - $new_commit['url'] = isset($commit['url']) ? $commit['url'] : ''; - $new_commit['message'] = isset($commit['message']) ? trim($commit['message']) : ''; - $new_commit['added'] = isset($commit['added']) ? $commit['added'] : []; - $new_commit['modified'] = isset($commit['modified']) ? $commit['modified'] : []; - $new_commit['removed'] = isset($commit['removed']) ? $commit['removed'] : []; - $new_commit['committed_at'] = isset($commit['timestamp']) ? strtotime($commit['timestamp']) : ''; + $new_commit['sha'] = isset($commit['id']) ? $commit['id'] : ''; + $new_commit['url'] = isset($commit['url']) ? $commit['url'] : ''; + $new_commit['message'] = isset($commit['message']) ? trim($commit['message']) : ''; + $new_commit['added'] = isset($commit['added']) ? $commit['added'] : []; + $new_commit['modified'] = isset($commit['modified']) ? $commit['modified'] : []; + $new_commit['removed'] = isset($commit['removed']) ? $commit['removed'] : []; + $new_commit['committed_at'] = isset($commit['timestamp']) ? strtotime($commit['timestamp']) : ''; - if (isset($commit['author'])) - { - $new_commit['author'] = $commit['author']; - if (isset($commit['author']['email']) && $commit['author']['email']) - { - $new_author = EloquentUser::where('email', $commit['author']['email'])->first(); - if ($new_author) - { - $new_commit['author']['id'] = $new_author->id; + if (isset($commit['author'])) { + $new_commit['author'] = $commit['author']; + if (isset($commit['author']['email']) && $commit['author']['email']) { + $new_author = EloquentUser::where('email', $commit['author']['email'])->first(); + if ($new_author) { + $new_commit['author']['id'] = $new_author->id; $new_commit['author']['name'] = $new_author->first_name; - $new_commit['author']['email'] = $new_author->email; - } - } - } - else - { - $new_commit['author'] = []; - } + $new_commit['author']['email'] = $new_author->email; + } + } + } else { + $new_commit['author'] = []; + } - return $new_commit; + return $new_commit; } } diff --git a/app/WebHook/GitLabPush.php b/app/WebHook/GitLabPush.php index 49532eba2..e91c42994 100644 --- a/app/WebHook/GitLabPush.php +++ b/app/WebHook/GitLabPush.php @@ -5,7 +5,7 @@ use App\WebHook\GitPush; use Cartalyst\Sentinel\Users\EloquentUser; -class GitLabPush extends GitPush +class GitLabPush extends GitPush { /** @@ -16,33 +16,31 @@ class GitLabPush extends GitPush */ public function parse($data) { - // set the repo + // set the repo $repo = []; $repo['name'] = $data['repository']['name']; $repo['homepage'] = $data['repository']['homepage']; $this->repo = $repo; // set the branch $this->branch = isset($data['ref']) ? substr($data['ref'], 11) : ''; // refs/heads/ - // get the pusher + // get the pusher $user_name = isset($data['user_name']) ? $data['user_name'] : ''; $user_email = isset($data['user_email']) ? $data['user_email'] : ''; $user = [ 'name' => $user_name, 'email' => $user_email ]; - if ($user_email) - { - $user2 = EloquentUser::where('email', $user_email)->first(); - if ($user2) - { - $user['id'] = $user2->id; + if ($user_email) { + $user2 = EloquentUser::where('email', $user_email)->first(); + if ($user2) { + $user['id'] = $user2->id; $user['name'] = $user2->first_name; - $user['email'] = $user2->email; - } + $user['email'] = $user2->email; + } } $this->pusher = $user; // set the commits $this->commits = isset($data['commits']) ? $data['commits'] : []; // get the after $this->after = isset($data['after']) ? $data['after'] : ''; - // get the before + // get the before $this->before = isset($data['before']) ? $data['before'] : ''; } @@ -54,40 +52,35 @@ public function parse($data) */ public function arrangeCommit($commit) { - $new_commit = []; + $new_commit = []; $new_commit['repo'] = $this->getRepo(); $new_commit['branch'] = $this->getBranch(); $new_commit['pusher'] = $this->getPusher(); $new_commit['pushed_at'] = time(); - $new_commit['sha'] = isset($commit['id']) ? $commit['id'] : ''; - $new_commit['url'] = isset($commit['url']) ? $commit['url'] : ''; - $new_commit['message'] = isset($commit['message']) ? trim($commit['message']) : ''; - $new_commit['added'] = isset($commit['added']) ? $commit['added'] : []; - $new_commit['modified'] = isset($commit['modified']) ? $commit['modified'] : []; - $new_commit['removed'] = isset($commit['removed']) ? $commit['removed'] : []; - $new_commit['committed_at'] = isset($commit['timestamp']) ? strtotime($commit['timestamp']) : ''; + $new_commit['sha'] = isset($commit['id']) ? $commit['id'] : ''; + $new_commit['url'] = isset($commit['url']) ? $commit['url'] : ''; + $new_commit['message'] = isset($commit['message']) ? trim($commit['message']) : ''; + $new_commit['added'] = isset($commit['added']) ? $commit['added'] : []; + $new_commit['modified'] = isset($commit['modified']) ? $commit['modified'] : []; + $new_commit['removed'] = isset($commit['removed']) ? $commit['removed'] : []; + $new_commit['committed_at'] = isset($commit['timestamp']) ? strtotime($commit['timestamp']) : ''; - if (isset($commit['author'])) - { - $new_commit['author'] = $commit['author']; - if (isset($commit['author']['email']) && $commit['author']['email']) - { - $new_author = EloquentUser::where('email', $commit['author']['email'])->first(); - if ($new_author) - { - $new_commit['author']['id'] = $new_author->id; + if (isset($commit['author'])) { + $new_commit['author'] = $commit['author']; + if (isset($commit['author']['email']) && $commit['author']['email']) { + $new_author = EloquentUser::where('email', $commit['author']['email'])->first(); + if ($new_author) { + $new_commit['author']['id'] = $new_author->id; $new_commit['author']['name'] = $new_author->first_name; - $new_commit['author']['email'] = $new_author->email; - } - } - } - else - { - $new_commit['author'] = []; - } + $new_commit['author']['email'] = $new_author->email; + } + } + } else { + $new_commit['author'] = []; + } - return $new_commit; + return $new_commit; } } diff --git a/app/WebHook/GitPush.php b/app/WebHook/GitPush.php index 594c2bb5b..d96074c81 100644 --- a/app/WebHook/GitPush.php +++ b/app/WebHook/GitPush.php @@ -6,7 +6,7 @@ use DB; use Exception; -class GitPush +class GitPush { // the push git repository protected $repo = []; @@ -18,9 +18,9 @@ class GitPush protected $commits = []; // the pusher - protected $pusher = []; + protected $pusher = []; - // the after + // the after protected $after = ''; // the before @@ -91,8 +91,7 @@ public function execWorkflow($project_key, $issue, $action_id, $caller) { $issue_id = $issue['_id']->__toString(); $entry_id = isset($issue['entry_id']) ? $issue['entry_id'] : ''; - if (!$entry_id) - { + if (!$entry_id) { return; } @@ -118,29 +117,25 @@ public function insCommits($project_key) $issue_table = 'issue_' . $project_key; $commits = $this->getCommits(); - foreach($commits as $commit) - { + foreach ($commits as $commit) { $new_commit = $this->arrangeCommit($commit); $issue_data = $this->relateIssue($project_key, $new_commit['message']); - if ($issue_data === false) - { + if ($issue_data === false) { continue; } $issue_no = $issue_data['no']; $action = $issue_data['action']; $issue = DB::collection($issue_table)->where('no', $issue_no)->where('del_flg', '<>', 1)->first(); - if (!$issue) - { + if (!$issue) { return; } - // insert the commit to issue + // insert the commit to issue DB::collection($table)->insert($new_commit + [ 'issue_id' => $issue['_id']->__toString() ]); // transimit the issue status - if ($action > 0 && isset($new_commit['author']['id']) && $new_commit['author']['id']) - { + if ($action > 0 && isset($new_commit['author']['id']) && $new_commit['author']['id']) { $this->execWorkflow($project_key, $issue, $action, $new_commit['author']['id']); } } @@ -156,33 +151,28 @@ public function insCommits($project_key) */ public function relateIssue($project_key, $message) { - if (!$message) - { + if (!$message) { return false; } $messages = explode(' ', trim($message)); $prefix = array_shift($messages); - if (strpos($prefix, '-') === false) - { + if (strpos($prefix, '-') === false) { return false; } $marks = explode('-', $prefix); - if ($marks[0] != $project_key) - { + if ($marks[0] != $project_key) { return false; } - if (!$marks[1] || !is_numeric($marks[1]) || strpos($marks[1], '.') !== false) - { + if (!$marks[1] || !is_numeric($marks[1]) || strpos($marks[1], '.') !== false) { return false; } $issue_no = intval($marks[1]); $action = 0; - if (isset($marks[2]) && $marks[2]) - { + if (isset($marks[2]) && $marks[2]) { $action = is_numeric($marks[2]) && strpos($marks[2], '.') === false ? intval($marks[2]) : 0; } diff --git a/app/Workflow/Eloquent/CurrentStep.php b/app/Workflow/Eloquent/CurrentStep.php index facfcff2f..d4b4c1bef 100644 --- a/app/Workflow/Eloquent/CurrentStep.php +++ b/app/Workflow/Eloquent/CurrentStep.php @@ -6,7 +6,7 @@ class CurrentStep extends Model { - protected $table = 'oswf_currentstep'; + protected $table = 'oswf_currentstep'; protected $fillable = array( 'entry_id', diff --git a/app/Workflow/Eloquent/Definition.php b/app/Workflow/Eloquent/Definition.php index bf498b66b..322d97001 100644 --- a/app/Workflow/Eloquent/Definition.php +++ b/app/Workflow/Eloquent/Definition.php @@ -43,5 +43,4 @@ public function validate() { return true; } - } diff --git a/app/Workflow/Eloquent/Entry.php b/app/Workflow/Eloquent/Entry.php index bcc53884d..b9df2b5d3 100644 --- a/app/Workflow/Eloquent/Entry.php +++ b/app/Workflow/Eloquent/Entry.php @@ -9,10 +9,10 @@ class Entry extends Model protected $table = 'oswf_entry'; protected $fillable = array( - 'definition_id', + 'definition_id', 'creator', 'state', - 'propertysets' + 'propertysets' ); public function definition() @@ -25,4 +25,3 @@ public function currentSteps() return $this->hasMany('App\Workflow\Eloquent\CurrentStep'); } } - diff --git a/app/Workflow/Exceptions.php b/app/Workflow/Exceptions.php index 302081a15..4dc5fcca8 100644 --- a/app/Workflow/Exceptions.php +++ b/app/Workflow/Exceptions.php @@ -2,15 +2,39 @@ namespace App\Workflow; -class StateNotActivatedException extends \UnexpectedValueException {} -class StepNotFoundException extends \UnexpectedValueException {} -class CurrentStepNotFoundException extends \UnexpectedValueException {} -class ActionNotFoundException extends \UnexpectedValueException {} -class ActionNotAvailableException extends \UnexpectedValueException {} -class ResultNotFoundException extends \UnexpectedValueException {} -class ResultNotAvailableException extends \UnexpectedValueException {} -class FunctionNotFoundException extends \BadMethodCallException {} -class EntryNotFoundException extends \UnexpectedValueException {} -class ConfigNotFoundException extends \UnexpectedValueException {} -class SplitNotFoundException extends \UnexpectedValueException {} -class JoinNotFoundException extends \UnexpectedValueException {} +class StateNotActivatedException extends \UnexpectedValueException +{ +} +class StepNotFoundException extends \UnexpectedValueException +{ +} +class CurrentStepNotFoundException extends \UnexpectedValueException +{ +} +class ActionNotFoundException extends \UnexpectedValueException +{ +} +class ActionNotAvailableException extends \UnexpectedValueException +{ +} +class ResultNotFoundException extends \UnexpectedValueException +{ +} +class ResultNotAvailableException extends \UnexpectedValueException +{ +} +class FunctionNotFoundException extends \BadMethodCallException +{ +} +class EntryNotFoundException extends \UnexpectedValueException +{ +} +class ConfigNotFoundException extends \UnexpectedValueException +{ +} +class SplitNotFoundException extends \UnexpectedValueException +{ +} +class JoinNotFoundException extends \UnexpectedValueException +{ +} diff --git a/app/Workflow/Func.php b/app/Workflow/Func.php index 31b55920a..7180e1319 100644 --- a/app/Workflow/Func.php +++ b/app/Workflow/Func.php @@ -9,9 +9,8 @@ use Sentinel; use DB; -class Func +class Func { - public static $issue_properties = []; public static $snap_id = ''; @@ -19,8 +18,8 @@ class Func /** * check if user is the type. * - * @param array $param - * @return boolean + * @param array $param + * @return boolean */ public static function isSome($param) { @@ -28,24 +27,17 @@ public static function isSome($param) $project_key = $param['project_key']; $caller = $param['caller']; - if ($param['someParam'] == 'assignee') - { + if ($param['someParam'] == 'assignee') { $issue = DB::collection('issue_' . $project_key)->where('_id', $issue_id)->first(); - if ($issue && isset($issue['assignee']) && isset($issue['assignee']['id']) && $issue['assignee']['id'] === $caller) - { + if ($issue && isset($issue['assignee']) && isset($issue['assignee']['id']) && $issue['assignee']['id'] === $caller) { return true; } - } - else if ($param['someParam'] == 'reporter') - { + } elseif ($param['someParam'] == 'reporter') { $issue = DB::collection('issue_' . $project_key)->where('_id', $issue_id)->first(); - if ($issue && isset($issue['reporter']) && isset($issue['reporter']['id']) && $issue['reporter']['id'] === $caller) - { + if ($issue && isset($issue['reporter']) && isset($issue['reporter']['id']) && $issue['reporter']['id'] === $caller) { return true; } - } - else if ($param['someParam'] == 'principal') - { + } elseif ($param['someParam'] == 'principal') { $principal = Provider::getProjectPrincipal($project_key) ?: []; return $principal && $principal['id'] === $caller; } @@ -76,10 +68,8 @@ public static function checkSubTasksState($param) $project_key = $param['project_key']; $subtasks = DB::collection('issue_' . $project_key)->where('parent_id', $issue_id)->get([ 'state' ]); - foreach ($subtasks as $subtask) - { - if ($subtask['state'] != $param['stateParam']) - { + foreach ($subtasks as $subtask) { + if ($subtask['state'] != $param['stateParam']) { return false; } } @@ -114,10 +104,8 @@ public static function belongsToRole($param) $caller = $param['caller']; $roles = Acl::getRolesByUid($project_key, $caller); - foreach ($roles as $role) - { - if ($role === $param['roleParam']) - { + foreach ($roles as $role) { + if ($role === $param['roleParam']) { return true; } } @@ -128,12 +116,11 @@ public static function belongsToRole($param) * set resolution value to issue_properties. * * @param array $param - * @return void + * @return void */ public static function setResolution($param) { - if (isset($param['resolutionParam']) && $param['resolutionParam']) - { + if (isset($param['resolutionParam']) && $param['resolutionParam']) { self::$issue_properties[ 'resolution'] = $param['resolutionParam']; } } @@ -146,8 +133,7 @@ public static function setResolution($param) */ public static function setState($param) { - if (isset($param['state']) && $param['state']) - { + if (isset($param['state']) && $param['state']) { self::$issue_properties['state'] = $param['state']; } } @@ -161,8 +147,7 @@ public static function setState($param) public static function assignIssueToUser($param) { $user_info = Sentinel::findById($param['assignedUserParam']); - if ($user_info) - { + if ($user_info) { self::$issue_properties['assignee'] = [ 'id' => $user_info->id, 'name' => $user_info->first_name ]; } } @@ -179,27 +164,19 @@ public static function assignIssue($param) $issue_id = $param['issue_id']; $caller = $param['caller']; - if ($param['assigneeParam'] == 'me') - { + if ($param['assigneeParam'] == 'me') { $user_info = Sentinel::findById($caller); - if ($user_info) - { + if ($user_info) { self::$issue_properties['assignee'] = [ 'id' => $user_info->id, 'name' => $user_info->first_name ]; } - } - else if ($param['assigneeParam'] == 'reporter') - { + } elseif ($param['assigneeParam'] == 'reporter') { $issue = DB::collection('issue_' . $project_key)->where('_id', $issue_id)->first(); - if ($issue && isset($issue['reporter'])) - { + if ($issue && isset($issue['reporter'])) { self::$issue_properties['assignee'] = $issue['reporter']; } - } - else if ($param['assigneeParam'] == 'principal') - { + } elseif ($param['assigneeParam'] == 'principal') { $principal = Provider::getProjectPrincipal($project_key) ?: []; - if ($principal) - { + if ($principal) { self::$issue_properties['assignee'] = $principal; } } @@ -218,7 +195,9 @@ public static function addComments($param) $caller = $param['caller']; $comments = isset($param['comments']) ? $param['comments'] : ''; - if (!$comments) { return; } + if (!$comments) { + return; + } $user_info = Sentinel::findById($caller); $creator = [ 'id' => $user_info->id, 'name' => $user_info->first_name, 'email' => $user_info->email ]; @@ -242,8 +221,7 @@ public static function updIssue($param) $project_key = $param['project_key']; $caller = $param['caller']; - if (count(self::$issue_properties) > 0) - { + if (count(self::$issue_properties) > 0) { $updValues = []; $user_info = Sentinel::findById($caller); $updValues['modifier'] = [ 'id' => $user_info->id, 'name' => $user_info->first_name, 'email' => $user_info->email ]; @@ -273,35 +251,29 @@ public static function triggerEvent($param) { $issue_id = $param['issue_id']; $project_key = $param['project_key']; - $event_key = array_get($param, 'eventParam', 'normal'); + $event_key = array_get($param, 'eventParam', 'normal'); $user_info = Sentinel::findById($param['caller']); $caller = [ 'id' => $user_info->id, 'name' => $user_info->first_name, 'email' => $user_info->email ]; - if (self::$snap_id) - { + if (self::$snap_id) { Event::fire(new IssueEvent($project_key, $issue_id, $caller, [ 'event_key' => $event_key, 'snap_id' => self::$snap_id ])); } $updValues = []; - if ($event_key === 'resolve_issue') - { + if ($event_key === 'resolve_issue') { $updValues['resolved_at'] = time(); $updValues['resolver'] = $caller; $issue = DB::collection('issue_' . $project_key)->where('_id', $issue_id)->first(); - if (isset($issue['regression_times']) && $issue['regression_times']) - { + if (isset($issue['regression_times']) && $issue['regression_times']) { $updValues['regression_times'] = $issue['regression_times'] + 1; - } - else - { + } else { $updValues['regression_times'] = 1; } $logs = []; - if (isset($issue['resolved_logs']) && $issue['resolved_logs']) - { + if (isset($issue['resolved_logs']) && $issue['resolved_logs']) { $logs = $issue['resolved_logs']; } $log = []; @@ -311,19 +283,15 @@ public static function triggerEvent($param) $updValues['resolved_logs'] = $logs; $his_resolvers = []; - foreach($logs as $v) - { + foreach ($logs as $v) { $his_resolvers[] = $v['user']['id']; } $updValues['his_resolvers'] = array_unique($his_resolvers); - } - else if ($event_key === 'close_issue') - { + } elseif ($event_key === 'close_issue') { $updValues['closed_at'] = time(); $updValues['closer'] = $caller; } - if ($updValues) - { + if ($updValues) { DB::collection('issue_' . $project_key)->where('_id', $issue_id)->update($updValues); } } diff --git a/app/Workflow/Util.php b/app/Workflow/Util.php index de9a03218..c0b90d0b7 100644 --- a/app/Workflow/Util.php +++ b/app/Workflow/Util.php @@ -7,96 +7,96 @@ class Util // public function preStepFunc1($args) { - echo 'pre step func1 ==='; + echo 'pre step func1 ==='; } // public function postStepFunc1($args) { - echo 'post step func1 ==='; + echo 'post step func1 ==='; } // public function preStepFunc2($args) { - echo 'pre step func2 ==='; + echo 'pre step func2 ==='; } // public function postStepFunc2($args) { - echo 'post step func2 ==='; + echo 'post step func2 ==='; } // public function preActionFunc1($args) { - echo 'pre action func1 ==='; + echo 'pre action func1 ==='; } // public function postActionFunc1($args) { - echo 'post action func1 ==='; + echo 'post action func1 ==='; } // public function preActionFunc2($args) { - echo 'pre action func2 ==='; + echo 'pre action func2 ==='; } // public function postActionFunc2($args) { - echo 'post action func2 ==='; + echo 'post action func2 ==='; } // public function preResultFunc1($args) { - echo 'pre result func1 ==='; + echo 'pre result func1 ==='; } // public function postResultFunc1($args) { - echo 'post result func1 ==='; + echo 'post result func1 ==='; } // public function preResultFunc2($args) { - echo 'pre result func2 ==='; + echo 'pre result func2 ==='; } // public function postResultFunc2($args) { - echo 'post result func2 ==='; + echo 'post result func2 ==='; } // public function trueCondition1($args) { - return true; + return true; } // public function trueCondition2($args) { - return true; + return true; } - // + // public function falseCondition1($args) { - return false; + return false; } // public function falseCondition2($args) { - return false; + return false; } } diff --git a/app/Workflow/Workflow.php b/app/Workflow/Workflow.php index bd1662405..ae248469f 100644 --- a/app/Workflow/Workflow.php +++ b/app/Workflow/Workflow.php @@ -19,12 +19,13 @@ use App\Workflow\SplitNotFoundException; use App\Workflow\JoinNotFoundException; -class Workflow { +class Workflow +{ /** * The workflow five states. * - * @var int + * @var int */ const OSWF_CREATED = 1; const OSWF_ACTIVATED = 2; @@ -35,7 +36,7 @@ class Workflow { /** * The workflow instance object. * - * @var App\Workflow\Eloquent\Entry + * @var App\Workflow\Eloquent\Entry */ protected $entry; @@ -47,7 +48,7 @@ class Workflow { protected $wf_config; /** - * workflow options + * workflow options * * @var array */ @@ -62,26 +63,19 @@ class Workflow { public function __construct($entry_id) { $entry = Entry::find($entry_id); - if ($entry) - { + if ($entry) { $this->entry = $entry; $definition = Definition::find($entry->definition_id); - if (!$definition) - { + if (!$definition) { throw new ConfigNotFoundException(); } - if (isset($definition->contents) && $definition->contents) - { + if (isset($definition->contents) && $definition->contents) { $this->wf_config = $definition->contents; - } - else - { + } else { throw new ConfigNotFoundException(); } - } - else - { + } else { throw new EntryNotFoundException(); } } @@ -110,7 +104,7 @@ public static function createInstance($definition_id, $caller) */ public function getEntryId() { - return $this->entry->id; + return $this->entry->id; } /** @@ -121,10 +115,8 @@ public function getEntryId() */ private function isActionAvailable($action_descriptor) { - if (isset($action_descriptor['restrict_to']) && isset($action_descriptor['restrict_to']['conditions']) && $action_descriptor['restrict_to']['conditions']) - { - if (!$this->passesConditions($action_descriptor['restrict_to']['conditions'])) - { + if (isset($action_descriptor['restrict_to']) && isset($action_descriptor['restrict_to']['conditions']) && $action_descriptor['restrict_to']['conditions']) { + if (!$this->passesConditions($action_descriptor['restrict_to']['conditions'])) { return false; } } @@ -134,15 +126,14 @@ private function isActionAvailable($action_descriptor) /** * initialize workflow. * - * @param array options + * @param array options * @return void */ public function start($options=[]) { $this->options = array_merge($this->options, $options); - if (!isset($this->wf_config['initial_action']) || !$this->wf_config['initial_action']) - { + if (!isset($this->wf_config['initial_action']) || !$this->wf_config['initial_action']) { throw new ActionNotFoundException(); } @@ -161,20 +152,17 @@ public function start($options=[]) //} $action_descriptor = $this->wf_config['initial_action']; - if (!$this->isActionAvailable($action_descriptor)) - { + if (!$this->isActionAvailable($action_descriptor)) { throw new ActionNotAvailableException(); } // confirm result whose condition is satified. - if (!isset($action_descriptor['results']) || !$action_descriptor['results']) - { + if (!isset($action_descriptor['results']) || !$action_descriptor['results']) { throw new ResultNotFoundException(); } $available_result_descriptor = $this->getAvailableResult($action_descriptor['results']); - if (!$available_result_descriptor) - { + if (!$available_result_descriptor) { throw new ResultNotAvailableException(); } // create new current step @@ -238,8 +226,7 @@ public function getCurrentSteps() public function getStepMeta($step_id, $name='') { $step_description = $this->getStepDescriptor($step_id); - if ($name) - { + if ($name) { return isset($step_description[$name]) ? $step_description[$name] : ''; } return $step_description; @@ -250,7 +237,7 @@ public function getStepMeta($step_id, $name='') * * @param App\Workflow\Eloquent\CurrentStep $current_step * @param int $action_id - * @return string previous_id + * @return string previous_id */ private function moveToHistory($current_step, $action_id) { @@ -279,21 +266,17 @@ private function moveToHistory($current_step, $action_id) private function createNewCurrentStep($result_descriptor, $action_id, $previous_id='') { $step_descriptor = []; - if (isset($result_descriptor['step']) && $result_descriptor['step']) - { + if (isset($result_descriptor['step']) && $result_descriptor['step']) { $step_descriptor = $this->getStepDescriptor($result_descriptor['step']); - if (!$step_descriptor) - { + if (!$step_descriptor) { throw new StepNotFoundException(); } } - if (!$step_descriptor) - { + if (!$step_descriptor) { return; } // order to use for workflow post-function - if (isset($step_descriptor['state']) && $step_descriptor['state']) - { + if (isset($step_descriptor['state']) && $step_descriptor['state']) { $this->options['state'] = $step_descriptor['state']; } @@ -310,8 +293,7 @@ private function createNewCurrentStep($result_descriptor, $action_id, $previous_ $new_current_step->save(); // trigger before step - if (isset($step_descriptor['pre_functions']) && $step_descriptor['pre_functions']) - { + if (isset($step_descriptor['pre_functions']) && $step_descriptor['pre_functions']) { $this->executeFunctions($step_descriptor['pre_functions']); } } @@ -325,111 +307,90 @@ private function createNewCurrentStep($result_descriptor, $action_id, $previous_ */ private function transitionWorkflow($current_steps, $action_id) { - foreach ($current_steps as $current_step) - { + foreach ($current_steps as $current_step) { $step_descriptor = $this->getStepDescriptor($current_step->step_id); - if (!$step_descriptor) - { + if (!$step_descriptor) { throw new StepNotFoundException(); } $action_descriptor = $this->getActionDescriptor(isset($step_descriptor['actions']) ? $step_descriptor['actions'] : [], $action_id); - if ($action_descriptor) - { + if ($action_descriptor) { break; } } - if (!$action_descriptor) - { - throw new ActionNotFoundException(); + if (!$action_descriptor) { + throw new ActionNotFoundException(); } - if (!$this->isActionAvailable($action_descriptor)) - { + if (!$this->isActionAvailable($action_descriptor)) { throw new ActionNotAvailableException(); } - if (!isset($action_descriptor['results']) || !$action_descriptor['results']) - { + if (!isset($action_descriptor['results']) || !$action_descriptor['results']) { throw new ResultNotFoundException(); } // confirm result whose condition is satified. $available_result_descriptor = $this->getAvailableResult($action_descriptor['results']); - if (!$available_result_descriptor) - { + if (!$available_result_descriptor) { throw new ResultNotAvailableException(); } // triggers after step - if (isset($step_descriptor['post_functions']) && $step_descriptor['post_functions']) - { + if (isset($step_descriptor['post_functions']) && $step_descriptor['post_functions']) { $this->executeFunctions($step_descriptor['post_functions']); } // triggers before action - if (isset($action_descriptor['pre_functions']) && $action_descriptor['pre_functions']) - { + if (isset($action_descriptor['pre_functions']) && $action_descriptor['pre_functions']) { $this->executeFunctions($action_descriptor['pre_functions']); } // triggers before result - if (isset($available_result_descriptor['pre_functions']) && $available_result_descriptor['pre_functions']) - { + if (isset($available_result_descriptor['pre_functions']) && $available_result_descriptor['pre_functions']) { $this->executeFunctions($available_result_descriptor['pre_functions']); } // split workflow - if (isset($available_result_descriptor['split']) && $available_result_descriptor['split']) - { + if (isset($available_result_descriptor['split']) && $available_result_descriptor['split']) { // get split result $split_descriptor = $this->getSplitDescriptor($available_result_descriptor['split']); - if (!$split_descriptor) - { + if (!$split_descriptor) { throw new SplitNotFoundException(); } // move current to history step $prevoius_id = $this->moveToHistory($current_step, $action_id); - foreach ($split_descriptor['list'] as $result_descriptor) - { + foreach ($split_descriptor['list'] as $result_descriptor) { $this->createNewCurrentStep($result_descriptor, $action_id, $prevoius_id); } - } - else if (isset($available_result_descriptor['join']) && $available_result_descriptor['join']) - { + } elseif (isset($available_result_descriptor['join']) && $available_result_descriptor['join']) { // fix me. join logic will be realized, suggest using the propertyset // get join result $join_descriptor = $this->getJoinDescriptor($available_result_descriptor['join']); - if (!$join_descriptor) - { + if (!$join_descriptor) { throw new JoinNotFoundException(); } // move current to history step $prevoius_id = $this->moveToHistory($current_step, $action_id); - if ($this->isJoinCompleted()) - { + if ($this->isJoinCompleted()) { // record other previous_ids by propertyset $this->createNewCurrentStep($join_descriptor, $action_id, $prevoius_id); } - } - else - { + } else { // move current to history step $prevoius_id = $this->moveToHistory($current_step, $action_id); // create current step $this->createNewCurrentStep($available_result_descriptor, $action_id, $prevoius_id); } // triggers after result - if (isset($available_result_descriptor['post_functions']) && $available_result_descriptor['post_functions']) - { + if (isset($available_result_descriptor['post_functions']) && $available_result_descriptor['post_functions']) { $this->executeFunctions($available_result_descriptor['post_functions']); } // triggers after action - if (isset($action_descriptor['post_functions']) && $action_descriptor['post_functions']) - { + if (isset($action_descriptor['post_functions']) && $action_descriptor['post_functions']) { $this->executeFunctions($action_descriptor['post_functions']); } } /** - * check if the join is completed + * check if the join is completed */ private function isJoinCompleted() { @@ -437,7 +398,7 @@ private function isJoinCompleted() } /** - * execute action + * execute action * * @param string $action_id * @param array $options; @@ -446,14 +407,12 @@ private function isJoinCompleted() public function doAction($action_id, $options=[]) { $state = $this->getEntryState($this->entry->id); - if ($state != self::OSWF_CREATED && $state != self::OSWF_ACTIVATED) - { + if ($state != self::OSWF_CREATED && $state != self::OSWF_ACTIVATED) { throw new StateNotActivatedException(); } $current_steps = $this->getCurrentSteps(); - if (!$current_steps) - { + if (!$current_steps) { throw new CurrentStepNotFoundException(); } @@ -467,14 +426,12 @@ public function doAction($action_id, $options=[]) * get join descriptor from list. * * @param string $join_id - * @return array + * @return array */ private function getJoinDescriptor($join_id) { - foreach ($this->wf_config['joins'] as $join) - { - if ($join['id'] == $join_id) - { + foreach ($this->wf_config['joins'] as $join) { + if ($join['id'] == $join_id) { return $join; } } @@ -485,14 +442,12 @@ private function getJoinDescriptor($join_id) * get split descriptor from list. * * @param string $split_id - * @return array + * @return array */ private function getSplitDescriptor($split_id) { - foreach ($this->wf_config['splits'] as $split) - { - if ($split['id'] == $split_id) - { + foreach ($this->wf_config['splits'] as $split) { + if ($split['id'] == $split_id) { return $split; } } @@ -504,16 +459,14 @@ private function getSplitDescriptor($split_id) * * @param array $actions * @param string $action_id - * @return array + * @return array */ private function getActionDescriptor($actions, $action_id) { // get global config $actions = $actions ?: []; - foreach ($actions as $action) - { - if ($action['id'] == $action_id) - { + foreach ($actions as $action) { + if ($action['id'] == $action_id) { return $action; } } @@ -529,10 +482,8 @@ private function getActionDescriptor($actions, $action_id) */ private function getStepDescriptor($step_id) { - foreach ($this->wf_config['steps'] as $step) - { - if ($step['id'] == $step_id) - { + foreach ($this->wf_config['steps'] as $step) { + if ($step['id'] == $step_id) { return $step; } } @@ -578,8 +529,7 @@ public function getAvailableActions($options=[], $dest_state = false) $available_actions = []; // get current steps $current_steps = $this->getCurrentSteps(); - foreach ($current_steps as $current_step) - { + foreach ($current_steps as $current_step) { $actions = $this->getAvailableActionsFromStep($current_step->step_id, $dest_state); $actions && $available_actions += $actions; } @@ -596,38 +546,29 @@ public function getAvailableActions($options=[], $dest_state = false) private function getAvailableActionsFromStep($step_id, $dest_state = false) { $step_descriptor = $this->getStepDescriptor($step_id); - if (!$step_descriptor) - { + if (!$step_descriptor) { throw new StepNotFoundException(); } - if (!isset($step_descriptor['actions']) || !$step_descriptor['actions']) - { + if (!isset($step_descriptor['actions']) || !$step_descriptor['actions']) { return []; } // global conditions for step - if (!$this->isActionAvailable($step_descriptor)) - { + if (!$this->isActionAvailable($step_descriptor)) { return []; } $available_actions = []; - foreach ($step_descriptor['actions'] as $action) - { - if ($this->isActionAvailable($action)) - { - if ($dest_state) - { + foreach ($step_descriptor['actions'] as $action) { + if ($this->isActionAvailable($action)) { + if ($dest_state) { $state = ''; - if (isset($action['results']) && is_array($action['results']) && count($action['results']) > 0 && isset($action['results'][0]['step'])) - { + if (isset($action['results']) && is_array($action['results']) && count($action['results']) > 0 && isset($action['results'][0]['step'])) { $dest_step_descriptor = $this->getStepDescriptor($action['results'][0]['step']); $state = $dest_step_descriptor['state']; } $available_actions[] = [ 'id' => $action['id'], 'name' => $action['name'], 'screen' => $action['screen'] ?: '', 'state' => $state ]; - } - else - { + } else { $available_actions[] = [ 'id' => $action['id'], 'name' => $action['name'], 'screen' => $action['screen'] ?: '' ]; } } @@ -637,7 +578,7 @@ private function getAvailableActionsFromStep($step_id, $dest_state = false) } /** - * get available result from result-list + * get available result from result-list * * @param array $results_descriptor * @return array @@ -647,18 +588,13 @@ public function getAvailableResult($results_descriptor) $available_result_descriptor = []; // confirm result whose condition is satified. - foreach ($results_descriptor as $result_descriptor) - { - if (isset($result_descriptor['conditions']) && $result_descriptor['conditions']) - { - if ($this->passesConditions($result_descriptor['conditions'])) - { + foreach ($results_descriptor as $result_descriptor) { + if (isset($result_descriptor['conditions']) && $result_descriptor['conditions']) { + if ($this->passesConditions($result_descriptor['conditions'])) { $available_result_descriptor = $result_descriptor; break; } - } - else - { + } else { $available_result_descriptor = $result_descriptor; } } @@ -673,23 +609,19 @@ public function getAvailableResult($results_descriptor) */ private function passesConditions($conditions) { - if (!isset($conditions['list']) || !$conditions['list']) - { + if (!isset($conditions['list']) || !$conditions['list']) { return true; } $type = isset($conditions['type']) && isset($conditions['type']) ? $conditions['type'] : 'and'; $result = $type == 'and' ? true : false; - foreach ($conditions['list'] as $condition) - { + foreach ($conditions['list'] as $condition) { $tmp = $this->passesCondition($condition); - if ($type == 'and' && !$tmp) - { + if ($type == 'and' && !$tmp) { return false; } - if ($type == 'or' && $tmp) - { + if ($type == 'or' && $tmp) { return true; } } @@ -715,15 +647,12 @@ private function passesCondition($condition) */ private function executeFunctions($functions) { - if (!$functions || !is_array($functions)) - { + if (!$functions || !is_array($functions)) { return; } - foreach ($functions as $function) - { - if (is_array($function) && $function) - { + foreach ($functions as $function) { + if (is_array($function) && $function) { $this->executeFunction($function); } } @@ -742,8 +671,7 @@ private function executeFunction($function) $action = isset($method[1]) && $method[1] ? $method[1] : 'handle'; // check handle function exists - if (!method_exists($class, $action)) - { + if (!method_exists($class, $action)) { throw new FunctionNotFoundException(); } $args = isset($function['args']) ? $function['args'] : []; @@ -771,8 +699,7 @@ public static function getWorkflowNames() private function genTmpVars($args=[]) { $tmp_vars = []; - foreach ($this->entry as $key => $val) - { + foreach ($this->entry as $key => $val) { $tmp_vars[$key] = $val; } $tmp_vars = array_merge($tmp_vars, $this->options); @@ -783,7 +710,7 @@ private function genTmpVars($args=[]) /** * get property set * - * @return mixed + * @return mixed */ public function getPropertySet($key) { @@ -791,9 +718,9 @@ public function getPropertySet($key) } /** - * add property set + * add property set * - * @return void + * @return void */ public function setPropertySet($key, $val) { @@ -804,7 +731,7 @@ public function setPropertySet($key, $val) /** * remove property set * - * @return void + * @return void */ public function removePropertySet($key) { @@ -820,32 +747,27 @@ public static function getStates($contents) { $state_ids = []; $steps = isset($contents['steps']) && $contents['steps'] ? $contents['steps'] : []; - foreach ($steps as $step) - { + foreach ($steps as $step) { $state_ids[] = isset($step['state']) ? $step['state'] : ''; } return $state_ids; } /** - * get used screens in the workflow + * get used screens in the workflow * - * @return array + * @return array */ public static function getScreens($contents) { $screen_ids = []; $steps = isset($contents['steps']) && $contents['steps'] ? $contents['steps'] : []; - foreach ($steps as $step) - { - if (!isset($step['actions']) || !$step['actions']) - { + foreach ($steps as $step) { + if (!isset($step['actions']) || !$step['actions']) { continue; } - foreach ($step['actions'] as $action) - { - if (!isset($action['screen']) || !$action['screen']) - { + foreach ($step['actions'] as $action) { + if (!isset($action['screen']) || !$action['screen']) { continue; } $action['screen'] != '-1' && !in_array($action['screen'], $screen_ids) && $screen_ids[] = $action['screen']; @@ -855,9 +777,9 @@ public static function getScreens($contents) } /** - * get step num + * get step num * - * @return int + * @return int */ public static function getStepNum($contents) { diff --git a/config.sh b/config.sh index 92750f8c9..8d08d5616 100644 --- a/config.sh +++ b/config.sh @@ -46,5 +46,9 @@ fi if [ `grep -c "'sync_flag'," $eloquentuserfile` -eq 0 ]; then sed -i "/fillable/a\ 'sync_flag'," $eloquentuserfile fi +#add phone field to fillable +if [ `grep -c "'phone'," $eloquentuserfile` -eq 0 ]; then + sed -i "/fillable/a\ 'phone'," $eloquentuserfile +fi echo "configure complete." diff --git a/config/database.php b/config/database.php index 6fe03b385..bed77552d 100644 --- a/config/database.php +++ b/config/database.php @@ -78,7 +78,7 @@ 'schema' => 'public', ], - 'mongodb' => [ + 'mongodb' => [ 'driver' => 'mongodb', 'host' => env('DB_HOST', 'localhost'), 'port' => env('DB_PORT', 27017), diff --git a/database/.gitignore b/database/.gitignore index 9b1dffd90..97fc97677 100644 --- a/database/.gitignore +++ b/database/.gitignore @@ -1 +1,2 @@ *.sqlite +*.sqlite-journal diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php new file mode 100644 index 000000000..5e516ceea --- /dev/null +++ b/database/factories/UserFactory.php @@ -0,0 +1,27 @@ +define(User::class, function (Faker $faker) { + return [ + 'name' => $faker->name, + 'email' => $faker->unique()->safeEmail, + 'email_verified_at' => now(), + 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password + 'remember_token' => Str::random(10), + ]; +}); diff --git a/database/migrations/2014_10_12_000000_create_users_table.php b/database/migrations/2014_10_12_000000_create_users_table.php index 59aa01a55..4a3ba4723 100644 --- a/database/migrations/2014_10_12_000000_create_users_table.php +++ b/database/migrations/2014_10_12_000000_create_users_table.php @@ -1,5 +1,6 @@ increments('id'); + $table->bigIncrements('id'); $table->string('name'); $table->string('email')->unique(); + $table->timestamp('email_verified_at')->nullable(); $table->string('password'); $table->rememberToken(); $table->timestamps(); @@ -29,6 +31,6 @@ public function up() */ public function down() { - Schema::drop('users'); + Schema::dropIfExists('users'); } } diff --git a/database/migrations/2014_10_12_100000_create_password_resets_table.php b/database/migrations/2014_10_12_100000_create_password_resets_table.php index 294c3ea40..0d5cb8450 100644 --- a/database/migrations/2014_10_12_100000_create_password_resets_table.php +++ b/database/migrations/2014_10_12_100000_create_password_resets_table.php @@ -1,5 +1,6 @@ string('email')->index(); - $table->string('token')->index(); + $table->string('token'); $table->timestamp('created_at')->nullable(); }); } @@ -26,6 +27,6 @@ public function up() */ public function down() { - Schema::drop('password_resets'); + Schema::dropIfExists('password_resets'); } } diff --git a/database/migrations/2019_08_19_000000_create_failed_jobs_table.php b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php new file mode 100644 index 000000000..d432dff08 --- /dev/null +++ b/database/migrations/2019_08_19_000000_create_failed_jobs_table.php @@ -0,0 +1,35 @@ +bigIncrements('id'); + $table->text('connection'); + $table->text('queue'); + $table->longText('payload'); + $table->longText('exception'); + $table->timestamp('failed_at')->useCurrent(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::dropIfExists('failed_jobs'); + } +} diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index e119db624..91cb6d1c2 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -5,7 +5,7 @@ class DatabaseSeeder extends Seeder { /** - * Run the database seeds. + * Seed the application's database. * * @return void */ diff --git a/front-end b/front-end index 334c50452..eabc08b48 160000 --- a/front-end +++ b/front-end @@ -1 +1 @@ -Subproject commit 334c50452c7a01a98b0b80b284d719c4961fdcc4 +Subproject commit eabc08b4807e2f84fad60873c1866b66b7d8907e