public static function handleExportRequest()
 {
     $GLOBALS['Session']->requireAccountLevel('Staff');
     // This was causing a script timeout (30 seconds), this should help speed it up
     \Site::$debug = false;
     $sw = new SpreadsheetWriter();
     // fetch key objects from database
     $students = Student::getAllByListIdentifier(empty($_GET['students']) ? 'all' : $_GET['students']);
     $skills = Skill::getAll(['indexField' => 'ID']);
     $demonstrations = Demonstration::getAllByWhere('StudentID IN (' . implode(',', array_map(function ($Student) {
         return $Student->ID;
     }, $students)) . ')', ['order' => 'ID']);
     // build and output headers list
     $headers = ['Timestamp', 'Submitted by', 'ID', 'Name', 'Type of experience', 'Context', 'Perfromance task', 'Artifact', 'Competency', 'Standard', 'Rating', 'Level', 'Mapping'];
     $sw->writeRow($headers);
     // one row for each demonstration standard
     foreach ($demonstrations as $Demonstration) {
         $row = [date('Y-m-d H:i', $Demonstration->Created), $Demonstration->Creator->FullName, $Demonstration->Student->StudentNumber, $Demonstration->Student->FullName, $Demonstration->ExperienceType, $Demonstration->Context, $Demonstration->PerformanceType, $Demonstration->ArtifactURL];
         $demonstrationSkills = DemonstrationSkill::getAllByField('DemonstrationID', $Demonstration->ID);
         // Don't rebuild the row for each standard demonstrated, just overwrite the last set of values
         foreach ($demonstrationSkills as $DemonstrationSkill) {
             $skill = $skills[$DemonstrationSkill->SkillID];
             $row[8] = $skill->Competency->Code;
             $row[9] = $skill->Code;
             $row[10] = $DemonstrationSkill->Level > 0 ? $DemonstrationSkill->Level : 'M';
             $row[11] = 9;
             $row[12] = '';
             $sw->writeRow($row);
         }
     }
 }
Esempio n. 2
0
 /**
  * Construct
  * Initiate needed classes
  */
 public function __construct()
 {
     self::$title = '+Task';
     self::$action = false;
     self::$section = false;
     self::$subsection = false;
     self::$do = false;
     /*
      * References to instances of classes accessible for other classes
      */
     self::$i18n = new i18n();
     self::$db = new dBase();
     self::$auth = new Auth();
     self::$user = Auth::$user;
     $config = Config::getInstance();
     self::$defaults = $config->getSection('DEFAULTS');
     self::$debug = $config->getSection('DEBUG');
     self::getOffsetArray();
     self::display();
     self::getDebug();
     self::$log = new log();
     ##FB::info($_REQUEST, 'Request data');
     ##FB::info($_SERVER, 'Site construct');
 }
Esempio n. 3
0
<?php

