Example #1
0
 /**
  * Translate label
  *
  * @param string $name Label name
  * @param string $code Language code
  *
  * @return string|void
  */
 public function translate($name, $code)
 {
     if (!isset($this->translations[$code])) {
         $this->translations[$code] = $this->getRepo()->findLabelsByCode($code);
     }
     return \Includes\Utils\ArrayManager::getIndex($this->translations[$code], $name);
 }
Example #2
0
 /**
  * Method to get critical path length for a node
  *
  * @param string $module Module actual name
  *
  * @return integer
  */
 public function getCriticalPath($module)
 {
     if (!isset($this->criticalPaths)) {
         $this->criticalPaths = $this->calculateCriticalPathLengths();
     }
     return \Includes\Utils\ArrayManager::getIndex($this->criticalPaths, $module);
 }
Example #3
0
 /**
  * Return all classes metadata
  *
  * @param string $class Class name OPTIONAL
  *
  * @return array
  */
 public static function getAllMetadata($class = null)
 {
     if (!isset(static::$metadata)) {
         static::$metadata = array();
         // Create hash array to quick access its elements
         foreach (static::getHandler()->getMetadataFactory()->getAllMetadata() as $data) {
             static::$metadata[$data->name] = $data;
         }
     }
     return \Includes\Utils\ArrayManager::getIndex(static::$metadata, $class);
 }
Example #4
0
 /**
  * Return minimum quantity
  *
  * @return integer
  */
 protected function getMinQuantity()
 {
     $minQuantity = $this->getProduct()->getMinQuantity($this->getCart()->getProfile() ? $this->getCart()->getProfile()->getMembership() : null);
     $result = parent::getMinQuantity();
     $minimumQuantity = $minQuantity ? $minQuantity : $result;
     if (!$this->isCartPage()) {
         $items = \XLite\Model\Cart::getInstance()->getItemsByProductId($this->getProduct()->getProductId());
         $quantityInCart = $items ? \Includes\Utils\ArrayManager::sumObjectsArrayFieldValues($items, 'getAmount', true) : 0;
         $result = $minimumQuantity > $quantityInCart ? $minimumQuantity - $quantityInCart : $result;
     } else {
         $result = $minimumQuantity;
     }
     return $result;
 }
 /**
  * Translate array of data received from Paypal to the array for updating cart
  *
  * @param array $paypalData Array of customer data received from Paypal
  *
  * @return array
  */
 public function prepareBuyerData($paypalData)
 {
     $countryCode = \Includes\Utils\ArrayManager::getIndex($paypalData, 'SHIPTOCOUNTRYCODE');
     $country = \XLite\Core\Database::getRepo('XLite\\Model\\Country')->findOneByCode($countryCode);
     $stateCode = \Includes\Utils\ArrayManager::getIndex($paypalData, 'SHIPTOSTATE');
     $state = $country && $stateCode ? \XLite\Core\Database::getRepo('XLite\\Model\\State')->findOneByCountryAndCode($country->getCode(), $stateCode) : null;
     $street = trim(\Includes\Utils\ArrayManager::getIndex($paypalData, 'SHIPTOSTREET') . ' ' . \Includes\Utils\ArrayManager::getIndex($paypalData, 'SHIPTOSTREET2'));
     $data = array('shippingAddress' => array('name' => (string) \Includes\Utils\ArrayManager::getIndex($paypalData, 'SHIPTONAME'), 'street' => $street, 'country' => $country ?: '', 'state' => $state ? $state : (string) \Includes\Utils\ArrayManager::getIndex($paypalData, 'SHIPTOSTATE'), 'city' => (string) \Includes\Utils\ArrayManager::getIndex($paypalData, 'SHIPTOCITY'), 'zipcode' => (string) \Includes\Utils\ArrayManager::getIndex($paypalData, 'SHIPTOZIP'), 'phone' => (string) \Includes\Utils\ArrayManager::getIndex($paypalData, 'PHONENUM')));
     return $data;
 }
