Jump to content

NotionCommotion

Members
  • Posts

    2,446
  • Joined

  • Last visited

  • Days Won

    10

Everything posted by NotionCommotion

  1. If I only need to perform a single method on an object, is there anything wrong with chaining a new object? $obj=new myObj(); $obj_prop=$obj->getProp(); $obj_prop=myStaticObj::something()->getProp(); $obj_prop=new myObj()->getProp(); //Error? $obj_prop=(new myObj())->getProp();
  2. Are cookies disabled on your browser? If so, enable them. If not, try the following: <?php session_start(); echo('session_name(): <pre>'.print_r(session_name(),1).'</pre>'); echo('session_id(): <pre>'.print_r(session_id(),1).'</pre>'); echo('session_get_cookie_params(): <pre>'.print_r(session_get_cookie_params(),1).'</pre>'); echo('$_COOKIE: <pre>'.print_r($_COOKIE,1).'</pre>'); echo('$_SESSION: <pre>'.print_r($_SESSION,1).'</pre>'); $_SESSION['test']=time();
  3. First, you need to calculate your employees per hour. You can either do this by creating a fancy query, or just retrieving your data as you show it and iterating over it to get the results. Then, I would recommend a JavaScript plugin such as http://www.jqplot.com/examples/barTest.php to create your graph.
  4. Yea, I guess I should just get in the habit of doing so.
  5. Had some JS that wasn't working, and turned out I had a whitespace at the end of a PHP file. To fix it and other bad files, came up with the following. See any problems with it? Yea, I know that it surely could be done at the command line, but made me feel safer doing it this way. Also, maybe should just get rid of the closing PHP tags altogether, but still have the issue with opening tags. Thanks <?php $dir=dirname(dirname(dirname(__FILE__))).'/classes'; echo($dir."\n\n"); $dir = new DirectoryIterator($dir); foreach ($dir as $fileinfo) { if (!$fileinfo->isDot() && $fileinfo->getExtension()=='php') { $file=$fileinfo->getPathname(); $content=file_get_contents($file); if(ctype_space(substr($content, 0, 1)) || ctype_space(substr($content, -1))){ echo("TRIM: $file\n"); file_put_contents($file, trim($content)); } } } ?>
  6. Thanks Maxxd. Yea, I agree those are the biggies which a bad design could bring about. But is it okay to "just do things right", are there things a real good database designer could do which would make the programmer's life better? I only bring up the super/sub table design pattern because that is where I have witnessed it, but I expect there are more opportunities. Yes, I know this is a database/SQL question, but it has PHP implications so please stay with me. Say you have three tables: teachers, students, and parents, and each have a first name, last name, username, email, bla, bla, bla, and also a couple of other unique to each fields. Would you create a separate table for each? I think most PHP developers would. The design is normalized so we did our duty, right? No duplicated data (feel free to pip in benanamen), right? So, all is good... But now we want to link all these type of people (i.e. teachers, students, parents) to their favorite movie. Well, that is three separate queries for each. Do we embed different queries in the application for each, and be forced to maintain them? Do we get fancy (i.e. complicated) and have the application create the query? Or, should the database developer have the foresight to create a super table for us so we could just JOIN to that? Have these questions not been asked before, or am I just asking things which aren't important?
  7. My bad, I didn't give you all the info. These methods are used with other child classes as well. Yea, I've been messing around with doing so. Is this considered a "right" way of doing this? Or is this considered the correct way, or should I be doing things totally differently?
  8. I recognize that you have much more expertise than me regarding programming, but respectfully disagree. I have dealt with some database designs which complicate the PHP code and some which make it very simple. I don't know for sure, but highly suspect that the database design often has the same impact regardless of the programming language used.
  9. I have an application which takes input from GET or POST, creates a controller, and evokes the appropriate task. While not exactly how it is done, it is pretty close to: $controller=new childController(); $task=array_merge(['task'=>'default'],$_GET,$_POST)['task']; $controller->$task(); Now, I have two tasks which are almost identical, and the only difference is one passes "foo" to documents::removeDocument(), and the other passes "bar". To implement, I did the following: class childController extends parentController { public function deleteFooDocument(){$this->deleteDocumentHelper('foo');} public function deleteBarDocument(){$this->deleteDocumentHelper('bar');} } <?php class parentController { protected function deleteDocumentHelper($type){ if(isset($_POST['id'],$_POST['doc_id'])){ if(documents::removeDocument($type,$_POST['doc_id'],$_POST['id'])) { $success=1; //Ability to replace the following line with one or more lines $this->getModel()->updateParentAudit($this->audit_table,$_POST['id']); } else {$success=0;} header('Content-Type: application/json;'); $this->dontCache(); echo(json_encode(array('success'=>$success))); } else {exit($this->missingPage());} } } ?> Now, I realize one of the methods should do $this->getModel()->updateParentAudit($this->audit_table,$_POST['id']); upon successfully deleting a document, but the other should do something else, and am struggling on how to deal with it. I think I am going down a slippery slope. Did a little research on "helper methods", and some say they are evil. Should I be doing this totally differently?
  10. Thanks ignace, The same document can be attached to different entities, so added_by, deleted_by, added_at, deleted_at needs to remain in the m2m table. I am also using a surrogate for people, companies, and projects, and have a little extra data located in superTable such as when the entity was added, etc. My hopes were not as much to debate the database design, but discuss how the schema has implications on the associated PHP code. As JonnoTheDev pointed out "You do not want to be creating separate tables for each type as there is no flexibility in the design and as you have already found out it is hard to create the business logic." By using a super table, my PHP code to add/view/delete documents becomes almost the same and the application becomes much simpler. I did not expect that the database schema would have such a great impact on the PHP code.
  11. While I agree that normalization is very important, I don't believe either of these designs are not normalized up to the 3rd normal form. Where do you feel they aren't? Why do you believe second design is no good?
  12. Each document needs to be associated with a given person, company, or project, and not just be of one of the people, companies, and projects types. Given this requirement, do you still feel it could be accomplished with two tables? You are absolutely correct! It is amazing how the database schema could complicate other issues.
  13. table1, table2, and table3 are People, Companies, and Projects. There are actually more as you suggested. Currently, I've been using the first schema, but it is making my PHP complicated. It seems like the second schema I showed might result in much simpler PHP script. You mean as I show in the second schema?
  14. From purely a PHP coding perspective, what are the pros and cons of the two below database designs?
  15. I am still trying to understand how this would work. Are you saying that the child implements the parent abstract method, and that parent method calls a method defined in the child to get the necessary value?
  16. @Kicken. I just went over your actual script examples. For your first example, seems like this is what you are doing. No? Instead of calling the method "doSomething()", you call it "doSomethingInternal()". From a naming prospective, anything wrong with calling the internal method "_doSomething()"? You did create an abstract method "doSomething()", but it is empty. What is the point? To just let people know it is being defined in the child, or is there something more? For your second example, I see how you are using getExtra(). Where does the success() and failure() methods come in? Thanks @Requinx. Do you mind giving me a brief script example how this would be implemented? Something similar to my original and the one that Kicken provided so I could compare? Thanks
  17. Thanks Kicken, Yea, I see your point and don't disagree with your reasons why it is bad. I've totally ignored (or at least 96% ignored as I have in fact created some abstract classes without really knowing why) the concepts of abstract, traits, and the like, but expect I need to do differently. If you know of any good resources to learn up, please advise. Regardless, still appreciate your help.
  18. Exactly! Basically what I am doing, but using the same name. Why not use the same name and do my default argument value hack? If not, is there an accepted naming standard? For instance, if child method is "doThis()", parent helper method should be "_doThis()".. I really need to get better at this! Are you willing to give me some pseudo-real examples on how this works? Or point me to some literature which I could read through, and hopefully answer questions regarding it? Thanks you!
  19. Thanks Requinx, The child class will never be passed an argument, and the parent will always be passed one.. The only reason I included the "dummy" argument is so I could use the same method name in each without generating a warning/error. Does this change your recommendations? Will do. I was thinking of passing a very simple anonymous function, but was chastised a while back...
  20. I have a method in several child classes which are basically the same, but have some small differences, and I would like to have most of the script in the parent class. The following would basically work, but I would rather execute $this->bla_a() before echoing anything. How would you recommend doing so? Thanks $controller=new ChildController1(); $controller->doSomething(); class ParentController { protected function doSomething($extra) { header('Content-Type: application/json;'); $id=(isset($_POST['id']))?$_POST['id']:0; $other=new otherclass(); $x=$other->bla($id,$extra); $flag=$x['flag']; unset($x['flag']); echo(json_encode($x)); return $flag; } } class ChildController1 extends ParentController { public function doSomething($extra='dummy') { if(parent::doSomething('usethis1')){ $this->bla_a(); } } } class ChildController2 extends ParentController { public function doSomething($extra='dummy') { if(parent::doSomething('usethis2')){ $this->bla_b(); } } }
  21. Hi Jacques, I am concerned that showing all the authorization rules will divert focus. Guess if I better organized them, might not be the case, but unfortunately it is the case. Yes, I have considered using transactions and will do so if they provide value. Don't think it is necessary on the option 2. I didn't say so, but the authorization rules will require a database query. Seems that this is also a potential reason to go with option 2. While I framed the question as I did, part (or most) of my dilemma is how to scope functions of a class to perform most of this scope. I want a class which is responsible to upload and validate the file, store the file in the documents table, move the file to its correct directory, and even add these link junction records. At least, I think this is what I want, but I have been going back and forth. I believe the audit trails which I previously mentioned are outside of what this class should do, and plan on doing them after the action occurs. Then comes these authorization rules that I mentioned. They seem like they should be defined outside of this class which makes me question my option 2, but maybe they can still be defined outside and implemented within the class? Hope I am not overly confusing the issue.
  22. I have an application where users can create one of 10 types of entity records, and 8 of these record types are identified by a single primary key, and 2 of them are identified by a duel composite key. Users are then able to upload files to the server provided the file validates physically (i.e. file size, extension, etc), and whether the file can be "linked" to one of the previously mentioned entity records based on various "authorization" rules which will be promoted by the JavaScript client and enforced by the server either using PHP code and/or the database. Upon successfully uploading a file and linking it to an entity record, several other transactions occur such as audit trails, etc. My plan is to create the 10 described entity records table, a single "documents" table, and 10 junction tables to save the link state to the 10 entity tables. For this discussion, please assume this schema is correct. I would like recommendations on the steps to implement. One option is when a file is submitted to the server... Verify that all necessary POST/FILE data is provided Verify that the file passes physical validation. Make sure the authorization rules are met. Store the file statistics in the "documents" table and retrieve its primary key. Create the junction link record. Move the file to the correct location. Save audit trails, etc. Another option is when a file is submitted to the server... Verify that all necessary POST/FILE data is provided Verify that the file meets passes physical validation. Store the file statistics in the "documents" table and retrieve its primary key. Attempt to create the junction link record using a query than must pass authorization rules. If inserted... Move the file to the correct location. Save audit trails, etc. If not inserted... Delete the file statistics in the database Recommendations on which approach, or whether it should be a different approach all together?
  23. Hi Ginerjm, bla() was just an example. Instead of a function, assume it was a bunch of script which I didn't wish to duplicate in getstuff(). Did you look into []? Just a shortcut for array(), and [1,2,3] is the same as array(1,2,3).
  24. Try the following. Also, experiment with using $key=>$value in your foreach loops. <?php $array=[ 'catalog'=>[ [ 'attributes'=>['book'=>20160122], 'section'=>[ ['id'=>'F100','title'=>'Across the Sea'], ['id'=>'F101','title'=>'Blue Water'], ['id'=>'F102','title'=>'Red Rove'] ] ], [ 'attributes'=>['book'=>20160123], 'section'=>[ ['id'=>'F103','title'=>'xAcross the Sea'], ['id'=>'F104','title'=>'xBlue Water'], ['id'=>'F105','title'=>'xRed Rove'] ] ], ]]; foreach($array['catalog'] as $catalog){ echo('Book: '.$catalog['attributes']['book']."\n"); foreach($catalog['section'] as $section){ echo($section['id'].' '.$section['title']."\n"); } echo("\n"); } ?>
  25. Thanks Jacques, If I wasn't already convinced, I definitely am now.
×
×
  • 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.