sentence1
stringlengths 52
3.87M
| sentence2
stringlengths 1
47.2k
| label
stringclasses 1
value |
---|---|---|
protected function setUser($user_id)
{
$this->data_user = array();
if (is_numeric($user_id)) {
$this->data_user = $this->user->get($user_id);
if (empty($this->data_user)) {
$this->outputHttpStatus(404);
}
}
} | Sets a user data
@param integer|null $user_id | entailment |
protected function submitEditUser()
{
if ($this->isPosted('delete')) {
$this->deleteUser();
} else if ($this->isPosted('save') && $this->validateEditUser()) {
if (isset($this->data_user['user_id'])) {
$this->updateUser();
} else {
$this->addUser();
}
}
} | Handles a submitted user data | entailment |
protected function validateEditUser()
{
$this->setSubmitted('user');
$this->setSubmittedBool('status');
$this->setSubmitted('update', $this->data_user);
$this->validateComponent('user', array('admin' => $this->access('user_edit')));
return !$this->hasErrors();
} | Validates a submitted user data
@return bool | entailment |
protected function deleteUser()
{
$this->controlAccess('user_delete');
if ($this->user->delete($this->data_user['user_id'])) {
$this->redirect('admin/user/list', $this->text('User has been deleted'), 'success');
}
$this->redirect('', $this->text('User has not been deleted'), 'warning');
} | Deletes a user | entailment |
protected function updateUser()
{
$this->controlAccess('user_edit');
if ($this->user->update($this->data_user['user_id'], $this->getSubmitted())) {
$this->redirect('admin/user/list', $this->text('User has been updated'), 'success');
}
$this->redirect('', $this->text('User has not been updated'), 'warning');
} | Updates a user | entailment |
protected function addUser()
{
$this->controlAccess('user_add');
if ($this->user->add($this->getSubmitted())) {
$this->redirect('admin/user/list', $this->text('User has been added'), 'success');
}
$this->redirect('', $this->text('User has not been added'), 'warning');
} | Adds a new user | entailment |
protected function setTitleEditUser()
{
if (isset($this->data_user['name'])) {
$title = $this->text('Edit %name', array('%name' => $this->data_user['name']));
} else {
$title = $this->text('Add user');
}
$this->setTitle($title);
} | Sets title on the edit user page | entailment |
protected function setBreadcrumbEditUser()
{
$breadcrumbs = array();
$breadcrumbs[] = array(
'url' => $this->url('admin'),
'text' => $this->text('Dashboard')
);
$breadcrumbs[] = array(
'text' => $this->text('Users'),
'url' => $this->url('admin/user/list')
);
$this->setBreadcrumbs($breadcrumbs);
} | Sets breadcrumbs on the edit user page | entailment |
public function get($command = null)
{
if (isset($command)) {
$routes = $this->getList();
return isset($routes[$command]) ? $routes[$command] : array();
}
return $this->route;
} | Returns the current CLI route
@param null|string $command
@return array | entailment |
public function setParams($params = null)
{
if (isset($params)) {
$this->params = (array) $params;
} else {
$this->params = $this->cli->parseParams($this->server->cliArgs());
}
return $this;
} | Set CLI params (both options and arguments)
@param array|null $params
@return $this | entailment |
public function getList()
{
$routes = &gplcart_static('cli.route.list');
if (isset($routes)) {
return $routes;
}
$routes = (array) gplcart_config_get(GC_FILE_CONFIG_ROUTE_CLI);
$this->hook->attach('cli.route.list', $routes, $this);
$this->setAliases($routes);
return $routes;
} | Returns an array of CLI routes
@return array | entailment |
protected function setAliases(array $routes)
{
foreach ($routes as $command => $route) {
if (!isset($route['alias'])) {
continue;
}
if (isset($this->aliases[$route['alias']])) {
throw new OverflowException("Command alias '{$route['alias']}' is not unique");
}
$this->aliases[$route['alias']] = $command;
}
} | Sets an array of commands keyed by their aliases
@param array $routes
@throws OverflowException | entailment |
public function set($route = null)
{
if (!isset($route)) {
$routes = $this->getList();
$command = array_shift($this->params);
if (isset($this->aliases[$command])) {
$command = $this->aliases[$command];
}
if (empty($routes[$command])) {
$command = 'help';
$this->params = array();
}
if (empty($routes[$command])) {
throw new OutOfBoundsException('Unknown command');
}
if (isset($routes[$command]['status']) && empty($routes[$command]['status'])) {
throw new OutOfBoundsException('Disabled command');
}
$route = $routes[$command];
$route['command'] = $command;
$route['params'] = $this->params;
}
$this->route = (array) $route;
return $this;
} | Sets the current route
@param array|null $route
@return $this
@throws OutOfBoundsException | entailment |
public function callController($route = null)
{
if (!isset($route)) {
$route = $this->route;
}
$callback = Handler::get($route, null, 'controller');
if (!$callback[0] instanceof CliController) {
throw new LogicException('Controller must be instance of \gplcart\core\CliController');
}
call_user_func($callback);
throw new LogicException('The command was completed incorrectly');
} | Call a route controller
@param null|array
@throws LogicException | entailment |
public function currency(array &$submitted, array $options = array())
{
$this->options = $options;
$this->submitted = &$submitted;
$this->validateCurrency();
$this->validateBool('default');
$this->validateBool('status');
$this->validateCodeCurrency();
$this->validateName();
$this->validateNumericCodeCurrency();
$this->validateSymbolCurrency();
$this->validateMajorUnitCurrency();
$this->validateMinorUnitCurrency();
$this->validateConvertionRateCurrency();
$this->validateDecimalsCurrency();
$this->validateRoundingStepCurrency();
$this->unsetSubmitted('update');
return $this->getResult();
} | Performs full currency data validation
@param array $submitted
@param array $options
@return boolean|array | entailment |
protected function validateCurrency()
{
$id = $this->getUpdatingId();
if ($id === false) {
return null;
}
$data = $this->currency->get($id);
if (empty($data)) {
$this->setErrorUnavailable('update', $this->translation->text('Currency'));
return false;
}
$this->setUpdating($data);
return true;
} | Validates a currency to be updated
@return boolean|null | entailment |
protected function validateMajorUnitCurrency()
{
$field = 'major_unit';
if ($this->isExcluded($field)) {
return null;
}
$value = $this->getSubmitted($field);
if ($this->isUpdating() && !isset($value)) {
$this->unsetSubmitted($field);
return null;
}
if (empty($value) || mb_strlen($value) > 50) {
$this->setErrorLengthRange($field, $this->translation->text('Major unit'), 1, 50);
return false;
}
return true;
} | Validates currency major unit
@return boolean|null | entailment |
protected function validateConvertionRateCurrency()
{
$field = 'conversion_rate';
$value = $this->getSubmitted($field);
if (!isset($value)) {
return null;
}
$label = $this->translation->text('Conversion rate');
if (empty($value) || strlen($value) > 10) {
$this->setErrorLengthRange($field, $label, 1, 10);
return false;
}
if (preg_match('/^[0-9]\d*(\.\d+)?$/', $value) !== 1) {
$this->setErrorInvalid($field, $label);
return false;
}
return true;
} | Validates currency conversion rate
@return boolean|null | entailment |
protected function validateDecimalsCurrency()
{
$field = 'decimals';
$value = $this->getSubmitted($field);
if (!isset($value)) {
$this->unsetSubmitted($field);
return null;
}
if (preg_match('/^[0-2]+$/', $value) !== 1) {
$this->setErrorInvalid($field, $this->translation->text('Decimals'));
return false;
}
return true;
} | Validates currency decimals
@return boolean|null | entailment |
protected function validateNumericCodeCurrency()
{
$field = 'numeric_code';
if ($this->isExcluded($field)) {
return null;
}
$value = $this->getSubmitted($field);
if ($this->isUpdating() && !isset($value)) {
$this->unsetSubmitted($field);
return null;
}
$label = $this->translation->text('Numeric code');
if (empty($value)) {
$this->setErrorRequired($field, $label);
return false;
}
if (preg_match('/^[0-9]{3}$/', $value) !== 1) {
$this->setErrorInvalid($field, $label);
return false;
}
$updating = $this->getUpdating();
if (isset($updating['numeric_code']) && $updating['numeric_code'] == $value) {
return true;
}
foreach ($this->currency->getList() as $currency) {
if ($currency['numeric_code'] == $value) {
$this->setErrorExists($field, $label);
return false;
}
}
return true;
} | Validates currency numeric code
@return boolean|null | entailment |
protected function validateCodeCurrency()
{
$field = 'code';
if ($this->isExcluded($field)) {
return null;
}
$value = $this->getSubmitted($field);
if ($this->isUpdating() && !isset($value)) {
$this->unsetSubmitted($field);
return null;
}
$label = $this->translation->text('Code');
if (empty($value)) {
$this->setErrorRequired($field, $label);
return false;
}
if (preg_match('/^[a-zA-Z]{3}$/', $value) !== 1) {
$this->setErrorInvalid($field, $label);
return false;
}
$code = strtoupper($value);
$updating = $this->getUpdating();
if (isset($updating['code']) && $updating['code'] === $code) {
return true;
}
$existing = $this->currency->get($code);
if (!empty($existing)) {
$this->setErrorExists($field, $label);
return false;
}
$this->setSubmitted($field, $code);
return true;
} | Validates currency code
@return boolean|null | entailment |
public function listTransaction()
{
$this->actionListTransaction();
$this->setTitleListTransaction();
$this->setBreadcrumbListTransaction();
$this->setFilterListTransaction();
$this->setPagerListTransaction();
$this->setData('transactions', $this->getListTransaction());
$this->setData('payment_methods', $this->payment->getList());
$this->outputListTransaction();
} | Displays the transaction overview page | entailment |
protected function setPagerListTransaction()
{
$conditions = $this->query_filter;
$conditions['count'] = true;
$pager = array(
'query' => $this->query_filter,
'total' => (int) $this->transaction->getList($conditions)
);
return $this->data_limit = $this->setPager($pager);
} | Sets pager
@return array | entailment |
protected function actionListTransaction()
{
list($selected, $action) = $this->getPostedAction();
$deleted = 0;
foreach ($selected as $id) {
if ($action === 'delete' && $this->access('transaction_delete')) {
$deleted += (int) $this->transaction->delete($id);
}
}
if ($deleted > 0) {
$message = $this->text('Deleted %num item(s)', array('%num' => $deleted));
$this->setMessage($message, 'success');
}
} | Applies an action to the selected transactions | entailment |
protected function getListTransaction()
{
$conditions = $this->query_filter;
$conditions['limit'] = $this->data_limit;
return (array) $this->transaction->getList($conditions);
} | Returns an array of transactions
@return array | entailment |
public function run($text, $filter)
{
if (is_string($filter)) {
$filter = $this->get($filter);
}
$filtered = null;
$this->hook->attach('filter', $text, $filter, $filtered, $this);
if (isset($filtered)) {
return (string) $filtered;
}
return $this->filter($text);
} | Filter a text string
@param string $text
@param string|array $filter
@return string | entailment |
public function get($filter_id)
{
$filters = $this->getHandlers();
return empty($filters[$filter_id]) ? array() : $filters[$filter_id];
} | Returns a filter
@param string $filter_id
@return array | entailment |
public function getByRole($role_id)
{
foreach ($this->getHandlers() as $filter) {
if (in_array($role_id, (array) $filter['role_id'])) {
return $filter;
}
}
return array();
} | Returns a filter for the given user role ID
@param integer $role_id
@return array | entailment |
public function getHandlers()
{
$filters = &gplcart_static('filter.handlers');
if (isset($filters)) {
return $filters;
}
$filters = array();
$this->hook->attach('filter.handlers', $filters, $this);
foreach ($filters as $id => &$filter) {
$filter['filter_id'] = $id;
$filter += array(
'role_id' => array(),
'status' => true,
'module' => null
);
}
return $filters;
} | Returns an array of defined filters
@return array | entailment |
protected function limitList(array &$list, array $limit)
{
list($from, $to) = $limit;
$list = array_slice($list, $from, $to, true);
} | Limit the list using the limit
@param array $list
@param array $limit | entailment |
protected function sortList(array &$list, array $allowed, array $query, array $default = array())
{
if (empty($default)) {
$default = array('sort' => '', 'order' => '');
} else {
$order = reset($default);
$field = key($default);
$default = array('sort' => $field, 'order' => $order);
}
$query += $default;
if (in_array($query['sort'], $allowed)) {
uasort($list, function ($a, $b) use ($query) {
return $this->callbackSortList($a, $b, $query);
});
}
} | Sort the list by a field
@param array $list
@param array $allowed
@param array $query
@param array $default | entailment |
protected function filterList(array &$list, array $allowed_fields, array $query)
{
$filter = array_intersect_key($query, array_flip($allowed_fields));
if (!empty($filter)) {
$list = array_filter($list, function ($item) use ($filter) {
return $this->callbackFilterList($item, $filter);
});
}
} | Filter the list by a field
@param array $list
@param array $allowed_fields
@param array $query | entailment |
protected function callbackFilterList(array $item, $filter)
{
foreach ($filter as $field => $term) {
if (empty($item[$field])) {
$item[$field] = '0';
}
if (!is_string($item[$field])) {
$item[$field] = (string) (int) !empty($item[$field]);
}
if (stripos($item[$field], $term) === false) {
return false;
}
}
return true;
} | Callback for array_filter() function
@param array $item
@param array $filter
@return bool | entailment |
protected function callbackSortList($a, $b, array $query)
{
$arg1 = isset($a[$query['sort']]) ? (string) $a[$query['sort']] : '0';
$arg2 = isset($b[$query['sort']]) ? (string) $b[$query['sort']] : '0';
$diff = strnatcasecmp($arg1, $arg2);
return $query['order'] === 'asc' ? $diff : -$diff;
} | Callback function for uasort()
@param array $a
@param array $b
@param array $query
@return int | entailment |
public function getMessage()
{
switch ($this->code) {
case self::LOAD_FAILED:
return $this->extraDetails;
case self::SCHEMA_VIOLATION:
return $this->extraDetails;
case self::FIELD_VALIDATION:
$field = $this->extraDetails['field'];
$error = $this->extraDetails['error'];
$value = json_encode($this->extraDetails['value']);
return "{$field}: {$error} ({$value})";
case self::ROW_FIELD_VALIDATION:
$row = $this->extraDetails['row'];
$field = $this->extraDetails['field'];
$error = $this->extraDetails['error'];
$value = $this->extraDetails['value'];
return "row {$row} {$field}: {$error} ({$value})";
case self::ROW_VALIDATION:
$row = $this->extraDetails['row'];
$error = $this->extraDetails['error'];
return "row {$row}: {$error}";
default:
throw new \Exception("Invalid schema validation code: {$this->code}");
}
} | returns a string representation of the error.
@return string
@throws \Exception | entailment |
public function listReportRoute()
{
$this->setTitleListReportRoute();
$this->setBreadcrumbListReportRoute();
$this->setFilterListReportRoute();
$this->setPagerListReportRoute();
$this->setData('routes', (array) $this->getListReportRoute());
$this->setData('permissions', $this->getPermissionsReportRole());
$this->outputListReportRoute();
} | Displays the route overview page | entailment |
protected function setPagerListReportRoute()
{
$pager = array(
'query' => $this->query_filter,
'total' => (int) $this->getListReportRoute(true)
);
return $this->data_limit = $this->setPager($pager);
} | Sets pager
@return array | entailment |
protected function getListReportRoute($count = false)
{
$list = $this->route->getList();
$this->prepareListReportRoute($list);
$allowed = $this->getAllowedFiltersReportRoute();
$this->filterList($list, $allowed, $this->query_filter);
$this->sortList($list, $allowed, $this->query_filter, array('pattern' => 'asc'));
if ($count) {
return count($list);
}
$this->limitList($list, $this->data_limit);
return $list;
} | Returns an array of routes or counts them
@param bool $count
@return array|int | entailment |
protected function prepareListReportRoute(array &$routes)
{
$permissions = $this->getPermissionsReportRole();
foreach ($routes as $pattern => &$route) {
if (strpos($pattern, 'admin') === 0 && !isset($route['access'])) {
$route['access'] = 'admin';
}
if (!isset($route['access'])) {
$route['access'] = GC_PERM_PUBLIC;
}
$access_names = array();
if (isset($permissions[$route['access']])) {
$access_names[$route['access']] = $this->text($permissions[$route['access']]);
} else {
$access_names[''] = $this->text($permissions[GC_PERM_PUBLIC]);
}
if ($route['access'] === GC_PERM_SUPERADMIN) {
$access_names = array(GC_PERM_SUPERADMIN => $this->text($permissions[GC_PERM_SUPERADMIN]));
}
$route['pattern'] = $pattern;
$route['access_name'] = implode(' + ', $access_names);
$route['access'] = implode('', array_keys($access_names));
$route['status'] = !isset($route['status']) || !empty($route['status']);
}
} | Prepares an array of routes
@param array $routes | entailment |
public function current(array $condition)
{
$value = strtotime(reset($condition['value']));
return empty($value) ? false : $this->compare(GC_TIME, $value, $condition['operator']);
} | Whether the date condition is met
@param array $condition
@return boolean | entailment |
protected function init()
{
$this->attributes = [];
$this->groupAttributes = [];
$this->attributes['id'] = $this->open->name . '-' . $this->name;
if($this->name) {
$this->attributes['name'] = $this->name;
}
} | Initialization function | entailment |
protected function initPresenter()
{
if($this->name && $this->open->isSubmitted()) {
$this->error = $this->dataStore->getError($this->name);
}
$this->presenter->setElement($this);
} | Inject the element into presenter | entailment |
public function createService(ServiceLocatorInterface $serviceLocator)
{
$config = $serviceLocator->get('ApplicationConfig');
$config = isset($config['module_listener_options']) ?
$config['module_listener_options'] : array();
/*
* "module_listener_options":
*
* This should be an array of paths in which modules reside.
* If a string key is provided, the listener will consider that a module
* namespace, the value of that key the specific path to that module's
* Module class.
*/
if (!isset($config['module_paths'])) {
$paths = array();
$cwd = getcwd() . '/';
foreach (array('modules', 'vendor') as $dir) {
if (is_dir($dir = $cwd . $dir)) {
$paths[] = $dir;
}
}
$config['module_paths'] = $paths;
}
// "extra_module_paths" is an invention of PPI (aka doesn't exist in ZF2).
if (isset($config['extra_module_paths'])) {
$config['module_paths'] = array_merge($config['module_paths'], $config['extra_module_paths']);
}
$listenerOptions = new ListenerOptions($config);
$defaultListeners = new DefaultListenerAggregate($listenerOptions);
return $defaultListeners;
} | Creates and returns the default module listeners, providing them configuration
from the "module_listener_options" key of the ApplicationConfig
service. Also sets the default config glob path.
@param ServiceLocatorInterface $serviceLocator
@return DefaultListenerAggregate
@note If ListenerOptions becomes a service use "ModuleListenerOptions" or "module.listenerOptions" as the key. | entailment |
public function listStore()
{
$this->actionListStore();
$this->setTitleListStore();
$this->setBreadcrumbListStore();
$this->setFilterListStore();
$this->setPagerListStore();
$this->setData('stores', $this->getListStore());
$this->setData('default_store', $this->store->getDefault());
$this->outputListStore();
} | Displays the store overview page | entailment |
protected function setPagerListStore()
{
$conditions = $this->query_filter;
$conditions['count'] = true;
$pager = array(
'query' => $this->query_filter,
'total' => (int) $this->store->getList($conditions)
);
return $this->data_limit = $this->setPager($pager);
} | Sets pager
@return array | entailment |
protected function actionListStore()
{
list($selected, $action, $value) = $this->getPostedAction();
$updated = $deleted = 0;
foreach ($selected as $id) {
if ($action === 'status' && $this->access('store_edit')) {
$updated += (int) $this->store->update($id, array('status' => (int) $value));
}
if ($action === 'delete' && $this->access('store_delete') && !$this->store->isDefault($id)) {
$deleted += (int) $this->store->delete($id);
}
}
if ($updated > 0) {
$message = $this->text('Updated %num item(s)', array('%num' => $updated));
$this->setMessage($message, 'success');
}
if ($deleted > 0) {
$message = $this->text('Deleted %num item(s)', array('%num' => $deleted));
$this->setMessage($message, 'success');
}
} | Applies an action to the selected stores | entailment |
protected function getListStore()
{
$conditions = $this->query_filter;
$conditions['limit'] = $this->data_limit;
return $this->store->getList($conditions);
} | Returns an array of stores
@return array | entailment |
public function editStore($store_id = null)
{
$this->setStore($store_id);
$this->seTitleEditStore();
$this->setBreadcrumbEditStore();
$this->setData('store', $this->data_store);
$this->setData('themes', $this->getListThemeStore());
$this->setData('is_default', $this->isDefaultStore());
$this->setData('can_delete', $this->canDeleteStore());
$this->setData('countries', $this->getCountriesStore());
$this->setData('collections', $this->getListCollectionStore());
$this->setData('languages', $this->language->getList(array('enabled' => true)));
$this->submitEditStore();
$this->setDataEditStore();
$this->setJsEditStore();
$this->outputEditStore();
} | Displays the store settings form
@param integer|null $store_id | entailment |
protected function canDeleteStore()
{
return isset($this->data_store['store_id'])
&& $this->store->canDelete($this->data_store['store_id'])
&& $this->access('store_delete')
&& !$this->isDefaultStore();
} | Whether the store can be deleted
@return boolean | entailment |
protected function setStore($store_id)
{
$this->data_store = array();
if (is_numeric($store_id)) {
$this->data_store = $this->store->get($store_id);
if (empty($this->data_store)) {
$this->outputHttpStatus(404);
}
}
$this->prepareStore($this->data_store);
} | Sets a store data
@param int|null $store_id | entailment |
protected function getListThemeStore()
{
$themes = $this->module->getByType('theme', true);
unset($themes[$this->theme_backend]);
return $themes;
} | Returns an array of available theme modules excluding backend theme
@return array | entailment |
protected function getListCollectionStore()
{
if (empty($this->data_store['store_id'])) {
return array();
}
$conditions = array(
'status' => 1,
'store_id' => $this->data_store['store_id']
);
$collections = (array) $this->collection->getList($conditions);
$list = array();
foreach ($collections as $collection) {
$list[$collection['type']][$collection['collection_id']] = $collection;
}
return $list;
} | Returns an array of enabled collection for the store keyed by an entity name
@return array | entailment |
protected function submitEditStore()
{
if ($this->isPosted('delete')) {
$this->deleteStore();
} else if ($this->isPosted('save') && $this->validateEditStore()) {
if (isset($this->data_store['store_id'])) {
$this->updateStore();
} else {
$this->addStore();
}
}
} | Handles a submitted store data | entailment |
protected function validateEditStore()
{
$this->setSubmitted('store', null, false);
$this->setSubmittedBool('status');
$this->setSubmitted('update', $this->data_store);
$this->setSubmittedBool('data.anonymous_checkout');
foreach (array('email', 'phone', 'fax', 'map') as $field) {
$this->setSubmittedArray("data.$field");
}
$this->validateComponent('store');
return !$this->hasErrors();
} | Validates a submitted store data
@return bool | entailment |
protected function deleteStore()
{
$this->controlAccess('store_delete');
if ($this->store->delete($this->data_store['store_id'])) {
$this->redirect('admin/settings/store', $this->text('Store has been deleted'), 'success');
}
$this->redirect('', $this->text('Store has not been deleted'), 'danger');
} | Deletes a store | entailment |
protected function updateStore()
{
$this->controlAccess('store_edit');
if ($this->store->update($this->data_store['store_id'], $this->getSubmitted())) {
$this->redirect('admin/settings/store', $this->text('Store has been updated'), 'success');
}
$this->redirect('', $this->text('Store has not been updated'), 'warning');
} | Updates a store | entailment |
protected function addStore()
{
$this->controlAccess('store_add');
if ($this->store->add($this->getSubmitted())) {
$this->redirect('admin/settings/store', $this->text('Store has been added'), 'success');
}
$this->redirect('', $this->text('Store has not been added'), 'warning');
} | Adds a new store | entailment |
protected function setDataEditStore()
{
foreach (array('logo', 'favicon') as $field) {
$value = $this->getData("store.data.$field");
if (!empty($value)) {
$this->setData("store.{$field}_thumb", $this->image($value));
}
}
foreach (array('email', 'phone', 'fax', 'map') as $field) {
$value = $this->getData("store.data.$field");
if (isset($value)) {
$this->setData("store.data.$field", implode("\n", (array) $value));
}
}
} | Prepares a store data | entailment |
protected function seTitleEditStore()
{
if (isset($this->data_store['store_id'])) {
$title = $this->text('Edit %name', array('%name' => $this->data_store['name']));
} else {
$title = $this->text('Add store');
}
$this->setTitle($title);
} | Sets titles on the store edit page | entailment |
protected function setBreadcrumbEditStore()
{
$breadcrumbs = array();
$breadcrumbs[] = array(
'url' => $this->url('admin'),
'text' => $this->text('Dashboard')
);
$breadcrumbs[] = array(
'url' => $this->url('admin/settings/store'),
'text' => $this->text('Stores')
);
$this->setBreadcrumbs($breadcrumbs);
} | Sets breadcrumbs on the store edit page | entailment |
public function init($modules = null)
{
if (!isset($modules)) {
$modules = $this->module->getEnabled();
}
foreach ((array) $modules as $module) {
if (empty($module['hooks'])) {
continue;
}
foreach ($module['hooks'] as $method) {
$this->register($method, $module['class']);
}
}
return $this->hooks;
} | Registers module hooks
@param array|null $modules
@return array | entailment |
public function attach($hook, &$a = null, &$b = null, &$c = null, &$d = null, &$e = null)
{
$module_id = null;
if (strpos($hook, '|') !== false) {
list($hook, $module_id) = explode('|', $hook, 2);
}
$method = $this->getMethod($hook);
if (isset($module_id)) {
$class = $this->module->getClass($module_id);
return $this->call($class, $method, $a, $b, $c, $d, $e);
}
if (empty($this->hooks[$method])) {
return false;
}
foreach (array_keys($this->hooks[$method]) as $class) {
$this->call($class, $method, $a, $b, $c, $d, $e);
}
return true;
} | Call all defined functions for the hook
@param string $hook
@param mixed $a
@param mixed $b
@param mixed $c
@param mixed $d
@param mixed $e
@return boolean | entailment |
public function call($class, $method, &$a = null, &$b = null, &$c = null, &$d = null, &$e = null)
{
if (!is_callable(array($class, $method))) {
return false;
}
try {
$instance = Container::get($class);
$instance->{$method}($a, $b, $c, $d, $e);
$this->called[$method][$class] = array($class, $method);
return array($a, $b, $c, $d, $e);
} catch (Exception $exc) {
return false;
}
} | Calls a hook method
@param string $class
@param string $method
@param mixed $a
@param mixed $b
@param mixed $c
@param mixed $d
@param mixed $e
@return boolean|array | entailment |
public function collection(array &$submitted, array $options = array())
{
$this->options = $options;
$this->submitted = &$submitted;
$this->validateCollection();
$this->validateBool('status');
$this->validateTitle();
$this->validateDescription();
$this->validateTranslation();
$this->validateStoreId();
$this->validateTypeCollection();
$this->unsetSubmitted('update');
return $this->getResult();
} | Performs full collection data validation
@param array $submitted
@param array $options
@return boolean|array | entailment |
protected function validateCollection()
{
$id = $this->getUpdatingId();
if ($id === false) {
return null;
}
$data = $this->collection->get($id);
if (empty($data)) {
$this->setErrorUnavailable('update', $this->translation->text('Collection'));
return false;
}
$this->setSubmitted('update', $data);
return true;
} | Validates a collection to be updated
@return boolean|null | entailment |
protected function validateTypeCollection()
{
$field = 'type';
if ($this->isExcluded($field) || $this->isUpdating()) {
return null; // Do not check type on update - it cannot be changed and will be ignored
}
$value = $this->getSubmitted($field);
$label = $this->translation->text('Type');
if (empty($value)) {
$this->setErrorRequired($field, $label);
return false;
}
$types = $this->collection->getTypes();
if (!isset($types[$value])) {
$this->setErrorUnavailable($field, $label);
return false;
}
return true;
} | Validates collection type field
@return boolean | entailment |
public static function get($class)
{
$key = strtolower($class);
if (isset(static::$instances[$key])) {
return static::$instances[$key];
}
static::override($class);
if (!class_exists($class)) {
throw new ReflectionException("Class $class does not exist");
}
$instance = static::getInstance($class);
static::register($class, $instance);
return $instance;
} | Instantiates and registers a class
@param string $class
@return object
@throws ReflectionException | entailment |
public static function getInstance($class)
{
$reflection = new ReflectionClass($class);
$constructor = $reflection->getConstructor();
if (empty($constructor)) {
return new $class;
}
$parameters = $constructor->getParameters();
if (empty($parameters)) {
return new $class;
}
$dependencies = array();
foreach ($parameters as $parameter) {
$parameter_class = $parameter->getClass();
$dependencies[] = static::get($parameter_class->getName());
}
return $reflection->newInstanceArgs($dependencies);
} | Returns an instance using a class name
@param string $class
@return object | entailment |
protected static function override(&$class)
{
$map = gplcart_config_get(GC_FILE_CONFIG_COMPILED_OVERRIDE);
if (isset($map[$class])) {
$override = end($map[$class]);
$class = $override;
}
return $class;
} | Override a class namespace
@param string $class
@return string | entailment |
public function productClass(array &$submitted, array $options = array())
{
$this->options = $options;
$this->submitted = &$submitted;
$this->validateProductClass();
$this->validateBool('status');
$this->validateTitle();
$this->unsetSubmitted('update');
return $this->getResult();
} | Performs full product class validation
@param array $submitted
@param array $options
@return array|boolean | entailment |
protected function validateProductClass()
{
$id = $this->getUpdatingId();
if ($id === false) {
return null;
}
$data = $this->product_class->get($id);
if (empty($data)) {
$this->setErrorUnavailable('update', $this->translation->text('Product class'));
return false;
}
$this->setUpdating($data);
return true;
} | Validates a product class ID
@return boolean|null | entailment |
public function set($langcode, $context)
{
$result = null;
$this->hook->attach('translation.set.before', $langcode, $context, $result, $this);
if (isset($result)) {
return $result;
}
$this->setContext($context);
$this->setLangcode($langcode);
$result = $this->prepareFiles($langcode);
$this->hook->attach('translation.set.after', $langcode, $context, $result, $this);
return (bool) $result;
} | Set up a language
@param string|null $langcode
@param string|null $context
@return bool | entailment |
protected function prepareFiles($langcode)
{
if (empty($langcode) || $langcode === 'en') {
return $this->prepared = false;
}
$main_file = $this->getFile($langcode);
if (!is_file($main_file)) {
return $this->prepared = false;
}
$dir = $this->getCompiledDirectory();
if (!file_exists($dir) && !mkdir($dir, 0775, true)) {
return $this->prepared = false;
}
$common_file = $this->getCommonFile($langcode);
if (is_file($common_file)) {
return $this->prepared = true;
}
$directory = dirname($common_file);
if (!file_exists($directory) && !mkdir($directory, 0775, true)) {
return $this->prepared = false;
}
return $this->prepared = copy($main_file, $common_file);
} | Prepare all necessary files for the language
@param string $langcode
@return bool | entailment |
public function getFile($langcode = null, $module_id = '')
{
if (!isset($langcode)) {
$langcode = $this->langcode;
}
if (empty($module_id)) {
$directory = $this->getDirectory($langcode);
} else {
$directory = $this->getModuleDirectory($module_id);
}
return "$directory/$langcode.csv";
} | Returns a path to a translation file
@param string|null $langcode
@param string $module_id
@return string | entailment |
public function getCommonFile($langcode = null)
{
if (!isset($langcode)) {
$langcode = $this->langcode;
}
return $this->getCompiledDirectory($langcode) . "/$langcode.csv";
} | Returns the path to a common translation file
@param string|null $langcode
@return string | entailment |
public function text($string, array $arguments = array())
{
if (!$this->prepared) {
return $this->formatString($string, $arguments);
}
if (empty($this->langcode) || $this->langcode === 'en') {
return $this->formatString($string, $arguments);
}
$context_file = $this->getContextFile($this->context, $this->langcode);
$context_translations = $this->loadTranslation($context_file);
if (isset($context_translations[$string])) {
return $this->formatString($string, $arguments, $context_translations[$string]);
}
$common_file = $this->getCommonFile();
$common_translations = $this->loadTranslation($common_file);
if (isset($common_translations[$string])) {
$this->addTranslation($string, $common_translations, $context_file);
return $this->formatString($string, $arguments, $common_translations[$string]);
}
$this->addTranslation($string, $common_translations, $context_file);
$this->addTranslation($string, $common_translations, $common_file);
return $this->formatString($string, $arguments);
} | Translates a string
@param string $string
@param array $arguments
@return string | entailment |
public function getContextFile($context, $langcode)
{
if (empty($context)) {
return '';
}
static $files = array();
if (!isset($files["$context$langcode"])) {
$filename = $this->getFilenameFromContext($context);
$directory = $this->getCompiledDirectory($langcode);
$files["$context$langcode"] = "$directory/$filename.csv";
}
return $files["$context$langcode"];
} | Returns a context translation file
@param string $context
@param string $langcode
@return string | entailment |
protected function formatString($source, array $args, array $data = array())
{
if (!isset($data[0]) || $data[0] === '') {
return gplcart_string_format($source, $args);
}
return gplcart_string_format($data[0], $args);
} | Returns a translated and formated string
@param string $source
@param array $args
@param array $data
@return string | entailment |
public function loadTranslation($file)
{
$translations = &gplcart_static("translation.$file");
if (isset($translations)) {
return (array) $translations;
}
$translations = array();
if (empty($file) || !is_file($file)) {
return $translations = array();
}
foreach ($this->parseCsv($file) as $row) {
$key = array_shift($row);
$translations[$key] = $row;
}
return $translations;
} | Returns an array of translations from CSV files
@param string $file
@return array | entailment |
public function loadJsTranslation($langcode = null)
{
$strings = $this->loadTranslation($this->getContextJsFile($langcode));
$translations = array();
foreach ($strings as $source => $translation) {
if (isset($translation[0]) && $translation[0] !== '') {
$translations[$source] = $translation;
}
}
return $translations;
} | Returns an array of JS translations
@param string|null $langcode
@return array | entailment |
public function parseCsv($file)
{
$handle = fopen($file, 'r');
if (!is_resource($handle)) {
return array();
}
$content = array();
while (($data = fgetcsv($handle)) !== false) {
$content[] = $data;
}
fclose($handle);
return $content;
} | Parse a translation file
@param string $file
@return array | entailment |
protected function addTranslation($string, array $translations, $file)
{
if ($this->prepared && !isset($this->written[$file][$string]) && !empty($this->context)) {
$data = array($string);
if (isset($translations[$string][0]) && $translations[$string][0] !== '') {
$data = $translations[$string];
array_unshift($data, $string);
}
gplcart_file_csv($file, $data);
$this->written[$file][$string] = true;
}
} | Append the string to the translation file
@param string $string
@param array $translations
@param string $file | entailment |
public function parseJs($content)
{
$matches = $results = array();
$pattern = '~[^\w]Gplcart\s*\.\s*text\s*\(\s*((?:(?:\'(?:\\\\\'|[^\'])*\'|"(?:\\\\"|[^"])*")(?:\s*\+\s*)?)+)\s*[,\)]~s';
preg_match_all($pattern, $content, $matches);
foreach ($matches[1] as $strings) {
foreach ((array) $strings as $string) {
$results[] = implode('', preg_split('~(?<!\\\\)[\'"]\s*\+\s*[\'"]~s', substr($string, 1, -1)));
}
}
return $results;
} | Extracts strings wrapped in Gplcart.text()
@param string $content
@return array | entailment |
public function createJsTranslation($content, $langcode = null)
{
$extracted = $this->parseJs($content);
if (empty($extracted)) {
return false;
}
$file = $this->getContextJsFile($langcode);
$translations = $this->loadTranslation($this->getCommonFile($langcode));
foreach ($extracted as $string) {
$this->addTranslation($string, $translations, $file);
}
return true;
} | Creates context JS translation
@param string $content
@param string|null $langcode
@return boolean | entailment |
public function refresh($langcode = null)
{
$result = null;
$this->hook->attach('translation.refresh.before', $langcode, $result, $this);
if (isset($result)) {
return $result;
}
gplcart_file_empty($this->getCompiledDirectory($langcode), array('csv'));
gplcart_static_clear();
$this->prepareFiles($langcode);
$this->mergeModuleTranslations($langcode);
$result = true;
$this->hook->attach('translation.refresh.after', $langcode, $result, $this);
return $result;
} | Removes cached translation files
@param string|null $langcode
@return bool | entailment |
protected function mergeTranslation($merge_file, $langcode = null)
{
$common_file = $this->getCommonFile($langcode);
$merge_translations = $this->loadTranslation($merge_file);
$common_translations = $this->loadTranslation($common_file);
if (!empty($merge_translations)) {
foreach ($merge_translations as $source => $translation) {
if (!isset($common_translations[$source])) {
array_unshift($translation, $source);
gplcart_file_csv($common_file, $translation);
}
}
}
} | Merge two translations
@param string $merge_file
@param string|null $langcode | entailment |
protected function mergeModuleTranslations($langcode = null)
{
$modules = $this->module->getEnabled();
// Sort modules in descending order
// More important modules go first so their translations will be added earlier
gplcart_array_sort($modules, 'weight', false);
foreach ($modules as $module) {
$file = $this->getFile($langcode, $module['module_id']);
if (is_file($file)) {
$this->mergeTranslation($file, $langcode);
}
}
} | Add translations from all enabled modules to common file
@param string|null $langcode | entailment |
public function findAttribute($name)
{
foreach ($this->subAttributes as $attribute) {
if ($attribute->getName() === $name) {
return $attribute;
}
}
return null;
} | @param string $name
@return null|Attribute | entailment |
public static function deserializeObject(array $data)
{
$subAttributes = [];
if (isset($data['subAttributes'])) {
foreach ($data['subAttributes'] as $subAttribute) {
$subAttributes[] = static::deserializeObject($subAttribute);
}
}
$result = new static(
$data['name'],
$data['type'],
$data['multiValued'],
$data['required'],
isset($data['description']) ? $data['description'] : null,
$subAttributes,
isset($data['canonicalValues']) ? $data['canonicalValues'] : [],
isset($data['caseExact']) ? $data['caseExact'] : false,
$data['mutability'],
$data['returned'],
isset($data['uniqueness']) ? $data['uniqueness'] : null,
isset($data['referenceTypes']) ? $data['referenceTypes'] : []
);
return $result;
} | @param array $data
@return Attribute | entailment |
public function post(Request $request)
{
$this->validate($request, [
'file' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:4096',
]);
$fileName = basename($request->file->getClientOriginalName(), '.' . $request->file->getClientOriginalExtension());
$fileExtension = $request->file->getClientOriginalExtension();
$postName = $this->sanitizeUrl($fileName);
$mime = $request->file->getMimeType();
$postmeta = NikuPostmeta::where([
['meta_key', '=', 'attachment_url'],
['meta_value', 'LIKE', '/uploads/images/' . $fileName . '%']
])->get();
if($postmeta->count() != 0){
$count = $postmeta->count() + 1;
$fileCount = '-' . $count;
} else {
$fileCount = '';
}
$postName = $postName . $fileCount;
$fileName = $fileName . $fileCount . '.' . $fileExtension;
$post = new NikuPosts;
$post->post_title = $fileName;
$post->post_name = $postName;
$post->post_type = 'attachment';
$post->post_mime_type = $mime;
$post->status = 'inherit';
if(Auth::check()){
$post->post_author = Auth::user()->id;
} else {
$post->post_author = '0';
}
$post->save();
$postmeta = new NikuPostmeta;
$postmeta->post_id = $post->id;
$postmeta->meta_key = 'attachment_url';
$postmeta->meta_value = '/uploads/images/' . $fileName;
$postmeta->save();
$request->file->move(public_path('uploads/images'), $fileName);
$postObject = collect([
'status' => 0,
'postmeta' => [
0 => [
'meta_value' => $postmeta->meta_value,
]
],
'id' => $postmeta->post_id
]);
return response()->json([
'object' => $postObject
]);
} | Add attachment to the filesystem and add it to the database | entailment |
public function createService(ServiceLocatorInterface $serviceLocator)
{
$mm = $serviceLocator->get('ModuleManager');
$mm->loadModules();
$moduleParams = $mm->getEvent()->getParams();
$config = ArrayUtils::merge(
$moduleParams['configListener']->getMergedConfig(false),
$serviceLocator->get('ApplicationConfig')
);
$parametersBag = $serviceLocator->get('ApplicationParameters');
$config['parameters'] = isset($config['parameters']) ?
ArrayUtils::merge($parametersBag->all(), $config['parameters']) :
$config['parameters'] = $parametersBag->all();
return $parametersBag->resolveArray($config);
} | Create the application configuration service.
Retrieves the Module Manager from the service locator, and executes
{@link Zend\ModuleManager\ModuleManager::loadModules()}.
It then retrieves the config listener from the module manager, and from
that the merged configuration.
@param ServiceLocatorInterface $serviceLocator
@return array|\Traversable | entailment |
public function setUsed($price_rule_id)
{
$sql = 'UPDATE price_rule SET used=used + 1 WHERE price_rule_id=?';
return (bool) $this->db->run($sql, array($price_rule_id))->rowCount();
} | Increments a number of usages by 1
@param integer $price_rule_id
@return boolean | entailment |
public function codeMatches($price_rule_id, $code)
{
$sql = 'SELECT price_rule_id
FROM price_rule
WHERE code=? AND price_rule_id=? AND status=?';
return (bool) $this->db->fetchColumn($sql, array($code, $price_rule_id, 1));
} | Performs simple rule code validation
@param integer $price_rule_id
@param string $code
@return boolean | entailment |
public function calculate(&$total, $data, &$components, array $price_rule)
{
try {
$callback = Handler::get($this->getTypes(), $price_rule['value_type'], 'calculate');
call_user_func_array($callback, array(&$total, &$components, $price_rule, $data));
} catch (Exception $ex) {
trigger_error($ex->getMessage());
}
} | Calculate a price rule
@param int $total
@param array $data
@param array $components
@param array $price_rule | entailment |
public function getTypes()
{
$handlers = &gplcart_static('price.rule.types');
if (isset($handlers)) {
return $handlers;
}
$handlers = gplcart_config_get(GC_FILE_CONFIG_PRICE_RULE_TYPE);
$this->hook->attach('price.rule.types', $handlers, $this);
return $handlers;
} | Returns an array of price rule types
@return array | entailment |
public function getTriggered(array $data, array $options)
{
$options['trigger_id'] = $this->trigger->getTriggered($data, $options);
if (empty($options['trigger_id'])) {
return array();
}
$coupons = 0;
$results = array();
foreach ((array) $this->getList($options) as $id => $rule) {
if ($rule['code'] !== '') {
$coupons++;
}
if ($coupons <= 1) {
$results[$id] = $rule;
}
}
// Coupons always go last
uasort($results, function ($a) {
return $a['code'] === '' ? -1 : 1;
});
return $results;
} | Returns an array of triggered price rules
@param array $data
@param array $options
@return array | entailment |
public function itemId(array $condition, array $data)
{
if (!isset($data['product_id']) || !isset($data['bundle'])) {
return false;
}
if (!is_array($data['bundle'])) {
$data['bundle'] = explode(',', (string) $data['bundle']);
}
return $this->compare($data['bundle'], $condition['value'], $condition['operator']);
} | Whether the product is a bundled item and its ID is in a list of allowed IDs
@param array $condition
@param array $data
@return boolean | entailment |
public function itemCount(array $condition, array $data)
{
if (!isset($data['product_id']) || !isset($data['bundle'])) {
return false;
}
if (!is_array($data['bundle'])) {
$data['bundle'] = explode(',', (string) $data['bundle']);
}
return $this->compare(count($data['bundle']), $condition['value'], $condition['operator']);
} | Whether the product has the given number of bundled items
@param array $condition
@param array $data
@return boolean | entailment |
public function editReview($product_id, $review_id = null)
{
$this->setProductReview($product_id);
$this->setReview($review_id);
$this->setTitleEditReview();
$this->setBreadcrumbEditReview();
$this->setData('review', $this->data_review);
$this->setData('product', $this->data_product);
$this->setData('can_delete', $this->canDeleteReview());
$this->submitEditReview();
$this->setDataRatingEditReview();
$this->outputEditReview();
} | Displays the edit review page
@param integer $product_id
@param integer|null $review_id | entailment |
protected function setProductReview($product_id)
{
$this->data_product = $this->product->get($product_id);
if (empty($this->data_product['status']) || $this->data_product['store_id'] != $this->store_id) {
$this->outputHttpStatus(404);
}
$this->prepareProductReview($this->data_product);
} | Sets a product data
@param integer $product_id | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.