Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace app\modules\api\controllers\v1;
- use app\components\rest\Controller;
- use app\modules\salary\models\Office;
- use app\modules\salary\models\WorkingShift;
- use Yii;
- /**
- * Class MercuryController
- * @package app\modules\api\controllers\v1
- */
- class MercuryController extends Controller
- {
- /**
- * @return array
- */
- public function actionGetOffices()
- {
- $data = Office::find()
- ->joinWith([
- 'country',
- 'callCenters',
- 'people',
- 'callCenterToOffices',
- 'workingShifts',
- 'taxes',
- 'staffing',
- 'currency'
- ])
- ->active()
- ->all();
- $offices = [];
- foreach ($data as $office) {
- $offices[] = [
- 'id' => $office->id,
- 'country_ru' => $office->country->name,
- 'country_en' => $office->country->name_en,
- 'type' => $office->type,
- 'name_ru' => $office->name,
- 'shift' => $this->compareWorkingShifts($office->getWorkingShifts()->all()),
- 'position' => $this->compareStaffings($office->staffing)
- ];
- break;
- }
- $this->responseData['data'] = $offices;
- return $this->success();
- }
- /**
- * @param $shiftsData
- * @return array
- */
- public function compareWorkingShifts($shiftsData)
- {
- $shifts = [];
- foreach ($shiftsData as $shift) {
- $shifts[] = [
- 'id' => $shift->id,
- 'name' => $shift->name,
- 'description' => [
- 'lunch_time' => $shift->lunch_time,
- 'working_mon' => $shift->working_mon,
- 'working_tue' => $shift->working_tue,
- 'working_wed' => $shift->working_wed,
- 'working_thu' => $shift->working_thu,
- 'working_fri' => $shift->working_fri,
- 'working_sat' => $shift->working_sat,
- 'working_sun' => $shift->working_sun
- ]
- ];
- }
- return $shifts;
- }
- /**
- * @param $staffings
- * @return array
- */
- public function compareStaffings($staffings)
- {
- $positions = [];
- foreach ($staffings as $staffing) {
- $positions[] = [
- 'id' => $staffing->id,
- 'name_ru' => $staffing->designation->name,
- 'name_en' => yii::t('common', $staffing->designation->name, [], 'en-US'),
- 'salary_usd' => $staffing->salary_usd,
- 'salary_local' => $staffing->salary_local,
- 'lead' => $staffing->designation->team_lead
- ];
- }
- return $positions;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement