Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7062877
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:38:49+00:00 2026-05-28T04:38:49+00:00

I just want to know if I’m on the right path. Making most functions

  • 0

I just want to know if I’m on the right path. Making most functions abstract didn’t seem necessary as the data is just about the same. Is this an invalid approach?

<?php

    abstract class Model_Tasks {

        /**
         * Database object
         *
         * @access  protected
         */
        protected $db;

        /**
         * User ID
         *
         * @access  protected
         */
        protected $uid;

        /**
         * Data array
         *
         * @access  protected
         */
        protected $data;

        /**
         * SQL Query
         *
         * @access  protected
         */
        protected $query;

        /**
         * __construct
         *
         * @access  protected
         */
        protected function __construct($query) {
            $this->db = Model_DB::getInstance();
            $this->uid = $_SESSION['uid'];

            $this->query = $query;
            $this->getTasks();
        }

        /**
         * getTasks
         *
         * @param   string
         * @access  abstract protected
         */
        protected function getTasks() {
            $result = $this->db->prepare($this->query);
            $result->execute(array(
                ':uid' => $this->uid
            ));
            $this->data =& $result->fetchAll();
            $this->taskCount = $result->rowCount();
        }

        /**
         * constructTask
         *
         * Build the HTML of a task
         *
         * @param   int
         * @param   int
         * @param   string
         * @param   string
         * @access  protected
         */
        protected function constructTask(
            $id, $cost, $title, $checked = 0
        ) {
            $cost = money_format('$%i', $cost);
            $title = stripslashes($title);

            return '
                <label class="task">
                    <input type="checkbox" name="done[]" rel="'.$id.'" '.($checked?'checked="checked"':'').' />
                    <code>'.$cost.'</code> &mdash; '.$title.'
                </label>'."\n";
        }

        /** 
         * generateOutput
         *
         * Call by key [pending, completed] and return the constructed tasks
         *
         * @param   bool
         * @access  final public
         */
        final public function generateOutput($checked) {

            try {
                if(!is_bool($checked)) throw new Exception('generateOutput must contain a boolean variable');

                if(!isset($this->data)) throw new Exception('Array has not been set.');
                else $data = $this->data;
            } catch(Exception $e) {
                die('<pre>'.$e->getMessage().'<hr />'.$e->getTraceAsString());
            }

            if(is_array($data)): foreach($data AS &$r)
                $str .= $this->constructTask($r['id'], $r['cost'], $r['title'], $checked);

            else:
                $str = '<label class="tasks"></label>';

            endif;

            return $str;
        }
    }

    // ------------------------------------------------------------------------

    /**
     * pendingTasks
     *
     * @access  public
     */
    class pendingTasks extends Model_Tasks {

        public $taskCount;

        public function __construct() {
            $query = '
                SELECT id, title, cost
                FROM tasks
                WHERE (
                    status IS FALSE
                    AND uid = :uid
                ) ORDER BY cost DESC
            ';

            parent::__construct($query);
        }
    }

    /**
     * completedTasks
     *
     * @access  public
     */
    class completedTasks extends Model_Tasks {

        public function __construct() {
            $query = '
                SELECT id, title, cost
                FROM tasks
                WHERE (
                    status IS TRUE
                    AND uid = :uid
                ) ORDER BY id DESC
                LIMIT 7
            ';

            parent::__construct($query);
        }
    }

All it does is to print out a task with a specific query, and return an associative array.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:38:49+00:00Added an answer on May 28, 2026 at 4:38 am

    “Is this an invalid approach?”

    No. Your code is using abstract correctly. You are able to centralize common logic, but by declaring the parent class as abstract, you are forcing the instantiation of the class to be done via a child class (extends your abstract, parent class), which works well.

    Piece of advice:

    $this->uid = $_SESSION['uid'];
    

    Declaring member variables in this fashion breaks encapsulation. I’d advise you to assign member variables like this via your calling code, and not in your constructor.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i just want to know about the files and folder structure for a site
i just want to know a general information about this particular information. Any good
I just want to know a easy way to extract all data with same
I just want to know what is your opinion about how to fingerprint/verify html/links
Just want to know how to read an attribute of a parent node from
I just want to know: How can I delete 'log.txt' if the last modification
I just want to know how does the table resulting from readXML look like,
I just want to know if there is a program that can convert an
i just want to know how the call hierarchy is implemented in eclipse IDE
I just want to know where am i wrong here: import java.io.*; class Tokens{

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.