/**
  * Check for imports in the document and process them.
  * Converts imported xml into ACL and passes back to this builder.
  *
  * This is recursive so the end result is that we do a depth first leaf node
  * construction of the ACL
  *
  * @param string $basePath Path to directory of parent file
  */
 protected function processImports($basePath)
 {
     $xpath = new \DOMXPath($this->xml);
     $xpath->registerNamespace('acl', self::NS);
     $importNodes = $xpath->query('//acl:acl/acl:imports/acl:import');
     if ($importNodes->length == 0) {
         return;
     }
     foreach ($importNodes as $iNode) {
         $importName = $iNode->nodeValue;
         if (dirname($importName) == '.') {
             //assume it is in same directory as the parent file
             $importName = "{$basePath}/{$importName}";
         } elseif (strstr($importName, '..') == 0) {
             //it is relative to parent file directory
             $file = basename($importName);
             $dir = realpath($basePath . '/' . dirname($importName));
             $importName = "{$dir}/{$file}";
         }
         $builder = new self(new StringType($importName), $this->acl);
         if ($builder->build()) {
             $result = $builder->getResult();
             $this->acl = $result['acl'];
         }
     }
 }
Example #2
0
 public function getResult($method = true, array $options = []) : Result
 {
     $options = $this->formatResultOptions($options);
     // Filter if tag is provided & return
     if ($options['%tagFilter']) {
         $chrono = new Timer_Chrono($this->_timer, 'GetResult with filter');
         $filter = new self();
         foreach ($this->getCandidatesList() as $candidate) {
             $filter->addCandidate($candidate);
         }
         foreach ($this->getVotesList($options['tags'], $options['withTag']) as $vote) {
             $filter->addVote($vote);
         }
         unset($chrono);
         return $filter->getResult($method, ['algoOptions' => $options['algoOptions']]);
     }
     ////// Start //////
     // Prepare
     $this->prepareResult();
     //////
     $chrono = new Timer_Chrono($this->_timer);
     if ($method === true) {
         $this->initResult(Condorcet::getDefaultMethod());
         $result = $this->_Calculator[Condorcet::getDefaultMethod()]->getResult($options['algoOptions']);
     } elseif ($method = Condorcet::isAuthMethod($method)) {
         $this->initResult($method);
         $result = $this->_Calculator[$method]->getResult($options['algoOptions']);
     } else {
         throw new CondorcetException(8, $method);
     }
     $chrono->setRole('GetResult for ' . $method);
     return $result;
 }
