/**
  * Pre-processor for $table->delete($pk)
  *
  * @param   mixed $pk An optional primary key value to delete.  If not set the instance property value is used.
  *
  * @return  void
  *
  * @since   3.1.2
  * @throws  UnexpectedValueException
  */
 public function onBeforeDelete($pk)
 {
     $db = $this->table->getDbo();
     jimport('Socialcommunity.profile');
     $profile = new Socialcommunity\Profile\Profile($db);
     $profile->load($this->table->id);
     if ($profile->getId()) {
         $params = JComponentHelper::getParams('com_socialcommunity');
         /** @var  $params Joomla\Registry\Registry */
         $filesystemHelper = new Prism\Filesystem\Helper($params);
         $mediaFolder = $filesystemHelper->getMediaFolderUri($profile->getId());
         $filesystem = $filesystemHelper->getFilesystem();
         $profile->removeImages($filesystem, $mediaFolder);
     }
 }
 /**
  * Remove all sessions for the user name
  *
  * Method is called after user data is deleted from the database
  *
  * @param   array   $user    Holds the user data
  * @param   boolean $success True if user was successfully stored in the database
  * @param   string  $msg     Message
  *
  * @return  boolean
  *
  * @since   1.6
  */
 public function onUserAfterDelete($user, $success, $msg)
 {
     $userId = Joomla\Utilities\ArrayHelper::getValue($user, 'id', 0, 'int');
     if (!$success or !$userId) {
         return false;
     }
     // Remove profile images.
     $profile = new Socialcommunity\Profile\Profile($this->db);
     $profile->load(array('user_id' => $userId));
     if ($profile->getId()) {
         // Remove profile record.
         $query = $this->db->getQuery(true);
         $query->delete($this->db->quoteName('#__itpsc_profiles'))->where($this->db->quoteName('user_id') . '=' . (int) $userId);
         $this->db->setQuery($query);
         $this->db->execute();
         // Remove profile images.
         $params = JComponentHelper::getParams('com_socialcommunity');
         /** @var $params Joomla\Registry\Registry */
         jimport('Prism.libs.init');
         $filesystemHelper = new Prism\Filesystem\Helper($params);
         $mediaFolder = $filesystemHelper->getMediaFolder($userId);
         $filesystem = $filesystemHelper->getFilesystem();
         $profile->removeImages($filesystem, $mediaFolder);
     }
     return true;
 }
 /**
  * Delete image
  */
 public function removeImage()
 {
     // Check for request forgeries.
     JSession::checkToken('get') or jexit(JText::_('JINVALID_TOKEN'));
     $itemId = $this->input->getInt('id', 0);
     $profile = new Socialcommunity\Profile\Profile(JFactory::getDbo());
     $profile->load($itemId);
     $redirectOptions = array('view' => 'profile', 'id' => $itemId);
     if (!$profile->getId()) {
         $this->displayNotice(JText::_('COM_SOCIALCOMMUNITY_INVALID_PROFILE'), $redirectOptions);
         return;
     }
     try {
         $params = JComponentHelper::getParams('com_socialcommunity');
         $filesystemHelper = new Prism\Filesystem\Helper($params);
         jimport('Prism.libs.init');
         $storageFilesystem = $filesystemHelper->getFilesystem();
         $mediaFolder = $filesystemHelper->getMediaFolder($profile->getUserId());
         $model = $this->getModel();
         $model->removeImage($itemId, $mediaFolder, $storageFilesystem);
     } catch (Exception $e) {
         JLog::add($e->getMessage());
         throw new Exception(JText::_('COM_SOCIALCOMMUNITY_ERROR_SYSTEM'));
     }
     $this->displayMessage(JText::_('COM_SOCIALCOMMUNITY_IMAGE_DELETED'), $redirectOptions);
 }