Ejemplo n.º 1
0
Archivo: Job.php Proyecto: 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;
 }
Ejemplo n.º 2
0
 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;
 }
Ejemplo n.º 3
0
Archivo: User.php Proyecto: pshon/vcapi
 /**
  * @param $login
  * @param $pass
  * @return bool
  * @throws \ErrorException
  */
 public function auth($login, $pass)
 {
     $this->unAuth();
     $result = Request::post('/users/app_auth.json', array('data' => array('User' => array('username' => $login, 'password' => $pass))), $this->instanceIdentifier);
     $this->getShortInfo();
     if (empty($this->id)) {
         return Error::exception('Authorization error');
     }
     return true;
 }
Ejemplo n.º 4
0
 /**
  * @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;
 }
Ejemplo n.º 5
0
 /**
  * @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;
 }
Ejemplo n.º 6
0
 /**
  * @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;
 }