Exemple #1
0
 /**
  * Making request in model
  * @param  array $types
  * @param  array $ordered
  * @param  int   $limit
  * @return array
  */
 public function getList($types = array(), $ordered = array(), $limit = 20)
 {
     $tmpItems = $this->getItems();
     $currItem = $this->app->jbrequest->getSystem('item');
     $items = array();
     if (!is_array($ordered)) {
         $ordered = (array) $ordered;
     }
     if (is_array($tmpItems)) {
         if (array_key_exists($currItem, $tmpItems)) {
             unset($tmpItems[$currItem]);
         }
         $tmpItems = array_slice($tmpItems, 0, $limit, true);
         foreach ($tmpItems as $key => $tmpItem) {
             $itemsIds[] = $key;
             $appsIds[] = $tmpItem['appId'];
         }
     }
     if (!empty($itemsIds)) {
         $options = array('id' => $itemsIds, 'limit' => $limit, 'published' => 1);
         $items = JBModelItem::model()->getList(array_unique($appsIds), -1, array_unique($types), $options);
         $items = $this->app->jbarray->sortByArray($items, array_keys($tmpItems));
     }
     if (!empty($ordered['order']) && !empty($items)) {
         if ($ordered['order'] == self::ORDER_DESC) {
             $items = array_reverse($items);
         } elseif ($ordered['order'] == self::ORDER_RANDOM) {
             shuffle($items);
         }
     }
     return $items;
 }
Exemple #2
0
 /**
  * @param $value
  * @param null $position
  * @return Item|void
  */
 public function fromCSV($value, $position = null)
 {
     $itemsAlias = $this->_getArray($value, JBCSVItem::SEP_ROWS, 'alias');
     $result = array();
     foreach ($itemsAlias as $alias) {
         if ($item = JBModelItem::model()->getByAlias($alias, $this->_item->application_id)) {
             $result[] = $item->id;
         }
     }
     $result = array_unique($result);
     $this->_element->bindData(array('item' => $result));
 }
Exemple #3
0
 /**
  * @param $value
  * @param null $position
  * @return Item
  */
 public function fromCSV($value, $position = null)
 {
     $relatedCategories = JBModelItem::model()->getRelatedCategories($this->_item->id);
     if ($this->_getBool($value)) {
         $relatedCategories[] = 0;
         $this->app->category->saveCategoryItemRelations($this->_item, $relatedCategories);
     } else {
         $index = array_search(0, $relatedCategories);
         if (false !== $index) {
             unset($relatedCategories[$index]);
             $this->app->category->saveCategoryItemRelations($this->_item, $relatedCategories);
         }
     }
     return $this->_item;
 }
Exemple #4
0
 /**
  * Convert order to new format
  * @param $page
  * @return bool
  */
 public function convertItems($page)
 {
     $this->_migrate = $this->app->jbmigrate;
     $params = $this->_migrate->getParams();
     $this->_fields = $this->_migrate->getOrderFields();
     $this->_statusList = $this->_getStatusList();
     $realStep = $page - $params->find('steps.system_steps');
     $size = $params->find('steps.step');
     if ($realStep <= 0) {
         return -1;
     }
     $orders = JBModelItem::model()->getList($params->get('app'), null, $params->get('type'), array('limit' => array(($realStep - 1) * $size, $size), 'published' => 0, 'state' => -1, 'order' => 'id'));
     if (count($orders) > 0) {
         foreach ($orders as $order) {
             if ($newOrder = $this->_convertOrder($order)) {
                 JBModelOrder::model()->save($newOrder, true);
             }
         }
         return $page + 1;
     }
     return false;
 }
 /**
  * @param $value
  * @param null $position
  * @return Item|void
  */
 public function fromCSV($value, $position = null)
 {
     $value = $this->_getString($value);
     if ($value) {
         $application = $this->_item->getApplication();
         $appCategories = $application->getCategories();
         $appCategoryAlias = array_map(create_function('$cat', 'return $cat->alias;'), $appCategories);
         $appCategoryNames = array_map(create_function('$cat', 'return $cat->name;'), $appCategories);
         $primaryCategoryId = null;
         $alias = null;
         $name = $value;
         if (strpos($value, JBCSVItem::SEP_CELL)) {
             list($name, $alias) = explode(JBCSVItem::SEP_CELL, $value);
         }
         if ($name == '__ROOT__') {
             $primaryCategoryId = 0;
         } else {
             if ($alias && ($id = array_search($alias, $appCategoryAlias))) {
                 $primaryCategoryId = $id;
             } else {
                 if ($name && ($id = array_search($name, $appCategoryNames))) {
                     $primaryCategoryId = $id;
                 }
             }
         }
         if (!is_null($primaryCategoryId)) {
             $relatedCategories = JBModelItem::model()->getRelatedCategories($this->_item->id);
             if (!in_array($primaryCategoryId, $relatedCategories)) {
                 $relatedCategories[] = $primaryCategoryId;
                 $relatedCategories = array_unique($relatedCategories);
                 $this->app->category->saveCategoryItemRelations($this->_item, $relatedCategories);
             }
             $this->_item->getParams()->set('config.primary_category', $primaryCategoryId);
         }
     }
     return $this->_item;
 }
