예제 #1
0
    /**
     * @param JobModel $model
     */
    public function add($model)
    {
        if ($model->validateForAdd()) {
            try {
                $query = <<<SQL
INSERT job
     ( id
     , primaryContactId
     , companyId
     , applicationStatusId
     , lastStatusChange
     , urgency
     , created
     , updated
     , nextActionDue
     , nextAction
     , positionTitle
     , location
     , url
     )
VALUES ( NULL, ?, ?, ?, ?, ?, NOW(), NOW(), ?, ?, ?, ?, ? )
SQL;
                $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 . ' - ' . $this->_dbh->error);
                }
                if (!$stmt->bind_param('iiisssssss', $primaryContactId, $companyId, $applicationStatusId, $lastStatusChange, $urgency, $nextActionDue, $nextAction, $positionTitle, $location, $url)) {
                    throw new ControllerException('Binding parameters for prepared statement failed.');
                }
                if (!$stmt->execute()) {
                    throw new ControllerException('Failed to execute INSERT statement. (' . $this->_dbh->error . ')');
                }
                $newId = $stmt->insert_id;
                /**
                 * @SuppressWarnings checkAliases
                 */
                if (!$stmt->close()) {
                    throw new ControllerException('Something broke while trying to close the prepared statement.');
                }
                return $newId;
            } catch (Exception $e) {
                throw new ControllerException($e->getMessage());
            }
        } else {
            throw new ControllerException("Invalid data.");
        }
    }
예제 #2
0
파일: addJob.php 프로젝트: kbcmdba/pjs2
 * 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() . "Jobs - Add Job");
$body = '';
$act = Tools::Param('act');
if ("Add Job" === $act) {
    $model = new JobModel();
    $model->populateFromForm();
    if (!$model->validateForAdd()) {
        $view = new JobFormView('Add Job', $model);
        $body = "<h2>Invalid data</h2>\n" . $view->getForm();
    } else {
        $jobController = new JobController();
        $newId = $jobController->add($model);
        if ($newId > 0) {
            $body = "Added job # " . $newId . "<br />\n";
        }
    }
} else {
    $body = "";
    $view = new JobFormView("Add Job", null);
    $body = $view->getForm();
}
$webPage->setBody($body);