public function actionAdd($bid) { $brand = Brands::model()->findByPk($bid); $model = new Addresses(); // Uncomment the following line if AJAX validation is needed //$this->performAjaxValidation($model); if (isset($_POST['Addresses'])) { if ($_FILES['file']) { foreach ($_FILES['file']['name'] as $k => $v) { if ($v) { $file[$k] = CUploadedFile::getInstanceByName('file[' . $k . ']'); if (in_array(strtolower($file[$k]->getExtensionName()), array('jpg', 'gif', 'png', 'jpeg'))) { $model->{$k} = $k . '.' . $file[$k]->getExtensionName(); } else { $model->{$k} = CUploadedFile::getInstanceByName('file[' . $k . ']'); } } } } $model->attributes = $_POST['Addresses']; if ($model->save()) { if ($file) { $folder = dirname(Yii::app()->request->scriptFile); $folder .= '/userdata/addresses/addresses_' . $model->id . '/'; foreach ($file as $k => $v) { if (in_array(strtolower($file[$k]->getExtensionName()), array('jpg', 'gif', 'png', 'jpeg'))) { UploadImages::upload($file[$k]->getTempName(), $model->{$k}, $folder, 'addresses', $k); } } } $this->redirect('/admin/brands/' . $bid . '/addresses/'); } } $this->render('_form', array('model' => $model, 'brand' => $brand, 'title' => 'Добавление адреса')); }
$addrs = new Addresses(); $addrs->setKeyID($keyID); // home address $homeAddr = $addrs->getColumn('homeAddress'); $homeAddr->setColumn('city', 'san francisco'); $homeAddr->setColumn('street', '1234 x street'); $homeAddr->setColumn('zip', '94107'); // work address $workAddr = $addrs->getColumn('workAddress'); $workAddr->setColumn('city', 'san jose'); $workAddr->setColumn('street', '9876 y drive'); // custom labelled supercolumn $customAddr = new Address('customAddress'); $customAddr->setColumn('city', 'another city'); $addrs->addSuper($customAddr); if (!$addrs->save()) { die($addrs->lastError()); } unset($addrs); // Load the saved Addresses $addrs = new Addresses(); if (!$addrs->load($keyID)) { die($addrs->lastError()); } // Show our loaded CF in JSON format, including key path echo '<pre>' . $addrs->toJSON(TRUE) . '</pre>'; // Example export -> import of JSON structure from loaded data into new object $addrsClone = new Addresses(); // Populates data from JSON export (therefore must exclude key path) $addrsClone->populate($addrs->toJSON()); // Set key
/** * Create Empty company without users * @param $fedId * @param $newCompanyName * @param $impVendorInfo * @return Clients */ public static function createEmptyCompany($fedId, $newCompanyName, $impVendorInfo = null) { $client = new Clients; // begin transaction $transaction = Yii::app()->db->beginTransaction(); try { $company = new Companies; $project = new Projects; $companyAdreses = new CompanyAddresses; //$usersClientList = new UsersClientList; $company->Company_Name = $newCompanyName; $company->Company_Fed_ID = $fedId; if (preg_match('/^(\d{2}\-\d{7})|(\d{3}\-\d{2}\-\d{4})$/', $company->Company_Fed_ID)) { //usual w9 do nothing } if (preg_match('/^(IN[-]\d{7})$/', $company->Company_Fed_ID)) { //international w9 $company->Temp_Fed_ID_Flag = 'N'; } if (preg_match('/^(T0[-]\d{7})$/', $company->Company_Fed_ID)) { //international w9 $company->Temp_Fed_ID_Flag = 'T'; } $company->Auth_Code = Helper::generatePassword(); $company->save(); $company_adress = new Addresses; if ($impVendorInfo) { $company_adress = new Addresses; $company_adress->Address1 = $impVendorInfo['address']; $company_adress->City = $impVendorInfo['city']; $company_adress->State = $impVendorInfo['state']; $company_adress->ZIP = $impVendorInfo['zip']; if ($company_adress->validate()) { $company_adress->save(); } else { $company_adress = new Addresses; $company_adress->save(); } } $company_adress->save(); $companyAdreses->Company_ID = $company->Company_ID; $companyAdreses->Address_ID = $company_adress->Address_ID ? $company_adress->Address_ID : 0; $companyAdreses->save(); $client->Company_ID = $company->Company_ID; $client->Client_Type = 1; $client->Client_Number = 1; $client->save(); //create client project $project->Client_ID = $client->Client_ID; $project->Project_Name = "Corporate"; $project->Project_Description = "Description of the Project"; $project->PO_Starting_Number = Projects::DEFAULT_PO_STARTING_NUMBER; $project->Ck_Req_Starting_Numb = Projects::DEFAULT_CKRQ_STARTING_NUMBER; $project->save(); $transaction->commit(); } catch(Exception $e) { $transaction->rollback(); } return $client; }
/** * Add a new address * @param $id * @param array $data * @return integer address_id */ public static function AddNew(array $data, $id = "") { if (is_numeric($id)) { $address = self::find($id); } else { $address = new Addresses(); } $address['address'] = $data['address']; $address['city'] = $data['city']; $address['code'] = $data['code']; $address['area'] = $data['area']; $region_id = intval($data['region_id']); if ($region_id != 0) { $address['region_id'] = $region_id; } // Get the latitude and longitude coordinates $coords = Shineisp_Commons_Utilities::getCoordinates($data['city']); $address['latitude'] = $coords['results'][0]['geometry']['location']['lat']; $address['longitude'] = $coords['results'][0]['geometry']['location']['lng']; $address['country_id'] = $data['country_id']; $address['customer_id'] = $data['customer_id']; $address->save(); return $address['address_id']; }