Author: Jonathan.Wage
Date: 2010-01-13 23:00:15 +0100 (Wed, 13 Jan 2010)
New Revision: 26586

Modified:
   plugins/sfSympalPlugin/trunk/lib/form/sfSympalForm.class.php
   
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php
   plugins/sfSympalPlugin/trunk/lib/util/sfSympalFormToolkit.class.php
   plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php
   plugins/sfSympalPlugin/trunk/test/fixtures/project/data/fresh_test_db.sqlite
Log:
[1.4][sfSympalPlugin][1.0] Refactoring routing to fix issue where custom 
module/action on content record without a custom path did not work


Modified: plugins/sfSympalPlugin/trunk/lib/form/sfSympalForm.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/form/sfSympalForm.class.php        
2010-01-13 21:50:10 UTC (rev 26585)
+++ plugins/sfSympalPlugin/trunk/lib/form/sfSympalForm.class.php        
2010-01-13 22:00:15 UTC (rev 26586)
@@ -72,6 +72,11 @@
       sfSympalFormToolkit::changeContentIdWidget($form);
     }
 
+    if (isset($form['module']))
+    {
+      sfSympalFormToolkit::changeModuleWidget($form);
+    }
+
     foreach ($form as $name => $field)
     {
       $widget = $field->getWidget();

Modified: 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php 
    2010-01-13 21:50:10 UTC (rev 26585)
+++ 
plugins/sfSympalPlugin/trunk/lib/model/doctrine/PluginsfSympalContent.class.php 
    2010-01-13 22:00:15 UTC (rev 26586)
@@ -8,6 +8,7 @@
   protected
     $_allPermissions,
     $_route,
+    $_routeObject,
     $_mainMenuItem;
 
   public static function createNew($type)
@@ -300,6 +301,21 @@
       ->render();
   }
 
+  public function getMonthPublished($format = 'm')
+  {
+    return date('m', strtotime($this->getDatePublished()));
+  }
+
+  public function getDayPublished()
+  {
+    return date('d', strtotime($this->getDatePublished()));
+  }
+
+  public function getYearPublished()
+  {
+    return date('Y', strtotime($this->getDatePublished()));
+  }
+
   public function getAuthorName()
   {
     return $this->getCreatedBy()->getName();
@@ -317,7 +333,7 @@
 
   public function getRouteName()
   {
-    if ($this['custom_path'])
+    if ($this['custom_path'] || $this['module'] || $this['action'])
     {
       return '@sympal_content_' . str_replace('-', '_', $this['slug']);
     } else if ($this['Type']['default_path']) {
@@ -361,6 +377,20 @@
     }
   }
 
+  public function getRouteObject($path = null)
+  {
+    if (!$this->_routeObject)
+    {
+      if (is_null($path))
+      {
+        $path = $this->getRoutePath();
+      }
+
+      $this->_routeObject = new sfRoute($path, array('sf_format' => 'html'));
+    }
+    return $this->_routeObject;
+  }
+
   public function getRoute($routeString = null, $path = null)
   {
     if (!$this->_route)
@@ -380,15 +410,7 @@
         $routeString = $this->getRouteName();
       }
 
-      if (is_null($path))
-      {
-        $path = $this->getRoutePath();
-      }
-
-      $route = new sfRoute($path);
-      $variables = $route->getVariables();
-
-      $this->_route = $this->_fillRoute($routeString, $variables);
+      $this->_route = $this->_fillRoute($routeString);
     }
 
     return $this->_route;
@@ -396,14 +418,23 @@
 
   public function getEvaluatedRoutePath()
   {
-    $route = url_for($this->getRoute());
-    $replace = sfContext::getInstance()->getRequest()->getScriptName();
+    return $this->getRouteObject()->generate($this->_buildValues());
+  }
 
-    return str_replace($replace, null, $route);
+  protected function _fillRoute($route)
+  {
+    $values = $this->_buildValues();
+    if (!empty($values))
+    {
+      return $route.'?'.http_build_query($values);
+    } else {
+      return $route;
+    }
   }
 
