Exemplo n.º 1
0
 public static function doSelectWithTitle(Criteria $c, $culture = null, $include_unpublished_pages = false, $con = null)
 {
     $dbMap = Propel::getDatabaseMap($c->getDbName());
     if ($con === null) {
         $con = Propel::getConnection($c->getDbName());
     }
     if ($culture === null) {
         $culture = sfContext::getInstance()->getUser()->getCulture();
     }
     // Set the correct dbName if it has not been overridden
     if ($c->getDbName() == Propel::getDefaultDB()) {
         $c->setDbName(self::DATABASE_NAME);
     }
     self::addSelectColumns($c);
     $startcol = self::NUM_COLUMNS - self::NUM_LAZY_LOAD_COLUMNS + 1;
     $c->addSelectColumn(sfSimpleCMSSlotPeer::VALUE);
     if (!$include_unpublished_pages) {
         $c->add(self::IS_PUBLISHED, true);
     }
     // Start of the complicated stuff
     // ------------------------------
     // big hack to have the join operate on three conditions
     $c->addJoin(sfSimpleCMSSlotPeer::PAGE_ID, sfSimpleCMSPagePeer::ID . ' AND ' . sfSimpleCMSSlotPeer::CULTURE . ' = ? AND ' . sfSimpleCMSSlotPeer::NAME . ' = \'title\'', Criteria::RIGHT_JOIN);
     // but now we need to populate the statement by hand
     $params = array();
     $sql = BasePeer::createSelectSql($c, $params);
     array_unshift($params, array('column' => sfSimpleCMSSlotPeer::CULTURE, 'table' => sfSimpleCMSSlotPeer::TABLE_NAME, 'value' => $culture));
     $stmt = $con->prepareStatement($sql);
     $stmt->setLimit($c->getLimit());
     $stmt->setOffset($c->getOffset());
     $i = 1;
     foreach ($params as $param) {
         $tableName = $param['table'];
         $columnName = $param['column'];
         $value = $param['value'];
         if ($value === null) {
             $stmt->setNull($i++);
         } else {
             $cMap = $dbMap->getTable($tableName)->getColumn($columnName);
             $setter = 'set' . CreoleTypes::getAffix($cMap->getCreoleType());
             $stmt->{$setter}($i++, $value);
         }
     }
     $rs = $stmt->executeQuery(ResultSet::FETCHMODE_NUM);
     // ----------------------------
     // End of the complicated stuff
     /*
     // The complicated code above is there just to add a join on the three conditions 
     // It could be achieved in a simpler way with these lines
     $c->addJoin(sfSimpleCMSSlotPeer::PAGE_ID, sfSimpleCMSPagePeer::ID, Criteria::RIGHT_JOIN);
     $c->add(sfSimpleCMSSlotPeer::CULTURE, $culture);
     $c->add(sfSimpleCMSSlotPeer::NAME, 'title');
     // But then pages with no title would not be visible in menus
     // So we do it with more code and it's both safe and functional
     */
     $results = array();
     while ($rs->next()) {
         $page = new sfSimpleCMSPage();
         $page->hydrate($rs);
         //$page->setCulture($culture);
         $page->setTitle($rs->getString($startcol));
         $results[] = $page;
     }
     return $results;
 }