Roles or Edit only in the same Location

Home Forums HRM Roles or Edit only in the same Location

Tagged: , , , ,

Viewing 8 reply threads
  • Author
    • #6880

      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, 1 month ago by JuacOHI. Reason: formatting
    • #6901
      Shawon Chowdhury

      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 πŸ™‚

    • #6905

      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="{{ }}">
      erp_html_form_input( array(
      'label' => __( 'Location', 'erp' ),
      'name' => 'work[location]',
      'value' => '{{ }}',
      '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>

    • #6911
      Shawon Chowdhury


      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 filter erp_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 πŸ™‚

      • #7014

        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.

    • #7030
      Shawon Chowdhury


      ​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 πŸ™‚

    • #7066

      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!!

    • #7067
      Shawon Chowdhury

      Yeah, you got it right. Copy paste mistake πŸ™
      BTW glad to hear that it worked for you.

      Cheers πŸ™‚

    • #18985
    • #52805

      I am trying to do something similar to this but using departments. Is that possible?

Viewing 8 reply threads
  • The forum ‘HRM’ is closed to new topics and replies.

Contact Us

Reach out to us for any inquiry

You must enter full name
You must enter email
You must enter message

We received your query

We will reply to you very soon :)