Jump to content

kn0wl3dg3

Members
  • Posts

    61
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

kn0wl3dg3's Achievements

Member

Member (2/5)

0

Reputation

  1. That was my plan, or kind of, but I would have done it wrong by your example. I planned on adding AdoDB as an abstraction layer, but it sounds like you mean more than that. Pretty much all my properties except for the totals are retrieved from the db so what would the report class actually do if the ReportModel does all that? I'm going to read those links; maybe the answer is in there. Onward and upward.. Thanks
  2. Is this a better attempt? I know it's not what you guys are suggesting, and I do want to do it the right way, I just realized there was more basic things that I was getting wrong, and want to correct those mistakes first...baby steps. So aside from not doing a composite class or collection yet, is this a better version? Are my basics right here? Thanks guys, I can't tell you how much I appreciate the time <?php require_once('class_Employer.php'); class Report { public $Employer; // Employer object* // Activations protected $employeesactivations; // total number of activated employees* protected $familyactivations; // total number of activated family members* // User Counts protected $employeecount; // count of users using system* protected $familycount; // count of family members using system* protected $malecount; // count of male users* protected $femalecount; // count of female users* protected $unansweredcount; // count of unanswered users* // Logins protected $employeelogins; // count of employee logins* protected $familylogins; // count of family logins* protected $malelogins; // count of male user logins* protected $femalelogins; // count of female user logins* protected $unansweredlogins; // count of unanswered user logins* // MISC public $error = false; // error message* public function __construct($id) { $this->Employer = new Employer($id); $this->setEmployeeCount(); $this->setFamilyCount(); $this->setEmployeeLogins(); $this->setFamilyLogins(); $this->setEmployeeActivations(); $this->setFamilyActivations(); $this->setMaleLoginCount(); $this->setFemaleLoginCount(); $this->setUnansweredLoginCount(); $this->setMaleUserCount(); $this->setFemaleUserCount(); $this->setUnansweredUserCount(); } // general public function error($message = "") { if ($message != "") {$this->error = $message;} return $this->error; } private function queryDB($sql) { // this will ultimitaely be replaced with a class such as MySQLi or abstraction layer such as AdoDB $res = mysql_query($sql); // if theres no result, set error message and return false; otherwise return the result if (!$res) {$this->error = "Could not access database: ".mysql_error(); return false;} return $res; } // topics // get $limit most popular topics public function getPopularTopics($limit) { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) {$this->error = "There was a problem with the database"; return false;} while ($row = mysql_fetch_assoc($res)) { $topics[] = $row['Category']; } return $topics; } // user counts private function setEmployeeCount() { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->employeecount = $row[0]; } public function getEmployeeCount() { return $this->employeecount; } private function setFamilyCount() { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->familycount = $row[0]; } public function getFamilyCount() { return $this->familycount; } public function getTotalUserCount() { return $this->employeecount + $this->familycount; } private function setMaleUserCount() { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->malecount = $row[0]; } public function getMaleUserCount() { return $this->malecount; } private function setFemaleUserCount() { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->femalecount = $row[0]; } public function getFemaleUserCount() { return $this->femalecount; } private function setUnansweredUserCount() { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->unansweredcount = $row[0]; } public function getUnansweredUserCount() { return $this->unansweredcount; } // logins private function setEmployeeLogins() { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->employeelogins = $row[0]; } public function getEmployeeLogins() { return $this->employeelogins; } private function setFamilyLogins() { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->familylogins = $row[0]; } public function getFamilyLogins() { return $this->familylogins; } public function getTotalLogins() { return $this->employeelogins + $this->familylogins; } private function setMaleLoginCount() { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->malelogins = $row[0]; } public function getMaleLogins() { return $this->malelogins; } private function setFemaleLoginCount() { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->femalelogins = $row[0]; } public function getFemaleLogins() { return $this->femalelogins; } private function setUnansweredLoginCount() { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->unansweredlogins = $row[0]; } public function getUnansweredLogins() { return $this->unansweredlogins; } // activations private function setEmployeeActivations() { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->employeeactivations = $row[0]; } public function getEmployeeActivations() { return $this->employeeactivations; } private function setFamilyActivations() { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->familyactivations = $row[0]; } public function getFamilyActivations() { return $this->familyactivations; } public function getTotalActivations() { return $this->employeeactivations + $this->familyactivations; } public function getActivationList() { $sql = "*******"; if (($res = $this->queryDB($sql)) === false) return false; while ($row = mysql_fetch_assoc($res)) { $status = ($row['UserName'] != "") ? "Activated" : "Not activated" ; $activationlist[] = "$row[F_Name] $row[L_Name] - $status"; } return $activationlist; } } ?>
  3. @ignace: in regards to your example- I understand what you're getting at I'm excited to say. The actual implementation of that understanding is a totally different thing right now though :-\ I get what you mean, but doubt I could do it yet. I'm afraid this is all a bit above me still. I'm excited to learn it though. @Nightslyr: can you explain this a little bit? Oh, and I stopped last night at my local book store to get that book and they don't carry it, gotta order it online Big Chain Store my ass
  4. Aww, I see. That makes sense Not sure I follow. The report was supposed to build itself, then I could call different properties where I wanted to display them. That way, I could only get things from the report to show, but all the building of it was done internally. I'm taking it thats not the correct way..or at least I didn't accomplish that
  5. Whoa, sensory overload. I'm going to have to read through these a few times to get what you guys are throwing down Ok, @ignace, I don't know what to say yet, I need to look through that post alot closer @Nightslyr, same thing, but I can explain one thing. A user has an admin status set in the db, either 1 or 0, 1 means they are an admin. If they are, they get access to the reporting dashboard. Each User is associated with an Employer with a fk in the db. That would be the id sent into the class in my code. When they entered the dashboard, I would use the employer id for the company they work for to produce the report. Does that change your thoughts or am I still ass-backwards? Lol And here: This is what brought up my original question. I thought it was better to expose the one function getProperty instead of all the getters/setters. You're saying I'm doing it wrong though is what I'm hearing
  6. Ok, here's what I had when I came on today with my original question. It's what I thought I should be doing. A little primer: the purpose of our site is for a company to offer this for they're employees and families to use. This report would show usage for that company. Let me have it (keep in mind it was a first draft, not something that is meant to go immediately into a live environment) Thanks <?php require_once('employer.class.php'); class Report { public $Employer; // Employer object - holds db id, name, contact info, etc.* // Activations protected $employeesactivations; // total number of activated employees* protected $familyactivations; // total number of activated family members* protected $totalactivations; // total number of activated employees and family* protected $activationlist; // list of users and activation status* // User Counts protected $employeecount; // count of users using system* protected $familycount; // count of family members using system* protected $totalcount; // employees and family members* protected $malecount; // count of male users* protected $femalecount; // count of female users* protected $unansweredcount; // count of unanswered users* // Logins protected $totallogins; // employees and family members* protected $employeelogins; // count of employee logins* protected $familylogins; // count of family logins* protected $malelogins; // count of male user logins* protected $femalelogins; // count of female user logins* protected $unansweredlogins; // count of unanswered user logins* // MISC protected $populartopics; // Most clicked on topics* public $error = false; // error message* public function __construct($id) { $this->Employer = new Employer($id); $this->setPopularTopics(5); $this->setEmployeeCount(); $this->setFamilyCount(); $this->setTotalUserCount(); $this->setEmployeeLogins(); $this->setFamilyLogins(); $this->setTotalLogins(); $this->setEmployeeActivations(); $this->setFamilyActivations(); $this->setTotalActivations(); $this->setActivationList(); $this->setMaleLoginCount(); $this->setFemaleLoginCount(); $this->setUnansweredLoginCount(); $this->setMaleUserCount(); $this->setFemaleUserCount(); $this->setUnansweredUserCount(); } public function setProperty($prop, $value) { $prop = strtolower($prop); $this->$prop = $value; } public function getProperty($prop) { $prop = strtolower($prop); return $this->$prop; } public function error($message = "") { if ($message != "") {$this->error = $message;} return $this->error; } private function queryDB($sql) { // this will ultimitaely be replaced with a class such as MySQLi or abstraction layer such as AdoDB $res = mysql_query($sql); // if theres no result, set error message and return false; otherwise return the result if (!$res) {$this->error = "Could not access database: ".mysql_error(); return false;} return $res; } private function setPopularTopics($limit) { $sql = "********"; if (($res = $this->queryDB($sql)) === false) {$this->error = "There was a problem with the database"; return false;} while ($row = mysql_fetch_assoc($res)) { $this->populartopics[] = $row['Category']; } } private function setEmployeeCount() { $sql = "********"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->setProperty('employeecount',$row[0]); } private function setFamilyCount() { $sql = "********"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->setProperty('familycount',$row[0]); } private function setTotalUserCount() { $this->setProperty('totalcount', $this->employeecount + $this->familycount); } private function setEmployeeLogins() { $sql = "********"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->setProperty('employeelogins',$row[0]); } private function setFamilyLogins() { $sql = "********"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->setProperty('familylogins',$row[0]); } private function setTotalLogins() { $this->setProperty('totallogins', $this->employeelogins + $this->familylogins); } private function setEmployeeActivations() { $sql = "********"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->setProperty('employeeactivations',$row[0]); } private function setFamilyActivations() { $sql = "********"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->setProperty('familyactivations',$row[0]); } private function setTotalActivations() { $this->setProperty('totalactivations', $this->employeeactivations + $this->familyactivations); } private function setActivationList() { $sql = "********"; if (($res = $this->queryDB($sql)) === false) return false; while ($row = mysql_fetch_assoc($res)) { $status = ($row['UserName'] != "") ? "Activated" : "Not activated" ; $this->activationlist[] = "$row[F_Name] $row[L_Name] - $status"; } } private function setMaleLoginCount() { $sql = "********"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->setProperty('malelogins',$row[0]); } private function setFemaleLoginCount() { $sql = "********"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->setProperty('femalelogins',$row[0]); } private function setUnansweredLoginCount() { $sql = "********"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->setProperty('unansweredlogins',$row[0]); } private function setMaleUserCount() { $sql = "********"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->setProperty('malecount',$row[0]); } private function setFemaleUserCount() { $sql = "********"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->setProperty('femalecount',$row[0]); } private function setUnansweredUserCount() { $sql = "********"; if (($res = $this->queryDB($sql)) === false) return false; $row = mysql_fetch_row($res); $this->setProperty('unansweredcount',$row[0]); } // THERE WOULD BE MORE FUNCTIONALITY ADDED HERE, BUT YOU CAN SEE WHERE THIS IS HEADING } ?>
  7. You know what I meant But that was a dense question in retrospect
  8. Tell me about it If I tried this, would you be willing to look at it and tell me where I'm going wrong and how to fix it?
  9. I'm not sure, that's the part I'm having trouble recognizing I think. I would like to try it on a basic usage report, just telling an employer how many people are using the site, what topics they go to, etc. That was actually one of the examples used in an article (not that particular game). I do understand that part. Maybe thats part of the problem with the examples I'm finding; they're too perfect, or obvious maybe. Going to do that! Thanks
  10. Ok, I read a couple of articles on Composite classes. To my understanding, it's basically just an array of objects in another object, written in such a way that method calls behave the same for all objects in the list. i.e. a call to display() will determine how to get there depending on the object it's called on, but will always result in something being displayed to screen (for example). Am I on course? I understand the examples used in the articles (book shelves and to-do lists), but am having trouble seeing how this would be used for a report, and how I would set it up. Maybe that's my biggest issue, I don't really know how to "see" objects, or think that way. Any suggestions? Thanks for the help, I appreciate it
  11. Ok, that makes sense. So I'm not too far off base on my reasoning there. I feel there's a very important hint in there somewhere...
  12. I'll check it out thanks. I have those too, which led to researching the question "why all these methods" and the quote I posted. Ie. why write functions get_name, get_id, get_something_else, set_name, set_id, set_something_else when it could be done getProperty('name, id or whatever here') setProperty('name, id or whatever here') You always hear people saying "you should write a function to do that" so it just seemed counter-intuitive to write out so many functions that do the same thing just to different properties. I hope I'm stating my confusion clearly. Alot of things hold that much data, think of a recipe for example, or a report. A recipe would have more than 10 properties that I can think of offhand, that just store info. I don't see how breaking that up into other classes would be useful. A report would be different. It would need to take all kindfs of data and perform processes on them. I can see where breaking it out then would help. I'm not arguing, I swear! Just trying to learn the proper way to do things. Thanks so much for your helpful response.
  13. Is this an accurate statement? Even if there's like 20+ properties? That would be 40+ methods and that's not including doing anything with those properties but setting/getting. That sounds...I don't know...against the grain.
  14. I knew that just don't know why it is. I get the difference between visibilities. I just thought by extending Class A, I would be able to use a method from class A on Class B. But I think I get what your saying. Even though I extended A, class B still considers A to be an outside class and therefore wouldn't allow access to B's private property? I thought by extending it I could use it; that's where my confusion lies.
×
×
  • 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.