Example #1
0
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */
require_once "Libs/autoload.php";
$config = new Config();
$webPage = new PJSWebPage($config->getTitle() . "Notes - Add Note");
$body = '';
$act = Tools::Param('act');
if ("Add Note" === $act) {
    $model = new NoteModel();
    $model->populateFromForm();
    if (!$model->validateForAdd()) {
        $view = new NoteFormView('Add Note', $model);
        $body = "<h2>Invalid data</h2>\n" . $view->getForm();
    } else {
        $noteController = new NoteController();
        $newId = $noteController->add($model);
        if ($newId > 0) {
            $body = "Added note # " . $newId . "<br />\n";
        }
    }
} else {
    $body = "";
    $noteModel = new NoteModel();
    $noteModel->setAppliesToTable(Tools::param('appliesToTable'));
    $noteModel->setAppliesToId(Tools::param('appliesToId'));
    $view = new NoteFormView("Add Note", $noteModel);
    $body = $view->getForm();
}
$webPage->setBody($body);
$webPage->displayPage();
Example #2
0
    /**
     * @param string $whereClause
     * @see ControllerBase::getSome()
     */
    public function getSome($whereClause = '1 = 1')
    {
        $sql = <<<SQL
SELECT id
     , appliesToTable
     , appliesToId
     , created
     , updated
     , noteText
  FROM note
 WHERE {$whereClause}
 ORDER
    BY updated
SQL;
        $stmt = $this->_dbh->prepare($sql);
        if (!$stmt) {
            throw new ControllerException('Failed to prepare SELECT statement. (' . $this->_dbh->error . ') from this SQL: ' . $sql);
        }
        if (!$stmt->execute()) {
            throw new ControllerException('Failed to execute SELECT statement. (' . $this->_dbh->error . ')');
        }
        $stmt->bind_result($id, $appliesToTable, $appliesToId, $created, $updated, $noteText);
        $models = array();
        while ($stmt->fetch()) {
            $model = new NoteModel();
            $model->setId($id);
            $model->setAppliesToTable($appliesToTable);
            $model->setAppliesToId($appliesToId);
            $model->setCreated($created);
            $model->setUpdated($updated);
            $model->setNoteText($noteText);
            $models[] = $model;
        }
        return $models;
    }