示例#1
0
 /**
  * Поиск предметов в БД
  */
 public function actionGetItemInfo()
 {
     if (request()->getParam('item-id')) {
         $model = AllItems::model()->findByPk(request()->getParam('item-id'));
         if (!$model) {
             throw new CHttpException(404);
         }
         $this->ajax['status'] = 'success';
         $this->ajax['msg'] = $model->name . ($model->add_name ? ' (' . $model->add_name . ') [' . $model->item_id . ']' : '');
         echo CJSON::encode($this->ajax);
     } else {
         set_time_limit(0);
         $query = request()->getParam('query');
         $limit = request()->getParam('limit', 0);
         if (strlen($query)) {
             $criteria = new CDbCriteria();
             $criteria->select = 'item_id, name, add_name, icon';
             if ($limit > 0) {
                 $criteria->limit = $limit;
             }
             $criteria->order = 'name';
             $criteria->compare('name', $query, TRUE);
             $model = AllItems::model()->findAll($criteria);
             $items = array();
             foreach ($model as $item) {
                 $items[] = array('id' => $item->item_id, 'value' => $item->name . ($item->add_name ? ' (' . $item->add_name . ') [' . $item->item_id . ']' : ''), 'icon' => $item->getIcon());
             }
             echo CJSON::encode($items);
         }
     }
     app()->end();
 }
示例#2
0
 /**
  * Контроль предметов
  *
  * @param array $itemsIds
  *
  * @return array
  */
 public function getItemsControl(array $itemsIds)
 {
     if (!$itemsIds) {
         return array();
     }
     $res = AllItems::model()->findAllByAttributes(array('item_id' => $itemsIds));
     $itemNames = array();
     foreach ($res as $row) {
         $itemNames[$row->getPrimaryKey()] = $row;
     }
     unset($res);
     /*
        SELECT
        Max(items.count) AS maxCountItems,Count(items.count) AS countItems,items.owner_id,items.object_id,items.item_id,items.count,items.enchant_level,items.loc,items.loc_data,characters.charId AS char_id,characters.account_name,characters.char_name,
        characters.`level`,characters.curHp,characters.maxCp,characters.curCp,characters.maxMp,characters.curMp,characters.maxHp,characters.x,characters.y,characters.z,characters.exp,characters.sp,characters.pvpkills,characters.pkkills,characters.clanid AS clan_id,
        characters.base_class,characters.title,characters.`online`,characters.onlinetime,clan_data.clan_name,clan_data.clan_level,clan_data.hasCastle,clan_data.hasFort,clan_data.crest_id AS clan_crest,clan_data.reputation_score
        FROM
        items
        LEFT JOIN characters ON items.owner_id = characters.charId
        LEFT JOIN clan_data ON characters.clanid = clan_data.clan_id
        WHERE
        items.item_id IN (57, 4037, 5588, 10)
        GROUP BY
        items.owner_id,
        items.item_id
        ORDER BY
        items.item_id ASC
     */
     $res = $this->_db->createCommand()->select("Max(items.count) AS maxCountItems,Count(items.count) AS countItems,items.owner_id,items.object_id,items.item_id,items.count,items.enchant_level,items.loc,items.loc_data,characters.charId AS char_id,characters.account_name,characters.char_name,\r\n                characters.level,characters.curHp,characters.maxCp,characters.curCp,characters.maxMp,characters.curMp,characters.maxHp,characters.x,characters.y,characters.z,characters.exp,characters.sp,characters.pvpkills,characters.pkkills,characters.clanid AS clan_id,\r\n                characters.base_class,characters.title,characters.online,characters.onlinetime,clan_data.clan_name,clan_data.clan_level,clan_data.hasCastle,clan_data.hasFort,clan_data.crest_id AS clan_crest,clan_data.reputation_score")->leftJoin('characters', 'items.owner_id = characters.charId')->leftJoin('clan_data', 'characters.clanid = clan_data.clan_id')->where(array('in', 'item_id', $itemsIds))->group('items.owner_id, items.item_id')->order('maxCountItems DESC')->from('items')->queryAll();
     $characters = array();
     foreach ($res as $item) {
         if (!isset($characters[$item['item_id']]['maxTotalItems'])) {
             $characters[$item['item_id']]['maxTotalItems'] = 0;
         }
         $characters[$item['item_id']]['itemInfo'] = $itemNames[$item['item_id']];
         $characters[$item['item_id']]['characters'][] = $item;
         $characters[$item['item_id']]['maxTotalItems'] += $item['maxCountItems'];
         $characters[$item['item_id']]['totalItems'] = count($characters[$item['item_id']]['characters']);
     }
     foreach (array_diff_key($itemNames, $characters) as $item) {
         $characters[$item->item_id]['itemInfo'] = $item;
         $characters[$item->item_id]['characters'] = array();
         $characters[$item->item_id]['maxTotalItems'] = 0;
         $characters[$item->item_id]['totalItems'] = 0;
     }
     return $characters;
 }
