PluginProbe
ShiftController Employee Shift Scheduling / 4.9.66
ShiftController Employee Shift Scheduling v4.9.66
4.9.97 4.9.96 4.9.95 4.9.74 4.9.75 4.9.76 4.9.77 4.9.78 4.9.84 4.9.85 4.9.87 4.9.91 4.9.92 trunk 2.1.0 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 3.2.4 All 38 releases
← All changes | sh4/api/api.php +0 -273 4.9.774.9.66 View file →
@@ -12,15 +12,12 @@
12 12 HC3_IPermission $permission,
13 13 HC3_Translate $translate,
14 14
15 15 SH4_Employees_Query $employeesQuery,
16 - SH4_Employees_Command $employeesCommand,
17 16 SH4_Calendars_Query $calendarsQuery,
18 - SH4_Calendars_Presenter $calendarPresenter,
19 17 SH4_Shifts_Presenter $shiftsPresenter,
20 18
21 19 SH4_App_Query $appQuery,
22 - SH4_App_Command $appCommand,
23 20 SH4_Employees_Presenter $employeePresenter,
24 21
25 22 SH4_Shifts_Conflicts $conflicts,
26 23 // SH4_Shifts_Acl $shiftsAcl,
@@ -32,14 +29,11 @@
32 29 $this->translate = $translate;
33 30 $this->permission = $hooks->wrap( $permission );
34 31
35 32 $this->employeesQuery = $hooks->wrap( $employeesQuery );
36 - $this->employeesCommand = $hooks->wrap( $employeesCommand );
37 33 $this->calendarsQuery = $hooks->wrap( $calendarsQuery );
38 - $this->calendarPresenter = $hooks->wrap( $calendarPresenter );
39 34 $this->employeePresenter = $hooks->wrap( $employeePresenter );
40 35 $this->appQuery = $hooks->wrap( $appQuery );
41 - $this->appCommand = $hooks->wrap( $appCommand );
42 36
43 37 $this->shiftsPresenter = $hooks->wrap( $shiftsPresenter );
44 38 $this->conflicts = $hooks->wrap($conflicts);
45 39 $this->shiftsQuery = $hooks->wrap( $shiftsQuery );
@@ -51,21 +45,8 @@
51 45 add_filter( 'shiftcontroller4/api/shifts/getbyid', array($this->self, 'shiftsGetById'), 10, 1 );
52 46 add_filter( 'shiftcontroller4/api/shifts/create', array($this->self, 'shiftsCreate'), 10, 1 );
53 47 add_filter( 'shiftcontroller4/api/shifts/deletebyid', array($this->self, 'shiftsDeleteById'), 10, 1 );
54 48 add_filter( 'shiftcontroller4/api/shifts/updatebyid', array($this->self, 'shiftsUpdateById'), 10, 2 );
55 -
56 - add_filter( 'shiftcontroller4/api/employees/get', array($this->self, 'employeesGet'), 10, 1 );
57 - add_filter( 'shiftcontroller4/api/employees/getbyid', array($this->self, 'employeesGetById'), 10, 1 );
58 - add_filter( 'shiftcontroller4/api/employees/create', array($this->self, 'employeesCreate'), 10, 1 );
59 - add_filter( 'shiftcontroller4/api/employees/getbyuserid', array($this->self, 'employeesGetByUserId'), 10, 1 );
60 - add_filter( 'shiftcontroller4/api/employees/createbyuserid', array($this->self, 'employeesCreateByUserId'), 10, 1 );
61 -
62 - add_filter( 'shiftcontroller4/api/calendars/get', array($this->self, 'calendarsGet'), 10, 1 );
63 - add_filter( 'shiftcontroller4/api/employees/getbycalendarid', array($this->self, 'employeesGetByCalendarId'), 10, 1 );
64 - add_filter( 'shiftcontroller4/api/employees/addtocalendar', array($this->self, 'employeesAddToCalendar'), 10, 2 );
65 - add_filter( 'shiftcontroller4/api/employees/removefromcalendar', array($this->self, 'employeesRemoveFromCalendar'), 10, 2 );
66 -
67 - add_filter( 'shiftcontroller4/api/calendars/getbyemployeeid', array($this->self, 'calendarsGetByEmployeeId'), 10, 1 );
68 49 }
69 50
70 51 public function toArrayEmployee( array $employeeList )
71 52 {
@@ -85,27 +66,8 @@
85 66
86 67 return $out;
87 68 }
88 69
89 - public function toArrayCalendar( array $list )
90 - {
91 - $out = array();
92 -
93 - foreach( $list as $e ){
94 - $thisOut = $this->calendarPresenter->export( $e, true );
95 -
96 - $keys = array_keys( $thisOut );
97 - reset( $keys );
98 - foreach( $keys as $k ){
99 - $thisOut[$k] = $this->translate->translate( $thisOut[$k] );
100 - }
101 -
102 - $out[] = $thisOut;
103 - }
104 -
105 - return $out;
106 - }
107 -
108 70 public function toArray( array $shifts )
109 71 {
110 72 $out = array();
111 73
@@ -676,241 +638,6 @@
676 638 $this->shiftsCommand->unpublish( $shift );
677 639 }
678 640
679 641 return;
680 - }
681 -
682 - public function employeesGet( $queryParams = array() )
683 - {
684 - $args = array();
685 - $ret = $this->employeesQuery->read();
686 - $ret = $this->self->toArrayEmployee( $ret );
687 - return $ret;
688 - }
689 -
690 - public function calendarsGet( $queryParams = array() )
691 - {
692 - $args = array();
693 - $ret = $this->calendarsQuery->read();
694 - $ret = $this->self->toArrayCalendar( $ret );
695 - return $ret;
696 - }
697 -
698 - public function employeesGetById( $id )
699 - {
700 - $args = array();
701 - $ret = $this->employeesQuery->findById( $id );
702 - if( ! $ret ){
703 - return new WP_Error( 'no_employee', 'Not Found', array('status' => 404) );
704 - }
705 -
706 - $ret = [ $ret ];
707 - $ret = $this->self->toArrayEmployee( $ret );
708 - $ret = current( $ret );
709 - return $ret;
710 - }
711 -
712 - public function employeesGetByUserId( $userId )
713 - {
714 - $employee = $this->appQuery->findEmployeeByUserId( $userId );
715 - if( ! $employee ){
716 - return new WP_Error( 'no_employee', 'Not Found', array('status' => 404) );
717 - }
718 -
719 - $employees = array( $employee );
720 - $ret = $this->self->toArrayEmployee( $employees );
721 - $ret = array_shift( $ret );
722 -
723 - return $ret;
724 - }
725 -
726 - public function employeesGetByCalendarId( $calendarId )
727 - {
728 - $calendar = $this->calendarsQuery->findById( $calendarId );
729 - if( ! $calendar ){
730 - return new WP_Error( 'no_calendar', 'Not Found', array('status' => 404) );
731 - }
732 -
733 - $employees = $this->appQuery->findEmployeesForCalendar( $calendar );
734 - $ret = $this->self->toArrayEmployee( $employees );
735 -
736 - return $ret;
737 - }
738 -
739 - public function calendarsGetByEmployeeId( $employeeId )
740 - {
741 - $employee = $this->employeesQuery->findById( $employeeId );
742 - if( ! $employee ){
743 - return new WP_Error( 'no_employee', 'Not Found', array('status' => 404) );
744 - }
745 -
746 - $calendars = $this->appQuery->findCalendarsForEmployee( $employee );
747 - $ret = $this->self->toArrayCalendar( $calendars );
748 -
749 - return $ret;
750 - }
751 -
752 -/* returns employee id */
753 - public function employeesCreate( $values )
754 - {
755 - $errors = array();
756 -
757 - $userId = isset( $values['user_id'] ) ? $values['user_id'] : null;
758 - $title = isset( $values['title'] ) ? $values['title'] : null;
759 -
760 - if( $userId ){
761 - // check if there's an employee linked to that user
762 - $employee = $this->appQuery->findEmployeeByUserId( $userId );
763 - if( $employee ){
764 - return new WP_Error( 'user_occupied', 'The user is already linked to another employee', array('status' => 500) );
765 - }
766 -
767 - $wpUser = get_user_by( 'id', $userId );
768 - if( ! $wpUser ){
769 - return new WP_Error( 'no_user', 'User not found', array('status' => 404) );
770 - }
771 - }
772 -
773 - if( (! $userId) && (null === $title) ){
774 - $errors['title'] = 'Required Field';
775 - }
776 - $description = isset( $values['description'] ) ? $values['description'] : null;
777 -
778 - if( $errors ){
779 - $errorStr = array();
780 - foreach( $errors as $k => $v ) $errorStr[] = $k . ': ' . $v;
781 - $errorStr = join( ', ', $errorStr );
782 - return new WP_Error( 'error', $errorStr, array('status' => 500) );
783 - }
784 -
785 - try {
786 - // create by user id
787 - if( null === $title ){
788 - $employeeId = $this->self->employeesCreateByUserId( $userId );
789 - }
790 - else {
791 - $employeeId = $this->employeesCommand->create( $title, $description );
792 - }
793 - }
794 - catch( HC3_ExceptionArray $e ){
795 - $errors = $e->getErrors();
796 - }
797 -
798 - if( $errors ){
799 - $errorStr = array();
800 - foreach( $errors as $k => $v ) $errorStr[] = $k . ': ' . $v;
801 - $errorStr = join( ', ', $errorStr );
802 - return new WP_Error( 'error', $errorStr, array('status' => 500) );
803 - }
804 -
805 - if( ! $userId ){
806 - return $employeeId;
807 - }
808 -
809 - // link user to employee
810 - if( null !== $title ){
811 - $this->appCommand->linkEmployeeToUserById( $employeeId, $userId );
812 - }
813 -
814 - return $employeeId;
815 - }
816 -
817 -/* returns employee id */
818 - public function employeesCreateByUserId( $userId )
819 - {
820 - $employee = $this->appQuery->findEmployeeByUserId( $userId );
821 - if( $employee ){
822 - $ret = $employee->getId();
823 - return $ret;
824 - }
825 -
826 - $wpUser = get_user_by( 'id', $userId );
827 - if( ! $wpUser ){
828 - return new WP_Error( 'no_user', 'User not found', array('status' => 404) );
829 - }
830 -
831 - $title = $wpUser->display_name;
832 - $description = null;
833 -
834 - try {
835 - $employeeId = $this->employeesCommand->create( $title, $description );
836 - }
837 - catch( HC3_ExceptionArray $e ){
838 - $errors = $e->getErrors();
839 - }
840 -
841 - if( $errors ){
842 - $errorStr = array();
843 - foreach( $errors as $k => $v ) $errorStr[] = $k . ': ' . $v;
844 - $errorStr = join( ', ', $errorStr );
845 - return new WP_Error( 'error', $errorStr, array('status' => 500) );
846 - }
847 -
848 - // link user to employee
849 - $this->appCommand->linkEmployeeToUserById( $employeeId, $userId );
850 -
851 - return $employeeId;
852 - }
853 -
854 -/* returns employee id */
855 - public function employeesAddToCalendar( $employeeId, $calendarId )
856 - {
857 - $errors = array();
858 -
859 - $employee = $this->employeesQuery->findById( $employeeId );
860 - if( ! $employee ){
861 - return new WP_Error( 'no_employee', 'Not found', array('status' => 404) );
862 - }
863 -
864 - $calendar = $this->calendarsQuery->findById( $calendarId );
865 - if( ! $calendar ){
866 - return new WP_Error( 'no_calendar', 'Not found', array('status' => 404) );
867 - }
868 -
869 - try {
870 - $this->appCommand->addEmployeeToCalendar( $employee, $calendar );
871 - }
872 - catch( HC3_ExceptionArray $e ){
873 - $errors = $e->getErrors();
874 - }
875 -
876 - if( $errors ){
877 - $errorStr = array();
878 - foreach( $errors as $k => $v ) $errorStr[] = $k . ': ' . $v;
879 - $errorStr = join( ', ', $errorStr );
880 - return new WP_Error( 'error', $errorStr, array('status' => 500) );
881 - }
882 -
883 - return true;
884 - }
885 -
886 - public function employeesRemoveFromCalendar( $employeeId, $calendarId )
887 - {
888 - $errors = array();
889 -
890 - $employee = $this->employeesQuery->findById( $employeeId );
891 - if( ! $employee ){
892 - return new WP_Error( 'no_employee', 'Not found', array('status' => 404) );
893 - }
894 -
895 - $calendar = $this->calendarsQuery->findById( $calendarId );
896 - if( ! $calendar ){
897 - return new WP_Error( 'no_calendar', 'Not found', array('status' => 404) );
898 - }
899 -
900 - try {
901 - $this->appCommand->removeEmployeeFromCalendar( $employee, $calendar );
902 - }
903 - catch( HC3_ExceptionArray $e ){
904 - $errors = $e->getErrors();
905 - }
906 -
907 - if( $errors ){
908 - $errorStr = array();
909 - foreach( $errors as $k => $v ) $errorStr[] = $k . ': ' . $v;
910 - $errorStr = join( ', ', $errorStr );
911 - return new WP_Error( 'error', $errorStr, array('status' => 500) );
912 - }
913 -
914 - return true;
915 642 }
916 643 }