/**
  * Get {@link Foc} by the identifier 'id' found in the URL.
  * @return Foc {@link Foc} instance
  * @throws NotFoundException if the param or {@link Foc} instance is not found
  */
 public static function getFocByGetId()
 {
     $id = null;
     try {
         $id = self::getUrlParam('id');
     } catch (Exception $ex) {
         throw new NotFoundException('No Foc identifier provided.');
     }
     if (!is_numeric($id)) {
         throw new NotFoundException('Invalid Foc identifier provided.');
     }
     $dao = new FocDao();
     $foc = $dao->findById($id);
     if ($foc === null) {
         throw new NotFoundException('Unknown Foc identifier provided.');
     }
     return $foc;
 }
<?php

$foc = Utils::getFocByGetId();
$dao = new FocDao();
$dao->delete($foc->getId());
Flash::addFlash('User deleted successfully.');
Utils::redirect('list', array('status' => $foc->getStatus()));
示例#3
0
<?php

$status = Utils::getUrlParam('status');
FocValidator::validateStatus($status);
$dao = new FocDao();
$search = new FocSearchCriteria();
$search->setStatus($status);
// data for template
$title = Utils::capitalize($status) . 'Foc';
$foc = $dao->find($search);
$edit = array_key_exists('id', $_GET);
if ($edit) {
    $foc = Utils::getFocByGetId();
} else {
    // set defaults
    $foc = new Foc();
    $foc->setPriority(Foc::PRIORITY_MEDIUM);
    $dueOn = new DateTime("+1 day");
    $dueOn->setTime(0, 0, 0);
    $foc->setDueOn($dueOn);
}
if (array_key_exists('cancel', $_POST)) {
    // redirect
    Utils::redirect('detail', array('id' => $foc->getId()));
} elseif (array_key_exists('save', $_POST)) {
    // for security reasons, do not map the whole $_POST['foc']
    $data = array('username' => $_POST['foc']['username'], 'firsname' => $_POST['foc']['firsname'], 'lastname' => $_POST['foc']['lastname'], 'email' => $_POST['foc']['email'], 'password' => $_POST['foc']['password']);
    // map
    FocMapper::map($foc, $data);
    // validate
    $errors = FocValidator::validate($foc);
    // validate
    if (empty($errors)) {
        // save
        $dao = new FocDao();
        $foc = $dao->save($foc);
        Flash::addFlash('Changes saved successfully.');
        // redirect
        Utils::redirect('detail', array('id' => $foc->getId()));
    }
}
示例#5
0
$edit = array_key_exists('id', $_GET);
if ($edit) {
    $Users = Utils::getFocByGetId();
} else {
    // set defaults
    $Users = new Foc();
    $Users->setPriority(Foc::PRIORITY_MEDIUM);
    $dueOn = new DateTime("+1 day");
    $dueOn->setTime(0, 0, 0);
    $Users->setDueOn($dueOn);
}
if (array_key_exists('cancel', $_POST)) {
    // redirect
    Utils::redirect('detail', array('id' => $Users->getId()));
} elseif (array_key_exists('save', $_POST)) {
    // for security reasons, do not map the whole $_POST['foc']
    $data = array('username' => $_POST['Users']['username'], 'firsname' => $_POST['Users']['firsname'], 'lastname' => $_POST['Users']['lastname'], 'email' => $_POST['Users']['email'], 'password' => $_POST['Users']['password']);
    // map
    UsersMapper::map($Users, $data);
    // validate
    $errors = UsersValidator::validate($Users);
    // validate
    if (empty($errors)) {
        // save
        $dao = new FocDao();
        $Users = $dao->save($Users);
        Flash::addFlash('Changes saved successfully.');
        // redirect
        Utils::redirect('detail', array('id' => $Users->getId()));
    }
}