public function getProjectFunds() { // Create response object $response = new Prism\Response\Json(); $app = JFactory::getApplication(); /** @var $app JApplicationAdministrator */ $itemId = $app->input->getInt('id'); // Check for errors. if (!$itemId) { $response->setTitle(JText::_('COM_CROWDFUNDINGFINANCE_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_INVALID_PROJECT'))->failure(); echo $response; JFactory::getApplication()->close(); } try { // Get statistics $project = new Crowdfunding\Statistics\Project(JFactory::getDbo(), $itemId); $data = $project->getFundedAmount(); } catch (Exception $e) { JLog::add($e->getMessage()); $response->setTitle(JText::_('COM_CROWDFUNDINGFINANCE_FAIL'))->setText(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM'))->failure(); echo $response; JFactory::getApplication()->close(); throw new Exception(JText::_('COM_CROWDFUNDINGFINANCE_ERROR_SYSTEM')); } $response->setData($data)->success(); echo $response; JFactory::getApplication()->close(); }
/** * Publish or not an item. If state is going to be published, * we have to calculate end date. * * @param integer $itemId * @param integer $userId * @param integer $state * * @throws Exception */ public function saveState($itemId, $userId, $state) { $keys = array('id' => $itemId, 'user_id' => $userId); /** @var $row CrowdfundingTableProject */ $row = $this->getTable(); $row->load($keys); // Prepare data only if the user publish the project. if ((int) $state === Prism\Constants::PUBLISHED) { // Get number of transactions. $statistics = new Crowdfunding\Statistics\Project($this->getDbo(), $row->get('id')); $transactionsNumber = (int) $statistics->getTransactionsNumber(); // If it is not approve and there are no transactions, reset starting date. if ($transactionsNumber === 0 and (int) $row->get('approved') === Prism\Constants::NOT_APPROVED) { $row->set('funding_start', '0000-00-00'); } $this->prepareTable($row); } $row->set('published', (int) $state); $row->store(); // Trigger the event $context = $this->option . '.project'; $pks = array($row->get('id')); // Include the content plugins for the change of state event. JPluginHelper::importPlugin('content'); // Trigger the onContentChangeState event. $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger('onContentChangeState', array($context, $pks, $state)); if (in_array(false, $results, true)) { throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_CHANGE_STATE')); } }
protected function prepareManager() { $model = JModelLegacy::getInstance('Manager', 'CrowdfundingModel', $config = array('ignore_request' => false)); /** @var $model CrowdfundingModelManager */ // Get state $this->state = $model->getState(); /** @var $state Joomla\Registry\Registry */ $this->imageWidth = $this->params->get('image_width', 200); $this->imageHeight = $this->params->get('image_height', 200); $this->titleLength = $this->params->get('discover_title_length', 0); $this->descriptionLength = $this->params->get('discover_description_length', 0); // Get the folder with images $this->imageFolder = $this->params->get('images_directory', 'images/crowdfunding'); // Filter the URL. $uri = JUri::getInstance(); $filter = JFilterInput::getInstance(); $this->returnUrl = $filter->clean($uri->toString()); // Get item $itemId = $this->state->get('manager.id'); // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get('project_currency')); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); $this->item = $model->getItem($itemId, $this->userId); // Check if the item exists. if (!CrowdfundingHelper::isAuthorized($this->userId, $this->item, 'manager')) { $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_SOMETHING_WRONG'), 'notice'); $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute())); return; } $statistics = new Crowdfunding\Statistics\Project(JFactory::getDbo(), $this->item->id); $this->statistics = array('updates' => $statistics->getUpdatesNumber(), 'comments' => $statistics->getCommentsNumber(), 'funders' => $statistics->getTransactionsNumber()); // Get rewards $this->rewards = new Crowdfunding\Rewards(JFactory::getDbo()); $this->rewards->load(array('project_id' => $this->item->id)); $this->pathwayName = JText::_('COM_CROWDFUNDING_STEP_MANAGER'); }
protected function prepareManager() { $model = JModelLegacy::getInstance("Manager", "CrowdfundingModel", $config = array('ignore_request' => false)); /** @var $model CrowdfundingModelManager */ // Get state $this->state = $model->getState(); /** @var $state Joomla\Registry\Registry */ $this->imageWidth = $this->params->get("image_width", 200); $this->imageHeight = $this->params->get("image_height", 200); $this->titleLength = $this->params->get("discover_title_length", 0); $this->descriptionLength = $this->params->get("discover_description_length", 0); // Get the folder with images $this->imageFolder = $this->params->get("images_directory", "images/crowdfunding"); // Filter the URL. $uri = JUri::getInstance(); $filter = JFilterInput::getInstance(); $this->returnUrl = $filter->clean($uri->toString()); // Get item $itemId = $this->state->get('manager.id'); // Get currency $currency = Crowdfunding\Currency::getInstance(JFactory::getDbo(), $this->params->get("project_currency")); $this->amount = new Crowdfunding\Amount($this->params); $this->amount->setCurrency($currency); $this->item = $model->getItem($itemId, $this->userId); // Check if the item exists. if (!$this->isValid()) { return; } $statistics = new Crowdfunding\Statistics\Project(JFactory::getDbo(), $this->item->id); $this->statistics = array("updates" => $statistics->getUpdatesNumber(), "comments" => $statistics->getCommentsNumber(), "funders" => $statistics->getTransactionsNumber()); // Get rewards $this->rewards = new Crowdfunding\Rewards(JFactory::getDbo()); $this->rewards->load(array("project_id" => $this->item->id)); $this->pathwayName = JText::_("COM_CROWDFUNDING_STEP_MANAGER"); }
/** * Publish or not an item. If state is going to be published, * we have to calculate end date. * * @param integer $itemId * @param integer $userId * @param integer $state * * @throws Exception */ public function saveState($itemId, $userId, $state) { $keys = array('id' => $itemId, 'user_id' => $userId); /** @var $row CrowdfundingTableProject */ $row = $this->getTable(); $row->load($keys); // Prepare data only if the user publish the project. if ((int) $state === Prism\Constants::PUBLISHED) { // Get number of transactions. $statistics = new Crowdfunding\Statistics\Project($this->getDbo(), $row->get('id')); $transactionsNumber = (int) $statistics->getTransactionsNumber(); // If it is not approve and there are no transactions, reset starting date. if ($transactionsNumber === 0 and (int) $row->get('approved') === Prism\Constants::NOT_APPROVED) { $row->set('funding_start', Prism\Constants::DATE_DEFAULT_SQL_DATE); } $this->prepareTable($row); // Validate dates $params = JComponentHelper::getParams('com_crowdfunding'); /** @var $params Joomla\Registry\Registry */ $minDays = (int) $params->get('project_days_minimum', 15); $maxDays = (int) $params->get('project_days_maximum'); // If there is an ending date, validate the period. $fundingEndDate = new Prism\Validator\Date($row->get('funding_end')); if ($fundingEndDate->isValid()) { $validatorPeriod = new Crowdfunding\Validator\Project\Period($row->get('funding_start'), $row->get('funding_end'), $minDays, $maxDays); if (!$validatorPeriod->isValid()) { if ($maxDays > 0) { throw new RuntimeException(JText::sprintf('COM_CROWDFUNDING_ERROR_INVALID_ENDING_DATE_MIN_MAX_DAYS', $minDays, $maxDays)); } else { throw new RuntimeException(JText::sprintf('COM_CROWDFUNDING_ERROR_INVALID_ENDING_DATE_MIN_DAYS', $minDays)); } } } } $row->set('published', (int) $state); $row->store(); // Trigger the event $context = $this->option . '.project'; $pks = array($row->get('id')); // Include the content plugins for the change of state event. JPluginHelper::importPlugin('content'); // Trigger the onContentChangeState event. $dispatcher = JEventDispatcher::getInstance(); $results = $dispatcher->trigger('onContentChangeState', array($context, $pks, $state)); if (in_array(false, $results, true)) { throw new Exception(JText::_('COM_CROWDFUNDING_ERROR_CHANGE_STATE')); } }