public function actionIndex()
 {
     //Get the preferences model
     $preferences = new Preferences();
     // Make an user model from current user
     $person = \Yii::$app->user->identity;
     if (isset(\Yii::$app->request->post()['Preferences'])) {
         $preferences->load(\Yii::$app->request->post());
         $preferences->saveForUser($person);
     }
     // Fill preferences with user preferences
     $preferences->fillForUser($person);
     // Show data as form
     return $this->render("index", ["model" => $person, "preferences" => $preferences]);
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Preferences::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['pref_ID' => $this->pref_ID]);
     $query->andFilterWhere(['like', 'pref_name', $this->pref_name])->andFilterWhere(['like', 'pref_value', $this->pref_value]);
     return $dataProvider;
 }
// Form 1 : Decisions per month pew organizations
echo Html::beginForm('index.php?r=results/resultsb21afmorg', 'post');
// 2. Show selected Organisations
echo '<label class="control-label">Οργανισμοί</label>';
echo Select2::widget(['name' => 'select_orgs', 'data' => $currentOrgs, 'value' => '', 'options' => ['placeholder' => 'Οργανισμός...', 'multiple' => false]]);
echo Html::textInput("set_afm");
?>
                    <br>
            <?php 
echo Html::submitButton('Εμφάνιση');
?>
    
                    <br>     
            <?php 
echo Html::endForm();
?>
                
          
        </div>        
    </div>        
        
    </div>
    
        <p>
            <?php 
$updateDate = Preferences::getRefreshDate();
echo '<br><br><label class="control-label">Τελευταία Ενημέρωση: </label>';
echo '<label class="control-label">' . $updateDate[0] . '</label>';
?>
        </p>    
Exemple #4
0
<?php

use yii\helpers\Html;
use app\models\Preferences;
use yii\widgets\ActiveForm;
?>
<div class="preferences">
<?php 
echo $form->field($model, 'durations')->checkboxlist(Preferences::getDurationsList());
?>

<?php 
echo $form->field($model, 'workTypes')->checkboxlist(Preferences::getWorkTypesList());
?>

