sentence1
stringlengths
52
3.87M
sentence2
stringlengths
1
47.2k
label
stringclasses
1 value
protected function setDataRatingEditReview() { $options = array( 'product' => $this->data_product, 'review' => $this->getData('review'), 'unvote' => $this->config('rating_unvote', 1) ); $this->setData('rating', $this->render('common/rating/edit', $options)); }
Sets rating widget
entailment
protected function validateEditReview() { $this->setSubmitted('review'); $this->filterSubmitted(array('text', 'rating')); $this->setSubmitted('user_id', $this->uid); $this->setSubmitted('update', $this->data_review); $this->setSubmitted('product_id', $this->data_product['product_id']); $this->setSubmitted('status', (int) $this->config('review_status', 1)); $this->validateComponent('review'); return !$this->hasErrors(false); }
Validates an array of submitted review data @return bool
entailment
protected function updateReview() { $submitted = $this->getSubmitted(); if ($this->review->update($this->data_review['review_id'], $submitted)) { $message = $this->text('Review has been updated'); if (empty($submitted['status'])) { $message = $this->text('Review has been updated and will be published after approval'); } $this->redirect("product/{$this->data_product['product_id']}", $message, 'success'); } $this->redirect("product/{$this->data_product['product_id']}"); }
Updates a submitted review
entailment
protected function addReview() { $submitted = $this->getSubmitted(); $added = $this->review->add($submitted); if (empty($added)) { $message = $this->text('Review has not been added'); $this->redirect('', $message, 'warning'); } $message = $this->text('Review has been added'); if (empty($submitted['status'])) { $message = $this->text('Review has been added and will be published after approval'); } $this->redirect("product/{$this->data_product['product_id']}", $message, 'success'); }
Adds a submitted review
entailment
protected function deleteReview() { if (!$this->canDeleteReview()) { $message = $this->text('Unable to delete'); $this->redirect("product/{$this->data_product['product_id']}", $message, 'warning'); } if ($this->review->delete($this->data_review['review_id'])) { $message = $this->text('Review has been deleted'); $this->redirect("product/{$this->data_product['product_id']}", $message, 'success'); } }
Deletes a review
entailment
protected function controlAccessEditReview() { if (!$this->config('review_enabled', 1) || empty($this->uid)) { $this->outputHttpStatus(403); } if (!$this->config('review_editable', 1)) { $this->outputHttpStatus(403); } if (isset($this->data_review['review_id']) && $this->data_review['user_id'] != $this->uid) { $this->outputHttpStatus(403); } }
Controls access to the edit review page
entailment
protected function prepareReview(array &$review) { $rating = $this->rating->getByUser($this->data_product['product_id'], $this->uid); $review['rating'] = isset($rating['rating']) ? $rating['rating'] : 0; }
Prepares an array of review data @param array $review
entailment
protected function prepareProductReview(array &$product) { $this->setItemImages($product, 'product', $this->image); $this->setItemThumbProduct($product, $this->image); $this->setItemPriceCalculated($product, $this->product); $this->setItemPriceFormatted($product, $this->price, $this->current_currency); }
Prepares an array of product data @param array $product
entailment
public function getLoader() { if (null === $this->loader) { $locator = new FileLocator($this->paths); $resolver = new LoaderResolver(array( new YamlFileLoader($locator), new PhpFileLoader($locator), new IniFileLoader($locator), new ArrayLoader(), )); $this->loader = new DelegatingLoader($resolver); } return $this->loader; }
Returns a loader to handle config loading. @return DelegatingLoader The loader
entailment
public function getList(array $options = array()) { $methods = &gplcart_static(gplcart_array_hash(array('payment.methods' => $options))); if (isset($methods)) { return $methods; } $methods = $this->getDefaultList(); $this->hook->attach('payment.methods', $methods, $this); $weights = array(); foreach ($methods as $id => &$method) { $method['id'] = $id; if (!isset($method['weight'])) { $method['weight'] = 0; } if (!empty($options['status']) && empty($method['status'])) { unset($methods[$id]); continue; } if (!empty($options['module']) && (empty($method['module']) || !in_array($method['module'], (array) $options['module']))) { unset($methods[$id]); continue; } $weights[] = $method['weight']; } if (empty($methods)) { return array(); } // Sort by weight then by key array_multisort($weights, SORT_ASC, array_keys($methods), SORT_ASC, $methods); return $methods; }
Returns an array of payment methods @param array $options @return array
entailment
public function get($method_id) { $methods = $this->getList(); return empty($methods[$method_id]) ? array() : $methods[$method_id]; }
Returns a payment method @param string $method_id @return array
entailment
public function setAlias(array $data, $alias_model, $entity, $delete_existing = true) { if ((empty($data['form']) && empty($data['alias'])) || empty($data[$entity . '_id'])) { return null; } if ($delete_existing) { $alias_model->delete(array('entity' => $entity, 'entity_id' => $data[$entity . '_id'])); } if (empty($data['alias'])) { $data['alias'] = $alias_model->generateEntity($entity, $data); } if (empty($data['alias'])) { return null; } $alias = array( 'alias' => $data['alias'], 'entity' => $entity, 'entity_id' => $data[$entity . '_id'] ); return $alias_model->add($alias); }
Deletes and/or adds an alias @param array $data @param \gplcart\core\models\Alias $alias_model @param string $entity @param boolean $delete_existing @return mixed
entailment
public function enable($module_id) { try { $result = $this->canEnable($module_id); } catch (Exception $ex) { $result = $ex->getMessage(); } $this->hook->attach("module.enable.before|$module_id", $result, $this); if ($result !== true) { return $result; } $this->module->update($module_id, array('status' => 1)); $this->setOverrideConfig(); $this->hook->attach("module.enable.after|$module_id", $result, $this); return $result; }
Enables a module @param string $module_id @return boolean|string
entailment
public function disable($module_id) { try { $result = $this->canDisable($module_id); } catch (Exception $ex) { $result = $ex->getMessage(); } $this->hook->attach("module.disable.before|$module_id", $result, $this); if ($result !== true) { return $result; } if ($this->module->isInstalled($module_id)) { $this->module->update($module_id, array('status' => false)); } else { $this->module->add(array('status' => false, 'module_id' => $module_id)); } $this->setOverrideConfig(); $this->hook->attach("module.disable.after|$module_id", $result, $this); return $result; }
Disables a module @param string $module_id @return boolean|string
entailment
public function install($module_id, $status = true) { gplcart_static_clear(); try { $result = $this->canInstall($module_id); } catch (Exception $ex) { $result = $ex->getMessage(); } $this->hook->attach("module.install.before|$module_id", $result, $this); if ($result !== true) { $this->module->delete($module_id); return $result; } $this->module->add(array('module_id' => $module_id, 'status' => $status)); $this->setOverrideConfig(); $this->hook->attach("module.install.after|$module_id", $result, $this); return $result; }
Install a module @param string $module_id @param boolean $status @return mixed
entailment
public function uninstall($module_id) { try { $result = $this->canUninstall($module_id); } catch (Exception $ex) { $result = $ex->getMessage(); } $this->hook->attach("module.uninstall.before|$module_id", $result, $this); if ($result !== true) { return $result; } $this->module->delete($module_id); $this->setOverrideConfig(); $this->hook->attach("module.uninstall.after|$module_id", $result, $this); return $result; }
Un-install a module @param string $module_id @return mixed
entailment
public function canEnable($module_id) { if ($this->module->isEnabled($module_id)) { throw new UnexpectedValueException($this->translation->text('Module already installed and enabled')); } if ($this->module->isLocked($module_id)) { throw new UnexpectedValueException($this->translation->text('Module is locked in code')); } if ($this->module->isInstaller($module_id)) { $error = $this->translation->text('Modules with "installer" type cannot be installed/enabled when system is already set up'); throw new UnexpectedValueException($error); } $this->module->getInstance($module_id); // Test module class return $this->checkRequirements($module_id); }
Whether a given module can be enabled @param string $module_id @return mixed @throws UnexpectedValueException
entailment
public function canInstall($module_id) { if ($this->module->isInstalled($module_id)) { throw new UnexpectedValueException($this->translation->text('Module already installed')); } if ($this->module->isLocked($module_id)) { throw new UnexpectedValueException($this->translation->text('Module is locked in code')); } if ($this->module->isInstaller($module_id)) { $error = $this->translation->text('Modules with "installer" type cannot be installed/enabled when system is already set up'); throw new UnexpectedValueException($error); } $this->module->getInstance($module_id); // Test module class return $this->checkRequirements($module_id); }
Whether a given module can be installed (and enabled) @param string $module_id @return mixed @throws UnexpectedValueException
entailment
public function canUninstall($module_id) { if ($this->module->isActiveTheme($module_id)) { $error = $this->translation->text('Modules with "theme" type and active status cannot be disabled/uninstalled'); throw new UnexpectedValueException($error); } if ($this->module->isLocked($module_id)) { throw new UnexpectedValueException($this->translation->text('Module is locked in code')); } return $this->checkDependentModules($module_id, $this->module->getList()); }
Whether a given module can be un-installed @param string $module_id @return bool @throws UnexpectedValueException
entailment
public function checkRequirements($module_id) { $this->checkModuleId($module_id); $module = $this->module->getInfo($module_id); $this->checkCore($module); $this->checkPhpVersion($module); if ($this->module->isInstaller($module_id)) { $error = $this->translation->text('Modules with "installer" type cannot be installed/enabled when system is already set up'); throw new UnexpectedValueException($error); } $this->checkDependenciesExtensions($module); $this->checkDependenciesModule($module_id); return true; }
Checks all requirements for the module @param string $module_id @return bool @throws UnexpectedValueException
entailment
public function checkDependenciesExtensions(array $module) { if (!empty($module['extensions'])) { $missing = array(); foreach ($module['extensions'] as $extension) { if (!extension_loaded($extension)) { $missing[] = $extension; } } if (!empty($missing)) { $error = $this->translation->text("Missing PHP extensions: @list", array('@list' => implode(',', $missing))); throw new UnexpectedValueException($error); } } return true; }
Check if all required extensions (if any) are loaded @param array $module @return bool @throws UnexpectedValueException
entailment
public function checkPhpVersion(array $module) { if (!empty($module['php'])) { $components = $this->getVersionComponents($module['php']); if (empty($components)) { throw new UnexpectedValueException($this->translation->text('Failed to read PHP version')); } list($operator, $number) = $components; if (!version_compare(PHP_VERSION, $number, $operator)) { $error = $this->translation->text('Requires incompatible version of @name', array('@name' => 'PHP')); throw new UnexpectedValueException($error); } } return true; }
Checks PHP version compatibility for the module ID @param array $module @return boolean @throws UnexpectedValueException
entailment
public function checkModuleId($module_id) { if (!$this->module->isValidId($module_id)) { throw new UnexpectedValueException($this->translation->text('Invalid module ID')); } return true; }
Checks a module ID @param string $module_id @return boolean @throws UnexpectedValueException
entailment
public function checkCore(array $module) { if (!isset($module['core'])) { throw new OutOfBoundsException($this->translation->text('Missing core version')); } if (version_compare(gplcart_version(), $module['core']) < 0) { throw new UnexpectedValueException($this->translation->text('Module incompatible with the current system core version')); } return true; }
Checks core version requirements @param array $module @return boolean @throws OutOfBoundsException @throws UnexpectedValueException
entailment
public function checkDependentModules($module_id, array $modules) { unset($modules[$module_id]); $required_by = array(); foreach ($modules as $info) { if (empty($info['dependencies'])) { continue; } foreach (array_keys($info['dependencies']) as $dependency) { if ($dependency === $module_id && !empty($info['status'])) { $required_by[] = $info['name']; } } } if (empty($required_by)) { return true; } throw new UnexpectedValueException($this->translation->text('Required by') . ': ' . implode(', ', $required_by)); }
Checks dependent modules @param string $module_id @param array $modules @return bool @throws UnexpectedValueException
entailment
public function getOverrideMap() { gplcart_static_clear(); $map = array(); foreach ($this->module->getEnabled() as $module) { $directory = GC_DIR_MODULE . "/{$module['id']}/override/classes"; if (!is_readable($directory)) { continue; } foreach ($this->scanOverrideFiles($directory) as $file) { $original = str_replace('/', '\\', str_replace($directory . '/', '', preg_replace('/Override$/', '', $file))); $override = str_replace('/', '\\', str_replace(GC_DIR_SYSTEM . '/', '', $file)); $map["gplcart\\$original"][$module['id']] = "gplcart\\$override"; } } return $map; }
Returns an array of class name spaces to be overridden @return array
entailment
protected function checkDependenciesModule($module_id) { $modules = $this->module->getList(); $validated = $this->validateDependencies($modules, true); if (empty($validated[$module_id]['errors'])) { return true; } $messages = array(); foreach ($validated[$module_id]['errors'] as $error) { list($text, $arguments) = $error; $messages[] = $this->translation->text($text, $arguments); } throw new UnexpectedValueException(implode('<br>', $messages)); }
Checks module dependencies @param string $module_id @return boolean @throws UnexpectedValueException
entailment
protected function scanOverrideFiles($directory, array &$results = array()) { foreach (new DirectoryIterator($directory) as $file) { if ($file->isFile() && $file->getExtension() === 'php') { $results[] = $file->getFilename(); } elseif ($file->isDir() && !$file->isDot()) { $this->scanOverrideFiles($file->getRealPath(), $results); } } return $results; }
Recursively scans module override files @param string $directory @param array $results @return array
entailment
public function listAccountAddress($user_id) { $this->setUserAccountAddress($user_id); $this->actionAccountAddress(); $this->setTitleListAccountAddress(); $this->setBreadcrumbListAccountAddress(); $this->setData('user', $this->data_user); $this->setData('addresses', $this->getListAccountAddress()); $this->outputListAccountAddress(); }
Displays the address overview page @param integer $user_id
entailment
protected function getListAccountAddress() { $addresses = $this->address->getTranslatedList($this->data_user['user_id']); return $this->prepareListAccountAddress($addresses); }
Returns an array of addresses @return array
entailment
protected function prepareListAccountAddress(array $addresses) { $prepared = array(); foreach ($addresses as $address_id => $items) { $prepared[$address_id]['items'] = $items; $prepared[$address_id]['locked'] = !$this->address->canDelete($address_id); } return $prepared; }
Prepares an array of user addresses @param array $addresses @return array
entailment
protected function actionAccountAddress() { $key = 'delete'; $this->controlToken($key); $address_id = $this->getQuery($key); if (!empty($address_id)) { if ($this->address->delete($address_id)) { $this->redirect('', $this->text('Address has been deleted'), 'success'); } $this->redirect('', $this->text('Address has not been deleted'), 'warning'); } }
Handles various actions
entailment
protected function setBreadcrumbListAccountAddress() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('/'), 'text' => $this->text('Shop') ); $breadcrumbs[] = array( 'text' => $this->text('Account'), 'url' => $this->url("account/{$this->data_user['user_id']}") ); $this->setBreadcrumbs($breadcrumbs); }
Sets breadcrumbs on the address overview page
entailment
public static function popBeforeSmtp( $host, $port = false, $tval = false, $username = '', $password = '', $debug_level = 0 ) { $pop = new POP3; return $pop->authorise($host, $port, $tval, $username, $password, $debug_level); }
Simple static wrapper for all-in-one POP before SMTP @param $host @param boolean $port @param boolean $tval @param string $username @param string $password @param integer $debug_level @return boolean
entailment
private function setError($error) { $this->errors[] = $error; if ($this->do_debug >= 1) { echo '<pre>'; foreach ($this->errors as $error) { print_r($error); } echo '</pre>'; } }
Add an error to the internal error store. Also display debug output if it's enabled. @param $error
entailment
private function catchWarning($errno, $errstr, $errfile, $errline) { $this->setError(array( 'error' => "Connecting to the POP3 server raised a PHP warning: ", 'errno' => $errno, 'errstr' => $errstr, 'errfile' => $errfile, 'errline' => $errline )); }
POP3 connection error handler. @param integer $errno @param string $errstr @param string $errfile @param integer $errline @access private
entailment
public function read($length) { if (! $this->resource || ! $this->isReadable()) { return false; } if ($this->eof()) { return ''; } return fread($this->resource, $length); }
Read data from the stream. @param int $length Read up to $length bytes from the object and return them. Fewer than $length bytes may be returned if underlying stream call returns fewer bytes. @return string|false Returns the data read from the stream; in the event of an error or inability to read, can return boolean false.
entailment
public function getMetadata($key = null) { if (null === $key) { return stream_get_meta_data($this->resource); } $metadata = stream_get_meta_data($this->resource); if (! array_key_exists($key, $metadata)) { return; } return $metadata[$key]; }
Retrieve metadata from the underlying stream. @see http://php.net/stream_get_meta_data for a description of the expected output. @return array
entailment
public function route(array $condition) { if (!in_array($condition['operator'], array('=', '!='))) { return false; } $route = $this->route->get(); return $this->compare($route['pattern'], $condition['value'], $condition['operator']); }
Returns true if route condition is met @param array $condition @return boolean
entailment
public function path(array $condition) { if (!in_array($condition['operator'], array('=', '!='))) { return false; } $path = $this->url->path(); $found = false; foreach ((array) $condition['value'] as $pattern) { if (gplcart_path_match($path, $pattern)) { $found = true; } } return $condition['operator'] === '=' ? $found : !$found; }
Returns true if path condition is met @param array $condition @return boolean
entailment
public function add(array $data) { $result = null; $this->hook->attach('file.add.before', $data, $result, $this); if (isset($result)) { return (int) $result; } if (empty($data['mime_type'])) { $data['mime_type'] = mime_content_type(gplcart_file_absolute($data['path'])); } if (empty($data['file_type'])) { $data['file_type'] = strtolower(strtok($data['mime_type'], '/')); } if (empty($data['title'])) { $data['title'] = basename($data['path']); } $data['created'] = $data['modified'] = GC_TIME; $result = $data['file_id'] = $this->db->insert('file', $data); $this->setTranslations($data, $this->translation_entity, 'file', false); $this->hook->attach('file.add.after', $data, $result, $this); return (int) $result; }
Adds a file to the database @param array $data @return integer
entailment
public function delete($condition, $check = true) { $result = null; $this->hook->attach('file.delete.before', $condition, $check, $result, $this); if (isset($result)) { return (bool) $result; } if (!is_array($condition)) { $condition = array('file_id' => $condition); } if ($check && isset($condition['file_id']) && !$this->canDelete($condition['file_id'])) { return false; } $result = (bool) $this->db->delete('file', $condition); if ($result && isset($condition['file_id'])) { $this->deleteLinked($condition['file_id']); } $this->hook->attach('file.delete.after', $condition, $check, $result, $this); return (bool) $result; }
Deletes a file from the database @param int|array $condition @param bool $check @return boolean
entailment
public function deleteFromDisk($file) { if (!is_array($file)) { $file = $this->get($file); } $result = null; $this->hook->attach('file.delete.disk.before', $file, $result, $this); if (isset($result)) { return (bool) $result; } if (empty($file['path'])) { return false; } $path = gplcart_file_absolute($file['path']); if (!is_file($path)) { return false; } $result = unlink($path); $this->hook->attach('file.delete.disk.after', $file, $result, $this); return $result; }
Deletes a file from disk @param array|int $file @return boolean
entailment
public function deleteAll($file, &$db = 0, &$disk = 0, $check = true) { if (!is_array($file)) { $file = $this->get($file); } if (!isset($file['file_id'])) { return false; } if (!$this->delete($file['file_id'], $check)) { return false; } $db++; if (!$this->deleteFromDisk($file)) { return false; } $disk++; return true; }
Deletes a file both from database and disk @param int|array $file @param int $db @param int $disk @param bool $check @return bool
entailment
public function canDelete($file_id) { $sql = 'SELECT NOT EXISTS (SELECT file_id FROM product_sku WHERE file_id=:id)'; return (bool) $this->db->fetchColumn($sql, array('id' => (int) $file_id)); }
Whether the file can be deleted @param integer $file_id @return boolean
entailment
public function supportedExtensions($dot = false) { $extensions = array(); foreach ($this->getHandlers() as $handler) { if (!empty($handler['extensions'])) { $extensions += array_merge($extensions, (array) $handler['extensions']); } } $extensions = array_unique($extensions); if ($dot) { $extensions = array_map(function ($value) { return ".$value"; }, $extensions); } return $extensions; }
Returns an array of all supported file extensions @param boolean $dot @return array
entailment
public function getHandler($name) { $handlers = $this->getHandlers(); if (strpos($name, '.') !== 0) { return isset($handlers[$name]) ? $handlers[$name] : array(); } $extension = ltrim($name, '.'); foreach ($handlers as $handler) { if (empty($handler['extensions'])) { continue; } foreach ((array) $handler['extensions'] as $allowed_extension) { if ($extension === $allowed_extension) { return $handler; } } } return array(); }
Returns a handler data @param string $name @return array
entailment
protected function validateCastValue($val) { if (isset($this->descriptor()->bareNumber) && $this->descriptor()->bareNumber === false) { return mb_ereg_replace('((^\D*)|(\D*$))', '', $val); } elseif (!is_numeric($val)) { throw $this->getValidationException('value must be numeric', $val); } else { $intVal = (int) $val; if ($intVal != (float) $val) { throw $this->getValidationException('value must be an integer', $val); } else { return $intVal; } } }
@param mixed $val @return int @throws \frictionlessdata\tableschema\Exceptions\FieldValidationException;
entailment
public function init(Request $request, $postType, $id) { // Lets validate if the post type exists and if so, continue. $postTypeModel = $this->getPostType($postType); if(!$postTypeModel){ $errorMessages = 'You are not authorized to do this.'; return $this->abort($errorMessages); } if(method_exists($postTypeModel, 'override_delete_post')){ return $postTypeModel->override_delete_post($id, $request); } // Check if the post type has a identifier if(empty($postTypeModel->identifier)){ $errorMessages = 'The post type does not have a identifier.'; if(array_has($postTypeModel->errorMessages, 'post_type_identifier_does_not_exist')){ $errorMessages = $postTypeModel->errorMessages['post_type_identifier_does_not_exist']; } return $this->abort($errorMessages); } $post = $this->findPostInstance($postTypeModel, $request, $postType, $id, 'delete_post'); if(!$post){ $errorMessages = 'Post does not exist.'; if(array_has($postTypeModel->errorMessages, 'post_does_not_exist')){ $errorMessages = $postTypeModel->errorMessages['post_does_not_exist']; } return $this->abort($errorMessages); } if($postTypeModel->disableDelete){ $errorMessages = 'The post type does not support deleting.'; if(array_has($postTypeModel->errorMessages, 'post_type_identifier_does_not_support_deleting')){ $errorMessages = $postTypeModel->errorMessages['post_type_identifier_does_not_support_deleting']; } return $this->abort($errorMessages); } if(method_exists($postTypeModel, 'on_delete_check')){ $onCheck = $postTypeModel->on_delete_check($postTypeModel, $post->id, []); if($onCheck['continue'] === false){ $errorMessages = 'You are not authorized to do this.'; if(array_key_exists('message', $onCheck)){ $errorMessages = $onCheck['message']; } return $this->abort($errorMessages); } } // Delete the post $post->delete(); // Lets fire events as registered in the post type $this->triggerEvent('on_delete_event', $postTypeModel, $post->id, []); $successMessage = 'Post succesfully deleted.'; if(array_has($postTypeModel->successMessage, 'post_deleted')){ $successMessage = $postTypeModel->successMessage['post_deleted']; } if(method_exists($postTypeModel, 'override_delete_response')){ return $postTypeModel->override_delete_response($post, $request); } // Return the response return response()->json([ 'code' => 'success', 'message' => $successMessage, 'post' => [ 'id' => $post->id, 'post_title' => $post->post_title, 'post_name' => $post->post_name, 'status' => $post->status, 'post_type' => $post->post_type, 'created_at' => $post->created_at, 'updated_at' => $post->updated_at, ], ], 200); }
Delete a single post
entailment
protected function validateData() { $field = 'data'; if ($this->isExcluded($field)) { return null; } $value = $this->getSubmitted($field); if (!isset($value)) { $this->unsetSubmitted($field); return null; } if (!is_array($value)) { $this->setErrorInvalid($field, $this->translation->text('Data')); return false; } return true; }
Validates "data" field @return bool|null
entailment
protected function validateMetaTitle() { $field = 'meta_title'; $value = $this->getSubmitted($field); if (!isset($value)) { $this->unsetSubmitted($field); return true; } if (mb_strlen($value) > 60) { $this->setErrorLengthRange($field, $this->translation->text('Meta title'), 0, 60); return false; } return true; }
Validates a meta title @return boolean
entailment
protected function validateBool($field) { $value = $this->getSubmitted($field); if (!isset($value)) { $this->unsetSubmitted($field); return null; } $this->setSubmitted($field, (int) filter_var($value, FILTER_VALIDATE_BOOLEAN)); return true; }
Convert different values into boolean @param mixed $field @return bool|null
entailment
protected function validateTranslation() { $translations = $this->getSubmitted('translation'); if (empty($translations)) { return null; } $lengths = array( 'meta_title' => 60, 'meta_description' => 160 ); foreach ($translations as $lang => $translation) { foreach ($translation as $field => $value) { if ($value === '') { unset($translations[$lang][$field]); continue; } $max = isset($lengths[$field]) ? $lengths[$field] : 255; if (mb_strlen($value) > $max) { $label = ucfirst(str_replace('_', ' ', $field)); $this->setErrorLengthRange("translation.$lang.$field", $label, 0, $max); } } if (empty($translations[$lang])) { unset($translations[$lang]); } } $this->setSubmitted('translation', $translations); return !$this->isError('translation'); }
Validates category translations @return boolean|null
entailment
protected function validateImages() { $field = 'images'; $images = $this->getSubmitted($field); if (empty($images) || !is_array($images)) { $this->unsetSubmitted($field); return null; } foreach ($images as &$image) { if (isset($image['title'])) { $image['title'] = mb_strimwidth($image['title'], 0, 255, ''); } if (isset($image['description'])) { $image['description'] = mb_strimwidth($image['description'], 0, 255, ''); } if (empty($image['translation'])) { continue; } foreach ($image['translation'] as $lang => &$translation) { foreach ($translation as $key => &$value) { if ($value === '') { unset($image['translation'][$lang][$key]); continue; } $value = mb_strimwidth($value, 0, 255, ''); } if (empty($image['translation'][$lang])) { unset($image['translation'][$lang]); continue; } } } $this->setSubmitted($field, $images); return true; }
Validates / prepares an array of submitted images @return null|bool
entailment
protected function validateUploadImages($entity) { $files = $this->request->file('files'); if (empty($files['name'][0])) { return null; } $directory = $this->config->get("{$entity}_image_dirname", $entity); $results = $this->file_transfer->uploadMultiple($files, 'image', "image/upload/$directory"); foreach ($results['transferred'] as $key => $path) { $this->setSubmitted("images.$key.path", $path); } if (!empty($results['errors'])) { $this->setError('images', implode('<br>', (array) $results['errors'])); return false; } return true; }
Validates uploaded images @param string $entity @return bool|null
entailment
protected function validateAlias() { $field = 'alias'; $value = $this->getSubmitted($field); if (empty($value)) { $this->unsetSubmitted($field); return null; } $label = $this->translation->text('Alias'); if (mb_strlen($value) > 255) { $this->setErrorLengthRange($field, $label, 0, 255); return false; } if (preg_match('/^[A-Za-z0-9_.-]+$/', $value) !== 1) { $this->setErrorInvalid($field, $label); return false; } $updating = $this->getUpdating(); if (isset($updating['alias']) && $updating['alias'] === $value) { return true; // Do not check own alias on update } if ($this->alias->exists($value)) { $this->setErrorExists($field, $label); return false; } return true; }
Validates an alias @return boolean|null
entailment
protected function validateEmail() { $field = 'email'; if ($this->isExcluded($field)) { return null; } $value = $this->getSubmitted($field); if ($this->isUpdating() && !isset($value)) { $this->unsetSubmitted($field); return null; } $label = $this->translation->text('E-mail'); if (empty($value)) { $this->setErrorRequired($field, $label); return false; } if (!filter_var($value, FILTER_VALIDATE_EMAIL)) { $this->setErrorInvalid($field, $label); return false; } return true; }
Validates an E-mail @return boolean
entailment
public function addData(Serializing $event) { if ($event->isSerializer(ForumSerializer::class) && $event->actor->isAdmin()) { $event->attributes['datitisev-dashboard.data'] = [ 'postCount' => Post::where('type', 'comment')->count(), 'discussionCount' => Discussion::count(), 'userCount' => User::where('is_email_confirmed', 1)->count(), ]; } }
Adds settings to admin settings. @param Serializing $event
entailment
public function listReportStatus() { $this->setTitleListReportStatus(); $this->setBreadcrumbListReportStatus(); $this->setData('statuses', $this->getReportStatus()); $this->outputListReportStatus(); }
Displays the status page
entailment
public function getVolume(array $order, array &$cart) { $result = null; $this->hook->attach('order.volume.get.before', $order, $cart, $result, $this); if (isset($result)) { return (float) $result; } $total = 0.0; foreach ($cart['items'] as &$item) { $this->sumTotalVolume($total, $item, $order); } $result = round($total, 2); $this->hook->attach('order.volume.get.after', $order, $cart, $result, $this); return (float) $result; }
Returns a total volume of all products in the order @param array $order @param array $cart @return float|null
entailment
public function getWeight(array $order, array &$cart) { $result = null; $this->hook->attach('order.weight.get.before', $order, $cart, $result, $this); if (isset($result)) { return (float) $result; } $total = 0.0; foreach ($cart['items'] as &$item) { $this->sumTotalWeight($total, $item, $order); } $result = round($total, 2); $this->hook->attach('order.weight.get.after', $order, $cart, $result, $this); return (float) $result; }
Returns a total weight of all products in the order @param array $order @param array $cart @return float|null
entailment
protected function sumTotalVolume(&$total, array &$item, array $order) { $product = &$item['product']; if (empty($product['width']) || empty($product['height']) || empty($product['length'])) { return null; } if ($product['size_unit'] !== $order['size_unit']) { try { $product['width'] = $this->convertor->convert($product['width'], $product['size_unit'], $order['size_unit']); $product['height'] = $this->convertor->convert($product['height'], $product['size_unit'], $order['size_unit']); $product['length'] = $this->convertor->convert($product['length'], $product['size_unit'], $order['size_unit']); } catch (Exception $ex) { return null; } $product['size_unit'] = $order['size_unit']; } $volume = (float) ($product['width'] * $product['height'] * $product['length']); $total += (float) ($volume * $item['quantity']); return null; }
Sum volume totals @param float $total @param array $item @param array $order @return null
entailment
protected function sumTotalWeight(&$total, array &$item, array $order) { $product = &$item['product']; if ($product['weight_unit'] !== $order['weight_unit']) { try { $product['weight'] = $this->convertor->convert($product['weight'], $product['weight_unit'], $order['weight_unit']); } catch (Exception $ex) { return null; } $product['weight_unit'] = $order['weight_unit']; } $total += (float) ($product['weight'] * $item['quantity']); return null; }
Sum weight totals @param float $total @param array $item @param array $order @return null
entailment
public function createService(ServiceLocatorInterface $serviceLocator) { $routeCollection = new RouteCollection(); $requestContext = $serviceLocator->get('RouterRequestContext'); $routerOptions = array(); $logger = $serviceLocator->has('logger') ? $serviceLocator->get('Logger') : null; $router = new Router($requestContext, $routeCollection, $routerOptions, $logger); // @todo - consider making a base router class, and then have a ModuleRouterFactory to pull module routes // @todo - find a way to set routes on this after we instantiate this factory // @todo - let you add new routes on demand and call $router->setRouteCollection() return $router; }
Create and return the router. @param ServiceLocatorInterface $serviceLocator @return \PPI\Framework\Router\Router
entailment
public function getModulesPath() { $paths = $this->locator->getModulesPath(); foreach (array_keys($paths) as $module) { $paths[$module] .= DIRECTORY_SEPARATOR . TemplateReference::MODULE_VIEWS_DIRECTORY; } return $paths; }
Returns an array of paths to modules views dir. @return array An array of paths to each loaded module
entailment
public function listProductClass() { $this->actionListProductClass(); $this->setTitleListProductClass(); $this->setBreadcrumbListProductClass(); $this->setFilterListProductClass(); $this->setPagerListProductClass(); $this->setData('product_classes', $this->getListProductClass()); $this->outputListProductClass(); }
Returns the product class overview page
entailment
public function setPagerListProductClass() { $conditions = $this->query_filter; $conditions['count'] = true; $pager = array( 'query' => $this->query_filter, 'total' => (int) $this->product_class->getList($conditions) ); return $this->data_limit = $this->setPager($pager); }
Set pager on the product class overview page @return array
entailment
protected function getListProductClass() { $conditions = $this->query_filter; $conditions['limit'] = $this->data_limit; return (array) $this->product_class->getList($conditions); }
Returns an array of product classes @return array
entailment
public function editProductClass($product_class_id = null) { $this->setProductClass($product_class_id); $this->setTitleEditProductClass(); $this->setBreadcrumbEditProductClass(); $this->setData('can_delete', $this->canDeleteProductClass()); $this->setData('product_class', $this->data_product_class); $this->submitEditProductClass(); $this->outputEditProductClass(); }
Route callback for the edit product class page @param null|integer $product_class_id
entailment
protected function canDeleteProductClass() { return isset($this->data_product_class['product_class_id']) && $this->access('product_class_delete') && $this->product_class->canDelete($this->data_product_class['product_class_id']); }
Whether a product class can be deleted @return bool
entailment
protected function submitEditProductClass() { if ($this->isPosted('delete') && $this->canDeleteProductClass()) { $this->deleteProductClass(); } else if ($this->isPosted('save') && $this->validateEditProductClass()) { if (isset($this->data_product_class['product_class_id'])) { $this->updateProductClass(); } else { $this->addProductClass(); } } }
Handles a submitted product class
entailment
protected function validateEditProductClass() { $this->setSubmitted('product_class'); $this->setSubmittedBool('status'); $this->setSubmitted('update', $this->data_product_class); $this->validateComponent('product_class'); return !$this->hasErrors(); }
Validates a products class data @return bool
entailment
protected function deleteProductClass() { $this->controlAccess('product_class_delete'); if ($this->product_class->delete($this->data_product_class['product_class_id'])) { $this->redirect('admin/content/product-class', $this->text('Product class has been deleted'), 'success'); } $this->redirect('', $this->text('Product class has not been deleted'), 'warning'); }
Deletes a product class
entailment
protected function updateProductClass() { $this->controlAccess('product_class_edit'); if ($this->product_class->update($this->data_product_class['product_class_id'], $this->getSubmitted())) { $this->redirect('admin/content/product-class', $this->text('Product class has been updated'), 'success'); } $this->redirect('', $this->text('Product class has not been updated'), 'warning'); }
Updates a product class
entailment
protected function addProductClass() { $this->controlAccess('product_class_add'); if ($this->product_class->add($this->getSubmitted())) { $this->redirect('admin/content/product-class', $this->text('Product class has been added'), 'success'); } $this->redirect('', $this->text('Product class has not been added'), 'warning'); }
Adds a new product class
entailment
protected function setTitleEditProductClass() { if (isset($this->data_product_class['product_class_id'])) { $title = $this->text('Edit %name', array('%name' => $this->data_product_class['title'])); } else { $title = $this->text('Add product class'); } $this->setTitle($title); }
Sets title on the edit product class page
entailment
protected function setBreadcrumbEditProductClass() { $breadcrumbs = array(); $breadcrumbs[] = array( 'url' => $this->url('admin'), 'text' => $this->text('Dashboard') ); $breadcrumbs[] = array( 'text' => $this->text('Product classes'), 'url' => $this->url('admin/content/product-class') ); $this->setBreadcrumbs($breadcrumbs); }
Sets breadcrumbs on the edit product class page
entailment
public function get($order_id) { $result = null; $this->hook->attach('order.get.before', $order_id, $result, $this); if (isset($result)) { return $result; } $conditions = array( 'limit' => array(0, 1), 'order_id' => $order_id ); $list = (array) $this->getList($conditions); $result = empty($list) ? array() : reset($list); $this->setCart($result); $this->hook->attach('order.get.after', $order_id, $result, $this); return $result; }
Loads an order from the database @param integer $order_id @return array
entailment
public function add(array $order) { $result = null; $this->hook->attach('order.add.before', $order, $result, $this); if (isset($result)) { return (int) $result; } unset($order['order_id']); // In case the order is cloning $order['created'] = $order['modified'] = GC_TIME; $order += array('status' => $this->getDefaultStatus()); $this->prepareComponents($order); $result = $this->db->insert('orders', $order); $this->hook->attach('order.add.after', $order, $result, $this); return (int) $result; }
Adds an order @param array $order @return integer
entailment
public function update($order_id, array $data) { $result = null; $this->hook->attach('order.update.before', $order_id, $data, $result, $this); if (isset($result)) { return (bool) $result; } $data['modified'] = GC_TIME; $this->prepareComponents($data); $result = (bool) $this->db->update('orders', $data, array('order_id' => $order_id)); $this->hook->attach('order.update.after', $order_id, $data, $result, $this); return (bool) $result; }
Updates an order @param integer $order_id @param array $data @return boolean
entailment
public function delete($order_id) { $result = null; $this->hook->attach('order.delete.before', $order_id, $result, $this); if (isset($result)) { return (bool) $result; } $result = (bool) $this->db->delete('orders', array('order_id' => $order_id)); if ($result) { $this->deleteLinked($order_id); } $this->hook->attach('order.delete.after', $order_id, $result, $this); return (bool) $result; }
Deletes an order @param integer $order_id @return boolean
entailment
public function getStatuses() { $statuses = &gplcart_static('order.statuses'); if (isset($statuses)) { return $statuses; } $statuses = array( 'pending' => $this->translation->text('Pending'), 'canceled' => $this->translation->text('Canceled'), 'delivered' => $this->translation->text('Delivered'), 'completed' => $this->translation->text('Completed'), 'processing' => $this->translation->text('Processing'), 'dispatched' => $this->translation->text('Dispatched'), 'pending_payment' => $this->translation->text('Awaiting payment') ); $this->hook->attach('order.statuses', $statuses, $this); return $statuses; }
Returns an array of order statuses @return array
entailment
public function getStatusName($id) { $statuses = $this->getStatuses(); return isset($statuses[$id]) ? $statuses[$id] : ''; }
Returns a status name @param string $id @return string
entailment
public function getComponentTypes() { $types = array( 'cart' => $this->translation->text('Cart'), 'payment' => $this->translation->text('Payment'), 'shipping' => $this->translation->text('Shipping') ); $this->hook->attach('order.component.types', $types); return $types; }
Returns an array of order component types @return array
entailment
public function getComponentType($name) { $types = $this->getComponentTypes(); return empty($types[$name]) ? '' : $types[$name]; }
Returns a component type name @param string $name @return string
entailment
public function calculate(array &$data) { $result = array(); $this->hook->attach('order.calculate.before', $data, $result, $this); if (!empty($result)) { return (array) $result; } $components = array(); $total = $data['cart']['total']; $this->calculateComponents($total, $data, $components); $this->calculatePriceRules($total, $data, $components); $result = array( 'total' => $total, 'components' => $components, 'currency' => $data['cart']['currency'], 'total_decimal' => $this->price->decimal($total, $data['cart']['currency']), 'total_formatted' => $this->price->format($total, $data['cart']['currency']), 'total_formatted_number' => $this->price->format($total, $data['cart']['currency'], true, false), ); $this->hook->attach('order.calculate.after', $data, $result, $this); return (array) $result; }
Calculates order totals @param array $data @return array
entailment
public function getCompleteMessage(array $order) { $vars = array( '@num' => $order['order_id'], '@status' => $this->getStatusName($order['status']) ); if (is_numeric($order['user_id'])) { $message = $this->translation->text('Thank you for your order! Order ID: @num, status: @status', $vars); } else { $message = $this->translation->text('Thank you for your order! Order ID: @num, status: @status', $vars); } $this->hook->attach('order.complete.message', $message, $order, $this); return $message; }
Returns the checkout complete message @param array $order @return string
entailment
protected function calculateComponents(&$total, array &$data, array &$components) { foreach (array('shipping', 'payment') as $type) { if (isset($data['order'][$type]) && isset($data[$type . '_methods'][$data['order'][$type]]['price'])) { $price = $data[$type . '_methods'][$data['order'][$type]]['price']; $components[$type] = array('price' => $price); $total += $components[$type]['price']; } } }
Calculate order components (e.g shipping) using predefined values which can be provided by modules @param int $total @param array $data @param array $components
entailment
protected function calculatePriceRules(&$total, array &$data, array &$components) { $options = array( 'status' => 1, 'store_id' => $data['order']['store_id'] ); $code = null; if (isset($data['order']['data']['pricerule_code'])) { $code = $data['order']['data']['pricerule_code']; } foreach ($this->price_rule->getTriggered($data, $options) as $price_rule) { if ($price_rule['code'] !== '' && !isset($code)) { $components[$price_rule['price_rule_id']] = array('rule' => $price_rule, 'price' => 0); continue; } if (isset($code) && !$this->priceRuleCodeMatches($price_rule['price_rule_id'], $code)) { $components[$price_rule['price_rule_id']] = array('rule' => $price_rule, 'price' => 0); continue; } $this->price_rule->calculate($total, $data, $components, $price_rule); } }
Calculate order price rules @param int $total @param array $data @param array $components
entailment
protected function deleteLinked($order_id) { $this->db->delete('cart', array('order_id' => $order_id)); $this->db->delete('order_log', array('order_id' => $order_id)); $this->db->delete('history', array('entity' => 'order', 'entity_id' => $order_id)); }
Deletes all database records related to the order ID @param int $order_id
entailment
protected function prepareComponents(array &$order) { if (!empty($order['cart']['items'])) { foreach ($order['cart']['items'] as $sku => $item) { $price = isset($item['total']) ? $item['total'] : null; $order['data']['components']['cart']['items'][$sku]['price'] = $price; } } }
Prepares order components @param array $order
entailment
protected function deleteLinked($page_id) { $this->db->delete('page_translation', array('page_id' => $page_id)); $this->db->delete('file', array('entity' => 'page', 'entity_id' => $page_id)); $this->db->delete('alias', array('entity' => 'page', 'entity_id' => $page_id)); $sql = 'DELETE ci FROM collection_item ci INNER JOIN collection c ON(ci.collection_id = c.collection_id) WHERE c.type = ? AND ci.entity_id = ?'; $this->db->run($sql, array('page', $page_id)); }
Deletes all database records related to the page ID @param int $page_id
entailment
public function getMeta($key) { $postmeta = $this->postmeta; $postmeta = $postmeta->keyBy('meta_key'); if(array_has($postmeta, $key . '.meta_value')){ $returnValue = $postmeta[$key]['meta_value']; return $returnValue; } }
Retrieve the meta value of a certain key
entailment
public function createService(ServiceLocatorInterface $serviceLocator) { if (!$serviceLocator->has('ServiceListener')) { $serviceLocator->setFactory('ServiceListener', 'PPI\Framework\ServiceManager\Factory\ServiceListenerFactory'); } $config = $serviceLocator->get('ApplicationConfig'); $defaultListeners = $serviceLocator->get('ModuleDefaultListener'); $serviceListener = $serviceLocator->get('ServiceListener'); $serviceListener->addServiceManager( $serviceLocator, 'service_manager', 'Zend\ModuleManager\Feature\ServiceProviderInterface', 'getServiceConfig' ); $serviceListener->addServiceManager( 'RoutePluginManager', 'route_manager', 'Zend\ModuleManager\Feature\RouteProviderInterface', 'getRouteConfig' ); $modules = isset($config['modules']) ? $config['modules'] : array(); $events = $serviceLocator->get('EventManager'); $events->attach($defaultListeners); $events->attach($serviceListener); $moduleEvent = new ModuleEvent(); $moduleEvent->setParam('ServiceManager', $serviceLocator); $moduleManager = new ModuleManager($modules, $events); $moduleManager->setEvent($moduleEvent); return $moduleManager; }
Creates and returns the module manager. Instantiates the default module listeners, providing them configuration from the "module_listener_options" key of the ApplicationConfig service. Also sets the default config glob path. Module manager is instantiated and provided with an EventManager, to which the default listener aggregate is attached. The ModuleEvent is also created and attached to the module manager. @param ServiceLocatorInterface $serviceLocator @return ModuleManager
entailment
public function id(array $condition) { $user_id = $this->user->getId(); return $this->compare($user_id, $condition['value'], $condition['operator']); }
Whether the user ID condition is met @param array $condition @return boolean
entailment
public function roleId(array $condition) { $role_id = $this->user->getRoleId(); return $this->compare($role_id, $condition['value'], $condition['operator']); }
Whether the user role condition is met @param array $condition @return boolean
entailment
public function getPath() { $controller = str_replace('\\', '/', $this->get('controller')); $path = (empty($controller) ? '' : $controller . '/') . $this->get('name') . '.' . $this->get('format') . '.' . $this->get('engine'); return empty($this->parameters['module']) ? self::APP_VIEWS_DIRECTORY . '/' . $path : '@' . $this->get('module') . '/' . self::MODULE_VIEWS_DIRECTORY . '/' . $path; }
Returns the path to the template - as a path when the template is not part of a module - as a resource when the template is part of a module. @return string A path to the template or a resource
entailment
public function getLogicalName() { return sprintf('%s:%s:%s.%s.%s', $this->parameters['module'], $this->parameters['controller'], $this->parameters['name'], $this->parameters['format'], $this->parameters['engine']); }
{@inheritdoc}
entailment
public function imageStyle(array &$submitted, array $options = array()) { $this->options = $options; $this->submitted = &$submitted; $this->validateImageStyle(); $this->validateName(); $this->validateBool('status'); $this->validateActionsImageStyle(); $this->unsetSubmitted('update'); return $this->getResult(); }
Performs full image style data validation @param array $submitted @param array $options @return boolean|array
entailment
protected function validateImageStyle() { $id = $this->getUpdatingId(); if ($id === false) { return null; } $data = $this->image_style->get($id); if (empty($data)) { $this->setErrorUnavailable('update', $this->translation->text('Image style')); return false; } $this->setSubmitted('update', $data); return true; }
Validates an image style to be updated @return boolean|null
entailment