public function fetchAll() { $this->buildStart(); $this->build(); $this->buildStat(); $results = array(); while ($data = $this->stat->fetch()) { $ecm = new AreaCommentModel(); $ecm->setFromDataBaseRow($data); $results[] = $ecm; } return $results; }
public function update(AreaCommentModel $areacomment, $fields, UserAccountModel $user = null) { $alreadyInTransaction = $this->db->inTransaction(); // Make Information Data $fieldsSQL1 = array(); $fieldsParams1 = array('id' => $areacomment->getId()); foreach ($fields as $field) { $fieldsSQL1[] = " " . $field . "=:" . $field . " "; if ($field == 'title') { $fieldsParams1['title'] = substr($areacomment->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED); } else { if ($field == 'comment') { $fieldsParams1['comment'] = $areacomment->getDescription(); } else { if ($field == 'is_deleted') { $fieldsParams1['is_deleted'] = $areacomment->getIsDeleted() ? 1 : 0; } else { if ($field == 'is_closed_by_admin') { $fieldsParams1['is_closed_by_admin'] = $areacomment->getIsClosedByAdmin() ? 1 : 0; } } } } } // Make History Data $fieldsSQL2 = array('area_comment_id', 'user_account_id', 'created_at', 'approved_at'); $fieldsSQLParams2 = array(':area_comment_id', ':user_account_id', ':created_at', ':approved_at'); $fieldsParams2 = array('area_comment_id' => $areacomment->getId(), 'user_account_id' => $user ? $user->getId() : null, 'created_at' => $this->timesource->getFormattedForDataBase(), 'approved_at' => $this->timesource->getFormattedForDataBase()); foreach ($this->possibleFields as $field) { if (in_array($field, $fields) || $field == 'title') { $fieldsSQL2[] = " " . $field . " "; $fieldsSQLParams2[] = " :" . $field . " "; if ($field == 'title') { $fieldsParams2['title'] = substr($areacomment->getTitle(), 0, VARCHAR_COLUMN_LENGTH_USED); } else { if ($field == 'comment') { $fieldsParams2['comment'] = $areacomment->getDescription(); } else { if ($field == 'is_deleted') { $fieldsParams2['is_deleted'] = $areacomment->getIsDeleted() ? 1 : 0; } else { if ($field == 'is_closed_by_admin') { $fieldsParams2['is_closed_by_admin'] = $areacomment->getIsClosedByAdmin() ? 1 : 0; } } } } $fieldsSQL2[] = " " . $field . "_changed "; $fieldsSQLParams2[] = " 0 "; } else { $fieldsSQL2[] = " " . $field . "_changed "; $fieldsSQLParams2[] = " -2 "; } } try { if (!$alreadyInTransaction) { $this->db->beginTransaction(); } // Information SQL $stat = $this->db->prepare("UPDATE area_comment_information SET " . implode(",", $fieldsSQL1) . " WHERE id=:id"); $stat->execute($fieldsParams1); // History SQL $stat = $this->db->prepare("INSERT INTO area_comment_history (" . implode(",", $fieldsSQL2) . ") VALUES (" . implode(",", $fieldsSQLParams2) . ")"); $stat->execute($fieldsParams2); if (!$alreadyInTransaction) { $this->db->commit(); } } catch (Exception $e) { if (!$alreadyInTransaction) { $this->db->rollBack(); } throw $e; } }
public function uncloseByAdmin(AreaCommentModel $areaCommentModel, UserAccountModel $user) { global $DB; try { $DB->beginTransaction(); $areaCommentModel->setIsClosedByAdmin(false); $this->areaCommentDBAccess->update($areaCommentModel, array('is_closed_by_admin'), $user); $DB->commit(); } catch (Exception $e) { $DB->rollBack(); } }