<?php 
echo !$no_courses ? $form->field($model, 'courses')->checkboxlist(Preferences::getCoursesList()) : "";
?>
</div>


 /**
  * Finds the Preferences model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Preferences the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Preferences::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function actionRefreshdataajax()
 {
     $currentOrgs = Preferences::getSelectedOrgIds();
     //print_r($currentOrgs);
     $currentTypes = Preferences::getSelectedTypes();
     //print_r($currentTypes);
     $currentDates = Preferences::getSelectedDates();
     //print_r($currentDates);
     $pages = 0;
     $b21_counter = 0;
     $client = new \OpendataClient();
     $client->setAuth('apiuser_1', 'ApiUser@1');
     foreach ($currentOrgs as $corg) {
         $pages = 0;
         foreach ($currentTypes as $ctype) {
             $string = "/search?org=" . $corg . "&type=" . $ctype . "&size=500&from_date=" . $currentDates[0] . "&to_date=" . $currentDates[1] . "&page=" . $pages;
             //print ($string);
             $response = $client->getResource($string);
             if ($response->code === 200) {
                 $unitData = $response->data;
                 $sum = 0.0;
                 $counter = 1;
                 $actual_size = 1;
                 $breakOrg = 0;
                 while ($actual_size != 0) {
                     foreach ($unitData['decisions'] as $unit) {
                         try {
                             //print_r($unit);
                             Yii::$app->db->createCommand()->insert('decisions', ['ada' => $unit['ada'], 'protocolNumber' => $unit['protocolNumber'], 'subject' => $unit['subject'], 'issueDate' => gmdate("Y-m-d", $unit['issueDate'] / 1000), 'decisionTypeId' => $unit['decisionTypeId'], 'organizationId' => $unit['organizationId'], 'submissionTimestamp' => gmdate("Y-m-d", $unit['submissionTimestamp'] / 1000), 'versionId' => $unit['versionId'], 'status' => $unit['status'], 'url' => $unit['documentUrl'], 'documentChecksum' => $unit['documentChecksum'], 'correctedVersionId' => $unit['correctedVersionId']])->execute();
                             $b21_counter++;
                             $orgData = $unit['extraFieldValues']['org'];
                             //foreach ($orgData as $org) {
                             //print_r($orgData);
                             if (isset($orgData['enterName']['name'])) {
                                 $Name = $orgData['enterName']['name'];
                             } else {
                                 $Name = '-';
                             }
                             if (isset($orgData['afmCountry'])) {
                                 $Country = $orgData['afmCountry'];
                             } else {
                                 $Country = '';
                             }
                             Yii::$app->db->createCommand()->insert('decisionsb21', ['b21_ada' => $unit['ada'], 'afm' => $orgData['afm'], 'afmType' => $orgData['afmType'], 'afmCountry' => $Country, 'enterName' => '1', 'name' => $Name])->execute();
                             //}
                             $sponsorData = $unit['extraFieldValues']['sponsor'];
                             //print_r($sponsorData);
                             foreach ($sponsorData as $sponsor1) {
                                 // Expense Amount DATA
                                 if (!isset($sponsor1['expenseAmount']['kae'])) {
                                     $kae = null;
                                 } else {
                                     $kae = $sponsor1['expenseAmount']['kae'];
                                 }
                                 if (!isset($sponsor1['expenseAmount']['amount'])) {
                                     $amount = null;
                                 } else {
                                     $amount = $sponsor1['expenseAmount']['amount'];
                                 }
                                 if (!isset($sponsor1['expenseAmount']['currency'])) {
                                     $currency = null;
                                 } else {
                                     $currency = $sponsor1['expenseAmount']['currency'];
                                 }
                                 // Sponsor DATA
                                 if (!isset($sponsor1['sponsorAFMName']['afmType'])) {
                                     $afmType = null;
                                 } else {
                                     $afmType = $sponsor1['sponsorAFMName']['afmType'];
                                 }
                                 if (!isset($sponsor1['sponsorAFMName']['name'])) {
                                     $name = null;
                                 } else {
                                     $name = $sponsor1['sponsorAFMName']['name'];
                                 }
                                 if (!isset($sponsor1['sponsorAFMName']['noVATOrg'])) {
                                     $noVATOrg = null;
                                 } else {
                                     $noVATOrg = $sponsor1['sponsorAFMName']['noVATOrg'];
                                 }
                                 if (!isset($sponsor1['sponsorAFMName']['afm'])) {
                                     $afm = null;
                                 } else {
                                     $afm = $sponsor1['sponsorAFMName']['afm'];
                                 }
                                 if (!isset($sponsor1['sponsorAFMName']['afmCountry'])) {
                                     $afmCountry = null;
                                 } else {
                                     $afmCountry = $sponsor1['sponsorAFMName']['afmCountry'];
                                 }
                                 if (!isset($sponsor1['sponsorAFMName']['noVATOrg'])) {
                                     $noVATOrg = null;
                                 } else {
                                     $noVATOrg = $sponsor1['sponsorAFMName']['noVATOrg'];
                                 }
                                 // CPV DATA
                                 if (!isset($sponsor1['cpv'])) {
                                     $cpv = "-";
                                 } else {
                                     $cpv = $sponsor1['cpv'];
                                 }
                                 Yii::$app->db->createCommand()->insert('sponsor', ['sp_ada' => $unit['ada'], 'afm' => $afm, 'afmType' => $afmType, 'afmCountry' => $afmCountry, 'enterName' => '1', 'name' => $name, 'noVATOrg' => $noVATOrg, 'kae' => $kae, 'amount' => $amount, 'currency' => $currency, 'cpv' => $cpv])->execute();
                                 /*Yii::$app->db->createCommand()->insert('cpvperdecisions', [
                                       'cpd_ada' => $unit['ada'],
                                       'cpd_cpv' => $cpv,
                                   ])->execute();*/
                             }
                             $counter++;
                         } catch (Exception $e) {
                             echo 'Caught exception: ', $e->getMessage(), "\n<br>";
                             $exc = $e->getMessage();
                             //if (strstr($exc, "1062 Duplicate entry") != FALSE){
                             //$breakOrg = 1;
                             //break;
                             //}
                         }
                     }
                     $pages++;
                     $string = "/search?org=" . $corg . "&type=" . $ctype . "&size=500&from_date=" . $currentDates[0] . "&to_date=" . $currentDates[1] . "&page=" . $pages;
                     $response = $client->getResource($string);
                     $unitData = $response->data;
                     //echo "---" . $unitData['info']['actualSize'];
                     $actual_size = $unitData['info']['actualSize'];
                     if ($actual_size == NULL) {
                         $actualSize = 1;
                     } else {
                         if ($actual_size == 0) {
                             break;
                         }
                     }
                     unset($unit);
                     unset($orgData);
                     unset($kae);
                     unset($afmType);
                     //unset($cpv);
                     unset($afmType);
                     unset($name);
                     unset($amount);
                     //if ($breakOrg == 1) {
                     //$actualSize = 0;
                     // break;
                     //}
                 }
             } else {
                 echo "Error " . $response->code;
             }
         }
     }
     // Update TimeStamp
     $mysqltime = date("d-m-Y H:i:s");
     Yii::$app->db->createCommand("DELETE FROM preferences WHERE pref_name LIKE 'lastrefreshdate'")->execute();
     Yii::$app->db->createCommand("INSERT INTO preferences (pref_name, pref_value) VALUES ('lastrefreshdate','" . $mysqltime . "')")->execute();
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     return ['message' => $b21_counter + ' ΑΠΟΦΑΣΕΙΣ ΤΥΠΟΥ Β.2.1 ΠΡΟΣΤΕΘΗΚΑΝ', 'code' => $b21_counter];
 }
 public function actionResultsb21afmorg()
 {
     if (!isset($_POST['select_orgs']) || empty($_POST['select_orgs'])) {
         $orgID1 = Preferences::findOne(['pref_name' => 'Resultsb21afmorgID']);
         $orgID = $orgID1->pref_value;
         Preferences::deleteAll(['pref_name' => 'Resultsb21afmorgID']);
     } else {
         $orgID = $_POST['select_orgs'];
     }
     if (!isset($_POST['set_afm']) || empty($_POST['set_afm'])) {
         $afm1 = Preferences::findOne(['pref_name' => 'Resultsb21afmorgcpv']);
         $afm = $afm1->pref_value;
         Preferences::deleteAll(['pref_name' => 'Resultsb21afmorgcpv']);
     } else {
         $afm = $_POST['set_afm'];
     }
     Preferences::deleteAll(['pref_name' => 'Resultsb21afmorgID']);
     Yii::$app->view->params['Resultsb21afmorgID'] = $orgID;
     $pref = new Preferences();
     $pref->pref_name = 'Resultsb21afmorgID';
     $pref->pref_value = $orgID;
     $pref->save();
     Preferences::deleteAll(['pref_name' => 'Resultsb21afmorgcpv']);
     Yii::$app->view->params['Resultsb21afmorgcpv'] = $afm;
     $pref = new Preferences();
     $pref->pref_name = 'Resultsb21afmorgcpv';
     $pref->pref_value = $afm;
     $pref->save();
     return $this->render('resultsb21afmorg');
 }
 public function createnewstep3()
 {
     $model = new Vacancy();
     $preferences = new Preferences();
     $data = Yii::$app->request->post();
     $model->load($data);
     $preferences->load($data);
     $transaction = \Yii::$app->db->beginTransaction();
     try {
         //TODO check for errors and cancel transaction
         $model->save();
         $model->savePreferences($preferences);
         $connection = \Yii::$app->db;
         // TODO Place this in preferences logic
         $connection->createCommand("INSERT INTO person_vacancy_role (person_id, vacancy_id, role_id) " . "VALUES (:person_id, :vacancy_id, :role_id)")->bindValues([":person_id" => \YII::$app->getUser()->getIdentity()->getId(), ":vacancy_id" => $model->getPrimaryKey(), ":role_id" => VacancyRoleHelper::OWNER])->execute();
         // Vacanty - course_id
         $course_id = $this->getSession()['create-new-vacancy-course-id'];
         if (isset($course_id) && $course_id != "none") {
             $connection->createCommand("INSERT INTO course_vacancy (course_id, vacancy_id) VALUES (:course_id, :vacancy_id)")->bindValues([":course_id" => $course_id, ":vacancy_id" => $model->getPrimaryKey()])->execute();
         }
         $transaction->commit();
     } catch (\Exception $e) {
         $transaction->rollBack();
         throw $e;
     }
     return $this->actionView($model->id);
 }
