public function actionIndex()
 {
     // Residents::model()->deleteAll();
     foreach (range(0, 5) as $key => $value) {
         $fakerObj = Faker\Factory::create();
         $model = new Residents('createNewRecord');
         $model->salutation = $fakerObj->title;
         $model->firstname = $fakerObj->firstName;
         $model->lastname = $fakerObj->lastName;
         $model->middle_name = $fakerObj->firstName;
         $model->blood_type = "O";
         $model->house_number = $fakerObj->buildingNumber;
         $model->street_name = $fakerObj->streetName;
         $model->barangay_name = $fakerObj->streetName;
         $model->mobile_phone_number = "0906" . rand(1111111, 9999999);
         $model->town = "Solano";
         $model->province = "Nueva Vizcaya";
         $model->country = "Philippines";
         $model->birthdayYear = date("Y");
         $model->birthdayMonth = date("m");
         $model->birthdayDate = date("d");
         $model->residentSinceYear = date("Y");
         $model->residentSinceMonth = date("m");
         $model->residentSinceDate = date("d");
         $model->employment_type = "Full-time";
         if ($model->save()) {
             echo "New record created \r\n";
         } else {
             echo CHtml::errorSummary($model);
             die;
         }
     }
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Residents();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Residents'])) {
         $model->attributes = $_POST['Residents'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function actionIndex()
 {
     Yii::import('application.libs.Zebra_Image.Zebra_Image');
     $residentRecord = new Residents("createNewRecord");
     if (Yii::app()->request->isPostRequest && $_POST['Residents']) {
         $oldProfilePic = $residentRecord->profile_picture;
         $residentRecord->attributes = $_POST['Residents'];
         if ($residentRecord->validate()) {
             //Decode with base64
             if (isset($residentRecord->profile_picture) && !empty($residentRecord->profile_picture) && !is_null($residentRecord->profile_picture)) {
                 $foto = str_replace('data:image/png;base64,', '', $residentRecord->profile_picture);
                 $foto = str_replace(' ', '+', $foto);
                 $data_foto = base64_decode($foto);
                 //Set photo filename
                 $currentUserFileName = sprintf("%s_%s_%s_%s", $residentRecord->firstname, $residentRecord->middle_name, $residentRecord->lastname, uniqid());
                 $filename = $currentUserFileName . '.png';
                 $filepath = YiiBase::getPathOfAlias("webroot.themes.abound.uploads") . '/' . $filename;
                 $writeToDisk = file_put_contents($filepath, $data_foto);
                 //remove extra space
                 $image = new Zebra_Image();
                 $image->source_path = $filepath;
                 $image->target_path = $filepath;
                 $image->jpeg_quality = 100;
                 $image->preserve_aspect_ratio = true;
                 $image->enlarge_smaller_images = true;
                 $image->preserve_time = true;
                 $image->resize(300, 300, ZEBRA_IMAGE_CROP_TOPLEFT);
                 $residentRecord->profile_picture = $filepath;
             }
             if ($residentRecord->save()) {
                 Yii::app()->user->setFlash("success", "<strong>Record Saved ! </strong>New Resident Record Created");
                 $this->redirect(array('/register'));
             }
         } else {
             Yii::app()->user->setFlash("error", CHtml::errorSummary($residentRecord));
         }
     }
     $this->render('index', compact('residentRecord'));
 }