• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List
  • Globals

survey/classes/class.ilObjSurveyAccess.php

Go to the documentation of this file.
00001 <?php
00002 /*
00003         +-----------------------------------------------------------------------------+
00004         | ILIAS open source                                                           |
00005         +-----------------------------------------------------------------------------+
00006         | Copyright (c) 1998-2001 ILIAS open source, University of Cologne            |
00007         |                                                                             |
00008         | This program is free software; you can redistribute it and/or               |
00009         | modify it under the terms of the GNU General Public License                 |
00010         | as published by the Free Software Foundation; either version 2              |
00011         | of the License, or (at your option) any later version.                      |
00012         |                                                                             |
00013         | This program is distributed in the hope that it will be useful,             |
00014         | but WITHOUT ANY WARRANTY; without even the implied warranty of              |
00015         | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the               |
00016         | GNU General Public License for more details.                                |
00017         |                                                                             |
00018         | You should have received a copy of the GNU General Public License           |
00019         | along with this program; if not, write to the Free Software                 |
00020         | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA. |
00021         +-----------------------------------------------------------------------------+
00022 */
00023 
00024 include_once("classes/class.ilObjectAccess.php");
00025 
00035 class ilObjSurveyAccess extends ilObjectAccess
00036 {
00052         function _checkAccess($a_cmd, $a_permission, $a_ref_id, $a_obj_id, $a_user_id = "")
00053         {
00054                 global $ilUser, $lng, $rbacsystem, $ilAccess;
00055 
00056                 if ($a_user_id == "")
00057                 {
00058                         $a_user_id = $ilUser->getId();
00059                 }
00060 
00061                 switch ($a_permission)
00062                 {
00063                         case "visible":
00064                                 if (!ilObjSurveyAccess::_lookupCreationComplete($a_obj_id) &&
00065                                         (!$rbacsystem->checkAccess('write', $a_ref_id)))
00066                                 {
00067                                         $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("warning_survey_not_complete"));
00068                                         return false;
00069                                 }
00070                                 break;
00071                 }
00072 
00073                 switch ($a_cmd)
00074                 {
00075                         case "run":
00076                                 if (!ilObjSurveyAccess::_lookupCreationComplete($a_obj_id)
00077                                         || !(ilObjSurveyAccess::_lookupStatus($a_obj_id) == 1))
00078                                 {
00079                                         $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("warning_survey_not_complete"));
00080                                         return false;
00081                                 }
00082                                 break;
00083 
00084                         case "evaluation":
00085                                 if (!ilObjSurveyAccess::_lookupCreationComplete($a_obj_id))
00086                                 {
00087                                         $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("warning_survey_not_complete"));
00088                                         return false;
00089                                 }
00090                                 // maybe an additional evaluation permission would be suitable
00091                                 if (!$rbacsystem->checkAccess('write',$a_ref_id) &&
00092                                         !ilObjSurveyAccess::_lookupEvaluationAccess($a_obj_id))
00093                                 {
00094                                         $ilAccess->addInfoItem(IL_NO_OBJECT_ACCESS, $lng->txt("no_permission"));
00095                                         return false;
00096                                 }
00097                                 break;
00098                 }
00099 
00100                 return true;
00101         }
00102         
00103         
00116         function _getCommands()
00117         {
00118                 $commands = array
00119                 (
00120                         array("permission" => "read", "cmd" => "run", "lang_var" => "svy_run",
00121                                 "default" => true),
00122                         array("permission" => "write", "cmd" => "", "lang_var" => "edit"),
00123                         array("permission" => "read", "cmd" => "evaluation", "lang_var" => "svy_evaluation")
00124                 );
00125                 
00126                 return $commands;
00127         }
00128 
00129         //
00130         // object specific access related methods
00131         //
00132 
00136         function _lookupCreationComplete($a_obj_id)
00137         {
00138                 global $ilDB;
00139 
00140                 $q = sprintf("SELECT * FROM survey_survey WHERE obj_fi=%s",
00141                         $ilDB->quote($a_obj_id)
00142                 );
00143                 $result = $ilDB->query($q);
00144 
00145                 if ($result->numRows() == 1)
00146                 {
00147                         $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00148                 }
00149                 if (!$row->complete)
00150                 {
00151                         return false;
00152                 }
00153 
00154                 return true;
00155         }
00156 
00160         function _lookupEvaluationAccess($a_obj_id)
00161         {
00162                 global $ilDB;
00163 
00164                 $q = sprintf("SELECT * FROM survey_survey WHERE obj_fi=%s",
00165                         $ilDB->quote($a_obj_id)
00166                 );
00167                 $result = $ilDB->query($q);
00168                 if ($result->numRows() == 1)
00169                 {
00170                         $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00171                 }
00172 
00173                 return $row->evaluation_access;
00174         }
00175 
00179         function _lookupStatus($a_obj_id)
00180         {
00181                 global $ilDB;
00182 
00183                 $q = sprintf("SELECT * FROM survey_survey WHERE obj_fi=%s",
00184                         $ilDB->quote($a_obj_id)
00185                 );
00186                 $result = $ilDB->query($q);
00187                 if ($result->numRows() == 1) {
00188                         $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00189                 }
00190 
00191                 return $row->status;
00192         }
00193 
00199         function _lookupFinished($a_obj_id, $a_user_id = "")
00200         {
00201                 global $ilDB, $ilUser;
00202 
00203                 $finished = "";
00204                 if (!strlen($a_user_id))
00205                         $a_user_id = $ilUser->id;
00206 
00207                 $q = sprintf("SELECT * FROM survey_survey WHERE obj_fi=%s",
00208                                 $ilDB->quote($a_obj_id)
00209                         );
00210                 $result = $ilDB->query($q);
00211                 if ($result->numRows() == 1)
00212                 {
00213                         $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00214                         if ($row->anonymize == 1)
00215                         {
00216                                 $q = sprintf("SELECT * FROM survey_finished WHERE survey_fi = %s AND anonymous_id = %s",
00217                                         $ilDB->quote($row->survey_id),
00218                                         $ilDB->quote(md5($a_user_id . $row->survey_id) . "")
00219                                 );
00220                         }
00221                         else
00222                         {
00223                                 $q = sprintf("SELECT * FROM survey_finished WHERE survey_fi = %s AND user_fi = %s",
00224                                         $ilDB->quote($row->survey_id),
00225                                         $ilDB->quote($a_user_id)
00226                                 );
00227                         }
00228                         $result = $ilDB->query($q);
00229                         if ($result->numRows() == 1)
00230                         {
00231                                 $row = $result->fetchRow(DB_FETCHMODE_OBJECT);
00232                                 $finished = (int)$row->state;
00233                         }
00234                 }
00235 
00236                 return $finished;
00237         }
00238 
00239 }
00240 
00241 ?>

Generated on Fri Dec 13 2013 10:18:33 for ILIAS Release_3_5_x_branch .rev 46805 by  doxygen 1.7.1