public function getChatSession()
 {
     return GcrChatSessionTable::getInstance()->find($this->session_id);
 }
 public function executeDelete(sfWebRequest $request)
 {
     $this->forward404Unless($this->getRequest()->isXmlHttpRequest());
     $this->authorizeRequest($request);
     if ($session_id = $request->getParameter('id')) {
         if ($chat_session = GcrChatSessionTable::getInstance()->find($session_id)) {
             $user_chat_session = $chat_session->getSessionUser($this->user);
             if ($user_chat_session) {
                 $user_chat_session->delete();
             }
         }
     }
     return sfView::NONE;
 }
 public function deleteInstitutionFromSystemEntirely()
 {
     // delete each moodle instance owned by this institution
     foreach ($this->getEschools() as $eschool) {
         $eschool->deleteEschoolFromSystemEntirely();
     }
     // delete this institution's database schema
     GcrDatabaseAccessPostgres::deleteSchemaFromSystem($this);
     // delete moodledata directory for institution
     exec(escapeshellcmd('rm -R ' . gcr::moodledataDir . $this->short_name . '/'));
     // delete password salt history for this institution
     Doctrine_Query::create()->delete('GcrInstitutionSaltHistory')->where('institutionid = ?', $this->id)->execute();
     Doctrine_Query::create()->delete('GcrTrial t')->where('t.organization_id = ?', $this->id)->execute();
     GcrChainedPaymentTable::getInstance()->createQuery('c')->delete()->where('c.user_institution_id = ?', $this->short_name)->execute();
     GcrChatSessionTable::getInstance()->createQuery('c')->delete()->where('c.eschool_id = ?', $this->short_name)->execute();
     GcrChatSessionUsersTable::getInstance()->createQuery('c')->delete()->where('c.user_eschool_id = ?', $this->short_name)->execute();
     GcrChatSessionInviteTable::getInstance()->createQuery('c')->delete()->where('c.user_eschool_id = ?', $this->short_name)->orWhere('c.from_user_eschool_id = ?', $this->short_name)->execute();
     GcrCommissionTable::getInstance()->createQuery('c')->delete()->where('c.institution_id = ?', $this->short_name)->execute();
     GcrEclassroomTable::getInstance()->createQuery('e')->delete()->where('e.user_institution_id = ?', $this->short_name)->execute();
     GcrEschoolMonthlyDataTable::getInstance()->createQuery('e')->delete()->where('e.eschool_id = ?', $this->short_name)->execute();
     GcrUserMonthlyDataTable::getInstance()->createQuery('u')->delete()->where('u.user_institution_id = ?', $this->short_name)->execute();
     GcrPayoffTable::getInstance()->createQuery('p')->delete()->where('p.user_eschool_id = ?', $this->short_name)->execute();
     GcrPurchaseTable::deleteInstitutionRecords($this);
     GcrUserStorageS3Table::deleteBucket($this);
     if ($address = $this->getAddressObject()) {
         $address->delete();
     }
     if ($contact1 = $this->getPersonObject()) {
         $contact1->delete();
     }
     if ($contact2 = $this->getPerson2Object()) {
         $contact2->delete();
     }
     $this->delete();
 }