Example #1
0
 public function getIndex()
 {
     $key = Input::get('search');
     if (isset($key)) {
         $data = Type::where('name', 'like', '%' . $key . '%')->orderBy('id', 'desc')->paginate(10);
     } else {
         $data = Type::orderBy('id', 'desc')->paginate(10);
     }
     return View::make('home/dashboard', array())->nest('content', 'Type/index', array('data' => $data));
 }
 public function index()
 {
     $arrReturn = array();
     $typeObj = Type::where('short_name', Request::path())->first();
     $type_id = '1';
     // pr($typeObj);die;
     if (is_object($typeObj)) {
         $arrReturn['typeObj'] = $typeObj;
         $type_id = $typeObj->id;
     }
     $arrReturn['htmlPopularSearches'] = $this->loadPopularSearchImages();
     $arrReturn['htmlFeaturedCollections'] = $this->loadFeaturedCollections($type_id);
     $this->layout->content = View::make('frontend.types.index')->with($arrReturn);
 }
Example #3
0
 public function getRate($slug = '')
 {
     $type = Type::where('type', 'rate')->first();
     $posts = Post::where('type_id', '=', $type->id)->where('status', 1)->where('parent', '=', '0')->orderBy('created_at', 'desc')->get();
     $posts_child = Post::where('type_id', '=', $type->id)->where('status', 1)->where('parent', '!=', '0')->orderBy('created_at', 'desc')->get();
     if (!empty($slug)) {
         $row = Post::where('slug', $slug)->first();
         $posts_child = Post::where('type_id', '=', $type->id)->where('parent', $row->id)->where('status', 1)->orderBy('created_at', 'desc')->get();
         $blade = 'home.page-menu-title';
     } else {
         $tv = Rate::where('type', 'tv')->where('status', 1)->orderBy('position', 'asc')->get();
         $inet = Rate::where('type', 'inet')->first();
         $inetOption = Rate::where('type', 'inetOption')->where('status', 1)->orderBy('position', 'asc')->get();
         $row = array('inet' => json_decode($inet->description), 'inetOption' => $inetOption, 'tv' => $tv);
         $blade = 'home.page-rate';
     }
     $view = array('posts' => $posts, 'posts_child' => $posts_child, 'type' => $type, 'row' => $row);
     return View::make($blade, $view);
 }
 public function getCreateSitemap()
 {
     $urlroot = Config::get('app.url');
     $types = Type::where('status', 1)->get(array('type', 'updated_at', 'id'));
     $pages = Post::where('status', 1)->get(array('slug', 'updated_at', 'type_id'));
     // $project = Project::get(array('slug', 'updated_at'));
     // var_dump($urlroot); die();
     $xml = new DomDocument('1.0', 'utf-8');
     $urlset = $xml->createElement('urlset');
     $urlset->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
     foreach ($types as $type) {
         $url = $xml->createElement('url');
         $urlset->appendChild($url);
         $loc = $xml->createElement('loc');
         $url->appendChild($loc);
         $loc->appendChild($text = $xml->createTextNode($urlroot . '/' . $type->type));
         $lastmod = $xml->createElement('lastmod');
         $url->appendChild($lastmod);
         $lastmod->appendChild($xml->createTextNode(date('Y-m-d', strtotime($type->updated_at))));
         foreach ($pages as $post) {
             if ($post->type_id == $type->id) {
                 $url = $xml->createElement('url');
                 $urlset->appendChild($url);
                 $loc = $xml->createElement('loc');
                 $url->appendChild($loc);
                 $loc->appendChild($text = $xml->createTextNode($urlroot . '/' . $type->type . '/' . $post->slug));
                 $lastmod = $xml->createElement('lastmod');
                 $url->appendChild($lastmod);
                 $lastmod->appendChild($xml->createTextNode(date('Y-m-d', strtotime($post->updated_at))));
             }
         }
     }
     $xml->appendChild($urlset);
     $xml->formatOutput = true;
     $xml->save('sitemap.xml');
     if (!@fopen('sitemap.xml', "r")) {
         return Redirect::back()->with('error', 'ошибка при обновлении файла sitemap.xml');
     }
     return Redirect::back()->with('success', 'файл sitemap.xml обновлен');
     // return Response::download('sitemap.xml');
 }
