/** * Store a newly created resource in storage. * * @return Response */ public function store() { $validator = Validator::make(Input::all(), array('company_id' => 'required', 'name' => 'required', 'description' => 'required', 'url' => 'required|url', 'photo' => 'required|image')); if ($validator->fails()) { return Response::json($validator->messages(), 400); } $item = new Item(); $item->company_id = Input::get('company_id'); $item->name = Input::get('name'); $item->description = Input::get('description'); $item->url = Input::get('url'); //temporary for territory $item->territory_id = 1; $item->save(); //save tags if available foreach (Input::get('tag') as $tagid) { $item->tags()->attach($tagid); } $image = Input::file('photo'); $filename = $item->id; $saveBigUrl = base_path() . '/public/images/items/' . $filename . '.jpg'; $saveMediumUrl = base_path() . '/public/images/items/' . $filename . '_medium.jpg'; $saveSmallUrl = base_path() . '/public/images/items/' . $filename . '_small.jpg'; Image::make($image->getRealPath())->fit(600, null, function ($constraint) { //for big image $constraint->upsize(); })->save($saveBigUrl, 50)->fit(300)->save($saveMediumUrl, 50)->fit(100)->save($saveSmallUrl, 50); $item->big_image_url = url('images/items/' . $filename . '.jpg'); $item->medium_image_url = url('images/items/' . $filename . '_medium.jpg'); $item->small_image_url = url('images/items/' . $filename . '_small.jpg'); $item->save(); return Response::json(array('success_code' => 'OK', 'data' => $item->toArray()), 200); }
/** * Set ups up for each test. * * @return void * @author Eric Rochester <*****@*****.**> **/ public function setUp() { parent::setUp(); $this->_todel = array(); $this->user = $this->db->getTable('user')->find(1); $this->_authenticateUser($this->user); $this->phelper = new Omeka_Test_Helper_Plugin(); $this->phelper->setUp('NeatlineFeatures'); $this->_dbHelper = Omeka_Test_Helper_Db::factory($this->application); // Retrieve the element for some DC fields. $el_table = get_db()->getTable('Element'); $this->_title = $el_table->findByElementSetNameAndElementName('Dublin Core', 'Title'); $this->_subject = $el_table->findByElementSetNameAndElementName('Dublin Core', 'Subject'); $this->_coverage = $el_table->findByElementSetNameAndElementName('Dublin Core', 'Coverage'); $this->_cutil = new NeatlineFeatures_Utils_View(); $this->_cutil->setEditOptions(null, $this->_coverage, "", "Elements[38][0]", 0); $this->_item = new Item(); $this->_item->save(); $this->toDelete($this->_item); $t1 = $this->addElementText($this->_item, $this->_title, '<b>A Title</b>', 1); $t2 = $this->addElementText($this->_item, $this->_subject, 'Subject'); $this->toDelete($t1); $this->toDelete($t2); $this->_item->save(); }
public function store() { try { $addModel = Input::json()->all(); //select the vendor name of the new selected vendor $vendorQueryResult = Vendor::find($addModel['vendor_id']); $newVendorName = $vendorQueryResult->name; //creates the new item, sets the properties, and saves it $addItem = new Item(); $addItem->description = $addModel['description']; $addItem->email_threshold = $addModel['email_threshold']; $addItem->item_url = $addModel['item_url']; $addItem->name = $addModel['name']; $addItem->on_order_quantity = $addModel['on_order_quantity']; $addItem->quantity = $addModel['quantity']; $addItem->vendor_id = $addModel['vendor_id']; $addItem->active = 1; $addItem->save(); $addItem->adjustmentQty = 0; $addItem->vendor_name = $newVendorName; return $addItem->toJson(); } catch (Exception $e) { return json_encode('{"error":{"text":' . $e->getMessage() . '}}'); } }
function processFile($filename) { //extract the filename to get the exact filename on the folder $newFile = substr($filename, 3); $dirname = substr($filename, 0, 2); $fs = new Filesystem(); if ($fs->exists('../Repo/' . $dirname . '/' . $newFile)) { $xml = simplexml_load_file('../Repo/' . $dirname . '/' . $newFile, null, LIBXML_NOCDATA); $newXML = json_decode(json_encode($xml), true); $data = formulateData($newXML, $dirname); //insert data to db $po = new PurchaseOrder(); $po->setFilename($newFile); $po->setStore($dirname); $po->setCustomerCode($data['customer_code']); $po->setDeliveryDate($data['delivery_date']); $po->setNumber($data['number']); $po->save(); $po_id = $po->getId(); //insert all items foreach ($data['items'] as $key => $value) { $items = new Item(); $items->setPurchaseOrderId($po_id); $items->setUpc($value['upc']); $items->setQty($value['qty']); $items->setQty($value['discount']); $items->save(); } $formulated_data = formulateData($newXML, $dirname); $formulated_data['id'] = $po_id; //print_r($formulated_data); return $formulated_data; } }
public static function save_new_item_to_wardrobe() { self::check_logged_in(); $params = $_POST; // Alustetaan uusi Item-luokan olion käyttäjän syöttämillä arvoilla // Tallennetaan erikseen attribuutit muuttujaan.. $attributes = array('type' => $params['type'], 'brand' => $params['brand'], 'color' => $params['color'], 'color_2nd' => $params['color_2nd'], 'material' => $params['material'], 'image' => $params['image']); //..ja luodaan olio attributestaulukon avulla $item = new Item($attributes); // kutsutaan item:in metodia errors, joka tarkistaa olivatko // attribuutit valideja $errors = $item->errors(); if (count($errors) == 0) { // Validi item, tallennetaan // Kutsutaan alustamamme olion save metodia, joka tallentaa olion tietokantaan $item->save(); //tallennetaan mys käyttäjän vaatekaappiin Wardrobe::add_item_for_person($item->item_id, $_SESSION['user']); // Ohjataan käyttäjä lisäyksen jälkeen vaatteen esittelysivulle Redirect::to('/wardrobe/wardrobe.html', array('message' => 'Item added to your wardrobe!')); } else { // Invalidi syöte // Luodaan uusi näkymä johon välitetään syötetyt arvot View::make('wardrobe/new_item.html', array('errors' => $errors, 'attributes' => $attributes)); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $item = new Item(); $detil_item = new DetilItem(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Item'], $_POST['DetilItem'])) { $item->attributes = $_POST['Item']; $detil_item->attributes = $_POST['DetilItem']; if ($item->validate() & $detil_item->validate()) { $connection = Yii::app()->db; $transaction = $connection->beginTransaction(); try { if ($item->save()) { $detil_item->setAttribute('ID_ITEM', $item->ID_ITEM); $detil_item->setAttribute('TANGGAL_INPUT', date('Y-m-d H:i:s')); if ($detil_item->save()) { $transaction->commit(); Yii::app()->user->setFlash('info', MyFormatter::alertSuccess('<strong>Selamat!</strong> Data telah berhasil disimpan.')); $this->redirect(array('view', 'id' => $item->ID_ITEM)); } } } catch (Exception $e) { $transaction->rollback(); Yii::app()->user->setFlash('info', MyFormatter::alertDanger('<strong>Error!</strong> Data gagal untuk disimpan.' . $e->getMessage())); } } } $this->render('create', array('item' => $item, 'detil_item' => $detil_item)); }
/** * Save Item * * @param Item $item * @throws DaoException */ public function saveItem(Item $item) { try { $item->save(); } catch (Exception $e) { throw new DaoException($e->getMessage(), $e->getCode(), $e); } }
public function add_item($book_id, $quantity = 1) { $item = new Item(); $item->book_id = $book_id; $item->cart_id = $this->id; $item->quantity = $quantity; $item->save(); }
public function postNewItem($f3) { $new_item = new Item($f3->get('DB')); $new_item->label = $f3->get('POST["label"]'); $new_item->price = $f3->get('POST["price"]'); $new_item->quantity = $f3->get('POST["quantity"]'); $new_item->discount = $f3->get('POST["discount"]'); $new_item->type = $f3->get('POST["type"]'); $new_item->save(); }
function item_post() { $message = array('id' => $this->get('id'), 'title' => $this->post('title')); $item = new Item(); $item->title = $this->post('title'); $item->datetime = $this->post('datetime'); $item->save(); $this->response($message, 200); // 200 being the HTTP response code }
public function add() { $item = new Item(); $item->user_id = $this->session->userdata('id'); $item->item = $this->input->post('listing-title'); $item->description = $this->input->post('listing-body'); $item->asking = $this->input->post('listing-asking'); $item->save(); // Redirect to view mode header('Location: /marketplace'); }
/** * Performs the work of inserting or updating the row in the database. * * If the object is new, it inserts it; otherwise an update is performed. * All related objects are also updated in this method. * * @param PropelPDO $con * @return int The number of rows affected by this insert/update and any referring fk objects' save() operations. * @throws PropelException * @see save() */ protected function doSave(PropelPDO $con) { $affectedRows = 0; // initialize var to track total num of affected rows if (!$this->alreadyInSave) { $this->alreadyInSave = true; // We call the save method on the following object(s) if they // were passed to this object by their coresponding set // method. This object relates to these object(s) by a // foreign key reference. if ($this->aEmpresa !== null) { if ($this->aEmpresa->isModified() || $this->aEmpresa->isNew()) { $affectedRows += $this->aEmpresa->save($con); } $this->setEmpresa($this->aEmpresa); } if ($this->aItem !== null) { if ($this->aItem->isModified() || $this->aItem->isNew()) { $affectedRows += $this->aItem->save($con); } $this->setItem($this->aItem); } if ($this->isNew()) { $this->modifiedColumns[] = DocumentoPeer::ID_DOCUMENTO; } // If this object has been modified, then save it to the database. if ($this->isModified()) { if ($this->isNew()) { $pk = DocumentoPeer::doInsert($this, $con); $affectedRows += 1; // we are assuming that there is only 1 row per doInsert() which // should always be true here (even though technically // BasePeer::doInsert() can insert multiple rows). $this->setIdDocumento($pk); //[IMV] update autoincrement primary key $this->setNew(false); } else { $affectedRows += DocumentoPeer::doUpdate($this, $con); } $this->resetModified(); // [HL] After being saved an object is no longer 'modified' } if ($this->collHistoricoDocumentos !== null) { foreach ($this->collHistoricoDocumentos as $referrerFK) { if (!$referrerFK->isDeleted()) { $affectedRows += $referrerFK->save($con); } } } $this->alreadyInSave = false; } return $affectedRows; }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $input = Input::get('text'); $item = new Item(); $item->text = $input; $item->save(); if ($item) { return 1; } else { return 0; } }
public function run() { $item = new Item(); $item->item_name = 'Thuderfury, Blessed Blade of the Windseeker'; $item->item_type = 'Weapon'; $item->date_listed = '1902-05-22'; $item->price = '150.00'; $item->unit = 'g'; $item->description = 'Did someone say Thunderfury? Legendary! '; $item->item_number = '19019'; $item->save(); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $input = Input::get('name'); $item = new Item(); $item->name = $input; $item->save(); if ($item) { return $item->id; } else { return 0; } }
function test_deleteAll() { $name = "Gold Liberty Dollar"; $name2 = "Bronze My Little Pony: Applejack"; $test_Item = new Item(null, $name); $test_Item->save(); $test_Item2 = new Item(null, $name2); $test_Item2->save(); Item::deleteAll(); $result = Item::getAll(); $this->assertEquals([], $result); }
/** * Store a newly created resource in storage. * * @return Response */ public function store() { $item = new Item(); $item->item_name = Input::get('item_name'); $item->item_type = Input::get('item_type'); $item->date_listed = Input::get('date_listed'); $item->price = Input::get('price'); $item->unit = Input::get('unit'); $item->description = Input::get('description'); $item->item_number = Input::get('item_number'); $item->save(); return Redirect::action('ItemsController@index'); }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Item(); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Item'])) { $model->attributes = $_POST['Item']; if ($model->save()) { $this->redirect(array('view', 'id' => $model->id_item)); } } $this->render('create', array('model' => $model)); }
public function postNew() { $rules = array('name' => 'required|min:3|max:255'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::route('new')->withErrors($validator); } $item = new Item(); $item->name = Input::get('name'); $item->onwer_id = Auth::user()->id; $item->save(); return Redirect::route('home'); }
/** * There should be a web map service tab in the item edit form. * * @return void. */ public function testItemEditTab() { // Create item. $item = new Item(); $item->save(); // Hit item edit. $this->dispatch('items/edit/' . $item->id); // Check for tab. $this->assertXpathContentContains('//ul[@id="section-nav"]/li/a[@href="#web-map-service-metadata"]', 'Web Map Service'); // Check for textareas. $this->assertXpath('//textarea[@id="address"][@name="address"]'); $this->assertXpath('//textarea[@id="layers"][@name="layers"]'); }
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 addItem($itemId) { $shop = Shop::where('user_id', Auth::user()->id)->first(); if (!$shop) { $shop = new Shop(); $shop->user_id = Auth::user()->id; $shop->save(); } $shopItem = new Item(); $shopItem->item_id = $itemId; $shopItem->shop_id = $cart->id; $shopItem->save(); return redirect('/shop'); }
/** * Store a newly created resource in storage. * POST /item * * @return Response */ public function store() { Input::merge(array_map('trim', Input::all())); $input = Input::all(); $validation = Validator::make($input, Item::$rules); if ($validation->passes()) { $item = new Item(); $item->item = strtoupper(Input::get('item')); $item->save(); return Redirect::route('item.index')->with('class', 'success')->with('message', 'Record successfully created.'); } else { return Redirect::route('item.create')->withInput()->withErrors($validation)->with('class', 'error')->with('message', 'There were validation error.'); } }
/** * Creates a new model. * If creation is successful, the browser will be redirected to the 'view' page. */ public function actionCreate() { $model = new Item(); //var_dump($model);exit; if (isset($_POST['Item'])) { $this->handlePostData(); $model->attributes = $_POST['Item']; // var_dump($model->attributes);exit; if ($model->save()) { $this->redirect(array('view', 'id' => $model->item_id)); } } $this->render('create', array('model' => $model)); }
public function postAddItem() { $rules = array('description' => 'required|min:3|max:100'); $validator = Validator::make(Input::all(), $rules); if ($validator->fails()) { return Redirect::route('todo/add')->withErrors($validator); } /* Item toevoegen aan DB */ $item = new Item(); $item->name = Input::get('description'); $item->owner_id = Auth::user()->id; $item->save(); return Redirect::to('todo')->with('message', 'Het item "' . Input::get('description') . '" is toegevoegd.'); }
public function run() { //$nurse_ids = Yii::app()->request->getParam('id',0); $item_model = new Item(); $com_id = $this->controller->comId; if (isset($_POST['Item'])) { $_POST['Item']['com_id'] = $com_id; $item_model->attributes = $_POST['Item']; if ($item_model->save()) { $this->controller->redirect('/mama/item/index'); } } $this->controller->render('add', array('item_model' => $item_model)); }
/** * This tests that the DELETE hook works properly. * * @return void * @author Eric Rochester <*****@*****.**> **/ public function testDeleteHook() { $item = new Item(); $item->save(); $text = $this->addElementText($item, $this->_title, '<b>testDeleteHook</b>', 1); $this->toDelete($text); $text = $this->addElementText($item, $this->_coverage, "WKT: POINT(123, 456)\n\nSomthing", 0); $this->toDelete($text); $_POST['Elements'][(string) $this->_cutil->getElementId()] = array('0' => array('mapon' => '1', 'text' => '')); $item->save(); $item_id = $item->id; $item->delete(); $results = $this->db->getTable('NeatlineFeature')->findBy(array('item_id' => $item_id)); $this->assertEmpty($results); }
/** * Try to map a correspondence between the local and remote owners. Requires that a key with * sufficient permission to the API is given * * @param Item $item */ protected function updateItemOwner($item) { $ownerId = $this->responseData['owner']['id']; if (!$ownerId) { $item->owner_id = null; $item->save(); return; } $owner = $this->db->getTable('OmekaApiImportRecordIdMap')->localRecord('User', $ownerId, $this->endpointUri); if ($owner) { $item->owner_id = $owner->id; } else { $response = $this->service->users->get($ownerId); if ($response->getStatus() == 200) { $responseData = json_decode($response->getBody(), true); $adapter = new ApiImport_ResponseAdapter_Omeka_UserAdapter($responseData, $this->endpointUri); $adapter->import(); $item->owner_id = $adapter->record->id; } else { _log(__("Attempting User import") . " " . $response->getStatus() . ": " . $response->getMessage(), Zend_Log::INFO); } } $item->save(); }
/** * Store a newly created resource in storage. * e.g. curl -i --user a@aa.com:a1\! -H "Content-Type: application/json" -X POST -d '{"name":"Smart 68 Keyboard","image_url":"http://image.com/1"}' localhost:8000/api/v1/item * * @return Response */ public function store() { $validator = Validator::make(Input::all(), array('name' => 'required|min:3|unique:items', 'image_url' => 'url')); if ($validator->fails()) { return Response::json(array('errors' => $validator->messages()), 400); } $item = new Item(); $item->name = Input::get('name'); $item->image_url = Input::get('image_url'); $item->creator = Auth::user()->user_id; $item->save(); $response = Response::json(null, 201); $response->header('Location', action('ItemController@show', $item->item_id)); return $response; }
/** * Tests that all_element_texts can correctly produce an array as output. */ public function testArrayOutput() { $title = 'title'; $subject = 'subject'; $description = 'description'; $elementTexts = array('Dublin Core' => array('Title' => array(array('text' => $title, 'html' => false)), 'Subject' => array(array('text' => $subject, 'html' => false)), 'Description' => array(array('text' => $description, 'html' => false)))); $item = new Item(); $item->addElementTextsByArray($elementTexts); $item->save(); $metadataOutput = all_element_texts($item, array('return_type' => 'array')); $this->assertInternalType('array', $metadataOutput); $this->assertArrayHasKey('Dublin Core', $metadataOutput); $this->assertEquals($title, $metadataOutput['Dublin Core']['Title'][0]); $this->assertEquals($subject, $metadataOutput['Dublin Core']['Subject'][0]); $this->assertEquals($description, $metadataOutput['Dublin Core']['Description'][0]); }