本文整理汇总了PHP中Inventory::model方法的典型用法代码示例。如果您正苦于以下问题:PHP Inventory::model方法的具体用法?PHP Inventory::model怎么用?PHP Inventory::model使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Inventory
的用法示例。
在下文中一共展示了Inventory::model方法的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionIdelete
public function actionIdelete($id)
{
if (Yii::app()->user->isGuest or Yii::app()->user->access_level < Config::get('access_level_admin')) {
$this->redirect(Yii::app()->homeUrl);
}
$model = Inventory::model()->findByPK($id);
$model->delete();
$this->redirect(Yii::app()->homeUrl . 'admin/check/items/');
}
示例2: add_item
public function add_item($item_id, $item_owner, $amount)
{
$criteria = new CDbCriteria();
$criteria->select = 'MAX(item_unique_id) as item_unique_id';
$last_item_id = Inventory::model()->find($criteria);
$form = new Inventory();
$form->scenario = 'buy';
$form->item_id = $item_id;
$form->item_owner = $item_owner;
$form->item_creator = '';
$form->item_count = $amount;
$form->item_unique_id = $last_item_id->item_unique_id + 1;
$form->item_location = 127;
$form->item_skin = $item_id;
$form->save(false);
return $form->item_unique_id;
}
示例3: actionCreate
/**
* Creates a new model.
* If creation is successful, the browser will be redirected to the 'view' page.
*/
public function actionCreate()
{
$model = new Entry();
if (isset($_POST['amount']) && isset($_POST['invoice']) && isset($_POST['name'])) {
$inventory_info = $_POST["name"];
$inventory_info_arr = explode(":", $inventory_info);
$inventory_id = intval($inventory_info_arr[0]);
$inventory = Inventory::model()->findByPk($inventory_id);
if ($inventory->id) {
$inventory_id = $inventory->id;
$model->inventory = $inventory_id;
$model->item = $inventory->name . " - " . $inventory->model;
$model->price = intval($_POST['price']);
$model->amount = intval($_POST['amount']);
$model->invoice = intval($_POST['invoice']);
if ($model->save()) {
$this->redirect(array('/invoice/view', 'id' => $model->invoice));
}
} else {
throw new Exception("Invalid Inventory ID");
}
}
$this->render('/invoice/view', array('id' => $_POST['invoice']));
}
示例4: loadModel
public function loadModel($id)
{
$model = Inventory::model()->findByPk($id);
if ($model === null) {
throw new CHttpException(404, Yii::t('app', 'The requested page does not exist.'));
}
return $model;
}
示例5: array
<?php
$this->breadcrumbs[] = Yii::t('crud', 'Rentals');
Yii::app()->clientScript->registerScript('search', "\n \$('.search-button').click(function(){\n \$('.search-form').toggle();\n return false;\n });\n \$('.search-form form').submit(function(){\n \$.fn.yiiGridView.update(\n 'rental-grid',\n {data: \$(this).serialize()}\n );\n return false;\n });\n ");
?>
<?php
$this->widget("TbBreadcrumbs", array("links" => $this->breadcrumbs));
?>
<h1>
<?php
echo Yii::t('crud', 'Rentals');
?>
<small><?php
echo Yii::t('crud', 'Manage');
?>
</small>
</h1>
<?php
$this->renderPartial("_toolbar", array("model" => $model));
?>
<?php
$this->widget('TbGridView', array('id' => 'rental-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'template' => '{pager}{items}{pager}{summary}', 'pager' => array('class' => 'TbPager', 'displayFirstAndLast' => true), 'columns' => array(array('class' => 'CLinkColumn', 'header' => '', 'labelExpression' => '$data->itemLabel', 'urlExpression' => 'Yii::app()->controller->createUrl("view", array("rental_id" => $data["rental_id"]))'), array('class' => 'editable.EditableColumn', 'name' => 'rental_id', 'editable' => array('url' => $this->createUrl('/sakila/slim/rental/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'rental_date', 'editable' => array('url' => $this->createUrl('/sakila/slim/rental/editableSaver'))), array('name' => 'inventory_id', 'value' => 'CHtml::value($data,\'inventory.itemLabel\')', 'filter' => CHtml::listData(Inventory::model()->findAll(array('limit' => 1000)), 'inventory_id', 'itemLabel')), array('name' => 'customer_id', 'value' => 'CHtml::value($data,\'customer.itemLabel\')', 'filter' => CHtml::listData(Customer::model()->findAll(array('limit' => 1000)), 'customer_id', 'itemLabel')), array('class' => 'editable.EditableColumn', 'name' => 'return_date', 'editable' => array('url' => $this->createUrl('/sakila/slim/rental/editableSaver'))), array('name' => 'staff_id', 'value' => 'CHtml::value($data,\'staff.itemLabel\')', 'filter' => CHtml::listData(Staff::model()->findAll(array('limit' => 1000)), 'staff_id', 'itemLabel')), array('class' => 'editable.EditableColumn', 'name' => 'last_update', 'editable' => array('url' => $this->createUrl('/sakila/slim/rental/editableSaver'))), array('class' => 'TbButtonColumn', 'viewButtonUrl' => 'Yii::app()->controller->createUrl("view", array("rental_id" => $data->rental_id))', 'updateButtonUrl' => 'Yii::app()->controller->createUrl("update", array("rental_id" => $data->rental_id))', 'deleteButtonUrl' => 'Yii::app()->controller->createUrl("delete", array("rental_id" => $data->rental_id))'))));
示例6: actionGenerate
public function actionGenerate()
{
$names = file(getcwd() . "/protected/tests/names.txt");
$streets = file(getcwd() . "/protected/tests/streets.txt");
$name_arr = array();
$street_arr = array();
foreach ($names as $line) {
$name = explode(" ", $line);
$name_arr[] = trim($name[0]);
}
foreach ($streets as $line) {
$street = explode(" ", $line);
if (count($street) == 3) {
$name1 = trim($street[0]);
$name2 = trim($street[1]);
$name3 = trim($street[2]);
$street_arr[] = $name1 . " " . $name2 . " " . $name3 . ", Toronto";
}
}
$limit = 1000000;
for ($i = 0; $i < $limit; $i++) {
set_time_limit(0);
// resetting the MySQL timeout
echo "Creating an invoice #{$i} <br/>";
$invoice = new Invoice();
$invoice->name = $name_arr[rand(0, count($name_arr) - 1)];
$invoice->address = rand(1, 5000) . " " . $street_arr[rand(0, count($street_arr) - 1)];
$y = 2012;
//rand(2006,2012);
if ($y < 2012) {
$m = rand(1, 12);
} else {
$m = rand(1, 11);
}
$m = 11;
$d = rand(1, 2);
$invoice->date = date($y . '-' . $m . '-' . $d);
$invoice->delivery_date = date($y . '-' . $m . '-' . $d);
$invoice->phone1 = "647" . rand(1, 9) . rand(1, 9) . rand(1, 9) . rand(1, 9) . rand(1, 9) . rand(1, 9) . rand(1, 9);
$invoice->delivery_date = date($y . '-' . $m . '-' . $d);
$invoice->delivery_cost = rand(10, 50);
if ($invoice->save()) {
$number_of_items = rand(3, 9);
for ($j = 0; $j < $number_of_items; $j++) {
$entry = new Entry();
$entry->invoice = $invoice->id;
$entry->inventory = rand(3, 2709);
$inventory = Inventory::model()->findByPk($entry->inventory);
if ($inventory) {
$entry->item = $inventory->name . " #" . $inventory->model;
$entry->quantity = rand(1, $inventory->quantity);
$entry->price = round($inventory->in * 1.3);
$entry->amount = round($entry->price * 0.9 * $entry->quantity);
if ($entry->save()) {
echo "--Entry Created! <br/>";
$inventory->quantity = $inventory->quantity - $entry->quantity;
if ($inventory->save()) {
echo "---Inventory Updated! <br/>";
} else {
$entry->delete();
echo "***Inventory Error! Failed to update <br/>";
}
} else {
echo "***Entry Error! <br/>";
print_r($entry->getErrors());
echo "<br/>";
}
} else {
echo "*Inventory Error! (invalid randomed inventory id) <br/>";
}
}
if ($invoice->Amount > 0) {
echo "Invoice Created! id=>" . $invoice->id . "<br/>";
} else {
echo "Invoice has no entries! Deleting id=>" . $invoice->id . "<br/>";
$invoice->delete();
}
} else {
echo "Invoice Error! <br/>";
print_r($invoice->getError());
echo "<br/>";
}
echo "<hr/>";
}
}
示例7: array
<?php
$this->breadcrumbs = array($model->label(2) => array('index'), 'Manage');
$this->menu = array(array('label' => 'List' . ' ' . $model->label(2), 'url' => array('index')), array('label' => 'Create' . ' ' . $model->label(), 'url' => array('create')));
Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\t\$('.search-form').toggle();\n\treturn false;\n});\n\$('.search-form form').submit(function(){\n\t\$.fn.yiiGridView.update('rental-grid', {\n\t\tdata: \$(this).serialize()\n\t});\n\treturn false;\n});\n");
?>
<h1><?php
echo 'Manage' . ' ' . GxHtml::encode($model->label(2));
?>
</h1>
<p>
You may optionally enter a comparison operator (<, <=, >, >=, <> or =) at the beginning of each of your search values to specify how the comparison should be done.
</p>
<?php
echo GxHtml::link('Advanced Search', '#', array('class' => 'search-button'));
?>
<div class="search-form">
<?php
$this->renderPartial('_search', array('model' => $model));
?>
</div><!-- search-form -->
<?php
$this->widget('zii.widgets.grid.CGridView', array('id' => 'rental-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'columns' => array('rental_id', 'rental_date', array('name' => 'inventory_id', 'value' => 'GxHtml::valueEx($data->inventory)', 'filter' => GxHtml::listDataEx(Inventory::model()->findAllAttributes(null, true))), array('name' => 'customer_id', 'value' => 'GxHtml::valueEx($data->customer)', 'filter' => GxHtml::listDataEx(Customer::model()->findAllAttributes(null, true))), 'return_date', array('name' => 'staff_id', 'value' => 'GxHtml::valueEx($data->staff)', 'filter' => GxHtml::listDataEx(Staff::model()->findAllAttributes(null, true))), array('class' => 'CButtonColumn'))));
示例8: array
<div class="row">
<?php
echo $form->label($model, 'rental_date');
?>
<?php
echo $form->textField($model, 'rental_date');
?>
</div>
<div class="row">
<?php
echo $form->label($model, 'inventory_id');
?>
<?php
echo $form->dropDownList($model, 'inventory_id', GxHtml::listDataEx(Inventory::model()->findAllAttributes(null, true)), array('prompt' => 'All'));
?>
</div>
<div class="row">
<?php
echo $form->label($model, 'customer_id');
?>
<?php
echo $form->dropDownList($model, 'customer_id', GxHtml::listDataEx(Customer::model()->findAllAttributes(null, true)), array('prompt' => 'All'));
?>
</div>
<div class="row">
<?php
echo $form->label($model, 'return_date');
示例9:
echo $form->error($model, 'last_update');
?>
</div><!-- row -->
<label><?php
echo GxHtml::encode($model->getRelationLabel('actors'));
?>
</label>
<?php
echo $form->checkBoxList($model, 'actors', GxHtml::encodeEx(GxHtml::listDataEx(Actor::model()->findAllAttributes(null, true)), false, true));
?>
<label><?php
echo GxHtml::encode($model->getRelationLabel('categories'));
?>
</label>
<?php
echo $form->checkBoxList($model, 'categories', GxHtml::encodeEx(GxHtml::listDataEx(Category::model()->findAllAttributes(null, true)), false, true));
?>
<label><?php
echo GxHtml::encode($model->getRelationLabel('inventories'));
?>
</label>
<?php
echo $form->checkBoxList($model, 'inventories', GxHtml::encodeEx(GxHtml::listDataEx(Inventory::model()->findAllAttributes(null, true)), false, true));
?>
<?php
echo GxHtml::submitButton('Save');
$this->endWidget();
?>
</div><!-- form -->
示例10: autorepairObjectsEquipment
/**
* knight's equipment are repaired automatically. Looking for equipment with pde loosed, calculate repair cost, substract to knight coins and add pde points.
* Return if error
* @param unknown_type $combat
* @param unknown_type $knight
* @return multitype:number boolean
*/
public static function autorepairObjectsEquipment(&$combat, &$knight)
{
//
$output = array('errno' => 0, 'error' => '', 'automatic_repair' => true, 'repair_cost' => 0, 'not_enought_money' => false);
//Prepared statement
$sql = '';
//Load all items of inventory of knight
$inventory = Inventory::model()->findAll('knights_id = :knights_id AND (type = ' . Inventory::EQUIPMENT_TYPE_ARMOUR . ' OR type = ' . Inventory::EQUIPMENT_TYPE_SPEAR . ' )', array(':knights_id' => $knight->id));
if (count($inventory)) {
//For each item check maximun pde
foreach ($inventory as $item) {
//Load class of item
if ($item['type'] == Inventory::EQUIPMENT_TYPE_ARMOUR) {
$object = ArmoursObjects::model()->findByPk($item['identificator']);
$classItem = Armours::model()->findByPk($object->armours_id);
} else {
$object = SpearsObjects::model()->findByPk($item['identificator']);
$classItem = Spears::model()->findByPk($object->spears_id);
}
//echo "\n".$knight->name.": ".$classItem->name." PDE MAX (".$classItem->pde.") object pde (".$object->current_pde.") ";
//Check if need a repair
if ($object->current_pde < $classItem->pde) {
//Check prize of reparation
$percentPDEloose = 1 - $object->current_pde / $classItem->pde;
$repair_cost = ceil($classItem->prize * $percentPDEloose);
//echo "coins (".$knight->coins.") percent ($percentPDEloose) prize class item(".$classItem->prize.") repair cost (".$repair_cost.")";
//Check coins and cost
if ($knight->coins > $repair_cost) {
Yii::log('Reparando ' . $classItem->name . ' por ' . $repair_cost . ' MO');
//Add autorepair row
$objectRepair = new ObjectRepairs();
$objectRepair->attributes = array('knights_id' => $knight->id, 'inventory_type' => $item['type'], 'combats_id' => $combat->id, 'object_identificator' => $item['identificator'], 'class_identificator' => $classItem->id, 'current_pde' => $object->current_pde, 'maximum_pde' => $classItem->pde, 'repair_cost' => $repair_cost, 'date' => date('Y-m-d H:m:s'));
if (!$objectRepair->save()) {
$output['errno'] = 2;
$output['error'] .= $objectRepair->getErrors();
}
//We can repair the object
$object->current_pde = $classItem->pde;
if (!$object->save()) {
$output['errno'] = 4;
}
//Subtract coins
$knight->coins -= $repair_cost;
$output['repair_cost'] += $repair_cost;
} else {
//Upsss, knight has not enought money!! we break loop
Yii::log('¡¡No se puede reparar!!');
$output['not_enought_money'] = true;
break;
}
}
}
} else {
$output['errno'] = 1;
}
//var_dump($output);
return $output;
}
示例11: getFirstEmptySocket
/**
* Search for empty socket in inventory. return empty position or false is is full
* @param unknown_type $knight_id
* @return number|boolean
*/
public static function getFirstEmptySocket($knight_id)
{
Yii::trace('[INVENTORY][getFirstEmptySocket] Check empty socket');
$criteria = new CDbCriteria();
$criteria->select = 'position';
$criteria->condition = 'knights_id = :knights_id AND position > ' . Yii::app()->params['inventory']['useEquipmentPosition'];
$criteria->params = array(':knights_id' => $knight_id);
$criteria->order = 'position ASC';
$items = Inventory::model()->findAll($criteria);
Yii::trace('[INVENTORY][getFirstEmptySocket] Total items (' . count($items) . ') maximum items (' . (Yii::app()->params['inventory']['maxPosition'] - Yii::app()->params['inventory']['useEquipmentPosition']) . ')');
//Check if secondary equipment is full
if (count($items) < Yii::app()->params['inventory']['maxPosition'] - Yii::app()->params['inventory']['useEquipmentPosition']) {
//Check first position free
$position = 11;
foreach ($items as $item) {
//Yii::trace( 'Check sockect '.$position.' with position object '.$item->position );
//check if position is free
if ($item->position != $position) {
//This position is empty
return $position;
}
//Next position
$position++;
}
//Amount of items is less than total of sockets. No socket beetwen items then last sokect is empty.
return $position;
} else {
return false;
}
}
示例12: actionShowPendingRoundDialog
public function actionShowPendingRoundDialog()
{
$output = array('errno' => 1, 'html' => '');
//Check session is enable
if (!Yii::app()->user->isGuest) {
//Check if user is in his page
if (Yii::app()->user->knights_id == $this->knight->id) {
//Check input
if (isset($_GET['id']) && is_numeric($_GET['id']) && $_GET['id'] > 0) {
//Search combat
$combat = Combats::model()->with('rounds')->find('id=:id', array(':id' => $_GET['id']));
if ($combat) {
//Check if status is enable
if ($combat->status == Combats::STATUS_ENABLE) {
//Check if user is in combat
if (Yii::app()->user->knights_id == $combat->from_knight || Yii::app()->user->knights_id == $combat->to_knight) {
//Check the last round is pending
if ($combat->rounds[count($combat->rounds) - 1]->status == Rounds::STATUS_PENDING) {
//cargamos el inventario del caballero
$item_list = Inventory::model()->findAll('knights_id=:knights_id', array(':knights_id' => $this->knight->id));
$inventory = array();
foreach ($item_list as $item) {
switch ($item->type) {
case Inventory::EQUIPMENT_TYPE_ARMOUR:
$armours_object = ArmoursObjects::model()->with(array('armours' => array('with' => array('type0', 'armoursMaterials', 'equipmentSize', 'equipmentQualities', 'equipmentRarity'))))->find('t.id=:id', array(':id' => $item->identificator));
$item_info['armours_id'] = $armours_object->armours->id;
$item_info['name'] = $armours_object->armours->name;
$item_info['armoursPDE'] = $armours_object->armours->pde;
$item_info['current_pde'] = $armours_object->current_pde;
$item_info['armours_type_name'] = $armours_object->armours->type0->name;
$item_info['armoursMaterialName'] = $armours_object->armours->armoursMaterials->name;
$item_info['armoursMaterialEndurance'] = $armours_object->armours->armoursMaterials->endurance;
$item_info['armoursMaterialPrize'] = $armours_object->armours->armoursMaterials->prize;
$item_info['armoursMaterialName'] = $armours_object->armours->armoursMaterials->name;
$item_info['equipmentSizeName'] = $armours_object->armours->equipmentSize->name;
$item_info['equipmentQualitiesName'] = $armours_object->armours->equipmentQualities->name;
$item_info['equipmentRarityName'] = $armours_object->armours->equipmentRarity->name;
$template = 'armour';
break;
case Inventory::EQUIPMENT_TYPE_SPEAR:
$spears_object = SpearsObjects::model()->with(array('spears' => array('with' => array('equipmentQualities', 'equipmentRarity', 'equipmentSize', 'spearsMaterials', 'spearsObjects'))))->find('t.id=:id', array(':id' => $item->identificator));
$item_info['spears_id'] = $spears_object->spears->id;
$item_info['name'] = $spears_object->spears->name;
$item_info['PDE'] = $spears_object->spears->pde;
$item_info['current_pde'] = $spears_object->current_pde;
$item_info['spears_damage'] = $spears_object->spears->damage;
$item_info['spearPrize'] = $spears_object->spears->prize;
$item_info['spearsMaterialName'] = $spears_object->spears->spearsMaterials->name;
$item_info['equipmentQualitiesName'] = $spears_object->spears->equipmentQualities->name;
$item_info['equipmentSizeName'] = $spears_object->spears->equipmentSize->name;
$item_info['equipmentRarityName'] = $spears_object->spears->equipmentRarity->name;
$template = 'spear';
break;
case Inventory::EQUIPMENT_TYPE_TRICK:
//FALTA DEFINIR LOS TRICKS!!
$template = 'trick';
break;
}
$data_template = array('item' => $item, 'item_info' => $item_info);
$inventory[$item->position] = $this->renderFile(Yii::app()->basePath . '/views/character/item_' . $template . '.php', $data_template, true);
}
//return html
$output['html'] = $this->renderFile(Yii::app()->basePath . '/views/character/dialog_pending_round.php', array('inventory' => $inventory), true);
$output['errno'] = 0;
} else {
$output['html'] = '<p>La última ronda no está pendiente.</p>';
}
} else {
$output['html'] = '<p>No participas en este combate.</p>';
}
} else {
$output['html'] = '<p>No se puede mostrar si el desafio no está en curso.</p>';
}
} else {
$output['html'] = '<p>No se ha encontrado el desafio.</p>';
}
} else {
$output['html'] = '<p>Los datos de entrada no tienen un formato válido.</p>';
}
} else {
$output['html'] = '<p>Sólo puedes toquetear tu caballero.</p>';
}
} else {
$output['html'] = '<p>Tu sesión ha expirado. Tienes que volver a hacer login.</p>';
}
echo CJSON::encode($output);
}
示例13: array
<?php
$this->breadcrumbs[] = Yii::t('crud', 'Rentals');
Yii::app()->clientScript->registerScript('search', "\n\$('.search-button').click(function(){\n\$('.search-form').toggle();\nreturn false;\n});\n\$('.search-form form').submit(function(){\n\$.fn.yiiGridView.update('rental-grid', {\ndata: \$(this).serialize()\n});\nreturn false;\n});\n");
?>
<?php
$this->widget("TbBreadcrumbs", array("links" => $this->breadcrumbs));
?>
<h1>
<?php
echo Yii::t('crud', 'Rentals');
?>
<small><?php
echo Yii::t('crud', 'Manage');
?>
</small>
</h1>
<?php
$this->renderPartial("_toolbar", array("model" => $model));
$this->widget('TbGridView', array('id' => 'rental-grid', 'dataProvider' => $model->search(), 'filter' => $model, 'pager' => array('class' => 'TbPager', 'displayFirstAndLast' => true), 'columns' => array(array('class' => 'editable.EditableColumn', 'name' => 'rental_id', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/rental/editableSaver'))), array('class' => 'editable.EditableColumn', 'name' => 'rental_date', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/rental/editableSaver'))), array('name' => 'inventory_id', 'value' => 'CHtml::value($data,\'inventory.itemLabel\')', 'filter' => CHtml::listData(Inventory::model()->findAll(array('limit' => 1000)), 'inventory_id', 'itemLabel')), array('name' => 'customer_id', 'value' => 'CHtml::value($data,\'customer.itemLabel\')', 'filter' => CHtml::listData(Customer::model()->findAll(array('limit' => 1000)), 'customer_id', 'itemLabel')), array('class' => 'editable.EditableColumn', 'name' => 'return_date', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/rental/editableSaver'))), array('name' => 'staff_id', 'value' => 'CHtml::value($data,\'staff.itemLabel\')', 'filter' => CHtml::listData(Staff::model()->findAll(array('limit' => 1000)), 'staff_id', 'itemLabel')), array('class' => 'editable.EditableColumn', 'name' => 'last_update', 'editable' => array('url' => $this->createUrl('/sakila/hybrid/rental/editableSaver'))), array('class' => 'TbButtonColumn', 'viewButtonUrl' => "Yii::app()->controller->createUrl('view', array('rental_id' => \$data->rental_id))", 'updateButtonUrl' => "Yii::app()->controller->createUrl('update', array('rental_id' => \$data->rental_id))", 'deleteButtonUrl' => "Yii::app()->controller->createUrl('delete', array('rental_id' => \$data->rental_id))"))));