Jump to content

New to OOP - When does a Method get set?


cybertick

Recommended Posts

 

I am trying to insert the current Date/Time into mysql database using the following code.

 

I do not understand how $submitDate &  $submitTime are to be set.

 

Will this work as coded?

 

 
<?php

class SubmitDateRecord {

  const DB_TABLE = 'timesheet';
const DB_FIELD_SUBMIT_TIME = 'submit_time';


private $submitDate;
private $submitTime;


public function setSubmitDate($submitDate) {
    $this->submitDate = $submitDate;
}

public function getSubmitDate() {
    return $this->submitDate;
}

public function setSubmitTime($submitTime) {
    $this->submitTime = $submitTime;
}

public function getSubmitTime() {
    return $this->submitTime;
}



public function addRecord() {

   	$insertTable = "`".self::DB_TABLE."`";
       
	$insertFields[] = "`".self::DB_FIELD_SUBMIT_TIME."`";

	$insertValues[] = "'{$this->submitDate} {$this->submitTime}'";
           

	$sqlBuilder = new SQLQBuilder();
	$query = $sqlBuilder->simpleInsert($insertTable, $insertValues, $insertFields);

	$dbConnection = new DMLFunctions();
	$result = $dbConnection->executeQuery($query);

	if ($result) {
	    return true;
	} else {
	    return false;
	}

}


private function _buildRecordObjects($result) {

	while ($row = mysql_fetch_array($result)) {

		$submitdateObj = new SubmitDateRecord();

		$submitdateObj->setAttendanceId($row['attendance_id']);
		$submitdateObj->setEmployeeId($row['employee_id']);

		/* $row['submit_time'] comes in '0000-00-00 00:00:00' format.
		 * We want date in '0000-00-00' format and time in '00:00' format.
		 */
		$tmpArr = explode(' ', $row['submit_time']);
		$submitdateObj->setSubmitDate($tmpArr[0]);
		$submitdateObj->setSubmitTime(substr($tmpArr[1], 0, 5)); // Omiting 'seconds' part is ok since it is always zero








		$submitdateObj->setStatus($row['status']);



		$submitdateArr[] = $submitdateObj;

	}

	return $submitdateArr;

}

}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.