예제 #1
0
파일: Job.php 프로젝트: pshon/vcapi
 /**
  * @param $energy
  * @return array|bool
  * @throws \ErrorException
  */
 public function doWork($energy)
 {
     if (!$this->worker) {
         return Error::exception("User doesn't work now");
     }
     if (!User::getInstance($this->instanceIdentifier)->energy || User::getInstance($this->instanceIdentifier)->energy < $energy) {
         return Error::exception('No energy');
     }
     if ($energy === 0) {
         $energy = User::getInstance($this->instanceIdentifier)->energy;
     }
     if (!($energy = intval($energy))) {
         return Error::exception('Energy must be bigger than null');
     }
     $energy = $this->splitEnergy($energy);
     $statistic = array('energy' => 0, 'salary' => 0, 'experience' => 0, 'production_points' => 0);
     foreach ($energy as $value) {
         $query = array('data' => array('User' => array('energy' => $value), 'Company' => array('id' => $this->companyId)));
         $result = Request::post('/users/begin_work.json', $query, $this->instanceIdentifier);
         $statistic['energy'] += $result->work_report->user_energy_spent;
         $statistic['salary'] += $result->short_work_report->salary;
         $statistic['experience'] += $result->short_work_report->exp;
         $statistic['production_points'] += $result->short_work_report->today_production_points;
     }
     return $statistic;
 }
예제 #2
0
 /**
  * @return mixed
  * @throws \ErrorException
  */
 public function getShortList()
 {
     $result = Request::get('/corporations/corporation_list.json', $this->instanceIdentifier);
     if (!empty($result->error)) {
         Error::exception($result->setFlash[0]->msg);
     }
     return $result->corporations;
 }
예제 #3
0
파일: Vacancy.php 프로젝트: pshon/vcapi
 public function getJob()
 {
     if (User::getInstance()->UserLevel->level < $this->level) {
         Error::exception('User professional level is low, be need ' . $this->level . ' level or higher');
         return false;
     }
     $result = Request::post('/vacancies/work_vacancy.json', array('data' => array('CompanyVacancy' => array('id' => $this->id))), $this->instanceIdentifier);
     return $result;
 }
예제 #4
0
파일: Worker.php 프로젝트: pshon/vcapi
 /**
  * @param $companyId
  * @param $level
  * @param $qty
  * @return bool
  * @throws \ErrorException
  */
 public function hire($companyId, $level, $qty)
 {
     $typeId = $this->getTypeIdByLevel($level);
     $qty = intval($qty);
     if ($typeId) {
         Error::exception('Bad worker level.');
         return false;
     }
     $result = Request::post('/company_foreign_workers/add/' . $companyId . '/' . $typeId . '/' . $qty . '.json', array(), $this->instanceIdentifier);
     if (!empty($result->error)) {
         Error::exception($result->setFlash[0]->msg);
         return false;
     }
     return true;
 }
예제 #5
0
파일: Company.php 프로젝트: pshon/vcapi
 /**
  * @return bool
  * @throws \ErrorException
  */
 public function saveVacancy()
 {
     $query = array('data' => array('CompanyVacancy' => array('company_id' => $this->id, 'salary' => $this->vacancy->salary, 'level' => $this->vacancy->level, 'is_hiring' => $this->vacancy->is_hiring)));
     $result = Request::post('/vacancies/save_vacancy.json', $query);
     if (!empty($result->error)) {
         Error::exception($result->setFlash[0]->msg);
     }
     return true;
 }
예제 #6
0
파일: Corporation.php 프로젝트: pshon/vcapi
 /**
  * @param $production
  * @param $count
  * @param $price
  * @param string $currency
  * @return bool
  * @throws \ErrorException
  */
 public function sellProduction($production, $count, $price, $currency = 'vdollars')
 {
     $result = Request::post('/exchanges/add_corporation_exchange.json', array('data' => array('Exchange' => array('price' => floatval($price), 'currency' => $currency, 'number' => $count, 'item_type_id' => $production instanceof Product ? $production->id : $production, 'corporation_id' => $this->id))), $this->instanceIdentifier);
     if (!empty($result->error)) {
         Error::exception($result->setFlash[0]->msg);
         return false;
     }
     return true;
 }
예제 #7
0
파일: User.php 프로젝트: pshon/vcapi
 /**
  * Get all companies that belong to user
  *
  * @return \VCAPI\Common\Collection
  * @throws \ErrorException
  */
 public function getCompanies()
 {
     $result = Request::get('/companies/user_companies.json', $this->instanceIdentifier);
     if (empty($result->userId)) {
         return Error::exception('Authorization error');
     }
     $companies = new Collection();
     foreach ($result->companies as $company) {
         $companies->add(new Company($company->Company, $this->instanceIdentifier));
     }
     return $companies;
 }