public function createAddress(Address $address) { $address->setId(null); $sql = ' INSERT INTO addresses_tb(id,street_no,street,suburb,city,post_code) VALUES (:id,:street_no,:street,:suburb,:city,:post_code)'; return $this->execute($sql, $address); }
protected function add(Address $address) { $q = $this->dao->prepare('INSERT INTO ' . $this->table() . ' SET TITLE = :title, ADDRESS_1 = :address1, ADDRESS_2 = :address2, ZIP_CODE = :zipCode, CITY = :city, COUNTRY = :country, USER_ID = :userId'); $q->bindValue(':title', $address->getTitle()); $q->bindValue(':address1', $address->getAddress1()); $q->bindValue(':address2', $address->getAddress2()); $q->bindValue(':zipCode', $address->getZipCode()); $q->bindValue(':city', $address->getCity()); $q->bindValue(':country', $address->getCountry()); $q->bindValue(':userId', $address->getUserId(), PDO::PARAM_INT); $q->execute(); $address->setId($this->dao->lastInsertId()); }
public function edit() { if ($_SERVER['REQUEST_METHOD'] === 'POST') { $entity = new Address(); $entity->setId($_GET['id'])->setName($_POST['name'])->setAddress($_POST['address'])->setDateAdded(date('Y-m-d H:i:s')); if (isset($_FILES['image'])) { $entity->saveImage($_FILES['image']); } $addressCollection = new AddressCollection(); $addressCollection->save($entity); header('Location: index.php?c=address'); exit; } $addressCollection = new AddressCollection(); $data = array('address' => $addressCollection->one(array('id' => $_GET['id']))); $this->loadView('address/edit', $data); }
public static function map(Address $address, array $properties) { if (array_key_exists('id', $properties)) { $address->setId($properties['id']); } if (array_key_exists('street', $properties)) { $address->setStreet($properties['street']); } if (array_key_exists('suburb', $properties)) { $address->setSuburb($properties['suburb']); } if (array_key_exists('city', $properties)) { $address->setCity($properties['city']); } if (array_key_exists('post_code', $properties)) { $address->setPostCode($properties['post_code']); } if (array_key_exists('street_no', $properties)) { $address->setstreetNo($properties['street_no']); } }
public static function getAddresses($where = null) { $dados = Database::ReadAll("address a, city c, state s", "a.*, c.*, s.*", "WHERE a.id_city = c.id_city AND s.id_state = c.id_state " . $where); if (!$dados) { return ''; } foreach ($dados as $dado) { $address = new Address(); $address->setId($dado['ID_ADDRESS']); $address->setStreet($dado['NAME_ADDRESS']); $address->setNumber($dado['NUMBER']); $address->setComplement($dado['COMPLEMENT']); $address->setDistrict($dado['DISTRICT']); $address->setLatitude($dados['LATITUDE']); $address->setLongitude($dados['LONGITUDE']); $address->setCity($dado['NAME_CITY']); $address->setState($dado['INITIALS']); $address->setPs($dado['PS']); $addresses[] = $address; } return $addresses; }
function contactParser($data) { $contact = new Contact(); if (isset($data['id'])) { $contact->setId($data['id']); } if (isset($data['firstName'])) { $contact->setFirstName($data['firstName']); } if (isset($data['name'])) { $contact->setName($data['name']); } if (isset($data['mail'])) { $contact->setMail($data['mail']); } if (isset($data['phone'])) { $contact->setPhone($data['phone']); } if (isset($data['phone2'])) { $contact->setPhone2($data['phone2']); } if (isset($data['phone3'])) { $contact->setPhone3($data['phone3']); } if (isset($data['company'])) { $contact->setCompany($data['company']); } if (isset($data['address'])) { $dataAddress = $data['address']; $address = new Address(); if (isset($dataAddress['id'])) { $address->setId($dataAddress['id']); } if (isset($dataAddress['line1'])) { $address->setLine1($dataAddress['line1']); } if (isset($dataAddress['line2'])) { $address->setLine2($dataAddress['line2']); } if (isset($dataAddress['zipCode'])) { $address->setZipCode($dataAddress['zipCode']); } if (isset($dataAddress['city'])) { $address->setCity($dataAddress['city']); } if (isset($dataAddress['latitude']) && isset($dataAddress['longitude'])) { $address->setLatitude($dataAddress['latitude']); $address->setLongitude($dataAddress['longitude']); } else { $mapService = new GoogleMapService(); $latlng = $mapService->getLatLong($address); if ($latlng != [] && sizeof($latlng) == 2) { $address->setLatitude($latlng[0]); $address->setLongitude($latlng[1]); } } $contact->setAddress($address); } if (isset($data['type'])) { if (isset($data['type']['id']) && isset($data['type']['name'])) { $type = new Type($data['type']['id'], $data['type']['name']); } elseif (isset($data['type']['name'])) { $type = new Type(null, $data['type']['name']); } else { $type = null; } $contact->setType($type); } if (isset($data['exchangeId'])) { $contact->setExchangeId($data['exchangeId']); } return $contact; }
public function getAddressesByRayon($address, $rayon) { $list = []; try { if (!parent::getBdd()->inTransaction()) { parent::getBdd()->beginTransaction(); } $query = "SELECT *, ( 6371 * acos( cos( radians(:latitude) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:longitude) )\n + sin( radians(:latitude) ) * sin( radians( latitude ) ) ) ) AS distance FROM address HAVING distance < :rayon ORDER BY distance LIMIT 0 , 150;"; $request = parent::getBdd()->prepare($query); $request->bindParam(':latitude', $address->getLatitude()); $request->bindParam(':longitude', $address->getLongitude()); $request->bindParam(':rayon', $rayon); $request->execute(); while ($data = $request->fetch()) { $address = new Address(); $address->setId($data['id']); $address->setLine1($data['line1']); $address->setLine2($data['line2']); $address->setZipCode($data['zipcode']); $address->setCity($data['city']); $address->setLatitude($data['latitude']); $address->setLongitude($data['longitude']); array_push($list, $address); } if ($list == []) { return null; } return $list; } catch (Exception $e) { error_log($e->getMessage()); } return null; }