Esempio n. 1
0
 /**
  * Singleton method
  *
  * @param null
  * @return MageBridgeConnectorStore
  */
 public static function getInstance()
 {
     static $instance;
     if (null === self::$_instance) {
         self::$_instance = new self();
     }
     return self::$_instance;
 }
 public function display($tpl = null)
 {
     // Initialize the view
     $this->setTitle('Connectors');
     // Set buttons in the toolbar
     MageBridgeToolBarHelper::help('magebridge.connectors');
     JToolBarHelper::publishList();
     JToolBarHelper::unpublishList();
     JToolBarHelper::editListX();
     // Initialize common variables
     $application = JFactory::getApplication();
     $option = JRequest::getCmd('option') . '-connectors';
     // Handle the filters
     $filter_type = $application->getUserStateFromRequest($option . 'filter_type', 'filter_type', '', 'word');
     $filter_state = $application->getUserStateFromRequest($option . 'filter_state', 'filter_state', '', 'word');
     $filter_order = $application->getUserStateFromRequest($option . 'filter_order', 'filter_order', 'p.ordering', 'cmd');
     $filter_order_Dir = $application->getUserStateFromRequest($option . 'filter_order_Dir', 'filter_order_Dir', '', 'word');
     // Get data from the model
     $items = $this->get('Data');
     $total = $this->get('Total');
     $pagination = $this->get('Pagination');
     // filters
     $options = array(array('value' => '', 'text' => '- Select Type -'), array('value' => 'store', 'text' => 'Store Connectors'), array('value' => 'product', 'text' => 'Product Connectors'), array('value' => 'profile', 'text' => 'Profile Connectors'));
     $javascript = 'onchange="document.adminForm.submit();"';
     $lists['type'] = JHTML::_('select.genericlist', $options, 'filter_type', $javascript, 'value', 'text', $filter_type);
     $lists['state'] = JHTML::_('grid.state', $filter_state);
     // table ordering
     $lists['order_Dir'] = $filter_order_Dir;
     $lists['order'] = $filter_order;
     // Prepare the items for display
     if (!empty($items)) {
         foreach ($items as $index => $item) {
             if ($item->type == 'product') {
                 $object = MageBridgeConnectorProduct::getInstance()->getConnectorObject($item);
             } else {
                 if ($item->type == 'profile') {
                     $object = MageBridgeConnectorProfile::getInstance()->getConnectorObject($item);
                 } else {
                     $object = MageBridgeConnectorStore::getInstance()->getConnectorObject($item);
                 }
             }
             if (is_object($object)) {
                 $item->enabled = $object->isEnabled();
             } else {
                 $item->enabled = false;
             }
             $item->edit_link = 'index.php?option=com_magebridge&view=connector&task=edit&cid[]=' . $item->id;
             $items[$index] = $item;
         }
     }
     $user = JFactory::getUser();
     $this->assignRef('user', $user);
     $this->assignRef('lists', $lists);
     $this->assignRef('items', $items);
     $this->assignRef('pagination', $pagination);
     parent::display($tpl);
 }
