Jump to content

fry2010

Members
  • Posts

    326
  • Joined

  • Last visited

Everything posted by fry2010

  1. ok, obviously I didn't get my head round it right the first time. Looks like an elegant solution. Cheers ignace!
  2. ok. Cheers guys. As always some great insight. Igance, that looks like a nice solution. So would I be right in saying that, if a user updated their contact table, then in order to get these new values I would have to load ALL their account info with this proposed method? Basically I just create an sql to deal with all account resources (joins all tables) even though I may not want table 'x', I will get its columns anyway? Sounds like a clean solution, although not as fully optimized as possible if I understand your method correctly.. unless of course I modified it to deal with more granular requests..
  3. I have looked at doctrine before when looking into symphony. It looks like a good solution, but I am still not sure how it would deal with joined queries. Could you possibly direct me to the correct part in the documentation that relates to that or even an example?
  4. How could I create a class that has a single responsibility yet also can obtain data from other objects, whilst using joins? I'll give an example: I am obtaining user account data and then wish to grab their contact information and profile information, both of which are in different tables. My table structure: create table user_accounts ( userAccountId mediumint( unsigned NOT NULL AUTO_INCREMENT, email varchar(255) not null, password varchar(40) not null ); create table exists profile ( groupAccountId mediumint( unsigned not null, avatar varchar(160) not null DEFAULT '', groupName varchar(160) not null DEFAULT '' ); create table user_contact_details ( contactDetailId mediumint( unsigned not null AUTO_INCREMENT, userAccountId mediumint( unsigned not null, addressLine1 varchar(60) not null DEFAULT '', street varchar(60) not null DEFAULT '', postcode varchar( not null DEFAULT 1, telephone varchar(15) not null DEFAULT '', mobile varchar(15) not null DEFAULT '' ) So, if I want to grab information from all tables, but grab them from one class, how would this reflect on single responsibility? How would you go about designing a class for this?
  5. Just in case anyone wondered, I eventually got a fairly good polymorphic design setup (at least I think so): Created a base class called 'profileObject'. This had a static method called 'getProfileObject(userObject $userObject)'. As you can see this accepted an object of type userObject. This method auto-loaded the required sub-class. For example if the userObject account type was an affiliate, then it would load the sub-class called 'affiliateProfileObject()'. The sub-class extended an abstract class called 'Profile'. This obviously set out the required methods and properties. Now anytime I want to get profile of a user object I simply call: $userProfileObject = profileObject::getProfileObject($userObject); Then if I need to access a property of that users profile I can simply use $userProfileObject->avatar; Hope this helps someone else. Of course if anyone wants to make suggestions on how this could be improved etc I would be interested to hear it. cheers.
  6. I have been reading a lot on polymophism and understand the basics, however when it comes to implementation on something as diverse as different user account types, I struggle to make sense on how best to achieve it. So wondered if someone could give me some pointers as to achieve it: My database tables: user_account ( id mediumint(7)... firstName varchar(120)... lastName varchar(120)... accountTypeId tinyint(1)... etc... ) account_type_1_profile ( userId mediumint(7)... getEmails tinyint(1)... aboutMe... showDemo... ) account_type_2_profile ( userId mediumint(7)... differentProfileSetting1 tinyint(1)... differentProfileSetting2 tinyint(2)... ) As you can see I have a single table for all user account types, but different profile tables. I felt this was best as different accounts will have different profile information. Also I will be having user groups into the mix, so again create another table for group profile settings and a user to group table. Now when creating accounts I have to create a main account, and also a profile for the user depending on the type of user. My current system is: class userClass() class userAccountClass() - create and edit the account table class userProfileClass() - create and edit the user profile Within userAccountClass() I have a method called createAccount() - which creates any type of account. within userProfileClass() I have a method called createProfile() - which is where my issues start to arrive. How can I build it to be polymorphic given that there are a variety of different account profile types? How do I avoid using a big switch statement or multiple methods to achieve same result? Suggestions welcome..
  7. Ok that clarifies a lot for me. You seem to understand exactly the issue I am getting at here, the fact of getting the pagination to work with the result set from the model, without being integrated. I just wanted to avoid having to request a method twice with effectivly the same sql query. So I believe my design issue is with my control aspect. Cheers Kevin
  8. I know this is a common question in relation to object oriented coding, but the answers I see in other places don't really explain how to deal with my situation (probably a very common one). Basically I have created an abstract class 'model', I then want to extend on this with class 'userModel'. Now here is the issue, I also have a third class 'pagination' that I want to be a available to the 'userModel' class. Is any of these approaches the correct way: 1) I could extend the 'model' class with the 'pagination' class, then extend the 'pagination' class with the 'userModel' class. So 'model' -> 'pagination' -> 'userModel' - However these just seems wrong to extend the pagination class 2) Put the 'pagination' methods inside the 'model' class and just extend the model class. So 'model' -> 'userModel'. - However doesn't this go against the seperation of behavoirs with classes? 3) Don't extend the pagination class, but call it seperatly in my control code. The typical answers I see basically suggest that the structure of the classes are wrong if I find I come accross this issue, yet to me the classes seem to be seperated logically. As in they each lay the plans to well defined behavoirs. So I don't see how they can be re-structured. Please enlighten me on where I am going wrong with my thinking here...
  9. Iv been using the tutorial here: http://akrabat.com/zend-framework-2-tutorial/ I wondered if anyone else was finding issues such as the skeletonApp downloaded from git not working correctly? I managed to get it working, however when setting up the 'Album' application, it seems to just mess the whole lot up? So wondered if anyone has recently been using this tutorial and came accross the same things I have, and also offer possible solutions? thanks.
  10. ok yeah i was wrong. Capitlization error. Cheers.
  11. I take it I have upset you guys by calling joomla a big pile of dump?
  12. Clearly it's not. 404 errors mean 'this is not pointing to the right location' Really? It's possible to point to the correct location and still get a 404 not found error. You have heard of the php function, header() right? Just becuase something declares itself as 'not found' does not make it correct. That is down to the system (joomla) throwing this '404' header, even though the resource is there.
  13. hey, Im working with possibly the biggest pile of dump CMS, joomla 2.5. I am having an issue getting a Jquery ajax call to request a .php file within a component directory. Basically joomla is throwing a 404 not found. I have made sure it is correctly pointing to the right location, its just throwing this error. Any ideas?
  14. I have got around the problem now, by setting the foreign fields to allow NULL values, instead of setting to NOT NULL. I also discovered that you cant limit a load data infile, but it is a high requested feature in the mysql boards. Just thought I would record that here in case anyone else runs into a similair problem.
  15. also, is there a way to LIMIT a load data infile? It appears that it doesnt insert all 1 million rows in one go, so I am using IGNORE XXX LINES to skip them. Is there a way to see how many of those rows in the CSV file that had been read?
  16. Im just after some advice and also help with a problem I have. I am trying to insert around 1 million rows, in CSV format using load data infile. I am aware and can use the command to insert it into a basic table with no foreign keys, however I wish to use foreign keys for 6 of the columns. The first issue is I am getting the usual 'Foreign key constraint failed'. Now, I have gone through the file creating a seperate table of data in this csv format to use as the foreign table. I then search in this table to find the resulting insert ID, and insert that into the main table . eg: MAIN TABLE IDtitleforeignId 1'test'164 FOREIGN TABLE foreignIdtitle 164'match this please' 163'don't match this' So the first step I take, is go through the CSV file and populate the foreign table with one of the columns data. Using a query as such: LOAD DATA INFILE 'test.csv' IGNORE INTO TABLE foreignTable FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (@dummy, @dummy,title); This goes through all 1 million rows ok, and only inserts unique rows. Next step I want to insert the data into the main table using a similair query to above, but selecting from the foreign table for the correct ID: LOAD DATA INFILE 'test.csv' IGNORE INTO TABLE foreignTable FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY '\r\n' IGNORE 1 LINES (@dummy,title, @foreignId) SET foreignId = (SELECT foreignId FROM foreignTable WHERE title = @foreignId) This is when I get a foreign key constraint failure. So what are my options, ideally keeping the foreign key? I imagine what is happening is it finds a row that does not contain a match to the foreignTitle, so it does not provide a foreignId for the insert to use. Therefore it fails the entire query. So is there a way I can get it to use a different value if it failed to find a foreign key id? I have thought of using this: (SELECT foreignId FROM foreignTable WHERE title = @foreignId OR '1' = '1') This does work, but it does not attempt to find the real value first before going to the OR query. SSo my foreignIds are all the same, even though they shudnt be. I realise this kind of question is a real long shot here. Im open to suggestions. cheers.
  17. Ok I don't think what I want to do is possible with google API docs. Basically I want to display .doc, .docx etc files in the browser, with all the same formatting. So googles API doesnt have anything for the viewer from what I can tell.
  18. Can someone advise, the way I need to use the API is basically like this: I will be setting a cron job to send a bunch of documents to google docs to parse them I then want to retrieve the documents that google has parsed into images, i imagine using the download document method in the API. However, googles documentation on obtaining an OAUTH token falls short here. Can someone point me to an example of requesting an OAUTH token to my own account? If I even need that? I have the access key etc, but knowwhere does it explain how I actually permit myself access, at least I cant find it.
  19. mmk, I failed to spot that looking at google docs, rather than their API. Will have look through that, thanks. btw if any of you know of the method I should use that would be handy, otherwise Ill have a good look through. cheers.
  20. Ok, my issue is that when using cURL to download a request to google docs, using cURL option file transfer, it downloads immediately. This means that all I really end up saving is a loading screen. So I guess my question is, is there a way to make cURL wait untill the page at google docs is complete? Or is there a better solution? I basically want to store a local copy of what google docs produces, so next time a user needs to view that document, they dont have to wait for loading time. Here is curl request im using: // Download the file from google docs $fh = fopen(DIR_DOWNLOAD . '/database/' . $fileName . '.html', 'w'); $ch = curl_init($docsFile); curl_setopt($ch, CURLOPT_FILE, $fh); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_exec($ch); print_r(curl_getinfo($ch)); curl_close($ch); fclose($fh);
  21. I have created a cron task on dedicated server. It is requesting a php page. Both are under the 'root' user, and 777 permissions. This is purely to get it working. It is executing the php script, but the includes with the php script are not being included. Here are the error messages I get: PHP Deprecated: Comments starting with '#' are deprecated in /etc/php5/cli/conf.d/imap.ini on line 1 in Unknown on line 0 PHP Warning: Directive 'safe_mode' is deprecated in PHP 5.3 and greater in Unknown on line 0 PHP Warning: include_once(): Unable to access ../globalConfig.php in /var/www/vhosts/***REMOVED****/inc/cronTasks/pull.php on line 4 PHP Warning: include_once(../globalConfig.php): failed to open stream: No such file or directory in /var/www/vhosts/***REMOVED****/inc/cronTasks/pull.php on line 4 Anyone got any ideas? The php file here is within the same directory as the files I am trying to include. So I am pretty sure it is finding the included files, it's just not being allowed to include it. I have set the include paths correctly as includes are working, it's only when I use it as a cron job. The cron job is performed by 'root' user as well.
  22. Fenway, your a legend! I didnt even think to try that. cheers.
  23. The reason I am using GROUP BY is because I still want to return all other rows, but select one specific row to display first. the table design is (simplified): create table person ( id int unsigned not null AUTO_INCREMENT name varchar(40) not null, PRIMARY KEY (id) ); create table order ( id int unsigned not null AUTO_INCREMENT, personid int unsigned not null, productid int unsigned not null, name varchar(40) not null, PRIMARY KEY (id), FOREIGN KEY (personid) references person(id), FOREIGN KEY (productid) references product(id) ); create table product ( id int unsigned not null, name varchar(40) not null, PRIMARY KEY (id) ); query: select a.*, b.*, c.* FROM person AS a LEFT JOIN order AS b ON a.id = b.personid LEFT JOIN product AS c ON c.id = b.productid WHERE c.name = 'some product' GROUP BY (b.id = 43) DESC ORDER BY b.name; Please note the tables and query have been condensed a lot, just to give the idea of what im trying to achieve. So I am basically wanting to get the data for orders that have a certain product name, in name order, but I also want to select a specific order id, even if that has the product name in it or not. I want that row to be the first returned row. I appreciate your guidence.
  24. Been a while since iv been on here... Any help appreciated: What I am trying to achieve is to select a specific row from a table, then get the rest of the rows. I have found the solution to this using: GROUP BY (id = 1); However I still want to filter the rest of the rows with the ORDER BY clause. When I try to do this, it does not return the GROUP BY id first. cheers.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.