/** * Store a newly created resource in storage. * * @return Response */ public function store() { $input = Input::all(); $validation = Validator::make($input, Location::$rules); if ($validation->passes()) { $this->location->create($input); return Redirect::route('admin.locations.index'); } return Redirect::route('admin.locations.create')->withInput()->withErrors($validation)->with('message', 'There were validation errors.'); }
public function run() { $faker = Faker::create(); foreach (range(1, 10) as $index) { Location::create([]); } }
public static function create($data) { session_start(); $headers = apache_request_headers(); $token = $headers['X-Auth-Token']; if ($token != $_SESSION['form_token']) { header('Invalid CSRF Token', true, 401); return print json_encode(array('success' => false, 'status' => 400, 'msg' => 'Invalid CSRF Token / Bad Request / Unauthorized ... Please Login again'), JSON_PRETTY_PRINT); } else { if (isset($data['name']) && empty($data['name'])) { return print json_encode(array('success' => false, 'status' => 200, 'msg' => 'Location Name is required'), JSON_PRETTY_PRINT); } else { if (isset($data['x_coord']) && empty($data['x_coord'])) { return print json_encode(array('success' => false, 'status' => 200, 'msg' => 'X Coordinate is required'), JSON_PRETTY_PRINT); } else { if (isset($data['y_coord']) && empty($data['y_coord'])) { return print json_encode(array('success' => false, 'status' => 200, 'msg' => 'Y Coordinate is required'), JSON_PRETTY_PRINT); } else { $var = ['name' => $data['name'], 'x' => $data['x_coord'], 'y' => $data['y_coord'], 'description' => $data['description'], 'landarea' => $data['landarea'], 'image_path' => $data['image_path']]; Location::create($var); } } } } }
/** * @param array $attributes */ public function loadRelated(array $attributes) { parent::loadRelated($attributes); if (isset($attributes['location'])) { $this->location = Location::create($attributes['location']); } }
public function run() { $faker = Faker::create(); foreach (range(1, 20) as $index) { Location::create(['location_name' => $faker->company, 'location_street' => $faker->streetAddress, 'location_city' => $faker->city, 'location_state' => $faker->stateAbbr, 'location_zip' => $faker->postcode]); } }
/** * Store a newly created location in storage. * * @return Response */ public function store() { $validator = Validator::make($data = Input::all(), Location::$rules); if ($validator->fails()) { return Redirect::back()->withErrors($validator)->withInput(); } Location::create($data); return Redirect::route('locations.index'); }
/** * Run the migrations. * * @return void */ public function up() { Schema::create('locations', function (Blueprint $table) { $table->increments('id'); $table->string('location')->unique(); $table->timestamps(); }); Location::create(['location' => 'Baguio City']); Location::create(['location' => 'Gen San']); }
/** * Фабрикует класс, обрабатывающий сообщение * @param array $m Сообщение на вход * @return object Класс, ответственный за данный тип сообщения */ public static function parseInput($m) { if (empty($m['message_id'])) { return NULL; } if (!empty($m['text'])) { $command = Command::create($m); return $command ? $command : TextMessage::create($m); } elseif (!empty($m['location'])) { return Location::create($m); } }
/** * Creates a clan object with the given data * @param array $data an associative array to fill up the members of the * clan class * @return Clan a clan object with the data given as it's members */ public static function create(array $data) : Clan { $clan = new Clan(); parent::fill($data, $clan); if (is_array($clan->location)) { $clan->location = Location::create($clan->location); } if (is_array($clan->memberList)) { $members = []; foreach ($clan->memberList as $member) { $members[] = Player::create($member); } $clan->memberList = $members; } return $clan; }
/** * This function will grab input data for both the Location and CalendarEvent models * and store the newly created Location and CalendarEvent * @return Response */ public function store() { // Grab the Input data for the everything $input = Input::only('name', 'address', 'city', 'state', 'postal_code', 'start_time', 'end_time', 'title', 'description', 'price'); //validate:form exceptions handled in start/global.php $this->calendarEventForm->validate($input); if (Input::get('location') == -1) { $location = Location::create($input); $locationId = $location->id; } else { $locationId = Input::get('location'); } $calendarEvent = CalendarEvent::create(array('start_time' => Input::get('start_time'), 'end_time' => Input::get('end_time'), 'title' => Input::get('title'), 'description' => Input::get('description'), 'price' => Input::get('price'), 'location_id' => $locationId, 'user_id' => Auth::id())); return Response::json(CalendarEvent::with('user', 'location')->where('user_id', Auth::id())->get()); // On Successful Creation Show The Event Page // return Redirect::action('CalendarEventsController@show', $calendarEvent->id); }
private function addorupdateLcnsAndPrsnAddr($person_id, $postedData){ //for person addresses. //office address $ofcaddrid = $postedData->ofcaddresses[0]->id; if($postedData->isofcaddress){ $addrattributes = array( "street" => $postedData->ofcaddresses[0]->street, "locality" => $postedData->ofcaddresses[0]->locality, "city" => $postedData->ofcaddresses[0]->city, "state" => $postedData->ofcaddresses[0]->state, "country" => $postedData->ofcaddresses[0]->country, "pincode" => $postedData->ofcaddresses[0]->pincode, "remarks" => $postedData->ofcaddresses[0]->remarks ); if($ofcaddrid > 0){ $addrdata = \Location::find($ofcaddrid); $addrdata->update_attributes($addrattributes); }else{ $addrdata = \Location::create($addrattributes); $this->createPersonAddress($person_id, $addrdata->id, "office"); } }else{ $this->deletePersonLocations($person_id, $ofcaddrid, "office"); } //residence address $rsdaddrid = $postedData->rsdaddresses[0]->id; if($postedData->isrsdaddress){ $addrattributes = array( "street" => $postedData->rsdaddresses[0]->street, "locality" => $postedData->rsdaddresses[0]->locality, "city" => $postedData->rsdaddresses[0]->city, "state" => $postedData->rsdaddresses[0]->state, "country" => $postedData->rsdaddresses[0]->country, "pincode" => $postedData->rsdaddresses[0]->pincode, "remarks" => $postedData->rsdaddresses[0]->remarks ); if($rsdaddrid > 0){ $addrdata = \Location::find($rsdaddrid); $addrdata->update_attributes($addrattributes); }else{ $addrdata = \Location::create($addrattributes); $this->createPersonAddress($person_id, $addrdata->id, "residence"); } }else{ $this->deletePersonLocations($person_id, $rsdaddrid, "residence"); } //other address $otheraddrid = $postedData->otheraddresses[0]->id; if($postedData->isotheraddress){ $addrattributes = array( "street" => $postedData->otheraddresses[0]->street, "locality" => $postedData->otheraddresses[0]->locality, "city" => $postedData->otheraddresses[0]->city, "state" => $postedData->otheraddresses[0]->state, "country" => $postedData->otheraddresses[0]->country, "pincode" => $postedData->otheraddresses[0]->pincode, "remarks" => $postedData->otheraddresses[0]->remarks ); if($otheraddrid > 0){ $addrdata = \Location::find($otheraddrid); $addrdata->update_attributes($addrattributes); }else{ $addrdata = \Location::create($addrattributes); $this->createPersonAddress($person_id, $addrdata->id, "other"); } }else{ $this->deletePersonLocations($person_id, $otheraddrid, "other"); } }
/** * @throws LocationIDMissingException */ public static function add() { if ($_GET['action'] == "add_child" and $_GET['id'] or $_GET['action'] == "add") { if ($_GET['nextpage'] == 1) { $page_1_passed = true; if (!$_POST['name']) { $page_1_passed = false; $error = "You must enter a name"; } } else { $page_1_passed = false; $error = ""; } if ($page_1_passed == false) { $template = new HTMLTemplate("location/admin/location/add.html"); $paramquery = $_GET; $paramquery['nextpage'] = "1"; $params = http_build_query($paramquery, '', '&'); $template->set_var("params", $params); if ($error) { $template->set_var("error", $error); } else { $template->set_var("error", ""); } $type_array = Location::list_types(); $result = array(); $counter = 0; if (is_array($type_array) and count($type_array) >= 1) { foreach ($type_array as $key => $value) { if ($_POST['type_id'] == $value['id']) { $result[$counter]['selected'] = "selected='selected'"; } else { $result[$counter]['selected'] = ""; } $result[$counter]['value'] = $value['id']; $result[$counter]['content'] = $value['name']; $counter++; } } $template->set_var("type_array", $result); if ($_POST['name']) { $template->set_var("name", $_POST['name']); } else { $template->set_var("name", ""); } if ($_POST['additional_name']) { $template->set_var("additional_name", $_POST['additional_name']); } else { $template->set_var("additional_name", ""); } $template->output(); } else { $location = new Location(null); if ($_GET['action'] == "add_child" and is_numeric($_GET['id'])) { $toid = $_GET['id']; } else { $toid = null; } if ($_POST['prefix'] == "1") { $show_prefix = true; } else { $show_prefix = false; } $paramquery = $_GET; unset($paramquery['action']); unset($paramquery['nextpage']); $params = http_build_query($paramquery, '', '&'); if ($location->create($toid, $_POST['type_id'], $_POST['name'], $_POST['additional_name'], $show_prefix)) { Common_IO::step_proceed($params, "Add Location", "Operation Successful", null); } else { Common_IO::step_proceed($params, "Add Location", "Operation Failed", null); } } } else { throw new LocationIDMissingException(); } }
public function ajax_add_entry() { $response = array('success' => 0, 'error' => 'Something went wrong. Please try again.'); if (wp_verify_nonce($_POST['entry_nonce'], 'entry-nonce')) { $miles = strlen(trim($_POST['miles'])) > 0 && is_numeric($_POST['miles']) ? abs(trim($_POST['miles'])) : 1; $location = new Location(); if ($_POST['location_id'] > 0) { $location->id = $_POST['location_id']; $location->read(); if (!$location->user_id == get_current_user_id()) { $location->id = 0; } } if ($location->id == 0) { $location->user_id = get_current_user_id(); $location->title = strlen(trim($_POST['title'])) > 0 ? trim($_POST['title']) : 'New Location'; $location->miles = $miles; $location_id = Location::checkTitle($location->user_id, $location->title); if ($location_id > 0) { $location->id = $location_id; $location->update(); } else { $location->create(); } } $entry = new Entry(); $entry->user_id = get_current_user_id(); $entry->entry_date = $_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day']; $entry->mode = $_POST['mode']; $entry->miles = $miles; $entry->location = $location; $entry->create(); if ($entry->id > 0) { $response['success'] = 1; $response['id'] = $entry->id; $response['title'] = $entry->location->title; $response['miles'] = number_format($entry->miles, 2); $response['day'] = $_POST['day']; } } header('Content-Type: application/json'); echo json_encode($response); exit; }
static function select($query, $bindings = array(), $useReadPdo = true) { return static::connection()->select($query, $bindings = array(), $useReadPdo = true); } } class Location extends Model { use GeoDistanceTrait; protected $fillable = ['name', 'lat', 'lng']; public $timestamps = false; } Capsule::table('locations')->truncate(); Location::create(['name' => 'Cardiff', 'lat' => 51.4833, 'lng' => 3.1833]); Location::create(['name' => 'Newport', 'lat' => 51.5833, 'lng' => 3.0]); Location::create(['name' => 'Swansea', 'lat' => 51.6167, 'lng' => 3.95]); Location::create(['name' => 'London', 'lat' => 51.5072, 'lng' => 0.1275]); /*for ($i = 0; $i < 1000; $i++) { Location::create(['location' => $i, 'lat' => $i, 'lng' => $i, 'updated_at' => $i, 'created_at' => $i]); }*/ $I = new UnitTester($scenario); $lat = 51.4833; $lng = 3.1833; $location = new Location(); $locations = $location->lat($lat)->lng($lng)->within(20, 'miles')->get(); $I->wantTo('find locations within 5 miles'); $locations = Location::within(5, 'miles', $lat, $lng)->get(); $I->assertEquals(1, $locations->count(), 'One location found within 5 miles'); $I->wantTo('find 2 locations within 132000 feet (25 miles)'); $locations = Location::within(132000, 'feet', $lat, $lng)->get(); $I->assertEquals(2, $locations->count(), 'One location found within 132000 feet');
/** * saveOrder * * @param unknown $sender * @param unknown $param * * @throws Exception * */ public function saveOrder($sender, $param) { $results = $errors = array(); try { Dao::beginTransaction(); $items = array(); $purchaseOrder = PurchaseOrder::get(trim($param->CallbackParameter->purchaseOrder->id)); if (!$purchaseOrder instanceof PurchaseOrder) { throw new Exception('Invalid PurchaseOrder passed in!'); } $comment = trim($param->CallbackParameter->comments); $purchaseOrder->addComment(Comments::TYPE_WAREHOUSE, $comment); $products = $param->CallbackParameter->products; $outStandingOrders = array(); $invoiceNos = array(); foreach ($products->matched as $item) { $product = Product::get(trim($item->product->id)); if (!$product instanceof Product) { throw new Exception('Invalid Product passed in!'); } if (isset($item->product->EANcode)) { $EANcode = trim($item->product->EANcode); $productcodes = ProductCode::getAllByCriteria('pro_code.productId = :productId and pro_code.typeId = :typeId', array('productId' => $product->getId(), 'typeId' => ProductCodeType::ID_EAN), true, 1, 1); if (count($productcodes) > 0) { $productcodes[0]->setCode($EANcode)->save(); } else { ProductCode::create($product, ProductCodeType::get(ProductCodeType::ID_EAN), $EANcode); } } if (isset($item->product->UPCcode)) { $UPCcode = trim($item->product->UPCcode); $productcodes = ProductCode::getAllByCriteria('pro_code.productId = :productId and pro_code.typeId = :typeId', array('productId' => $product->getId(), 'typeId' => ProductCodeType::ID_UPC), true, 1, 1); if (sizeof($productcodes)) { $productcodes[0]->setCode($UPCcode)->save(); } else { ProductCode::create($product, ProductCodeType::get(ProductCodeType::ID_UPC), $UPCcode); } } if (isset($item->product->warehouseLocation) && ($locationName = trim($item->product->warehouseLocation)) !== '') { $locs = Location::getAllByCriteria('name = ?', array($locationName), true, 1, 1); $loc = count($locs) > 0 ? $locs[0] : Location::create($locationName, $locationName); $product->addLocation(PreferredLocationType::get(PreferredLocationType::ID_WAREHOUSE), $loc); } $serials = $item->serial; $totalQty = 0; foreach ($serials as $serial) { $qty = trim($serial->qty); $totalQty += intval($qty); $serialNo = trim($serial->serialNo); $unitPrice = trim($serial->unitPrice); $invoiceNo = trim($serial->invoiceNo); $invoiceNos[] = $invoiceNo; $comments = trim($serial->comments); ReceivingItem::create($purchaseOrder, $product, $unitPrice, $qty, $serialNo, $invoiceNo, $comments); } OrderItem::getQuery()->eagerLoad('OrderItem.order', 'inner join', 'ord', 'ord.id = ord_item.orderId and ord.active = 1 and ord.type = :ordType and ord_item.productId = :productId and ord.statusId in ( :statusId1, :statusId2, :statusId3)'); $orderItems = OrderItem::getAllByCriteria('ord_item.active = 1', array('ordType' => Order::TYPE_INVOICE, 'productId' => $product->getId(), 'statusId1' => OrderStatus::ID_INSUFFICIENT_STOCK, 'statusId2' => OrderStatus::ID_ETA, 'statusId3' => OrderStatus::ID_STOCK_CHECKED_BY_PURCHASING)); if (count($orderItems) > 0) { $orders = array(); foreach ($orderItems as $orderItem) { if (!array_key_exists($orderItem->getOrder()->getId(), $orders)) { $orders[$orderItem->getOrder()->getId()] = $orderItem->getOrder()->getJson(); } } $outStandingOrders[$product->getId()] = array('product' => $product->getJson(), 'recievedQty' => $totalQty, 'outStandingOrders' => array_values($orders)); } } $results['outStandingOrders'] = count($outStandingOrders) > 0 ? array_values($outStandingOrders) : array(); $results['item'] = PurchaseOrder::get($purchaseOrder->getId())->getJson(); $invoiceNos = array_unique($invoiceNos); $results['invoiceNos'] = $invoiceNos; Dao::commitTransaction(); } catch (Exception $ex) { Dao::rollbackTransaction(); $errors[] = $ex->getMessage(); } $param->ResponseData = StringUtilsAbstract::getJson($results, $errors); }
/** * Returns a location with the given id * @param int $id the unique identifier of the location * @return The Location with the given id */ private function _locationsById(int $id) : Location { $curlClient = curl_init(self::BASE_URL . self::LOCATIONS_URL . '/' . $id); curl_setopt($curlClient, CURLOPT_HTTPHEADER, $this->_curlHeader); curl_setopt($curlClient, CURLOPT_RETURNTRANSFER, true); $result = json_decode(curl_exec($curlClient), true); return Location::create($result); }
/** * @param array $attributes */ public function loadRelated(array $attributes) { parent::loadRelated($attributes); if (isset($attributes['from'])) { $this->from = User::create($attributes['from']); } if (isset($attributes['chat'])) { $this->chat = isset($attributes['chat']->title) ? GroupChat::create($attributes['chat']) : User::create($attributes['chat']); } if (isset($attributes['forward_from'])) { $this->forward_from = User::create($attributes['forward_from']); } if (isset($attributes['forward_from_chat'])) { $this->forward_from_chat = Chat::create($attributes['forward_from_chat']); } if (isset($attributes['reply_to_message'])) { $this->reply_to_message = Message::create($attributes['reply_to_message']); } if (isset($attributes['entities'])) { $this->entities = array_map(function ($entity) { return MessageEntity::create($entity); }, $attributes['entities']); } if (isset($attributes['audio'])) { $this->audio = Audio::create($attributes['audio']); } if (isset($attributes['document'])) { $this->document = Document::create($attributes['document']); } if (isset($attributes['photo'])) { $this->photo = array_map(function ($photo) { return PhotoSize::create($photo); }, $attributes['photo']); } if (isset($attributes['sticker'])) { $this->sticker = Sticker::create($attributes['sticker']); } if (isset($attributes['video'])) { $this->video = Video::create($attributes['video']); } if (isset($attributes['voice'])) { $this->voice = Voice::create($attributes['voice']); } if (isset($attributes['contact'])) { $this->contact = Contact::create($attributes['contact']); } if (isset($attributes['location'])) { $this->location = Location::create($attributes['location']); } if (isset($attributes['venue'])) { $this->venue = Venue::create($attributes['venue']); } if (isset($attributes['new_chat_member'])) { $this->new_chat_member = User::create($attributes['new_chat_member']); } if (isset($attributes['left_chat_member'])) { $this->left_chat_member = new User($attributes['left_chat_member']); } if (isset($attributes['new_chat_photo'])) { $this->new_chat_photo = array_map(function ($photo) { return PhotoSize::create($photo); }, $attributes['new_chat_photo']); } }
private function _setLocation(Product &$product, $param) { if (isset($param->CallbackParameter->locations) && count($locations = $param->CallbackParameter->locations) > 0) { //delete all price first $deleteIds = array(); foreach ($locations as $location) { if (trim($location->active) === '0' && isset($location->id)) { $deleteIds[] = trim($location->id); } } if (count($deleteIds) > 0) { PreferredLocation::updateByCriteria('active = 0', 'id in (' . str_repeat('?', count($deleteIds)) . ')', $deleteIds); } //update or create new foreach ($locations as $location) { if (isset($location->id) && in_array(trim($location->id), $deleteIds)) { continue; } if (!($type = PreferredLocationType::get(trim($location->typeId))) instanceof PreferredLocationType) { continue; } $locationName = trim($location->value); $locs = Location::getAllByCriteria('name = ?', array($locationName), true, 1, 1); $loc = count($locs) > 0 ? $locs[0] : Location::create($locationName, $locationName); if (!isset($location->id) || ($id = trim($location->id)) === '') { if (trim($location->active) === '1') { PreferredLocation::create($loc, $product, $type); } //if it's deactivated one, ignore } else { if (($preferredLocation = PreferredLocation::get($id)) instanceof PreferredLocation) { $preferredLocation->setLocation($loc)->setActive(trim($location->active) === '1')->setProduct($product)->setType($type)->save(); } } } } return $this; }