当前位置: 首页>>代码示例>>PHP>>正文


PHP State::add方法代码示例

本文整理汇总了PHP中State::add方法的典型用法代码示例。如果您正苦于以下问题:PHP State::add方法的具体用法?PHP State::add怎么用?PHP State::add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在State的用法示例。


在下文中一共展示了State::add方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: stateShouldKeepItemsByRuleNumberAndPosition

 /**
  * @test
  */
 public function stateShouldKeepItemsByRuleNumberAndPosition()
 {
     $item1 = new Item(new Rule(1, 'E', array('E', '+', 'T')), 0);
     $state = new State(0, array($item1));
     $this->assertSame($item1, $state->get(1, 0));
     $item2 = new Item(new Rule(2, 'T', array('T', '+', 'F')), 0);
     $state->add($item2);
     $this->assertSame($item2, $state->get(2, 0));
 }
开发者ID:MPV,项目名称:AspectMock-test,代码行数:12,代码来源:StateTest.php

示例2: _installStates

 /**
  * @param SimpleXMLElement $xml
  * @return bool
  * @throws PrestaShopException
  */
 protected function _installStates($xml)
 {
     if (isset($xml->states->state)) {
         foreach ($xml->states->state as $data) {
             /** @var SimpleXMLElement $data */
             $attributes = $data->attributes();
             $id_country = $attributes['country'] ? (int) Country::getByIso(strval($attributes['country'])) : false;
             $id_state = $id_country ? State::getIdByIso($attributes['iso_code'], $id_country) : State::getIdByName($attributes['name']);
             if (!$id_state) {
                 $state = new State();
                 $state->name = strval($attributes['name']);
                 $state->iso_code = strval($attributes['iso_code']);
                 $state->id_country = $id_country;
                 $id_zone = (int) Zone::getIdByName(strval($attributes['zone']));
                 if (!$id_zone) {
                     $zone = new Zone();
                     $zone->name = (string) $attributes['zone'];
                     $zone->active = true;
                     if (!$zone->add()) {
                         $this->_errors[] = Tools::displayError('Invalid Zone name.');
                         return false;
                     }
                     $id_zone = $zone->id;
                 }
                 $state->id_zone = $id_zone;
                 if (!$state->validateFields()) {
                     $this->_errors[] = Tools::displayError('Invalid state properties.');
                     return false;
                 }
                 $country = new Country($state->id_country);
                 if (!$country->contains_states) {
                     $country->contains_states = 1;
                     if (!$country->update()) {
                         $this->_errors[] = Tools::displayError('Cannot update the associated country: ') . $country->name;
                     }
                 }
                 if (!$state->add()) {
                     $this->_errors[] = Tools::displayError('An error occurred while adding the state.');
                     return false;
                 }
             } else {
                 $state = new State($id_state);
                 if (!Validate::isLoadedObject($state)) {
                     $this->_errors[] = Tools::displayError('An error occurred while fetching the state.');
                     return false;
                 }
             }
         }
     }
     return true;
 }
开发者ID:prestanesia,项目名称:PrestaShop,代码行数:56,代码来源:LocalizationPack.php