Example #6
0
 /**
  * Check if there is enough disk free space.
  * Return message on error
  *
  * @return string
  */
 protected function checkDiskFreeSpace()
 {
     $message = null;
     $totalSize = \Includes\Utils\ArrayManager::sumObjectsArrayFieldValues($this->getEntries(), 'getPackSize');
     $freeSpaceRaw = \Includes\Utils\FileManager::getDiskFreeSpace(LC_DIR_TMP);
     $freeSpace = null !== $freeSpaceRaw ? max(0, $freeSpaceRaw - self::FREE_SPACE_RESERVE) : null;
     if (null !== $freeSpace && $totalSize > $freeSpace) {
         $message = \XLite\Core\Translation::getInstance()->translate('Not enough disk space. Required: {{req}} (+{{reserve}} reserve). Available: {{avail}}', array('req' => \XLite\Core\Converter::formatFileSize($totalSize), 'reserve' => \XLite\Core\Converter::formatFileSize(self::FREE_SPACE_RESERVE), 'avail' => \XLite\Core\Converter::formatFileSize($freeSpace)));
     }
     return $message;
 }
Example #7
0
 /**
  * Find items by variant ID
  *
  * @param integer $variantId Variant ID to use
  *
  * @return array
  */
 public function getItemsByVariantId($variantId)
 {
     $items = $this->getItems();
     return \Includes\Utils\ArrayManager::filter($items, array($this, 'isItemVariantIdEqual'), $variantId);
 }
Example #8
0
 /**
  * Get module metadata (or only the certain field from it)
  *
  * @param string $name Array index
  *
  * @return mixed
  */
 protected function getMetadata($name)
 {
     return \Includes\Utils\ArrayManager::getIndex($this->metadata, $name, true);
 }
Example #9
0
 /**
  * Check if redirect to clean URL is needed
  *
  * @return boolean
  */
 protected function isRedirectToCleanURLNeeded()
 {
     return preg_match('/\\/cart\\.php/Si', \Includes\Utils\ArrayManager::getIndex(\XLite\Core\Request::getInstance()->getServerData(), 'REQUEST_URI'));
 }
Example #10
0
 /**
  * Prepare and save passed data
  *
  * @param array       $data Passed data OPTIONAL
  * @param string|null $name Index in request data array (optional) OPTIONAL
  *
  * @return void
  */
 protected function defineRequestData(array $data = array(), $name = null)
 {
     if (empty($data)) {
         $data = $this->prepareRequestParamsList();
     }
     // FIXME: check if there is the way to avoid this
     $this->formFields = null;
     // TODO: check if there is more convenient way to do this
     $this->requestData = $this->prepareRequestData($data);
     $this->requestData = \Includes\Utils\ArrayManager::filterByKeys($this->requestData, $this->getFormFields(true));
     $this->requestData = $this->prepareRequestDataByFormFields($this->requestData);
 }
Example #11
0
 /**
  * getPageTemplate
  *
  * @return string
  */
 public function getPageTemplate()
 {
     return \Includes\Utils\ArrayManager::getIndex($this->getPageTemplates(), $this->getPage());
 }
Example #12
0
 /**
  * Return info about model field
  *
  * @param string $field Field name
  * @param string $param Data param OPTIONAL
  *
  * @return array|mixed
  */
 public function getFieldInfo($field, $param = null)
 {
     try {
         $result = $this->getClassMetadata()->getFieldMapping($field);
     } catch (\Doctrine\ORM\Mapping\MappingException $exception) {
         $result = $this->getClassMetadata()->getAssociationMapping($field);
     }
     return \Includes\Utils\ArrayManager::getIndex($result, $param, null !== $param);
 }
Example #13
0
 /**
  * Retrive list of files that must be overwritten by request for install upgrades
  *
  * @return array
  */
 protected function getFilesToOverWrite()
 {
     $allFilesPlain = array();
     foreach (\XLite\Upgrade\Cell::getInstance()->getCustomFiles() as $files) {
         $allFilesPlain = array_merge($allFilesPlain, $files);
     }
     return \Includes\Utils\ArrayManager::filterByKeys($allFilesPlain, array_keys((array) \XLite\Core\Request::getInstance()->toRemain), true);
 }
Example #14
0
 /**
  * Get attribute column data
  *
  * @param \XLite\Model\Product   $product   Product object
  * @param \XLite\Model\Attribute $attribute Attribute object
  *
  * @return array
  */
 protected function getAttributeValue($product, $attributeName)
 {
     $value = null;
     $attr = \Includes\Utils\ArrayManager::searchInArraysArray($this->getAttributesColumns(), 'attributeName', $attributeName);
     if ($attr) {
         $entity = \XLite\Core\Database::getRepo('XLite\\Model\\Attribute')->find($attr['attributeId']);
         if ($entity) {
             $value = $entity->getAttributeValue($product, true);
         }
         if ($value && is_array($value)) {
             $value = array_shift($value);
         }
     }
     return $value ?: '';
 }
Example #15
0
 /**
  * Getter method for $this->dbOptions
  *
  * @return array
  */
 protected static function getDbOptions($name = null)
 {
     return \Includes\Utils\ArrayManager::getIndex(static::$dbOptions ?: \Includes\Utils\ConfigParser::getOptions(array('database_details')), $name);
 }
Example #16
0
 /**
  * Get some data for depenendecy in list
  *
  * @param \XLite\Model\Module $module Current module
  *
  * @return string
  */
 protected function getDependencyCSSClass(\XLite\Model\Module $module)
 {
     return \Includes\Utils\ArrayManager::getIndex($this->getDependencyData($module), 'class', true);
 }
Example #17
0
 /**
  * Get the errors which are connected with the membership of the user who placed the order
  *
  * @param \XLite\Model\Order $order
  *
  * @return array
  */
 protected function getMembershipErrors(\XLite\Model\Order $order)
 {
     $found = true;
     $memberships = $this->getMemberships();
     // Memberhsip
     if (0 < count($memberships)) {
         $membership = $order->getProfile() ? $order->getProfile()->getMembership() : null;
         $found = $membership ? \Includes\Utils\ArrayManager::findValue($memberships, array($this, 'checkMembershipId'), $membership->getMembershipId()) : false;
     }
     return $found ? array() : array(static::ERROR_MEMBERSHIP);
 }
Example #18
0
 /**
  * Returns a description of the selected tab. If no tab is selected, returns NULL.
  *
  * @return array
  */
 protected function getSelectedTab()
 {
     return \Includes\Utils\ArrayManager::getIndex($this->getTabs(), $this->getCurrentTarget());
 }
Example #19
0
 /**
  * Return list of registered plugins
  *
  * @param string $hook Hook name OPTIONAL
  *
  * @return array
  */
 protected static function getPlugins($hook = null)
 {
     if (!isset(static::$plugins)) {
         // Check config file
         if (\Includes\Utils\FileManager::isFileReadable(static::getConfigFile())) {
             // Iterate over all sections
             foreach (parse_ini_file(static::getConfigFile(), true) as $section => $plugins) {
                 // Set plugins order
                 asort($plugins, SORT_NUMERIC);
                 // Save plugins list
                 static::$plugins[$section] = array_fill_keys(array_keys($plugins), null);
             }
         } else {
             \Includes\ErrorHandler::fireError('Unable to read config file for the Decorator plugins');
         }
     }
     return \Includes\Utils\ArrayManager::getIndex(static::$plugins, $hook);
 }
Example #20
0
 /**
  * Get specific options list for 'from' and for 'to' lists
  *
  * @param boolean $from Flag: is need to get options for 'from' list
  *
  * @return array
  */
 protected function getSpecificOptions($from = true)
 {
     $options = $this->getOptions();
     $values = $this->getValue();
     $keys = is_array($values) ? $values : array($values);
     $result = \Includes\Utils\ArrayManager::filterByKeys($options, $keys, $from);
     return $result;
 }
Example #21
0
 /**
  * Alias
  *
  * @param array  $data  Data to get field value from
  * @param string $field Name of field to get
  *
  * @return mixed
  */
 protected function getField(array $data, $field)
 {
     return \Includes\Utils\ArrayManager::getIndex($data, $field, true);
 }
