/** * Returns a new ItemSubTypeQuery object. * * @param string $modelAlias The alias of a model in the query * @param ItemSubTypeQuery|Criteria $criteria Optional Criteria to build the query from * * @return ItemSubTypeQuery */ public static function create($modelAlias = null, $criteria = null) { if ($criteria instanceof ItemSubTypeQuery) { return $criteria; } $query = new ItemSubTypeQuery(); if (null !== $modelAlias) { $query->setModelAlias($modelAlias); } if ($criteria instanceof Criteria) { $query->mergeWith($criteria); } return $query; }
/** * @param $API_JSON * @param $offset */ function processApiData($API_JSON, $offset) { $APIItems = APIItemV2::getMultipleItemsByJSON($API_JSON); try { $itemCount = $offset; foreach ($APIItems as $APIItem) { $itemCount++; if ($APIItem == null) { print "Skipped item {$itemCount} on page {$offset}.\n"; continue; } echo "{$itemCount}: {$APIItem->getName()} (ID: {$APIItem->getItemId()})\n"; $itemData = array('TypeId' => getOrCreateTypeID($APIItem->getMarketType()), 'DataId' => $APIItem->getItemId(), 'Name' => $APIItem->getName(), 'RestrictionLevel' => $APIItem->getLevel(), 'Rarity' => getRarityID($APIItem->getRarity()), 'VendorSellPrice' => $APIItem->getVendorValue(), 'Img' => $APIItem->getImageURL(), 'RarityWord' => $APIItem->getRarity(), 'UnsellableFlag' => $APIItem->isUnsellable()); $item = ItemQuery::create()->findPK($APIItem->getItemId()); if ($item === null) { $item = new Item(); } $item->fromArray($itemData); $itemType = ItemTypeQuery::create()->findPk($itemData['TypeId']); if ($itemType !== null) { if ($APIItem->getSubType() !== null) { $itemSubType = ItemSubTypeQuery::create()->findOneByTitle($APIItem->getDBSubType()); if ($itemSubType === null) { //All of the below types are known to not exist in the market data with an ID (by this name). //Rune/Sigil/Utility/Gem/Booze/Halloween/LargeBundle/RentableContractNpc/ContractNPC/UnlimitedConsumable //TwoHandedToy/AppearanceChange/Immediate/Unknown $itemSubTypes = ItemSubTypeQuery::create()->filterByMainTypeId($itemData['TypeId'])->withColumn('MAX(id)', 'MAXid')->find(); $SubTypeID = $itemSubTypes[0]->getMAXid() + 1; $itemSubType = new ItemSubType(); $itemSubType->fromArray(array('Id' => $SubTypeID, 'MainTypeId' => $itemData['TypeId'], 'Title' => $APIItem->getDBSubType())); $itemSubType->save(); $itemType->addSubType($itemSubType); $item->setItemSubType($itemSubType); } $itemType->addSubType($itemSubType); $item->setItemSubType($itemSubType); } $item->setItemType($itemType); } $item->save(); } } catch (Exception $e) { echo "failed [[ {$e->getMessage()} ]] .. \n"; } }
/** * Get the associated ItemSubType object * * @param PropelPDO $con Optional Connection object. * @return ItemSubType The associated ItemSubType object. * @throws PropelException */ public function getItemSubType(PropelPDO $con = null) { if ($this->aItemSubType === null && $this->item_sub_type_id !== null) { $this->aItemSubType = ItemSubTypeQuery::create()->filterByItem($this)->findOne($con); /* The following can be used additionally to guarantee the related object contains a reference to this object. This level of coupling may, however, be undesirable since it could result in an only partially populated collection in the referenced object. $this->aItemSubType->addItems($this); */ } return $this->aItemSubType; }
/** * Returns the number of related ItemSubType objects. * * @param Criteria $criteria * @param boolean $distinct * @param PropelPDO $con * @return int Count of related ItemSubType objects. * @throws PropelException */ public function countSubTypes(Criteria $criteria = null, $distinct = false, PropelPDO $con = null) { $partial = $this->collSubTypesPartial && !$this->isNew(); if (null === $this->collSubTypes || null !== $criteria || $partial) { if ($this->isNew() && null === $this->collSubTypes) { return 0; } else { if ($partial && !$criteria) { return count($this->getSubTypes()); } $query = ItemSubTypeQuery::create(null, $criteria); if ($distinct) { $query->distinct(); } return $query->filterByMainType($this)->count($con); } } else { return count($this->collSubTypes); } }
$app->get("/type/{type}/{subtype}/{page}", function (Request $request, $type, $subtype, $page) use($app) { $page = $page > 0 ? $page : 1; $q = ItemQuery::create(); if ($type == -1) { $type = null; } if ($subtype == -1) { $subtype = null; } if (!is_null($type)) { if (!($type = ItemTypeQuery::create()->findPk($type))) { return $app->abort(404, "bad type"); } $q->filterByItemType($type); if (!is_null($subtype)) { if (!($subtype = ItemSubTypeQuery::create()->findPk(array($subtype, $type->getId())))) { return $app->abort(404, "bad type"); } $q->filterByItemSubType($subtype); } } // use generic function to render return item_list($app, $request, $q, $page, 50, array('type' => $type, 'subtype' => $subtype)); })->assert('type', '-?\\d*')->assert('subtype', '-?\\d*')->assert('page', '-?\\d*')->value('type', -1)->value('subtype', -1)->value('page', 1)->bind('type'); /** * ---------------------- * route /item * ---------------------- */ $app->get("/item/{dataId}", function ($dataId) use($app) { $item = ItemQuery::create()->findPK($dataId);
/** * Removes this object from datastore and sets delete attribute. * * @param PropelPDO $con * @return void * @throws PropelException * @throws Exception * @see BaseObject::setDeleted() * @see BaseObject::isDeleted() */ public function delete(PropelPDO $con = null) { if ($this->isDeleted()) { throw new PropelException("This object has already been deleted."); } if ($con === null) { $con = Propel::getConnection(ItemSubTypePeer::DATABASE_NAME, Propel::CONNECTION_WRITE); } $con->beginTransaction(); try { $deleteQuery = ItemSubTypeQuery::create()->filterByPrimaryKey($this->getPrimaryKey()); $ret = $this->preDelete($con); if ($ret) { $deleteQuery->delete($con); $this->postDelete($con); $con->commit(); $this->setDeleted(true); } else { $con->commit(); } } catch (Exception $e) { $con->rollBack(); throw $e; } }