$GLOBALS['Session']->requireAccountLevel('Developer');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    Site::$autoPull = true;
    Site::$debug = true;
    set_time_limit(0);
    $trees = array('dwoo-plugins', 'event-handlers', 'ext-library', 'html-templates', 'js-library', 'php-classes', 'php-config', 'phpunit-tests', 'php-migrations', 'site-root', 'sencha-workspace/.sencha', 'sencha-workspace/microloaders', 'sencha-workspace/pages', 'sencha-workspace/packages', 'sencha-workspace/EmergenceEditor', 'sencha-workspace/EmergencePullTool', 'sencha-workspace/ContentEditor');
    $message = "";
    foreach ($_POST['collections'] as $collection) {
        $filesCached = Emergence_FS::cacheTree($collection, true);
        $message .= sprintf('Precached %03u files in %s' . PHP_EOL, $filesCached, $collection);
    }
}
RequestHandler::respond('precache', array('message' => $message));
 public static function handleExportRequest()
 {
     $GLOBALS['Session']->requireAccountLevel('Staff');
     // This was causing a script timeout (30 seconds), this should help speed it up
     \Site::$debug = false;
     $sw = new SpreadsheetWriter();
     // fetch key objects from database
     $students = Student::getAllByListIdentifier(empty($_GET['students']) ? 'all' : $_GET['students']);
     $contentAreas = ContentArea::getAll(['order' => 'Code']);
     // collect counts of all missing demonstrations by student+competency
     try {
         $missingResults = DB::allRecords('SELECT StudentID, CompetencyID, SUM(neededDemonstrationsMissed) AS totalNeededDemonstrationsMissed' . ' FROM (' . '  SELECT' . '    Demonstration.StudentID' . '    ,Skill.CompetencyID' . '    ,LEAST(' . '       GREATEST(Skill.DemonstrationsRequired - SUM(IF(DemonstrationSkill.Level != 0, 1, 0)), 0)' . '       ,SUM(IF(DemonstrationSkill.Level = 0, 1, 0))' . '    ) AS neededDemonstrationsMissed' . '   FROM `%s` Demonstration' . '   JOIN `%s` DemonstrationSkill' . '    ON DemonstrationSkill.DemonstrationID = Demonstration.ID' . '   JOIN `%s` Skill' . '    ON Skill.ID = DemonstrationSkill.SkillID' . '   WHERE Demonstration.StudentID IN (%s)' . '   GROUP BY Demonstration.StudentID, DemonstrationSkill.SkillID' . ' ) MissingDemonstrationsByStudentSkill' . ' GROUP BY StudentID, CompetencyID', [Demonstration::$tableName, DemonstrationSkill::$tableName, Skill::$tableName, implode(',', array_map(function ($Student) {
             return $Student->ID;
         }, $students))]);
         $missingDemonstrationsByStudentCompetency = [];
         foreach ($missingResults as $result) {
             $missingDemonstrationsByStudentCompetency[$result['StudentID']][$result['CompetencyID']] = intval($result['totalNeededDemonstrationsMissed']);
         }
     } catch (TableNotFoundException $e) {
         $missingDemonstrationsByStudentCompetency = [];
     }
     // build and output headers list
     $headers = ['Student Name', 'Student Number', 'Grade Level'];
     foreach ($contentAreas as $ContentArea) {
         foreach ($ContentArea->Competencies as $Competency) {
             $headers[] = $Competency->Code . '-Logged';
             $headers[] = $Competency->Code . '-Total';
             $headers[] = $Competency->Code . '-AVG';
         }
         $headers[] = $ContentArea->Code . '-Logged';
         $headers[] = $ContentArea->Code . '-Total';
         $headers[] = $ContentArea->Code . '-Missing';
         $headers[] = $ContentArea->Code . '-AVG';
     }
     $sw->writeRow($headers);
     // one row for each demonstration
     foreach ($students as $Student) {
         $row = [$Student->FullName, $Student->StudentNumber, 9];
         foreach ($contentAreas as $ContentArea) {
             $demonstrationsCounted = 0;
             $demonstrationsRequired = 0;
             $demonstrationsMissing = 0;
             $contentAreaAverageTotal = 0;
             foreach ($ContentArea->Competencies as $Competency) {
                 $competencyCompletion = $Competency->getCompletionForStudent($Student);
                 // Logged
                 $row[] = $competencyCompletion['demonstrationsCount'];
                 // Total
                 $row[] = $Competency->getTotalDemonstrationsRequired();
                 // Average
                 $row[] = $competencyCompletion['demonstrationsCount'] ? round($competencyCompletion['demonstrationsAverage'], 2) : null;
                 $demonstrationsCounted += $competencyCompletion['demonstrationsCount'];
                 $demonstrationsRequired += $Competency->getTotalDemonstrationsRequired();
                 // averages are weighted by number of demonstrations
                 $contentAreaAverageTotal += $competencyCompletion['demonstrationsAverage'] * $competencyCompletion['demonstrationsCount'];
                 if (isset($missingDemonstrationsByStudentCompetency[$Student->ID][$Competency->ID])) {
                     $demonstrationsMissing += $missingDemonstrationsByStudentCompetency[$Student->ID][$Competency->ID];
                 }
             }
             $row[] = $demonstrationsCounted;
             $row[] = $demonstrationsRequired;
             $row[] = $demonstrationsMissing;
             $row[] = $demonstrationsCounted ? round($contentAreaAverageTotal / $demonstrationsCounted, 2) : null;
         }
         $sw->writeRow($row);
     }
 }
 public function Update()
 {
     //$obj_parent = $this->CreateMyTrueParent();
     /*if($obj_parent!=false)
          {
              $obj_parent->Update();
          }
          if($obj_parent!=false)
          {
              //Attributs du parent
              $temp = get_object_vars($obj_parent);
              $temp = root::removeRootProperties($temp);
              $attr_parent = array_keys($temp);
              //Attributs du actuel
              $temp = get_object_vars($this);
              $temp = root::removeRootProperties($temp);
              $attr = array_keys($temp);
              //virer les clés similaires entre parent et actuel
              array_splice($attr,sizeof($attr)-sizeof($attr_parent),sizeof($attr_parent));
              //récupérer le nom de la clé étrangère unique
              $foreign_key_id = $this->getParentsPref()[0].'id';
          }
          else
          {
              $attr = get_object_vars($this);
              $attr = root::removeRootProperties($attr);
              $attr = array_keys($attr);
              $foreign_key_id = 'id';
          }
       */
     $attr = $this->getSqlAttr();
     $dotliste = '';
     $cpt = 0;
     foreach ($attr as $key => $val) {
         $cpt++;
         if (!in_array($key, $this->getPrimary())) {
             $dotliste .= $key . '=:' . $key;
             if ($cpt != sizeof($attr)) {
                 $dotliste .= ',';
             }
         }
     }
     if ($dotliste == '') {
         return;
     }
     //Préparation de la requete WHERE
     if (Manager::getInstance()->isDebug()) {
         Site::debug("UPDATE " . DBPRE . get_class($this) . " SET " . $dotliste . " WHERE " . $this->getPrimaryFormatedForSql());
     }
     $req = DB::getInstance()->prepare("UPDATE " . DBPRE . get_class($this) . " SET " . $dotliste . " WHERE " . $this->getPrimaryFormatedForSql());
     foreach ($attr as $key => $val) {
         if (!in_array($key, $this->getPrimary())) {
             if (is_object($this->getAttrWithPref($key))) {
                 $obj = $this->getAttrWithPref($key);
                 $prim = $obj->getPrimary();
                 $req->bindParam(':' . $key, $obj->getAttrWithPref($prim[0]));
             } else {
                 $req->bindParam(':' . $key, $this->getAttrWithPref($key));
             }
         }
     }
     $req->execute();
 }
 public function query()
 {
     $where = '';
     $table_from = '';
     $references_done = array();
     $declaration = array();
     $tempfrom = $this->from;
     if ($this->mode != "DELETE") {
         if ($this->select == '*') {
             $select = "SELECT ";
         }
         foreach ($tempfrom as $key => $class) {
             if ($this->select == '*') {
                 $select .= $class::getSqlSelectAttr("obj" . $key) . ',';
             }
             $copyfrom = $this->from;
             $objid = "obj" . $key;
             $found = false;
             foreach ($references_done as $d) {
                 $t = explode('.', $d);
                 if ($objid == $t[0]) {
                     $found = true;
                     break;
                 }
             }
             if (!$found && !in_array($class, $declaration)) {
                 $table_from .= DBPRE . $class . " as " . $objid . " " . strtoupper($objid);
                 array_push($declaration, $class);
             } else {
                 $table_from = substr($table_from, 0, -1);
             }
             //Si il y a au moins une référence
             if (sizeof($class::$references) > 0) {
                 $refobj = array();
                 //Parcourir ces références
                 foreach ($class::$references as $ref) {
                     $tab = Site::multiexplode(array('->', '#'), $ref);
                     //Si l'objet référé est bien dans la liste des objets sélectionnés
                     if (in_array($tab[1], $this->from)) {
                         $objrefid = "obj" . array_search($tab[1], $copyfrom);
                         //Si le champ sélectionné est bien un champ SQL
                         if (!in_array($tab[0], $class::$exclusion)) {
                             if (!in_array($objid . "." . $tab[0] . "->{$objrefid}", $references_done)) {
                                 if (in_array($tab[1], $refobj)) {
                                     $objrefid = "obj" . (array_push($this->from, $tab[1]) - 1);
                                     if ($this->select == '*') {
                                         $klas = $tab[1];
                                         $select .= $klas::getSqlSelectAttr($objrefid) . ',';
                                     }
                                 }
                                 $prim = $tab[1]::getStaticPrimary();
                                 $table_from = str_replace(strtoupper($objid), " LEFT JOIN " . DBPRE . $tab[1] . " as " . $objrefid . " " . strtoupper($objrefid) . " ON " . $objid . "." . $tab[0] . " = " . $objrefid . "." . $prim[0] . " " . strtoupper($objid), $table_from);
                                 array_push($declaration, $tab[1]);
                                 array_push($references_done, $objid . "." . $tab[0] . "->" . $objrefid);
                                 unset($copyfrom[array_search($tab[1], $copyfrom)]);
                                 array_push($refobj, $tab[1]);
                             } else {
                                 array_push($refobj, $tab[1]);
                             }
                         } else {
                             array_push($references_done, $objid . "." . $tab[0] . "->" . $tab[1]);
                         }
                     }
                 }
             }
             //Si il y a au moins une référence inverse
             if (sizeof($class::$referenced) > 0) {
                 $refobj = array();
                 //Parcourir ces références
                 foreach ($class::$referenced as $ref) {
                     $tab = Site::multiexplode(array('<-'), $ref);
                     //Si l'objet qui nous réfère est bien dans la liste des objets sélectionnés
                     if (in_array($tab[1], $this->from) && !in_array($tab[1], $refobj)) {
                         $objrefid = "obj" . array_search($tab[1], $copyfrom);
                         if (!in_array($objrefid . "." . $tab[0] . "->{$objid}", $references_done)) {
                             $prim = $class::getStaticPrimary();
                             $table_from = str_replace(strtoupper($objid), " LEFT JOIN " . DBPRE . $tab[1] . " as " . $objrefid . " " . strtoupper($objrefid) . " ON " . $objrefid . "." . $tab[0] . " = " . $objid . "." . $prim[0] . " " . strtoupper($objid), $table_from);
                             array_push($declaration, $tab[1]);
                             array_push($references_done, $objrefid . "." . $tab[0] . "->" . $objid);
                             unset($copyfrom[array_search($tab[1], $copyfrom)]);
                         }
                         array_push($refobj, $tab[1]);
                     }
                 }
             }
             if ($key != sizeof($tempfrom) - 1) {
                 $table_from .= ',';
             }
         }
         foreach ($this->from as $key => $t) {
             $table_from = str_replace("OBJ{$key}", "", $table_from);
         }
         if ($this->select == '*') {
             $this->select = substr($select, 0, -1) . " FROM ";
         }
     } else {
         foreach ($this->from as $key => $class) {
             $table_from .= DBPRE . $class . ',';
         }
         $table_from = substr($table_from, 0, -1);
     }
     if ($where != '') {
         $where = ' WHERE ' . $where;
     }
     if ($this->where != '') {
         if ($where != '') {
             $where .= $this->where;
         } else {
             $where = ' WHERE ' . $this->where;
         }
     } else {
         if ($where != '') {
             $where = substr($where, 0, -4);
         }
     }
     $orderby = '';
     if ($this->orderby != '') {
         $orderby = " ORDER BY ";
         foreach ($this->orderby as $o) {
             foreach ($this->from as $key => $f) {
                 if (property_exists($f, $o)) {
                     $orderby .= 'obj' . $key . '.' . $o . ',';
                     break;
                 }
             }
         }
         $orderby = substr($orderby, 0, -1);
     }
     $request = $this->select . $table_from . $where . $this->extra . $orderby;
     if ($this->debug) {
         Site::debug($request);
     }
     $pdo = DB::getInstance();
     $result = $pdo->query($request);
     if ($this->mode == "DEFAULT") {
         while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
             //Créer ou récupérer les objets
             $objects = array();
             foreach ($this->from as $key => $t) {
                 $primary = $t::getStaticPrimary();
                 if ($row[$primary[0] . "_obj" . $key] != NULL) {
                     $obj = new $t(0, false);
                     $obj->CreateWithObjId($row, '_obj' . $key);
                     $obj = $this->addToObjects($obj);
                     $objects["obj" . $key] = $obj;
                     if (array_key_exists($t, $objects)) {
                         if (is_array($objects[$t])) {
                             array_push($objects[$t], $obj);
                         } else {
                             $objects[$t] = array($objects[$t], $obj);
                         }
                     } else {
                         $objects[$t] = $obj;
                     }
                 } else {
                     $objects["obj" . $key] = NULL;
                 }
             }
             //Linker les objets entre eux
             foreach ($references_done as $ref) {
                 $tab = Site::multiexplode(array('->', '.'), $ref);
                 //if(preg_match("^obj[0-9]+$",$tab[0]))
                 if ($objects[$tab[0]] != NULL && array_key_exists($tab[2], $objects)) {
                     $objects[$tab[0]]->setViaManager($tab[1], $objects[$tab[2]]);
                 }
             }
         }
     } else {
         if ($this->mode == "COUNT") {
             $rs = $result->fetch(PDO::FETCH_ASSOC);
             $result->closeCursor();
             $this->select = "";
             $this->from = "";
             $this->where = "";
             $this->extra = "";
             $this->mode = "";
             $this->orderby = "";
             return $rs["NUMBER"];
         }
     }
     $result->closeCursor();
     $this->select = "";
     $this->from = "";
     $this->where = "";
     $this->extra = "";
     $this->mode = "";
     $this->orderby = "";
 }