Example #3
0
 /**
  * Remove a list of users given their user id from the cours
  * @param array $userIdList list of user ids to add
  * @param Claro_Class $class execute class unregistration instead of individual registration if given (default:null)
  * @param bool $keepTrackingData tracking data will be deleted if set to false (default:true, i.e. keep data)
  * @param array $moduleDataToPurge list of module_label => (purgeTracking => bool, purgeData => bool)
  * @param bool $unregisterFromSourceIfLastSession remove users that are in no other session course from the source course if any
  * @return boolean
  */
 public function removeUserIdListFromCourse($userIdList, $class = null, $keepTrackingData = true, $moduleDataToPurge = array(), $unregisterFromSourceIfLastSession = true)
 {
     if (!count($userIdList)) {
         return false;
     }
     $classMode = is_null($class) ? false : true;
     $courseCode = $this->course->courseId;
     $sqlCourseCode = $this->database->quote($courseCode);
     if ($classMode && !$class->isRegisteredToCourse($courseCode)) {
         $this->result->addError(get_lang("Class not registered to course"));
         $this->result->setStatus(Claro_BatchRegistrationResult::STATUS_ERROR_NOTHING_TO_DO);
         return false;
     }
     // update user registration counts
     $cntToChange = $classMode ? 'count_class_enrol' : 'count_user_enrol';
     $this->database->exec("\n            UPDATE\n                `{$this->tableNames['rel_course_user']}`\n            SET\n                `{$cntToChange}` = `{$cntToChange}` - 1\n            WHERE\n                `code_cours` = {$sqlCourseCode}\n            AND\n                `{$cntToChange}` > 0\n            AND\n                `user_id` IN (" . implode(',', $userIdList) . ")\n        ");
     // get the user ids to remove
     $userListToRemove = $this->database->query("\n            SELECT \n                `user_id`\n            FROM\n                `{$this->tableNames['rel_course_user']}`\n            WHERE\n                `count_class_enrol` <= 0\n            AND\n                `count_user_enrol` <= 0\n            AND\n                `code_cours` = {$sqlCourseCode}\n        ");
     if ($userListToRemove->numRows()) {
         $userIdListToRemove = array();
         foreach ($userListToRemove as $user) {
             $userIdListToRemove[] = $user['user_id'];
         }
         $sqlList = array();
         $sqlList[] = "DELETE FROM `{$this->tableNames['bb_rel_topic_userstonotify']}` WHERE user_id IN (" . implode(',', $userIdListToRemove) . ")";
         $sqlList[] = "DELETE FROM `{$this->tableNames['userinfo_content']}` WHERE user_id IN (" . implode(',', $userIdListToRemove) . ")";
         $sqlList[] = "UPDATE `{$this->tableNames['group_team']}` SET `tutor` = NULL WHERE `tutor` IN (" . implode(',', $userIdListToRemove) . ")";
         $sqlList[] = "DELETE FROM `{$this->tableNames['group_rel_team_user']}` WHERE user IN (" . implode(',', $userIdListToRemove) . ")";
         if (!$keepTrackingData) {
             $sqlList[] = "DELETE FROM `{$this->tableNames['tracking_event']}` WHERE user_id IN (" . implode(',', $userIdListToRemove) . ")";
         }
         $sqlList[] = "DELETE FROM `{$this->tableNames['rel_course_user']}` WHERE user_id IN (" . implode(',', $userIdListToRemove) . ") AND `code_cours` = {$sqlCourseCode}";
         foreach ($sqlList as $sql) {
             $this->database->exec($sql);
         }
         if (!empty($moduleDataToPurge)) {
             foreach ($moduleDataToPurge as $moduleData) {
                 $connectorPath = get_module_path($moduleData['label']) . '/connector/adminuser.cnr.php';
                 if (file_exists($connectorPath)) {
                     require_once $connectorPath;
                     $connectorClass = $moduleData['label'] . '_AdminUser';
                     if (class_exist($connectorClass)) {
                         $connector = new $connectorClass($this->database);
                         if ($moduleData['purgeTracking']) {
                             $connector->purgeUserListCourseTrackingData($userIdListToRemove, $this->course->courseId);
                         }
                         if ($moduleData['purgeResources']) {
                             $connector->purgeUserListCourseResources($userIdListToRemove, $this->course->courseId);
                         }
                     } else {
                         Console::warning("Class {$connectorClass} not found");
                     }
                 } else {
                     Console::warning("No user delete connector found for module {$moduleData['label']}");
                 }
             }
         }
         $this->result->addDeleted($userIdListToRemove);
         if ($this->course->isSourceCourse()) {
             $sessionCourseIterator = $this->course->getChildren();
             foreach ($sessionCourseIterator as $sessionCourse) {
                 $batchReg = new self($sessionCourse, $this->database);
                 $batchReg->removeUserIdListFromCourse($userIdListToRemove, $class, $keepTrackingData, $moduleDataToPurge, $unregisterFromSourceIfLastSession);
                 $this->result->mergeResult($batchReg->getResult());
             }
         }
         if ($this->course->hasSourceCourse() && $unregisterFromSourceIfLastSession) {
             $sourceCourse = $this->course->getSourceCourse();
             $sessionCourseIterator = $sourceCourse->getChildren();
             $foundSessionWithClass = false;
             if ($classMode) {
                 foreach ($sessionCourseIterator as $sessionCourse) {
                     if ($sessionCourse->courseId != $this->course->courseId && $class->isRegisteredToCourse($sessionCourse->courseId)) {
                         $foundSessionWithClass = true;
                     }
                 }
                 if (!$foundSessionWithClass) {
                     $batchReg = new self($sourceCourse, $this->database);
                     $batchReg->removeUserIdListFromCourse($userIdListToRemove, $class, $keepTrackingData, $moduleDataToPurge, $unregisterFromSourceIfLastSession);
                 }
             } else {
                 // get userids registered in other sessions than the current one
                 $sessionList = $sourceCourse->getChildrenList();
                 if (count($sessionList)) {
                     $userIdListToRemoveFromSource = array();
                     $sessionIdList = array_keys($sessionList);
                     $sqlCourseCode = $this->database->quote($this->course->courseId);
                     $usersInOtherSessions = $this->database->query("\n                            SELECT\n                                user_id\n                            FROM\n                                `{$this->tableNames['rel_course_user']}`\n                            WHERE\n                                user_id IN (" . implode(',', $userIdListToRemove) . ")\n                            AND\n                                code_cours IN ('" . implode("','", $sessionIdList) . "')\n                            AND\n                                code_cours != {$sqlCourseCode}\n                        ");
                     // loop on $userIdList and keep only those who are not in another session and inject them in $userIdListToRemoveFromSource
                     $usersInOtherSessionsList = array();
                     foreach ($usersInOtherSessions as $userNotToRemove) {
                         $usersInOtherSessionsList[$userNotToRemove['user_id']] = $userNotToRemove['user_id'];
                     }
                     foreach ($userListToRemove as $userIdToRemove) {
                         if (!isset($usersInOtherSessionsList[$userIdToRemove['user_id']])) {
                             $userIdListToRemoveFromSource[] = $userIdToRemove['user_id'];
                         }
                     }
                     if (count($userIdListToRemoveFromSource)) {
                         $batchReg = new self($sourceCourse, $this->database);
                         $batchReg->removeUserIdListFromCourse($userIdListToRemoveFromSource, $class, $keepTrackingData, $moduleDataToPurge, $unregisterFromSourceIfLastSession);
                         $this->result->mergeResult($batchReg->getResult());
                     }
                 }
             }
         }
     } else {
         $this->result->setStatus(Claro_BatchRegistrationResult::STATUS_ERROR_NOTHING_TO_DO);
         $this->result->addError(get_lang("No user to delete"));
     }
     return !$this->result->hasError();
 }
