Jump to content

FrancisChung

Members
  • Content Count

    469
  • Joined

  • Last visited

  • Days Won

    1

Everything posted by FrancisChung

  1. Completely understand if you don't wish to create accounts for the sake of it. I happen to use Bitbucket quite a lot as well, which integrates well with Sourcetree since they share the same maker.
  2. I had another read, and I think the best course of action try and reverse engineer a working plugin? https://github.com/topdown/phpStorm-CC-Helpers
  3. I use Atlassians' Sourcetree if people wanted an alternative. https://www.sourcetreeapp.com/
  4. @maxf5, I tried about a year ago but I couldn't get it to work. I assume you're on the latest build of PHPStorm?
  5. I forgot about this .... everyone should upvote this to get a chance of being implemented. https://youtrack.jetbrains.com/issue/WI-36647 Or even better, any Java/PW gurus out there?
  6. Wait till you get to Factory Methods, Contravariance, Covariance, Builder + Specification patterns .... haha Ideally Classes should do one thing and only one thing. So you should probably make multiple smaller classes that has a very distinct and easily identifiable singular purpose rather than 1 monolithic one that tries to do everything.
  7. Wow, it's like Night & Day compared to your first iteration. Looking very good.
  8. 1 of OO Programming's Commandments is : "Thou shalt favour composition over inheritance (or extending a class)" It can seem complex, especially if you're starting out on OO concepts. https://stackoverflow.com/questions/49002/prefer-composition-over-inheritance https://medium.com/humans-create-software/composition-over-inheritance-cb6f88070205 The Medium.com has one of the best explanations I've seen. @bernhard's code above is an example of composition.
  9. Everyone starts somewhere at the bottom and make their way up. Your code wasn't that terrible, just needed a small house clean Glad to hear this. Makes it all worthwhile.
  10. You could take Bernhard's example and encapsulate it even further ... I've added 2 new functions NoErrors & DisplayErrors to encapsulate and hide away more logic.
  11. You want to define $errorMsg outside the function, where your main logic resides. I think I should also pass the message via reference not via value which is the default method of passing arguments. Funny enough, php.net has a very similar example there. http://php.net/manual/en/functions.arguments.php#functions.arguments.by-reference
  12. @SamC, if you're struggling with any aspects no matter how trivial. give me a shout and I can try and help out. I've quite enjoyed the discussions we're having so far.
  13. The idea with the validation functions is to encapsulate the checking logic and the error capture logic inside the function. You could even throw the error there immediately but I don't know what your requirements are. function CheckSendMe($errorMsg) { if ($input->post->sendMe) { return true else { $errorMsg = $errorMsg."Error MSg here"; //appending error msgs here return false; } } ... $cond1 = CheckSendMe($errorMsg); $cond2 = ValidateV($errorMsg); ... if ($cond1 && $cond2 && $cond3) { .... } else DisplayErrorMsg($errorMsg); The idea here is to minimise any long nested if-else chains and favouring readability over pre optimizations or micro optimizations. Perhaps if you're the only coder and or you're working in a small team or you're very familiar with the codebase then you may think this approach may seem like overkill. Until you work on a huge codebase that is alien to you, previously worked on a by a long list of programmers with varying skill levels, and the sight of a huge function with a dozen if-else statements nested coming your way will probably change your mind quickly about readability.
  14. Should never be too lazy for learning. Keep feeding that curious inner child inside you! I think all the myriad of intermediate and advanced techniques, paradigms, theories etc that we programmers use boils down to 2 objectives we strive for. Readability and ease of (future) maintenance. Something that helps achieve the two is proper encapsulation of code & logic, something I think I am still learning better ways to do after all these years! The Pipeline is merely one way of encapsulating your code & logic in a certain way that helps achieve readability. Object Orientated Programming was born because of this need for encapsulating code. You could certainly just use if statements and functions to achieve this as well, perhaps encapsulating some of the logic into smaller functions like below. $cond1 = CheckSendMe(); //$input->post->sendMe. $cond2 = ValidateV(); //$v->validate $cond3 = VerifyCaptcha(); //$captcha->verifyResponse() if ($cond1 && cond2 && cond3) { ConstructEmail(); if (SendMail()) DisplaySendMsg() else DisplaySendFailMsg() } I guess the different ways of encapsulating code will yield different results and your mileage will definitely vary a lot depending on what and how you use it.
  15. I'm pretty sure I read somewhere in the beginning that PW 2.x was not officially supported, at least in the very early versions, which is why I just got the early bird deal and never used it. Perhaps that has changed over recent iterations?
  16. Haha, maybe it's about time I dusted off Tracy Debugger too. Was an early adopter but have never used it because I was on PW 2.8.x for a long time until recently.
  17. You could apply something like the Pipeline Design Pattern to streamline a set of sequential work, which I think is what you're trying to achieve @SamC ? Having said that, it's not something I've used in PHP itself but I've used in other languages like C#. The advantage is better readability and maintainability and no more long nested if - else statements. https://medium.com/@aaronweatherall/the-pipeline-pattern-for-fun-and-profit-9b5f43a98130 An alternative method of getting rid of if - else statements is using functional programming paradigms like Lambda expressions and using optional types and using defensive programming techniques. There's a great course on it on Pluralsight on this called Advanced Defensive Programming Techniques. It can get a bit heavy but it's profoundly changed my coding views in a positive way. Even if you're not familiar with C#, I would recommend having a look at this course if you really want to advance yourself as a coder. https://www.pluralsight.com/courses/advanced-defensive-programming-techniques
  18. It's not this error you're referring to right? You must assign a template to the page before setting custom field values (title__data) [pageClass=Page, template=]
  19. Make a backup of the .htaccess file in your new site and copy across the .htaccess from the source site and see if that works. In my experience, where part of the site is accessible but not others (eg. Homepage vs Other pages) .htaccess has always been the culprit so far.
  20. @heldercervantes , I had to build something from scratch but unfortunately, it's coupled with the site I built it for at the moment despite my best efforts to make it more modular. None of it is in a PW Module although they are all constructed as separate PHP Object Classes at this stage. I had success with it if it's an ad that isn't from one of the advertising platforms out there, i.e. what I call an independent or internal ad. I'm having some issues with some Ads not showing up if it's an Ad from 1 of these Adverting platforms. It's a real pain in the <XXX>, ads! A module that can handle ads would be a huge boost for the Processwire platform. Unfortunately, this is my first attempt at Ads and I would really need someone who is well versed in Web Advertising to help me to undertake such a big task if I were to contemplate doing it.
  21. I use something called SimpleExcel to export / import CSV. http://faisalman.github.io/simple-excel-php/ Here's an example code snippet for Export : $AllPages is just the data source, so you can replace it with your own. I would also ignore all the col_subcat fields and any associated functions like GetSubCategoryNames. You can replace 'SSS-Exported' at the bottom to the filename of your choosing. public function ProcessXML() { $AllPages = Data::PagesAllContentsNoInteraktives(); if ($AllPages->count()==0) exit; $_colTitle = 0; //A $_colCategory=1; //B $_colSubcat1 =2; //C $_colSubcat2 =3; //D $_colSubcat3 =4; //E $_colSubcat4 =5; //F $_colSubcat5 =6; //G $_colContent = 7; //H $_colIntro = 8; //I $_colAuthor = 9;//J $_colImage = 10;//K $_colAlt = 11;//L $_colTitleNav= 12;//M $_colSEOTitle= 13;//N $_colKeywords= 14;//O $_colSEOImage= 16;//Q $_colMeta = 15;//P $_colURL = 17;//R $_colURLnew = 18;//S $_colCanonical=19;//T $_colParent = 20;//U $_colAudio = 21;//V $_colVideo = 22;//W $worksheet = array(); array_push($worksheet, array( 'Title', 'Category', 'Sub-Category I', 'Sub-Category II', 'Sub-Category III', 'Sub-Category IV', 'Sub-Category V', 'Content', 'Intro', 'Author', 'Image', 'Alt', 'Title for Navigation', 'SEO Title', 'Keywords', 'Meta Description', 'SEO Image', 'URL', 'URL New', 'Canonical', 'Parent', 'Audio', 'Video URL', 'ID' ) ); foreach ($AllPages as $page) { try { $subcats = GetSubCategoryNames($page); $subcat1=''; $subcat2=''; $subcat3=''; $subcat4=''; $subcat5=''; try { $subcat1 = $subcats[0]; $subcat2 = $subcats[1]; $subcat3 = $subcats[2]; $subcat4 = $subcats[3]; $subcat5 = $subcats[4]; } catch (\Exception $e) {} array_push($worksheet, array( $page->title, GetCategoryName($page), $subcat1, $subcat2, $subcat3, $subcat4, $subcat5, $page->content, $page->content_intro, $page->author, $page->image, $page->image_alt, $page->title_nav, $page->seo_title, $page->seo_keywords, $page->seo_description, $page->seo_image, $page->url, $page->url, '', $page->seo_canonical, $page->audio, $page->video_url, $page->id )); } catch (\Exception $e) { WriteLog($e->getMessage() . " " . "{$page->title}" . " has errors"); } } try { $excel = new SimpleExcel('xml'); $excel->writer->setData($worksheet); $excel->writer->saveFile('SSS-Exported'); } catch (\Exception $e) { WriteLog($e->getMessage()); } } P/S In case you need to switch from CSV to XML, this post could be of interest. .
  22. Or alternatively, if you can associate a field with each menu item say "show". You would loop through each children, tagging anything to show. When you loop through up the chain, you check if the children has something to show, and if it does it gets tagged as show. Only thing I'm not clear is if there's a scenario where a parent has to be shown but there's no content for its child. You may need to check for this scenario separately, and if such conditions are met, you will need to recurse back down to the children and tag it to show.
  23. Sounds like you need to keep track of the state of the children that have content using a separate list or array or whatever data structure you see fit. I assume each item is uniquely identifiable? If so, you can add to this structure all items that has the related item or content. I guess when you hit the logic whether you determine a parent/grandparent needs to be shown, you need to refer to this structure and do a membership test. i.e. Are any items in this list a child or grandchild of mine. If it's in this structure, you know you have to show it. If not, you don't have to.
  24. Just wanted to add that it's not just PHP that treats 0 as False and 1 as True. You'll find most (traditional) languages will do the same (at least the ones I've come across). There are some exceptions like Ruby & Lisp which treats 0 as true, AFAIK. If you're wondering why 0s & 1s ... well I don't have a definite answer myself as it's one of those topics that will divide opinion. IMHO I side with the view that it originates from Electronics & Boolean Algebra. But it certainly sounds like a question for Quora
  25. Unfortunately, this magazine has bitten the dust but they were gracious enough to have their entire back catalogue available for download. https://secure2.linuxjournal.com/pdf/dljdownload.php
×
×
  • Create New...