public function actionAppendZno() { $model = new Documents('ZNO'); $model->TypeID = 4; $subjects = array(); $valid = true; if (isset($_GET["Documents"])) { $documentid = $_GET["Documents"]['idDocuments']; unset($_GET["Documents"]['idDocuments']); if (!empty($documentid)) { $model = $this->loadDocuments($documentid); } $model->attributes = $_GET["Documents"]; $valid = $model->validate() && $valid; } // Удаление предметов try { if (isset($_GET["Documentsubject"])) { foreach ($_GET["Documentsubject"] as $i => $obj) { $subjectid = $obj["idDocumentSubject"]; unset($obj["idDocumentSubject"]); if (!empty($subjectid) && $subjectid > 0) { $item = $this->loadSubjects($subjectid); } else { $item = new Documentsubject(); } $item->attributes = $obj; if ($item->deleted == 0) { $valid = $item->validate() && $valid; $subjects[] = $item; } else { if (!$item->isNewRecord) { $item->delete(); } } } } } catch (CHttpException $e) { echo CJSON::encode(array("result" => "error", "data" => $e->getMessage())); Yii::app()->end(); } catch (Exception $e) { echo CJSON::encode(array("result" => "error", "data" => "Дія заборонена!")); Yii::app()->end(); } // Сохранение предметов if (!$valid) { echo CJSON::encode(array("result" => "error", "data" => $this->renderPartial('_form', array('model' => $model, 'subjects' => $subjects), true))); } else { /* save all new records */ $flag = $transaction = Yii::app()->db->getCurrentTransaction(); if ($transaction === null) { $transaction = Yii::app()->db->beginTransaction(); } try { if ($model->save()) { foreach ($subjects as $subject) { $subject->DocumentID = $model->idDocuments; if ($subject->deleted == 0) { if (!$subject->save()) { throw new Exception("Помилка збереження даних!"); } } else { if (!$subject->delete()) { throw new Exception("Помилка видалення даних!"); } } } } $transaction->commit(); $person = Person::model()->findByPk($model->PersonID); echo CJSON::encode(array("result" => "success", "data" => $this->renderPartial("//person/tabs/_zno", array('models' => $person->znos, 'personid' => $model->PersonID), true))); } catch (Exception $e) { if ($flag !== null) { $transaction->rollback(); } echo CJSON::encode(array("result" => "error", "data" => $e->getMessage())); } } }
public function loadRequestFromJsqon($jsondata, $sbj) { $data = CJSON::decode($jsondata); if (empty($data)) { throw new Exception("Заявку не знайдено!"); } $data = (object) $data[0]; $this->RequestFromEB = 1; $this->edboID = $data->idPersonRequest; $this->isBudget = $data->isBudget; $this->isContract = $data->isContract; $this->isNeedHostel = $data->isNeedHostel; $this->StatusID = $data->idPersonRequestStatusType; Yii::log($this->StatusID); $doc = Documents::model()->find("edboID=" . $data->idPersonDocument); if (empty($doc)) { throw new Exception("Документ для вступу відсутный або не синхронізований!"); } $this->EntrantDocumentID = $doc->idDocuments; $this->EducationFormID = $data->idPersonEducationForm; $this->QualificationID = $data->idQualification; $spec = Specialities::model()->find("SpecialityKode = '" . $data->universitySpecialitiesKode . "'"); if (empty($spec)) { throw new Exception("Пропозиція відсутня"); //$this->SepcialityID = 153677; } else { $this->SepcialityID = $spec->idSpeciality; } Yii::log($this->SepcialityID); $this->LanguageExID = $data->idLanguageEx; $this->EntranceTypeID = $data->idPersonEnteranceTypes; $this->CausalityID = $data->idPersonRequestExaminationCause; $this->SkipDocumentValue = $data->skipDocumentValue; $this->priority = $data->requestPriority; // Load subjects $sdata = CJSON::decode($sbj); if (empty($data)) { throw new Exception("Не задано передмети!"); } if (!empty($sdata[0])) { $s1 = (object) $sdata[0]; $doc = Documents::model()->find("edboID=" . $s1->idPersonDocument); $subj1 = Documentsubject::model()->find("DocumentID = {$doc->idDocuments} and SubjectID = {$s1->idSubject}"); $this->DocumentSubject1 = $subj1->idDocumentSubject; } if (!empty($sdata[1])) { $s1 = (object) $sdata[1]; $doc = Documents::model()->find("edboID=" . $s1->idPersonDocument); $subj1 = Documentsubject::model()->find("DocumentID = {$doc->idDocuments} and SubjectID = {$s1->idSubject}"); $this->DocumentSubject2 = $subj1->idDocumentSubject; } if (!empty($sdata[2])) { $s1 = (object) $sdata[2]; $doc = Documents::model()->find("edboID=" . $s1->idPersonDocument); $subj1 = Documentsubject::model()->find("DocumentID = {$doc->idDocuments} and SubjectID = {$s1->idSubject}"); $this->DocumentSubject3 = $subj1->idDocumentSubject; } Yii::log(print_r($this->DocumentSubject1 . " " . $this->DocumentSubject2 . " " . $this->DocumentSubject3, 1)); }
public static function loadAndSave($personid, $objarr) { foreach ($objarr as $item) { $val = (object) $item; if ($val->id_Type == 4) { $doc = new Documents(); $doc->scenario = "FULLINPUT"; $doc->PersonID = $personid; $doc->TypeID = $val->id_Type; $doc->edboID = $val->id_Document; $doc->AtestatValue = $val->attestatValue; $doc->Numbers = $val->number; $doc->Series = $val->series; $doc->DateGet = date("d.m.Y", mktime(0, 0, 0, $val->dateGet['month'] + 1, $val->dateGet['dayOfMonth'], $val->dateGet['year'])); $doc->ZNOPin = $val->znoPin; $doc->Issued = $val->issued; if ($val->dateGet['year'] < date("Y")) { Yii::log("Пропущено сертификат {$doc->Numbers} " . $val->dateGet['year'] . " года!"); continue; } if ($doc->save() && !empty($val->subjects)) { foreach ($val->subjects as $valstr) { $item = (object) $valstr; $subj = new Documentsubject(); $subj->DateGet = $doc->DateGet; $subj->edboID = $item->id_DocumentSubject; $subj->DocumentID = $doc->idDocuments; $subj->SubjectID = $item->id_Subject; $subj->SubjectValue = $item->subjectValue; $subj->save(); } } } else { if ($val->id_Type == 11 || $val->id_Type == 12 || $val->id_Type == 13 || $val->id_Type == 2) { $exdoc = null; try { if (empty($exdoc)) { $doc = new Documents(); //$doc->scenario = "FULLINPUT"; $doc->PersonID = $personid; $doc->TypeID = $val->id_Type; $doc->edboID = $val->id_Document; $doc->AtestatValue = $val->attestatValue; $doc->Numbers = $val->number; $doc->Series = $val->series; $doc->DateGet = date("d.m.Y", mktime(0, 0, 0, $val->dateGet['month'] + 1, $val->dateGet['dayOfMonth'], $val->dateGet['year'])); //$doc->ZNOPin = $val->znoPin; $doc->Issued = $val->issued; if (!$doc->save()) { throw new Exception(print_r($doc->getErrors(), 1)); } } } catch (Exception $exc) { Yii::log($exc->getMessage()); } } else { if (Yii::app()->user->checkAccess("asEDBOReqOperator")) { try { if (empty($exdoc)) { $doc = new Documents(); $doc->scenario = "FULLINPUT"; $doc->PersonID = $personid; $doc->TypeID = $val->id_Type; $doc->edboID = $val->id_Document; $doc->AtestatValue = $val->attestatValue; $doc->Numbers = $val->number; $doc->Series = $val->series; $doc->DateGet = date("d.m.Y", mktime(0, 0, 0, $val->dateGet['month'] + 1, $val->dateGet['dayOfMonth'], $val->dateGet['year'])); //$doc->ZNOPin = $val->znoPin; $doc->Issued = $val->issued; if (!$doc->save()) { throw new Exception(print_r($doc->getErrors())); } } } catch (Exception $exc) { Yii::log($exc->getMessage()); } } } } } }
<div class="row-fluid" style ="font-weight: bold;"> <div class="span1" align="center">П/Н</div> <div class ="span4"> <?php echo Documentsubject::model()->getAttributeLabel("SubjectID"); ?> </div> <!-- <div class ="span3"> <?php //echo Documentsubject::model()->getAttributeLabel("DateGet"); ?> </div> --> <div class ="span3"> <?php echo Documentsubject::model()->getAttributeLabel("SubjectValue"); ?> </div> <div class ="span1"></div> </div> <?php $j = 1; foreach ($subjects as $i => $subject) { ?> <div class="row-fluid" <?php echo $subject->deleted == 1 ? "style='display:none'" : ""; ?> > <div class="span1" align="center" > <span style="font-size: 14px; display:block; margin-top: 5px;"><?php echo $subject->deleted == 0 ? $j++ : $j;