Exemple #6
0
 /**
  * @return int
  */
 public function getStepsInfo()
 {
     $result = array('step' => self::STEP_SIZE, 'system_steps' => 1, 'steps' => 0, 'orders' => 0, 'items' => 0);
     $params = $this->getParams();
     $modelItems = JBModelItem::model();
     if ($params->get('prices_enable')) {
         $result['system_steps']++;
     }
     if ($params->get('orders_enable', 0)) {
         $result['orders'] = $modelItems->getTotal($params->get('app'), $params->get('orders_type'));
         $result['orders_steps'] = ceil($result['orders'] / $result['step']);
     }
     if ($params->get('prices_enable', 0)) {
         $result['items'] = $modelItems->getTotal($params->get('prices_app'), $params->get('prices_types'));
         $result['items_steps'] = ceil($result['items'] / $result['step']);
     }
     $result['total'] = $result['items'] + $result['orders'];
     $result['steps'] += ceil($result['total'] / $result['step']);
     $result['steps'] += $result['system_steps'];
     return $result;
 }
Exemple #7
0
 /**
  * @return int|boolean
  */
 public function getTotal()
 {
     $types = $this->_appParams->get('type_list');
     $appId = $this->_appParams->get('app_list');
     if (empty($types) || empty($appId)) {
         return false;
     }
     return JBModelItem::model()->getTotal($appId, $types);
 }
Exemple #8
0
 /**
  * Get total items.
  *
  * @return int
  */
 protected function _getTotal()
 {
     $config = $this->_jbconfig->getList('export.items');
     list($appId, $catList) = $this->_getCategoryList();
     return \JBModelItem::model()->getTotal($appId, $config->get('item_type'), $catList, $config->get('state', 0));
 }
Exemple #9
0
 /**
  * Get item list
  * @param $appId
  * @param $typeId
  * @param null $catId
  * @param array $options
  * @return mixed
  */
 protected function _getItemList($appId = null, $catId = null, $typeId = null, $options = array())
 {
     if (!isset($options['order'])) {
         $options['order'] = 'id';
     }
     return JBModelItem::model()->getList($appId, $catId, $typeId, $options);
 }
Exemple #10
0
 /**
  * Call after all items loaded
  */
 public function itemsPostProcess()
 {
     $addedIds = $this->app->jbsession->get('ids', 'import-ids');
     $this->_initSessionData();
     if ($this->_data->lose == self::LOSE_DISABLE) {
         JBModelItem::model()->disableAll($this->_data->appid, $this->_data->typeid, $addedIds);
     } else {
         if ($this->_data->lose == self::LOSE_REMOVE) {
             JBModelItem::model()->removeAll($this->_data->appid, $this->_data->typeid, $addedIds);
         }
     }
     $this->app->jbsession->clearGroup('import-ids');
 }
Exemple #11
0
 /**
  * Get items
  * @param $catId
  * @return mixed
  */
 protected function _getItems($catId)
 {
     $items = JBModelItem::model()->getList($this->_params->get('app_id'), $catId, $this->_params->get('type_id', false), array('limit' => $this->_params->get('items_limit'), 'published' => 1, 'order' => $this->_params->get('item_order')));
     return $items;
 }
