Doctrine / ExtJS: Use model to create another model - php

I'm having difficulties implementing some of the features my client would like to have.
We're building a shopware shop, which is almost done. I've developed some plugins and customizations to have the shop fit my client, but I'm not the best at backend development using ExtJS and Doctrine.
The situation is: The shop sells car parts. We've bought a third-party plugin that allows us to enter ktype numbers for each product, so that the client can search for his/her car in the frontend and get all fitting products.
The plugin has it's own window in the backend, which isn't very comfortable.
So I created an extra tab in the article details, which displays all entries from the database using the third-party model.
That wasn't so hard since the model and database were created by the third-party plugin and I just had to query the data and display it.
What I'm trying to accomplish is: I added an extra column (selected) with a checkbox, where the admin can choose the cars the article fits to.
The plan was to read the textfield "ktypes" of the article on load, check all corresponding checkboxes and then when a checkbox is altered just save the new ktypes array to the article.
Problem is, that this way I can't sort by that column since it's not in the ExtJS store/model.
So now I'm thinking I'll create my own Model with all the columns from the third-party model, add a article_id column and a selected column and reference everything there.
What I don't know is: How to I get the contents of the third-party model into my own database?
The third-party plugin doesn't reference the article. The table only holds all car data imported from a csv list. The reference between an article and the data is just a textfield in the article details.
I thought about Doctrine associations, but I don't really have a reference point or foreign key...
Has anyone got an idea how to solve this?
Can share code if that helps...
Thanks!

I went in a different direction but still need help. Will post a new question though since it's a different topic.
Thanks for trying to help!

Related

Adding a mysql table as custom Field in Smart Search(Joomla)

Can anyone please guide me how to create a custom field (search filter) on joomla.
I want to create a custom filter from which i can select any particular table to search items in that table. Kindly refer to the screenshot i have attached.
I am a beginner to joomla & PHP.
I want to incorporate the search in the core joomla smart search or if there is any problem with that than i dont have any problem in having a dedicated page on the site.
I have 8-9 tables with 5-6K records for which i want to search the data. User will search some keywords and filter it with the table name present in mysql database. Search will use that particular table selected. Only particular users having access to that page will be using that search. At most 2-3 people will be having access to search.
What i am concerned is about the process of creating a custom field with drop down field of table in mysql DB. I tried searching but i didn't got any specific information. I have the knowledge on OOP methodologies but not much on MVC. Kindly suggest.
What you want to do can be done but will require a functional understanding of both OOP methodologies and MVC principles.
You can create a custom field to generate the drop down field of tables to search.
The next part depends on how you want to incorporate the feature into your website. Do you want it to be part of the core Joomla search or have a dedicated view for it.
Another major programming obstacle is how to generate the table search queries in a way that doesn't require you to build out complicated and difficult to maintain query generation code for each table. Otherwise any tables not explicitly codes for would not be part of search until you updated code.
I would edit your question with following information:
where and how will user search
does search need to list all tables and search all
Is this something you want to expose to the public, or a tool for Admins.

cakephp application design query

I am really a new bee in cakephp development. I've got a design question and would like to get some ideas.
The web application is for a big corporation and each child companies underneath is exactly the same. one child company can not see data from another child company. so at this stage my query is should I build build separate replicated apps, each represent one child company. if so then data aggregation would be a big job in terms of running overall reports. the other option is to build one big application and display/hide data based on the user logged in (user and location of the company).
the next big problem is within each small company there are different units and only certain data is visible across. for example publication department can see customer details but not customer's order history details. from each company one admin user have a right to see all the details. its like each business unit represent a module with certain data visibility. I know cake has fantastic authentication module to handle this but what I need to know is should I put authentication based on controller level or action level? so then each business unit = one big controller
hope this description will give you some sort of vague idea of what i am trying to build.
thanks in advance
You can use ACL.Take a look here ACL tutorial or use a plugin like Alaxos Plugin

creating a site which needs to communicate with magento database

I am currently working on (a part of) a site where people buy an item from a magento based e-commerce website. However, to use that item, they need to go to another website. Basically that "other" website is what I am working on (and doing it via codeigniter)
I dont know much about magento. the only information my website needs from the magento website is some information regarding products (id, name and status). This information will be linked to other tables, i.e the product ID may be a foreign key in a table in my database. I did a little research and was able to figure out how data is stored in the magento database.
Both websites will be on same server.
Now I have two options which I could think of to get products from the magento website into my website,
first is that I create insert,update and delete triggers for the required tables in the magento website so that when a product is added, modified or deleted, it first tries to do the same on my database, and if successful, continues to do it in the magento database.
second option is that I simply merge the two databases of my website and magento website creating a direct relation link between the tables.
Like I previously stated, I dont know much about magento. So i wanted to know which was the safer, better approach or if there was an approach I diddnt think of.
Any help would be appreciated. Thanks.
further clarification of task:
Basically there is a magento website (lets call it "WEBSITE A") which sells "products". When a person buys a "product", they are basically given a "code" for that product. To use this "code", they have to go to another website which I am building using codeigniter (lets call this "WEBSITE B").
Now as you can guess, the code needs to be used in WEBSITE B, and once used it unlocks stuff for the user based upon the product to which the code belonged.
As you can guess, this will create a lot of links between product and other stuff.
product although created in WEBSITE A , is used in WEBSITE B.
Your first option: Never duplicate data unless you can help it. Why couldn't you query the Magento database instead, since it's on the same server?
Your second option: Never merge databases that aren't related.
Both options are basically anti-patterns. What you should do is query the Magento database directly, or if you want to use the Magento helper functions, include Magento and use its API directly:
<?php
require_once 'path/to/Mage.php';
// Use Magento APIs
?>

