Skip to content

Instantly share code, notes, and snippets.

@gusdecool
Forked from mirahtadi/Applicant.php
Last active January 10, 2017 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gusdecool/7c3157cfa88f6d107443e2c097918a2a to your computer and use it in GitHub Desktop.
Save gusdecool/7c3157cfa88f6d107443e2c097918a2a to your computer and use it in GitHub Desktop.
Jobs Yii
<?php
/**
* This is the model class for table "applicant".
*
* The followings are the available columns in table 'applicant':
* @property string $position
* @property integer $id
* @property string $fullName
* @property string $nickName
* @property string $dateOfBirth
* @property string $email
* @property string $phone
* @property string $address
* @property string $note
* @property string $position
*
* The followings are the available model relations:
*/
class Applicant extends CActiveRecord {
/**
* Returns the static model of the specified AR class.
* @param string $className active record class name.
* @return Applicant the static model class
*/
public static function model($className = __CLASS__) {
return parent::model($className);
}
/**
* @return string the associated database table name
*/
public function tableName() {
return 'applicant';
}
/**
* @return array validation rules for model attributes.
*/
public function rules() {
return array(
array('fullName, nickName, dateOfBirth, email, phone, address, position', 'required'),
array('fullName, nickName, email, phone, address', 'length', 'position', 'max' => 255),
array('note', 'safe'),
// array('curriculum', 'file', 'types'=>'jpg, gif, png, doc, pdf', 'safe' => false),
// The following rule is used by search().
// Please remove those attributes that should not be searched.
array('id, fullName, nickName, email, phone, address, note, position', 'safe', 'on' => 'search'),
);
}
/**
* @return array relational rules.
*/
public function relations() {
return array(
'application' => array(self::HAS_MANY, 'Application', 'applicantId'),
);
}
/**
* @return array customized attribute labels (name=>label)
*/
public function attributeLabels() {
return array(
'position' => 'Position',
'id' => 'ID',
'fullName' => 'Full Name',
'nickName' => 'Nick Name',
'dateOfBirth' => 'Date of Birth',
'email' => 'Email',
'phone' => 'Phone',
'address' => 'Address',
'note' => 'Note',
'position' => 'Position'
);
}
/**
* Retrieves a list of models based on the current search/filter conditions.
* @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
*/
public function search() {
$criteria = new CDbCriteria;
$criteria->compare('position', $this->position, true);
$criteria->compare('id', $this->id);
$criteria->compare('fullName', $this->fullName, true);
$criteria->compare('nickName', $this->nickName, true);
$criteria->compare('dateOfBirth', $this->dateOfBirth, true);
$criteria->compare('email', $this->email, true);
$criteria->compare('phone', $this->phone, true);
$criteria->compare('address', $this->address, true);
$criteria->compare('note', $this->note, true);
$criteria->compare('position', $this->position, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
}
<?php
/* @var $this JobController */
/* @var $applicant Applicant */
?>
<p>&nbsp;</p>
<h1>WORKING WITH US</h1>
<p>Thank you for interesting joining our team!</p>
<p>We are looking for passionate people to fill the position as :</p>
<div>
<ul>
<b>1. Instructor</b>
<li>* Local male</li>
<li>* Active</li>
<li>* Hardworking</li>
<li>* Dedicated</li>
<li>* Fluent in English</li>
<li>* Attractive package offered (salary, uniform, incentive & BPJS)</li>
</ul>
</div>
<p>&nbsp;</p>
<div>
<ul>
<b>2. FO / Reservation</b>
<li>* Female</li>
<li>* Fluency in English both oral and written is mandatory requirement</li>
<li>* Good in Microsoft Office Program, specially Excel, Word and Internet</li>
<li>* Love water sports</li>
<li>* Benefits: Salary (UMK++), Incentive, BPJS</li>
</ul>
</div>
<p>&nbsp;</p>
<p>To continue apply, please fill the form below:</p>
<?php
$form = $this->beginWidget('CActiveForm', array(
'id' => 'booking-form',
'enableAjaxValidation' => false,
'enableClientValidation' => false,
'htmlOptions' => array('enctype' => 'multipart/form-data'),
'focus' => array($applicant, 'fullName'),
));
/* @var $form CActiveForm */
echo $form->errorSummary($applicant);
?>
<article id="customer">
<div class="right">
<div class="form-row">
<div class="form-left">
<?php echo $form->labelEx($applicant, 'position'); ?>
</div>
<div class="form-right">
<?php echo $form->dropDownList($applicant, ‘position’, array(‘instructor’=>’Instructor', ‘reservation’=>’Reservation')); ?>
</div>
<div class="clear"></div>
</div>
<div class="form-row">
<div class="form-left">
<?php echo $form->labelEx($applicant, 'fullName'); ?>
</div>
<div class="form-right">
<?php echo $form->textField($applicant, 'fullName', array('required' => 'required')); ?>
</div>
<div class="clear"></div>
</div>
<div class="form-row">
<div class="form-left">
<?php echo $form->labelEx($applicant, 'nickName'); ?>
</div>
<div class="form-right">
<?php echo $form->textField($applicant, 'nickName'); ?>
</div>
<div class="clear"></div>
</div>
<div class="form-row">
<div class="form-left">
<?php echo $form->labelEx($applicant, 'dateOfBirth'); ?>
</div>
<div class="form-right">
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
//'name' => 'date',
'model' => $applicant,
'attribute' => 'dateOfBirth',
'options' => array(
'showAnim' => 'fold',
'dateFormat' => 'yy-mm-dd',
),
'htmlOptions' => array(
'required' => 'required'
),
));
?>
<br />
</div>
<div class="clear"></div>
</div>
<div class="form-row">
<div class="form-left">
<?php echo $form->labelEx($applicant, 'email'); ?>
</div>
<div class="form-right">
<?php echo $form->emailField($applicant, 'email'); ?>
</div>
<div class="clear"></div>
</div>
<div class="form-row">
<div class="form-left">
<?php echo $form->labelEx($applicant, 'phone'); ?>
</div>
<div class="form-right">
<?php echo $form->textField($applicant, 'phone'); ?>
</div>
<div class="clear"></div>
</div>
<div class="form-row">
<div class="form-left">
<?php echo $form->labelEx($applicant, 'address'); ?>
</div>
<div class="form-right">
<?php echo $form->textField($applicant, 'address', array('placeholder' => 'e.g: Jalan Legian Number 101')); ?>
</div>
<div class="clear"></div>
</div>
<div class="form-row">
<div class="form-left">
<?php echo $form->labelEx($applicant, 'note'); ?>
</div>
<div class="form-right">
<?php echo $form->textArea($applicant, 'note', array('placeholder' => 'You may paste your curriculum vitae here')); ?>
</div>
<div class="clear"></div>
</div>
<!--
<div class="form-row">
<div class="form-left">
<?php
echo $form->labelEx($applicant, 'image');
?>
</div>
<div class="form-right">
<?php
echo $form->fileField($applicant, 'image');
echo $form->error($applicant, 'image');
?>
</div>
<div class="clear"></div>
</div>
-->
</div>
<div class="clear"></div>
</article>
<article id="action">
<div class="left">&nbsp;</div>
<div class="right action-area">
<input type="submit" value="Submit" />
<input type="reset" value="Reset" />
</div>
<div class="clear"></div>
</article>
<?php $this->endWidget(); ?>
<?php
class JobController extends Controller {
public function filters() {
return array(
'accessControl - login',
);
}
public function accessRules() {
return array(
array('allow',
'users' => array('*'),
'actions' => array('index', 'success', 'error', 'email'),
),
array('allow',
'users' => array('*'),
'actions' => array('logout'),
),
array('deny',
'users' => array('*'),
)
);
}
public function actionIndex() {
$applicant = new Applicant();
if( isset($_POST['Applicant']) ){
$applicant->attributes = $_POST['Applicant'];
if($applicant->validate()){
$applicant->save();
// Sending Mail
$emailHrd = Yii::app()->params['emailHrd'];
$devEmail = Yii::app()->params['emailDeveloper'];
$to = "{$applicant->email},{$emailHrd}";
$subject = 'New Application';
$message = $this->renderPartial('/mail/job-success', array('applicant'=>$applicant), true);
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: Rip Curl School of Surf <$emailHrd>" . "\r\n";
mail($to, $subject, $message, $headers);
$this->redirect($this->createUrl('success'));
}
}
$this->render('index', array(
'applicant' => $applicant
));
}
public function actionSuccess(){
$this->render('success');
}
public function actionError() {
if ($error = Yii::app()->errorHandler->error) {
if (Yii::app()->request->isAjaxRequest)
echo $error['message'];
else
$this->render('error', $error);
}
}
/**
*
* @param int $id Applicant ID
*/
public function actionEmail($id){
$applicant = Applicant::model()->findByPk($id);
/* @var $applicant Applicant */
$message = new YiiMailMessage;
$message->view = 'booking-success';
$message->setBody(array('applicant'=>$applicant), 'text/html');
$message->addTo($applicant->email, $applicant->firstName);
$message->addTo('rcsos.bali@gmail.com', 'RCSOS Admin');
$message->from = 'rcsos.bali@gmail.com';
Yii::app()->mail->send($message);
$this->renderPartial('/mail/job-success', array('applicant'=>$applicant));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment