Jump to content

JonnoTheDev

Staff Alumni
  • Content Count

    3,584
  • Joined

  • Last visited

  • Days Won

    3

JonnoTheDev last won the day on April 16 2015

JonnoTheDev had the most liked content!

Community Reputation

19 Neutral

About JonnoTheDev

  • Rank
    Prolific Member
  • Birthday 04/29/1981

Profile Information

  • Gender
    Male
  • Location
    Liverpool, UK
  1. I can only see the need for 2 tables. A documents table and a document_types table. The documents table references the documents_type table by type_id I.e. documents ---------- doc_id type_id date_added doc_name document_types ---------- type_id type_title document_types would contain people, companies, and projects, and any other types. Each has an id and is used in a join from documents when you want to say fetch all company documents. 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.
  2. Here's a challenge for anyone using OOP so you can see how it benefits. I've started it off and you can see there are issues that need to be corrected. An online shop needs an order dispatch system for sending out parcels using different couriers. At the start of the day a batch will be started and at the end of the day it will be closed when no more parcels are going to be shipped. This is called the dispatch period. Each parcel sent out with a courier is called a consignment. Each consignment will be given a unique number and each courier will provide an algorithm for generating the number. At the end of the dispatch period a list of all consignment numbers need to be sent to each courier. Each courier has their own method for accepting the list i.e. UPS uses email, Fedex uses FTP. Build a structure using OOP to facilitate the implementation of the above scenario. It does not need to be a final product. Assume that your library is given to another developer to use who will build a front end for it that will have the following features: 1. Start a new batch 2. Add a consignment 3. End the batch /** * Interface CourierInterface */ interface CourierInterface { /** * Fetch a consignment number * @return int */ public function fetchConsignmentNumber(); /** * Dispatch a consignment number to a courier */ public function dispatch($number); } class FedexCourier implements CourierInterface { /** * @var int */ private static $count = 10000; /** * We will use a simple static counter here to return a number * @return int */ public function fetchConsignmentNumber() { self::$count++; return self::$count; } /** * Send to courier * @param $number * @return string */ public function dispatch($number) { } } class Consignment { /** * @var CourierInterface */ protected $courier; /** * @var int $number Should contain a consignment number */ protected $number; /** * Consignment constructor. * @param CourierInterface $courier */ public function __construct(CourierInterface $courier) { $this->courier = $courier; // fetch a consignment number from the courier $this->number = $this->courier->fetchConsignmentNumber(); } /** * Simple getter * @return int */ public function getNumber() { return $this->number; } /** * @return mixed */ public function process() { return $this->courier->dispatch($this->number); } } class Batch { /** * @var array */ protected $consignments = []; /** * Batch constructor. * Start the dispatch period * This could take in a storage dependency for persistence */ public function __construct() { } /** * Add a consignment to the current batch * * @param Consignment $consignment */ public function addConsignment(Consignment $consignment) { $this->consignments[] = $consignment; } /** * Process each consignment */ public function endDispatchPeriod() { // loop through each of the consignments // the storage dependency could be use here to track the consignment numbers // i.e. $c->getNumber() foreach ($this->consignments as $c) { $c->process(); } } } Client <?php // client code // start a new batch $batch = new Batch(); // add some consignments $parcel1 = new Consignment(new FedexCourier()); $batch->addConsignment($parcel1); $parcel2 = new Consignment(new FedexCourier()); $batch->addConsignment($parcel2); // end the batch $batch->endDispatchPeriod(); ?>
  3. You are using PHP 4 syntax that is obsolete. You should not use the var keyword, nor should you give a method the same name as the class. In PHP 4 this was how you defined the constructor. I suggest you read up on how to use classes in PHP 5. Refactored <?php class Customer extends VerySimpleModel implements TemplateVariable { public static $meta = array( 'table' => CUST_TABLE, 'pk' => array( 'cust_id' ), 'joins' => array( 'location' => array( 'constraint' => array( 'cust_id' => 'loc.cust_id' ), ), 'service' => array( 'constraint' => array( 'service_level' => 'service.id' ), ), ), ); public $id; public $name; public $contact; public $fname; public $lname; public $contact_phone; public $phone_number; public $fax_number; public $location; public $domain; public $service_level; public $row; public $address; private $_location = null; public function getCustomer( $id = 0 ) { echo 'here'; $this->id=0; if($id && ($info=$this->getInfoById($id)) ){ $this->row=$info; $this->id=$info["id"]; $this->name=$info["cust_name"]; $this->domain=$info["domain"]; $this->location=$this->getLocationInfo($id); $this->service_level=$info["service_level"]; } } } //page that is loading the Grid data $custs = Customer::objects();
  4. Have a look here https://github.com/ziadoz/awesome-php Most of these will be available through packagist
  5. Legend! Had to make a slight mod as, 'quantity' was ambiguous. I owe you a pint, cheers! SELECT product_model_id,model_code,GROUP_CONCAT(qty, ':', total_ordered ORDER BY qty ASC) AS qty_orders FROM product_model LEFT JOIN ( SELECT product_model_id, quantity AS qty, COUNT(op_id) AS total_ordered FROM order_product GROUP BY product_model_id, qty ) AS sq USING (product_model_id) GROUP BY product_model_id;
  6. I am trying to generate a report that will assist a client in determining price changes for their products. The query I need to use is bugging the hell out of me. I have extracted a portion of it as the other parts are irrelevant. What I am trying to do is display the number of times a product has been ordered of a certain quantity. I am attempting to concatenate the quantity with the number ordered. i.e. product_model_id model_code qty_orders ---------------------- --------------- ------------- 12 12345 1:32,2:12,3:2 So for the above product (12) the following info is returned A quantity of 1 has been ordered 32 times A quantity of 2 has been ordered 12 times A quantity of 3 has been ordered 2 times I can pull the qty_orders data out without issue by specifying the id of the product, however I need to display for all products including the additional information (product_model_id, model_code). Here is the database structure: product_model ------------- product_model_id model_code order_product ------------- op_id order_id product_model_id quantity I know that I need to do the sub query within a join but I can't get it quite right. Here is the part I have down. I need to get rid of the WHERE product_model_id=12 bit and create a join to product_model so I can display all products. SELECT GROUP_CONCAT(quantity, ':', total_ordered) AS qty_orders FROM ( SELECT quantity, COUNT(op_id) AS total_ordered FROM order_product WHERE product_model_id=12 GROUP BY quantity ) AS sq Complex SQL isn't really my forte so any help would be appreciated.
  7. 1. Remove any PHP / Server Side code 2. Strip out any <img> tags 3. Strip out any <script> tags 4. Strip out any <link> tags to CSS files Job done. Should run like lightning!
  8. Also consider Yii http://www.yiiframework.com/
  9. I would hate managers being there. In my old place we would go out for lunch on a Friday. This was prime time to bitch and slag off all the overpaid managers who did f*** all!
  10. This made me laugh. It reminds me of mission control at NASA or some NSA type Kiefer Sutherland Jack Bower 24 episode.
  11. Some nice offices. Mine's a bit of a tip at the moment.
  12. For dedicated servers I would like to add OVH http://www.ovh.co.uk/products/dedicated_offers.xml We have about 5 of these servers running CentOS.
  13. The IT team are probably on strike!
  14. I was speaking to a rep from RM last week. The data will be released. I think they are still working on how to make it accessible.
  15. The Royal Mail database will soon be open source as part of government legislation. It was set to be open as of April this year, however I have not checked it out. http://news.bbc.co.uk/1/hi/technology/8402327.stm I recently went to a conference where the following were doing a presentation on using postcode data. It is a paid service, but check it out. I have used before and it's easy to implement. http://www.postcodeanywhere.co.uk/
×
×
  • 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.