示例3: addressImport

 public function addressImport()
 {
     $this->receiveTab();
     $defaultLanguageId = (int) Configuration::get('PS_LANG_DEFAULT');
     $handle = $this->openCsvFile();
     self::setLocale();
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, Tools::getValue('separator')); $current_line++) {
         if (Tools::getValue('convert')) {
             $line = $this->utf8_encode_array($line);
         }
         $info = self::getMaskedRow($line);
         self::setDefaultValues($info);
         $address = new Address();
         self::array_walk($info, array('AdminImport', 'fillInfo'), $address);
         if (isset($address->country) and is_numeric($address->country)) {
             if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $address->country)) {
                 $address->id_country = (int) $address->country;
             }
         } elseif (isset($address->country) and is_string($address->country) and !empty($address->country)) {
             if ($id_country = Country::getIdByName(NULL, $address->country)) {
                 $address->id_country = (int) $id_country;
             } else {
                 $country = new Country();
                 $country->active = 1;
                 $country->name = self::createMultiLangField($address->country);
                 $country->id_zone = 0;
                 // Default zone for country to create
                 $country->iso_code = strtoupper(substr($address->country, 0, 2));
                 // Default iso for country to create
                 $country->contains_states = 0;
                 // Default value for country to create
                 $langFieldError = $country->validateFieldsLang(UNFRIENDLY_ERROR, true);
                 if (($fieldError = $country->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $country->add()) {
                     $address->id_country = (int) $country->id;
                 } else {
                     $this->_errors[] = $country->name[$defaultLanguageId] . ' ' . Tools::displayError('Cannot be saved');
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
                 }
             }
         }
         if (isset($address->state) and is_numeric($address->state)) {
             if (State::getNameById((int) $address->state)) {
                 $address->id_state = (int) $address->state;
             }
         } elseif (isset($address->state) and is_string($address->state) and !empty($address->state)) {
             if ($id_state = State::getIdByName($address->state)) {
                 $address->id_state = (int) $id_state;
             } else {
                 $state = new State();
                 $state->active = 1;
                 $state->name = $address->state;
                 $state->id_country = isset($country->id) ? (int) $country->id : 0;
                 $state->id_zone = 0;
                 // Default zone for state to create
                 $state->iso_code = strtoupper(substr($address->state, 0, 2));
                 // Default iso for state to create
                 $state->tax_behavior = 0;
                 if (($fieldError = $state->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $state->add()) {
                     $address->id_state = (int) $state->id;
                 } else {
                     $this->_errors[] = $state->name . ' ' . Tools::displayError('Cannot be saved');
                     $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
                 }
             }
         }
         if (isset($address->customer_email) and !empty($address->customer_email)) {
             if (Validate::isEmail($address->customer_email)) {
                 $customer = Customer::customerExists($address->customer_email, true);
                 if ($customer) {
                     $address->id_customer = (int) $customer;
                 } else {
                     $this->_errors[] = mysql_error() . ' ' . $address->customer_email . ' ' . Tools::displayError('does not exist in database') . ' ' . (isset($info['id']) ? ' (ID ' . $info['id'] . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                 }
             } else {
                 $this->_errors[] = '"' . $address->customer_email . '" :' . Tools::displayError('Is not a valid Email');
             }
         }
         if (isset($address->manufacturer) and is_numeric($address->manufacturer) and Manufacturer::manufacturerExists((int) $address->manufacturer)) {
             $address->id_manufacturer = (int) $address->manufacturer;
         } elseif (isset($address->manufacturer) and is_string($address->manufacturer) and !empty($address->manufacturer)) {
             $manufacturer = new Manufacturer();
             $manufacturer->name = $address->manufacturer;
             if (($fieldError = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $manufacturer->add()) {
                 $address->id_manufacturer = (int) $manufacturer->id;
             } else {
                 $this->_errors[] = mysql_error() . ' ' . $manufacturer->name . (isset($manufacturer->id) ? ' (' . $manufacturer->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                 $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
             }
         }
         if (isset($address->supplier) and is_numeric($address->supplier) and Supplier::supplierExists((int) $address->supplier)) {
             $address->id_supplier = (int) $address->supplier;
         } elseif (isset($address->supplier) and is_string($address->supplier) and !empty($address->supplier)) {
             $supplier = new Supplier();
             $supplier->name = $address->supplier;
             if (($fieldError = $supplier->validateFields(UNFRIENDLY_ERROR, true)) === true and ($langFieldError = $supplier->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true and $supplier->add()) {
                 $address->id_supplier = (int) $supplier->id;
             } else {
                 $this->_errors[] = mysql_error() . ' ' . $supplier->name . (isset($supplier->id) ? ' (' . $supplier->id . ')' : '') . ' ' . Tools::displayError('Cannot be saved');
                 $this->_errors[] = ($fieldError !== true ? $fieldError : '') . ($langFieldError !== true ? $langFieldError : '') . mysql_error();
             }
//.........这里部分代码省略.........
开发者ID:greench,项目名称:prestashop,代码行数:101,代码来源:AdminImport.php

示例4: _installStates

 protected function _installStates($xml)
 {
     if (isset($xml->states->state)) {
         foreach ($xml->states->state as $data) {
             $attributes = $data->attributes();
             if (!($id_state = State::getIdByName($attributes['name']))) {
                 $state = new State();
                 $state->name = strval($attributes['name']);
                 $state->iso_code = strval($attributes['iso_code']);
                 $state->id_country = Country::getByIso(strval($attributes['country']));
                 $state->id_zone = (int) Zone::getIdByName(strval($attributes['zone']));
                 if (!$state->validateFields()) {
                     $this->_errors[] = Tools::displayError('Invalid state properties.');
                     return false;
                 }
                 $country = new Country($state->id_country);
                 if (!$country->contains_states) {
                     $country->contains_states = 1;
                     if (!$country->update()) {
                         $this->_errors[] = Tools::displayError('Cannot update the associated country: ') . $country->name;
                     }
                 }
                 if (!$state->add()) {
                     $this->_errors[] = Tools::displayError('An error occurred while adding the state.');
                     return false;
                 }
             } else {
                 $state = new State($id_state);
                 if (!Validate::isLoadedObject($state)) {
                     $this->_errors[] = Tools::displayError('An error occurred while fetching the state.');
                     return false;
                 }
             }
             // Add counties
             foreach ($data->county as $xml_county) {
                 $county_attributes = $xml_county->attributes();
                 if (!($id_county = County::getIdCountyByNameAndIdState($county_attributes['name'], $state->id))) {
                     $county = new County();
                     $county->name = $county_attributes['name'];
                     $county->id_state = (int) $state->id;
                     $county->active = 1;
                     if (!$county->validateFields()) {
                         $this->_errors[] = Tools::displayError('Invalid County properties');
                         return false;
                     }
                     if (!$county->save()) {
                         $this->_errors[] = Tools::displayError('An error has occurred while adding the county');
                         return false;
                     }
                 } else {
                     $county = new County((int) $id_county);
                     if (!Validate::isLoadedObject($county)) {
                         $this->_errors[] = Tools::displayError('An error occurred while fetching the county.');
                         return false;
                     }
                 }
                 // add zip codes
                 foreach ($xml_county->zipcode as $xml_zipcode) {
                     $zipcode_attributes = $xml_zipcode->attributes();
                     $zipcodes = $zipcode_attributes['from'];
                     if (isset($zipcode_attributes['to'])) {
                         $zipcodes .= '-' . $zipcode_attributes['to'];
                     }
                     if ($county->isZipCodeRangePresent($zipcodes)) {
                         continue;
                     }
                     if (!$county->addZipCodes($zipcodes)) {
                         $this->_errors[] = Tools::displayError('An error has occurred while adding zipcodes');
                         return false;
                     }
                 }
             }
         }
     }
     return true;
 }
开发者ID:nicolasjeol,项目名称:hec-ecommerce,代码行数:76,代码来源:LocalizationPack.php

示例5: storeContactImportOne

 public function storeContactImportOne($info, $shop_is_feature_active, $regenerate, $force_ids, $validateOnly = false)
 {
     AdminImportController::setDefaultValues($info);
     if ($force_ids && isset($info['id']) && (int) $info['id']) {
         $store = new Store((int) $info['id']);
     } else {
         if (array_key_exists('id', $info) && (int) $info['id'] && Store::existsInDatabase((int) $info['id'], 'store')) {
             $store = new Store((int) $info['id']);
         } else {
             $store = new Store();
         }
     }
     AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $store);
     if (isset($store->image) && !empty($store->image)) {
         if (!AdminImportController::copyImg($store->id, null, $store->image, 'stores', !$regenerate)) {
             $this->warnings[] = $store->image . ' ' . $this->trans('cannot be copied.', array(), 'Admin.Parameters.Notification');
         }
     }
     if (isset($store->hours) && is_array($store->hours)) {
         $store->hours = serialize($store->hours);
     }
     if (isset($store->country) && is_numeric($store->country)) {
         if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $store->country)) {
             $store->id_country = (int) $store->country;
         }
     } elseif (isset($store->country) && is_string($store->country) && !empty($store->country)) {
         if ($id_country = Country::getIdByName(null, $store->country)) {
             $store->id_country = (int) $id_country;
         } else {
             $country = new Country();
             $country->active = 1;
             $country->name = AdminImportController::createMultiLangField($store->country);
             $country->id_zone = 0;
             // Default zone for country to create
             $country->iso_code = Tools::strtoupper(Tools::substr($store->country, 0, 2));
             // Default iso for country to create
             $country->contains_states = 0;
             // Default value for country to create
             $lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true);
             if (($field_error = $country->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $country->add()) {
                 $store->id_country = (int) $country->id;
             } else {
                 if (!$validateOnly) {
                     $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
                     $this->errors[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), $country->name[$default_language_id]);
                 }
                 if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
     }
     if (isset($store->state) && is_numeric($store->state)) {
         if (State::getNameById((int) $store->state)) {
             $store->id_state = (int) $store->state;
         }
     } elseif (isset($store->state) && is_string($store->state) && !empty($store->state)) {
         if ($id_state = State::getIdByName($store->state)) {
             $store->id_state = (int) $id_state;
         } else {
             $state = new State();
             $state->active = 1;
             $state->name = $store->state;
             $state->id_country = isset($country->id) ? (int) $country->id : 0;
             $state->id_zone = 0;
             // Default zone for state to create
             $state->iso_code = Tools::strtoupper(Tools::substr($store->state, 0, 2));
             // Default iso for state to create
             $state->tax_behavior = 0;
             if (($field_error = $state->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && !$validateOnly && $state->add()) {
                 $store->id_state = (int) $state->id;
             } else {
                 if (!$validateOnly) {
                     $this->errors[] = sprintf($this->trans('%s cannot be saved', array(), 'Admin.Parameters.Notification'), $state->name);
                 }
                 if ($field_error !== true || isset($lang_field_error) && $lang_field_error !== true) {
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
     }
     $res = false;
     if (($field_error = $store->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $store->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true) {
         if ($store->id && $store->storeExists($store->id)) {
             $res = $validateOnly ? $validateOnly : $store->update();
         }
         $store->force_id = (bool) $force_ids;
         if (!$res) {
             $res = $validateOnly ? $validateOnly : $store->add();
         }
         if (!$res) {
             $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf($this->trans('%1$s (ID: %2$s) cannot be saved', array(), 'Admin.Parameters.Notification'), $info['name'], isset($info['id']) ? $info['id'] : 'null');
         }
     } else {
         $this->errors[] = $this->l('Store is invalid') . ' (' . $store->name . ')';
         $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '');
     }
 }
开发者ID:M03G,项目名称:PrestaShop,代码行数:98,代码来源:AdminImportController.php

示例6: generate_entity

/** Generate bigdump : generate items for an entity
 *
 * @param $ID_entity entity ID
**/
function generate_entity($ID_entity) {
   global $MAX, $DB, $percent, $FIRST, $LAST, $MAX_KBITEMS_BY_CAT, $MAX_DISK,
         $DOCUMENTS, $NET_PORT, $NET_LOC;

   regenerateTreeCompleteName("glpi_entities");

   $current_year = date("Y");


   // DOMAIN
   $items = array("SP2MI", "CAMPUS"," IUT86", "PRESIDENCE", "CEAT", "D'omaine");
   $dp    = new Domain();
   $FIRST["domain"] = getMaxItem("glpi_domains")+1;

   for ($i=0 ; $i<$MAX['domain'] ; $i++) {
      if (isset($items[$i])) {
         $val = $items[$i];
      } else {
         $val = "domain $ID_entity '$i";
      }
      $dp->add(toolbox::addslashes_deep(array('name'         => $val,
                                              'entities_id'  => $ID_entity,
                                              'is_recursive' => 1,
                                              'comment'      => "comment $val")));
   }
   $LAST["domain"] = getMaxItem("glpi_domains");


   // STATUS
   $items = array("Reparation", "En stock", "En fonction", "Retour SAV", "En attente d'");
   $dp    = new State();
   $FIRST["state"] = getMaxItem("glpi_states")+1;
   for ($i=0 ; $i<$MAX['state'] ; $i++) {
      if (isset($items[$i])) {
         $val = $items[$i];
      } else {
         $val = "State $ID_entity '$i";
      }
      $state_id = $dp->add(toolbox::addslashes_deep(array('name'         => $val,
                                                          'entities_id'  => $ID_entity,
                                                          'is_recursive' => 1,
                                                          'comment'      => "comment $val")));

      // generate sub status
      for ($j=0 ; $j<$MAX['state'] ; $j++) {
         $val2 = "Sub $val $j";

         $dp->add(toolbox::addslashes_deep(array('name'         => $val2,
                                                 'entities_id'  => $ID_entity,
                                                 'is_recursive' => 1,
                                                 'states_id'    => $state_id,
                                                 'comment'      => "comment $val")));
      }

   }
   $LAST["state"]      = getMaxItem("glpi_states");


   // glpi_groups
   $FIRST["groups"] = getMaxItem("glpi_groups")+1;
   $group           = new Group();
   for ($i=0 ; $i<$MAX['groups'] ; $i++) {
      $gID = $group->add(toolbox::addslashes_deep(
                         array('entities_id'  => $ID_entity,
                               'name'         => "group d'$i",
                               'comment'      => "comment group d'$i",
                               'is_assign'    => 0)));

      // Generate sub group
      for ($j=0 ; $j<$MAX['groups'] ; $j++) {
         $group->add(toolbox::addslashes_deep(
                     array('entities_id'  => $ID_entity,
                           'name'         => "subgroup d'$j",
                           'comment'      => "comment subgroup d'$j of group $i",
                           'groups_id'    => $gID,
                           'is_assign'    => 0)));
      }
   }

   $LAST["groups"]      = getMaxItem("glpi_groups");

   $FIRST["techgroups"] = $LAST["groups"]+1;

   for ($i=0 ; $i<$MAX['groups'] ; $i++) {
         $group->add(toolbox::addslashes_deep(
                     array('entities_id'  => $ID_entity,
                           'name'         => "tech group d'$i",
                           'comment'      => "comment tech group d'$i")));
   }

   $LAST["techgroups"] = getMaxItem("glpi_groups");
   regenerateTreeCompleteName("glpi_groups");


   // glpi_users
   $FIRST["users_sadmin"] = getMaxItem("glpi_users")+1;
//.........这里部分代码省略.........
开发者ID:KaneoGmbH,项目名称:glpi,代码行数:101,代码来源:generate_bigdump.function.php

示例7: addressImport

 public function addressImport()
 {
     $this->receiveTab();
     $default_language_id = (int) Configuration::get('PS_LANG_DEFAULT');
     $handle = $this->openCsvFile();
     AdminImportController::setLocale();
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, $this->separator); $current_line++) {
         if (Tools::getValue('convert')) {
             $line = $this->utf8EncodeArray($line);
         }
         $info = AdminImportController::getMaskedRow($line);
         AdminImportController::setDefaultValues($info);
         $address = new Address();
         AdminImportController::arrayWalk($info, array('AdminImportController', 'fillInfo'), $address);
         if (isset($address->country) && is_numeric($address->country)) {
             if (Country::getNameById(Configuration::get('PS_LANG_DEFAULT'), (int) $address->country)) {
                 $address->id_country = (int) $address->country;
             }
         } elseif (isset($address->country) && is_string($address->country) && !empty($address->country)) {
             if ($id_country = Country::getIdByName(null, $address->country)) {
                 $address->id_country = (int) $id_country;
             } else {
                 $country = new Country();
                 $country->active = 1;
                 $country->name = AdminImportController::createMultiLangField($address->country);
                 $country->id_zone = 0;
                 // Default zone for country to create
                 $country->iso_code = Tools::strtoupper(Tools::substr($address->country, 0, 2));
                 // Default iso for country to create
                 $country->contains_states = 0;
                 // Default value for country to create
                 $lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true);
                 if (($field_error = $country->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $country->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $country->add()) {
                     $address->id_country = (int) $country->id;
                 } else {
                     $this->errors[] = sprintf(Tools::displayError('%s cannot be saved'), $country->name[$default_language_id]);
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
         if (isset($address->state) && is_numeric($address->state)) {
             if (State::getNameById((int) $address->state)) {
                 $address->id_state = (int) $address->state;
             }
         } elseif (isset($address->state) && is_string($address->state) && !empty($address->state)) {
             if ($id_state = State::getIdByName($address->state)) {
                 $address->id_state = (int) $id_state;
             } else {
                 $state = new State();
                 $state->active = 1;
                 $state->name = $address->state;
                 $state->id_country = isset($country->id) ? (int) $country->id : 0;
                 $state->id_zone = 0;
                 // Default zone for state to create
                 $state->iso_code = Tools::strtoupper(Tools::substr($address->state, 0, 2));
                 // Default iso for state to create
                 $state->tax_behavior = 0;
                 if (($field_error = $state->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $state->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $state->add()) {
                     $address->id_state = (int) $state->id;
                 } else {
                     $this->errors[] = sprintf(Tools::displayError('%s cannot be saved'), $state->name);
                     $this->errors[] = ($field_error !== true ? $field_error : '') . (isset($lang_field_error) && $lang_field_error !== true ? $lang_field_error : '') . Db::getInstance()->getMsgError();
                 }
             }
         }
         if (isset($address->customer_email) && !empty($address->customer_email)) {
             if (Validate::isEmail($address->customer_email)) {
                 // a customer could exists in different shop
                 $customer_list = Customer::getCustomersByEmail($address->customer_email);
                 if (count($customer_list) == 0) {
                     $this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be saved.'), Db::getInstance()->getMsgError(), $address->customer_email, isset($info['id']) && !empty($info['id']) ? $info['id'] : 'null');
                 }
             } else {
                 $this->errors[] = sprintf(Tools::displayError('"%s" is not a valid email address.'), $address->customer_email);
                 continue;
             }
         } elseif (isset($address->id_customer) && !empty($address->id_customer)) {
             if (Customer::customerIdExistsStatic((int) $address->id_customer)) {
                 $customer = new Customer((int) $address->id_customer);
                 // a customer could exists in different shop
                 $customer_list = Customer::getCustomersByEmail($customer->email);
                 if (count($customer_list) == 0) {
                     $this->errors[] = sprintf(Tools::displayError('%1$s does not exist in database %2$s (ID: %3$s), and therefore cannot be saved.'), Db::getInstance()->getMsgError(), $customer->email, (int) $address->id_customer);
                 }
             } else {
                 $this->errors[] = sprintf(Tools::displayError('The customer ID #%d does not exist in the database, and therefore cannot be saved.'), $address->id_customer);
             }
         } else {
             $customer_list = array();
             $address->id_customer = 0;
         }
         if (isset($address->manufacturer) && is_numeric($address->manufacturer) && Manufacturer::manufacturerExists((int) $address->manufacturer)) {
             $address->id_manufacturer = (int) $address->manufacturer;
         } elseif (isset($address->manufacturer) && is_string($address->manufacturer) && !empty($address->manufacturer)) {
             $manufacturer = new Manufacturer();
             $manufacturer->name = $address->manufacturer;
             if (($field_error = $manufacturer->validateFields(UNFRIENDLY_ERROR, true)) === true && ($lang_field_error = $manufacturer->validateFieldsLang(UNFRIENDLY_ERROR, true)) === true && $manufacturer->add()) {
                 $address->id_manufacturer = (int) $manufacturer->id;
             } else {
                 $this->errors[] = Db::getInstance()->getMsgError() . ' ' . sprintf(Tools::displayError('%1$s (ID: %2$s) cannot be saved'), $manufacturer->name, isset($manufacturer->id) && !empty($manufacturer->id) ? $manufacturer->id : 'null');
//.........这里部分代码省略.........
开发者ID:ecssjapan,项目名称:guiding-you-afteropen,代码行数:101,代码来源:AdminImportController.php

示例8: State

<?php

if (Tools::P('saveState') == 'add') {
    $state = new State();
    $state->copyFromPost();
    $state->add();
    if (is_array($state->_errors) and count($state->_errors) > 0) {
        $errors = $state->_errors;
    } else {
        $_GET['id'] = $state->id;
        UIAdminAlerts::conf('省/州已添加');
    }
}
if (isset($_GET['id'])) {
    $id = (int) $_GET['id'];
    $obj = new State($id);
}
if (Tools::P('saveState') == 'edit') {
    if (Validate::isLoadedObject($obj)) {
        $obj->copyFromPost();
        $obj->update();
    }
    if (is_array($obj->_errors) and count($obj->_errors) > 0) {
        $errors = $obj->_errors;
    } else {
        UIAdminAlerts::conf('国家已更新');
    }
}
if (isset($errors)) {
    UIAdminAlerts::MError($errors);
}
开发者ID:yiuked,项目名称:tmcart,代码行数:31,代码来源:state_edit.php

示例9: importStates

 protected function importStates()
 {
     $this->truncateTables(array('state'));
     $handle = $this->openCsvFile('states.csv');
     for ($current_line = 0; $line = fgetcsv($handle, MAX_LINE_SIZE, ';'); $current_line++) {
         $res = false;
         $fields = $this->filterFields('State', $this->states_fields, $line);
         if (!isset($fields['id_state'])) {
             $state = new State($line[0]);
             $state->id = $line[0];
         } else {
             $state = new State($fields['id_state']);
         }
         foreach ($fields as $key => $field) {
             $state->{$key} = $field;
         }
         $state->force_id = true;
         if (!$res) {
             $res = $state->add();
         }
     }
     $this->closeCsvFile($handle);
     return true;
 }
开发者ID:evgrishin,项目名称:se1614,代码行数:24,代码来源:AdminSampleDataInstallImport.php


注:本文中的State::add方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。