Beispiel #1
0
    /**
     * @param JobModel $model
     * @see ControllerBase::update()
     */
    public function update($model)
    {
        if ($model->validateForUpdate()) {
            try {
                $query = <<<SQL
UPDATE job
   SET primaryContactId = ?
     , companyId = ?
     , applicationStatusId = ?
     , lastStatusChange = ?
     , urgency = ?
     , nextActionDue = ?
     , nextAction = ?
     , positionTitle = ?
     , location = ?
     , url = ?
 WHERE id = ?
SQL;
                $id = $model->getId();
                $primaryContactId = $model->getPrimaryContactId();
                $companyId = $model->getCompanyId();
                $applicationStatusId = $model->getApplicationStatusId();
                $lastStatusChange = $model->getLastStatusChange();
                $urgency = $model->getUrgency();
                $nextActionDue = $model->getNextActionDue();
                $nextAction = $model->getNextAction();
                $positionTitle = $model->getPositionTitle();
                $location = $model->getLocation();
                $url = $model->getUrl();
                $stmt = $this->_dbh->prepare($query);
                if (!$stmt) {
                    throw new ControllerException('Prepared statement failed for ' . $query);
                }
                if (!$stmt->bind_param('iiisssssssi', $primaryContactId, $companyId, $applicationStatusId, $lastStatusChange, $urgency, $nextActionDue, $nextAction, $positionTitle, $location, $url, $id)) {
                    throw new ControllerException('Binding parameters for prepared statement failed.');
                }
                if (!$stmt->execute()) {
                    throw new ControllerException('Failed to execute UPDATE statement. (' . $this->_dbh->error . ')');
                }
                /**
                 * @SuppressWarnings checkAliases
                 */
                if (!$stmt->close()) {
                    throw new ControllerException('Something broke while trying to close the prepared statement.');
                }
                return $id;
            } catch (Exception $e) {
                throw new ControllerException($e->getMessage());
            }
        } else {
            throw new ControllerException("Invalid data.");
        }
    }
Beispiel #2
0
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along
 * with this program; if not, write to the Free Software Foundation, Inc.,
 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 *
 */
require_once "Libs/autoload.php";
$config = new Config();
$webPage = new PJSWebPage($config->getTitle() . ' - Edit Job');
$act = Tools::Param('act');
if ("Edit Job" === $act) {
    $jobModel = new JobModel();
    $jobModel->populateFromForm();
    if (!$jobModel->validateForUpdate()) {
        $view = new JobFormView('Edit Job', $jobModel);
        $body = "<h2>Invalid data</h2>\n" . $view->getForm();
    } else {
        $jobController = new JobController();
        $newId = $jobController->update($jobModel);
        if ($newId > 0) {
            $body = "Edited job # " . $newId . "<br />\n";
        }
    }
} else {
    $jobController = new JobController();
    $jobModel = $jobController->get(Tools::param('id'));
    $view = new JobFormView('Edit Job', $jobModel);
    $body = $view->getForm();
}