Symfony 1.3: Need to override backend filter field's set of data

My project is using Symfony 1.3.11, PHP version is 5.3.3.
Let me explain my case and my problem:
We wanted to add another kind of user, not just "user" and "admin" (using sfGuardPlugin). I did add "business" and I did give him permissions to only ONE admin module -- "purchases" (accessing own and under some conditions -- other people's purchases made on the site).
The "business" user can be associated to one or more Partners (firms) registered in the site, effectively allowing us to handle business owners or representatives a wee bit differently.
When the "business" user accesses the admin section, the list of purchases he sees must be this: All Purchases for all Products of all Partners he has associated with him. (Not exactly a trivial query).
I did that, in my opinion, in a stupid manner, but it does work -- namely overriding the "apps/backend/modules/purchase/actions/actions.class.php#executeIndex". I had to first copy-paste some code from the version of that method in the cache.
In short, I did hook myself to the "executeIndex" and added a code to do the proper Criteria, and the code works.
The problem now is this:
The filter field above the list (the one containing the Product list) does contain all possible Products. We want it to only contain all Products for all Partners the current user is associated with.
Thing is, it's my first time having to override the admin's filters and I am lost as to where should I plug my code.
Any help is appreciated. Thanks for your time.
UPDATE: Strangely very unpopular question. Nobody ever had to do this? Wow.
You have to unset the product_list and set another widget with the filtered choices.
Check this post where I explain something like that but using doctrine. In your case the sfGuardUserForm is your somthingFilterForm.
You could also filter data using this method. This is a little more elegant but both would work.

Adding interactions to admin pages generated by the admin generator

I am using Symfony 1.2.9 (with Propel ORM) to create a website. I have started using the admin generator to implement the admin functionality.
I have come accross a slight 'problem' however. My models are related (e.g. one table may have several 1:N relations and N:N relations). I have not found a way to address this satisfactorily yet. As a tactical solution (for list views), I have decided to simply show the parent object, and then add interactions to show the related objects.
I'll use a Blog model to illustrate this.
Here are the relationships for a blog model:
N:M relationship with Blogroll (models a blog roll)
1:N relationship with Blogpost (models a post submitted to a blog)
I had originally intended on displaying the (paged) blogpost list for a blog,, when it was selected, using AJAX, but I am struggling enough with the admin generator as it is, so I have shelved that idea - unless someone is kind enough to shed some light on how to do this.
Instead, what I am now doing (as a tactical/interim soln), is I have added interactions to the list view which allow a user to:
View a list of the blog roll for the
blog on that row
View a list of the posts for the blog on that row
Add a post for the blog on tha row
In all of the above, I have written actions that will basically forward the request to the approriate action (admin generated). However, I need to pass some parameters (like the blog id etc), so that the correct blog roll or blog post list etc is returned.
I am sure there is a better way of doing what I want to do, but in case there isn't here are my questions:
How may I obtain the object that relates to a specific row (of the
clicked link) in the list view (e.g. the blog object in this example)
Once I have the object, I may choose to extract various fields: id etc.
How can I pass these arguments to the admin generated action ?
Regarding the second question, my guess is that this may be the way to do it (I may be wrong)
public function executeMyAddedBlogRollInteractionLink(sfWebRequest $request)
{
// get the object *somehow* (I'm guessing this may work)
$object = $this->getRoute()->getObject();
// retrieve the required parameters from the object, and build a query string
$query_str=$object->getId();
//forward the request to the generated code (action to display blogroll list in this case)
$this->forward('backendmodulename',"getblogrolllistaction?params=$query_string");
}
This feels like a bit of a hack, but I'm not sure how else to go about it. I'm also not to keen on sending params (which may include user_id etc via a GET, even a POST is not that much safer, since it is fairly sraightforward to see what requests a browser is making). if there is a better way than what I suggest above to implement this kind of administration that is required for objects with 1 or more M:N relationships, I will be very glad to hear the "recommended" way of going about it.
I remember reading about marking certain actions as internal. i.e. callable from only within the app. I wonder if that would be useful in this instance?
I'm assuming your application is called backend. Suppose there are two models, BlogPost and BlogPostComment. These are managed using admin generated modules called blog_post and blog_post_comment.
I believe you want a link against each BlogPost displayed on the list page at backend.php/blog_post. The links take you to backend.php/blog_post_comment, which should only show comments related to the relevant BlogPost.
Under apps/backend/blog_post/templates, create a file called _commentslink.php and put this in it:
View Comments
Then in apps/backend/blog_post/config/generator.yml, you need to include this partial in the fields for the list view:
....
param:
config:
list:
display: [ id, title, _commentslink ]
Note the _commentslink - the _ tells it to use a partial instead of looking for the field in the model. Your object is available in this partial as $<name of model> - $blog_post in this case.
Essentially, all this method does is links to the same action as the filter on the comments list normally goes to, passing the relevant condition to it to make it filter by blogpost_id.
If you've got CSRF protection enabled in the backend, you'll need to disable it, or this method won't work. This is set in apps/backend/config/settings.yml. There will be a setting in there called csrf_secret - it should be set to false to disable csrf.
You should try symfony 1.3/1.4 out if you need support for 1:N relationships in forms. 1.3 is in my experience a relatively hassle free upgrade from 1.2.x - 1.4 is the same, but with deprecated features removed.

Categories