Example #1
0
 /**
  * Add a new timesheet
  *
  * Status will be overwritten
  */
 public function addTimesheet()
 {
     $newId = UniqueIDGenerator::getInstance()->getNextID(self::TIMESHEET_DB_TABLE_TIMESHEET, self::TIMESHEET_DB_FIELD_TIMESHEET_ID);
     $this->setTimesheetId($newId);
     if ($this->getStartDate() == '' || $this->getEndDate() == '') {
         $this->_getNewDates();
     }
     $this->setStatus(self::TIMESHEET_STATUS_NOT_SUBMITTED);
     $sql_builder = new SQLQBuilder();
     $insertTable = self::TIMESHEET_DB_TABLE_TIMESHEET;
     $insertFields[0] = "`" . self::TIMESHEET_DB_FIELD_TIMESHEET_ID . "`";
     $insertFields[1] = "`" . self::TIMESHEET_DB_FIELD_EMPLOYEE_ID . "`";
     $insertFields[2] = "`" . self::TIMESHEET_DB_FIELD_TIMESHEET_PERIOD_ID . "`";
     $insertFields[3] = "`" . self::TIMESHEET_DB_FIELD_START_DATE . "`";
     $insertFields[4] = "`" . self::TIMESHEET_DB_FIELD_END_DATE . "`";
     $insertFields[5] = "`" . self::TIMESHEET_DB_FIELD_STATUS . "`";
     $insertValues[0] = $this->getTimesheetId();
     $insertValues[1] = $this->getEmployeeId();
     $insertValues[2] = $this->getTimesheetPeriodId();
     $insertValues[3] = "'" . $this->getStartDate() . "'";
     $insertValues[4] = "'" . $this->getEndDate() . "'";
     $insertValues[5] = $this->getStatus();
     $insertValues = $sql_builder->quoteCorrect($insertValues);
     $query = $sql_builder->simpleInsert($insertTable, $insertValues, $insertFields);
     $dbConnection = new DMLFunctions();
     $result = $dbConnection->executeQuery($query);
     if ($result && mysql_affected_rows() > 0) {
         return true;
     }
     return false;
 }
 /**
  * Update project information
  */
 public function updateProject()
 {
     if ($this->_isDuplicateName(true)) {
         throw new ProjectsException("Duplicate name", 1);
     }
     $sql_builder = new SQLQBuilder();
     $updateTable = self::TABLE_NAME;
     if ($this->getCustomerId() != null) {
         $updateFields[] = "`" . self::PROJECT_DB_FIELD_CUSTOMER_ID . "`";
         $updateValues[] = "'" . $this->getCustomerId() . "'";
     }
     if ($this->getProjectName() != null) {
         $updateFields[] = "`" . self::PROJECT_DB_FIELD_NAME . "`";
         $updateValues[] = "'" . $this->getProjectName() . "'";
     }
     if ($this->getProjectDescription() != null) {
         $updateFields[] = "`" . self::PROJECT_DB_FIELD_DESCRIPTION . "`";
         $updateValues[] = "'" . $this->getProjectDescription() . "'";
     }
     if ($this->getDeleted() != null) {
         $updateFields[] = "`" . self::PROJECT_DB_FIELD_DELETED . "`";
         $updateValues[] = $this->getDeleted();
     }
     $updateConditions[] = "`" . self::PROJECT_DB_FIELD_PROJECT_ID . "` = {$this->getProjectId()}";
     if (is_array($updateFields)) {
         $updateValues = $sql_builder->quoteCorrect($updateValues);
         $sqlQString = $sql_builder->simpleUpdate($updateTable, $updateFields, $updateValues, $updateConditions);
         $dbConnection = new DMLFunctions();
         $message2 = $dbConnection->executeQuery($sqlQString);
         //Calling the addData() function
         // We don't check mysql_affected_rows here since the update may not have changed any
         // of the database fields.
         if ($message2) {
             return true;
         }
     }
     return false;
 }