示例#3
0
 /**
  * Контроль предметов
  *
  * @param array $itemList (ID предметов по которым будет выборка)
  *
  * @return array
  */
 public function getItemsControl(array $itemList)
 {
     if (!$itemList) {
         return array();
     }
     $res = AllItems::model()->findAllByAttributes(array('item_id' => $itemList));
     $itemNames = array();
     foreach ($res as $row) {
         $itemNames[$row->getPrimaryKey()] = $row;
     }
     unset($res);
     /*
     SELECT 
     MAX(items.count) AS maxCountItems, COUNT(items.count) AS countItems, items.owner_id, items.object_id, items.item_id, items.count, items.enchant_level, items.loc, items.loc_data, characters.account_name, characters.obj_Id AS char_id, characters.char_name, characters.sex, characters.x, characters.y, characters.z, characters.karma, characters.pvpkills, characters.pkkills, characters.clanid AS clan_id, characters.title, characters.accesslevel AS access_level, characters.online, characters.onlinetime, character_subclasses.class_id AS base_class, character_subclasses.level, character_subclasses.exp, character_subclasses.sp, character_subclasses.maxHp, character_subclasses.curHp, character_subclasses.maxCp, character_subclasses.curCp, character_subclasses.maxMp, character_subclasses.curMp, clan_subpledges.name AS clan_name, clan_data.clan_level, clan_data.hasCastle, clan_data.crest AS clan_crest, clan_data.reputation_score 
     FROM items 
     LEFT JOIN characters ON items.owner_id = characters.obj_Id
     LEFT JOIN character_subclasses ON character_subclasses.char_obj_id = characters.obj_Id AND character_subclasses.isBase = 1
     LEFT JOIN clan_data ON clan_data.clan_id = characters.clanid
     LEFT JOIN clan_subpledges ON clan_subpledges.clan_id = clan_data.clan_id AND clan_subpledges.type = 0 
     GROUP BY items.owner_id, items.item_id
     */
     $res = $this->_db->createCommand()->select('MAX(items.count) AS maxCountItems, COUNT(items.count) AS countItems, items.owner_id, items.object_id, items.item_id, items.count, items.enchant_level, items.loc, items.loc_data, characters.account_name, characters.obj_Id AS char_id, characters.char_name, characters.sex, characters.x, characters.y, characters.z, characters.karma, characters.pvpkills, characters.pkkills, characters.clanid AS clan_id, characters.title, characters.accesslevel AS access_level, characters.online, characters.onlinetime, character_subclasses.class_id AS base_class, character_subclasses.level, character_subclasses.exp, character_subclasses.sp, character_subclasses.maxHp, character_subclasses.curHp, character_subclasses.maxCp, character_subclasses.curCp, character_subclasses.maxMp, character_subclasses.curMp, clan_subpledges.name AS clan_name, clan_data.clan_level, clan_data.hasCastle, clan_data.crest AS clan_crest, clan_data.reputation_score')->leftJoin('characters', 'items.owner_id = characters.obj_Id')->leftJoin('character_subclasses', 'character_subclasses.char_obj_id = characters.obj_Id AND character_subclasses.isBase = 1')->leftJoin('clan_data', 'clan_data.clan_id = characters.clanid')->leftJoin('clan_subpledges', 'clan_subpledges.clan_id = clan_data.clan_id AND clan_subpledges.type = 0')->andWhere(array('in', 'item_id', $itemList))->group('items.owner_id, items.item_id')->from('items')->queryAll();
     $characters = array();
     foreach ($res as $item) {
         if (!isset($characters[$item['item_id']]['maxTotalItems'])) {
             $characters[$item['item_id']]['maxTotalItems'] = 0;
         }
         $characters[$item['item_id']]['itemInfo'] = $itemNames[$item['item_id']];
         $characters[$item['item_id']]['characters'][] = $item;
         $characters[$item['item_id']]['maxTotalItems'] += $item['maxCountItems'];
         $characters[$item['item_id']]['totalItems'] = count($characters[$item['item_id']]['characters']);
     }
     foreach (array_diff_key($itemNames, $characters) as $item) {
         $characters[$item->item_id]['itemInfo'] = $item;
         $characters[$item->item_id]['characters'] = array();
         $characters[$item->item_id]['maxTotalItems'] = 0;
         $characters[$item->item_id]['totalItems'] = 0;
     }
     return $characters;
 }