Jump to content

ignace

Moderators
  • Posts

    6,457
  • Joined

  • Last visited

  • Days Won

    26

Everything posted by ignace

  1. Calling date without parameter returns a nice warning: "date() expects at least 1 parameter"
  2. Passing Registry objects to constructor's is a sign of poor understanding of the problem the pattern is solving or how to apply it. I even doubt that in your current case you actually even need the pattern as Registry, Singleton and the like should be your last resort, and even then..
  3. I'm not sure which CMS systems already support these functionalities, maybe: Dokeos or Moodle? The assignment seems simple to me so you could write it in PHP without using a framework. Actually I would advise you to use a framework only when you absolutely have to, like when your application has to be portable across multiple RDBMS vendors. You could write this yourself of course but framework's were created to save time.
  4. Have a file on your server that holds the latest version info (eg version.txt) If you only have a version number (eg 1.5.1b) then a text-file should suffice otherwise if you have more information that needs to be checked (eg modules compatibility, ..) then I would opt for a XML-file. Patching would be done through either packages or live patches from your source-control system.
  5. Aren't all websites multi-user collaborative?
  6. $form = new SavePreviewForm(); if($this->getRequest()->isPost()) { if($form->isValid($this->getRequest()->getPost()) { if($form->isPreviewClicked()) { /* code to handle preview */ } if($form->isSaveClicked()) { /* code to handle save */ } } }
  7. I have posted 2 other solutions besides the Registry, perhaps you missed those?
  8. Nope all you need is to write a class that implements Zend_Db_Adapter_Abstract and implement the abstract methods (+-14).
  9. $str = implode('-', array_slice(explode('-', $str), 0, 5));
  10. class SavePreviewForm extends Zend_Form { public function isPreviewClicked() { return $this->getElement(self::PREVIEW)->isChecked(); } public function isSaveClicked() { return $this->getElement(self::SAVE)->isChecked(); } }
  11. Indeed. You shouldn't be storing the files but their contents. If someone uploads in docx format only those with Office 2010 can actually open the file. Read out the file contents, store those into the database and let the user choose the format prior to downloading the document.
  12. You could take a look at the other libs for inspiration DB is so common that the implementation can almost be called a pattern.
  13. Or you write them using an if/else structure or using an OO-structure: class QueryObject { private $where = array(); public function reset() { $this->where = array(); } public function zipCodeIs($zipCode) { $this->where[] = 'zipcode = ' . $zipCode; } public function usernameIs($username) { $this->where[] = 'username = ' . $username; } public function genderIs($gender) { $this->where[] = 'gender = ' . $gender; } public function execute() { return $this->adapter->query('SELECT ' . $this->columns . ' FROM ' . $this->table . ' WHERE ' . $this->_generateWhereClause()); } protected function _generateWhereClause() { return implode(' AND ', $this->where); } } The QueryObject is a pattern defined by Martin Fowler, this is a very loosely based implementation of that pattern as it doesn't abstract the actual query. Doctrine implements this perfectly where you can use your models properties in place-of your column names also called DQL (Doctrine Query Language): SELECT Users.* FROM Users The advantage is that your actual column names can be changed without having to alter the code.
  14. Luckily books are still available in print and PDF, I would probably stop reading books if they ever switch to PDF-only.
  15. It's called pagination. MySQL has 2 convenient "tools": SQL_CALC_FOUND_ROWS and found_rows() for use with pagination. SELECT SQL_CALC_FOUND_ROWS .. FROM .. WHERE .. LIMIT $offset, $count SQL_CALC_FOUND_ROWS hints MySQL to keep a total of all rows in the result set to be retrieved with found_rows(). SELECT found_rows() Returns the total rows in the result set as if the query was executed without the LIMIT-clause. This query has to be followed directly after SQL_CALC_FOUND_ROWS. $totalPages = ceil($foundRows / $count); You calculate the offset from the page number using the below formula: ($page - 1) * $count Where $page >= 1 and $count > 0
  16. If you are throwing this through a function you may aswell just use JSONP: <script type="text/javascript" src="script.php?callback=jsFunction&arg1=value1&arg2=.."></script> jsFunction({"1":"Miami Heat","2":"Orlando Magic ","3":"Oklahoma City Thunder","4":"Tampa Bay Lightning ","5":"Colorado Avalanche","6":"Minnesota Wild","7":"Boston Red Sox","8":"Chicago White Sox ", "9":"New York Mets ", "10":"Philadelphia Phillies "}); JSONP means "JSON with Padding" where padding is the callback function, all you need to do is prepend the callback (jsFunction) and upon calling the script (src="..") it will be executed like regular JS, your PHP would look like: echo $callback, '(', json_encode($array), ');'; // jsFunction(..);
  17. define('EXP_MODIFIER', 200); function getExperience($level) { if($level > 70) $level = 70; return $level * EXP_MODIFIER; } function getLevel($experience) { if($experience < 0) $experience = 0; return ceil($experience / 200); } What should getMaxExperience() do? You are going to have to tell us some details about these functions and what you want them to do.
  18. What do you think Post/Redirect/Get implies?
  19. json_encode echo json_encode(array(1 => 'Miami', 2 => 'Magic' 4 => 'Thunder' 5 => 'Lightning' 6 => 'Avalanche' 8 => 'Red Sox' 9 => 'White Sox' ));
  20. CREATE TABLE categories ( category_id SMALLINT UNSIGNED NOT NULL AUTO_INCREMENT, category_name VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, PRIMARY KEY (category_id) ) ENGINE=INNODB; CREATE TABLE items ( item_id INT UNSIGNED NOT NULL AUTO_INCREMENT, category_id SMALLINT UNSIGNED NOT NULL, item_name VARCHAR(32) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, item_price DECIMAL(5,2) UNSIGNED NOT NULL, item_description VARCHAR(255) CHARACTER SET utf8 COLLATE utf8_general_ci NOT NULL, item_image BLOB NOT NULL, item_stock SMALLINT UNSIGNED NOT NULL, item_time DATETIME NOT NULL, PRIMARY KEY (item_id), FOREIGN KEY (category_id) REFERENCES categories (category_id) ) ENGINE=INNODB; If there is any information specific to some item create a new table and let it hold a reference to the items table.
  21. SELECT player, score FROM ( SELECT concat(users.first_name, ' ', users.last_name) AS player, sum(scores.score) AS score FROM users JOIN scores ON users.id = scores.user_id GROUP BY player ) AS scoreboard ORDER BY score DESC Not the most efficient way as MySQL will use a temporary table for the sorting, but it will point you in the right direction. I wonder if the below would work: SELECT concat(users.first_name, ' ', users.last_name) AS player, sum(scores.score) AS score FROM users JOIN scores ON users.id = scores.user_id GROUP BY player ORDER BY sum(scores.score) DESC
  22. Using David's proposal you won't even notice that their is a script running so to speak, in contrast to using explode and file which would pull the entire file contents into memory.
×
×
  • 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.