I took Francois's advise and attempted to make a behavior. Its not working
though. I don't get any errors or anything - it just doesn't seem to be
firing, which im sure is due to a lack of thorough understanding and my
behavior deviating from the ones I saw in the wiki.
First of all the behviors I looked at all play with a column/field for the
object they are dealing with. like Object->isDeleted/ObjectPeer::IS_DELETED,
what im trying to do however (and I may be completely ass-backwards in my
approach) is to:
1.) check the criteria to see if it has criterion for a column
2.) if not, check to see if there are any criterion - if yes use addAnd, if
not use add(), to add a condition for a foreign table like:
$c->add(ForeingObjectPeer::COLUMN, 'value').
3.) check if there is already a join to the foreign table, if there is
already a join to the foreign table, if not then add one like:
$c->addJoin(ObjectPeer::FOREIGN_KEY, ForeignObjectPeer::FOREIGN_REFERENCE,
Criteria::LEFT_JOIN)
so looking at sfPropelParanoidBehavior and sfPropelSpamTag ive come up with
something like this:
class sfPropelWorkflowBehavior
{
static protected $hasWorkflow = true;
public function updateCriteria($class, $crit, $con = null)
{
/* 'WorkflowStatus' */
$workflowModel = sfConfig::get('app_workflow_model');
/* 'name' */
$workflowColumn = sfConfig::get('app_workflow_status_column');
/* 'published' */
$workflowDefaultStatus = sfConfig::get('app_workflow_default_status');
/* 'workflow_status_id' */
$workflowForeignKey = sfConfig::get('app_workflow_foreign_key');
/* 'id' */
$workflowForeignReference =
sfConfig::get('app_workflow_foreign_reference');
/* code to perform operations described in 1-3 above. The code itself
works as ive tested it directly in an action and all is well /*
}
function enable()
{
self::$hasWorkflow = true;
}
function disable()
{
self::$hasWorkflow = false;
}
}
And my config looks like so:
sfPropelBehavior::registerHooks('workflow',
array(
'Peer:doSelectRS' => array(
'sfPropelWorkflowBehavior', 'updateCriteria'
),
'Peer:doSelectJoin' => array(
'sfPropelWorkflowBehavior', 'updateCriteria'
),
'Peer:doSelectJoinAll' => array(
'sfPropelWorkflowBehavior', 'updateCriteria'
),
'Peer:doSelectJoinAllExcept' => array(
'sfPropelWorkflowBehavior', 'updateCriteria'
)
)
);
I got rid of:
$columnName = sfConfig::get('propel_behavior_paranoid_'.$class.'_column');
(which would be 'propel_behavior_workflow_'.$class.'_column' in my case)
thinking I didn't need it but because my behavior has nothing to do with the
object class calling it, only the criteria. maybe im wrong and this has
something to do with the proper operation of a behavior?
Is there anymore documentation on propel behaviors anywhere?
On 4/29/07 5:55 PM, "Francois Zaninotto"
<[EMAIL PROTECTED]> wrote:
>
> Ant,
>
> I'd definitely use a Propel behavior. Take a look at the
> sfPropelSpamTagBehavior, for instance. Every query receives an additional
> criteria automatically.
>
> http://trac.symfony-project.com/trac/wiki/sfPropelSpamTagBehaviorPlugin
>
> There is little documentation on behaviors
>
> http://www.symfony-project.com/book/trunk/17-Extending-Symfony#Extending%20w
> ith%20More%20Precision (scroll down a little, there you are: "Propel
> Behaviors")
>
> But there are enough examples to understand most of it
>
> http://trac.symfony-project.com/trac/wiki/SymfonyPlugins#Propelextensions
>
> François
>
> -----Message d'origine-----
> De : [email protected] [mailto:[EMAIL PROTECTED]
> De la part de Ant Cunningham
> Envoyé : dimanche 29 avril 2007 23:14
> À : [email protected]
> Objet : [symfony-users] Best way to do this?
>
>
> What would be the best way to add a default join and condition to ALL
> queries in an application?
>
> Ive got a table for workflow and for the frontend app I always have to
> select only the records that are published regradless of their table.
>
> How would you do this?
>
> thanks!
>
>
>
>
>
>
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"symfony users" 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-users?hl=en
-~----------~----~----~----~------~----~------~--~---