?>

<?php 
$form = RoleBasedActiveForm::begin();
?>

<?php 
echo $form->field($preferences, 'courses')->checkboxlist(Preferences::getCoursesList());
?>

<?php 
echo $form->field($preferences, 'workTypes')->checkboxlist(Preferences::getWorkTypesList());
?>

<?php 
echo $form->field($preferences, 'durations')->checkboxlist(Preferences::getDurationsList());
?>



<style>
    .form-group {
        float: left;
        margin-right: 200px;
    }
</style>


<div class="form-group">
    <?php 
echo Html::submitButton('Update', ['class' => 'btn btn-primary']);
$this->params['breadcrumbs'][] = $this->title;
?>

    <h1><?php 
echo Html::encode($this->title);
?>
</h1>

    <div class="row">
            <div style="text-align: justify;" class="col-lg-12">
<?php 
$currentOrgs = Preferences::getSelectedOrgIds();
//print_r($currentOrgs);
$currentTypes = Preferences::getSelectedTypes();
//print_r($currentTypes);
$currentDates = Preferences::getSelectedDates();
//print_r($currentDates);
$pages = 0;
$client = new OpendataClient();
$client->setAuth('apiuser_1', 'ApiUser@1');
foreach ($currentOrgs as $corg) {
    $pages = 0;
    foreach ($currentTypes as $ctype) {
        $string = "/search?org=" . $corg . "&type=" . $ctype . "&size=500&from_date=" . $currentDates[0] . "&to_date=" . $currentDates[1] . "&page=" . $pages;
        //print ($string);
        $response = $client->getResource($string);
        if ($response->code === 200) {
            $unitData = $response->data;
            $sum = 0.0;
            $counter = 1;
            $actual_size = 1;