public static function createWidget($kshow, $entry_id = null, $parent_widget_obj_or_id = null, $ui_conf_id = 1, $custom_data = null, $partner_data = null, $security_type = null)
 {
     $widget = new widget();
     $widget->setKshowId($kshow->getId());
     $widget->setEntryId($entry_id);
     $widget->setPartnerId($kshow->getPartnerId());
     $widget->setSubpId($kshow->getSubpId());
     $source_widget = null;
     if ($parent_widget_obj_or_id != null) {
         if ($parent_widget_obj_or_id instanceof widget) {
             $source_widget = $parent_widget_obj_or_id;
             $widget->setSourceWidgetId($parent_widget_obj_or_id->getId());
         } else {
             // assume its an id
             $source_widget = widgetPeer::retrieveByPK($parent_widget_obj_or_id);
             $widget->setSourceWidgetId($parent_widget_obj_or_id);
         }
     }
     $widget->setUiConfId($ui_conf_id);
     if ($source_widget) {
         $widget->setRootWidgetId($source_widget->getRootWidgetId());
         if ($ui_conf_id == null) {
             // if none was explicitly set - use the parent_widget's ui_conf
             $widget->setUiConfId($source_widget->getUiConfId());
         }
     }
     $widget->setCustomData($custom_data);
     $widget->setPartnerData($partner_data);
     $widget->setSecurityType($security_type);
     $widget->setId(self::calculateId($widget));
     if ($widget->getUiConfId() == null) {
         // set the default to be 1
         $widget->setUiConfId(1);
     }
     if ($widget->getRootWidgetId() == null) {
         // set the root to be self -
         $widget->setRootWidgetId($widget->getId());
     }
     $widget->save();
     return $widget;
 }
 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;
 }