From 01a8e95b73008d02485010b95e64dcbb403a39e8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=D0=90=D0=BD=D0=B4=D1=80=D0=B5=D0=B9=20=D0=A0=D1=83=D0=B4?=
 =?UTF-8?q?=D0=B5=D0=BD=D0=B5=D1=86?= <andrey.rudenets@gmail.com>
Date: Mon, 25 Aug 2014 16:38:49 +0400
Subject: [PATCH] =?UTF-8?q?=D0=93=D0=B5=D0=BD=D0=B5=D1=80=D0=B0=D1=86?=
 =?UTF-8?q?=D0=B8=D1=8F=20PDF-=D1=84=D0=B0=D0=B9=D0=BB=D0=BE=D0=B2=20?=
 =?UTF-8?q?=D1=81=20=D0=BA=D0=BE=D0=B4=D0=B0=D0=BC=D0=B8=20=D0=B0=D0=BA?=
 =?UTF-8?q?=D1=82=D0=B8=D0=B2=D0=B0=D1=86=D0=B8=D0=B8,=20=D0=BF=D0=BE?=
 =?UTF-8?q?=D0=BA=D0=B0=20=D1=82=D0=BE=D0=BB=D1=8C=D0=BA=D0=BE=20=D1=81?=
 =?UTF-8?q?=D1=82=D1=83=D0=B4=D0=B5=D0=BD=D1=82=D1=8B.?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../Controller/Handler/AdmAccounts.php        | 37 +++++++++++++++++--
 .../Controller/Handler/AdmStudents.php        | 21 +++++++++++
 .../classes/Model/Admin/Accounts.php          | 29 +++++++++++++++
 .../views/pdf/activationTemplate.twig         | 20 ++++++++++
 ~dev_rating/media/css/acTpl.css               | 34 +++++++++++++++++
 .../modules/mpdf/classes/View/MPDF/Core.php   |  2 +-
 6 files changed, 139 insertions(+), 4 deletions(-)
 create mode 100644 ~dev_rating/application/classes/Model/Admin/Accounts.php
 create mode 100644 ~dev_rating/application/views/pdf/activationTemplate.twig
 create mode 100644 ~dev_rating/media/css/acTpl.css

diff --git a/~dev_rating/application/classes/Controller/Handler/AdmAccounts.php b/~dev_rating/application/classes/Controller/Handler/AdmAccounts.php
index 97178e6e8..1b56245b9 100644
--- a/~dev_rating/application/classes/Controller/Handler/AdmAccounts.php
+++ b/~dev_rating/application/classes/Controller/Handler/AdmAccounts.php
@@ -1,16 +1,47 @@
 <?php defined('SYSPATH') or die('No direct script access.');
 
