sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
protected function setStateCity($state_id) { $this->data_state = $this->state->get($state_id); if (empty($this->data_state)) { $this->outputHttpStatus(404); } }
Sets an array of state data @param integer $state_id
entailment
protected function setCountryCity($country_code) { $this->data_country = $this->country->get($country_code); if (empty($this->data_country)) { $this->outputHttpStatus(404); } }
Returns an array of country data @param string $country_code
entailment
protected function setPagerListCity() { $options = $this->query_filter; $options['count'] = true; $options['state_id'] = $this->data_state['state_id']; $pager = array( 'query' => $this->query_filter, 'total' => (int) $this->city->getList($options) ); return $this->data_limit = $this->setPager($pager); }
Sets pager @return array
entailment
protected function getListCity() { $conditions = $this->query_filter; $conditions['limit'] = $this->data_limit; $conditions['state_id'] = $this->data_state['state_id']; return (array) $this->city->getList($conditions); }
Returns an array of cities found for the filter conditions @return array
entailment
protected function setBreadcrumbListCity() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('admin'), 'text' => $this->text('Dashboard') ); $breadcrumbs[] = array( 'url' => $this->url('admin/settings/country'), 'text' => $this->text('Countries') ); $breadcrumbs[] = array( 'url' => $this->url("admin/settings/states/{$this->data_country['code']}"), 'text' => $this->text('Country states of %name', array('%name' => $this->data_country['name'])) ); $this->setBreadcrumbs($breadcrumbs); }
Sets breadcrumbs on the city overview page
entailment
public function editCity($country_code, $state_id, $city_id = null) { $this->setCity($city_id); $this->setStateCity($state_id); $this->setCountryCity($country_code); $this->setTitleEditCity(); $this->setBreadcrumbEditCity(); $this->setData('city', $this->data_city); $this->setData('state', $this->data_state); $this->setData('country', $this->data_country); $this->setData('zones', $this->getZonesCity()); $this->setData('can_delete', $this->canDeleteCity()); $this->submitEditCity(); $this->outputEditCity(); }
Displays the city edit page @param string $country_code @param integer $state_id @param null|integer $city_id
entailment
protected function canDeleteCity() { return isset($this->data_city['city_id']) && $this->access('city_delete') && $this->city->canDelete($this->data_city['city_id']); }
Whether the city can be deleted @return bool
entailment
protected function setCity($city_id) { $this->data_city = array(); if (is_numeric($city_id)) { $this->data_city = $this->city->get($city_id); if (empty($this->data_city)) { $this->outputHttpStatus(404); } } }
Sets an array of city data @param integer $city_id
entailment
protected function submitEditCity() { if ($this->isPosted('delete')) { $this->deleteCity(); } else if ($this->isPosted('save') && $this->validateEditCity()) { if (isset($this->data_city['city_id'])) { $this->updateCity(); } else { $this->addCity(); } } }
Handles a submitted city
entailment
protected function validateEditCity() { $this->setSubmitted('city'); $this->setSubmittedBool('status'); $this->setSubmitted('update', $this->data_city); $this->setSubmitted('country', $this->data_country['code']); $this->setSubmitted('state_id', $this->data_state['state_id']); $this->validateComponent('city'); return !$this->hasErrors(); }
Validates an array of submitted city data @return bool
entailment
protected function deleteCity() { $this->controlAccess('city_delete'); if ($this->city->delete($this->data_city['city_id'])) { $url = "admin/settings/cities/{$this->data_country['code']}/{$this->data_state['state_id']}"; $this->redirect($url, $this->text('City has been deleted'), 'success'); } $this->redirect('', $this->text('City has not been deleted'), 'warning'); }
Deletes a city
entailment
protected function updateCity() { $this->controlAccess('city_edit'); if ($this->city->update($this->data_city['city_id'], $this->getSubmitted())) { $url = "admin/settings/cities/{$this->data_country['code']}/{$this->data_state['state_id']}"; $this->redirect($url, $this->text('City has been updated'), 'success'); } $this->redirect('', $this->text('City has not been updated'), 'warning'); }
Updates a city
entailment
protected function addCity() { $this->controlAccess('city_add'); if ($this->city->add($this->getSubmitted())) { $url = "admin/settings/cities/{$this->data_country['code']}/{$this->data_state['state_id']}"; $this->redirect($url, $this->text('City has been added'), 'success'); } $this->redirect('', $this->text('City has not been added'), 'warning'); }
Adds a new city
entailment
protected function setTitleEditCity() { if (isset($this->data_city['city_id'])) { $title = $this->text('Edit %name', array('%name' => $this->data_city['name'])); } else { $title = $this->text('Add city'); } $this->setTitle($title); }
Sets page title on the city edit page
entailment
protected function setBreadcrumbEditCity() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('admin'), 'text' => $this->text('Dashboard') ); $breadcrumbs[] = array( 'url' => $this->url('admin/settings/country'), 'text' => $this->text('Countries') ); $breadcrumbs[] = array( 'url' => $this->url("admin/settings/states/{$this->data_country['code']}"), 'text' => $this->text('Country states of %name', array('%name' => $this->data_country['name'])) ); $breadcrumbs[] = array( 'url' => $this->url("admin/settings/cities/{$this->data_country['code']}/{$this->data_state['state_id']}"), 'text' => $this->text('Cities of state %name', array('%name' => $this->data_state['name'])) ); $this->setBreadcrumbs($breadcrumbs); }
Sets breadcrumbs on the city edit page
entailment
public function getList(array $options = array()) { $result = null; $this->hook->attach('product.class.list.before', $options, $result, $this); if (isset($result)) { return $result; } $sql = 'SELECT pc.*'; if (!empty($options['count'])) { $sql = 'SELECT COUNT(pc.product_class_id)'; } $sql .= ' FROM product_class pc WHERE pc.product_class_id IS NOT NULL'; $conditions = array(); if (isset($options['title'])) { $sql .= ' AND pc.title LIKE ?'; $conditions[] = "%{$options['title']}%"; } if (isset($options['status'])) { $sql .= ' AND pc.status=?'; $conditions[] = (int) $options['status']; } $allowed_order = array('asc', 'desc'); $allowed_sort = array('title', 'status', 'product_class_id'); $sql .= ' GROUP BY pc.product_class_id'; if (isset($options['sort']) && in_array($options['sort'], $allowed_sort) && isset($options['order']) && in_array($options['order'], $allowed_order)) { $sql .= " ORDER BY pc.{$options['sort']} {$options['order']}"; } else { $sql .= ' ORDER BY pc.title ASC'; } if (!empty($options['limit'])) { $sql .= ' LIMIT ' . implode(',', array_map('intval', $options['limit'])); } if (empty($options['count'])) { $result = $this->db->fetchAll($sql, $conditions, array('index' => 'product_class_id')); } else { $result = (int) $this->db->fetchColumn($sql, $conditions); } $this->hook->attach('product.class.list.after', $options, $result, $this); return $result; }
Returns an array of product classes or counts them @param array $options @return array|integer
entailment
public function add(array $data) { $result = null; $this->hook->attach('product.class.add.before', $data, $result, $this); if (isset($result)) { return (int) $result; } $result = $this->db->insert('product_class', $data); $this->hook->attach('product.class.add.after', $data, $result, $this); return (int) $result; }
Adds a product class @param array $data @return integer
entailment
public function canDelete($product_class_id) { $sql = 'SELECT product_id FROM product WHERE product_class_id=?'; $result = $this->db->fetchColumn($sql, array($product_class_id)); return empty($result); }
Whether the product class can be deleted @param integer $product_class_id @return boolean
entailment
public function update($product_class_id, array $data) { $result = null; $this->hook->attach('product.class.update.before', $product_class_id, $data, $result, $this); if (isset($result)) { return (bool) $result; } $conditions = array('product_class_id' => $product_class_id); $result = (bool) $this->db->update('product_class', $data, $conditions); $this->hook->attach('product.class.update.after', $product_class_id, $data, $result, $this); return (bool) $result; }
Updates a product class @param integer $product_class_id @param array $data @return boolean
entailment
public function getFields($product_class_id) { $result = &gplcart_static("product.class.fields.$product_class_id"); if (isset($result)) { return $result; } $result = array(); $fields = $this->field->getList(); $ops = array( 'product_class_id' => $product_class_id ); foreach ((array) $this->product_class_field->getList($ops) as $product_class_field) { if (isset($fields[$product_class_field['field_id']])) { $data = array('values' => $this->field_value->getList(array( 'field_id' => $product_class_field['field_id']))); $data += $fields[$product_class_field['field_id']]; $data += $product_class_field; $result[$fields[$product_class_field['field_id']]['type']][$product_class_field['field_id']] = $data; } } return $result; }
Returns an array of fields for a given product class @param integer $product_class_id @return array
entailment
public function getList($prodict_id) { $result = null; $this->hook->attach('product.field.list.before', $prodict_id, $result, $this); if (isset($result)) { return $result; } $sql = 'SELECT * FROM product_field WHERE product_id=?'; $fields = $this->db->fetchAll($sql, array($prodict_id)); $result = array(); foreach ($fields as $field) { $result[$field['type']][$field['field_id']][] = $field['field_value_id']; } $this->hook->attach('product.field.list.after', $prodict_id, $result, $this); return $result; }
Returns an array of fields for a given product @param integer $prodict_id @return array
entailment
public function request($url, $options = array()) { $result = null; $this->hook->attach('http.request.before', $url, $options, $result, $this); if (isset($result)) { return $result; } $result = $this->socket->request($url, $options); $this->hook->attach('http.request.after', $url, $options, $result, $this); return $result; }
Perform an HTTP request @param string $url @param array $options @return mixed
entailment
public function getList(array $options = array()) { $options += array( 'enabled' => false, 'in_database' => false ); $currencies = &gplcart_static(gplcart_array_hash(array('currency.list' => $options))); if (isset($currencies)) { return $currencies; } $this->hook->attach('currency.list.before', $options, $currencies, $this); if (isset($currencies)) { return $currencies; } $iso = (array) $this->getIso(); $default = $this->getDefaultData(); $saved = $this->config->get('currencies', array()); $currencies = array_replace_recursive($iso, $saved); $this->hook->attach('currency.list.after', $options, $currencies, $this); foreach ($currencies as $code => &$currency) { $currency['code'] = $code; $currency += $default; $currency['in_database'] = isset($saved[$code]); if ($code === 'USD') { $currency['status'] = $currency['default'] = 1; } if ($options['enabled'] && empty($currency['status'])) { unset($currencies[$code]); continue; } if ($options['in_database'] && empty($currency['in_database'])) { unset($currencies[$code]); } } return $currencies; }
Returns an array of currencies @param array $options @return array
entailment
public function add(array $data) { $result = null; $this->hook->attach('currency.add.before', $data, $result, $this); if (isset($result)) { return (bool) $result; } $data['modified'] = GC_TIME; $data['code'] = strtoupper($data['code']); if (!empty($data['default'])) { $data['status'] = 1; $this->config->set('currency', $data['code']); } $default = $this->getDefaultData(); $data += $default; $currencies = $this->config->select('currencies', array()); $currencies[$data['code']] = array_intersect_key($data, $default); $result = $this->config->set('currencies', $currencies); $this->hook->attach('currency.add.after', $data, $result, $this); return (bool) $result; }
Adds a currency @param array $data @return boolean
entailment
public function update($code, array $data) { $result = null; $this->hook->attach('currency.update.before', $code, $data, $result, $this); if (isset($result)) { return (bool) $result; } $existing = $this->getList(); if (empty($existing[$code])) { return false; } unset($data['code']); $data['modified'] = GC_TIME; if (!empty($data['default'])) { $data['status'] = 1; $this->config->set('currency', $code); } $saved = $this->config->select('currencies', array()); if (empty($saved[$code])) { $data += $existing[$code]; } else { $data += $saved[$code]; } $default = $this->getDefaultData(); $saved[$code] = array_intersect_key($data, $default); $result = $this->config->set('currencies', $saved); $this->hook->attach('currency.update.after', $code, $data, $result, $this); return (bool) $result; }
Updates a currency @param string $code @param array $data @return boolean
entailment
public function delete($code, $check = true) { $result = null; $this->hook->attach('currency.delete.before', $code, $check, $result, $this); if (isset($result)) { return (bool) $result; } if ($check && !$this->canDelete($code)) { return false; } $currencies = $this->config->select('currencies', array()); unset($currencies[$code]); $result = $this->config->set('currencies', $currencies); $this->hook->attach('currency.delete.after', $code, $check, $result, $this); return (bool) $result; }
Deletes a currency @param string $code @param bool $check @return boolean
entailment
public function canDelete($code) { $code = strtoupper($code); if ($code == $this->getDefault()) { return false; } $currencies = $this->config->select('currencies', array()); if (!isset($currencies[$code])) { return false; } $sql = 'SELECT NOT EXISTS (SELECT currency FROM orders WHERE currency=:code) AND NOT EXISTS (SELECT currency FROM price_rule WHERE currency=:code) AND NOT EXISTS (SELECT currency FROM product WHERE currency=:code)'; return (bool) $this->db->fetchColumn($sql, array('code' => $code)); }
Whether the currency can be deleted @param string $code @return boolean
entailment
public function convert($amount, $from_currency, $to_currency) { if ($from_currency === $to_currency) { return $amount; // Nothing to convert } $currency = $this->get($from_currency); $target_currency = $this->get($to_currency); $exponent = $target_currency['decimals'] - $currency['decimals']; $amount *= pow(10, $exponent); return $amount * ($currency['conversion_rate'] / $target_currency['conversion_rate']); }
Converts currencies @param integer $amount @param string $from_currency @param string $to_currency @return integer
entailment
public function getCode($set = true) { $list = $this->getList(); $code = $this->getFromUrl(); if (empty($code)) { $code = $this->getFromCookie(); } if (empty($list[$code]['status'])) { $code = $this->getDefault(); } if ($set) { $this->setCookie($code); } return $code; }
Returns the current currency code @param bool $set @return string
entailment
public function setCookie($code) { $lifespan = $this->config->get('currency_cookie_lifespan', 365 * 24 * 60 * 60); $this->request->setCookie('currency', $code, $lifespan); }
Saves a currency code in cookie @param string $code
entailment
public function getIso($code = null) { $data = (array) gplcart_config_get(GC_FILE_CONFIG_CURRENCY); if (isset($code)) { return isset($data[$code]) ? $data[$code] + array('code' => $code) : array(); } return $data; }
Returns an array of currencies or a single currency data if $code is set @param null|string $code @return array|string
entailment
public static function get($id) { $instance = self::getInstance(); //缓存文件不存在 if (!$instance->has($id)) { return false; } $file = $instance->_file($id); $data = $instance->_fileGetContents($file); if ($data['expire'] == 0 || time() < $data['expire']) { return $data['contents']; } return false; }
得到缓存信息 @param string $id @return boolean|array
entailment
public static function set($id, $data, $cacheLife = 0) { $instance = self::getInstance(); $time = time(); $cache = array(); $cache['contents'] = $data; $cache['expire'] = $cacheLife === 0 ? 0 : $time + $cacheLife; $cache['mtime'] = $time; $file = $instance->_file($id); return $instance->_filePutContents($file, $cache); }
设置一个缓存 @param string $id 缓存id @param array $data 缓存内容 @param int $cacheLife 缓存生命 默认为0无限生命
entailment
public static function delete($id) { $instance = self::getInstance(); if (!$instance->has($id)) { return false; } $file = $instance->_file($id); //删除该缓存 return unlink($file); }
清除一条缓存 @param string cache id @return void
entailment
public static function has($id) { $instance = self::getInstance(); $file = $instance->_file($id); if (!is_file($file)) { return false; } return true; }
判断缓存是否存在 @param string $id cache_id @return boolean true 缓存存在 false 缓存不存在
entailment
protected function _file($id) { $instance = self::getInstance(); $fileNmae = $instance->_idToFileName($id); return self::cacheDir() . $fileNmae; }
通过缓存id得到缓存信息路径 @param string $id @return string 缓存文件路径
entailment
protected function _idToFileName($id) { $instance = self::getInstance(); $prefix = $instance->_options['file_name_prefix']; return $prefix . '---' . $id; }
通过id得到缓存信息存储文件名 @param $id @return string 缓存文件名
entailment
protected function _fileNameToId($fileName) { $instance = self::getInstance(); $prefix = $instance->_options['file_name_prefix']; return preg_replace('/^' . $prefix . '---(.*)$/', '$1', $fileName); }
通过filename得到缓存id @param $id @return string 缓存id
entailment
protected function _filePutContents($file, $contents) { if ($this->_options['mode'] == 1) { $contents = serialize($contents); } else { $time = time(); $contents = "<?php\n" . " // mktime: " . $time . "\n" . " return " . var_export($contents, true) . "\n?>"; } $result = false; $f = @fopen($file, 'w'); if ($f) { @flock($f, LOCK_EX); fseek($f, 0); ftruncate($f, 0); $tmp = @fwrite($f, $contents); if (!($tmp === false)) { $result = true; } @fclose($f); } @chmod($file, 0777); return $result; }
把数据写入文件 @param string $file 文件名称 @param array $contents 数据内容 @return bool
entailment
protected function _fileGetContents($file) { if (!is_file($file)) { return false; } if ($this->_options['mode'] == 1) { $f = @fopen($file, 'r'); @$data = fread($f, filesize($file)); @fclose($f); return unserialize($data); } else { return include $file; } }
从文件得到数据 @param sring $file @return boolean|array
entailment
public static function setCacheMode($mode = 1) { $instance = self::getInstance(); if ($mode == 1) { $instance->_options['mode'] = 1; } else { $instance->_options['mode'] = 2; } return $instance; }
设置缓存存储类型 @param int $mode @return self
entailment
public static function flush() { $instance = self::getInstance(); $glob = @glob(self::cacheDir() . $instance->_options['file_name_prefix'] . '--*'); if (empty($glob)) { return false; } foreach ($glob as $v) { $fileName = basename($v); $id = $instance->_fileNameToId($fileName); $instance->delete($id); } return true; }
删除所有缓存 @return boolean
entailment
public static function validate($descriptor) { try { new static($descriptor); return []; } catch (Exceptions\SchemaLoadException $e) { return [ new SchemaValidationError(SchemaValidationError::LOAD_FAILED, $e->getMessage()), ]; } catch (Exceptions\SchemaValidationFailedException $e) { return $e->validationErrors; } }
loads and validates the given descriptor source (php object / string / path to file / url) returns an array of validation error objects. @param mixed $descriptor @return array
entailment
public function castRow($row) { $outRow = []; $validationErrors = []; foreach ($this->fields() as $fieldName => $field) { $value = array_key_exists($fieldName, $row) ? $row[$fieldName] : null; if (in_array($value, $this->missingValues())) { $value = null; } try { $outRow[$fieldName] = $field->castValue($value); } catch (Exceptions\FieldValidationException $e) { $validationErrors = array_merge($validationErrors, $e->validationErrors); } } if (count($validationErrors) > 0) { throw new Exceptions\FieldValidationException($validationErrors); } return $outRow; }
@param mixed[] $row @return mixed[] @throws Exceptions\FieldValidationException
entailment
public function validateRow($row) { try { $this->castRow($row); return []; } catch (Exceptions\FieldValidationException $e) { return $e->validationErrors; } }
@param array $row @return SchemaValidationError[]
entailment
public function getNextLine() { $row = $this->nextRow; if ($row === null) { if (!$this->resource) { $this->open(); } if ($this->isEof()) { throw new \Exception('EOF'); } $row = $this->nextRow; if ($row === null) { throw new \Exception('cannot get valid row, but isEof returns false'); } } $this->nextRow = null; $colNum = 0; $obj = []; if (count($row) != count($this->headerRow)) { throw new DataSourceException('Invalid row: '.implode(', ', $row)); } foreach ($this->headerRow as $fieldName) { $obj[$fieldName] = $row[$colNum]; ++$colNum; } return $obj; }
@return array @throws DataSourceException
entailment
public function isEof() { if ($this->nextRow) { return false; } else { try { $eof = feof($this->resource); } catch (\Exception $e) { throw new DataSourceException($e->getMessage(), $this->curRowNum); } if ($eof) { return true; } else { $this->nextRow = $this->getRow(); if (!$this->nextRow || $this->nextRow === ['']) { try { $eof = feof($this->resource); } catch (\Exception $e) { throw new DataSourceException($e->getMessage(), $this->curRowNum); } if ($eof) { // RFC4180: The last record in the file may or may not have an ending line break. return true; } else { throw new DataSourceException('invalid csv file', $this->curRowNum); } } else { return false; } } } }
@return bool @throws DataSourceException
entailment
protected function getRow($continueRow = null) { ++$this->curRowNum; try { $line = fgets($this->resource); } catch (\Exception $e) { throw new DataSourceException($e->getMessage(), $this->curRowNum); } $row = $this->csvDialect->parseRow($line, $continueRow); if (count($row) > 0 && is_a($row[count($row) - 1], 'frictionlessdata\\tableschema\\ContinueEnclosedField')) { return $this->getRow($row); } else { return $row; } }
@return array @throws DataSourceException
entailment
public function user(array &$submitted, array $options) { $this->options = $options; $this->submitted = &$submitted; $this->validateUser(); $this->validateBool('status'); $this->validateName(); $this->validateEmail(); $this->validateEmailUniqueUser(); $this->validatePasswordUser(); $this->validatePasswordLengthUser(); $this->validatePasswordOldUser(); $this->validateStoreId(); $this->validateRoleUser(); $this->validateTimezoneUser(); $this->validateData(); $this->unsetSubmitted('update'); return $this->getResult(); }
Performs full validation of submitted user data @param array $submitted @param array $options @return array|boolean
entailment
public function login(array &$submitted, array $options = array()) { $this->options = $options; $this->submitted = &$submitted; $this->validateEmail(); $this->validatePasswordUser(); return $this->getResult(); }
Performs full login data validation @param array $submitted @param array $options @return array|boolean
entailment
public function resetPassword(array &$submitted, array $options = array()) { $this->options = $options; $this->submitted = &$submitted; $email = $this->getSubmitted('email'); $password = $this->getSubmitted('password'); if (isset($password)) { $this->validateStatusUser(); $this->validatePasswordLengthUser(); } else if (isset($email)) { $this->validateEmail(); $this->validateEmailExistsUser(); } return $this->getResult(); }
Performs password reset validation @param array $submitted @param array $options @return array|boolean
entailment
protected function validateUser() { $id = $this->getUpdatingId(); if ($id === false) { return null; } $data = $this->user->get($id); if (empty($data)) { $this->setErrorUnavailable('update', $this->translation->text('User')); return false; } $this->setUpdating($data); return true; }
Validates a user to be updated @return boolean
entailment
protected function validateStatusUser() { $field = 'user'; if ($this->isExcluded($field)) { return null; } $value = $this->getSubmitted($field); if (is_numeric($value)) { $value = $this->user->get($value); } if (empty($value['status']) || empty($value['user_id'])) { $this->setErrorUnavailable($field, $this->translation->text('User')); return false; } $this->setSubmitted($field, $value); return true; }
Validates user status @return boolean
entailment
protected function validateEmailUniqueUser() { $field = 'email'; $value = $this->getSubmitted($field); if ($this->isError($field) || !isset($value)) { return null; } $updating = $this->getUpdating(); if (isset($updating['email']) && $updating['email'] === $value) { return true; } $user = $this->user->getByEmail($value); if (empty($user)) { return true; } $this->setErrorExists($field, $this->translation->text('E-mail')); return false; }
Validates uniqueness of submitted E-mail @return boolean|null
entailment
protected function validateEmailExistsUser() { $field = 'email'; $value = $this->getSubmitted($field); if ($this->isError($field) || !isset($value)) { return null; } $user = $this->user->getByEmail($value); if (empty($user['status'])) { $this->setErrorUnavailable($field, $this->translation->text('E-mail')); return false; } $this->setSubmitted($field, $user); return true; }
Validates an email and checks the responding user enabled @return boolean|null
entailment
protected function validatePasswordUser() { $field = 'password'; if ($this->isExcluded($field)) { return null; } $value = $this->getSubmitted($field); if ($this->isUpdating() && (!isset($value) || $value === '')) { return null; } if (empty($value)) { $this->setErrorRequired($field, $this->translation->text('Password')); return false; } return true; }
Validates a user password @return boolean|null
entailment
protected function validatePasswordLengthUser() { $field = 'password'; if ($this->isExcluded($field) || $this->isError($field)) { return null; } $value = $this->getSubmitted($field); if ($this->isUpdating() && (!isset($value) || $value === '')) { return null; } $length = mb_strlen($value); list($min, $max) = $this->user->getPasswordLength(); if ($length < $min || $length > $max) { $this->setErrorLengthRange($field, $this->translation->text('Password'), $min, $max); return false; } return true; }
Validates password length @return boolean|null
entailment
protected function validatePasswordOldUser() { $field = 'password_old'; if ($this->isExcluded($field)) { return null; } if (!$this->isUpdating() || !empty($this->options['admin'])) { return null; } $password = $this->getSubmitted('password'); if (!isset($password) || $password === '') { return null; } $old_password = $this->getSubmitted($field); if (!isset($old_password) || $old_password === '') { $this->setErrorRequired($field, $this->translation->text('Old password')); return false; } $updating = $this->getUpdating(); $hash = gplcart_string_hash($old_password, $updating['hash'], 0); if (!gplcart_string_equals($updating['hash'], $hash)) { $error = $this->translation->text('Old and new password not matching'); $this->setError($field, $error); return false; } return true; }
Validates an old user password @return boolean|null
entailment
protected function validateRoleUser() { $field = 'role_id'; $value = $this->getSubmitted($field); if (empty($value)) { return null; } $label = $this->translation->text('Role'); if (!is_numeric($value)) { $this->setErrorNumeric($field, $label); return false; } $role = $this->role->get($value); if (empty($role)) { $this->setErrorUnavailable($field, $label); return false; } return true; }
Validates a user role @return boolean|null
entailment
protected function validateTimezoneUser() { $field = 'timezone'; if ($this->isExcluded($field)) { return null; } $value = $this->getSubmitted($field); if (!isset($value)) { $this->unsetSubmitted($field); return null; } $timezones = gplcart_timezones(); if (empty($timezones[$value])) { $this->setErrorInvalid($field, $this->translation->text('Timezone')); return false; } return true; }
Validates "timezone" field @return bool|null
entailment
public function get($store = null) { if (!$this->db->isInitialized()) { return array(); } if (!isset($store)) { $url = $this->server->httpHost(); $basepath = trim($this->request->base(true), '/'); $store = trim("$url/$basepath", '/'); } $result = &gplcart_static("store.get.$store"); if (isset($result)) { return $result; } $this->hook->attach('store.get.before', $store, $result, $this); if (isset($result)) { return $result; } $conditions = array(); if (is_numeric($store)) { $conditions['store_id'] = $store; } else if (strpos($store, '/') === false) { $conditions['domain'] = $store; } else { list($domain, $basepath) = explode('/', $store, 2); $conditions['domain'] = $domain; $conditions['basepath'] = $basepath; } $conditions['limit'] = array(0, 1); $list = (array) $this->getList($conditions); $result = empty($list) ? array() : reset($list); if (isset($result['data'])) { $result['data'] += $this->getDefaultData(); } $this->hook->attach('store.get.after', $store, $result, $this); return $result; }
Loads a store @param integer|string|null $store @return array
entailment
public function getDefault($load = false) { $store_id = $this->config->get('store', 1); if ($load) { return $this->get($store_id); } return (int) $store_id; }
Returns a default store @param boolean $load @return array|integer
entailment
protected function deleteLinked($store_id) { $this->db->delete('triggers', array('store_id' => $store_id)); $this->db->delete('wishlist', array('store_id' => $store_id)); $this->db->delete('collection', array('store_id' => $store_id)); $this->db->delete('product_sku', array('store_id' => $store_id)); }
Delete all database rows related to the store @param int $store_id
entailment
public function canDelete($store_id) { if ($this->isDefault($store_id)) { return false; } $sql = 'SELECT NOT EXISTS (SELECT store_id FROM product WHERE store_id=:id) AND NOT EXISTS (SELECT store_id FROM category_group WHERE store_id=:id) AND NOT EXISTS (SELECT store_id FROM page WHERE store_id=:id) AND NOT EXISTS (SELECT store_id FROM orders WHERE store_id=:id) AND NOT EXISTS (SELECT store_id FROM cart WHERE store_id=:id) AND NOT EXISTS (SELECT store_id FROM user WHERE store_id=:id)'; return (bool) $this->db->fetchColumn($sql, array('id' => $store_id)); }
Whether the store can be deleted @param integer $store_id @return boolean
entailment
public function getTranslation($item, $langcode, $store = null) { $config = $this->getConfig(null, $store); if (!empty($config['translation'][$langcode][$item])) { return $config['translation'][$langcode][$item]; } if (isset($config[$item])) { return $config[$item]; } return ''; }
Returns a translatable store configuration item @param string $item @param string $langcode @param mixed $store @return string
entailment
public function getConfig($item = null, $store = null) { if (empty($store)) { $store = $this->get(); } elseif (!is_array($store)) { $store = $this->get($store); } if (empty($store['data'])) { $store['data'] = $this->getDefaultData(); } if (!isset($item)) { return $store['data']; } return gplcart_array_get($store['data'], $item); }
Returns a value from a given config item @param mixed $item @param mixed $store @return mixed
entailment
public function delete($address_id, $check = true) { $result = null; $this->hook->attach('address.delete.before', $address_id, $check, $result, $this); if (isset($result)) { return (bool) $result; } if ($check && !$this->canDelete($address_id)) { return false; } $result = (bool) $this->db->delete('address', array('address_id' => $address_id)); $this->hook->attach('address.delete.after', $address_id, $check, $result, $this); return (bool) $result; }
Deletes an address @param integer $address_id @param bool $check @return boolean
entailment
public function get($condition) { if (!is_array($condition)) { $condition = array('address_id' => $condition); } $result = &gplcart_static(gplcart_array_hash(array('address.get' => $condition))); if (isset($result)) { return $result; } $result = null; $this->hook->attach('address.get.before', $condition, $result, $this); if (isset($result)) { return (array) $result; } $condition['prepare'] = false; $condition['limit'] = array(0, 1); $list = (array) $this->getList($condition); $result = empty($list) ? array() : reset($list); if (isset($result['country_format'])) { $result['country_format'] += $this->country->getDefaultFormat(); } $this->hook->attach('address.get.after', $condition, $result, $this); return (array) $result; }
Loads an address from the database @param int|array|string $condition @return array
entailment
public function getTranslatedList($user_id, $status = true) { $conditions = array( 'status' => $status, 'user_id' => $user_id ); $addresses = array(); foreach ((array) $this->getList($conditions) as $address_id => $address) { $addresses[$address_id] = $this->getTranslated($address, true); } return $addresses; }
Returns an array of addresses with translated address fields for the user @param integer $user_id @param boolean $status @return array
entailment
public function getTranslated(array $address, $both = false) { $default = $this->country->getDefaultFormat(); $format = gplcart_array_merge($default, $address['country_format']); gplcart_array_sort($format); $results = array(); foreach ($format as $key => $data) { if (!array_key_exists($key, $address) || empty($data['status'])) { continue; } if ($key === 'country') { $address[$key] = $address['country_native_name']; } if ($key === 'state_id') { $address[$key] = $address['state_name']; } if ($key === 'city_id' && !empty($address['city_name'])) { $address[$key] = $address['city_name']; } if ($both) { $results[$data['name']] = $address[$key]; continue; } $results[$key] = $address[$key]; } return array_filter($results); }
Returns an array of translated address fields @param array $address @param boolean $both @return array
entailment
public function getExceeded($user_id, $existing = null) { $limit = $this->getLimit($user_id); if (empty($limit)) { return array(); } if (!isset($existing)) { $existing = $this->getList(array('user_id' => $user_id)); } $count = count($existing); if (empty($count) || $count <= $limit) { return array(); } return array_slice((array) $existing, 0, ($count - $limit)); }
Returns an array of exceeded addresses for the user ID @param string|integer $user_id @param null|array $existing @return array
entailment
public function getLimit($user_id) { if (empty($user_id) || !is_numeric($user_id)) { return (int) $this->config->get('user_address_limit_anonymous', 1); } return (int) $this->config->get('user_address_limit', 4); }
Returns a number of addresses the user can have @param string|integer @return integer
entailment
protected function prepareList(array $addresses, array $data) { $countries = $this->country->getList(); $list = array(); foreach ($addresses as $address_id => $address) { $list[$address_id] = $address; if (empty($data['status'])) { continue; // Do not check enabled country, state and city } if (empty($countries)) { continue; // No countries defined in the system } if ($address['country'] !== '' && $address['country_status'] == 0) { unset($list[$address_id]); continue; } if (!empty($address['state_id']) && $address['state_status'] == 0) { unset($list[$address_id]); continue; } // City ID can also be not numeric (user input) if (is_numeric($address['city_id']) && $address['city_status'] == 0) { unset($list[$address_id]); } } return $list; }
Returns an array of filtered addresses @param array $addresses @param array $data @return array
entailment
public function matchRequest(SymfonyRequest $request) { $laravelRequest = LaravelRequest::createFromBase($request); $route = $this->findRoute($laravelRequest); $route->setParameter('_module', $this->moduleName); return $route; }
Given a request object, find the matching route. @param Request $request @return \Illuminate\Routing\Route
entailment
public function selectCompare() { $this->controlProductsCompare(); $this->setTitleSelectCompare(); $this->setBreadcrumbSelectCompare(); $this->setData('products', $this->getProductsSelectCompare()); $this->outputSelectCompare(); }
Page callback Displays the select to compare page
entailment
protected function controlProductsCompare() { $options = array( 'status' => 1, 'store_id' => $this->store_id, 'product_id' => $this->product_compare->getList() ); if (!empty($options['product_id'])) { $existing = array_keys($this->product->getList($options)); if (array_diff($options['product_id'], $existing)) { $this->product_compare->set($existing); } } }
Make sure that products saved in cookie are all valid and available to the user If some products were removed, disabled or moved to another store they will be removes from cookie
entailment
protected function getProductsSelectCompare() { $conditions = array( 'product_id' => $this->getProductComparison()); $options = array( 'view' => $this->configTheme('compare_view', 'grid'), 'buttons' => array('cart_add', 'wishlist_add', 'compare_remove') ); $products = $this->getProducts($conditions, $options); return $this->reindexProductsCompare($products); }
Returns an array of products re-indexed by a class ID @return array
entailment
protected function reindexProductsCompare(array $products) { $prepared = array(); foreach ($products as $product_id => $product) { $prepared[$product['product_class_id']][$product_id] = $product; } return $prepared; }
Returns an array of products indexed by a class ID @param array $products @return array
entailment
public function compareCompare($ids) { $this->setProductCompare($ids); $this->controlAccessCompareCompare(); $this->setTitleCompareCompare(); $this->setBreadcrumbCompareCompare(); $this->setData('products', $this->data_products); $this->setData('fields', $this->getFieldsCompare($this->data_products)); $this->outputCompareCompare(); }
Page callback Displays the product comparison page @param string $ids
entailment
protected function setProductCompare($string) { $ids = array_filter(array_map('trim', explode(',', $string)), 'ctype_digit'); $this->data_products = $this->getProductsCompare($ids); $this->prepareProductsCompare($this->data_products); }
Set an array of product IDs to compare @param string $string
entailment
protected function prepareProductsCompare(array &$products) { foreach ($products as $product_id => &$product) { $product['field'] = $this->product_field->getList($product_id); $this->setItemProductFields($product, $this->image, $this->product_class); } }
Prepare an array of products to be compared @param array $products
entailment
protected function getFieldsCompare(array $products) { $labels = array(); foreach ($products as $product) { if (!empty($product['field_value_labels'])) { foreach ($product['field_value_labels'] as $type => $fields) { foreach (array_keys($fields) as $field_id) { $labels[$type][$field_id] = $product['fields'][$type][$field_id]['title']; } } } } return $labels; }
Returns an array of all fields for the given products @param array $products @return array
entailment
protected function setBreadcrumbCompareCompare() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('/'), 'text' => $this->text('Home')); $breadcrumbs[] = array( 'url' => $this->url('compare'), 'text' => $this->text('Select products')); $this->setBreadcrumbs($breadcrumbs); }
Sets breadcrumbs on the product comparison page
entailment
public function format($amount, $currency_code, $decimal = true, $full = true) { $currency = $this->currency->get($currency_code); if (empty($currency)) { return 'n/a'; } if ($decimal) { $amount = $this->decimal($amount, $currency_code); } // Pass the amount to the currency template as %price variable $currency['price'] = $this->formatNumber($amount, $currency); if ($full) { return $this->formatTemplate($amount, $currency); } return $amount < 0 ? '-' . $currency['price'] : $currency['price']; }
Format a price @param integer $amount @param string $currency_code @param bool $decimal @param bool $full @return string
entailment
public function formatTemplate($amount, array $data) { $placeholders = array(); foreach (array_keys($data) as $key) { $placeholders["%$key"] = $key; } $formatted = gplcart_string_replace($data['template'], $placeholders, $data); return $amount < 0 ? "-$formatted" : $formatted; }
Format an amount using the currency template @param int|float $amount @param array $data @return string
entailment
public function formatNumber($amount, array $currency) { $rounded = $this->round(abs($amount), $currency); return number_format($rounded, $currency['decimals'], $currency['decimal_separator'], $currency['thousands_separator']); }
Format an amount with grouped thousands @param int|float $amount @param array $currency @return string
entailment
public function decimal($amount, $currency_code) { static $divisors = array(); if (empty($divisors[$currency_code])) { $currency = $this->currency->get($currency_code); $divisors[$currency_code] = pow(10, $currency['decimals']); } return $amount / $divisors[$currency_code]; }
Converts an amount from minor to major units @param integer $amount @param string $currency_code @return float
entailment
public function round($amount, array $currency) { if (empty($currency['rounding_step'])) { return round($amount, $currency['decimals']); } $modifier = 1 / $currency['rounding_step']; return round($amount * $modifier) / $modifier; }
Rounds an amount @param integer $amount @param array $currency @return integer
entailment
public function amount($decimal, $currency_code = null, $round = true) { static $factors = array(); if (empty($currency_code)) { $currency_code = $this->currency->getDefault(); } if (empty($factors[$currency_code])) { $currency = $this->currency->get($currency_code); $factors[$currency_code] = pow(10, $currency['decimals']); } if ($round) { $currency = $this->currency->get($currency_code); $decimal = $this->round($decimal, $currency); return (int) round($decimal * $factors[$currency_code]); } return $decimal * $factors[$currency_code]; }
Converts a price from major to minor units @param float $decimal @param string|null $currency_code @param boolean $round @return integer
entailment
public function convert($amount, $from_currency, $to_currency) { return $this->currency->convert($amount, $from_currency, $to_currency); }
Converts currencies @param int $amount @param string $from_currency @param string $to_currency @return int
entailment
public function setItemTotalFormattedNumber(array &$item, $price_model) { $item['total_formatted_number'] = $price_model->format($item['total'], $item['currency'], true, false); }
Adds "total_formatted_number" key @param array $item @param \gplcart\core\models\Price $price_model
entailment
public function setItemPriceFormatted(array &$item, $price_model, $currency = null) { if (!isset($currency)) { $currency = $item['currency']; } $price = $price_model->convert($item['price'], $item['currency'], $currency); $item['price_formatted'] = $price_model->format($price, $currency); if (isset($item['original_price'])) { $price = $price_model->convert($item['original_price'], $item['currency'], $currency); $item['original_price_formatted'] = $price_model->format($price, $currency); } }
Add keys with formatted prices @param array $item @param \gplcart\core\models\Price $price_model @param string|null $currency
entailment
public function setItemPriceCalculated(array &$item, $product_model) { $calculated = $product_model->calculate($item); if ($item['price'] != $calculated) { $item['original_price'] = $item['price']; } $item['price'] = $calculated; }
Adjust an original price according to applied price rules @param array $item @param \gplcart\core\models\Product $product_model
entailment
public function page(array &$submitted, array $options = array()) { $this->options = $options; $this->submitted = &$submitted; $this->validatePage(); $this->validateBool('status'); $this->validateBool('blog_post'); $this->validateTitle(); $this->validateDescriptionPage(); $this->validateMetaTitle(); $this->validateMetaDescription(); $this->validateTranslation(); $this->validateStoreId(); $this->validateCategoryPage(); $this->validateUserId(false); $this->validateImages(); $this->validateAlias(); $this->validateUploadImages('page'); $this->unsetSubmitted('update'); return $this->getResult(); }
Performs page data validation @param array $submitted @param array $options @return array|boolean
entailment
protected function validatePage() { $id = $this->getUpdatingId(); if ($id === false) { return null; } $data = $this->page->get($id); if (empty($data)) { $this->setErrorUnavailable('update', $this->translation->text('Page')); return false; } $this->setUpdating($data); return true; }
Validates a page to be updated @return boolean|null
entailment
protected function validateCategoryPage() { $field = 'category_id'; $value = $this->getSubmitted($field); if (empty($value)) { return null; } $label = $this->translation->text('Category'); if (!is_numeric($value)) { $this->setErrorNumeric($field, $label); return false; } $category = $this->category->get($value); if (empty($category['category_id'])) { $this->setErrorUnavailable($field, $label); return false; } return true; }
Validates a category ID @return boolean|null
entailment
protected function validatePost($postTypeModel, $request, $validationRules) { // Lets receive the current items from the post type validation array if(array_key_exists('post_name', $validationRules) && !is_array($validationRules['post_name'])){ $exploded = explode('|', $validationRules['post_name']); $validationRules['post_name'] = []; foreach($exploded as $key => $value){ $validationRules['post_name'][] = $value; } } // Lets validate if a post_name is required. if(!$postTypeModel->disableDefaultPostName){ // Make sure that only the post_name of the requested post_type is unique $validationRules['post_name'][] = 'required'; $validationRules['post_name'][] = Rule::unique('cms_posts')->where(function ($query) use ($postTypeModel) { return $query->where('post_type', $postTypeModel->identifier); }); } return $this->validate($request, $validationRules); }
Validating the creation and change of a post
entailment
public function setToken($token = null) { if (isset($token)) { return $this->token = $token; } return $this->token = gplcart_string_encode(crypt(session_id(), $this->config->getKey())); }
Sets a token @param string|null $token @return string
entailment
protected function setInstanceProperties() { $this->hook = $this->getInstance('gplcart\\core\\Hook'); $this->route = $this->getInstance('gplcart\\core\\Route'); $this->module = $this->getInstance('gplcart\\core\\Module'); $this->config = $this->getInstance('gplcart\\core\\Config'); $this->library = $this->getInstance('gplcart\\core\\Library'); $this->cart = $this->getInstance('gplcart\\core\\models\\Cart'); $this->user = $this->getInstance('gplcart\\core\\models\\User'); $this->store = $this->getInstance('gplcart\\core\\models\\Store'); $this->image = $this->getInstance('gplcart\\core\\models\\Image'); $this->filter = $this->getInstance('gplcart\\core\\models\\Filter'); $this->language = $this->getInstance('gplcart\\core\\models\\Language'); $this->validator = $this->getInstance('gplcart\\core\\models\\Validator'); $this->translation = $this->getInstance('gplcart\\core\\models\\Translation'); $this->url = $this->getInstance('gplcart\\core\\helpers\\Url'); $this->asset = $this->getInstance('gplcart\\core\\helpers\\Asset'); $this->pager = $this->getInstance('gplcart\\core\\helpers\\Pager'); $this->server = $this->getInstance('gplcart\\core\\helpers\\Server'); $this->session = $this->getInstance('gplcart\\core\\helpers\\Session'); $this->request = $this->getInstance('gplcart\\core\\helpers\\Request'); $this->response = $this->getInstance('gplcart\\core\\helpers\\Response'); }
Sets instance properties
entailment
protected function setRouteProperties() { $this->current_route = $this->route->get(); $this->path = $this->url->path(); $this->is_backend = $this->url->isBackend(); $this->is_install = $this->url->isInstall(); $this->host = $this->server->httpHost(); $this->scheme = $this->server->httpScheme(); $this->uri_path = $this->server->requestUri(); $this->is_ajax = $this->server->isAjaxRequest(); $this->uri = $this->scheme . $this->host . $this->uri_path; $this->base = $this->request->base(); $this->query = (array) $this->request->get(null, array(), 'array'); }
Sets the current route data
entailment