How to remove only one translation in CakePHP's TranslateBehavior? - php

I have a model with TranslateBehavior attached to it and I wonder if there is a method to remove only one translation of specific item and use only standard model methods (=not provide SQL query on i18n table explicitly, because I want to be absolutely independent of DB engine) and not set it blank but really remove.
Simple situation example:
There is an article in DB with translations in English and German. One day editor decides not to provide this article in German and wants to remove it from DB (but English version should be still available). And now appears the question I wrote above.
Thank you in advance for your help.

As for now after examining afterSave callback in the behavior class I see only some kind of workaround - to use the core model I18nModel defined in cake/libs/model/behavior/translate.php (bottom of the file) and use delete method with manually set all conditions that normally are set by translateBehavior.
The I18nModel model can be used in standard way:
var $uses = array('SomeModelUsingTranlateBehaviour','I18nModel');

Related

Doctrine2 - relation depending on parameter

I would like to know what is the best way to have an entity with 1:N relation to another entity but additionally depending on a parameter.
For example I have productentity and product_description entity, which depends on product_id and also on language (2 char code). Another examples would be manufacturer and manufacturer_description, category and category_description. There is a lot of it - you got the idea.
I though about extending EntityRepository class and adding automatic join based for example on an annotation. I'm just not sure if this is the "correct way" to do what I want. Can you suggest better solution? Another though was just to have method getDescription($language) in product entity but to me it just doesn't look as best solution, especially because I want to load the language-dependent content in 90% cases with all other information. Getting that content in separate query would just create unnecessary load.
Thank you for your suggestions.
There is a translatable extensions for doctrine. I've never used it but it looks like it might address your use case:
http://www.doctrine-project.org/2010/11/18/doctrine2-behavioral-extensions.html
See also
https://github.com/l3pp4rd/DoctrineExtensions

DoctrineExtensions, does entity have translation in current locale?

I'm using DoctrineExtensions in order to get my entities translated. It works really fine, but i don't know how to resolve this issue :
I use translation fallback, personal translations and ORM query hint in order to reduce DB queries. If the translation doesn't exist, so it will fallback to default values. Till here, there's no problem.
But (this is my question) how could I know that entity has fallen back into the default values ? I mean, if an entity has no translation, is there a way to check it ?
For example, if we want to process this entity somehow whenever there's no translation. Something like :
if (!entity.isTranslated) {
//do something here
}
Of course, just for simplicity, we consider that all fields have been translated or not.
I hope I've been clear enough.
Thanks
I don't think you can do it for now (v2.*).
There is a big refactoring for v3.0, in Translatable there will be no default locale anymore.
See the pull request here: https://github.com/l3pp4rd/DoctrineExtensions/pull/764
no more default locale, all locales are persisted as translations, translatable entity fields serve only as proxy and representation

Codeigniter set sidewide database filter

I want to have a filter on my site so they only see what they want to see. For example a user enables a location filter and selects that he only wants to see USA profiles. I save the filters in an different database table then userdata and in json.
This sounds quite simple but it isn't :) I want to prevent that I have to paste a long group of code to almost every model function.
Is it for example possible that I create 1 time a function with json_decode and foreaches to generate the right active record (where) codes and insert it in a model function with for example $this->enableFilters(); ? I use multiple models so I actually don't want to add a function to every model.
Is this all possible?
One option is to extend the core model class to include a common function. Look at the Extending Native Libraries part on the manual.
So, for example, you will create a MY_Model to extend CI_Model and all your models can extend MY_Model. Your common functions can be on MY_Model that is available to all child classes.

How do I place a View belonging to a Plugin in regular View (CakePHP Howto)

I would like to get some input regarding the feasibility of the following scenario/design pattern:
I would like to insert a View from a Category Plugin (/category/categories/tree) into one of my application Views (/posts/edit/3) as if it is an CakePHP element.
The inserted View has a high level of functionality (sorting, adding, deleting, etc...) and therefore simply calling echo $this->element(); does not seem appropriate to me. That 'feels' more like a practice appropriate in situations where 'snippet'/lower level functionality is needed.
My question: is this possible in CakePHP, if so: how to do this? (just a rough outline of the way to go would suffice)
My first idea is to call an element from the plugin and use $this->requestAction(); from the element.
But as I said earlier is my association with elements one of little functionality/snippet. Using a controller method and its View 'feels' more appropriate. But I don't know how to 'call' a View within a View.
Main reason why I would want this:
full Controller functionality.
activate helpers based on Plugin requirements (this should be of no concern to the posts-controller)
beforeFilter and beforeRender of Plugin might be of use. For example: $this->set('modelName', $this->modelClass);
You could look at using view blocks. AFAIK, they are generally designed to help solve more complex view construction, like the problem you are considering here.
Or call a plugin element directly.

CakePHP ACL lists, ARO alias

I've got a small question about Creating Aro-s in Cakephp
http://book.cakephp.org/#!/view/1547/Acts-As-a-Requester
I'm using code provided in cake-s tutorial (see the link), the problem is that alias for the aro-s are not set. how can this be achieved?
For the purpose of going through the tutorial quickly, you can simply set the alias using your favorite database managing program (phpMyAdmin or the like).
Edit1:
Go for the afterSave callback in the model under concern and set the alias from there.
Add something like this in your User Model.
public function afterSave() {
$this->Aro->save(array('alias'=>$this->data[$this->alias]['name']));
}
Change 'name' by the fieldName you want to use as alias for the Aro. Same in the Group Model.
Saludos.

Categories