Exemple #12
0
 /**
  * @param      $value
  * @param null $position
  * @return Item|void
  */
 public function fromCSV($value, $position = null)
 {
     static $memCache = array();
     $categoryTable = $this->app->table->category;
     $application = $this->_item->getApplication();
     if (!isset($memCache[$application->id])) {
         $appCategories = $this->app->table->category->getAll($application->id);
         $appCategoryAlias = array_map(create_function('$cat', 'return $cat->alias;'), $appCategories);
         $appCategoryNames = array_map(create_function('$cat', 'return $cat->name;'), $appCategories);
         $memCache[$application->id] = array('appCategories' => $appCategories, 'appCategoryAlias' => $appCategoryAlias, 'appCategoryNames' => $appCategoryNames);
     } else {
         $appCategories =& $memCache[$application->id]['appCategories'];
         $appCategoryAlias =& $memCache[$application->id]['appCategoryAlias'];
         $appCategoryNames =& $memCache[$application->id]['appCategoryNames'];
     }
     $itemCategories = $this->_getArray($value, 'simple');
     if ($position == 1) {
         $relatedCategories = array();
     } else {
         $relatedCategories = JBModelItem::model()->getRelatedCategories($this->_item->id);
     }
     try {
         // store categories
         foreach ($itemCategories as $categoryName) {
             $names = array_filter(explode(JBCSVItem::SEP_ROWS, $categoryName));
             $previousId = 0;
             $found = true;
             for ($i = 0; $i < count($names); $i++) {
                 list($name, $alias) = array_pad(explode(JBCSVItem::SEP_CELL, $names[$i]), 2, false);
                 // did the alias change?
                 if ($alias && isset($aliasMatches[$alias])) {
                     $alias = $aliasMatches[$alias];
                 }
                 // try to find category through alias, if category is not found, try to match name
                 if (!($id = array_search($alias, $appCategoryAlias)) && !$alias) {
                     $id = array_search($name, $appCategoryNames);
                     foreach (array_keys($appCategoryNames, $name) as $key) {
                         if ($previousId && isset($appCategories[$key]) && $appCategories[$key]->parent == $previousId) {
                             $id = $key;
                         }
                     }
                 }
                 if (!$found || !$id) {
                     $found = false;
                     $category = $this->app->object->create('Category');
                     $category->application_id = $application->id;
                     $category->name = JString::trim($name);
                     $category->parent = $previousId;
                     // set a valid category alias
                     $categoryAlias = $this->app->string->sluggify($alias ? $alias : $name);
                     $category->alias = $this->app->alias->category->getUniqueAlias(0, $categoryAlias);
                     try {
                         $categoryTable->save($category);
                         $appCategories[$category->id] = $category;
                         $appCategoryNames[$category->id] = $category->name;
                         $appCategoryAlias[$category->id] = $aliasMatches[$alias] = $category->alias;
                         $id = $category->id;
                     } catch (CategoryTableException $e) {
                     }
                 }
                 if ($id && $i == count($names) - 1) {
                     $relatedCategories[] = $id;
                 } else {
                     $previousId = $id;
                 }
             }
         }
         // add category to item relations
         if (!empty($relatedCategories)) {
             $relatedCategories = array_unique($relatedCategories);
             $this->app->category->saveCategoryItemRelations($this->_item, $relatedCategories);
             // make first category found primary category
             if (!$this->_item->getPrimaryCategoryId()) {
                 $this->_item->getParams()->set('config.primary_category', $relatedCategories[0]);
             }
         }
     } catch (ItemTableException $e) {
     }
     return $this->_item;
 }
Exemple #13
0
 /**
  * Convert items
  */
 public function convertItems($page)
 {
     $params = $this->_migrate->getParams();
     $realStep = $page - $params->find('steps.system_steps') - $params->find('steps.orders_steps');
     $size = $params->find('steps.step');
     if ($realStep <= 0) {
         return -1;
     }
     $items = JBModelItem::model()->getList($params->get('prices_app'), null, $params->get('prices_types'), array('limit' => array(($realStep - 1) * $size, $size), 'published' => 0, 'state' => -1, 'order' => 'id'));
     if ($items) {
         foreach ($items as $item) {
             if ($this->_convertItem($item)) {
                 $this->app->table->item->save($item);
             }
         }
         return $page + 1;
     }
     return false;
 }