protected function prepareBasic()
 {
     $model = JModelLegacy::getInstance('Project', 'CrowdfundingModel', $config = array('ignore_request' => false));
     /** @var $model CrowdfundingModelProject */
     // Get state
     $this->state = $model->getState();
     /** @var  $this->state Joomla\Registry\Registry */
     // Get params
     $this->params = $this->state->get('params');
     /** @var  $this->params Joomla\Registry\Registry */
     // Get item
     $itemId = $this->state->get('project.id');
     $this->item = $model->getItem($itemId, $this->userId);
     if (!CrowdfundingHelper::isAuthorized($this->userId, $this->item, 'basic')) {
         $this->app->enqueueMessage(JText::_('COM_CROWDFUNDING_ERROR_SOMETHING_WRONG'), 'notice');
         $this->app->redirect(JRoute::_(CrowdfundingHelperRoute::getDiscoverRoute()));
         return;
     }
     // Set a flag that describes the item as new.
     $this->isNew = false;
     if (!(int) $this->item->id) {
         $this->isNew = true;
     }
     $this->form = $model->getForm();
     // Get types
     $this->types = Crowdfunding\Types::getInstance(JFactory::getDbo());
     $this->numberOfTypes = count($this->types);
     // Prepare images
     $this->imageFolder = $this->params->get('images_directory', 'images/crowdfunding');
     if (!$this->item->image) {
         $this->imagePath = 'media/com_crowdfunding/images/no_image.png';
         $this->displayRemoveButton = 'none';
     } else {
         $this->imagePath = $this->imageFolder . '/' . $this->item->image;
         $this->displayRemoveButton = 'inline';
     }
     $mediaParams = JComponentHelper::getParams('com_media');
     $this->imageWidth = $this->params->get('image_width', 200);
     $this->imageHeight = $this->params->get('image_height', 200);
     $this->maxFilesize = Prism\Utilities\FileHelper::getMaximumFileSize($mediaParams->get('upload_maxsize', 10), 'MB');
     $this->pathwayName = JText::_('COM_CROWDFUNDING_STEP_BASIC');
     // Remove the temporary pictures if they exists.
     $this->removeTemporaryImages($model);
 }
Beispiel #2
0
 protected function importLocationsTxt($file, array $options)
 {
     if (JFile::exists($file)) {
         $db = $this->getDbo();
         $items = array();
         $columns = array('id', 'name', 'latitude', 'longitude', 'country_code', 'timezone');
         $i = 0;
         foreach (Prism\Utilities\FileHelper::getLine($file) as $key => $geodata) {
             $item = mb_split("\t", $geodata);
             // Check for missing ascii characters name
             $name = JString::trim($item[2]);
             if (!$name) {
                 // If missing ascii characters name, use utf-8 characters name
                 $name = JString::trim($item[1]);
             }
             // If missing name, skip the record
             if (!$name) {
                 continue;
             }
             // Filter by population.
             if ($options['minimum_population'] > (int) $item[14]) {
                 continue;
             }
             // Filter by country.
             $countryCode = JString::trim($item[8]);
             if ($options['country_code'] and strcmp($countryCode, $options['country_code']) !== 0) {
                 continue;
             }
             $id = !$options['reset_id'] ? (int) $item[0] : 'null';
             $items[] = $id . ',' . $db->quote($name) . ',' . $db->quote(JString::trim($item[4])) . ',' . $db->quote(JString::trim($item[5])) . ',' . $db->quote($countryCode) . ',' . $db->quote(JString::trim($item[17]));
             $i++;
             if ($i === 500) {
                 $i = 0;
                 $query = $db->getQuery(true);
                 $query->insert($db->quoteName('#__crowdf_locations'))->columns($db->quoteName($columns))->values($items);
                 $db->setQuery($query);
                 $db->execute();
                 $items = array();
             }
         }
         if (count($items) > 0) {
             $query = $db->getQuery(true);
             $query->insert($db->quoteName('#__crowdf_locations'))->columns($db->quoteName($columns))->values($items);
             $db->setQuery($query);
             $db->execute();
         }
         unset($content, $items);
     }
 }