vcapi is a non-official VirCities API implementation for PHP 5.3+
- PHP 5.3.x is required
- Install VCAPI using Composer (recommended) or manually
- Install CURL library for php (if not yer installed)
- Get Composer
- Require VCAPI with
php composer.phar require vircities/vcapi:dev-master
(currently not available stable release) - Add the following to your application's main PHP file:
require 'vendor/autoload.php';
Example 1 - Get user balance
<?php
require_once __DIR__ . '/vendor/autoload.php';
$user = \VCAPI\Model\User::getInstance();
if(!$user->auth('login', 'password')) {
echo "Not logged";
} else {
echo 'My balance: ' . $user->vd_balance . ' vd';
}
Example 2 - Vacancies and work
// If you want to login, use the previous example
$vacancies = new \VCAPI\Model\Vacancies();
// show all vacancies
print_r($vacancies->getList());
// show vacancies by company id
print_r($vacancies->getListByCompanyId($companyId));
// get a job
$vacancy = $vacancies->getListByCompanyId($companyId)[0];
$vacancy->getJob();
// do work of 100 energy points
$job = new \VCAPI\Model\Job();
$job->doWork(100);
Example 3 - Companies
// Get all companies that belong to user
$user = \VCAPI\Model\User::getInstance();
print_r($user->getCompanies());
// or load company information by ID
var_dump(\VCAPI\Model\Company::loadById($companyId))
Example 4 - Use collection features
$user = \VCAPI\Model\User::getInstance();
// return corporations collection
print_r($user->getCorporations());
// Find corporation with name "My Corporation"
$corporation = $user->getCorporations()->find('name', 'My Corporation')->item(0);
// Get corporation storage and sort items by quantity
print_r($corporation->getStorage()->sort('quantity', 'DESC'));
If you need debug mode, add this code on top:
\VCAPI\Common\Request::$debug = true;
Below is a list of the public methods in the common classes you will most likely use.
User::
auth($login, $password) // Authorization
getShortInfo() // Assign user info on current instance
getFullInfo() // Return extended user information
getCompanies() // Return all companies collection that belong to user
getCorporations() // Return all corporations collection which shares belong to user
unAuth() // Detach user session
$id // Current user id
$avatar // Avatar id
$avatar_img // Avatar img
$username //
$vd_balance // Current user balance in VD
$vg_balance // Current user balance in VG
$fight_points //
$health // Current user health
$max_health // Max user health
$energy // Current user energy
$max_energy // Max user energy
$prestige // Level of prestige
$social_status_title // Social status title (Горожанин, ...)
$social_status // Social status (CITIZEN, ...)
$city_id // City id
$city_name // City name
$party_name //
$last_up_energy //
$delta_recovery_energy //
$military_rank //
$military_rank_img //
$UserLevel // \VCAPI\Model\UserLevel (level, xp, nextLevelExperience)
$City // \VCAPI\Model\City (id, name)
$MilitaryRank // \VCAPI\Model\MilitaryRank (name, image)
Company::
loadById() // Load company information by id (static method)
getProductionList() //
setProductionId() //
setManagerId() //
getStorage() //
moveItemToCorporation() //
getWorkers() //
addForeignWorker() //
deleteWorker() //
deleteForeignWorker() //
deleteUserWorker() //
takeMoney() //
addMoney() //
saveVacancy() //
reopenVacancy() //
$id // Company id
$name // Company name
$company_type // CompanyType object
$city // Name of city (string)
$type //
$master_type //
$corporation_master //
$company_level //
$products_sold //
$take_funds //
$produced_items //
$company_income //
$storage_level //
$production_status //
$production_status_title //
$currently_producing // Is company currently producing smth or not (bool)
$private //
$manager_id //
$user_id //
$vd_balance //
$vg_balance //
$current_production // CompanyProduction object
$workersAllCnt //
$workersForeignCnt //
$workplaces //
$workers //
$vacancy //
MilitaryRank::
$name //
$image //
UserLevel::
$level //
$xp //
$nextLevelExperience //
Corporation::
*in process...*
Job::
*in process...*
Worker::
*in process...*
Vacancy::
*in process...*
Vacancies::
*in process...*
Product::
*in process...*
City::
getCitiesList() // Get list of cities (id => name)
getNameById() // Get city name by ID
$id //
$name //
Product::
*in process...*
Method name | Parameters | Description |
---|---|---|
getItemsGroups() | ||
getBusinessGroups() | ||
getAvailableItemGroups() | ||
getAvailableBusinessGroups() | ||
getAvailableStock() | ||
getAvailableCurrency() | ||
getAvailableItems() | ||
getCurrencyLotsList() | ||
getCurrencyLotsByType() | $type | |
getLotsList() | $category $itemName | |
getLotsListCityHall() | ||
getItemTypesList() | $category | |
getLotsOffer() | $currency, $itemTypeId, $sort, $direction | Get lots of offers by currency (vdollars OR vgold) and Item Type ID |
This code is shown here for informational purposes. Its use is prohibited administration VirCities. Use this code you can at your own risk. The author of the code does not carry responsible for the consequences that may result from using this code.
(MIT License)
Copyright (c) 2010 Chris O'Hara cohara87@gmail.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.