public static function createDefaultWidgetForPartner($partner_id, $subp_id, $kdp_ui_conf_id = 200) { if (!$kdp_ui_conf_id) { $kdp_ui_conf_id = 200; } $partner = PartnerPeer::retrieveByPK($partner_id); $widget_id = $partner->getDefaultWidgetId(); if ($kdp_ui_conf_id != null && $kdp_ui_conf_id != 200) { $widget_id .= "_{$kdp_ui_conf_id}"; } try { // create widget associated with the kdp_ui_conf $widget = new widget(); $widget->setId($widget_id); $widget->setPartnerId($partner_id); $widget->setSubpId($subp_id); $widget->setUiConfId($kdp_ui_conf_id); $widget->save(); return $widget; } catch (PropelException $pex) { // this migth very well indicate there is already such an id - return it; return widgetPeer::retrieveByPK($widget_id); } catch (Exception $ex) { // unrecoverable exception return null; } }
public function execute() { $this->forceSystemAuthentication(); myDbHelper::$use_alternative_con = null; // ajax stuff are here because there are too many actions in system module $ajax = $this->getRequestParameter("ajax", null); if ($ajax !== null) { switch ($ajax) { case "getPartnerName": $name = "Unknown Partner"; $partnerId = $this->getRequestParameter("id"); $partner = PartnerPeer::retrieveByPK($partnerId); if ($partner) { $name = $partner->getName(); } return $this->renderText(json_encode($name)); case "validateWidgetIds": $widgetIds = explode(",", $this->getRequestParameter("widgetIds")); $existingIds = array(); if (is_array($widgetIds)) { $widgets = widgetPeer::retrieveByPKs($widgetIds); if ($widgets) { foreach ($widgets as $widget) { $id = $widget->getId(); if (in_array($id, $widgetIds)) { $existingIds[] = $id; } } } } return $this->renderText(json_encode($existingIds)); } } // end of ajax stuff $uiConfId = $this->getRequestParameter("uiConfId"); $uiConf = uiConfPeer::retrieveByPK($uiConfId); if ($this->getRequest()->getMethodName() == "POST") { $numOfWidgets = (int) $this->getRequestParameter("numOfWidgets"); $startIndex = (int) $this->getRequestParameter("startIndex"); $partnerId = $this->getRequestParameter("partnerId"); $uiConfId = $this->getRequestParameter("uiConfId"); $entryId = $this->getRequestParameter("entryId"); $securityType = $this->getRequestParameter("securityType"); $securityPolicy = $this->getRequestParameter("securityPolicy"); $prefix = $this->getRequestParameter("prefix"); if ($prefix) { $prefix = "_"; } else { $prefix = ""; } for ($i = $startIndex; $i < $startIndex + $numOfWidgets; $i++) { $widget = new widget(); if (!$i) { $widget->setId($prefix . $partnerId . "_" . $uiConfId); } else { $widget->setId($prefix . $partnerId . "_" . $uiConfId . "_" . $i); } $widget->setUiConfId($uiConfId); $widget->setPartnerId($partnerId); $widget->setSubpId($partnerId * 100); $widget->setEntryId($entryId); $widget->setSecurityType($securityType); $widget->setSecurityPolicy($securityPolicy); $widget->save(); } $this->redirect("system/editUiconf?id=" . $uiConfId); } if ($uiConf) { $partner = PartnerPeer::retrieveByPK($uiConf->getPartnerId()); } else { $uiConf = new uiConf(); $partner = new Partner(); } $this->widget = new widget(); $this->uiConf = $uiConf; $this->partner = $partner; }
if (file_exists($widget['path'])) { $widget_db = widget::byPath($widget['path']); if (!is_object($widget_db)) { $widget_db = new widget(); } } else { $widget_db = new widget(); } utils::a2o($widget_db, $widget_ajax); $widget_db->save(); ajax::success(utils::o2a($widget_db)); } if (init('action') == 'add') { $widget = new widget(); $widget->setName(init('name')); $widget->save(); ajax::success(utils::o2a($widget)); } if (init('action') == 'remove') { $widget = widget::byPath(init('path')); if (!is_object($widget)) { throw new Exception('Widget non trouvé : ' . init('path')); } $widget->remove(); ajax::success(); } if (init('action') == 'applyWidget') { if (init('path') != 'default') { $widget = widget::byPath(init('path')); if (!is_object($widget)) { throw new Exception('Widget non trouvé : ' . init('path'));