/**
  * @param   array   $arguments    (optional)
  * @param   array   $options      (optional)
  */
 public function execute($arguments = array(), $options = array())
 {
     $databaseManager = new sfDatabaseManager($this->configuration);
     $connection = $databaseManager->getDatabase($options['connection'] ? $options['connection'] : null)->getConnection();
     afPortalStatePeer::deleteAllByIdXml($arguments['idxml']);
     return 0;
 }
 /**
  * Retrieve multiple objects by pkey.
  *
  * @param      array $pks List of primary keys
  * @param      PropelPDO $con the connection to use
  * @throws     PropelException Any exceptions caught during processing will be
  *		 rethrown wrapped into a PropelException.
  */
 public static function retrieveByPKs($pks, PropelPDO $con = null)
 {
     if ($con === null) {
         $con = Propel::getConnection(afPortalStatePeer::DATABASE_NAME, Propel::CONNECTION_READ);
     }
     $objs = null;
     if (empty($pks)) {
         $objs = array();
     } else {
         $criteria = new Criteria(afPortalStatePeer::DATABASE_NAME);
         $criteria->add(afPortalStatePeer::ID, $pks, Criteria::IN);
         $objs = afPortalStatePeer::doSelect($criteria, $con);
     }
     return $objs;
 }
 /**
  * resets the portal state to the default one
  * @author radu
  */
 public function executeResetPortalState()
 {
     $config = $this->hasRequestParameter('config') ? $this->getRequestParameter('config') : false;
     if ($config) {
         $config = json_decode($config);
         $content = get_object_vars($config->content);
         unset($config->content);
         $config->content[$config->layoutItem] = $content;
         unset($content);
         $afPortalStateObj = afPortalStatePeer::deleteByIdXml($config->idXml);
         /*$result=array('message'=>'Portal state was saved successfuly!');*/
         $result = array();
     } else {
         $result = array('message' => 'There was an error while sending the data!');
     }
     $result = json_encode($result);
     return $this->renderText($result);
 }
 public function validateXmlDocument($cli = false)
 {
     if ($this->cache_only) {
         $this->putCache();
         return array("INFO", null);
     }
     $obj = $this->inCache();
     if (!$obj || $obj->getSignature() != $this->hash) {
         try {
             if (!@$this->document->schemaValidate($this->schema)) {
                 $errors = libxml_get_errors();
                 if (!empty($errors)) {
                     throw new XmlValidatorException($errors, 0, $cli);
                 }
             }
         } catch (Exception $e) {
             if ($cli) {
                 return array("ERROR", $e);
             }
             throw $e;
         }
         $this->putCache($obj);
         if ($this->idxml) {
             afPortalStatePeer::deleteByIdXml($this->idxml);
         }
     }
     $this->is_valid = true;
     return $cli ? array("INFO", null) : true;
 }
 public static function deleteAllByIdXml($idXml)
 {
     $c = new Criteria();
     $c->add(self::ID_XML, $idXml);
     $objs = afPortalStatePeer::doSelect($c);
     if ($objs != null) {
         foreach ($objs as $obj) {
             $obj->delete();
         }
     }
 }
 /**
  * Find object by primary key using raw SQL to go fast.
  * Bypass doSelect() and the object formatter by using generated code.
  *
  * @param     mixed $key Primary key to use for the query
  * @param     PropelPDO $con A connection object
  *
  * @return    afPortalState A model object, or null if the key is not found
  */
 protected function findPkSimple($key, $con)
 {
     $sql = 'SELECT `ID`, `ID_XML`, `USER_ID`, `LAYOUT_TYPE`, `CONTENT`, `CREATED_AT`, `UPDATED_AT` FROM `af_portal_state` WHERE `ID` = :p0';
     try {
         $stmt = $con->prepare($sql);
         $stmt->bindValue(':p0', $key, PDO::PARAM_INT);
         $stmt->execute();
     } catch (Exception $e) {
         Propel::log($e->getMessage(), Propel::LOG_ERR);
         throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), $e);
     }
     $obj = null;
     if ($row = $stmt->fetch(PDO::FETCH_NUM)) {
         $obj = new afPortalState();
         $obj->hydrate($row);
         afPortalStatePeer::addInstanceToPool($obj, (string) $row[0]);
     }
     $stmt->closeCursor();
     return $obj;
 }
 private function readTemplates()
 {
     $this->widgets = $this->getWidgets();
     $attribute_holder = sfContext::getInstance()->getActionStack()->getLastEntry()->getActionInstance()->getVarHolder();
     $this->multi = true;
     if ($this->type !== self::WIZARD) {
         if (!isset($this->process["parses"][0]["areas"]["sidebar"])) {
             $this->process["parses"][0]["areas"]["sidebar"] = $this->defaultPanels["sidebar"];
         }
         if (!isset($this->process["parses"][0]["areas"]["footer"])) {
             $this->process["parses"][0]["areas"]["footer"] = $this->defaultPanels["footer"];
         }
     }
     // Processing afWidgetSelector settings, adding extra widgets.
     // TODO: Some parts must be changed in 1165!!
     if ($this->portalStateObj) {
         $layoutType = $this->portalStateObj->getLayoutType();
         $content = $this->portalStateObj->getContent();
         $tabs = $this->process["parses"][$this->iteration]["areas"]["content"]["tabs"];
         $tabbed = $layoutType == afPortalStatePeer::TYPE_TABBED;
         foreach ($content as $item) {
             if ($tabbed) {
                 $title = isset($item["tabTitle"]) ? $item["tabTitle"] : $item["portalTitle"];
             } else {
                 $title = null;
             }
             foreach ($tabs as $tkk => &$tab) {
                 $tab_id = $tabbed ? $tab["attributes"]["id"] : null;
                 $newtab = true;
                 if (!$title || $tab["attributes"]["title"] == $title) {
                     if (isset($item["portalColumns"])) {
                         foreach ($item["portalColumns"] as $column) {
                             foreach ($column as $component) {
                                 $tmp[0] = strtok($component->idxml, "/");
                                 $tmp[1] = strtok("/");
                                 $found = false;
                                 foreach ($tab["components"] as $data) {
                                     if ($data["module"] == $tmp[0] && $data["name"] == $tmp[1]) {
                                         $found = true;
                                         break;
                                     }
                                 }
                                 if (!$found) {
                                     if ($tmp[0] != '' && $tmp[1] != '') {
                                         $this->process["parses"][$this->iteration]["areas"]["content"]["tabs"][$tkk]["components"][self::getComponentKey($tmp[1])] = array("name" => $tmp[1], "module" => $tmp[0], "column" => 0, "refresh" => 0, "container" => "true", "parsable" => "true", "permissions" => "*", "priority" => 0, "params" => null);
                                     } else {
                                         /**
                                          * @todo - check #1274
                                          * I've added conditional statement here to solve problems
                                          * caused by invalid afPropelState object
                                          */
                                     }
                                 }
                             }
                         }
                     }
                     $newtab = false;
                     break;
                 }
             }
             if (!$newtab) {
                 continue;
             }
             if ($newtab) {
                 $tk = count($this->process["parses"][$this->iteration]["areas"]["content"]["tabs"]);
                 $this->process["parses"][$this->iteration]["areas"]["content"]["tabs"][$tk] = array("attributes" => array("title" => $title, "name" => "", "container" => "true", "parsable" => "true", "permissions" => "*", "priority" => 0, "id" => "tab" . ((int) preg_replace("/[^0-9]+/", "", $tab_id) + 1)));
                 if ($item["portalColumns"][0] != array()) {
                     foreach ($item["portalColumns"] as $ck => $column) {
                         foreach ($column as $component) {
                             $tmp[0] = strtok($component->idxml, "/");
                             $tmp[1] = strtok("/");
                             $this->process["parses"][$this->iteration]["areas"]["content"]["tabs"][$tk]["components"][self::getComponentKey($tmp[1])] = array("name" => $tmp[1], "module" => $tmp[0], "column" => $ck, "refresh" => 0, "container" => "true", "parsable" => "true", "permissions" => "*", "priority" => 0, "params" => null);
                         }
                     }
                 } else {
                     $this->process["parses"][$this->iteration]["areas"]["content"]["tabs"][$tk]["components"] = array();
                 }
             }
         }
     }
     foreach ($this->process["parses"][$this->iteration]["areas"] as $area_type => $area) {
         if (!isset($area["tabs"])) {
             $area["tabs"][0] = array("attributes" => array(), "components" => $area["components"]);
         }
         foreach ($area["tabs"] as $k => $tab) {
             $z = 0;
             if ($area_type == "content" && $this->portalConfig) {
                 $sizedata = $this->getPortalSizes($this->portalConfig->layoutType == afPortalStatePeer::TYPE_TABBED && $tab["attributes"]["layout"] != 0 ? $tab["attributes"] : $area["attributes"]);
                 $this->portalConfig->content[$k]["portalLayoutType"] = $sizedata[0];
                 if (isset($tab["attributes"]["title"])) {
                     $this->portalConfig->content[$k]["tabTitle"] = $tab["attributes"]["title"];
                 }
                 // Create empty columns
                 if (strstr($this->portalConfig->content[$k]["portalLayoutType"], ",")) {
                     $tmpx = explode(",", $this->portalConfig->content[$k]["portalLayoutType"]);
                     foreach ($tmpx as $x) {
                         $this->portalConfig->content[$k]["portalColumns"][] = array();
                     }
                 }
             }
             if (isset($tab['components']) && count($tab['components']) > 0) {
                 foreach ($tab["components"] as $name => $component) {
                     $this->currentUri = $component['module'] . "/" . $component['name'];
                     $arg = 0;
                     if (substr($name, 0, 4) != "tree") {
                         if (isset($component["post"])) {
                             $this->multisubmit = $component["post"];
                         }
                         // Checking widget permissions
                         if ($this->checkWidgetCredentials($component["module"], $component["name"]) === false) {
                             continue;
                         }
                         //adds all the widgets by default to first column
                         if ($area_type == "content" && !$this->portalStateObj) {
                             if ($this->type !== self::WIZARD) {
                                 $idx = $component["column"];
                                 if ($idx >= $sizedata[1]) {
                                     throw new XmlParserException("Invalid column reference!");
                                 }
                             } else {
                                 $idx = 0;
                             }
                             $this->portalConfig->content[$k]["portalColumns"][$idx][] = new stdClass();
                             $kx = count($this->portalConfig->content[$k]["portalColumns"][$idx]) - 1;
                             $this->portalConfig->content[$k]["portalColumns"][$idx][$kx]->idxml = $component["module"] . "/" . $component["name"];
                         }
                         $config_vars = afConfigUtils::getConfigVars($component['module'], $component['name'], $this->context->getRequest());
                         $this->vars[$component['module'] . "/" . $component['name']] = $config_vars;
                         $attribute_holder->add($config_vars);
                         $fileCU = new afConfigUtils($component['module']);
                         $file = $fileCU->getConfigFilePath($component["name"] . ".xml", true);
                         if (isset($component["params"])) {
                             foreach ($component["params"] as $pname => $pvalue) {
                                 $attribute_holder->add(array($pname => $pvalue));
                             }
                         }
                         $this->readXmlDocument($file);
                         $this->iteration++;
                         $this->process["parses"][$this->iteration]["component"] = $name;
                         $this->process["parses"][$this->iteration]["component_name"] = $component["name"];
                         $this->process["parses"][$this->iteration]["module"] = $component["module"];
                         $this->process["parses"][$this->iteration]["area"] = $area_type;
                         $this->process["parses"][$this->iteration]["refresh"] = isset($component['refresh']) ? $component['refresh'] : false;
                         if (($this->getCurrentView() == "edit" || $this->getCurrentView() == "show") && $this->fetch("//i:grouping")->length == 0) {
                             $arg = 1;
                         }
                         $this->runParser($arg);
                     } else {
                         if ($area_type == "content" && !$this->portalStateObj) {
                             if ($this->type !== self::WIZARD) {
                                 $idx = $component["column"];
                                 if ($idx >= $sizedata[1]) {
                                     throw new XmlParserException("Invalid column reference!");
                                 }
                             } else {
                                 $idx = 0;
                             }
                             $idxml = "tree" . $z;
                             $this->portalConfig->content[$k]["portalColumns"][$idx][] = new stdClass();
                             $kx = count($this->portalConfig->content[$k]["portalColumns"][$idx]) - 1;
                             $this->portalConfig->content[$k]["portalColumns"][$idx][$kx]->idxml = $idxml;
                         }
                         $this->tree = new afExtjsTree(array('title' => $component["title"]));
                         $this->tree_root = $this->tree->startRoot(array("title" => "Startroot"));
                         $this->buildTree($component["rootnode"], 1);
                         foreach (array_reverse($this->tree_item) as $level) {
                             foreach ($level as $f) {
                                 $f->end();
                             }
                         }
                         $this->tree->endRoot($this->tree_root);
                         $this->tree->end();
                         $this->extobjects[$idxml] = $this->tree;
                     }
                 }
             }
         }
     }
     if ($this->type == self::PAGE) {
         if (!$this->portalStateObj) {
             $this->portalStateObj = afPortalStatePeer::createOrUpdateState($this->portalConfig);
         }
         $layoutType = $this->portalStateObj->getLayoutType();
         $portalLayoutType = $this->portalStateObj->getPortalLayoutType();
         $this->portalContent = $this->portalStateObj->getContent();
         $this->portalColumns = $this->portalStateObj->getColumns();
         ksort($this->portalColumns);
         $this->portalColumnsSize = $this->portalStateObj->getColumnsSize();
         $portalTools = new afExtjsTools();
         if ($layoutType == afPortalStatePeer::TYPE_NORMAL) {
             $portalWidgets = $this->widgets;
             $portalTools->addItem(array('id' => 'gear', 'handler' => array('parameters' => 'e,target,portal', 'source' => "\r\n\t\t\t\t        if(afApp.hasDesktop()){portal = portal.items.items[0].items.items[0];}\r\n\t\t\t\t        \r\n\t\t\t\t\t\tvar layouts=[[100],[50,50],[25,75],[75,25],[33,33,33],[50,25,25],[25,50,25],[25,25,25,25],[40,20,20,20]]; \r\n\t\t\t\t\t\tvar menu=new Ext.menu.Menu({items:[\r\n\t\t\t\t\t\t\t{text: 'Layout Selector', handler:function(){\r\n\t\t\t\t\t\t\t\t\tportal.showLayoutSelector(target,'Layout Selector',layouts);\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_tile_horizontal.png' \r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Widget Selector', handler:function(){\r\n\t\t\t\t\t\t\t\t\tportal.showWidgetSelector(target,'Widget Selector');\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_side_boxes.png'\r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Reset to Default', handler:function(){\r\n\t\t\t\t\t\t\t\t\tnew Portals().reset(target,portal);\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_lightning.png'\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t   ]});\t\t\t\t\t\t \r\n\t\t\t\t\t\tmenu.showAt(e.getXY());")));
         } else {
             // TODO: Thise must be changed in 1165!!
             $newTabPortalWidgets = $this->filterWidgets(null, $this->portalContent, $this->widgets);
             $portalWidgets = null;
             $portalTools->addItem(array('id' => 'gear', 'handler' => array('parameters' => 'e,target,panel', 'source' => "\r\n\t\t\t\t        if(afApp.hasDesktop()){panel = panel.items.items[0];}\r\n\t\t\t\t        \r\n\t\t\t\t\t\tvar layouts=[[100],[50,50],[25,75],[75,25],[33,33,33],[50,25,25],[25,50,25],[25,25,25,25],[40,20,20,20]];\r\n\t\t\t\t\t\tvar tabpanel=panel.items.items[0];\r\n\t\t\t\t\t\tvar menu=new Ext.menu.Menu({items:[\r\n\t\t\t\t\t\t\t{text: 'Layout Selector', handler:function(){\r\n\t\t\t\t\t\t\t\t\ttabpanel.getActiveTab().items.items[0].showLayoutSelector(target,'Layout Selector for '+tabpanel.getActiveTab().title,layouts);\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_tile_horizontal.png' \r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Widget Selector', handler:function(){\r\n\t\t\t\t\t\t\t\t\ttabpanel.getActiveTab().items.items[0].showWidgetSelector(target,'Widget Selector for '+tabpanel.getActiveTab().title);\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_side_boxes.png'\r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Add New Tab', handler:function(){\r\n\t\t\t\t\t\t\t\t\tvar newTabPortalWidgets=" . json_encode($newTabPortalWidgets) . ";\r\n\t\t\t\t\t\t\t\t\tnew Portals().createNewTab(target,tabpanel,newTabPortalWidgets);\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_add.png'\r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Remove Tab', handler:function(){\r\n\t\t\t\t\t\t\t\t\tnew Portals().removeTab(target,tabpanel);\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_delete.png'\r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Change Title', handler:function(){\r\n\t\t\t\t\t\t\t\t\tnew Portals().changeTitle(target,tabpanel);\t\t\t\t\t\t\t\t\t\t\t\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_edit.png'\r\n\t\t\t\t\t\t\t},\r\n\t\t\t\t\t\t\t{text: 'Reset to Default', handler:function(){\r\n\t\t\t\t\t\t\t\t\tnew Portals().reset(target,tabpanel.getActiveTab().items.items[0]);\r\n\t\t\t\t\t\t\t\t},icon: '/images/famfamfam/application_lightning.png'\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t   ]});\t\t\t\t\t\t  \r\n\t\t\t\t\t\tmenu.showAt(e.getXY());")));
         }
         $this->layout = new afExtjsPortalLayout(array('id' => 'center_panel', 'tools' => $portalTools, 'idxml' => $this->portalIdXml, 'layoutType' => $layoutType, 'portalLayoutType' => $portalLayoutType, 'portalWidgets' => $portalWidgets));
         self::$masterLayout = $this->layout;
     }
     $this->postProcess();
 }
 /**
  * Populates the object using an array.
  *
  * This is particularly useful when populating an object from one of the
  * request arrays (e.g. $_POST).  This method goes through the column
  * names, checking to see whether a matching key exists in populated
  * array. If so the setByName() method is called for that column.
  *
  * You can specify the key type of the array by additionally passing one
  * of the class type constants BasePeer::TYPE_PHPNAME, BasePeer::TYPE_STUDLYPHPNAME,
  * BasePeer::TYPE_COLNAME, BasePeer::TYPE_FIELDNAME, BasePeer::TYPE_NUM.
  * The default key type is the column's phpname (e.g. 'AuthorId')
  *
  * @param      array  $arr     An array to populate the object from.
  * @param      string $keyType The type of keys the array uses.
  * @return     void
  */
 public function fromArray($arr, $keyType = BasePeer::TYPE_PHPNAME)
 {
     $keys = afPortalStatePeer::getFieldNames($keyType);
     if (array_key_exists($keys[0], $arr)) {
         $this->setId($arr[$keys[0]]);
     }
     if (array_key_exists($keys[1], $arr)) {
         $this->setIdXml($arr[$keys[1]]);
     }
     if (array_key_exists($keys[2], $arr)) {
         $this->setUserId($arr[$keys[2]]);
     }
     if (array_key_exists($keys[3], $arr)) {
         $this->setLayoutType($arr[$keys[3]]);
     }
     if (array_key_exists($keys[4], $arr)) {
         $this->setContent($arr[$keys[4]]);
     }
     if (array_key_exists($keys[5], $arr)) {
         $this->setCreatedAt($arr[$keys[5]]);
     }
     if (array_key_exists($keys[6], $arr)) {
         $this->setUpdatedAt($arr[$keys[6]]);
     }
 }