Example #5
0
 public function getType()
 {
     $q = Input::get('q');
     $data = Type::where('name', 'like', '%' . $q . '%')->orderBy('name', 'asc')->limit(10)->get();
     $array = array();
     foreach ($data as $row) {
         $array[] = array('id' => $row->id, 'text' => $row->name);
     }
     echo json_encode($array);
 }
 /**
  * Display detailed information about a specific item, including the icon,
  * description, price to buy in trade hubs and locally, and manufacturing costs
  * based on mineral prices in the local area.
  */
 public function item($id = NULL)
 {
     // Retrieve the basic information about this item.
     $type = Type::where('typeID', $id)->firstOrFail();
     // If material efficiency was updated, save to the database and set a local variable.
     $material_efficiency = $type->materialEfficiency;
     if (!isset($material_efficiency)) {
         $material_efficiency = new MaterialEfficiency();
         $material_efficiency->typeID = $id;
         $material_efficiency->materialEfficiency = 0;
     }
     if (Input::has('me')) {
         $material_efficiency->materialEfficiency = (int) Input::get('me');
     }
     // Save the updated material efficiency figure.
     $type->materialEfficiency()->save($material_efficiency);
     // Calculate volume if we need to use shipping data.
     $shipping_cost = Setting::where('key', 'shipping_cost')->first();
     $shipping_cost_to_include = 0;
     if ($shipping_cost->value > 0) {
         // If volume is below 1000, we assume it's not a ship hull and use the base volume.
         if ($type->volume < 1000) {
             $shipping_cost_to_include = $shipping_cost->value * $type->volume;
         } else {
             // For larger volumes, we need to use static values for ship types.
             switch ($type->groupID) {
                 case 31:
                     $shipping_cost_to_include = $shipping_cost->value * 500;
                     break;
                 case 25:
                 case 237:
                 case 324:
                 case 830:
                 case 831:
                 case 834:
                 case 893:
                     $shipping_cost_to_include = $shipping_cost->value * 2500;
                     break;
                 case 463:
                 case 543:
                     $shipping_cost_to_include = $shipping_cost->value * 3750;
                     break;
                 case 420:
                 case 541:
                     $shipping_cost_to_include = $shipping_cost->value * 5000;
                     break;
                 case 26:
                 case 358:
                 case 832:
                 case 833:
                 case 894:
                     $shipping_cost_to_include = $shipping_cost->value * 10000;
                     break;
                 case 28:
                     $shipping_cost_to_include = $shipping_cost->value * 20000;
                     break;
                 case 27:
                 case 381:
                     $shipping_cost_to_include = $shipping_cost->value * 50000;
                     break;
             }
         }
     }
     // Load the 64x64 icon to display.
     $icon = '';
     $ship = Ship::where('id', $id)->get();
     if (count($ship)) {
         $icon = 'https://image.eveonline.com/Render/' . $id . '_128.png';
     } elseif ($type->Group->Icon) {
         $icon = str_replace('_', '_64_', $type->MarketGroup->Icon->iconFile);
         $icon = preg_replace('/^0/', '', $icon);
         $icon = preg_replace('/0(.)$/', '$1', $icon);
         $icon = 'eve/items/' . $icon . '.png';
     }
     // Retrieve the current price ranges this item sells for.
     $response = API::eveCentral(array($id), Setting::where('key', 'home_region_id')->pluck('value'));
     $local_price = $response[$id];
     // Tech II items need to be treated differently.
     $t2_options = array();
     if ($type->metaType && $type->metaType->metaGroup && $type->metaType->metaGroup['metaGroupName'] == 'Tech II') {
         // Retrieve an array of different possibilities for decryptors.
         $tech_two = TechII::getInventionFigures($type);
         // For each decryptor, show the potential profit.
         $total_price = 1000000000;
         foreach ($tech_two as $decryptor) {
             // Default max runs is 10, add any modifier.
             $max_runs = 10;
             if (isset($decryptor['max_run_modifier'])) {
                 $max_runs += $decryptor['max_run_modifier'];
             }
             // Based on the chance of success, how many T2 items on average will be produced per run?
             $chance_of_success = $decryptor['chance_of_success'] / 100;
             $t2_items_per_blueprint = $max_runs * $chance_of_success;
             // Calculate the cost of manufacturing that many T2 items.
             $manufacturing_cost_per_blueprint = $t2_items_per_blueprint * ($decryptor['t2_manufacture_price'] * (100 - $decryptor['me_modifier']) / 100);
             $total_cost = $decryptor['invention_price'] + $manufacturing_cost_per_blueprint;
             $cost_per_unit = $total_cost / $t2_items_per_blueprint;
             $t2_options[] = array("typeName" => $decryptor['typeName'], "cost" => $cost_per_unit);
             if ($cost_per_unit < $total_price) {
                 $total_price = $cost_per_unit;
             }
         }
         $manufacturing = NULL;
     } else {
         // If the meta level of this item is not Meta 0, we don't need to pull the manufacture price.
         $item = Item::where('typeID', $id)->first();
         if ($item->allowManufacture == 1) {
             // Get a list of what is needed to manufacture the item.
             $manufacturing = array();
             $total_price = 0;
             $type_materials = DB::table('invTypeMaterials')->where('typeID', $id)->get();
             $types = array();
             $jita_types = array();
             // Loop through all the materials. For each one, add it to an array we will use to show manufacturing details.
             foreach ($type_materials as $material) {
                 // Build an array for the eve-central API call.
                 $types[] = $material->materialTypeID;
                 // Build an array for the eventual output.
                 $manufacturing[$material->materialTypeID] = (object) array("typeName" => Type::find($material->materialTypeID)->typeName, "qty" => $material->quantity * (1 - $material_efficiency->materialEfficiency / 100), "price" => 0, "jita" => FALSE);
             }
             // Make an API call to get the local price of materials.
             $api = API::eveCentral($types, $home_region_id = Setting::where('key', 'home_region_id')->pluck('value'));
             // Loop through each returned price and update the data in the manufacturing array.
             foreach ($api as $api_result) {
                 if ($api_result->median != 0) {
                     $manufacturing[$api_result->id]->price = $manufacturing[$api_result->id]->qty * $api_result->median;
                     $total_price += $manufacturing[$api_result->id]->price;
                 } else {
                     // Build an array of types to check prices at Jita.
                     $jita_types[] = $api_result->id;
                 }
             }
             // If we need to check prices at Jita, make another API call.
             if (count($jita_types)) {
                 $api = API::eveCentral($jita_types, NULL, 30000142);
                 // Loop through each returned price and update the data in the manufacturing array.
                 foreach ($api as $api_result) {
                     $manufacturing[$api_result->id]->price = $manufacturing[$api_result->id]->qty * $api_result->median;
                     $manufacturing[$api_result->id]->jita = TRUE;
                     $total_price += $manufacturing[$api_result->id]->price;
                 }
             }
             $potential_profits = NULL;
         } else {
             $manufacturing = NULL;
             $total_price = 999999999;
         }
     }
     // Retrieve current prices of the module in notable trade hubs.
     $jita = API::eveCentral($id, NULL, 30000142);
     $prices[] = (object) array("solarSystemName" => "Jita", "median" => $jita[$id]->median);
     $amarr = API::eveCentral($id, NULL, 30002187);
     $prices[] = (object) array("solarSystemName" => "Amarr", "median" => $amarr[$id]->median);
     $importCostToUse = (int) $jita[$id]->median < (int) $amarr[$id]->median ? $jita[$id]->median : $amarr[$id]->median;
     if ($shipping_cost_to_include) {
         $importCostToUse = $importCostToUse + $shipping_cost_to_include;
     }
     // Cache the industry and import potential profits for the item.
     $profit = $type->profit;
     if (!isset($profit)) {
         $profit = new Profit();
         $profit->typeID = $id;
     }
     $profit->manufactureCost = round($total_price);
     $profit->profitIndustry = round($local_price->median - $total_price);
     $profit->profitImport = round($local_price->median - $importCostToUse);
     // Save the cached potential profit figure.
     $type->profit()->save($profit);
     $profitToUse = $profit->profitIndustry > $profit->profitImport ? $profit->profitIndustry : $profit->profitImport;
     $costToUse = $profit->profitIndustry > $profit->profitImport ? $total_price : $importCostToUse;
     return View::make('item')->with('type', $type)->with('icon', $icon)->with('local_price', $local_price)->with('prices', $prices)->with('shipping_cost', $shipping_cost_to_include)->with('manufacturing', $manufacturing)->with('t2_options', $t2_options)->with('total_price', $total_price)->with('profit', $profit)->with('profitToUse', $profitToUse)->with('costToUse', $costToUse)->with('material_efficiency', $material_efficiency);
 }
 /**
  * Import zKillboard kills for the selected systems and alliances.
  */
 public function getZkillboard($systems = '')
 {
     // If this is the initial call to the function, retrieve the list of systems from the DB.
     if ($systems == '') {
         $systems_object = Setting::where('key', 'systems')->firstOrFail();
         $systems = $systems_object->value;
     }
     // Convert the comma-seperated string into an array.
     $systems_array = explode(',', $systems);
     // If there are more systems in the list than we want to pull at once, chop off the first X and call this function again.
     while (count($systems_array) > $this->api_system_limit) {
         $this->getZkillboard(implode(',', array_splice($systems_array, 0, $this->api_system_limit)));
     }
     // Retrieve the selected alliances from the database.
     $alliances = Setting::where('key', 'alliances')->firstOrFail();
     // Build the API URL.
     $url = 'https://zkillboard.com/api/xml/losses/no-attackers/' . 'allianceID/' . preg_replace('/\\s+/', '', $alliances->value) . '/' . 'solarSystemID/' . preg_replace('/\\s+/', '', $systems) . '/';
     // Send the request.
     $response = Request::get($url)->addHeader('Accept-Encoding', 'gzip')->addHeader('User-Agent', 'Eve Traders Handbook')->send();
     if (isset($response->body) && strlen($response->body) > 0) {
         $body = simplexml_load_string(gzdecode($response->body));
         $insert_count = 0;
         // Parse the response, inserting the losses into the database.
         foreach ($body->result->rowset->row as $row) {
             // First check whether this kill has not already been recorded.
             $kill = Kill::find($row['killID']);
             if (!isset($kill->killID)) {
                 // Create and save the new kill record.
                 $kill = new Kill();
                 $kill->killID = $row['killID'];
                 $kill->solarSystemID = $row['solarSystemID'];
                 $kill->characterID = $row->victim['characterID'];
                 $kill->characterName = $row->victim['characterName'];
                 $kill->allianceID = $row->victim['allianceID'];
                 $kill->corporationID = $row->victim['corporationID'];
                 $kill->shipTypeID = $row->victim['shipTypeID'];
                 $kill->killTime = $row['killTime'];
                 $kill->save();
                 $insert_count++;
                 // Insert the alliance information into the database unless it already exists.
                 $alliance = Alliance::find($kill->allianceID);
                 if (!isset($alliance->id)) {
                     $alliance = new Alliance();
                     $alliance->id = $kill->allianceID;
                     $alliance->allianceName = $row->victim['allianceName'];
                     $alliance->save();
                 }
                 // Insert the corporation information into the database unless it already exists.
                 $corporation = Corporation::find($kill->corporationID);
                 if (!isset($corporation->id)) {
                     $corporation = new Corporation();
                     $corporation->id = $kill->corporationID;
                     $corporation->corporationName = $row->victim['corporationName'];
                     $corporation->save();
                 }
                 // Insert the ship type that was lost into the database unless it already exists.
                 $ship = Ship::find($kill->shipTypeID);
                 $type = Type::find($kill->shipTypeID);
                 if (!isset($ship->id)) {
                     $ship = new Ship();
                     $ship->id = $kill->shipTypeID;
                     $ship->shipName = $type->typeName;
                     $ship->save();
                 }
                 // Insert the ship loss into the items database as well.
                 if (stristr($ship->shipName, 'Capsule') === FALSE) {
                     $item = new Item();
                     $item->killID = $row['killID'];
                     $item->typeID = $kill->shipTypeID;
                     $item->typeName = $type->typeName;
                     $item->categoryName = $type->group->category['categoryName'];
                     $item->metaGroupName = isset($type->metaType->metaGroup['metaGroupName']) ? $type->metaType->metaGroup['metaGroupName'] : '';
                     $item->allowManufacture = 1;
                     $item->qty = 1;
                     $item->save();
                 }
                 // Add the category to the list of filters available on the site.
                 $filter = Filter::find($type->group->category['categoryID']);
                 if (!isset($filter->categoryID)) {
                     $filter = new Filter();
                     $filter->categoryID = $type->group->category['categoryID'];
                     $filter->categoryName = $type->group->category['categoryName'];
                     $filter->iconID = $type->group->category['iconID'];
                     $filter->save();
                 }
                 // Loop through the items lost in the kill. Insert each one into the items table.
                 if (isset($row->rowset->row)) {
                     foreach ($row->rowset->row as $loss) {
                         $typeID = (int) $loss['typeID'];
                         $item = Item::where('typeID', '=', $typeID)->first();
                         // If this item already exists in the items table, we don't need to re-query all the additional
                         // information, we can just copy it from an existing row.
                         if (isset($item)) {
                             // This type has already been seen. Duplicate the record and save the new instance.
                             $clone = new Item();
                             $clone = $item->replicate();
                             // Update the right killID and quantity, and unset the primary key and date columns.
                             $clone->killID = $row['killID'];
                             $clone->qty = $loss['qtyDropped'] + $loss['qtyDestroyed'];
                             unset($clone->id);
                             unset($clone->created_at);
                             unset($clone->updated_at);
                             // Save the cloned row.
                             $clone->save();
                         } else {
                             // This is a never-before-seen lost item. Create a new row and look up all the related details.
                             $item = new Item();
                             $type = Type::find($typeID);
                             $item->killID = (int) $row['killID'];
                             $item->typeID = $typeID;
                             $item->typeName = $type->typeName;
                             $item->categoryName = $type->group->category['categoryName'];
                             $metaGroupName = isset($type->metaType->metaGroup['metaGroupName']) ? $type->metaType->metaGroup['metaGroupName'] : '';
                             if ($metaGroupName == 'Tech I' || $metaGroupName == '') {
                                 $metaLevel = DB::table('dgmTypeAttributes')->where('typeID', $typeID)->where('attributeID', 633)->first();
                                 if (isset($metaLevel)) {
                                     $metaGroupName = 'Meta ';
                                     $metaGroupName .= isset($metaLevel->valueInt) ? $metaLevel->valueInt : $metaLevel->valueFloat;
                                 }
                             }
                             $item->metaGroupName = $metaGroupName;
                             $blueprint = Type::where('typeName', $type->typeName . ' Blueprint')->count();
                             if ($blueprint > 0) {
                                 $item->allowManufacture = 1;
                             }
                             $item->qty = $loss['qtyDropped'] + $loss['qtyDestroyed'];
                             $item->save();
                             // Add the category to the list of filters available on the site.
                             $filter = Filter::find($type->group->category['categoryID']);
                             if (!isset($filter->categoryID)) {
                                 $filter = new Filter();
                                 $filter->categoryID = $type->group->category['categoryID'];
                                 $filter->categoryName = $type->group->category['categoryName'];
                                 $filter->iconID = $type->group->category['iconID'];
                                 $filter->save();
                             }
                         }
                     }
                 }
             }
         }
         echo "Inserted {$insert_count} new kills! ";
     } else {
         echo "No response received from zKillboard API.";
     }
 }