Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2018
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.90 KB | None | 0 0
  1. <?php
  2.  
  3. namespace app\modules\api\controllers\v1;
  4.  
  5. use app\components\rest\Controller;
  6. use app\modules\salary\models\Office;
  7. use app\modules\salary\models\WorkingShift;
  8. use Yii;
  9.  
  10. /**
  11.  * Class MercuryController
  12.  * @package app\modules\api\controllers\v1
  13.  */
  14. class MercuryController extends Controller
  15. {
  16.     /**
  17.      * @return array
  18.      */
  19.     public function actionGetOffices()
  20.     {
  21.         $data = Office::find()
  22.             ->joinWith([
  23.                 'country',
  24.                 'callCenters',
  25.                 'people',
  26.                 'callCenterToOffices',
  27.                 'workingShifts',
  28.                 'taxes',
  29.                 'staffing',
  30.                 'currency'
  31.             ])
  32.             ->active()
  33.             ->all();
  34.  
  35.         $offices = [];
  36.  
  37.         foreach ($data as $office) {
  38.             $offices[] = [
  39.                 'id' => $office->id,
  40.                 'country_ru' => $office->country->name,
  41.                 'country_en' => $office->country->name_en,
  42.                 'type' => $office->type,
  43.                 'name_ru' => $office->name,
  44.                 'shift' => $this->compareWorkingShifts($office->getWorkingShifts()->all()),
  45.                 'position' => $this->compareStaffings($office->staffing)
  46.             ];
  47.             break;
  48.         }
  49.  
  50.         $this->responseData['data'] = $offices;
  51.  
  52.         return $this->success();
  53.     }
  54.  
  55.     /**
  56.      * @param $shiftsData
  57.      * @return array
  58.      */
  59.     public function compareWorkingShifts($shiftsData)
  60.     {
  61.         $shifts = [];
  62.  
  63.         foreach ($shiftsData as $shift) {
  64.             $shifts[] = [
  65.                 'id' => $shift->id,
  66.                 'name' => $shift->name,
  67.                 'description' => [
  68.                     'lunch_time' => $shift->lunch_time,
  69.                     'working_mon' => $shift->working_mon,
  70.                     'working_tue' => $shift->working_tue,
  71.                     'working_wed' => $shift->working_wed,
  72.                     'working_thu' => $shift->working_thu,
  73.                     'working_fri' => $shift->working_fri,
  74.                     'working_sat' => $shift->working_sat,
  75.                     'working_sun' => $shift->working_sun
  76.                 ]
  77.             ];
  78.  
  79.         }
  80.  
  81.         return $shifts;
  82.     }
  83.  
  84.     /**
  85.      * @param $staffings
  86.      * @return array
  87.      */
  88.     public function compareStaffings($staffings)
  89.     {
  90.         $positions = [];
  91.  
  92.         foreach ($staffings as $staffing) {
  93.             $positions[] = [
  94.                 'id' => $staffing->id,
  95.                 'name_ru' => $staffing->designation->name,
  96.                 'name_en' => yii::t('common', $staffing->designation->name, [], 'en-US'),
  97.                 'salary_usd' => $staffing->salary_usd,
  98.                 'salary_local' => $staffing->salary_local,
  99.                 'lead' => $staffing->designation->team_lead
  100.             ];
  101.         }
  102.  
  103.         return $positions;
  104.     }
  105.  
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement