/** * Apply style to particular image. * * @static * @access public * @param string $sStyleName * @since 1.0.0, 2014-07-13 * @version 1.1.0, 2014-07-15 */ public function apply($sStyleName) { if (static::$aImageStyles === NULL) { static::$aImageStyles = \Plethora\Config::get('image_styles'); } $aStyles = \Plethora\Helper\Arrays::get(static::$aImageStyles, $sStyleName); if ($aStyles === NULL) { throw new \Plethora\Exception\Fatal('Image style "' . $sStyleName . '" do not exists.'); } $oImage = $this->getImage(); $oImageFile = $oImage->getImageFileObject(); $sStyledImagePath = 'uploads/image_styles/' . $sStyleName . '/' . $oImageFile->getName() . '.' . $oImageFile->getExt(); if (!file_exists($sStyledImagePath)) { foreach ($aStyles as $aStyle) { $oImage = call_user_func_array(array($oImage, $aStyle[0]), $aStyle[1]); } $oImage->save($sStyledImagePath); } return $sStyledImagePath; }
echo $amount; ?> </p> <?php } ?> </td> </tr> <tr> <td><?php echo __('Translations per application part'); ?> :</td> <td> <?php $amountPerPart = Helper\Arrays::get($info, 'amount_per_part', []); ?> <?php //dd($amountPerPart) ?> <?php foreach ($amountPerPart as $part => $data) { ?> <?php $type = NULL; switch ($part) { case 'fw': $type = 'Plethora'; break; case 'app': $type = __('Application');
/** * Check if particular uploaded file has valid extension. * * @static * @access public * @param ModelCore\FileBroker $fileBroker $_FILE like array * @param array $exts Extensions list * @return boolean|string * @since 1.0.0-alpha * @version 1.0.0-alpha */ public static function allowedExt(ModelCore\FileBroker $fileBroker, array $exts) { if (is_null($fileBroker)) { return TRUE; } $value = $fileBroker->getTempData(); if (!isset($value['tmp_name'])) { return TRUE; } $mimeType = Helper\MimeTypes::getMimeType($value['tmp_name']); $extByMime = Helper\MimeTypes::getExtByType($mimeType); $value['type'] = $mimeType; if (!$extByMime || !Helper\Arrays::anyInArray($exts, $extByMime)) { return __('File with wrong format uploaded! Allowed types of files: :exts.', ['exts' => implode(', ', $exts)]); } return TRUE; }
/** * @access private * @param string $sField * @return SearchEngine\RelFieldInfo|FALSE * @since 1.0.0-alpha * @version 1.0.0-alpha */ private function getRelFieldInfo($sField = NULL) { return $sField === NULL ? $this->aRelatedFieldsList : Arrays::get($this->aRelatedFieldsList, $sField, FALSE); }
/** * Method is called by Form object when this particular form is used (sent). * * @access protected * @return void * @since 1.0.0-alpha * @version 1.0.0-alpha */ protected function whenFormSubmitted() { $this->aFormMethodValues = $this->getFormObject()->getMethodValue(); if ($this->getFormObject()->isFieldsNameWithPrefix()) { $mSentData = Helper\Arrays::path($this->aFormMethodValues, $this->getFormObject()->getName() . '.' . $this->getName(), FALSE); } else { $mSentData = Helper\Arrays::get($this->aFormMethodValues, $this->getName(), FALSE); } if ($mSentData === FALSE) { foreach ($this->getLangs() as $lang) { $this->setValue([], 0, $lang); } } }
/** * Get all loaded local actions. * * @static * @access public * @param string $sForRoute * @return array * @since 1.0.0-alpha * @version 1.0.0-alpha */ public static function getLocalActions($sForRoute) { return Helper\Arrays::get(static::$aLocalActions, $sForRoute, []); }
/** * Create next level of menu. * * @access private * @param array $aRoutes * @return View * @since 1.2.0-dev * @version 1.2.0-dev */ private function createNextLevel(array $aRoutes) { $aEntries = []; $this->iLevel++; foreach ($aRoutes as $aRoute) { /* @var $aRoute array */ $oItem = $aRoute['object']; /* @var $oItem \Model\Menu\Item */ $oItemLocales = $oItem->getLocales(); /* @var $oItemLocales \Model\Menu\Item\Locales */ $sRouteTitle = $oItemLocales->getName(); /* @var $sRouteTitle string */ $sRouteName = $oItem->getRoute(); /* @var $sRouteName string */ $aRouteParams = $oItem->getRouteParams() !== NULL ? $oItem->getRouteParams() : []; /* @var $aRouteParams array */ $aAttributes = Arrays::get($aRoute, 'parameters', []); /* @var $aSiblings array */ $aSiblings = Arrays::get($aRoute, 'siblings', []); /* @var $aSiblings array */ $sClasses = $oItem->getClasses(); /* @var $sClasses string */ $oSiblings = NULL; $oRoute = Route::factory($sRouteName); $aParamsTypes = array_keys($oRoute->getParameterTypes()); $aParams = array_combine($aParamsTypes, $aRouteParams); $sPath = $oRoute->path($aParams); if (!isset($aAttributes['class'])) { $aAttributes['class'] = ''; } $aAttributes['class'] = trim($sClasses . ' ' . $aAttributes['class'] . ' ' . Arrays::get($aRoute, 'classes', '')); $oSingleLevel = View::factory('menu/model/single_level')->set('sRouteTitle', $sRouteTitle)->set('sRouteName', $sRouteName)->set('sPath', $sPath)->set('aRouteParams', $aRouteParams)->set('aParameters', $aAttributes); if ($aSiblings !== []) { $oSiblings = $this->createNextLevel($aSiblings); /* @var $oSiblings View */ } $oSingleLevel->set('oSiblings', $oSiblings); $aEntries[] = $oSingleLevel; } return View::factory('menu/menu')->set('iLevel', $this->iLevel)->set('aEntries', $aEntries); }
/** * @access public * @param string $sName * @return mixed * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function getConfigValue($sName) { return Helper\Arrays::get($this->aConfig, $sName, NULL); }
/** * @static * @access private * @param array $data * @return array * @since 1.2.0-dev * @version 1.2.0-dev */ private static function dividePerLang(array $data) { $output = []; foreach ($data as $context => $translatons) { foreach ($translatons as $string => $translatedLangs) { foreach ($translatedLangs as $lang => $translated) { Helper\Arrays::createMultiKeys($output, $lang . ':;:' . $string . ':;:' . $context, $translated, ':;:'); } } } return $output; }
/** * Add validation rules on the basis of ORM annotation mappings. * * @access private * @param Form\Field $oField * @param array $aMappings * @return bool * @since 1.0.0-alpha * @version 1.0.0-alpha */ private function addValidationByMapping(Form\Field &$oField, array $aMappings) { $iLength = Arrays::get($aMappings, 'length'); $sType = Arrays::get($aMappings, 'type'); // if there are no field mappings if (empty($aMappings) || $oField instanceof Form\Field\Hidden) { return FALSE; } // 'required' validation rule if (Arrays::get($aMappings, 'nullable', FALSE) === FALSE) { $oField->setRequired(); } // validation rules by type switch ($sType) { case 'string': if ($iLength !== NULL) { $oField->addRulesSet(RulesSetBuilder\String::factory()->max(':value', $iLength)); } break; case 'integer': if ($iLength !== NULL) { $oField->addRulesSet(RulesSetBuilder\Number::factory()->max(':value', $iLength)); } break; } return TRUE; }
/** * Get single metatag content. * * @access public * @param string $key * @return string * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function getMetaTagContent($key) { return ArraysHelper::path($this->aMeta, $key . '.content'); }
/** * Get errors for particular field. * * @access public * @param string $sPath * @return array * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function getErrorsForField($sPath) { return Helper\Arrays::path($this->fieldsErrors, $sPath, []); }
/** * Get a value from array list * * @static * @access public * @param string $sWholePath Config name in format [module.]fileName.array.nextArray.value(...) * @param mixed $mDefault * @param bool $bForcePath * @return mixed * @throws Exception * @since 1.0.0-alpha * @version 1.0.0-alpha */ public static function get($sWholePath, $mDefault = NULL, $bForcePath = FALSE) { if (!in_array($sWholePath, static::$aLoadedConfigs)) { static::$aLoadedConfigs[] = $sWholePath; $sPathToConfig = $bForcePath ? $sWholePath : static::modifyConfigPathToFilePath($sWholePath); static::load($sPathToConfig); } return Helper\Arrays::path(static::$aConfigs, $sWholePath, $mDefault); }
/** * Get particular field formatter. * * @access public * @param string $sField * @return array * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function getFieldFormatters($sField) { return Helper\Arrays::get($this->aFieldsFormatters, $sField, []); }
/** * Parse all attributes and return them as a string. * * @access public * @param array $aAddContent * @param boolean $bSaveOldValue * @param boolean $bWithSpace * @return string * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function renderAttributes($aAddContent = [], $bSaveOldValue = FALSE, $bWithSpace = TRUE) { $sReturn = ''; // render main attributes foreach ($this->aAttributes as $sName => $sValue) { if (!isset($aAddContent[$sName])) { $sReturn .= ' ' . $sName . '="' . trim($sValue) . '"'; } } // render the rest of the attributes with additional content foreach ($aAddContent as $sName => $sValue) { $sOldValue = $bSaveOldValue ? Arrays::get($this->aAttributes, $sName, '') : ''; $sReturn .= ' ' . $sName . '="' . trim($sOldValue . ($bWithSpace ? ' ' : '') . $sValue) . '"'; } // return rendered attributes return ltrim($sReturn); }
/** * Reset form values. * * @access protected * @return $this * @since 1.0.0-alpha * @version 1.0.0-alpha */ protected function resetValue() { $aDefaultValue = $this->getFormObject()->getDefaultVal($this->getName()); $this->aFormMethodValues = $this->getFormObject()->getMethodValue(); foreach ($this->getLangs() as $sLang) { if (isset($aDefaultValue[$sLang])) { $aDefaultValue[$sLang] = [$aDefaultValue[$sLang]]; } } if ($this->getFormObject()->isFieldsNameWithPrefix()) { $mSentData = Helper\Arrays::path($this->aFormMethodValues, $this->getFormObject()->getName() . '.' . $this->getName(), FALSE); } else { $mSentData = Helper\Arrays::get($this->aFormMethodValues, $this->getName(), FALSE); } if ($mSentData === FALSE && $this->getFormObject()->isSubmitted()) { $mSentData = []; foreach ($this->getLangs() as $sLang) { $mSentData[$sLang][] = []; } } $this->setValue($mSentData !== FALSE ? $mSentData : $aDefaultValue); return $this; }
/** * Render field and return its rendered value. * * @access public * @return string * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function render() { $content = ''; $values = $this->getValue(); $langVersions = $this->isMultilanguage() ? Router::getLangs() : ['und']; $fieldDefaultId = $this->getAttributes()->getAttribute('id'); $fieldDefaultName = $this->getAttributes()->getAttribute('name'); // create all cases of this field's value foreach ($langVersions as $sLang) { $fieldValueContent = []; $langValues = Helper\Arrays::get($values, $sLang, []); $amountOfFieldValues = count($langValues); // check quantity of this field's value for particular lang if ($this->getQuantity() !== 0 && $this->getQuantity() < $amountOfFieldValues) { $amountOfFieldValues = $this->getQuantity(); } // if current amount of fields is below minimal quantity if ($amountOfFieldValues < $this->getQuantityMin()) { $amountOfFieldValues = $this->getQuantityMin(); } // if current amount of fields is higher than maximal quantity if ($this->getQuantityMax() > 0 && $amountOfFieldValues > $this->getQuantityMax()) { $amountOfFieldValues = $this->getQuantityMax(); } // container for one lang values $fieldSingleValue = View::factory('base/form/field_single_lang')->set('sLang', $sLang)->bind('oField', $this); // for each value number for ($i = 0; $i < $amountOfFieldValues; $i++) { $this->getAttributes()->setAttribute('id', $fieldDefaultId . '_' . $sLang . '_' . $i)->setAttribute('name', $fieldDefaultName . '[' . $sLang . '][' . $i . ']'); $this->renderSingleValue($fieldValueContent, $sLang, $i); } // prepend to field whole content $content .= $fieldSingleValue->bind('aLangValues', $fieldValueContent)->render(); } // field pattern if ($this->getQuantity() !== 1) { $this->getAttributes()->setAttribute('id', $fieldDefaultId . '_LANGUAGE_NUMBER')->setAttribute('name', $fieldDefaultName . '[LANGUAGE][NUMBER]'); $sPatternContent = $this->renderSingleValuePattern(); $sPattern = View::factory('base/form/field_single_value')->set('sLang', 'LANGUAGE')->set('sOneValueNumber', 'NUMBER')->bind('sOneValueContent', $sPatternContent)->bind('oField', $this)->render(); $this->getFormObject()->addFieldPattern($this->getName(), $sPattern); } // reset ID and NAME attributes $this->resetIdAttribute(); $this->resetNameAttribute(); // rendering base of field return View::factory($this->getViewBase())->render(['sContent' => $content, 'oField' => $this]); }
/** * Render only one value of the field. * * @access protected * @param array $aFieldValueContent * @param string $sLang * @param integer $i * @return boolean * @since 1.0.0-alpha * @version 1.0.0-alpha */ protected function renderSingleValue(array &$aFieldValueContent, $sLang, $i) { // render file if (empty($this->sBrokerModel)) { $aFieldValueContent[$i] = View::factory('base/alert')->set('sType', 'warning')->set('sMsg', __('To make this field work properly, there must be a broker model name set.'))->render(); } else { $aFieldValueContent[$i] = View::factory($this->getView())->bind('sLang', $sLang)->bind('iValueNumber', $i)->bind('oField', $this)->set('oCurrentFile', Arrays::path($this->aFile, $sLang . '.' . $i, NULL))->set('oTmpFile', Arrays::path($this->aFileTemp, $sLang . '.' . $i, NULL))->render(); } // return TRUE value to tell, that field rendered successfully return TRUE; }
/** * Find active route in particular menu. * * @access private * @param array $routes * @param integer $parentKey * @param array $parent * @since 1.0.0-dev * @version 1.3.0-dev */ private function findActiveRoute(array &$routes, $parentKey = NULL, array $parent = []) { foreach ($routes as $i => &$route) { /* @var $route array */ /* @var $routeName string */ /* @var $routeParams array */ /* @var $activeRoutes array */ if (!isset($route['classes'])) { $route['classes'] = []; } $routeName = Helper\Arrays::get($route, 'route_name', NULL); $url = Helper\Arrays::get($route, 'url', NULL); $routeParams = Helper\Arrays::get($route, 'route_parameters', []); $activeRoutes = Helper\Arrays::get($route, 'active_routes', []); // $path = $url === NULL ? Route::factory($routeName)->path($routeParams) : $url; if ($routeName !== NULL) { $path = Route::factory($routeName)->path($routeParams); } else { $path = $url; } $path = str_replace(Router::getBase(), '', $path); $currentPath = Router::getCurrentUrl(); if (in_array(Router::getCurrentRouteName(), $activeRoutes)) { $route['classes'][] = ['current ' . $this->activeTrailClass]; } if ($parentKey !== NULL) { $route['parent_key'] = $parentKey; $route['parent'] = $parent; } if ($path === $currentPath) { $this->goBackAndSetActive($route); } if (isset($route['children']) && !empty($route['children'])) { $this->findActiveRoute($route['children'], $i, $routes); /* @var $oChildren View */ } } }
<?php /* @var $route array */ /* @var $routeTitle string */ /* @var $routeName string */ /* @var $path string */ /* @var $routeParams array */ /* @var $children View */ /* @var $classes View */ ?> <?php $prefix = \Plethora\Helper\Arrays::get($route, 'prefix', ''); $suffix = \Plethora\Helper\Arrays::get($route, 'suffix', ''); $innerPrefix = \Plethora\Helper\Arrays::get($route, 'inner_prefix', ''); $innerSuffix = \Plethora\Helper\Arrays::get($route, 'inner_suffix', ''); ?> <?php echo $prefix; ?> <li class="<?php echo implode(' ', $classes); ?> "> <?php if ($path !== NULL) { ?> <?php echo Html::a($path, $innerPrefix . '<span>' . $routeTitle . '</span>' . $innerSuffix); ?>
/** * Method generating search engine object. * * @access public * @param array $fields * @return Helper\SearchEngine * @throws Exception\Fatal * @throws Doctrine\ORM\Mapping\MappingException * @since 1.0.0-alpha * @version 1.0.0-alpha */ public function generateSearchEngine(array $fields = []) { $searchEngine = new Helper\SearchEngine($this); $baseConfig = static::getConfig(); # search engine config foreach ($this->getConfigSearchEngine()->getRelsFields() as $varName => $relFields) { if (property_exists($this, $varName)) { $fieldMapping = static::getMetadata()->getAssociationMapping($varName); $relClass = Helper\Arrays::get($fieldMapping, 'targetEntity'); $objConfig = call_user_func($relClass . '::getConfig'); /* @var $objConfig ModelCore\MConfig */ foreach ($relFields as $fieldName) { try { $fieldName = $baseConfig->hasField($fieldName) ? $varName . '_' . $fieldName : $fieldName; $field = $objConfig->getField($fieldName); $baseConfig->addField($field); $searchEngine->addRelFieldInfo($fieldName, $fieldName, $varName, $relClass); } catch (Exception $e) { } } } else { throw new Exception\Fatal('Zmienna "' . $varName . '" nie istnieje w klase "' . static::getClass() . '".'); } } # basic config foreach ($baseConfig->getFields() as $fieldName => $field) { /* @var $field Form\Field */ if ((empty($fields) || in_array($fieldName, $fields)) && !in_array($field->getType(), Helper\SearchEngine::getBannedFieldTypes())) { if (!in_array($field->getType(), static::$notInSearchEngine)) { if (isset(static::$aChangeThoseTypes[$field->getType()])) { $field = $field->cloneToOtherType(static::$aChangeThoseTypes[$field->getType()]); } if ($field->getQuantity() !== 1) { $field->setQuantity(1); $field->setQuantityMin(1); $field->setQuantityMax(1); } $field->getAttributes()->removeAttribute('disabled'); if ($field->isRequired()) { $field->setRequiredNot(); } $searchEngine->getForm()->addSingleton($field); } } } return $searchEngine; }