-  protected function _fillRoute($route, $variables)
+  protected function _buildValues()
   {
+    $variables = $this->getRouteObject()->getVariables();
     $isI18nEnabled = sfSympalConfig::isI18nEnabled();
 
     $values = array();
@@ -418,13 +449,7 @@
         $values[$name] = $this->$method();
       }
     }
-
-    if (!empty($values))
-    {
-      return $route.'?'.http_build_query($values);
-    } else {
-      return $route;
-    }
+    return $values;
   }
 
   public function trySettingTitleProperty($value)

Modified: plugins/sfSympalPlugin/trunk/lib/util/sfSympalFormToolkit.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/util/sfSympalFormToolkit.class.php 
2010-01-13 21:50:10 UTC (rev 26585)
+++ plugins/sfSympalPlugin/trunk/lib/util/sfSympalFormToolkit.class.php 
2010-01-13 22:00:15 UTC (rev 26586)
@@ -31,6 +31,25 @@
     $widgetSchema['content_id']->setOption('method', 'getIndented');
   }
 
+  public static function changeModuleWidget(sfForm $form)
+  {
+    $modules = 
sfContext::getInstance()->getConfiguration()->getPluginConfiguration('sfSympalPlugin')->getSympalConfiguration()->getModules();
+    $options = array('' => '');
+    foreach ($modules as $module)
+    {
+      $options[$module] = $module;
+    }
+    $widgetSchema = $form->getWidgetSchema();
+    $widgetSchema['module'] = new sfWidgetFormChoice(array(
+      'choices'   => $options
+    ));
+    $validatorSchema = $form->getValidatorSchema();
+    $validatorSchema['module'] = new sfValidatorChoice(array(
+      'choices'   => array_keys($options),
+      'required' => false
+    ));
+  }
+
   public static function changeDateWidget($name, sfForm $form)
   {
     sfSympalToolkit::useJQuery(array('ui'));

Modified: plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php     
2010-01-13 21:50:10 UTC (rev 26585)
+++ plugins/sfSympalPlugin/trunk/lib/util/sfSympalToolkit.class.php     
2010-01-13 22:00:15 UTC (rev 26586)
@@ -180,7 +180,7 @@
       $routes = array();
       foreach ($contents as $content)
       {
-        $routes[] = sprintf($routeTemplate,
+        $routes['content_'.$content->getId()] = sprintf($routeTemplate,
           substr($content->getRouteName(), 1),
           $content->getRoutePath(),
           $content->getModuleToRenderWith(),
@@ -193,13 +193,37 @@
         );
       }
 
+      $contents = Doctrine::getTable('sfSympalContent')
+        ->createQuery('c')
+        ->leftJoin('c.Type t')
+        ->innerJoin('c.Site s')
+        ->where("c.module IS NOT NULL AND c.module != ''")
+        ->orWhere("c.action IS NOT NULL AND c.action != ''")
+        ->andWhere('s.slug = ?', $siteSlug)
+        ->execute();
+
+      foreach ($contents as $content)
+      {
+        $routes['content_'.$content->getId()] = sprintf($routeTemplate,
+          substr($content->getRouteName(), 1),
+          $content->getEvaluatedRoutePath(),
+          $content->getModuleToRenderWith(),
+          $content->getActionToRenderWith(),
+          $content->Type->name,
+          $content->Type->id,
+          $content->id,
+          implode('|', sfSympalConfig::get('language_codes')),
+          implode('|', sfSympalConfig::get('content_formats'))
+        );
+      }
+
       $contentTypes = Doctrine::getTable('sfSympalContentType')
         ->createQuery('t')
         ->execute();
 
       foreach ($contentTypes as $contentType)
       {
-        $routes[] = sprintf($routeTemplate,
+        $routes['content_type_'.$contentType->getId()] = 
sprintf($routeTemplate,
           substr($contentType->getRouteName(), 1),
           $contentType->getRoutePath(),
           $contentType->getModuleToRenderWith(),

Modified: 
plugins/sfSympalPlugin/trunk/test/fixtures/project/data/fresh_test_db.sqlite
===================================================================
(Binary files differ)

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.


Reply via email to