Esempio n. 3
0
 private function setApp()
 {
     // If the values are already initialized, return them
     if (!empty($this->app_type) && !empty($this->app_value)) {
         return;
     }
     // Initialize system variables
     $application = JFactory::getApplication();
     // Check if the current Menu-Item has something to say about this
     $store = MageBridgeHelper::getParams()->get('store');
     if (!empty($store) && ($store = explode(':', $store))) {
         if ($store[0] == 'v') {
             $this->app_type = 'store';
             $this->app_value = $store[1];
             $application->setUserState('magebridge.store.type', $this->app_type);
             $application->setUserState('magebridge.store.name', $this->app_value);
             return;
         }
         if ($store[0] == 'g') {
             $this->app_type = 'group';
             $this->app_value = $store[1];
             $application->setUserState('magebridge.store.type', $this->app_type);
             $application->setUserState('magebridge.store.name', $this->app_value);
             return;
         }
     }
     // Check whether the GET-connector is enabled
     $get_connector = MageBridgeConnectorStore::getInstance()->getConnector('get');
     if (!empty($get_connector)) {
         // Check for GET-variables __store
         $store = $application->getUserState('___store');
         if (!empty($store)) {
             $this->app_type = 'store';
             $this->app_value = $store;
             return;
         }
         // Check if the current store is saved with the user session
         $saved_type = $application->getUserState('magebridge.store.type');
         $saved_name = $application->getUserState('magebridge.store.name');
         if (!empty($saved_type) && !empty($saved_name)) {
             $this->app_type = $saved_type;
             $this->app_value = $saved_name;
             return;
         }
     }
     // Determine the current store using MageBridge Store Connectors
     if ($application->isSite()) {
         $store = MageBridgeConnectorStore::getInstance()->getStore();
         if (!empty($store)) {
             $this->app_type = $store['type'];
             $this->app_value = $store['name'];
             return;
         }
     }
     // Load the settings from the database
     $storeview = MagebridgeModelConfig::load('storeview');
     $storegroup = MagebridgeModelConfig::load('storegroup');
     $website = MagebridgeModelConfig::load('website');
     // Never use a Store View or Store Group in the backend
     if ($application->isAdmin()) {
         if (JRequest::getCmd('view') == 'root') {
             $this->app_type = 'website';
             $this->app_value = 'admin';
         } else {
             $this->app_type = 'website';
             $this->app_value = $website;
         }
         return;
     }
     // When in the frontend, determine which store-type to use
     if (!empty($storeview)) {
         $this->app_type = 'store';
         $this->app_value = $storeview;
     } else {
         if (!empty($storegroup)) {
             $this->app_type = 'group';
             $this->app_value = $storegroup;
         } else {
             $this->app_type = 'website';
             $this->app_value = $website;
         }
     }
     return;
 }
 public function showForm($tpl = null)
 {
     // Initialize the view
     $this->setTitle('Edit store condition');
     // Initialize common variables
     $application = JFactory::getApplication();
     $user = JFactory::getUser();
     $option = JRequest::getCmd('option');
     // Get data from the model
     $model = $this->getModel();
     $item = $this->get('Data');
     // Get the item
     $item = $this->get('data');
     $isNew = $item->id < 1;
     // Fail if checked out not by 'me'
     if ($model->isCheckedOut($user->get('id'))) {
         $msg = JText::sprintf('Item locked', $item->name);
         $application->redirect('index.php?option=' . $option, $msg);
     }
     // Edit or Create?
     if (!$isNew) {
         $model->checkout($user->get('id'));
     } else {
         // initialise new record
         $item->published = 1;
         $item->order = 0;
     }
     // Build the HTML-select list for ordering
     $query = 'SELECT ordering AS value, name AS text' . ' FROM #__magebridge_stores' . ' ORDER BY ordering';
     // Build the fields
     $fields = array();
     $fields['store'] = $this->getFieldStore($item->type, $item->name);
     $fields['ordering'] = JHTML::_('list.specificordering', $item, $item->id, $query);
     $fields['published'] = JHTML::_('select.booleanlist', 'published', 'class="inputbox"', $item->published);
     // Clean the object before displaying
     JFilterOutput::objectHTMLSafe($item, ENT_QUOTES, 'text');
     $this->assignRef('user', JFactory::getUser());
     $this->assignRef('connectors', MageBridgeConnectorStore::getInstance()->getConnectors());
     $this->assignRef('fields', $fields);
     $this->assignRef('item', $item);
     parent::display($tpl);
 }