Example #22
0
 /**
  * Helper to get object field values
  *
  * @param object  $object   Object to get field value
  * @param string  $field    Field name
  * @param boolean $isGetter Flag OPTIONAL
  *
  * @return mixed
  */
 protected function getObjectField($object, $field, $isGetter = true)
 {
     return \Includes\Utils\ArrayManager::getObjectField($object, $field, $isGetter);
 }
Example #23
0
 /**
  * Get translation codes
  *
  * @return array
  */
 public function getTranslationCodes()
 {
     return \Includes\Utils\ArrayManager::getObjectsArrayFieldValues($this->getTranslations()->toArray(), 'getCode');
 }
Example #24
0
 /**
  * Get session cell by name
  *
  * @param string $name Cell name
  *
  * @return \XLite\Model\SessionCell|void
  */
 protected function getCellByName($name)
 {
     if (!isset($this->cache)) {
         $this->cache = array();
         foreach ((array) static::getSessionCellRepo()->findById($this->getId()) as $cell) {
             $this->cache[$cell->getName()] = $cell;
         }
     }
     return \Includes\Utils\ArrayManager::getIndex($this->cache, $name, true);
 }
Example #25
0
 /**
  * Get row heading
  *
  * @param string $row Row identificator
  *
  * @return array|string
  */
 public function getRowTitle($row)
 {
     return \Includes\Utils\ArrayManager::getIndex($this->getRowTitles(), $row);
 }
Example #26
0
 /**
  * Assign last used payment method
  *
  * @return \XLite\Model\Payment\Transaction|void
  */
 protected function assignLastPaymentMethod()
 {
     $found = null;
     if ($this->isPaymentMethodRequired() && $this->getProfile() && $this->getProfile()->getLastPaymentId()) {
         $paymentMethods = $this->getPaymentMethods();
         $found = \Includes\Utils\ArrayManager::findValue($paymentMethods, array($this, 'checkLastPaymentMethod'), $this->getProfile()->getLastPaymentId());
     }
     return $found ? $this->getFirstOpenPaymentTransaction() : null;
 }
Example #27
0
 /**
  * Check if the language code is in the active languages list
  * If customer language is not used right now, the default customer language code is used
  *
  * @param string $languageCode Language code
  *
  * @return string
  */
 protected function checkForActiveLanguage($languageCode)
 {
     $result = $languageCode;
     $langs = \XLite\Core\Database::getRepo('XLite\\Model\\Language')->findActiveLanguages();
     if (!empty($langs)) {
         $resultModel = \Includes\Utils\ArrayManager::searchInObjectsArray($langs, 'getCode', $result);
         if (null === $resultModel) {
             $result = \XLite\Core\Config::getInstance()->General->default_language;
         }
     }
     return $result;
 }
Example #28
0
 /**
  * Return code for the parsed "<list ... />" tag
  *
  * @param array $attrs All tag attributes
  *
  * @return string
  */
 protected function getListDisplayCode(array $attrs)
 {
     $type = ucfirst(\Includes\Utils\ArrayManager::getIndex($attrs, 'type'));
     $name = \Includes\Utils\ArrayManager::getIndex($attrs, 'name');
     $this->unsetAttributes($attrs, array('type', 'name'));
     $args = '';
     if (!empty($attrs)) {
         $args .= ', ' . $this->getAttributesList($attrs);
     }
     return '$this->display' . $type . 'ViewListContent(' . $this->flexyAttribute($name) . $args . ');';
 }
Example #29
0
 /**
  * Return "locked" amount: items already added to the cart
  *
  * @return integer
  */
 public function getLockedAmount()
 {
     return \Includes\Utils\ArrayManager::sumObjectsArrayFieldValues($this->getLockedItems(), 'getAmount', true);
 }
Example #30
0
 /**
  * processData
  *
  * @param array $data Collected data
  *
  * @return array
  */
 protected function processData($data)
 {
     $stats = $this->stats;
     foreach ($this->stats as $rownum => $periods) {
         foreach ($periods as $period => $val) {
             $stats[$rownum][$period] = is_array($data[$period]) && \Includes\Utils\ArrayManager::getIndex($data[$period], $rownum) ? $data[$period][$rownum][0] : null;
         }
     }
     return $stats;
 }