public function removeEschool($eschool)
 {
     $filters = array();
     $filters[] = new GcrDatabaseQueryFilter('mhr_institution_name', '=', $this->obj->name);
     $filters[] = new GcrDatabaseQueryFilter('eschool_id', '=', $eschool->getShortName());
     $q = new GcrDatabaseQuery($this->app, 'gcr_institution_catalog', 'delete from', $filters);
     $q->executeQuery();
 }
 public function getMdlRoleAssignments()
 {
     $records = array();
     $eschool = $this->getEschool();
     if ($eschool) {
         $mhr_user = $this->getUser();
         $mdl_user = $mhr_user->getUserOnEschool($eschool);
         if ($mdl_user) {
             $mdl_role = $eschool->selectFromMdlTable('role', 'shortname', 'eclassroomcourseowner', true);
             $filters = array();
             $filters[] = new GcrDatabaseQueryFilter('roleid', '=', $mdl_role->id);
             $filters[] = new GcrDatabaseQueryFilter('userid', '=', $mdl_user->getObject()->id);
             $q = new GcrDatabaseQuery($eschool, 'role_assignments', 'select * from', $filters);
             $records = $q->executeQuery();
         }
     }
     return $records;
 }
 public function setEmailAddress($email)
 {
     $this->app->beginTransaction();
     try {
         $filters = array();
         $filters[] = new GcrDatabaseQueryFilter('owner', '=', $this->obj->id);
         $filters[] = new GcrDatabaseQueryFilter('title', '=', $this->obj->email);
         $filters[] = new GcrDatabaseQueryFilter('artefacttype', '=', 'email');
         $q = new GcrDatabaseQuery($this->app, 'artefact', 'select * from', $filters);
         $mhr_artefact = $q->executeQuery(true);
         if ($mhr_artefact) {
             $mhr_artefact_internal_profile_email = $this->app->selectFromMhrTable('artefact_internal_profile_email', 'artefact', $mhr_artefact->id, true);
             if ($mhr_artefact_internal_profile_email) {
                 $this->app->updateMhrTable('artefact_internal_profile_email', array('email' => $email), array('artefact' => $mhr_artefact->id));
             }
             $this->app->updateMhrTable('artefact', array('title' => $email), array('id' => $mhr_artefact->id));
         }
         $eschools = $this->app->getMnetEschools();
         foreach ($eschools as $eschool) {
             $mdl_user = $this->getUserOnEschool($eschool);
             if ($mdl_user) {
                 $eschool->updateMdlTable('user', array('email' => $email), array('id' => $mdl_user->getObject()->id));
             }
         }
         $this->app->updateMhrTable('usr', array('email' => $email), array('id' => $this->obj->id));
     } catch (Doctrine_Exception $e) {
         $this->app->rollbackTransaction();
         $this->app->gcError($e->getMessage(), 'gcdatabaseerror');
     }
     $this->app->commitTransaction();
 }
 /**
  * Created by: Ron Stewart
  * Date: 9/8/2011
  * This function was designed to set all non-siteadmin accounts to not receive emails (internal)
  * This was used to prevent spamming where bulk uploaded users were assigned random email
  * addresses at globalclassroom.us
  */
 public function executeTurnOffEmails(sfWebRequest $request)
 {
     global $CFG;
     $this->checkAuthorization();
     $this->forward404Unless($request->isMethod(sfRequest::POST));
     $form = $request->getPostParameters();
     if ($institution = Doctrine::getTable('GcrInstitution')->find($form['institution'])) {
         $i = 0;
         foreach ($institution->selectFromMhrTable('usr') as $mhr_user_obj) {
             $mhr_user = new GcrMhrUser($mhr_user_obj, $institution);
             if (!$mhr_user->getRoleManager()->hasPrivilege('EschoolStaff') && $mhr_user_obj->id != 0) {
                 $filters = array();
                 $filters[] = new GcrDatabaseQueryFilter('field', '=', 'maildisabled');
                 $filters[] = new GcrDatabaseQueryFilter('usr', '=', $mhr_user_obj->id);
                 $q = new GcrDatabaseQuery($institution, 'usr_account_preference', 'select * from', $filters);
                 if ($q->executeQuery(true)) {
                     $institution->updateMhrTable('usr_account_preference', array('value' => '1'), array('usr' => $mhr_user_obj->id, 'field' => 'maildisabled'));
                 } else {
                     $institution->insertIntoMhrTable('usr_account_preference', array('usr' => $mhr_user_obj->id, 'field' => 'maildisabled', 'value' => '1'));
                 }
                 $i++;
             }
         }
         $_SESSION['adminEschoolActionMessage'] = $institution->getFullName() . ' (' . $institution->getShortName() . '): ' . $i . ' users had emailing turned off';
     } else {
         $CFG->current_app->gcError('Invalid Institution Id: ' . $form['institution'], 'gcdatabaseerror');
     }
     $this->redirect($CFG->current_app->getUrl() . '/admin/eschool');
 }
 public function getCapabilities($filters = array(), $return_one = false)
 {
     $filters[] = new GcrDatabaseQueryFilter('roleid', '=', $this->obj->id);
     $q = new GcrDatabaseQuery($this->app, 'role_capabilities', 'select * from', $filters);
     return $q->executeQuery($return_one);
 }
 public function getMnetInstitutions()
 {
     $mnet_institutions = array();
     $filters = array(new GcrDatabaseQueryFilter('deleted', '=', '0'));
     $q = new GcrDatabaseQuery($this, 'mnet_host', 'select * from', $filters);
     foreach ($q->executeQuery() as $mdl_mnet_host) {
         if ($institution = $this->getHost($mdl_mnet_host)) {
             $mnet_institutions[] = $institution;
         }
     }
     if (count($mnet_institutions) > 0) {
         return $mnet_institutions;
     }
     return false;
 }
 public function getUsers($include_admin = false, $include_deleted = false)
 {
     $min_user_id = 0;
     $filters = array();
     if (!$include_admin) {
         $min_user_id = 1;
     }
     $filters[] = new GcrDatabaseQueryFilter('id', '>', $min_user_id);
     if (!$include_deleted) {
         $filters[] = new GcrDatabaseQueryFilter('deleted', '<', 1);
     }
     $q = new GcrDatabaseQuery($this, 'usr', 'select * from', $filters);
     return $q->executeQuery();
 }