Esempio n. 5
0
 /**
  * Handle the event when searching for items
  *
  * @param string $text
  * @param string $phrase
  * @param string $ordering
  * @param array  $areas
  *
  * @return array
  */
 public function onContentSearch($text, $phrase, $ordering = '', $areas = null)
 {
     // Do not continue if not enabled
     if ($this->isEnabled() == false) {
         return array();
     }
     // Check if the areas match
     if (!empty($areas) && is_array($areas)) {
         if (!array_intersect($areas, array_keys($this->onContentSearchAreas()))) {
             return array();
         }
     }
     // Do not continue with an empty search string
     if (empty($text)) {
         return array();
     }
     // Load the plugin parameters
     $search_limit = (int) $this->params->get('search_limit', 50);
     $search_fields = trim($this->params->get('search_fields'));
     // Determine the search fields
     if (!empty($search_fields)) {
         $search_field_values = explode(',', $search_fields);
         $search_fields = array();
         //$search_fields = array('title', 'description');
         foreach ($search_field_values as $search_field_value) {
             $search_fields[] = trim($search_field_value);
         }
         array_unique($search_fields);
     } else {
         $search_fields = array('title', 'description');
     }
     // Build the search array
     $search_options = array('store' => MageBridgeConnectorStore::getInstance()->getStore(), 'website' => MagebridgeModelConfig::load('website'), 'text' => $text, 'search_limit' => $search_limit, 'search_fields' => $search_fields);
     // Include the MageBridge register
     MageBridgeModelDebug::getInstance()->trace('Search plugin');
     $register = MageBridgeModelRegister::getInstance();
     $segment_id = $register->add('api', 'magebridge_product.search', $search_options);
     // Include the MageBridge bridge
     $bridge = MageBridgeModelBridge::getInstance();
     $bridge->build(true);
     // Get the results
     $results = $register->getDataById($segment_id);
     // Do not continue if the result is empty
     if (empty($results)) {
         return array();
     }
     // Only show the maximum amount
     $results = array_slice($results, 0, $search_limit);
     $objects = array();
     foreach ($results as $index => $result) {
         $object = (object) null;
         $object->title = $result['name'];
         $object->text = $result['description'];
         $url = preg_replace('/^(.*)index.php/', 'index.php', $result['url']);
         $object->href = $url;
         $object->created = $result['created_at'];
         $object->metadesc = $result['meta_description'];
         $object->metakey = $result['meta_keyword'];
         $object->section = null;
         $object->browsernav = 2;
         $object->thumbnail = $result['thumbnail'];
         $object->small_image = $result['small_image'];
         $object->image = $result['image'];
         $objects[] = $object;
     }
     return $objects;
 }
Esempio n. 6
0
 /**
  * Method to store the item
  *
  * @package MageBridge
  * @access public
  * @param array $data
  * @return bool
  */
 public function store($data)
 {
     $row = $this->getTable();
     if (!empty($data['store'])) {
         $values = explode(':', $data['store']);
         $data['type'] = $values[0] == 'g' ? 'storegroup' : 'storeview';
         $data['name'] = $values[1];
         $data['title'] = $values[2];
         unset($data['store']);
     } else {
         $this->setError(JText::_('No store was selected'));
         return false;
     }
     if (!empty($data['default']) && $data['default']) {
         $this->storeDefault($data['type'], $data['name']);
         return true;
     }
     if (empty($data['name']) || empty($data['title'])) {
         $this->setError(JText::_('Invalid store'));
         return false;
     }
     if (empty($data['connector'])) {
         $this->setError(JText::_('No connector was selected'));
         return false;
     }
     $connector = MageBridgeConnectorStore::getConnector($data['connector']);
     if ($connector == false) {
         $this->setError(JText::_('Failed to load connector'));
         return false;
     }
     $data['connector_value'] = $connector->getFormPost($data);
     if (empty($data['label'])) {
         $data['label'] = $data['title'];
     }
     // Bind the form fields to the item table
     if (!$row->bind($data)) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Make sure the item table is valid
     if (!$row->check()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Store the item table to the database
     if (!$row->store()) {
         $this->setError($this->_db->getErrorMsg());
         return false;
     }
     // Save the ID for later usage
     $this->_id = $row->id;
     return true;
 }