コード例 #1
0
 /**
  * retrieving description and images for some widgets
  * @author radu
  */
 public function executeRetrieveWidgetsInfo()
 {
     $config = $this->hasRequestParameter('config') ? $this->getRequestParameter('config') : false;
     $portalWidgets = $this->hasRequestParameter('portalWidgets') ? $this->getRequestParameter('portalWidgets') : false;
     if ($config && $portalWidgets) {
         $config = json_decode($config);
         $content = get_object_vars($config->content);
         unset($config->content);
         $config->content[$config->layoutItem] = $content;
         unset($content);
         $portalWidgets = json_decode($portalWidgets);
         $i = 0;
         foreach ($portalWidgets as $pwi => $portalWidgetsFielset) {
             $i++;
             $result['rows'][$i]['title'] = $portalWidgetsFielset->title;
             $result['rows'][$i]['image'] = '';
             $result['rows'][$i]['widget'] = '';
             $result['rows'][$i]['description'] = '';
             $result['rows'][$i]['_selected'] = false;
             $result['rows'][$i]['_is_leaf'] = false;
             $result['rows'][$i]['_parent'] = null;
             $result['rows'][$i]['_id'] = $i;
             $j = $i;
             $parentChecked = false;
             foreach ($portalWidgetsFielset->widgets as $pfwi => $widget) {
                 $j++;
                 $ma = explode('/', $widget);
                 $image = $title = $description = '';
                 $checked = afPortalStatePeer::searchForWidgetInState($config, $widget);
                 $path = sfConfig::get("sf_root_dir") . '/apps/' . $this->context->getConfiguration()->getApplication() . '/modules/' . $ma[1] . '/config/' . $ma[2] . '.xml';
                 if (file_exists($path)) {
                     $action_config_vars = afConfigUtils::getConfigVars($ma[1], $ma[2], $this->getRequest());
                     $dom = new DOMDocument();
                     if ($dom->load($path)) {
                         foreach ($dom->documentElement->childNodes as $oChildNode) {
                             if ($oChildNode->nodeName == 'i:title') {
                                 $title = XmlBaseElementParser::parseValue(trim($oChildNode->nodeValue), $oChildNode, false, $action_config_vars);
                             }
                             if ($oChildNode->nodeName == 'i:description') {
                                 $description = XmlBaseElementParser::parseValue(trim($oChildNode->nodeValue), $oChildNode, false, $action_config_vars);
                                 $image = $oChildNode->getAttribute('image');
                             }
                         }
                         /**
                          * if image exists ok, but the images are saved in /images/widgets 
                          * same as the widget title, so try to get image
                          */
                         if (empty($image) && file_exists(sfConfig::get("sf_root_dir") . "/web/images/widgets/" . $title . ".PNG")) {
                             $image = "/images/widgets/" . $title . ".PNG";
                         }
                         if (!isset($description)) {
                             $description = "";
                         }
                         $image = empty($image) ? '/appFlowerPlugin/images/defaultWidget.gif' : $image;
                         $image = '<img src="' . $image . '" style="margin-right:5px; border:1px solid #99bbe8; padding:3px;float:left;">';
                     }
                     $result['rows'][$j]['title'] = $title;
                     $result['rows'][$j]['image'] = $image;
                     $result['rows'][$j]['widget'] = $widget;
                     $result['rows'][$j]['description'] = $description;
                     $result['rows'][$j]['_selected'] = $checked;
                     $result['rows'][$j]['_is_leaf'] = true;
                     $result['rows'][$j]['_parent'] = $i;
                     $result['rows'][$j]['_id'] = $j;
                     if ($checked) {
                         $parentChecked = true;
                     }
                 }
             }
             $result['rows'][$i]['_selected'] = $parentChecked;
             $i = $j;
         }
         $result['success'] = true;
         $result['totalCount'] = count($result['rows']);
         $result['rows'] = array_values($result['rows']);
         $info = json_encode($result);
     } else {
         $info = json_encode(array('success' => false, 'message' => 'Retrieving widgets information wasn\'t successful!'));
     }
     return $this->renderText($info);
 }