sentence1
stringlengths 52
3.87M
| sentence2
stringlengths 1
47.2k
| label
stringclasses 1
value |
---|---|---|
protected function getWidgetCartPreview(array $cart)
{
if (empty($cart['items'])) {
return '';
}
$options = array(
'cart' => $cart,
'limit' => $this->config('cart_preview_limit', 5)
);
return $this->render('cart/preview', $options, true);
} | Returns rendered cart preview
@param array $cart
@return string | entailment |
protected function execute(InputInterface $input, OutputInterface $output)
{
$indentation = 4;
if ($input->getOption('app-only')) {
$message = "This is the configuration defined in the app/ directory (not processed):\n";
$config = $this->getServiceManager()->get('ApplicationConfig');
} else {
$message = "This is the configuration in use for your current setup (merged and processed):\n";
$config = $this->getServiceManager()->get('Config');
}
$files = array();
$contents = array();
if (($files['php'] = $input->getOption('write-php'))) {
$contents['php'] = "<?php\n\nreturn " . var_export($config, true) . ";\n\n?>\n";
}
if (($files['yaml'] = $input->getOption('write-yaml'))) {
$dumper = new Dumper();
$dumper->setIndentation($indentation);
$contents['yaml'] = $dumper->dump($config, 6, 0, false, false);
}
if (empty($contents)) {
$dumper = new Dumper();
$dumper->setIndentation($indentation);
$output->writeln($message);
foreach ($config as $rootKey => $subConfig) {
$output->writeln('<info>' . $rootKey . '</info>:');
$output->writeln($dumper->dump($subConfig, 6, $indentation, false, false));
}
return;
}
foreach ($files as $format => $file) {
$output->write('Saving configuration in <info>' . strtoupper($format) . '</info> format...');
if ($fileExists = file_exists($file)) {
if (!isset($dialog)) {
$dialog = $this->getHelperSet()->get('dialog');
}
if (!$dialog->askConfirmation($output,
" <question>File \"" . $file . "\" already exists. Proceed anyway?</question> ", false)) {
continue;
}
}
file_put_contents($file, $contents[$format]);
if (!$fileExists) {
$output->writeln(' OK.');
}
}
} | {@inheritdoc} | entailment |
public function order(array &$submitted, array $options = array())
{
$this->options = $options;
$this->submitted = &$submitted;
$this->validateOrder();
$this->validateStoreId();
$this->validatePaymentOrder();
$this->validateShippingOrder();
$this->validateStatusOrder();
$this->validateShippingAddressOrder();
$this->validatePaymentAddressOrder();
$this->validateUserCartId();
$this->validateCreatorOrder();
$this->validateTotalOrder();
$this->validateData();
$this->validateComponentPricesOrder();
$this->validateCurrencyOrder();
$this->validateCommentOrder();
$this->validateTransactionOrder();
$this->validateLogOrder();
$this->unsetSubmitted('update');
return $this->getResult();
} | Performs full order data validation
@param array $submitted
@param array $options
@return array|boolean | entailment |
protected function validateOrder()
{
$id = $this->getUpdatingId();
if ($id === false) {
return null;
}
$data = $this->order->get($id);
if (empty($data)) {
$this->setErrorUnavailable('update', $this->translation->text('Order'));
return false;
}
$this->setUpdating($data);
return true;
} | Validates an order to be updated
@return boolean | entailment |
protected function validatePaymentOrder()
{
$field = 'payment';
if ($this->isExcluded($field)) {
return null;
}
$value = $this->getSubmitted($field);
if ($this->isUpdating() && !isset($value)) {
$this->unsetSubmitted($field);
return null;
}
$label = $this->translation->text('Payment');
if (empty($value)) {
$this->setErrorRequired($field, $label);
return false;
}
$method = $this->payment->get($value);
if (empty($method['status'])) {
$this->setErrorUnavailable($field, $label);
return false;
}
return true;
} | Validates a payment method
@return boolean|null | entailment |
protected function validateStatusOrder()
{
$field = 'status';
$value = $this->getSubmitted($field);
if (!isset($value)) {
$this->unsetSubmitted($field);
return null;
}
$statuses = $this->order->getStatuses();
if (empty($statuses[$value])) {
$this->setErrorUnavailable($field, $this->translation->text('Status'));
return false;
}
return true;
} | Validates a status
@return boolean|null | entailment |
protected function validatePaymentAddressOrder()
{
$field = 'payment_address';
if ($this->isExcluded($field)) {
return null;
}
$value = $this->getSubmitted($field);
if (!isset($value) && $this->isUpdating()) {
$this->unsetSubmitted($field);
return null;
}
if (empty($value) && !$this->isError('shipping_address')) {
$value = $this->getSubmitted('shipping_address');
}
$label = $this->translation->text('Payment address');
if (empty($value)) {
$this->setErrorRequired($field, $label);
return false;
}
if (!is_numeric($value)) {
$this->setErrorNumeric($field, $label);
return false;
}
$address = $this->address->get($value);
if (empty($address)) {
$this->setErrorUnavailable($field, $label);
return false;
}
$this->setSubmitted($field, $value);
return true;
} | Validates a payment address
@return boolean | entailment |
protected function validateCreatorOrder()
{
$field = 'creator';
$value = $this->getSubmitted($field);
if (!isset($value) && $this->isUpdating()) {
$this->unsetSubmitted($field);
return null;
}
if (empty($value)) {
return null;
}
$label = $this->translation->text('Creator');
if (!is_numeric($value)) {
$this->setErrorNumeric($field, $label);
return false;
}
$user = $this->user->get($value);
if (empty($user)) {
$this->setErrorUnavailable($field, $label);
return false;
}
return true;
} | Validates a creator user ID
@return boolean|null | entailment |
protected function validateTotalOrder()
{
$field = 'total';
$value = $this->getSubmitted($field);
if (!isset($value)) {
$this->unsetSubmitted($field);
return null;
}
$label = $this->translation->text('Total');
if (!is_numeric($value)) {
$this->setErrorNumeric($field, $label);
return false;
}
if (strlen($value) > 10) {
$this->setErrorLengthRange($field, $label, 0, 10);
return false;
}
return true;
} | Validates order total
@return boolean|null | entailment |
protected function validateComponentPricesOrder()
{
$field = 'data.components';
$components = $this->getSubmitted($field);
if (empty($components)) {
$this->unsetSubmitted($field);
return null;
}
$label = $this->translation->text('Price');
if (!is_array($components)) {
$this->setErrorInvalid($field, $label);
return false;
}
foreach ($components as $id => $component) {
if (!is_numeric($component['price'])) {
$this->setErrorNumeric("$field.$id", $label);
continue;
}
if (strlen($component['price']) > 10) {
$this->setErrorLengthRange("$field.$id", $label, 0, 10);
}
}
return !$this->isError('components');
} | Validates order component prices
@return bool | entailment |
protected function validateTransactionOrder()
{
$field = 'transaction_id';
$value = $this->getSubmitted($field);
if (!isset($value)) {
$this->unsetSubmitted($field);
return null;
}
$label = $this->translation->text('Transaction');
if (!is_numeric($value)) {
$this->setErrorNumeric($field, $label);
return false;
}
if (empty($value)) {
return true;
}
$transaction = $this->transaction->get($value);
if (empty($transaction)) {
$this->setErrorUnavailable($field, $label);
return false;
}
return true;
} | Validates a transaction ID
@return boolean|null | entailment |
protected function validateLogOrder()
{
if (mb_strlen($this->getSubmitted('log')) > 255) {
$this->setErrorLengthRange('log', $this->translation->text('Log'), 0, 255);
return false;
}
return true;
} | Validates a log message
@return boolean|null | entailment |
public function run($handler_id, &$submitted, array $options = array())
{
$result = null;
$this->hook->attach('validator.run.before', $submitted, $options, $result, $this);
if (isset($result)) {
return $result;
}
$result = $this->callHandler($handler_id, $submitted, $options);
$this->hook->attach('validator.run.after', $submitted, $options, $result, $this);
if ($result === true) {
return true;
}
return empty($result) ? $this->translation->text('Failed validation') : $result;
} | Performs validation using the given handler
@param string $handler_id
@param mixed $submitted
@param array $options
@return mixed | entailment |
public function callHandler($handler_id, &$submitted, array $options)
{
try {
$handlers = $this->getHandlers();
$callback = Handler::get($handlers, $handler_id, 'validate');
return call_user_func_array($callback, array(&$submitted, $options));
} catch (Exception $ex) {
return $ex->getMessage();
}
} | Call a validation handler
@param string $handler_id
@param mixed $submitted
@param array $options
@return mixed | entailment |
public function submitProductCompare($compare_action_model)
{
$this->setSubmitted('product');
$this->filterSubmitted(array('product_id'));
if ($this->isPosted('remove_from_compare')) {
$this->deleteFromProductCompare($compare_action_model);
} else if ($this->isPosted('add_to_compare')) {
$this->validateAddProductCompare();
$this->addToProductCompare($compare_action_model);
}
} | Handles adding/removing a submitted product from comparison
@param \gplcart\core\models\ProductCompareAction $compare_action_model | entailment |
public function addToProductCompare($compare_action_model)
{
$errors = $this->error();
if (empty($errors)) {
$submitted = $this->getSubmitted();
$result = $compare_action_model->add($submitted['product'], $submitted);
} else {
$result = array(
'redirect' => '',
'severity' => 'warning',
'message' => $this->format($errors)
);
}
if ($this->isAjax()) {
$this->outputJson($result);
}
$this->redirect($result['redirect'], $result['message'], $result['severity']);
} | Adds a submitted product to comparison
@param \gplcart\core\models\ProductCompareAction $compare_action_model | entailment |
public function deleteFromProductCompare($compare_action_model)
{
$product_id = $this->getSubmitted('product_id');
$result = $compare_action_model->delete($product_id);
if ($this->isAjax()) {
$this->outputJson($result);
}
$this->controlDeleteProductCompare($result, $product_id);
$this->redirect($result['redirect'], $result['message'], $result['severity']);
} | Deletes a submitted product from comparison
@param \gplcart\core\models\ProductCompareAction $compare_action_model | entailment |
protected function controlDeleteProductCompare(array &$result, $product_id)
{
if (empty($result['redirect'])) {
$segments = explode(',', $this->path());
if (isset($segments[0]) && $segments[0] === 'compare' && !empty($segments[1])) {
$ids = array_filter(array_map('trim', explode(',', $segments[1])), 'ctype_digit');
unset($ids[array_search($product_id, $ids)]);
$result['redirect'] = $segments[0] . '/' . implode(',', $ids);
}
}
} | Controls result after a product has been deleted from comparison
@param array $result
@param integer $product_id | entailment |
public static function configRoutes($groupConfig)
{
$groups = '';
$i = 0;
foreach($groupConfig['register_groups'] as $key => $value) {
$i++;
if($i == 1){
$groups .= $value;
} else {
$groups .= '|' . $value;
}
}
Route::group([
'middleware' => 'groups:' . $groups
], function ($object) {
Route::post('/config/{group}/show', '\Niku\Cms\Http\Controllers\Config\ShowConfigController@init')->name('show');
Route::post('/config/{group}/edit', '\Niku\Cms\Http\Controllers\Config\EditConfigController@init')->name('edit');
});
} | Get a Cms route registrar.
@param array $options
@return RouteRegistrar | entailment |
protected function getSignature(array $options)
{
$signature = "\r\n\r\n-------------------------------------\r\n@owner\r\n@address\r\n@phone\r\n@fax\r\n@store_email\r\n@map"; // @text
$replacements = array();
$replacements['@owner'] = empty($options['owner']) ? '' : $options['owner'];
$replacements['@address'] = empty($options['address']) ? '' : $options['address'];
$replacements['@phone'] = empty($options['phone']) ? '' : $this->translation->text('Tel: @phone', array('@phone' => implode(',', $options['phone'])));
$replacements['@fax'] = empty($options['fax']) ? '' : $this->translation->text('Fax: @fax', array('@fax' => implode(',', $options['fax'])));
$replacements['@store_email'] = empty($options['email']) ? '' : $this->translation->text('E-mail: @store_email', array('@store_email' => implode(',', $options['email'])));
$replacements['@map'] = empty($options['map']) ? '' : $this->translation->text('Find us on Google Maps: @map', array('@map' => 'http://maps.google.com/?q=' . implode(',', $options['map'])));
return rtrim(gplcart_string_format($signature, $replacements), "\t\n\r\0\x0B-");
} | Returns a string containing default e-mail signature
@param array $options
@return string | entailment |
public function resolveArray(array $data)
{
$self = $this;
array_walk_recursive($data, function (&$value, $key) use ($self) {
if (is_string($value)) {
$value = $self->resolveString($value);
}
});
return $data;
} | Replaces parameter placeholders (%name%) by their values in every string element of the $array.
@param array $data
@return array | entailment |
protected function flatten(array &$parameters, array $subnode = null, $path = null)
{
if (null === $subnode) {
$subnode = & $parameters;
}
foreach ($subnode as $key => $value) {
if (is_array($value)) {
$nodePath = $path ? $path . '.' . $key : $key;
$this->flatten($parameters, $value, $nodePath);
if (null === $path) {
unset($parameters[$key]);
}
} elseif (null !== $path) {
$parameters[$path . '.' . $key] = $value;
}
}
} | Flattens an nested array of parameters.
The scheme used is:
'key' => array('key2' => array('key3' => 'value'))
Becomes:
'key.key2.key3' => 'value'
This function takes an array by reference and will modify it
@param array &$parameters The array that will be flattened
@param array $subnode Current subnode being parsed, used internally for recursive calls
@param string $path Current path being parsed, used internally for recursive calls | entailment |
public function get($code)
{
$result = &gplcart_static("country.get.$code");
if (isset($result)) {
return $result;
}
$this->hook->attach('country.get.before', $code, $result, $this);
if (isset($result)) {
return $result;
}
$sql = 'SELECT * FROM country WHERE code=?';
$result = $this->db->fetch($sql, array($code), array('unserialize' => 'format'));
if (isset($result['format'])) {
$default_format = $this->getDefaultFormat();
$result['format'] = gplcart_array_merge($default_format, $result['format']);
gplcart_array_sort($result['format']);
}
$this->hook->attach('country.get.after', $code, $result, $this);
return $result;
} | Loads a country from the database
@param string $code
@return array | entailment |
public function getFormat($country, $only_enabled = false)
{
$data = is_string($country) ? $this->get($country) : (array) $country;
if (empty($data['format'])) {
$format = $this->getDefaultFormat();
gplcart_array_sort($format);
} else {
$format = $data['format'];
}
if ($only_enabled) {
return array_filter($format, function ($item) {
return !empty($item['status']);
});
}
return $format;
} | Returns an array of country format
@param string|array $country
@param bool $only_enabled
@return array | entailment |
public function add(array $data)
{
$result = null;
$this->hook->attach('country.add.before', $data, $result, $this);
if (isset($result)) {
return (bool) $result;
}
$result = true;
$this->db->insert('country', $data);
$this->hook->attach('country.add.after', $data, $result, $this);
return (bool) $result;
} | Adds a country
@param array $data
@return boolean | entailment |
public function getIso($code = null)
{
$data = (array) gplcart_config_get(GC_FILE_CONFIG_COUNTRY);
if (isset($code)) {
return isset($data[$code]) ? $data[$code] : '';
}
return $data;
} | Returns an array of country names or a country name if the code parameter is set
@param null|string $code
@return array|string | entailment |
protected function deleteLinked($code)
{
$this->db->delete('city', array('country' => $code));
$this->db->delete('state', array('country' => $code));
} | Deletes all database records related to the country
@param string $code | entailment |
public function delete(array $data = array())
{
$sql = 'DELETE FROM log';
$conditions = array();
if (empty($data['log_id'])) {
$sql .= " WHERE log_id IS NOT NULL";
} else {
settype($data['log_id'], 'array');
$placeholders = rtrim(str_repeat('?,', count($data['log_id'])), ',');
$sql .= " WHERE log_id IN($placeholders)";
$conditions = array_merge($conditions, $data['log_id']);
}
if (!empty($data['type'])) {
settype($data['type'], 'array');
$placeholders = rtrim(str_repeat('?,', count($data['type'])), ',');
$sql .= " AND type IN($placeholders)";
$conditions = array_merge($conditions, $data['type']);
}
$this->db->run($sql, $conditions);
return true;
} | Delete log records
@param array $data
@return boolean | entailment |
public function getStatus()
{
$statuses = array();
$statuses['core_version'] = array(
'title' => $this->translation->text('Core version'),
'description' => '',
'severity' => 'info',
'status' => gplcart_version(),
'weight' => 0,
);
$statuses['database_version'] = array(
'title' => $this->translation->text('Database version'),
'description' => '',
'severity' => 'info',
'status' => $this->db->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION),
'weight' => 1,
);
$statuses['php_version'] = array(
'title' => $this->translation->text('PHP version'),
'description' => '',
'severity' => 'info',
'status' => PHP_VERSION,
'weight' => 2,
);
$statuses['php_os'] = array(
'title' => $this->translation->text('PHP operating system'),
'description' => '',
'severity' => 'info',
'status' => PHP_OS,
'weight' => 3,
);
$statuses['php_memory_limit'] = array(
'title' => $this->translation->text('PHP Memory Limit'),
'description' => '',
'severity' => 'info',
'status' => ini_get('memory_limit'),
'weight' => 4,
);
$statuses['php_apc_enabled'] = array(
'title' => $this->translation->text('PHP APC cache enabled'),
'description' => '',
'severity' => 'info',
'status' => ini_get('apc.enabled') ? $this->translation->text('Yes') : $this->translation->text('No'),
'weight' => 5,
);
$statuses['server_software'] = array(
'title' => $this->translation->text('Server software'),
'description' => '',
'severity' => 'info',
'status' => filter_input(INPUT_SERVER, 'SERVER_SOFTWARE', FILTER_SANITIZE_STRING),
'weight' => 6
);
$date_format = $this->config->get('date_full_format', 'd.m.Y H:i');
$statuses['cron'] = array(
'title' => $this->translation->text('Cron last run'),
'description' => '',
'severity' => 'info',
'status' => date($date_format, $this->config->get('cron_last_run')),
'weight' => 7,
);
$filesystem = $this->checkFilesystem();
$statuses['filesystem'] = array(
'title' => $this->translation->text('Filesystem is protected'),
'description' => '',
'severity' => 'danger',
'status' => $filesystem === true ? $this->translation->text('Yes') : $this->translation->text('No'),
'details' => $filesystem === true ? array() : $filesystem,
'weight' => 8,
);
$statuses['search_index'] = array(
'title' => $this->translation->text('Search index'),
'description' => '',
'severity' => 'info',
'status' => $this->translation->text('@num rows', array('@num' => $this->countSearchIndex())),
'weight' => 9,
);
$this->hook->attach('report.statuses', $statuses, $this);
gplcart_array_sort($statuses);
return $statuses;
} | Returns an array of system statuses
@return array | entailment |
public function getSeverities()
{
return array(
'info' => $this->translation->text('Info'),
'danger' => $this->translation->text('Danger'),
'warning' => $this->translation->text('Warning')
);
} | Returns an array of log severity types
@return array | entailment |
public function checkFilesystem()
{
$results = array(
$this->checkPermissions(GC_FILE_CONFIG_COMPILED)
);
if (file_exists(GC_FILE_CONFIG_COMPILED_OVERRIDE)) {
$results[] = $this->checkPermissions(GC_FILE_CONFIG_COMPILED_OVERRIDE);
}
$filtered = array_filter($results, 'is_string');
return empty($filtered) ? true : $filtered;
} | Checks file system
@return boolean|array | entailment |
protected function checkPermissions($file, $permissions = '0444')
{
if (substr(sprintf('%o', fileperms($file)), -4) === $permissions) {
return true;
}
$vars = array('%name' => $file, '%perm' => $permissions);
return $this->translation->text('File %name is not secure. The file permissions must be %perm', $vars);
} | Checks file permissions
@param string $file
@param string $permissions
@return boolean|array | entailment |
public function setItemOrderShippingName(&$item, $shipping_model)
{
if (isset($item['shipping'])) {
$data = $shipping_model->get($item['shipping']);
$item['shipping_name'] = empty($data['title']) ? 'Unknown' : $data['title'];
}
} | Adds "shipping_name" key
@param array $item
@param \gplcart\core\models\Shipping $shipping_model | entailment |
public function setItemOrderPaymentName(&$item, $payment_model)
{
if (isset($item['payment'])) {
$data = $payment_model->get($item['payment']);
$item['payment_name'] = empty($data['title']) ? 'Unknown' : $data['title'];
}
} | Adds "payment_name" key
@param array $item
@param \gplcart\core\models\Payment $payment_model | entailment |
public function setItemOrderAddress(&$order, $address_model)
{
$order['address'] = array();
foreach (array('shipping', 'payment') as $type) {
$address = $address_model->get($order["{$type}_address"]);
if (!empty($address)) {
$order['address'][$type] = $address;
$order['address_translated'][$type] = $address_model->getTranslated($order['address'][$type], true);
}
}
} | Adds an address information for the order item
@param array $order
@param \gplcart\core\models\Address $address_model | entailment |
public function setItemOrderStatusName(&$item, $order_model)
{
if (isset($item['status'])) {
$data = $order_model->getStatusName($item['status']);
$item['status_name'] = empty($data) ? 'Unknown' : $data;
}
} | Adds "status_name" key
@param array $item
@param \gplcart\core\models\Order $order_model | entailment |
public function setItemOrderStoreName(&$item, $store_model)
{
if (isset($item['store_id'])) {
$data = $store_model->get($item['store_id']);
$item['store_name'] = empty($data['name']) ? 'Unknown' : $data['name'];
}
} | Adds "store_name" key
@param array $item
@param \gplcart\core\models\Store $store_model | entailment |
public static function deserializeObject(array $data)
{
$result = new static($data['resourceType'], isset($data['created']) ? Helper::string2dateTime($data['created']) : null);
if (isset($data['lastModified'])) {
$result->lastModified = Helper::string2dateTime($data['lastModified']);
}
if (isset($data['location'])) {
$result->location = $data['location'];
}
if (isset($data['version'])) {
$result->version = $data['version'];
}
return $result;
} | @param array $data
@return Meta | entailment |
public function listCategoryGroup()
{
$this->setTitleListCategoryGroup();
$this->setBreadcrumbListCategoryGroup();
$this->setFilterListCategoryGroup();
$this->setPagerListCategoryGroup();
$this->setData('category_groups', $this->getListCategoryGroup());
$this->setData('category_group_types', $this->category_group->getTypes());
$this->outputListCategoryGroup();
} | Displays the category group overview page | entailment |
protected function setPagerListCategoryGroup()
{
$options = $this->query_filter;
$options['count'] = true;
$pager = array(
'query' => $this->query_filter,
'total' => (int) $this->category_group->getList($options)
);
return $this->data_limit = $this->setPager($pager);
} | Sets pager
@return array | entailment |
protected function getListCategoryGroup()
{
$conditions = $this->query_filter;
$conditions['limit'] = $this->data_limit;
return $this->category_group->getList($conditions);
} | Returns an array of category groups
@return array | entailment |
public function editCategoryGroup($category_group_id = null)
{
$this->setCategoryGroup($category_group_id);
$this->setTitleEditCategoryGroup();
$this->setBreadcrumbEditCategoryGroup();
$this->setData('category_group', $this->data_category_group);
$this->setData('can_delete', $this->canDeleteCategoryGroup());
$this->setData('languages', $this->language->getList(array('enabled' => true)));
$this->setData('category_group_types', $this->category_group->getTypes());
$this->submitEditCategoryGroup();
$this->outputEditCategoryGroup();
} | Displays the edit category group page
@param integer|null $category_group_id | entailment |
protected function canDeleteCategoryGroup()
{
return isset($this->data_category_group['category_group_id'])
&& $this->category_group->canDelete($this->data_category_group['category_group_id'])
&& $this->access('category_group_delete');
} | Whether the category group can be deleted
@return boolean | entailment |
protected function setCategoryGroup($category_group_id)
{
$this->data_category_group = array();
if (is_numeric($category_group_id)) {
$conditions = array(
'language' => 'und',
'category_group_id' => $category_group_id
);
$this->data_category_group = $this->category_group->get($conditions);
if (empty($this->data_category_group)) {
$this->outputHttpStatus(404);
}
$this->prepareCategoryGroup($this->data_category_group);
}
} | Sets the category group data
@param integer $category_group_id | entailment |
protected function submitEditCategoryGroup()
{
if ($this->isPosted('delete')) {
$this->deleteCategoryGroup();
} else if ($this->isPosted('save') && $this->validateEditCategoryGroup()) {
if (isset($this->data_category_group['category_group_id'])) {
$this->updateCategoryGroup();
} else {
$this->addCategoryGroup();
}
}
} | Handles a submitted category group data | entailment |
protected function validateEditCategoryGroup()
{
$this->setSubmitted('category_group');
$this->setSubmitted('update', $this->data_category_group);
$this->validateComponent('category_group');
return !$this->hasErrors(false);
} | Validates a submitted category group data | entailment |
protected function deleteCategoryGroup()
{
$this->controlAccess('category_group_delete');
if ($this->category_group->delete($this->data_category_group['category_group_id'])) {
$this->redirect('admin/content/category-group', $this->text('Category group has been deleted'), 'success');
}
$this->redirect('', $this->text('Category group has not been deleted'), 'warning');
} | Deletes a category group | entailment |
protected function updateCategoryGroup()
{
$this->controlAccess('category_group_edit');
if ($this->category_group->update($this->data_category_group['category_group_id'], $this->getSubmitted())) {
$this->redirect('admin/content/category-group', $this->text('Category group has been updated'), 'success');
}
$this->redirect('', $this->text('Category group has not been updated'), 'warning');
} | Updates a category group | entailment |
protected function addCategoryGroup()
{
$this->controlAccess('category_group_add');
if ($this->category_group->add($this->getSubmitted())) {
$this->redirect('admin/content/category-group', $this->text('Category group has been added'), 'success');
}
$this->redirect('', $this->text('Category group has not been added'), 'warning');
} | Adds a new category group | entailment |
protected function setTitleEditCategoryGroup()
{
if (isset($this->data_category_group['category_group_id'])) {
$title = $this->text('Edit %name', array('%name' => $this->data_category_group['title']));
} else {
$title = $this->text('Add category group');
}
$this->setTitle($title);
} | Sets titles on the category group edit page | entailment |
protected function setBreadcrumbEditCategoryGroup()
{
$breadcrumbs = array();
$breadcrumbs[] = array(
'url' => $this->url('admin'),
'text' => $this->text('Dashboard')
);
$breadcrumbs[] = array(
'url' => $this->url('admin/content/category-group'),
'text' => $this->text('Category groups')
);
$this->setBreadcrumbs($breadcrumbs);
} | Sets breadcrumbs on the edit category group page | entailment |
public function listTrigger()
{
$this->actionListTrigger();
$this->setTitleListTrigger();
$this->setBreadcrumbListTrigger();
$this->setFilterListTrigger();
$this->setPagerListTrigger();
$this->setData('triggers', $this->getListTrigger());
$this->outputListTrigger();
} | Displays the trigger overview page | entailment |
protected function setPagerListTrigger()
{
$conditions = $this->query_filter;
$conditions['count'] = true;
$pager = array(
'query' => $this->query_filter,
'total' => (int) $this->trigger->getList($conditions)
);
return $this->data_limit = $this->setPager($pager);
} | Sets pager
@return array | entailment |
protected function getListTrigger()
{
$conditions = $this->query_filter;
$conditions['limit'] = $this->data_limit;
return (array) $this->trigger->getList($conditions);
} | Returns an array of triggers
@return array | entailment |
public function editTrigger($trigger_id = null)
{
$this->setTrigger($trigger_id);
$this->setTitleEditTrigger();
$this->setBreadcrumbEditTrigger();
$this->setData('trigger', $this->data_trigger);
$this->setData('can_delete', $this->canDeleteTrigger());
$this->setData('conditions', $this->condition->getHandlers());
$this->setData('operators', $this->condition->getOperators());
$this->submitEditTrigger();
$this->setDataEditTrigger();
$this->outputEditTrigger();
} | Displays the trigger edit page
@param null|integer $trigger_id | entailment |
protected function setTrigger($trigger_id)
{
$this->data_trigger = array();
if (is_numeric($trigger_id)) {
$this->data_trigger = $this->trigger->get($trigger_id);
if (empty($this->data_trigger)) {
$this->outputHttpStatus(404);
}
}
} | Sets a trigger data
@param integer $trigger_id | entailment |
protected function submitEditTrigger()
{
if ($this->isPosted('delete')) {
$this->deleteTrigger();
} else if ($this->isPosted('save') && $this->validateEditTrigger()) {
if (isset($this->data_trigger['trigger_id'])) {
$this->updateTrigger();
} else {
$this->addTrigger();
}
}
} | Handles a submitted trigger data | entailment |
protected function validateEditTrigger()
{
$this->setSubmitted('trigger', null, false);
$this->setSubmittedBool('status');
$this->setSubmittedArray('data.conditions');
$this->setSubmitted('update', $this->data_trigger);
$this->validateComponent('trigger');
return !$this->hasErrors();
} | Validates a submitted trigger
@return bool | entailment |
protected function deleteTrigger()
{
$this->controlAccess('trigger_delete');
if ($this->trigger->delete($this->data_trigger['trigger_id'])) {
$this->redirect('admin/settings/trigger', $this->text('Trigger has been deleted'), 'success');
}
$this->redirect('', $this->text('Trigger has not been deleted'), 'warning');
} | Deletes a trigger | entailment |
protected function updateTrigger()
{
$this->controlAccess('trigger_edit');
if ($this->trigger->update($this->data_trigger['trigger_id'], $this->getSubmitted())) {
$this->redirect('admin/settings/trigger', $this->text('Trigger has been updated'), 'success');
}
$this->redirect('', $this->text('Trigger has not been updated'), 'warning');
} | Updates a trigger | entailment |
protected function addTrigger()
{
$this->controlAccess('trigger_add');
if ($this->trigger->add($this->getSubmitted())) {
$this->redirect('admin/settings/trigger', $this->text('Trigger has been added'), 'success');
}
$this->redirect('', $this->text('Trigger has not been added'), 'warning');
} | Adds a new trigger | entailment |
protected function setDataEditTrigger()
{
$conditions = $this->getData('trigger.data.conditions');
if (empty($conditions) || !is_array($conditions)) {
return null;
}
if (!$this->isError()) {
gplcart_array_sort($conditions);
}
$modified = array();
foreach ($conditions as $condition) {
$modified[] = is_string($condition) ? $condition : $condition['original'];
}
$this->setData('trigger.data.conditions', implode("\n", $modified));
} | Converts an array of conditions into a multiline string | entailment |
protected function setTitleEditTrigger()
{
if (isset($this->data_trigger['name'])) {
$title = $this->text('Edit %name', array('%name' => $this->data_trigger['name']));
} else {
$title = $this->text('Add trigger');
}
$this->setTitle($title);
} | Sets title on the edit trigger page | entailment |
protected function setBreadcrumbEditTrigger()
{
$breadcrumbs = array();
$breadcrumbs[] = array(
'url' => $this->url('admin'),
'text' => $this->text('Dashboard')
);
$breadcrumbs[] = array(
'url' => $this->url('admin/settings/trigger'),
'text' => $this->text('Triggers')
);
$this->setBreadcrumbs($breadcrumbs);
} | Sets breadcrumbs on the edit trigger page | entailment |
public function initialize(array $config)
{
$table = Configure::check('CakephpBlueimpUpload.upload_table') ? Configure::read('CakephpBlueimpUpload.upload_table') : 'uploads';
$this->setTable($table);
$this->setDisplayField('id');
$this->setPrimaryKey('id');
$this->addBehavior('Timestamp');
$this->addBehavior('Alaxos.UserLink');
} | Initialize method
@param array $config The configuration for the Table.
@return void | entailment |
public function validationDefault(Validator $validator)
{
$validator
->add('id', 'valid', ['rule' => 'numeric'])
->allowEmpty('id', 'create');
$validator
->requirePresence('upload_id', 'create')
->notEmpty('upload_id');
$validator
->requirePresence('original_filename', 'create')
->notEmpty('original_filename');
$validator
->requirePresence('unique_filename', 'create')
->notEmpty('unique_filename');
$validator
->allowEmpty('subfolder');
$validator
->allowEmpty('mimetype');
$validator
->add('size', 'valid', ['rule' => 'numeric'])
->requirePresence('size', 'create')
->notEmpty('size');
$validator
->requirePresence('hash', 'create')
->notEmpty('hash');
$validator
->add('upload_complete', 'valid', ['rule' => 'boolean'])
->requirePresence('upload_complete', 'create')
->notEmpty('upload_complete');
$validator
->allowEmpty('label');
$validator
->add('created_by', 'valid', ['rule' => 'numeric'])
->requirePresence('created_by', 'create')
->notEmpty('created_by');
$validator
->add('modified_by', 'valid', ['rule' => 'numeric'])
->allowEmpty('modified_by');
return $validator;
} | Default validation rules.
@param \Cake\Validation\Validator $validator Validator instance.
@return \Cake\Validation\Validator | entailment |
public function trigger(array &$submitted, array $options)
{
$this->options = $options;
$this->submitted = &$submitted;
$this->validateTrigger();
$this->validateBool('status');
$this->validateName();
$this->validateStoreId();
$this->validateWeight();
$this->validateConditionsTrigger();
$this->unsetSubmitted('update');
return $this->getResult();
} | Performs full trigger data validation
@param array $submitted
@param array $options
@return array|boolean | entailment |
protected function validateTrigger()
{
$id = $this->getUpdatingId();
if ($id === false) {
return null;
}
$data = $this->trigger->get($id);
if (empty($data)) {
$this->setErrorUnavailable('update', $this->translation->text('Trigger'));
return false;
}
$this->setUpdating($data);
return true;
} | Validates a trigger to be updated
@return boolean | entailment |
public function validateConditionsTrigger()
{
$field = 'data.conditions';
if ($this->isExcluded($field)) {
return null;
}
$value = $this->getSubmitted($field);
if ($this->isUpdating() && !isset($value)) {
$this->unsetSubmitted($field);
return null;
}
$label = $this->translation->text('Conditions');
if (empty($value)) {
$this->setErrorRequired($field, $label);
return false;
}
if (!is_array($value)) {
$this->setErrorInvalid($field, $label);
return false;
}
$submitted = $this->getSubmitted();
$operators = array_map('htmlspecialchars', array_keys($this->condition->getOperators()));
$errors = $modified = array();
foreach ($value as $line => $condition) {
$line++;
$parts = gplcart_string_explode_whitespace($condition, 3);
$condition_id = array_shift($parts);
$operator = array_shift($parts);
$parameters = array_filter(explode(',', implode('', $parts)), function ($value) {
return $value !== '';
});
if (empty($parameters)) {
$errors[] = $line;
continue;
}
if (!in_array(htmlspecialchars($operator), $operators)) {
$errors[] = $line;
continue;
}
$args = array($parameters, $operator, $condition_id, $submitted);
$result = $this->validateConditionTrigger($condition_id, $args);
if ($result !== true) {
$errors[] = $line;
continue;
}
$modified[] = array(
'weight' => $line,
'id' => $condition_id,
'value' => $parameters,
'operator' => $operator,
'original' => "$condition_id $operator " . implode(',', $parameters),
);
}
if (!empty($errors)) {
$error = $this->translation->text('Error in @num definition', array('@num' => implode(',', $errors)));
$this->setError($field, $error);
}
if ($this->isError()) {
return false;
}
$this->setSubmitted($field, $modified);
return true;
} | Validates and modifies trigger conditions
@return boolean|null | entailment |
protected function validateConditionTrigger($condition_id, array $args)
{
try {
$handlers = $this->condition->getHandlers();
return static::call($handlers, $condition_id, 'validate', $args);
} catch (Exception $ex) {
return $ex->getMessage();
}
} | Call a validator handler
@param string $condition_id
@param array $args
@return mixed | entailment |
public function configureServiceManager(ServiceManager $serviceManager)
{
$config = $serviceManager->get('Config');
$appRootDir = $config['parameters']['app.root_dir'];
$appCacheDir = $config['parameters']['app.cache_dir'];
$appCharset = $config['parameters']['app.charset'];
// The "framework.templating" option is deprecated. Please replace it with "framework.view"
$config = $this->processConfiguration($config);
// these are the templating engines currently supported
// @todo - this needs to come from the app config.
$knownEngineIds = array('php', 'smarty', 'twig', 'mustache', 'plates', 'latte');
// these are the engines selected by the user
$engineIds = isset($config['engines']) ? $config['engines'] : array('php');
// filter templating engines
$engineIds = array_intersect($engineIds, $knownEngineIds);
if (empty($engineIds)) {
throw new \RuntimeException(sprintf('At least one templating engine should be defined in your app config (in $config[\'view.engines\']). These are the available ones: "%s". Example: "$config[\'templating.engines\'] = array(\'%s\');"', implode('", ', $knownEngineIds), implode("', ", $knownEngineIds)));
}
/*
* Templating Locator.
*/
$serviceManager->setFactory('templating.locator', function ($serviceManager) use ($appCacheDir) {
return new TemplateLocator(
$serviceManager->get('file_locator'),
$appCacheDir
);
});
/*
* Templating Name Parser.
*/
$serviceManager->setFactory('templating.name_parser', function ($serviceManager) {
return new TemplateNameParser($serviceManager->get('modulemanager'));
});
/*
* Filesystem Loader.
*/
$serviceManager->setFactory('templating.loader.filesystem', function ($serviceManager) {
return new FileSystemLoader($serviceManager->get('templating.locator'));
});
/*
* Templating assets helper.
*/
$serviceManager->setFactory('templating.helper.assets', function ($serviceManager) {
return new AssetsHelper($serviceManager->get('request')->getBasePath());
});
/*
* Templating globals.
*/
$serviceManager->setFactory('templating.globals', function ($serviceManager) {
return new GlobalVariables($serviceManager->get('servicemanager'));
});
/*
* PHP Engine.
*
* TODO: Migrate to Symfony\Bundle\FrameworkBundle\Templating\PhpEngine
*/
$serviceManager->setFactory('templating.engine.php', function ($serviceManager) use ($appCharset) {
$engine = new PhpEngine(
$serviceManager->get('templating.name_parser'),
$serviceManager->get('templating.loader'),
array(
new SlotsHelper(),
$serviceManager->get('templating.helper.assets'),
new RouterHelper($serviceManager->get('router')),
new SessionHelper($serviceManager->get('session')),
)
);
$engine->addGlobal('app', $serviceManager->get('templating.globals'));
$engine->setCharset($appCharset);
return $engine;
});
/*
* Twig Engine
*/
$serviceManager->setFactory('templating.engine.twig', function ($serviceManager) {
if (!class_exists('Twig_Environment')) {
throw new \Exception('PPI\Framework\TwigModule not found. Composer require: ppi/twig-module');
}
$twigEnvironment = new \Twig_Environment(
new \PPI\Framework\View\Twig\Loader\FileSystemLoader(
$serviceManager->get('templating.locator'),
$serviceManager->get('templating.name_parser'))
);
// Add some twig extension
$twigEnvironment->addExtension(new \PPI\Framework\View\Twig\Extension\AssetsExtension($serviceManager->get('templating.helper.assets')));
$twigEnvironment->addExtension(new \PPI\Framework\View\Twig\Extension\RouterExtension($serviceManager->get('router')));
return new \PPI\Framework\View\Twig\TwigEngine($twigEnvironment, $serviceManager->get('templating.name_parser'),
$serviceManager->get('templating.locator'), $serviceManager->get('templating.globals'));
});
/*
* Smarty Engine.
*/
$serviceManager->setFactory('templating.engine.smarty', function ($serviceManager) use ($appCacheDir) {
if (!class_exists('NoiseLabs\Bundle\SmartyBundle\SmartyEngine')) {
throw new \Exception('PPI\Framework\SmartyModule not found. Composer require: ppi/smarty-module');
}
$cacheDir = $appCacheDir . DIRECTORY_SEPARATOR . 'smarty';
$smartyEngine = new \PPI\Framework\View\Smarty\SmartyEngine(
new \Smarty(),
$serviceManager->get('templating.locator'),
$serviceManager->get('templating.name_parser'),
$serviceManager->get('templating.loader'),
array(
'cache_dir' => $cacheDir . DIRECTORY_SEPARATOR . 'cache',
'compile_dir' => $cacheDir . DIRECTORY_SEPARATOR . 'templates_c',
),
$serviceManager->get('templating.globals'),
$serviceManager->get('logger')
);
// Add some SmartyBundle extensions
$smartyEngine->addExtension(new SmartyAssetsExtension($serviceManager->get('templating.helper.assets')));
$smartyEngine->addExtension(new SmartyRouterExtension($serviceManager->get('router')));
return $smartyEngine;
});
// Mustache Engine
$serviceManager->setFactory('templating.engine.mustache', function ($serviceManager, $appCacheDir) {
if (!class_exists('Mustache_Engine')) {
throw new \Exception('PPI\Framework\MustacheModule not found. Composer require: ppi/mustache-module');
}
$rawMustacheEngine = new \Mustache_Engine(array(
'loader' => new MustacheFileSystemLoader($serviceManager->get('templating.locator'),
$serviceManager->get('templating.name_parser')),
'cache' => $appCacheDir . DIRECTORY_SEPARATOR . 'mustache',
));
return new MustacheEngine($rawMustacheEngine, $serviceManager->get('templating.name_parser'));
});
/*
* Delegating Engine.
*/
$serviceManager->setFactory('templating.engine.delegating', function ($serviceManager) use ($engineIds) {
$delegatingEngine = new DelegatingEngine();
// @todo - lazy load this
foreach ($engineIds as $id) {
$delegatingEngine->addEngine($serviceManager->get('templating.engine.' . $id));
}
return $delegatingEngine;
});
$serviceManager->setAlias('templating', 'templating.engine.delegating');
} | Templating engines currently supported:
- PHP
- Twig
- Smarty
- Mustache.
@param ServiceManager $serviceManager
@throws \RuntimeException | entailment |
protected function processConfiguration(array $config, ServiceManager $serviceManager = null)
{
$config = $config['framework'];
if (!isset($config['templating'])) {
$config['templating'] = array();
}
if (isset($config['view'])) {
$config['templating'] = $this->mergeConfiguration($config['view'], $config['templating']);
}
return $config['templating'];
} | {@inheritDoc} | entailment |
public function getByProduct($product_id)
{
$result = null;
$this->hook->attach('rating.get.before', $product_id, $result, $this);
if (isset($result)) {
return $result;
}
$sql = 'SELECT rating, votes FROM rating WHERE product_id=?';
$result = $this->db->fetch($sql, array($product_id));
$this->hook->attach('rating.get.after', $product_id, $result, $this);
return $result;
} | Returns an array of rating data for a given product
@param integer $product_id
@return array | entailment |
public function getByUser($product_id, $user_id)
{
$result = null;
$this->hook->attach('rating.get.user.before', $product_id, $user_id, $result, $this);
if (isset($result)) {
return $result;
}
$user_ids = (array) $user_id;
$conditions = array_merge($user_ids, array($product_id));
$placeholders = rtrim(str_repeat('?,', count($user_ids)), ',');
$sql = "SELECT * FROM rating_user WHERE user_id IN($placeholders) AND product_id=?";
$result = $this->db->fetchAll($sql, $conditions, array('index' => 'user_id'));
if (!is_array($user_id) && isset($result[$user_id])) {
$result = $result[$user_id];
}
$this->hook->attach('rating.get.user.after', $product_id, $user_id, $result, $this);
return $result;
} | Returns an array of user voting data for the given user(s)
@param integer $product_id
@param integer|array $user_id
@return array | entailment |
public function set(array $data)
{
$result = null;
$this->hook->attach('rating.set.before', $data, $result, $this);
if (isset($result)) {
return $result;
}
$conditions = array(
'user_id' => $data['user_id'],
'product_id' => $data['product_id']
);
$this->db->delete('rating_user', $conditions);
$this->addByUser($data);
$result = $this->setBayesian($data);
$this->hook->attach('rating.set.after', $data, $result, $this);
return $result;
} | Sets a rating for the given user and product
@param array $data
@return array | entailment |
protected function addByUser(array $data)
{
$result = null;
$this->hook->attach('rating.add.user.before', $data, $result, $this);
if (isset($result)) {
return (int) $result;
}
if (empty($data['rating'])) {
return 0; // Do not add rating 0 (unvote)
}
$result = $this->db->insert('rating_user', $data);
$this->hook->attach('rating.add.user.after', $data, $result, $this);
return (int) $result;
} | Adds a user rating
@param array $data
@return integer | entailment |
protected function setBayesian(array $data)
{
$rating = $this->getBayesian($data);
if (empty($rating['bayesian_rating'])) {
$this->db->delete('rating', array('product_id' => $data['product_id']));
return array();
}
$sql = 'INSERT INTO rating
SET rating=:rating, votes=:votes, product_id=:product_id
ON DUPLICATE KEY UPDATE rating=:rating, votes=:votes';
$params = array(
'product_id' => $data['product_id'],
'votes' => $rating['this_num_votes'],
'rating' => $rating['bayesian_rating']
);
$this->db->run($sql, $params);
return $rating;
} | Sets bayesian rating and votes for the given product
@param array $data
@return array | entailment |
public function getModulesPath()
{
$paths = array();
foreach ($this->getLoadedModules(true) as $module) {
$paths[$module->getName()] = $module->getPath();
}
return $paths;
} | Returns an array of paths to modules.
@return array An array of paths to each loaded module | entailment |
public function locateResource($name, $dir = null, $first = true)
{
if ('@' !== $name[0]) {
throw new \InvalidArgumentException(sprintf('A resource name must start with @ ("%s" given).', $name));
}
if (false !== strpos($name, '..')) {
throw new \RuntimeException(sprintf('File name "%s" contains invalid characters (..).', $name));
}
$moduleName = substr($name, 1);
$path = '';
if (false !== strpos($moduleName, '/')) {
list($moduleName, $path) = explode('/', $moduleName, 2);
}
$isResource = 0 === strpos($path, 'Resources') && null !== $dir;
$overridePath = substr($path, 9);
$resourceModule = null;
$modules = array($this->getModule($moduleName));
$files = array();
foreach ($modules as $module) {
if ($isResource && file_exists($file = $dir . '/' . $module->getName() . $overridePath)) {
if (null !== $resourceModule) {
throw new \RuntimeException(sprintf('"%s" resource is hidden by a resource from the "%s" derived module. Create a "%s" file to override the module resource.',
$file,
$resourceModule,
$dir . '/' . $modules[0]->getName() . $overridePath
));
}
if ($first) {
return $file;
}
$files[] = $file;
}
if (file_exists($file = $this->getResourcesPath($module) . '/' . $path)) {
if ($first && !$isResource) {
return $file;
}
$files[] = $file;
$resourceModule = $module->getName();
}
}
if (count($files) > 0) {
return $first && $isResource ? $files[0] : $files;
}
throw new \InvalidArgumentException(sprintf('Unable to find file "%s".', $name));
} | Returns the file path for a given resource.
A Resource can be a file or a directory.
The resource name must follow the following pattern:
@<ModuleName>/path/to/a/file.something
where ModuleName is the name of the module
and the remaining part is the relative path in the module.
If $dir is passed, and the first segment of the path is "Resources",
this method will look for a file named:
$dir/<ModuleName>/path/without/Resources
before looking in the module resource folder.
@param string $name A resource name to locate
@param string $dir A directory where to look for the resource first
@param bool $first Whether to return the first path or paths for all matching modules
@throws \InvalidArgumentException if the file cannot be found or the name is not valid
@throws \RuntimeException if the name contains invalid/unsafe
@throws \RuntimeException if a custom resource is hidden by a resource in a derived module
@return string|array The absolute path of the resource or an array if $first is false
@api | entailment |
protected function validate(array $values, $operator)
{
if (!in_array($operator, array('=', '!='))) {
return $this->translation->text('Unsupported operator');
}
if (count($values) != 1) {
return $this->translation->text('@field has invalid value', array(
'@field' => $this->translation->text('Condition')));
}
$scope = filter_var(reset($values), FILTER_VALIDATE_BOOLEAN, FILTER_NULL_ON_FAILURE);
if (!isset($scope)) {
return $this->translation->text('@field has invalid value', array(
'@field' => $this->translation->text('Condition')));
}
return true;
} | Common scope validator
@param array $values
@param string $operator
@return boolean|string | entailment |
public function render($name, array $parameters = array())
{
$engine = $this->getEngine($name);
if (!empty($this->globals)) {
foreach ($this->globals as $key => $val) {
$engine->addGlobal($key, $val);
}
}
// @todo - This only supports addHelper(), which is on PhpEngine, we should allow addExtension() on SmartyEngine and TwigEngine too.
if (!empty($this->helpers) && is_callable(array($engine, 'addHelpers'))) {
$engine->addHelpers($this->helpers);
}
return $engine->render($name, $parameters);
} | Renders a template.
@param mixed $name A template name or a TemplateReferenceInterface
instance
@param array $parameters An array of parameters to pass to the template
@throws \InvalidArgumentException If the template does not exist
@throws \RuntimeException If the template cannot be rendered
@return string The evaluated template as a string
@api | entailment |
public function getMeta($key)
{
$taxonomymeta = $this->taxonomymeta;
$taxonomymeta = $taxonomymeta->keyBy('meta_key');
if(array_has($taxonomymeta, $key . '.meta_value')){
$returnValue = $taxonomymeta[$key]['meta_value'];
return $returnValue;
}
} | Retrieve the meta value of a certain key | entailment |
public static function deserializeObject(array $data)
{
/** @var Bulk $result */
$result = parent::deserializeObject($data);
$result->maxOperations = $data['maxOperations'];
$result->maxPayloadSize = $data['maxPayloadSize'];
return $result;
} | @param array $data
@return Bulk | entailment |
public function set($name, $service, $shared = true)
{
return $this->setService($name, $service, $shared);
} | Register a service with the locator.
This method is an alias to $this->setService().
@param string $name
@param mixed $service
@param bool $shared
@return ServiceManager | entailment |
public function getParameter($name)
{
$config = $this->get('config');
if (!isset($config['parameters'][$name])) {
throw new \InvalidArgumentException(sprintf('You have requested a non-existent parameter "%s".', $name));
}
return $config['parameters'][$name];
} | Gets a parameter.
@param string $name The parameter name
@throws \InvalidArgumentException if the parameter is not defined
@return mixed The parameter value | entailment |
public function setParameter($name, $value)
{
$config = $this->get('config');
$config['parameters'][$name] = $value;
$this->set('config', $config);
} | Sets a parameter.
@param string $name The parameter name
@param mixed $value The parameter value | entailment |
protected function createConfig()
{
$this->setCliMessage('Creating configuration file...');
$config = file_get_contents(GC_FILE_CONFIG);
if (empty($config)) {
$error = $this->translation->text('Failed to read file @path', array('@path' => GC_FILE_CONFIG));
throw new UnexpectedValueException($error);
}
$config .= '$config[\'database\'] = ' . var_export($this->data['database'], true) . ';';
$config .= PHP_EOL . PHP_EOL;
$config .= 'return $config;';
$config .= PHP_EOL;
if (file_put_contents(GC_FILE_CONFIG_COMPILED, $config) === false) {
throw new UnexpectedValueException($this->translation->text('Failed to create config.php'));
}
chmod(GC_FILE_CONFIG_COMPILED, 0444);
} | Create the configuration file using data from a default file
@throws UnexpectedValueException | entailment |
protected function createPages()
{
$this->setCliMessage('Creating pages...');
$pages = array();
$pages[] = array(
'title' => 'Contact us',
'description' => 'Contact information',
);
$pages[] = array(
'title' => 'Help',
'description' => 'Help information. Coming soon...',
);
foreach ($pages as $page) {
$page += array(
'status' => 1,
'user_id' => $this->context['user_id'],
'store_id' => $this->context['store_id']
);
$this->getPageModel()->add($page);
}
} | Creates default pages | entailment |
protected function createLanguages()
{
$this->setCliMessage('Configuring language...');
if (!empty($this->data['store']['language']) && $this->data['store']['language'] !== 'en') {
$this->getLanguageModel()->update($this->data['store']['language'], array('default' => true));
}
} | Creates default languages | entailment |
protected function createSuperadmin()
{
$this->setCliMessage('Creating superadmin...');
$user = array(
'status' => 1,
'name' => 'Superadmin',
'store_id' => $this->context['store_id'],
'email' => $this->data['user']['email'],
'password' => $this->data['user']['password']
);
$user_id = $this->getUserModel()->add($user);
$this->config->set('user_superadmin', $user_id);
$this->setContext('user_id', $user_id);
} | Creates user #1 (super-admin) | entailment |
protected function createStore()
{
$this->setCliMessage('Creating store...');
$default = $this->getStoreModel()->getDefaultData();
$default['title'] = $this->data['store']['title'];
$default['email'] = array($this->data['user']['email']);
$store = array(
'status' => 0,
'data' => $default,
'name' => $this->data['store']['title'],
'domain' => $this->data['store']['host'],
'basepath' => $this->data['store']['basepath']
);
$store_id = $this->getStoreModel()->add($store);
$this->config->set('store', $store_id);
$this->setContext('store_id', $store_id);
} | Creates default store | entailment |
protected function createContent()
{
$this->setCliMessage('Creating content...');
$this->initConfig();
$this->createDbConfig();
$this->createStore();
$this->createSuperadmin();
$this->createCountries();
$this->createLanguages();
$this->createPages();
} | Create default content for the site | entailment |
protected function createDbConfig()
{
$this->setCliMessage('Configuring database...');
$this->config->set('intro', 1);
$this->config->set('installed', GC_TIME);
$this->config->set('cron_key', gplcart_string_random());
$this->config->set('installer', $this->data['installer']);
$this->config->set('timezone', $this->data['store']['timezone']);
} | Create store settings in the database | entailment |
protected function setContext($key, $value)
{
gplcart_array_set($this->context, $key, $value);
$this->session->set("install.context.$key", $value);
} | Sets the current context
@param string $key
@param mixed $value | entailment |
protected function getContext($key)
{
if (GC_CLI) {
return gplcart_array_get($this->context, $key);
}
return $this->session->get("install.context.$key");
} | Returns a value from the current context
@param string $key
@return mixed | entailment |
protected function setContextError($step, $message)
{
$pos = count($this->getContext("errors.$step")) + 1;
$this->setContext("errors.$step.$pos", $message);
} | Sets context error message
@param integer $step
@param string $message | entailment |
protected function getContextErrors($flatten = true)
{
$errors = $this->getContext('errors');
if (empty($errors)) {
return array();
}
if ($flatten) {
return gplcart_array_flatten($errors);
}
return $errors;
} | Returns an array of context errors
@param bool $flatten
@return array | entailment |
protected function createCountries()
{
$rows = $placeholders = array();
foreach ((array) $this->getCountryModel()->getIso() as $code => $country) {
$placeholders[] = '(?,?,?,?,?)';
$native_name = empty($country['native_name']) ? $country['name'] : $country['native_name'];
$rows = array_merge($rows, array(0, $country['name'], $code, $native_name, serialize(array())));
}
$values = implode(',', $placeholders);
$sql = "INSERT INTO country (status, name, code, native_name, format) VALUES $values";
$this->db->run($sql, $rows);
} | Creates countries from ISO list | entailment |
protected function start()
{
set_time_limit(0);
$this->session->delete('user');
$this->session->delete('install');
$this->session->set('install.data', $this->data);
} | Does initial tasks before installation | entailment |
protected function getSuccessMessage()
{
if (GC_CLI) {
$vars = array('@url' => rtrim("{$this->data['store']['host']}/{$this->data['store']['basepath']}", '/'));
return $this->translation->text("Your store has been installed.\nURL: @url\nAdmin area: @url/admin\nGood luck!", $vars);
}
return $this->translation->text('Your store has been installed. Now you can log in as superadmin');
} | Returns success message
@return string | entailment |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.