sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
protected function validateCreatedReview() { $field = 'created'; $value = $this->getSubmitted($field); if (!isset($value)) { $this->unsetSubmitted($field); return null; } $timestamp = strtotime($value); if (empty($timestamp)) { $this->setErrorInvalid($field, $this->translation->text('Created')); return false; } $this->setSubmitted('created', $timestamp); return true; }
Validates a created review date @return boolean|null
entailment
protected function validateEmailReview() { $field = 'email'; $value = $this->getSubmitted($field); if (!isset($value)) { $this->unsetSubmitted($field); return null; } $label = $this->translation->text('Email'); if (empty($value)) { $this->setErrorRequired($field, $label); return false; } $user = $this->user->getByEmail($value); if (empty($user['user_id'])) { $this->setErrorUnavailable($field, $label); return false; } $this->setSubmitted('user_id', $user['user_id']); return true; }
Validates a user E-mail @return boolean|null
entailment
public function configureServiceManager(ServiceManager $serviceManager) { foreach ($this->invokables as $name => $class) { $serviceManager->setInvokableClass($name, $class); } foreach ($this->factories as $name => $factoryClass) { $serviceManager->setFactory($name, $factoryClass); } foreach ($this->abstractFactories as $factoryClass) { $serviceManager->addAbstractFactory($factoryClass); } foreach ($this->aliases as $name => $service) { $serviceManager->setAlias($name, $service); } foreach ($this->shared as $name => $value) { $serviceManager->setShared($name, $value); } $serviceManager->addInitializer(function ($instance) use ($serviceManager) { if ($instance instanceof EventManagerAwareInterface) { if ($instance->getEventManager() instanceof EventManagerInterface) { $instance->getEventManager()->setSharedManager( $serviceManager->get('SharedEventManager') ); } else { $instance->setEventManager($serviceManager->get('EventManager')); } } }); $serviceManager->addInitializer(function ($instance) use ($serviceManager) { if ($instance instanceof ServiceManagerAwareInterface) { $instance->setServiceManager($serviceManager); } }); $serviceManager->addInitializer(function ($instance) use ($serviceManager) { if ($instance instanceof ServiceLocatorAwareInterface) { $instance->setServiceLocator($serviceManager); } }); $serviceManager->setService('ServiceManager', $serviceManager); }
Configure the provided service manager instance with the configuration in this class. In addition to using each of the internal properties to configure the service manager, also adds an initializer to inject ServiceManagerAware and ServiceLocatorAware classes with the service manager. @param ServiceManager $serviceManager
entailment
public function build(array $parameters = array()) { if (!isset($this->config['framework'])) { $this->config['framework'] = array(); } // Core parameters set by PPI\Framework\App $parametersBag = new ParameterBag($parameters); $parametersBag->resolve(); $this->setService('ApplicationParameters', $parametersBag); // Settings provided by the application itself on App boot, config provided by modules is not included $this->setService('ApplicationConfig', $parametersBag->resolveArray($this->config)); if (false === $this->has('Logger')) { $this->setService('Logger', new NullLogger()); } foreach (array( new Config\SessionConfig(), new Config\TemplatingConfig(), ) as $serviceConfig) { $serviceConfig->configureServiceManager($this); } return $this; }
@param array $parameters @return $this
entailment
public function executeCron() { $this->controlAccessExecuteCron(); $this->cron->run(); $this->response->outputHtml($this->text('Cron has started')); }
Processes CRON requests
entailment
protected function controlAccessExecuteCron() { if (strcmp($this->getQuery('key', ''), $this->cron->getKey()) !== 0) { $this->response->outputError403(false); } }
Controls access to execute CRON
entailment
public static function create($name, $type, $description = null) { $result = new static(); $result->name = $name; $result->type = $type; $result->description = $description; return $result; }
@param string $name @param string $type @param string $description @return AttributeBuilder
entailment
public function setReferenceTypes(array $referenceTypes) { $this->referenceTypes = []; foreach ($referenceTypes as $referenceType) { $this->addReferenceType($referenceType); } return $this; }
@param \string[] $referenceTypes @return AttributeBuilder
entailment
public function up() { Schema::create('cms_posts', function (Blueprint $table) { $table->bigIncrements('id'); $table->text('post_title')->nullable(); $table->bigInteger('post_author')->nullable(); $table->longText('post_content')->nullable(); $table->longText('custom')->nullable(); $table->text('post_excerpt')->nullable(); $table->string('post_password')->nullable(); $table->string('post_name')->nullable(); $table->bigInteger('post_parent')->nullable(); $table->string('post_type')->nullable(); $table->integer('menu_order')->nullable(); $table->string('post_mime_type')->nullable(); $table->string('status')->nullable(); $table->string('taxonomy')->nullable()->default('post'); $table->string('template')->nullable(); $table->index(['post_name', 'id']); $table->timestamps(); }); }
Run the migrations. @return void
entailment
public function listField() { $this->actionListField(); $this->setTitleListField(); $this->setBreadcrumbListField(); $this->setFilterListField(); $this->setPagerListField(); $this->setData('fields', $this->getListField()); $this->setData('widget_types', $this->field->getWidgetTypes()); $this->outputListField(); }
Displays the field overview page
entailment
protected function actionListField() { list($selected, $action) = $this->getPostedAction(); $deleted = 0; foreach ($selected as $field_id) { if ($action === 'delete' && $this->access('field_delete')) { $deleted += (int) $this->field->delete($field_id); } } if ($deleted > 0) { $message = $this->text('Deleted %num item(s)', array('%num' => $deleted)); $this->setMessage($message, 'success'); } }
Applies an action to the selected fields
entailment
protected function setPagerListField() { $conditions = $this->query_filter; $conditions['count'] = true; $pager = array( 'query' => $this->query_filter, 'total' => (int) $this->field->getList($conditions) ); return $this->data_limit = $this->setPager($pager); }
Set pager @return array
entailment
protected function getListField() { $conditions = $this->query_filter; $conditions['limit'] = $this->data_limit; return (array) $this->field->getList($conditions); }
Returns an array of fields @return array
entailment
public function editField($field_id = null) { $this->setField($field_id); $this->setTitleEditField(); $this->setBreadcrumbEditField(); $this->setData('field', $this->data_field); $this->setData('types', $this->field->getTypes()); $this->setData('can_delete', $this->canDeleteField()); $this->setData('widget_types', $this->field->getWidgetTypes()); $this->setData('languages', $this->language->getList(array('enabled' => true))); $this->submitEditField(); $this->outputEditField(); }
Displays the field edit form @param integer|null $field_id
entailment
protected function submitEditField() { if ($this->isPosted('delete')) { $this->deleteField(); } else if ($this->isPosted('save') && $this->validateEditField()) { if (isset($this->data_field['field_id'])) { $this->updateField(); } else { $this->addField(); } } }
Handles a submitted field data
entailment
protected function validateEditField() { $this->setSubmitted('field'); $this->setSubmitted('update', $this->data_field); $this->validateComponent('field'); return !$this->hasErrors(); }
Validates an array of submitted field data @return bool
entailment
protected function canDeleteField() { return isset($this->data_field['field_id']) && $this->field->canDelete($this->data_field['field_id']) && $this->access('field_delete'); }
Whether the field can be deleted @return bool
entailment
protected function setField($field_id) { $this->data_field = array(); if (is_numeric($field_id)) { $conditions = array( 'language' => 'und', 'field_id' => $field_id ); $this->data_field = $this->field->get($conditions); if (empty($this->data_field)) { $this->outputHttpStatus(404); } $this->prepareField($this->data_field); } }
Set a field data @param integer $field_id
entailment
protected function deleteField() { $this->controlAccess('field_delete'); if ($this->field->delete($this->data_field['field_id'])) { $this->redirect('admin/content/field', $this->text('Field has been deleted'), 'success'); } $this->redirect('', $this->text('Field has not been deleted'), 'warning'); }
Deletes a field
entailment
protected function updateField() { $this->controlAccess('field_edit'); if ($this->field->update($this->data_field['field_id'], $this->getSubmitted())) { $this->redirect('admin/content/field', $this->text('Field has been updated'), 'success'); } $this->redirect('', $this->text('Field has not been updated'), 'warning'); }
Updates a field
entailment
protected function addField() { $this->controlAccess('field_add'); if ($this->field->add($this->getSubmitted())) { $this->redirect('admin/content/field', $this->text('Field has been added'), 'success'); } $this->redirect('', $this->text('Field has not been added'), 'warning'); }
Adds a new field
entailment
protected function setTitleEditField() { if (isset($this->data_field['field_id'])) { $title = $this->text('Edit %name', array('%name' => $this->data_field['title'])); } else { $title = $this->text('Add field'); } $this->setTitle($title); }
Sets title on the field edit form
entailment
protected function setBreadcrumbEditField() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('admin'), 'text' => $this->text('Dashboard') ); $breadcrumbs[] = array( 'url' => $this->url('admin/content/field'), 'text' => $this->text('Fields') ); $this->setBreadcrumbs($breadcrumbs); }
Sets breadcrumbs on the field edit form
entailment
public function listCurrency() { $this->setTitleListCurrency(); $this->setBreadcrumbListCurrency(); $this->setFilterListCurrency(); $this->setPagerListCurrency(); $this->setData('currencies', (array) $this->getListCurrency()); $this->setData('default_currency', $this->currency->getDefault()); $this->outputListCurrency(); }
Displays the currency overview page
entailment
protected function setPagerListCurrency() { $pager = array( 'query' => $this->query_filter, 'total' => (int) $this->getListCurrency(true) ); return $this->data_limit = $this->setPager($pager); }
Sets pager @return array
entailment
protected function getListCurrency($count = false) { $currencies = $this->currency->getList(); $allowed = $this->getAllowedFiltersCurrency(); $this->filterList($currencies, $allowed, $this->query_filter); $this->sortList($currencies, $allowed, $this->query_filter, array('modified' => 'desc')); if ($count) { return count($currencies); } $this->limitList($currencies, $this->data_limit); return $currencies; }
Returns an array of sorted currencies @param bool $count @return array|int
entailment
public function editCurrency($code = null) { $this->setCurrency($code); $this->setTitleEditCurrency(); $this->setBreadcrumbEditCurrency(); $this->setData('edit', isset($code)); $this->setData('currency', $this->data_currency); $this->setData('can_delete', $this->canDeleteCurrency()); $this->setData('default_currency', $this->currency->getDefault()); $this->submitEditCurrency(); $this->outputEditCurrency(); }
Displays the currency edit form @param string|null $code
entailment
protected function submitEditCurrency() { if ($this->isPosted('delete')) { $this->deleteCurrency(); } else if ($this->isPosted('save') && $this->validateEditCurrency()) { if (isset($this->data_currency['code'])) { $this->updateCurrency(); } else { $this->addCurrency(); } } }
Handles a submitted currency data
entailment
protected function validateEditCurrency() { $this->setSubmitted('currency'); $this->setSubmittedBool('status'); $this->setSubmittedBool('default'); $this->setSubmitted('update', $this->data_currency); $this->validateComponent('currency'); return !$this->hasErrors(); }
Validates a submitted currency data @return boolean
entailment
protected function canDeleteCurrency() { return isset($this->data_currency['code']) && $this->access('currency_delete') && !$this->isPosted() && $this->currency->canDelete($this->data_currency['code']); }
Whether the currency can be deleted @return bool
entailment
protected function setCurrency($code) { $this->data_currency = array(); if (!empty($code)) { $this->data_currency = $this->currency->get($code); if (empty($this->data_currency)) { $this->outputHttpStatus(404); } } }
Set a currency data @param string $code
entailment
protected function deleteCurrency() { $this->controlAccess('currency_delete'); if ($this->currency->delete($this->data_currency['code'])) { $this->redirect('admin/settings/currency', $this->text('Currency has been deleted'), 'success'); } $this->redirect('', $this->text('Currency has not been deleted'), 'warning'); }
Deletes a currency
entailment
protected function updateCurrency() { $this->controlAccess('currency_edit'); if ($this->currency->update($this->data_currency['code'], $this->getSubmitted())) { $this->redirect('admin/settings/currency', $this->text('Currency has been updated'), 'success'); } $this->redirect('', $this->text('Currency has not been updated'), 'warning'); }
Updates a currency
entailment
protected function addCurrency() { $this->controlAccess('currency_add'); if ($this->currency->add($this->getSubmitted())) { $this->redirect('admin/settings/currency', $this->text('Currency has been added'), 'success'); } $this->redirect('', $this->text('Currency has not been added'), 'warning'); }
Adds a new currency
entailment
protected function setTitleEditCurrency() { if (isset($this->data_currency['code'])) { $title = $this->text('Edit %name', array('%name' => $this->data_currency['name'])); } else { $title = $this->text('Add currency'); } $this->setTitle($title); }
Sets titles on the currency edit page
entailment
protected function setBreadcrumbEditCurrency() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('admin'), 'text' => $this->text('Dashboard') ); $breadcrumbs[] = array( 'url' => $this->url('admin/settings/currency'), 'text' => $this->text('Currencies') ); $this->setBreadcrumbs($breadcrumbs); }
Sets breadcrumbs on the currency edit page
entailment
public function castRow($row) { if ($this->isLocked) { // schema is locked, no more inferring is needed return parent::castRow($row); } else { // add the row to the inferrer, update the descriptor according to the best inferred fields $this->fieldsInferer->addRows([$row]); $this->descriptor->fields = []; foreach ($this->fieldsInferer->infer() as $fieldName => $inferredField) { /* @var Fields\BaseField $inferredField */ $this->descriptor->fields[] = $inferredField->descriptor(); } $this->castRows = $this->fieldsInferer->castRows(); return $this->castRows[count($this->castRows) - 1]; } }
@param mixed[] $row @return mixed[] @throws Exceptions\FieldValidationException
entailment
protected function validatePost($request, $post, $validationRules) { $validationRules = $this->validateFieldByConditionalLogic($validationRules, $post, $post); // Lets receive the current items from the post type validation array if(array_key_exists('post_name', $validationRules) && !is_array($validationRules['post_name'])){ $exploded = explode('|', $validationRules['post_name']); $validationRules['post_name'] = []; foreach($exploded as $key => $value){ $validationRules['post_name'][] = $value; } } // Lets validate if a post_name is required. if(!$post->disableDefaultPostName){ // If we are edditing the current existing post, we must remove the unique check if($request->get('post_name') == $post->post_name){ $validationRules['post_name'] = 'required'; // If this is not a existing post name, we need to validate if its unique. They are changing the post name. } else { // Make sure that only the post_name of the requested post_type is unique $validationRules['post_name'][] = 'required'; $validationRules['post_name'][] = Rule::unique('cms_posts')->where(function ($query) use ($post) { return $query->where('post_type', $post->identifier); }); } } return $this->validate($request, $validationRules); }
Validating the creation and change of a post
entailment
public function listCountry() { $this->actionListCountry(); $this->setTitleListCountry(); $this->setBreadcrumbListCountry(); $this->setFilterListCountry(); $this->setPagerlListCountry(); $this->setData('countries', $this->getListCountry()); $this->outputListCountry(); }
Displays the country overview page
entailment
protected function actionListCountry() { list($selected, $action, $value) = $this->getPostedAction(); $updated = $deleted = 0; foreach ($selected as $code) { if ($action === 'status' && $this->access('country_edit')) { $updated += (int) $this->country->update($code, array('status' => $value)); } if ($action === 'delete' && $this->access('country_delete')) { $deleted += (int) $this->country->delete($code); } } 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 countries
entailment
protected function setPagerlListCountry() { $conditions = $this->query_filter; $conditions['count'] = true; $pager = array( 'query' => $this->query_filter, 'total' => (int) $this->country->getList($conditions) ); return $this->data_limit = $this->setPager($pager); }
Set pager @return array
entailment
protected function getListCountry() { $conditions = $this->query_filter; $conditions['limit'] = $this->data_limit; return (array) $this->country->getList($conditions); }
Returns an array of countries @return array
entailment
public function editCountry($code = null) { $this->setCountry($code); $this->setTitleEditCountry(); $this->setBreadcrumbEditCountry(); $this->setData('code', $code); $this->setData('country', $this->data_country); $this->setData('zones', $this->getZonesCountry()); $this->setData('can_delete', $this->canDeleteCountry()); $this->submitEditCountry(); $this->outputEditCountry(); }
Displays the country edit form @param string|null $code
entailment
protected function canDeleteCountry() { return isset($this->data_country['code']) && $this->access('country_delete') && $this->country->canDelete($this->data_country['code']); }
Whether the current country can be deleted @return bool
entailment
protected function setCountry($country_code) { $this->data_country = array(); if (!empty($country_code)) { $this->data_country = $this->country->get($country_code); if (empty($this->data_country)) { $this->outputHttpStatus(404); } } }
Set an array of country data @param string $country_code
entailment
protected function submitEditCountry() { if ($this->isPosted('delete')) { $this->deleteCountry(); } else if ($this->isPosted('save') && $this->validateEditCountry()) { if (isset($this->data_country['code'])) { $this->updateCountry(); } else { $this->addCountry(); } } }
Saves a submitted country data
entailment
protected function validateEditCountry() { $this->setSubmitted('country'); $this->setSubmittedBool('status'); $this->setSubmitted('update', $this->data_country); $this->validateComponent('country'); return !$this->hasErrors(); }
Validates a submitted country data @return bool
entailment
protected function deleteCountry() { $this->controlAccess('country_delete'); if ($this->country->delete($this->data_country['code'])) { $this->redirect('admin/settings/country', $this->text('Country has been deleted'), 'success'); } $this->redirect('', $this->text('Country has not been deleted'), 'warning'); }
Deletes a country
entailment
protected function updateCountry() { $this->controlAccess('country_edit'); if ($this->country->update($this->data_country['code'], $this->getSubmitted())) { $this->redirect('admin/settings/country', $this->text('Country has been updated'), 'success'); } $this->redirect('', $this->text('Country has not been updated'), 'warning'); }
Updates a country
entailment
protected function addCountry() { $this->controlAccess('country_add'); if ($this->country->add($this->getSubmitted())) { $this->redirect('admin/settings/country', $this->text('Country has been added'), 'success'); } $this->redirect('', $this->text('Country has not been added'), 'warning'); }
Adds a new country
entailment
protected function setTitleEditCountry() { if (isset($this->data_country['name'])) { $title = $this->text('Edit %name', array('%name' => $this->data_country['name'])); } else { $title = $this->text('Add country'); } $this->setTitle($title); }
Sets titles on the country edit page
entailment
protected function setBreadcrumbEditCountry() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('admin'), 'text' => $this->text('Dashboard') ); $breadcrumbs[] = array( 'url' => $this->url('admin/settings/country'), 'text' => $this->text('Countries') ); $this->setBreadcrumbs($breadcrumbs); }
Sets breadcrumbs on the country edit page
entailment
public function formatCountry($country_code) { $this->setCountry($country_code); $this->setTitleFormatCountry(); $this->setBreadcrumbFormatCountry(); $this->setData('format', $this->data_country['format']); $this->submitFormatCountry(); $this->outputFormatCountry(); }
Displays address format items for the given country @param string $country_code
entailment
protected function updateFormatCountry() { $format = $this->getSubmitted(); foreach ($format as $id => &$item) { $item['status'] = isset($item['status']); $item['required'] = isset($item['required']); if ($id === 'country') { $item['status'] = 1; $item['required'] = 1; } if ($item['required']) { $item['status'] = 1; } } if ($this->country->update($this->data_country['code'], array('format' => $format))) { $this->redirect('admin/settings/country', $this->text('Country has been updated'), 'success'); } $this->redirect('', $this->text('Country has not been updated'), 'warning'); }
Updates a country format
entailment
protected function setBreadcrumbFormatCountry() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('admin'), 'text' => $this->text('Dashboard') ); $breadcrumbs[] = array( 'url' => $this->url('admin/settings/country'), 'text' => $this->text('Countries') ); $breadcrumbs[] = array( 'url' => $this->url("admin/settings/country/edit/{$this->data_country['code']}"), 'text' => $this->text('Edit %name', array('%name' => $this->data_country['name'])) ); $this->setBreadcrumbs($breadcrumbs); }
Sets breadcrumbs on the country format edit page
entailment
public function createdToAdmin($order) { $store = $this->store->get($order['store_id']); $store_name = $this->store->getTranslation('title', $this->translation->getLangcode(), $store); $options = array('from' => reset($store['data']['email'])); $default = (array) $this->store->getDefault(true); $url = $this->store->getUrl($default); $vars = array( '@store' => $store_name, '@order_id' => $order['order_id'], '@order' => "$url/admin/sale/order/{$order['order_id']}", '@status' => $this->order->getStatusName($order['status']), '@total' => $this->price->format($order['total'], $order['currency']), ); $subject = $this->translation->text('New order #@order_id on @store', $vars); $message = $this->translation->text("Order status: @status\r\nTotal: @total\r\nView: @order", $vars); return array($options['from'], $subject, $message, $options); }
Sends an email to admin after a customer created an order @param array $order @return array
entailment
public function createdToCustomer($order) { $store = $this->store->get($order['store_id']); $url = $this->store->getUrl($store); $user = $this->user->get($order['user_id']); $store_name = $this->store->getTranslation('title', $this->translation->getLangcode(), $store); $options = $this->store->getConfig(null, $store); $options['from'] = reset($store['data']['email']); $vars = array( '@store' => $store_name, '@order_id' => $order['order_id'], '@order' => "$url/account/{$order['user_id']}", '@status' => $this->order->getStatusName($order['status']), ); $subject = $this->translation->text('Order #@order_id on @store', $vars); $message = $this->translation->text("Thank you for ordering on @store\r\n\r\nOrder ID: @order_id\r\nOrder status: @status\r\nView orders: @order", $vars); $message .= $this->getSignature($options); return array($user['email'], $subject, $message, $options); }
Sends an email to a logged in customer after his order has been created @param array $order @return array
entailment
public function add(array $product, array $data) { $result = array(); $this->hook->attach('cart.add.product.before', $product, $data, $result, $this); if (!empty($result)) { return (array) $result; } $data += array( 'quantity' => 1, 'user_id' => $this->cart->getUid(), 'store_id' => $product['store_id'], 'product_id' => $product['product_id'] ); $data['cart_id'] = $this->set($data); if (empty($data['cart_id'])) { return $this->getResultError(); } $result = $this->getResultAdded($data); $this->hook->attach('cart.add.product.after', $product, $data, $result, $this); return (array) $result; }
Adds the product to the cart @param array $product @param array $data @return array
entailment
public function toWishlist($cart_id) { $result = null; $this->hook->attach('cart.move.wishlist.before', $cart_id, $result, $this); if (isset($result)) { return (array) $result; } $cart = $this->cart->get($cart_id); if (empty($cart) || !$this->cart->delete($cart_id)) { return $this->getResultError(); } $result = $this->addToWishlist($cart); gplcart_static_clear(); $this->hook->attach('cart.move.wishlist.after', $data, $result, $this); return (array) $result; }
Moves a cart item to a wishlist @param int $cart_id @return array
entailment
public function delete($cart_id) { $result = array(); $this->hook->attach('cart.delete.item.before', $cart_id, $result, $this); if (!empty($result)) { return (array) $result; } $cart = $this->cart->get($cart_id); if (empty($cart) || !$this->cart->delete($cart_id)) { return $this->getResultError(); } $result = $this->getResultDelete($cart); $this->hook->attach('cart.delete.item.after', $cart_id, $result, $this); return $result; }
Deletes a cart item @param int $cart_id @return array
entailment
public function login(array $user, array $cart) { $result = array(); $this->hook->attach('cart.login.before', $user, $cart, $result, $this); if (!empty($result)) { return (array) $result; } if (!$this->config->get('cart_login_merge', 0)) { $this->cart->delete(array('user_id' => $user['user_id'])); } if (!empty($cart['items'])) { foreach ($cart['items'] as $item) { $this->cart->update($item['cart_id'], array('user_id' => $user['user_id'])); } } $this->cart->deleteCookie(); $result = $this->getResultLogin($user); $this->hook->attach('cart.login.after', $user, $cart, $result, $this); return (array) $result; }
Performs all needed tasks when customer is logging in during checkout @param array $user @param array $cart @return array
entailment
protected function set(array $data, $increment = true) { $options = array( 'order_id' => 0, 'sku' => $data['sku'], 'user_id' => $data['user_id'], 'store_id' => $data['store_id'] ); $list = $this->cart->getList($options); if (empty($list)) { return $this->cart->add($data); } $cart = reset($list); if ($increment) { $data['quantity'] += $cart['quantity']; } $this->cart->update($cart['cart_id'], array('quantity' => $data['quantity'])); return $cart['cart_id']; }
Adds/updates a cart item @param array $data @param bool $increment @return integer
entailment
protected function addToWishlist(array $cart) { $data = array( 'user_id' => $cart['user_id'], 'store_id' => $cart['store_id'], 'product_id' => $cart['product_id'] ); return $this->wishlist_action->add($data); }
Adds a product to the wishlist @param array $cart @return array
entailment
protected function getResultDelete(array $cart) { $options = array( 'user_id' => $cart['user_id'], 'store_id' => $cart['store_id'], ); $content = $this->cart->getContent($options); return array( 'redirect' => '', 'severity' => 'success', 'quantity' => empty($content['quantity']) ? 0 : $content['quantity'], 'message' => $this->translation->text('Product has been deleted from cart') ); }
Returns an array of resulting data after a product has been deleted from a cart @param array $cart @return array
entailment
protected function getResultAdded(array $data) { $options = array( 'user_id' => $data['user_id'], 'store_id' => $data['store_id'] ); $vars = array('@url' => $this->url->get('checkout')); $message = $this->translation->text('Product has been added to your cart. <a href="@url">Checkout</a>', $vars); return array( 'redirect' => '', 'message' => $message, 'severity' => 'success', 'cart_id' => $data['cart_id'], 'quantity' => $this->cart->getQuantity($options, 'total') ); }
Returns an array of resulting data after a product has been added to a cart @param array $data @return array
entailment
public function delete($trigger_id) { $result = null; $this->hook->attach('trigger.delete.before', $trigger_id, $result, $this); if (isset($result)) { return (bool) $result; } $result = (bool) $this->db->delete('triggers', array('trigger_id' => $trigger_id)); $this->hook->attach('trigger.delete.after', $trigger_id, $result, $this); return (bool) $result; }
Deletes a trigger @param integer $trigger_id @return boolean
entailment
public function getTriggered(array $data = array(), array $options = array()) { $options += array('status' => 1); $triggers = (array) $this->getList($options); if (empty($triggers)) { return array(); } $triggered = array(); foreach ($triggers as $trigger) { if ($this->condition->isMet($trigger, $data)) { $triggered[] = $trigger['trigger_id']; } } return $triggered; }
Returns an array of triggered IDs for the given context @param array $data @param array $options @return array
entailment
protected function prepareList(array $list) { foreach ($list as &$item) { if (!empty($item['data']['conditions'])) { gplcart_array_sort($item['data']['conditions']); } } return $list; }
Prepare an array of triggers @param array $list @return array
entailment
protected function submitWishlist($wishlist_action_model) { $this->setSubmitted('product'); $this->filterSubmitted(array('product_id')); if ($this->isPosted('remove_from_wishlist')) { $this->deleteFromWishlist($wishlist_action_model); } else if ($this->isPosted('add_to_wishlist')) { $this->validateAddToWishlist(); $this->addToWishlist($wishlist_action_model); } }
Adds/removes a product from the wishlist @param \gplcart\core\models\WishlistAction $wishlist_action_model
entailment
protected function validateAddToWishlist() { $this->setSubmitted('user_id', $this->getCartUid()); $this->setSubmitted('store_id', $this->getStoreId()); $this->validateComponent('wishlist'); }
Validates adding a submitted product to the wishlist
entailment
public function addToWishlist($wishlist_action_model) { $errors = $this->error(); if (empty($errors)) { $result = $wishlist_action_model->add($this->getSubmitted()); } else { $result = array( 'redirect' => '', 'severity' => 'warning', 'message' => $this->format($errors) ); } if ($this->isAjax()) { $this->outputJson($result); } $this->redirect($result['redirect'], $result['message'], $result['severity']); }
Add a product to the wishlist @param \gplcart\core\models\WishlistAction $wishlist_action_model
entailment
public function deleteFromWishlist($wishlist_action_model) { $product = array( 'user_id' => $this->getCartUid(), 'store_id' => $this->getStoreId(), 'product_id' => $this->getSubmitted('product_id') ); $result = $wishlist_action_model->delete($product); if ($this->isAjax()) { $this->outputJson($result); } $this->redirect($result['redirect'], $result['message'], $result['severity']); }
Deletes a submitted product from the wishlist @param \gplcart\core\models\WishlistAction $wishlist_action_model
entailment
public function boot() { // Register migrations only if its laravel 5.3 or heigher $laravel = app(); $version = $laravel::VERSION; $version = (float) $version; if($version >= 5.3){ $this->loadMigrationsFrom(__DIR__.'/../database/migrations'); } // Register translations $this->loadTranslationsFrom(__DIR__.'/../translations', 'niku-assets'); // Register config $this->publishes([ __DIR__.'/../config/niku-cms.php' => config_path('niku-cms.php'), ], 'niku-config'); // Register the default post types $this->publishes([ __DIR__.'/../PostTypes' => app_path('/Cms/PostTypes'), ], 'niku-posttypes'); $this->publishes([ __DIR__.'/../Mutators' => app_path('/Cms/Mutators'), ], 'niku-posttypes'); $this->publishes([ __DIR__.'/../ConfigTypes' => app_path('/Cms/ConfigTypes'), ], 'niku-posttypes'); }
Bootstrap the application services. @return void
entailment
public function listReview() { $this->actionListReview(); $this->setTitleListReview(); $this->setBreadcrumbListReview(); $this->setFilterListReview(); $this->setPagerListReview(); $this->setData('reviews', $this->getListReview()); $this->outputListReview(); }
Displays the reviews overview page
entailment
protected function setPagerListReview() { $conditions = $this->query_filter; $conditions['count'] = true; $pager = array( 'query' => $this->query_filter, 'total' => (int) $this->review->getList($conditions) ); return $this->data_limit = $this->setPager($pager); }
Sets pager @return array
entailment
protected function getListReview() { $conditions = $this->query_filter; $conditions['limit'] = $this->data_limit; return (array) $this->review->getList($conditions); }
Returns an array of reviews @return array
entailment
public function editReview($review_id = null) { $this->setReview($review_id); $this->setTitleEditReview(); $this->setBreadcrumbEditReview(); $this->setData('review', $this->data_review); $this->submitEditReview(); $this->setDataUserEditReview(); $this->setDataProductEditReview(); $this->outputEditReview(); }
Displays the review edit form @param integer|null $review_id
entailment
protected function setReview($review_id) { $this->data_review = array(); if (is_numeric($review_id)) { $this->data_review = $this->review->get($review_id); if (empty($this->data_review)) { $this->outputHttpStatus(404); } } }
Set a review data @param integer $review_id
entailment
protected function submitEditReview() { if ($this->isPosted('delete')) { $this->deleteReview(); } else if ($this->isPosted('save') && $this->validateEditReview()) { if (isset($this->data_review['review_id'])) { $this->updateReview(); } else { $this->addReview(); } } }
Handles a submitted review
entailment
protected function validateEditReview() { $this->setSubmitted('review'); $this->setSubmittedBool('status'); $this->setSubmitted('update', $this->data_review); $this->validateComponent('review'); return !$this->hasErrors(); }
Validates a submitted review @return bool
entailment
protected function deleteReview() { $this->controlAccess('review_delete'); if ($this->review->delete($this->data_review['review_id'])) { $this->redirect('admin/content/review', $this->text('Review has been deleted'), 'success'); } $this->redirect('', $this->text('Review has not been deleted'), 'warning'); }
Deletes a review
entailment
protected function updateReview() { $this->controlAccess('review_edit'); if ($this->review->update($this->data_review['review_id'], $this->getSubmitted())) { $this->redirect('admin/content/review', $this->text('Review has been updated'), 'success'); } $this->redirect('', $this->text('Review has not been updated'), 'warning'); }
Updates a review
entailment
protected function addReview() { $this->controlAccess('review_add'); if ($this->review->add($this->getSubmitted())) { $this->redirect('admin/content/review', $this->text('Review has been added'), 'success'); } $this->redirect('', $this->text('Review has not been added'), 'warning'); }
Adds a new review
entailment
protected function setDataUserEditReview() { $user = $this->user->get($this->getData('review.user_id')); if (isset($user['email'])) { $this->setData('review.email', $user['email']); } }
Set user template data
entailment
protected function setDataProductEditReview() { $product_id = $this->getData('review.product_id'); $products = array(); if (!empty($product_id)) { $product = $this->product->get($product_id); $options = array( 'entity' => 'product', 'entity_id' => $product_id, 'template_item' => 'backend|content/product/suggestion' ); $this->setItemThumb($product, $this->image, $options); $this->setItemPriceFormatted($product, $this->price); $this->setItemRendered($product, array('item' => $product), $options); $products = array($product); } $widget = array( 'multiple' => false, 'products' => $products, 'name' => 'review[product_id]', 'error' => $this->error('product_id') ); $this->setData('product_picker', $this->getWidgetProductPicker($widget)); }
Set product template data
entailment
protected function setTitleEditReview() { if (isset($this->data_review['review_id'])) { $title = $this->text('Edit %name', array('%name' => $this->text('Review'))); } else { $title = $this->text('Add review'); } $this->setTitle($title); }
Sets title on the edit review page
entailment
protected function setBreadcrumbEditReview() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('admin'), 'text' => $this->text('Dashboard') ); $breadcrumbs[] = array( 'text' => $this->text('Reviews'), 'url' => $this->url('admin/content/review') ); $this->setBreadcrumbs($breadcrumbs); }
Sets breadcrumbs on the edit review page
entailment
public function zoneId(array $condition, array $data, $key) { if (isset($data['data']['order'][$key])) { return $this->checkZoneIdByAddressId($condition, $data, $key); } return $this->checkZoneIdByAddressData($condition, $data); }
Whether the zone ID condition is met @param array $condition @param array $data @param string $key @return boolean
entailment
public function countryCode(array $condition, array $data, $key) { // Check form fields if (!empty($data['data']['address']['country'])) { $country = $data['data']['address']['country']; return $this->compare($country, $condition['value'], $condition['operator']); } if (empty($data['data']['order'][$key])) { return false; } $address = $this->address->get($data['data']['order'][$key]); if (empty($address['country'])) { return false; } return $this->compare($address['country'], $condition['value'], $condition['operator']); }
Whether the country condition is met @param array $condition @param array $data @param string $key @return boolean
entailment
public function stateId(array $condition, array $data, $key) { // Check form fields if (isset($data['data']['address']['state_id'])) { $state_id = $data['data']['address']['state_id']; return $this->compare($state_id, $condition['value'], $condition['operator']); } if (!isset($data['data']['order'][$key])) { return false; } $address = $this->address->get($data['data']['order'][$key]); if (empty($address['state_id'])) { return false; } return $this->compare($address['state_id'], $condition['value'], $condition['operator']); }
Whether the state ID condition is met @param array $condition @param array $data @param string $key @return boolean
entailment
protected function checkZoneIdByAddressId($condition, $data, $key) { $address = $this->address->get($data['data']['order'][$key]); if (empty($address)) { return false; } $fields = array('country_zone_id', 'state_zone_id', 'city_zone_id'); $ids = array(); foreach ($fields as $field) { $ids[] = $address[$field]; } return $this->compare($ids, $condition['value'], $condition['operator']); }
Whether the state ID condition is met using an existing address @param array $condition @param array $data @param string $key @return boolean
entailment
protected function checkZoneIdByAddressData($condition, $data) { if (empty($data['data']['order']['address'])) { return false; } $ids = $this->getAddressZoneId($data['data']['order']['address']); return $this->compare($ids, $condition['value'], $condition['operator']); }
Whether the state ID condition is met using form fields @param array $condition @param array $data @return boolean
entailment
protected function getAddressZoneId(array $address) { $result = array(); foreach (array('state_id', 'city_id', 'country') as $field) { if (empty($address[$field])) { continue; } if ($field === 'city_id') { $data = $this->city->get($address[$field]); } else if ($field === 'state_id') { $data = $this->state->get($address[$field]); } else if ($field === 'country') { $data = $this->country->get($address[$field]); } if (!empty($data['zone_id'])) { $result[] = $data['zone_id']; } } return $result; }
Returns an array of zone IDs from address components @param array $address @return array
entailment
public function setRule($rule, $replacement) { if (is_array($rule)) { $this->rules = $rule; return $this; } $this->rules[$rule] = $replacement; return $this; }
Adds a rule @param string|array $rule A single RegExp pattern or array of rules @param string $replacement A replacement HTML string or callable method @return $this
entailment
public function render($text) { $text = trim(str_replace(array("\r\n", "\r"), "\n", $text), "\n"); foreach ($this->rules as $regex => $replacement) { if (is_callable($replacement)) { $text = preg_replace_callback($regex, $replacement, $text); } else { $text = preg_replace($regex, $replacement, $text); } } return trim($text); }
Renders Markdown text into HTML @param string $text @return string
entailment
protected static function p(array $matches) { $line = $matches[1]; $trimmed = trim($line); if (preg_match('/^<\/?(ul|ol|li|h|p|bl)/', $trimmed)) { return "\n$line\n"; } return sprintf("\n<p>%s</p>\n", $trimmed); }
Renders "P" tag @param array $matches @return string
entailment
protected static function h(array $matches) { $level = strlen($matches[1]); return sprintf('<h%d>%s</h%d>', $level, trim($matches[2]), $level); }
Renders "H" tag @param array $matches @return string
entailment
public static function deserializeObject(array $data) { /** @var ResourceType $result */ $result = self::deserializeCommonAttributes($data); $result->name = $data['name']; $result->description = $data['description']; $result->endpoint = $data['endpoint']; $result->schema = $data['schema']; if (isset($data['schemaExtensions'])) { $result->schemaExtensions = []; foreach ($data['schemaExtensions'] as $schemaExtension) { $result->schemaExtensions[$schemaExtension['schema']] = $schemaExtension['required']; } } return $result; }
@param array $data @return ResourceType
entailment
public function getThumb(array $data, array $options) { $options += array( 'placeholder' => true, 'imagestyle' => $this->config->get('image_style', 3)); if (empty($options['entity_id'])) { return empty($options['placeholder']) ? '' : $this->getPlaceholder($options['imagestyle']); } $conditions = array( 'entity' => $options['entity'], 'entity_id' => $options['entity_id'] ); foreach ($this->getList($conditions) as $file) { if (isset($data[$options['entity'] . '_id']) && $file['entity_id'] == $data[$options['entity'] . '_id']) { return $this->getUrl($file['path'], $options['imagestyle']); } } return empty($options['placeholder']) ? '' : $this->getPlaceholder($options['imagestyle']); }
Returns a string containing a thumbnail image URL @param array $data @param array $options @return string
entailment
public function delete($file_id) { if (empty($file_id)) { return false; } $deleted = $count = 0; foreach ((array) $this->file->getList(array('file_id' => $file_id)) as $file) { $deleted += (int) $this->file->delete($file['file_id']); $count++; } return $count && $count == $deleted; }
Delete images by file ID(s) @param int|array $file_id @return bool
entailment