I'm wondering if perhaps I am doing this all wrong.. see for yourself:
Question:
- Does my OOP suck?
- is running multiple methods on a value {ie: strip_tags($copy->truncateString($articles[$i]['body'], 250, " "))} a terrible way to manage resources?
Should I create separate methods to use for the following line:
echo '<div class="summary"><a href="/' . BreadCrumbs::getCrumb(1) . '/'. BreadCrumbs::getCrumb(2) . '/article/' . $articles[$i]['id'] . '"><h5>' . $articles[$i]['title'] . '</h5></a> (' . $articles[$i]['date'] . ')<p>' . strip_tags($copy->truncateString($articles[$i]['body'], 250, " ")) . '</p><p><a href="/' . BreadCrumbs::getCrumb(1) . '/'. BreadCrumbs::getCrumb(2) . '/article/' . $articles[$i]['id'] . '"> Read more</a></p></div>';
Notes:
- pageTemplate is a class which will contain all html templats for this particular site
- Two static classes take care of site wide configuration variables (not seen here) and tracking the url (BreadCrumbs::).
- Calling BreadCrumbs::getCrumb(x) retrieves the 'value' at the x position of the url (ie: domain.com/"pos 1"/"pos 2"/"pos 3"). The values are managed at the top of the page and are checked if empty and replaced with a default value if they are.
- GetCopy is a class which has a number of functions designed to run a query (based on various parameters) and retrieves an array (or mulch-dimensional array). The function used below retrieves a mulch-dimensional array with each second level array containing a whole article.
GetCopy has a parent. It extends a class called CopyMan which contains various functions such as adding paragraphs to a block of text, truncating, converting date forms, and pagination tools. Called through the GetCopy object.
/** * homePage :: () * PUBLIC method * = lay out the home page content * */ public static function homePage() { // initialize GetCopy class $copy = new GetCopy(); // special feature container echo '<div id="special_box"><div class="special_header"><img src="/images/layout/special_header.png"></div><div class="special_container">'; $articles = $copy->getRows('articles', 'date', 0, 2); //print_r($articles); for ($i = 0; $i < count($articles); $i++) { echo '<div class="special_summary"><a href="/' . BreadCrumbs::getCrumb(1) . '/'. BreadCrumbs::getCrumb(2) . '/article/' . $articles[$i]['id'] . '"><h5>' . $articles[$i]['title'] . '</h5></a> (' . $articles[$i]['date'] . ')<p>' . strip_tags($copy->truncateString($articles[$i]['body'], 250, " ")) . '</p><p><a href="/' . BreadCrumbs::getCrumb(1) . '/'. BreadCrumbs::getCrumb(2) . '/article/' . $articles[$i]['id'] . '"> Read more</a></p></div>'; } echo '</div></div>'; }
EDIT: Just wanted to say thanks to those who have helped so far. I never went to university, took computer science, or ever worked in a team whereby I had a mentor. Learning everything on your own with no background to work from is hard, and its people like scrager and mseancole who become invaluable resources.
Further Information, to help provide insight:
-[Folder] Lib
-[Folder] bespoke
--> [Class] DisplayEngine
private static $instance;
public static function getInstance()
+ Methods for laying out divs.
--> [Class] PageTemplate
public function homePage()
-[Folder] copy
--> [Class] CopyMan
public function truncateString($string, $limit, $break='.', $pad='...')
public function convertToPara($string)
public function convertToLongDate($date)
protected function paginateList($table, $current_page, $list_length)
protected function setLimits($table, $page, $numArticles, $featured)
--> [Class] GetCopy extends CopyMan
require_once(Config::getAbsPath() . '/lib/omc_frmwrk/copy/CopyMan.php');
public function getFieldContents($table, $where_field, $where_match, $column)
public function getRow($table, $field_array, $where_field, $where_match)
public function getRows($table, $order_by, $limit_start, $limit_end)
public function getRowsWhere($table, $order_by, $where_field, $where_match, $limit_start, $limit_end)
-[Folder] database
--> [Class] DbMan
private static $db_host = Config::db_host;
private static $db_user = Config::db_user;
private static $db_pass = Config::db_pass;
private static $db_name = Config::db_name;
private $mysql_connection;
private $mysql_db;
private $query;
private $query_result;
private function dbConnect()
protected function executeQuery($query)
--> [Class] DbQuery extends DbMan
private $query;
public function prepareQuery($query_request)
-[Folder] helpers
--> [Class] ArrayHelp
public function recValueCheck($needle, $haystack)
public function recValueReturn($needle, $haystack)
-[Folder] layout
--> [Class] LogoMan
private static $site_logo;
public static function setSiteLogo($x) { self::$site_logo = $x; }
public function printLogo()
-[Folder] navigation
--> [Class] BreadCrumbs
private static $bread_crumbs;
private static $instance;
public static function getCrumbs() { return self::$bread_crumbs; }
public static function getCrumb($x) { return self::$bread_crumbs[$x]; }
public static function setCrumbs($x) { self::$bread_crumbs = explode("/", $x); }
public static function getInstance() { if (!self::$instance) { self::$instance = new self(); } return self::$instance; }
public static function setEmptyCrumb($crumb, $fallback)
--> [Class] NavMan
private static $links;
private static $nav_id;
public static function setLinks($x) { self::$links = $x; }
public static function setNavId($x) { self::$nav_id = $x; }
public function printNav($pre_link = "", $post_link = "")
--> [Class] Config
const db_host =
const db_user =
const db_pass =
const db_name =
private static $abs_path;
private static $include_css = array ()
private static $include_classes = array ()
private static $include_js = array ()
private static $site_logo = array ()
private static $nav_primary = array ()
private static $nav_secondary = array ()
+ Getters and Setters for all above
--> [Class] initialize
private static $include_css;
private static $include_classes;
private static $include_js;
public function __construct() //*sets session, runs include methods below *//
private function loadStylesheets()
private function loadRequiredClasses()
public function loadJavascript()