/** * Gather plugins, controllers and actions * Given the URI /example/main/index/p1/p2/p3/p4:1 * We would be passing 4 GET parameters (where p4 is a named key to value * pair and p1 - p3 would be assigned numeric keys) into the index action of * the main controller of the example plugin. * * The name of the plugin should also be that plugins namespace. * * We will predefine 3 possible paths for autoloading: * 1. Core, the core path will look for a Plugins directory in the core * * library, this will mostly be used for building examples. * 2. Main, This will check the main plugin path. * * 3. App, This will check the Plugin path inside App. This directory will * ship empty by default. I'm assuming this is where you will build your * application. * * An autoloader will figure out which path to pull from. * Finally we will istanitate the classes based on the PSR-4 autoloading * statndards. This might look something like: * * $class = '\\Example\\Controller\\MainController'; * $controller = new $class(); * $controller->index(); * * Sample URI /tinker_plugin/tinker_plugin/execute/e1/e2/e3/e4:1 * * @param object $loader * @param object $router * @param object $theme * @param object $view * @param boolean $render (set to false for unit testing) * @return void */ public function __construct($loader, $router, $theme, $view, $render = true) { $this->Loader = $loader; $this->Router = $router; $this->Theme = $theme; $this->View = $view; $plugin = $this->Router->getPlugin(true); $model = $this->Router->getPlugin(true); $controller = $this->Router->getController(true) . 'Controller'; $action = $this->Router->getAction(); //Autoload all plugins $this->Loader->addNamespace($plugin, 'plugin' . DS . $plugin . DS . 'src'); $this->Loader->addNamespace($plugin, APP . DS . 'plugin' . DS . $plugin . DS . 'src'); $this->Loader->addNamespace('App', APP . DS . 'src'); if ($render) { if (!empty($this->Router->checkAsset($loader))) { $this->Router->fetchAsset($this->Router->checkAsset($loader)); } else { //Load the MVC stack, if a specific plugin has not been defined as //a container MVC conventions will be used to load the MVC stack if (\Tinker\Di\IoCRegistry::registered($controller)) { $controller = \Tinker\Di\IoCRegistry::resolve($controller); } else { $class = "\\{$plugin}\\Controller\\{$controller}"; $model = "\\{$plugin}\\Model\\{$model}"; $controller = new $class($this->Theme, $this->View); $controller->inject(new $model()); } $controller->{$action}(); } } }
/** * Constructeur * * @param object $router Objet router. */ public function __construct($router) { // Contrôle de la connexion try { // Utilisateur connecté ? $auth = AuthManager::getInstance(); $this->authInfos = AuthHtml::afficherFormulaireConnexion('index.php?t=auth&a=connexion'); if ($auth->estConnecte()) { $this->authInfos = AuthHtml::afficherInformationsConnexion(); } $this->controllerClass = $router->getControllerClass(); $this->action = $router->getAction(); // La classe à instancier existe-t-elle ? if (!class_exists($this->controllerClass)) { throw new \Exception("La classe {$this->controllerClass} n'existe pas."); } // Y a-t-il une action demandée ? if ($this->action == 'defaut') { throw new \Exception("Aucune action demandée dans l'URL"); } // L'action demandée existe-t-elle ? if (!method_exists($this->controllerClass, $this->action)) { throw new \Exception("L'action {$this->action} n'existe pas."); } } catch (AuthException $e) { $html = $e->getMessage(); } }
/** * Sets the path for from which we are to render a view * @return type */ public function setViewPath() { $plugin = $this->Router->getPlugin(true); $controller = $this->Router->getController(); $action = $this->Router->getAction(); $paths = $this->Loader->getPrefixes(); for ($i = 0; $i < count($paths["{$plugin}\\"]); $i++) { $check = $paths["{$plugin}\\"][$i] . 'View' . DS . $controller . DS . $action . '.php'; if (is_file($check)) { $file = $check; } else { //If the literal path does not resolve, check against the include //paths $iPaths = explode(PATH_SEPARATOR, get_include_path()); foreach ($iPaths as $path) { if (file_exists($path . DS . $check)) { $file = $path . DS . $check; } } } } return $file; }
/** * copy all properties and create duplicate payment * * @param object $payment * @return boolean */ protected function moptDuplicatePayment($payment) { $duplicatedPayment = new \Shopware\Models\Payment\Payment(); $duplicatedPayment->setName($this->moptCreateUniquePaymentName($payment->getName())); $duplicatedPayment->setDescription($payment->getDescription()); $duplicatedPayment->setTemplate($payment->getTemplate()); $duplicatedPayment->setAdditionalDescription($payment->getAdditionalDescription()); $duplicatedPayment->setPosition(200); $duplicatedPayment->setActive(false); $duplicatedPayment->setAction($payment->getAction()); $duplicatedPayment->setPluginId($payment->getPluginId()); $duplicatedPayment->setSource(1); try { Shopware()->Models()->persist($duplicatedPayment); Shopware()->Models()->flush(); } catch (Exception $e) { return false; } return true; }
/** * This function for building custom fields * * @param object $qf form object (reference) * @param string $elementName name of the custom field * @param boolean $inactiveNeeded * @param boolean $userRequired true if required else false * @param boolean $search true if used for search else false * @param string $label label for custom field * * @access public * @static */ function addQuickFormElement(&$qf, $elementName, $fieldId, $inactiveNeeded, $useRequired, $search = false, $label = null) { $field =& new CRM_Core_DAO_CustomField(); $field->id = $fieldId; if (!$field->find(true)) { /* FIXME: failure! */ return null; } if (!isset($label)) { $label = $field->label; } /** * This was split into a different function before. however thanx to php4's bug with references, * it was not working, so i munged it back into one big function - lobo */ switch ($field->html_type) { case 'Text': if ($field->is_search_range && $search) { $qf->add('text', $elementName . '_from', $label . ' ' . ts('From'), $field->attributes); $qf->add('text', $elementName . '_to', ts('To'), $field->attributes); } else { $element =& $qf->add(strtolower($field->html_type), $elementName, $label, $field->attributes, ($useRequired || $field->is_required) && !$search); } break; case 'TextArea': $attributes = ''; if ($field->note_rows) { $attributes .= 'rows=' . $field->note_rows; } else { $attributes .= 'rows=4'; } if ($field->note_columns) { $attributes .= ' cols=' . $field->note_columns; } else { $attributes .= ' cols=60'; } $element =& $qf->add(strtolower($field->html_type), $elementName, $label, $attributes, ($useRequired || $field->is_required) && !$search); break; case 'Select Date': if ($field->is_search_range && $search) { $qf->add('date', $elementName . '_from', $label . ' ' . ts('From'), CRM_Core_SelectValues::date('custom', $field->start_date_years, $field->end_date_years, $field->date_parts), ($useRequired || $field->is_required) && !$search); $qf->add('date', $elementName . '_to', $label . ' ' . ts('To'), CRM_Core_SelectValues::date('custom', $field->start_date_years, $field->end_date_years, $field->date_parts), ($useRequired || $field->is_required) && !$search); } else { $qf->add('date', $elementName, $label, CRM_Core_SelectValues::date('custom', $field->start_date_years, $field->end_date_years, $field->date_parts), ($useRequired || $field->is_required) && !$search); } break; case 'Radio': $choice = array(); if ($field->data_type != 'Boolean') { $customOption = CRM_Core_BAO_CustomOption::getCustomOption($field->id, $inactiveNeeded); foreach ($customOption as $v) { $choice[] = $qf->createElement('radio', null, '', $v['label'], $v['value'], $field->attributes); } $qf->addGroup($choice, $elementName, $label); } else { $choice[] = $qf->createElement('radio', null, '', ts('Yes'), '1', $field->attributes); $choice[] = $qf->createElement('radio', null, '', ts('No'), '0', $field->attributes); $qf->addGroup($choice, $elementName, $label); } if (($useRequired || $field->is_required) && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'Select': $customOption = CRM_Core_BAO_CustomOption::getCustomOption($field->id, $inactiveNeeded); $selectOption = array(); foreach ($customOption as $v) { $selectOption[$v['value']] = $v['label']; } $qf->add('select', $elementName, $label, array('' => ts('- select -')) + $selectOption, ($useRequired || $field->is_required) && !$search); break; //added for select multiple //added for select multiple case 'Multi-Select': $customOption = CRM_Core_BAO_CustomOption::getCustomOption($field->id, $inactiveNeeded); $selectOption = array(); foreach ($customOption as $v) { $selectOption[$v['value']] = $v['label']; } $qf->addElement('select', $elementName, $label, $selectOption, array("size" => "5", "multiple")); if (($useRequired || $field->is_required) && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'CheckBox': $customOption = CRM_Core_BAO_CustomOption::getCustomOption($field->id, $inactiveNeeded); $check = array(); foreach ($customOption as $v) { $check[] =& $qf->createElement('checkbox', $v['value'], null, $v['label']); } $qf->addGroup($check, $elementName, $label); if (($useRequired || $field->is_required) && !$search) { $qf->addRule($elementName, ts('%1 is a required field.', array(1 => $label)), 'required'); } break; case 'Select State/Province': //Add State if ($qf->getAction() & (CRM_CORE_ACTION_VIEW | CRM_CORE_ACTION_BROWSE)) { $stateOption = array('' => '') + CRM_Core_PseudoConstant::stateProvince(); } else { $stateOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::stateProvince(); } $qf->add('select', $elementName, $label, $stateOption, ($useRequired || $field->is_required) && !$search); break; case 'Select Country': //Add Country if ($qf->getAction() & (CRM_CORE_ACTION_VIEW | CRM_CORE_ACTION_BROWSE)) { $countryOption = array('' => '') + CRM_Core_PseudoConstant::country(); } else { $countryOption = array('' => ts('- select -')) + CRM_Core_PseudoConstant::country(); } $qf->add('select', $elementName, $label, $countryOption, ($useRequired || $field->is_required) && !$search); break; } switch ($field->data_type) { case 'Int': // integers will have numeric rule applied to them. if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From must be an integer (whole number).', array(1 => $label)), 'integer'); $qf->addRule($elementName . '_to', ts('%1 To must be an integer (whole number).', array(1 => $label)), 'integer'); } else { $qf->addRule($elementName, ts('%1 must be an integer (whole number).', array(1 => $label)), 'integer'); } break; case 'Date': if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From is not a valid date.', array(1 => $label)), 'qfDate'); $qf->addRule($elementName . '_to', ts('%1 To is not a valid date.', array(1 => $label)), 'qfDate'); } else { $qf->addRule($elementName, ts('%1 is not a valid date.', array(1 => $label)), 'qfDate'); } break; case 'Float': case 'Money': if ($field->is_search_range && $search) { $qf->addRule($elementName . '_from', ts('%1 From must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); $qf->addRule($elementName . '_to', ts('%1 To must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); } else { $qf->addRule($elementName, ts('%1 must be a number (with or without decimal point).', array(1 => $label)), 'numeric'); } break; } }
/** * @param object $entity entity * @param string $method method * * @return string */ protected function resolveAction($entity, $method) { if ($entity instanceof ActionInterface) { return $entity; } elseif ($entity instanceof TimelineInterface) { return $entity->getAction(); } else { throw new \InvalidArgumentException(sprintf('Method "%s" accepts only a ActionInterface or a TimelineInterface', $method)); } }
/** * Affiche le resultat de la recherche * * @param object $grid objet de type Grid * @param boolean $pager : pagination * @param array or object $filter * @param array $order * @param string $title titre de la page * @param array $JSRequirements * @param string $addContent Contenu html à ajouter avant ou apres le Grid * de la forme: array('beforeForm' => '...', // avant le SearchForm * 'between' => '...', // entre le SearchForm et le Grid... * 'afterGrid' => '...') * @return string */ public function displayResult($grid, $pager = false, $filter = array(), $order = array(), $title = '', $JSRequirements = array(), $addContent = array(), $renderFunc = 'page') { // Si on ne passe pas une Collection directemt au Grid::render() if ($this->getItemsCollection() === false) { $mapper = Mapper::singleton($this->entity); if (!$grid->getMapper() instanceof Mapper) { $grid->setMapper($mapper); } } if ($grid->isPendingAction()) { $dispatchResult = $grid->dispatchAction($this->getItemsCollection()); if (Tools::isException($dispatchResult)) { $urlVarArray = array(); // On passe ds l'url les valeurs des hidden s'il y en a $hiddenFields = $this->getHiddenFields(); foreach ($hiddenFields as $key => $value) { if ($key == 'formSubmitted') { continue; } $urlVarArray[] = $key . '=' . $value; } $urlComplement = empty($urlVarArray) ? '' : '?' . implode('&', $urlVarArray); // L'action est-elle de type Popup: $triggeredAction = $grid->getAction($_REQUEST['actionId']); if ($triggeredAction->targetPopup === true) { $tpl = BASE_POPUP_TEMPLATE; $returnURL = 'javascript:window.close()'; } else { $tpl = BASE_TEMPLATE; $returnURL = basename($_SERVER['PHP_SELF']) . $urlComplement; } Template::errorDialog($dispatchResult->getMessage(), $returnURL, $tpl); exit; } } else { if ($this->getItemsCollection() !== false) { $mapper = $this->getItemsCollection(); } $result = $grid->render($mapper, $pager, $filter, $order); $addContent['beforeForm'] = isset($addContent['beforeForm']) ? $addContent['beforeForm'] : ''; $addContent['between'] = isset($addContent['between']) ? $addContent['between'] : ''; $addContent['afterGrid'] = isset($addContent['afterGrid']) ? $addContent['afterGrid'] : ''; $pageContent = $addContent['beforeForm'] . $this->render() . $addContent['between'] . $result . $addContent['afterGrid']; if (isset($_REQUEST['formSubmitted'])) { SearchTools::saveLastEntitySearched(); } Template::$renderFunc($title, $pageContent . '</form>', $JSRequirements); exit; } }