Example #4
0
 /**
  * Merge a sublayer with another sublayer below it in the stack
  * Note: the result layer will conserve the given id
  * Return true if success or false if layer isn't found or doesn't have a layer under it in the stack
  *
  * @param integer $layerId
  *
  * @return boolean
  */
 public function mergeDown($layerId)
 {
     // if the layer exists in document
     if ($this->isLayerInIndex($layerId)) {
         $layerLevel = $this->getLayerLevel($layerId);
         $layerPositions = $this->getLayerPositions($layerId);
         $layer = $this->getLayer($layerId);
         $layerWidth = $layer->getWidth();
         $layerHeight = $layer->getHeight();
         $layerPositionX = $this->layerPositions[$layerId]["x"];
         $layerPositionY = $this->layerPositions[$layerId]["y"];
         if ($layerLevel > 1) {
             $underLayerId = $this->layerLevels[$layerLevel - 1];
             $underLayer = $this->getLayer($underLayerId);
             $underLayerWidth = $underLayer->getWidth();
             $underLayerHeight = $underLayer->getHeight();
             $underLayerPositionX = $this->layerPositions[$underLayerId]["x"];
             $underLayerPositionY = $this->layerPositions[$underLayerId]["y"];
             $totalWidthLayer = $layerWidth + $layerPositionX;
             $totalHeightLayer = $layerHeight + $layerPositionY;
             $totalWidthUnderLayer = $underLayerWidth + $underLayerPositionX;
             $totalHeightUnderLayer = $underLayerHeight + $underLayerPositionY;
             $minLayerPositionX = $layerPositionX;
             if ($layerPositionX > $underLayerPositionX) {
                 $minLayerPositionX = $underLayerPositionX;
             }
             $minLayerPositionY = $layerPositionY;
             if ($layerPositionY > $underLayerPositionY) {
                 $minLayerPositionY = $underLayerPositionY;
             }
             if ($totalWidthLayer > $totalWidthUnderLayer) {
                 $layerTmpWidth = $totalWidthLayer - $minLayerPositionX;
             } else {
                 $layerTmpWidth = $totalWidthUnderLayer - $minLayerPositionX;
             }
             if ($totalHeightLayer > $totalHeightUnderLayer) {
                 $layerTmpHeight = $totalHeightLayer - $minLayerPositionY;
             } else {
                 $layerTmpHeight = $totalHeightUnderLayer - $minLayerPositionY;
             }
             $layerTmp = new self(array("width" => $layerTmpWidth, "height" => $layerTmpHeight));
             $layerTmp->addLayer(1, $underLayer, $underLayerPositionX - $minLayerPositionX, $underLayerPositionY - $minLayerPositionY);
             $layerTmp->addLayer(2, $layer, $layerPositionX - $minLayerPositionX, $layerPositionY - $minLayerPositionY);
             // Update layers
             $layerTmp->mergeAll();
             $this->layers[$underLayerId] = clone $layerTmp;
             $this->layerPositions[$underLayerId]["x"] = $minLayerPositionX;
             $this->layerPositions[$underLayerId]["y"] = $minLayerPositionX;
         } else {
             $layerTmp = new self(array("imageVar" => $this->image));
             $layerTmp->addLayer(1, $layer, $layerPositionX, $layerPositionY);
             // Update background image
             $this->image = $layerTmp->getResult();
         }
         unset($layerTmp);
         // Remove the merged layer from the stack
         $this->remove($layerId);
         return true;
     }
     return false;
 }