public static function store() { self::check_logged_in(); // POST-pyynnön muuttujat sijaitsevat $_POST nimisessä assosiaatiolistassa $params = $_POST; //array of item_ids (string) //View::make('notimplemented.html'); $user_id = $_SESSION['user']; if (!$params) { //Redirect::to('/outfits/' . $user_id . 'new/', array('message' => 'Please select items!')); } $items_in_outfit = array(); foreach ($params as $key => $value) { if (strlen($key) == 1) { $items_in_outfit[] = Item::find($value); } else { if ($key == 'rating') { $rating = $value; } else { if ($key == 'comment') { $comment = $value; } } } } $outfit_object = new Outfit(array('outfit_id' => null, 'items' => $items_in_outfit, 'rating' => $rating, 'comment' => $comment)); $outfit_object->save_to_db($user_id); Redirect::to('/outfits/' . $user_id, array('message' => 'Outfit created!')); }
function output($message = null, $allowHtml = false, $addslashes = false) { $message = preg_replace('/\\%name\\%/', $this->Session->read('Game.Character.name'), $message); $message = preg_replace('/\\%class\\%/', $this->Session->read('Game.Type.name'), $message); $message = preg_replace('/\\%hisher\\%/', 'his', $message); if ($allowHtml != true) { $message = htmlspecialchars($message); } /* Items */ preg_match_all('/\\[item\\](.*?)\\[\\/item\\]/', $message, $items); if (isset($items[1]) && !empty($items[1])) { // Laat de makers het niet zien... App::import('Model', 'Item'); $Item = new Item(); $Item->contain(); $items = $Item->find('all', array('fields' => array('Item.id', 'Item.name', 'Item.quality'), 'conditions' => array('Item.name' => $items[1]))); foreach ($items as $item) { $message = str_replace('[item]' . $item['Item']['name'] . '[/item]', '<span class="item_' . $item['Item']['quality'] . '" onmouseover="showMouseInfo(url + \'items/view/' . addslashes($item['Item']['name']) . '\');" onmouseout="hideMouseInfo();">[' . addslashes($item['Item']['name']) . ']</span>', $message); } } // Quests preg_match_all('/\\[quest\\](.*?)\\[\\/quest\\]/', $message, $quests); if (isset($quests[1]) && !empty($quests[1])) { foreach ($quests[1] as $quest) { $message = str_replace('[quest]' . $quest . '[/quest]', '<span class="quest" onmouseover="showMouseInfo(url + \'quests/view/' . $quest . '\');" onmouseout="hideMouseInfo();">' . htmlspecialchars($quest) . '</span>', $message); } } if ($addslashes === true) { $message = addslashes($message); } return $message; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { $item = Item::find($id); if (!$item) { return false; } $item->delete(); }
public function testShouldDeleteAllCorrectly() { $this->Item->deleteAll(['Item.id' => [1, 3]]); $this->assertEmpty($this->Item->find('all')); $this->Item->includeDeletedRecords(); $item = $this->Item->read(null, 1); $this->assertEqual($item['Item']['description'], ItemFixture::DESCR_DELETED); }
public function postUpdate() { $newname = Input::get('name'); $id = Input::get('id'); $ini = Item::find($id); $ini->name = $newname; $ini->save(); return Redirect::route('home'); }
public function mostrarInfoProducto($url) { $lang = Idioma::where('codigo', App::getLocale())->where('estado', 'A')->first(); $item_lang = Item::join('item_lang', 'item_lang.item_id', '=', 'item.id')->where('item_lang.lang_id', $lang->id)->where('item_lang.url', $url)->first(); //Me quedo con el item, buscando por url //$item = Item::where('url', $url)->first(); $item = Item::find($item_lang->item_id); $this->array_view['item'] = $item; return View::make($this->folder_name . '.' . $this->project_name . '-ver', $this->array_view); }
function delete_items($id = FALSE) { $item = Item::find($id); $item->inactive = 1; $item->save(); if (!$item) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_delete_item_error')); } else { $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_delete_item_success')); } redirect('items'); }
public function vistaEditar($id) { //Me quedo con el item, buscando por id $item = Item::find($id); if ($item) { $this->array_view['item'] = $item; return View::make($this->folder_name . '.editar-item', $this->array_view); } else { $this->array_view['texto'] = Lang::get('controllers.error_carga_pagina'); return View::make($this->project_name . '-error', $this->array_view); } }
public function ordenar() { foreach (Input::get('orden') as $key => $imagen_id) { if ($key == 0) { $destacado = 'A'; } else { $destacado = NULL; } $respuesta = Imagen::ordenarImagenItem($imagen_id, $key, Input::get('item_id'), $destacado); } $item = Item::find(Input::get('item_id')); $menu = $item->seccionItem()->menuSeccion()->modulo()->nombre; return Redirect::to('/' . $menu . '/' . $item->lang()->url)->with('mensaje', $respuesta['mensaje'])->with('ok', true); }
function test_find() { //Arrange $name = "Hello Kitty"; $name2 = "Pokemon"; $test_Item = new Item($name); $test_Item->save(); $test_Item2 = new Item($name2); $test_Item2->save(); //Act $result = Item::find($test_Item2->getId()); //Assert $this->assertEquals($test_Item2, $result); }
public function run() { $items = Item::all(); foreach ($items as $item) { $i = Item::find($item->id); if ($item->participant) { $i->event_id = $item->participant->event_id; $i->save(); } if ($item->member) { $i->team_id = $item->member->team_id; $i->save(); } } }
public static function update($id) { self::check_logged_in(); $params = $_POST; $attributes = array('id' => $id, 'itemtype_id' => Item::find($id)->itemtype_id, 'description' => $params['description']); $item = new Item($attributes); $errors = $item->errors(); if (count($errors) > 0) { $item = Item::find($id); $itemtype = ItemType::find($item->itemtype_id); View::make('item/edit.html', array('errors' => $errors, 'given_description' => $params['description'], 'item' => $item, 'itemtype' => $itemtype)); } else { $item->update(); Redirect::to('/item/' . $item->id, array('message' => 'The item has been modified successfully!')); } }
/** * Looting an Item from an Obstacle in the game map * * @param int the id of the character * @param int the id of the areas_obstacles_item */ function loot($characterInfo = null, $areas_obstacles_item_id = null) { if ($this->canLoot($areas_obstacles_item_id, $characterInfo['id'], $characterInfo['area_id'])) { // Opslaan die handel App::import('Model', 'AreasObstaclesItem'); $AreasObstaclesItem = new AreasObstaclesItem(); $drop = $AreasObstaclesItem->find('first', array('conditions' => array('AreasObstaclesItem.id' => $areas_obstacles_item_id))); $data['Drop']['areas_obstacle_item_id'] = $drop['AreasObstaclesItem']['id']; $data['Drop']['item_id'] = $drop['AreasObstaclesItem']['item_id']; $data['Drop']['character_id'] = $characterInfo['id']; $dataInventory['Inventory']['item_id'] = $drop['AreasObstaclesItem']['item_id']; $dataInventory['Inventory']['character_id'] = $characterInfo['id']; if ($this->save($data)) { // Item opvragen, en eventueel de character_id invullen als deze character de eerste is... App::import('Model', 'Item'); $Item = new Item(); $Item->unbindModelAll(); $thisItem = $Item->find('first', array('conditions' => array('Item.id' => $drop['AreasObstaclesItem']['item_id']))); if (isset($thisItem['Item']['character_id']) && $thisItem['Item']['character_id'] == 0) { $thisItem['Item']['character_id'] = $characterInfo['id']; $thisItem['Item']['discovered'] = date('Y-m-d H:i:s'); $Item->save($thisItem); } App::import('Model', 'Inventory'); $Inventory = new Inventory(); // Bagid en index opvragen $bagIndex = $this->hasFreeSpace($characterInfo['id'], $drop['AreasObstaclesItem']['item_id'], true); $dataInventory['Inventory']['index'] = $bagIndex['index']; $dataInventory['Inventory']['bag_id'] = $bagIndex['bag_id']; // Save to inventory if ($Inventory->save($dataInventory)) { App::import('Model', 'Quest'); $Quest = new Quest(); $Quest->update(null, $characterInfo['id']); // Item is nu in de inventory... We kunnen eventueel questen updaten nu return true; } else { return false; } } else { return false; } } else { return false; } }
public function vistaEditar($id, $next, $seccion_next) { //Me quedo con el item, buscando por id $item = Item::find($id); $portfolio = Portfolio::find($item->portfolio()->id); $secciones = parent::seccionesDinamicas(); if ($portfolio) { $this->array_view['item'] = $portfolio->item(); $this->array_view['portfolio'] = $portfolio; $this->array_view['secciones'] = $secciones; $this->array_view['continue'] = $next; $this->array_view['seccion_next'] = $seccion_next; return View::make($this->folder_name . '.editar', $this->array_view); } else { $this->array_view['texto'] = Lang::get('controllers.error_carga_pagina'); return View::make($this->project_name . '-error', $this->array_view); } }
public function SupplierAndItemInfo() { App::uses("Supplier", "Inventory.Model"); App::import("Model", "Inventory.Item"); $supplierModel = new Supplier(); $itemModel = new Item(); $supplierModel->recursive = 0; $suppliers = $supplierModel->find("all"); $tmp_suplliers = array(); foreach ($suppliers as $key => $supplier) { $tmp_suplliers[$supplier['Supplier']['id']]['name'] = $supplier['Supplier']['name']; $tmp_suplliers[$supplier['Supplier']['id']]['email'] = $supplier['Supplier']['email']; $tmp_suplliers[$supplier['Supplier']['id']]['gst'] = $supplier['Supplier']['gst_rate']; $tmp_suplliers[$supplier['Supplier']['id']]['pst'] = $supplier['Supplier']['pst_rate']; $tmp_suplliers[$supplier['Supplier']['id']]['item'] = $itemModel->find("list", array("fields" => array("id_plus_item"), 'conditions' => array('supplier_id' => $supplier['Supplier']['id']))); $tmp_suplliers[$supplier['Supplier']['id']]['address'] = $this->address_format($supplier['Supplier']['address'], $supplier['Supplier']['city'], $supplier['Supplier']['province'], $supplier['Supplier']['country'], $supplier['Supplier']['postal_code']); $tmp_suplliers[$supplier['Supplier']['id']]['phone'] = $this->phone_format($supplier['Supplier']['phone'], $supplier['Supplier']['phone_ext'], $supplier['Supplier']['cell'], $supplier['Supplier']['fax_number']); } return $tmp_suplliers; }
public function vistaEditar($id, $next, $seccion_next) { //Me quedo con el item, buscando por id $item = Item::find($id); $muestra = Muestra::find($item->muestra()->id); $secciones = parent::seccionesDinamicas(); if ($muestra) { $this->array_view['item'] = $muestra->item(); $this->array_view['muestra'] = $muestra; $this->array_view['secciones'] = $secciones; $this->array_view['continue'] = $next; $this->array_view['seccion_next'] = $seccion_next; $seccion = Seccion::find($seccion_next); $modulo = $seccion->menuSeccion()->modulo(); $this->array_view['menues'] = $modulo->menus; return View::make($this->folder_name . '.editar', $this->array_view); } else { $this->array_view['texto'] = Lang::get('controllers.error_carga_pagina'); return View::make($this->project_name . '-error', $this->array_view); } }
public static function borrar($input) { $respuesta = array(); $reglas = array(); $validator = Validator::make($input, $reglas); if ($validator->fails()) { $respuesta['mensaje'] = $validator; $respuesta['error'] = true; } else { $item = Item::find($input['id']); $item->fecha_baja = date("Y-m-d H:i:s"); $item->url = $item->url . "-borrado"; $item->estado = 'B'; $item->usuario_id_baja = Auth::user()->id; $item->save(); $respuesta['mensaje'] = 'Evento eliminado.'; $respuesta['error'] = false; $respuesta['data'] = $item; } return $respuesta; }
public static function isValid(array &$lineitem) { Zend_Registry::get('logger')->entering(); Zend_Registry::get('logger')->debug('Ensure buyer isn\'t the seller'); $items = new Item(); $item = $items->find($lineitem['item_id'])->current(); if (isset($item->owner_id) && $lineitem['user_id'] == $item->owner_id) { $lineitem['errors']['buyer'] = "owns this item"; } if (self::exists($lineitem['user_id'], $lineitem['item_id'])) { Zend_Registry::get('logger')->debug('Lineitem already exists'); $lineitem['errors']['item'] = 'is already in your shopping bag'; } else { Zend_Registry::get('logger')->debug('No such line item found'); } if (isset($lineitem['errors'])) { $ret = FALSE; } else { $ret = TRUE; } return $ret; Zend_Registry::get('logger')->exiting(); }
public function voteAction() { $item_id = $this->getRequest()->getParam('item'); $ip = $this->getRequest()->getServer('REMOTE_ADDR'); $vote_date = date("Ymd"); $where = "ip='{$ip}' and vote_date={$vote_date}"; $vote_log = new Vote_log(); $res = $vote_log->fetchAll($where)->toArray(); if (count($res) > 0) { $this->render('error'); } else { $date = array("ip" => $ip, "vote_date" => $vote_date, "item_id" => $item_id); if ($vote_log->insert($date) > 0) { $itemModel = new Item(); $item = $itemModel->find($item_id)->toArray(); $newcount = $item[0]['vote_count'] + 1; $set = array("vote_count" => $newcount); $where = "id={$item_id}"; $itemModel->update($set, $where); $this->render('ok'); } } }
public function process() { $factura = new Factura(); $factura->usuario_id = Auth::user()->id; $factura->total = Cart::total(); foreach (Cart::content() as $item) { if (Item::find($item['id'])->stock == 0) { Session::flash('error', 'El item ' . $item['name'] . ' se ha agotado'); return Redirect::back(); } if (Item::find($item['id'])->stock - $item['qty'] < 0) { Session::flash('error', 'No hay suficiente stock del item ' . $item['name'] . ' para cubrir su pedido'); return Redirect::back(); } } if ($factura->save()) { foreach (Cart::content() as $item) { $detalle = new Detalle(); $detalle->factura_id = $factura->id; $detalle->item_id = $item['id']; $detalle->cantidad = $item['qty']; if ($detalle->save()) { $deduct = Item::find($item['id']); $deduct->stock -= $item['qty']; $deduct->save(); } else { Session::flash('error', 'Error al procesar'); return Redirect::back(); } } } else { Session::flash('error', 'Error al procesar'); return Redirect::back(); } Cart::destroy(); return Redirect::to('shop'); }
public function getDetails($item_id) { $item = Item::find($item_id); // var_dump($item); $this->layout->content = View::make('item.details', array('item' => $item)); }
private function findItem($id_slug) { $article = Item::find()->where(['or', 'item_id=:id_slug', 'slug=:id_slug'], [':id_slug' => $id_slug])->status(Item::STATUS_ON)->one(); if ($article) { $article->updateCounters(['views' => 1]); return new ArticleObject($article); } else { return null; } }
public function item() { return Item::find($this->item_id); }
function getCabinetItems() { set_time_limit(0); $this->autoRender = false; $sql = "SELECT * FROM cabinetparts;"; $datas = $this->Cabinet->query($sql); App::uses("CabinetsItem", "Inventory.Model"); App::uses("Cabinet", "Inventory.Model"); $Cabinet_model = new Cabinet(); App::uses("Item", "Inventory.Model"); $Item_model = new Item(); foreach ($datas as $data) { $CabinetsItem_model = new CabinetsItem(); $cabinet_data['CabinetsItem']['lineid'] = $data['cabinetparts']['lineid']; $cabinet_data = $Cabinet_model->find('first', array('fields' => array('id', 'name'), 'conditions' => array('Cabinet.name' => $data['cabinetparts']['cabinet']), 'recursive' => -1)); $cabinet_data['CabinetsItem']['cabinet_id'] = !empty($cabinet_data['Cabinet']['id']) ? $cabinet_data['Cabinet']['id'] : "0"; $Item_data = $Item_model->find('first', array('fields' => array('id', 'number'), 'conditions' => array('Item.number' => $data['cabinetparts']['number']), 'recursive' => -1)); $cabinet_data['CabinetsItem']['item_id'] = !empty($Item_data['Item']['id']) ? $Item_data['Item']['id'] : "0"; if (!empty($Item_data)) { $item['Item']['id'] = $Item_data['Item']['id']; $item['Item']['item_department_id'] = 3; $item['Item']['Department'] = 'Accessories'; if (!$Item_model->save($item)) { pr($Item_model->validationErrors); } } $cabinet_data['CabinetsItem']['item_quantity'] = !empty($data['cabinetparts']['quantity']) ? $data['cabinetparts']['quantity'] : "1"; $cabinet_data['CabinetsItem']['component'] = $data['cabinetparts']['component']; $cabinet_data['CabinetsItem']['category'] = $data['cabinetparts']['category']; $cabinet_data['CabinetsItem']['number'] = $data['cabinetparts']['number']; $cabinet_data['CabinetsItem']['accessories'] = 1; if (!$CabinetsItem_model->save($cabinet_data)) { pr($CabinetsItem_model->validationErrors); } } }
/** * Show the form for editing the specified item. * * @param int $id * @return Response */ public function edit($id) { $item = Item::find($id); return View::make('items.edit', compact('item')); }
public function destroyAction() { $this->logger->entering(); $this->logger->info('Loading item from params'); $items = new Item(); $item = $this->_getParam('item'); $this->logger->info("Loading item by id"); $id = $item['id']; $item = $items->find($id)->current(); $this->logger->info('Ensure owned by user'); if ($this->session->user_id != $item->owner_id) { $this->logger->warn('User is not item owner'); $this->flash->notice = "Invalid Action"; $this->_redirect('/'); } $this->logger->info("Delete item by id {$id}"); $where = $this->db->quoteInto('id = ?', $id); $rows_affected = $items->delete($where); $this->logger->info('Delete item tag associations'); $items->deleteTags($id); $this->logger->info("Removing old item from search index"); ItemIndex::delete($item); $this->logger->info('Redirect to item index'); $this->_redirect('items'); $this->logger->exiting(); }
public function postDocSave($id) { $document = Document::find($id); $type = $document->os_type; $items = Document::find($document->id)->items; $sum_carrying_amount = 0; $sum_residual_value = 0; foreach ($items as $item) { if (isset($item->carrying_amount)) { $sum_carrying_amount = $sum_carrying_amount + $item->carrying_amount; } else { $sum_carrying_amount = $sum_carrying_amount; } if ($type != 'parcels') { $variable = Item::find($item->id)->variable; if (isset($variable->residual_value)) { $sum_residual_value = $sum_residual_value + $variable->residual_value; } $sum_residual_value = $sum_residual_value; } } $document->doc_carrying_amount = $sum_carrying_amount; if ($type != 'parcels') { $document->doc_residual_value = $sum_residual_value; } $document->save(); return Redirect::to('documents'); }
function item($id = FALSE) { if ($_POST) { unset($_POST['send']); $_POST = array_map('htmlspecialchars', $_POST); if ($_POST['name'] != "") { $_POST['name'] = $_POST['name']; $_POST['value'] = $_POST['value']; $_POST['type'] = $_POST['type']; } else { if ($_POST['item_id'] == "-") { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_add_item_error')); redirect('estimates/view/' . $_POST['invoice_id']); } else { $itemvalue = Item::find_by_id($_POST['item_id']); $_POST['name'] = $itemvalue->name; $_POST['type'] = $itemvalue->type; $_POST['value'] = $itemvalue->value; } } $item = InvoiceHasItem::create($_POST); if (!$item) { $this->session->set_flashdata('message', 'error:' . $this->lang->line('messages_add_item_error')); } else { $this->session->set_flashdata('message', 'success:' . $this->lang->line('messages_add_item_success')); } redirect('estimates/view/' . $_POST['invoice_id']); } else { $this->view_data['estimate'] = Invoice::find($id); $this->view_data['items'] = Item::find('all', array('conditions' => array('inactive=?', '0'))); $this->theme_view = 'modal'; $this->view_data['title'] = $this->lang->line('application_add_item'); $this->view_data['form_action'] = 'estimates/item'; $this->content_view = 'estimates/_item'; } }
/** * testUpdateBoolean * * return @void */ public function testUpdateBoolean() { $this->loadFixtures('Item', 'Syfile', 'Portfolio', 'Image', 'ItemsPortfolio'); $TestModel = new Item(); $result = $TestModel->save(array('published' => true, 'id' => 1)); $this->assertTrue((bool) $result); $result = $TestModel->find('first', array('fields' => array('id', 'published'), 'conditions' => array('Item.id' => 1))); $this->assertEquals(true, $result['Item']['published']); }
/** * Remove the specified resource from storage. * e.g. curl -i --user a@aa.com:a1\! -H "Content-Type: application/json" -X DELETE localhost:8000/api/v1/item/4 * * @param int $id * @return Response */ public function destroy($id) { $item = Item::find($id); if (!is_object($item)) { // Return 404 Not Found if item does not exist return Response::json(null, 404); } else { if ($item->creator != Auth::user()->user_id) { // Return 401 Unauthorized if the item was not created by the authenticated user return Response::json(null, 401); } else { // Delete the item if it exists and it was created by the authenticated user $item->delete(); return Response::json(null, 200); } } }