- This topic has 9 replies, 4 voices, and was last updated 5 years, 3 months ago by webbna.
-
AuthorPosts
-
-
May 4, 2017 at 2:03 am #6880JuacOHIParticipant
Hello, first of all, great plugin, I’ve been trying to figure out if its all what i need to implement it in a small business and so far its all good. Planning to buy the extension to add documents.
BUT!, I’ve a problem, and that would be that I need to create kind of a role, or add some line of code to make/let people only edit employees that are in the same Location.If i check the lines of codes in “single php”, in the actions box, i think that i could use something similar to (couldn’t past the whole code, but you get the idea):
if ( $employee->get_status() != 'Terminated' && current_user_can( 'erp_create_employee' ) ):
Or add a condition in:
if ( current_user_can( 'erp_edit_employee', $employee->id ) ) {
Is it possible ?. Its the only thing that i think that is missing so far.- This topic was modified 7 years, 7 months ago by JuacOHI. Reason: formatting
-
May 4, 2017 at 12:42 pm #6901Shawon ChowdhuryModerator
@juacohi,
Thanks for writing. But I am a little bit confused about the use case.
It would be great if you can make me clear on the use case of this role π -
May 4, 2017 at 9:01 pm #6905JuacOHIParticipant
Sorry if i wasn’t clear.
I’m asking if is possible to only let people edit employees that are from the same location. (From ERP Settings -> Locations), which when you add a new employee is this data: (I deleted the part that it says php becaue can’t paste php code)
<li data-selected="{{ data.work.location }}">
erp_html_form_input( array(
'label' => __( 'Location', 'erp' ),
'name' => 'work[location]',
'value' => '{{ data.work.location }}',
'custom_attr' => array( 'data-id' => 'erp-company-new-location' ),
// 'class' => 'erp-hrm-select2-add-more erp-hr-location-drop-down',
'class' => 'erp-hrm-select2',
'type' => 'select',
'options' => erp_company_get_location_dropdown_raw()
) );
So, in resume if I have 3 locations (main location, second and third), and I have an employee that can manage HRM , and this person is from Main Location, only let him edit employees that are from Main Location and NOT from second and third.
After taking in consideration what i just said, if i go to single.php (where you can find all the code to show the employee), I think that I could add a condition in the button edit to ONLY show that button if i’m from the same Location, and if not, hide the button but i can still see the employee from other locations.So I think that the code would be something like… get current user and ask his location, and then ask the location of the employee that i’m seeing, and if both match, let me edit that employee.
My best guess is that it should be in this line of code, which is when it shows the edit button in the Action Box.
<h3 class="hndle"><span>( 'Actions', 'erp' ); ?></span></h3>
<div class="inside">if ( current_user_can( 'erp_edit_employee', $employee->id ) ) {
<span class="edit">id; ?>" data-single="true" href="#">_e( 'Edit', 'erp' ); ?></span>
}
-
May 7, 2017 at 10:05 am #6911Shawon ChowdhuryModerator
This is the file location where the capabilities have been set up.
modules/hrm/includes/functions-capabilities.php
line no 138
And you can use this filtererp_hr_map_meta_caps
and make a plugin to manage custom roles instead of changing the core codes.Thanks and feel free to let me know if you need more help from me π
-
May 10, 2017 at 1:54 am #7014JuacOHIParticipant
Mhm.. sadly I’m not so good in PHP or making plugins to make one for custom roles and things like that.. For me its easier to add some line of code and “fix/patch” it to what i need..
Can you help me with this ?, how can i ask to get the current user work location ? so i could add an IF asking something like this:
if ( $employee->get_work_location () == current_user_work_location () ){
With that line of code i could get what i want, i just don’t know how to get the current user work location.
-
-
May 11, 2017 at 9:56 am #7030Shawon ChowdhuryModerator
βI’ve added a new function
get_work_location_id
. So now you can write condition like this…
β
βager = new \WeDevs\ERP\HRM\Employee( get_current_user_id() );
if ( $employee->get_work_location_id() === $manager->get_work_location_id() ) {
// write your code here
}Thanks π
-
May 14, 2017 at 11:11 pm #7066JuacOHIParticipant
Thanks! That works really good and I’m sure that a lot people will be happy with this easy fix π
btw you copy/pasted it wront, because it should be:
$manβager = new \WeDevs\ERP\HRM\Employee( get_current_user_id() );
if ( $employee->get_work_location_id() === $manager->get_work_location_id() ) {
// write your code here
}
You missed the “$man”Thanks for the quick help!!
-
May 15, 2017 at 7:48 am #7067Shawon ChowdhuryModerator
@JuacOHI,
Yeah, you got it right. Copy paste mistake π
BTW glad to hear that it worked for you.Cheers π
- This reply was modified 7 years, 7 months ago by Shawon Chowdhury.
-
July 9, 2018 at 4:00 pm #18985
-
September 18, 2019 at 1:37 am #52805webbnaParticipant
I am trying to do something similar to this but using departments. Is that possible?
-
-
AuthorPosts
- The forum ‘HRM’ is closed to new topics and replies.