-class Controller_Handler_AdmStudents extends Controller_Handler {
+class Controller_Handler_AdmAccounts extends Controller_Handler {
         
         public function before() {
-            $this->model = new Model_Admin_Students();
+            $this->model = new Model_Admin_Accounts();
             $this->setAccessLevel(self::ACCESS_USER);
             parent::before();
         }
         
         public function action_getActivationForStudents()
         {
-            
+            $facultyID = $this->post->offsetGet('facultyID');
+            $gradeNum = $this->post->offsetGet('gradeNum');
+            $groupsHandled = array(); $i = 0;
+            $studyGroups = $this->model->getStudyGroups($gradeNum, $facultyID);
+            foreach ($studyGroups as $group)
+            {
+                $i++; $j = 0;
+                $accounts = $this->model->getStudentsByStudyGroups($group['GroupID']);
+                $groupsHandled[$i]['Grade'] = $gradeNum;
+                $groupsHandled[$i]['Num'] = $group['GroupNum'];
+                $groupsHandled[$i]['Spec'] = $group['SpecName'];
+                foreach ($accounts as $row)
+                {
+                    $accInfo = $this->model->getAccountInfoByID($row['StudentAccID']);
+                    if($code = $accInfo->get('AccCode'))
+                    {
+                        $j++;
+                        $groupsHandled[$i]['People'][$j]['LastName'] = $row['StudentLast'];
+                        $groupsHandled[$i]['People'][$j]['FirstName'] = $row['StudentFirst'];
+                        $groupsHandled[$i]['People'][$j]['SecondName'] = $row['StudentSecond'];
+                        $groupsHandled[$i]['People'][$j]['ActivationCode'] = $code;
+                    }
+                }
+                $groupsHandled[$i]['PeopleCount'] = $j;
+            }
+            $mpdf = View_MPDF::factory('pdf/activationTemplate', array('Groups' => $groupsHandled, 
+                'System' => array('Title' => ASSEMBLY_SYSTEM_NAME, 'Version' => ASSEMBLY_VERSION)));
+            $cssPath = 'media/css/acTpl.css';
+            $css = file_get_contents($cssPath);
+            $mpdf->get_mpdf()->WriteHTML($css, 1);
+            $mpdf->write_to_disk('media/pdf/activationTemplate.pdf');  
+            $this->response->body($twig);
         }
         
         public function action_getActivationForTeachers()
diff --git a/~dev_rating/application/classes/Controller/Handler/AdmStudents.php b/~dev_rating/application/classes/Controller/Handler/AdmStudents.php
index 2bcf215ce..e1f97fda2 100644
--- a/~dev_rating/application/classes/Controller/Handler/AdmStudents.php
+++ b/~dev_rating/application/classes/Controller/Handler/AdmStudents.php
@@ -96,6 +96,27 @@ class Controller_Handler_AdmStudents extends Controller_Handler {
             }
         }
         
+        public function action_getStudentsByGrade()
+        {
+            $facultyID = $this->post->offsetGet('gradeNum');
+            $groupID = $this->post->offsetGet('gradeNum');
+            if($groupID != 0)
+            {
+                $students = $this->model->getStudentsByStudyGroups($groupID);
+                $studentsHandled = array(); $i = 0;
+                foreach($students as $row)
+                {
+                    $i++;
+                    $studentsHandled[$i]['LastName'] = $row['StudentLast'];
+                    $studentsHandled[$i]['FirstName'] = $row['StudentFirst'];
+                    $studentsHandled[$i]['SecondName'] = $row['StudentSecond'];
+                }
+                $twig = Twig::factory('admin/students/handler/listOutput');
+                $twig->List = $studentsHandled;
+                $this->response->body($twig);           
+            }
+        }
+        
         public function action_getStudentsByStudyGroup()
         {
             $groupID = $this->post->offsetGet('studyGroupID');
diff --git a/~dev_rating/application/classes/Model/Admin/Accounts.php b/~dev_rating/application/classes/Model/Admin/Accounts.php
new file mode 100644
index 000000000..c4862cbfd
--- /dev/null
+++ b/~dev_rating/application/classes/Model/Admin/Accounts.php
@@ -0,0 +1,29 @@
+<?php defined('SYSPATH') or die('No direct script access.');
+  
+class Model_Admin_Accounts extends Model
+{
+    public function getFaculties()
+    {
+        $sql = "CALL `GetFaculties`(); ";
+        return DB::query(Database::SELECT, $sql)->execute();
+    }
+    
+    public function getStudyGroups($gradeNum, $facultyID)
+    {
+        $sql = "CALL `GetStudyGroups`('$gradeNum', '$facultyID'); ";
+        return DB::query(Database::SELECT, $sql)->execute();
+    }
+    
+    public function getStudentsByStudyGroups($groupID)
+    {
+        $sql = "CALL `GetStudentsByStudyGroups`('$groupID'); ";
+        return DB::query(Database::SELECT, $sql)->execute();
+    }    
+    
+    public function getAccountInfoByID($ID)
+    {
+        $sql = "CALL `GetAccInfoByID`('$ID'); ";
+        return DB::query(Database::SELECT, $sql)->execute();
+    }    
+    
+}
\ No newline at end of file
diff --git a/~dev_rating/application/views/pdf/activationTemplate.twig b/~dev_rating/application/views/pdf/activationTemplate.twig
new file mode 100644
index 000000000..1428c3906
--- /dev/null
+++ b/~dev_rating/application/views/pdf/activationTemplate.twig
@@ -0,0 +1,20 @@
+{% for group in Groups %}
+    <h1>{{ System.Title }} - коды активации</h1>
+    <h3>{{ group.Spec }}, РєСѓСЂСЃ {{ group.Grade }}, РіСЂСѓРїРїР° {{ group.Num }}</h3>
+    {% for account in group.People %}
+    <table width='100%' cellspacing='0'>
+    <tr>
+        <td class="cutline" width='10%'>&nbsp;</td>
+        <td class='personal_info' width='60%'>
+            {{ loop.index }}. {{ account.LastName }} {{ account.FirstName }} {{ account.SecondName }}
+        </td>
+        <td class='activation_code' width='40%'>
+            {{ account.ActivationCode }}
+        </td>
+    </tr>
+    </table>
+    {% endfor %}
+    {% if not loop.last %}
+        <pagebreak />
+    {% endif %}
+{% endfor %}
\ No newline at end of file
diff --git a/~dev_rating/media/css/acTpl.css b/~dev_rating/media/css/acTpl.css
new file mode 100644
index 000000000..71784e7f8
--- /dev/null
+++ b/~dev_rating/media/css/acTpl.css
@@ -0,0 +1,34 @@
+html
+{
+    font-family: Arial;
+}
+
+tr
+{
+    margin: 2px 0;
+}
+
+.cutline
+{
+    border-left: 1px dotted black;
+    border-right: 1px dotted black;
+    background: #eee;
+    border-style: dotted;
+}
+
+.personal_info
+{
+    padding: 8px;
+    font-size: 14px;
+    border-top: 1px solid black;
+    border-bottom: 1px solid black;    
+}
+
+.activation_code
+{
+    padding: 8px;
+    font-size: 14px;
+    text-align: left;
+    border-top: 1px solid black;
+    border-bottom: 1px solid black;
+}
diff --git a/~dev_rating/modules/mpdf/classes/View/MPDF/Core.php b/~dev_rating/modules/mpdf/classes/View/MPDF/Core.php
index c856a6ea7..55efcb3ae 100644
--- a/~dev_rating/modules/mpdf/classes/View/MPDF/Core.php
+++ b/~dev_rating/modules/mpdf/classes/View/MPDF/Core.php
@@ -9,7 +9,7 @@
  * @copyright  (c) 2009 Woody Gilk
  * @license    MIT
  */
-abstract class View_MPDF_Core extends View {
+abstract class View_MPDF_Core extends Twig {
 
 	protected $mpdf = NULL;
 	protected $view_file = NULL;
-- 
GitLab