/**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate($id = null)
 {
     $model = new ConfirmationCertificate();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['ConfirmationCertificate'])) {
         $model->attributes = $_POST['ConfirmationCertificate'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $rec = ConfirmationRecord::model()->findByPk($id);
     $model->cert_dt = Yii::app()->dateFormatter->formatDateTime(time(), 'short', null);
     $this->render('create', array('model' => $model, 'confirmation' => $rec));
 }
 public function actionParishProfile()
 {
     $fams = Families::model()->findAll();
     $ppl = People::model()->findAll();
     $baptised1 = BaptismRecord::model()->findAll('baptism_dt > NOW() - INTERVAL 1 YEAR AND dob > NOW() - INTERVAL 1 YEAR');
     $baptised7 = BaptismRecord::model()->findAll('baptism_dt > NOW() - INTERVAL 1 YEAR AND dob BETWEEN NOW() - INTERVAL 7 YEAR AND NOW() - INTERVAL 1 YEAR');
     $baptised7p = BaptismRecord::model()->findAll('baptism_dt > NOW() - INTERVAL 1 YEAR AND dob < NOW() - INTERVAL 7 YEAR');
     $baptised = BaptismRecord::model()->findAll();
     $confirmed = ConfirmationRecord::model()->findAll('confirmation_dt > NOW() - INTERVAL 1 YEAR ');
     $firstComm = FirstCommunionRecord::model()->findAll('communion_dt > NOW() - INTERVAL 1 YEAR ');
     $married = MarriageRecord::model()->findAll('marriage_dt > NOW() - INTERVAL 1 YEAR');
     $married_cath = MarriageRecord::model()->findAll('marriage_dt > NOW() - INTERVAL 1 YEAR AND marriage_type <= 2');
     $married_nc = MarriageRecord::model()->findAll('marriage_dt > NOW() - INTERVAL 1 YEAR AND marriage_type > 2');
     $schedule = MassSchedule::model()->findAll(array('order' => 'day, time'));
     $pp = Pastors::model()->find('role = 1');
     $apps = Pastors::model()->findAll('role != 1');
     $this->render('parish-profile', array('families' => count($fams), 'members' => count($ppl), 'baptised' => count($baptised), 'baptised1' => count($baptised1), 'baptised7' => count($baptised7), 'baptised7p' => count($baptised7p), 'confirmed' => count($confirmed), 'firstComm' => count($firstComm), 'married' => count($married), 'married_nc' => count($married_nc), 'married_cath' => count($married_cath), 'pp' => $pp, 'apps' => $apps, 'schedule' => $schedule));
 }
 /**
  * Returns the data model based on the primary key given in the GET variable.
  * If the data model is not found, an HTTP exception will be raised.
  * @param integer $id the ID of the model to be loaded
  * @return ConfirmationRecord the loaded model
  * @throws CHttpException
  */
 public function loadModel($id)
 {
     $model = ConfirmationRecord::model()->findByPk($id);
     if ($model === null) {
         throw new CHttpException(404, 'The requested page does not exist.');
     }
     return $model;
 }
 protected function beforeSave()
 {
     if (parent::beforeSave()) {
         // Format dates based on the locale
         foreach ($this->metadata->tableSchema->columns as $columnName => $column) {
             if ($column->dbType == 'date') {
                 $this->{$columnName} = date('Y-m-d', CDateTimeParser::parse($this->{$columnName}, Yii::app()->locale->getDateFormat('short')));
             }
         }
         if (!isset($this->ref_no)) {
             $year = date_format(new DateTime($this->confirmation_dt), 'Y');
             $cond = "confirmation_dt >= '{$year}-01-01' and confirmation_dt <= '{$year}-12-31'";
             $parms = array();
             if (isset($this->id)) {
                 $parms[':id'] = $this->id;
                 $cond = "{$cond} and id<=:id";
             }
             $recs = ConfirmationRecord::model()->findAll(array('condition' => $cond, 'params' => $parms));
             $cnt = count($recs);
             if (!isset($this->id)) {
                 ++$cnt;
             }
             $this->ref_no = "{$year}/{$cnt}";
         }
         return true;
     } else {
         return false;
     }
 }