Exemplo n.º 1
0
 /**
  *	Get node path (apply it to request)
  *
  *	@return		list<RM_Tree_iNode>
  */
 public function getPath(RM_Store_iRequest $request, RM_Tree_iNode $node)
 {
     $path = array();
     foreach ($this->_dbh->query("SELECT ancestor_id FROM {$this->_table} WHERE descendent_id = ? AND ancestor_id<>0 AND level>0 ORDER BY level DESC", $node->id()) as $a) {
         $path[$a['ancestor_id']] = 0;
     }
     if (count($path)) {
         foreach ($request->filter('id IN(' . sqlBinds($path) . ')', array_keys($path)) as $i) {
             $path[$i->id()] = $i;
         }
     }
     $path[] = $node;
     return array_values($path);
 }
Exemplo n.º 2
0
 public function save()
 {
     if (!@$this->inDb) {
         M('Db')->exec('INSERT INTO rm_equipment (' . join(',', array_keys($this->_props)) . ') VALUES (' . sqlBinds($this->_props) . ')', array_values($this->_props));
         $this->inDb = 1;
     } else {
         $sql = 'UPDATE rm_equipment SET ';
         foreach ($this->_props as $prop => $val) {
             $a[] = "{$prop} = ?";
         }
         $sql .= join(',', $a) . ' WHERE id = ?';
         M('Db')->exec($sql, array_values($this->_props), $this->_props['id']);
     }
     return TRUE;
 }
Exemplo n.º 3
0
 public function _searchOtherWay(RM_Barcode_Entity $obEntity, $restriction)
 {
     $orPart = array('query' => array(), 'binds' => array());
     $query = M('Db')->createQuery($this->table('barcode'))->what('count(*) as qty');
     foreach ($restriction as $key => $value) {
         if ($obEntity->type() . '_id' == $key) {
             $invert = 0;
         } else {
             $invert = 1;
         }
         if (is_array($value)) {
             $condition = ($invert ? ' not' : '') . ' in (' . sqlBinds($value) . ')';
         } else {
             $condition = ($invert ? ' !' : '') . '=? ';
         }
         if (!$invert) {
             $query->where($this->fields('barcode', $key) . $condition, $value);
         } else {
             $orPart['query'][] = $this->fields('barcode', $key) . $condition;
             $orPart['binds'][] = $value;
         }
     }
     if ($orPart['query']) {
         $orRestriction = join(' or ', $orPart['query']);
         call_user_func_array(array($query, 'where'), array_merge(array('(' . $orRestriction . ')'), $orPart['binds']));
     }
     foreach ($query->execute() as $row) {
         return $row['qty'];
     }
     return 0;
 }
Exemplo n.º 4
0
 protected function _isAlreadyAwarded(RM_Points_Account $obAccount, $bdate)
 {
     $checkEvents = array('scanning', 'no-purchase');
     return count($obAccount->getPaymentList()->filter('event in (' . sqlBinds($checkEvents) . ')', $checkEvents)->filter('amount_date=?', $bdate)) > 0;
 }
Exemplo n.º 5
0
 protected function _processHanged($res)
 {
     $res = $res->fetchAll();
     if (count($res)) {
         $this->_error = 1;
     }
     $this->_repBegin("Broken events (daemon is broken?)", array('id' => qw2('ID 10 right'), 'c' => qw2('Created 20'), 'st' => qw2('Process-start 20'), 'event' => qw2('Event')));
     $idList = array();
     foreach ($res as $row) {
         $idList[] = $row['id'];
         $this->_repAdd(array('c' => $row['created'], 'id' => $row['id'], 'event' => $row['event_name']));
     }
     # try to re-run hanged/broken events
     if ($idList) {
         M('Event')->_trace("controlProcessQueue(): restarting broken events: " . join(',', $idList));
         $this->_dbh->exec("UPDATE {$this->eventQueue} SET process_start = NULL WHERE id IN(" . sqlBinds($idList) . ")", $idList);
     }
     $this->_repFinish(qw2('count'));
 }
Exemplo n.º 6
0
 /**
  * Список категорий, выбранных для ценовых распределений
  *
  * @return			RM_Store_iRequest
  **/
 public function getSelectedCategories()
 {
     $ids = $this->getSelectedIds();
     // этот мега-костыль я посвящаю Вадиму Мельникову! Вадим, никогда так не делай :)
     if (!$ids) {
         $ids[] = -1000000;
     }
     return M('Barcode')->getGeneraltypeList()->filter('id IN(' . sqlBinds($ids) . ')', $ids)->sort('name', 'ASC');
 }
Exemplo n.º 7
0
<?php

require '../../init.php';
// все, где в описчаниии есть "вино", + категория вино.
// отправляем в брик № 10000273
// старый атрибут 20000705
$obAttribute = iterFirst(M('Gpc')->getAttributeList()->filter('rus_name = ?', 'Импорт/СНГ/РФ'));
$gTypes = array();
foreach (M('Db')->query("select id from panelie_brand_generaltype where name in \n('вермут', 'водка', 'джин', 'коньяк', 'ликер', 'настойка горькая', 'ром', 'шампанское', 'Текила', 'Виски', 'Абсент')") as $tmp) {
    $gTypes[] = $tmp['id'];
}
foreach (M('Barcode')->getBarcodeList()->filter('generaltype_id in (' . sqlBinds($gTypes) . ')', $gTypes) as $obBarcode) {
    $caption = NULL;
    if (in_array(mb_strtolower($obBarcode->getGeneraltype()->name, 'utf8'), qw2('текила виски абсент'))) {
        $obValue = iterFirst(M('Gpc')->getValueList()->filter('rus_name = ?', 'Импорт'));
        $caption = $obBarcode->getGeneraltype()->name;
    } else {
        $obValue = getValueByOwner($obBarcode->owner_id);
    }
    if (!isNull($obValue)) {
        if (!$caption) {
            $caption = $obBarcode->getOwner()->name;
        }
        for ($i = 1; $i <= $obBarcode->_attribute_quantity; $i++) {
            if ($obBarcode->{'a' . $i} == $obAttribute->id()) {
                $obBarcode->{'v' . $i} = $obValue->id();
                break;
            } elseif (!$obBarcode->{'a' . $i}) {
                $obBarcode->{'a' . $i} = $obAttribute->id();
                $obBarcode->{'v' . $i} = $obValue->id();
                break;
Exemplo n.º 8
0
 public function hasIncompleteAnketa(RM_User_Object $obUser)
 {
     $incomplete = M('Cache')->get($this->_alertCacheNs(), 'anketa-' . $obUser->id());
     if (is_null($incomplete)) {
         //echo "anketa alert put in cache!<br>";
         /*			$result = iteratorToArray( M('Db')->query("SELECT complete_anketa FROM rm_report_panelist WHERE user_id = ?", $obUser->id()) );
         			$ca = (int)@$result[0]['complete_anketa'];
         			$incomplete = ($ca < 99) ? TRUE : FALSE;*/
         $person_ids = array();
         foreach ($this->getFamilyRespondents($obUser) as $obPerson) {
             $person_ids[] = $obPerson->id();
         }
         $anketas = $this->groupAnketaByType();
         $anketa_count = count($anketas['person']) * count($person_ids) + count($anketas['user']);
         $or = $person_ids ? "OR (respondent_id IN(" . sqlBinds($person_ids) . ") AND respondent_type = 'person')" : '';
         $binds = $person_ids ? array_merge(array($obUser->id()), $person_ids) : array($obUser->id());
         $result = iterFirst(M('Db')->query("SELECT COUNT(*) AS c FROM " . M('Anketa')->table('result') . " WHERE (respondent_id = ? AND respondent_type = 'user') {$or} AND end_time IS NOT NULL", $binds));
         $incomplete = (int) ($result['c'] < $anketa_count);
         M('Cache')->put($this->_alertCacheNs(), 'anketa-' . $obUser->id(), $incomplete);
     }
     //else
     //echo "anketa alert GET FROM cache!<br>";
     return $incomplete;
 }
Exemplo n.º 9
0
 /**
  * Removes invisible entries from report data
  *
  * @return	void
  **/
 protected function _applyInvisible(RM_Report_Object $obReport)
 {
     if ($obReport->invisible()) {
         M('Db')->setCurrentConnection('storage');
         $ids = array_keys($obReport->invisible());
         $query = M('Db')->createQuery($obReport->getTableName(), 'delete');
         $query->where($obReport->detail()->getFieldNameWithId() . ' IN (' . sqlBinds($ids) . ')', $ids);
         $query->execute();
         M('Db')->setCurrentConnection('default');
     }
 }
Exemplo n.º 10
0
 /**
  * Register in history table
  *
  * @param RM_Store_iHistoric $object
  */
 public function register(RM_Store_iHistoric $object, $code)
 {
     if ($object->isChildren() && !isNull($obParent = $object->getParent())) {
         M('Store')->history()->register($obParent, $this->getParentRegisterCode($code));
     }
     $data = array('stamp' => $this->getStamp(), 'guid_id' => $object->id(), 'guid_type' => $object->guidType(), 'stamptime' => M('Date')->dbDateTime(), 'code' => $code, 'user_id' => me()->id());
     $query = "INSERT INTO {$this->_table}(" . join(', ', array_keys($data)) . ") VALUES(" . sqlBinds($data) . ") ON DUPLICATE KEY UPDATE code = IF(code < " . $code . ", code, " . $code . ")";
     M('Db')->exec($query, array_values($data));
     return TRUE;
 }
Exemplo n.º 11
0
 protected function _saveObjectHelper($insert, RM_Store_Object $object, RM_Validator_iValidator $validator = NULL)
 {
     if (isNull($validator)) {
         $validator = $object->validator();
     }
     if (!isNull($validator) && !$validator->check($object->props())) {
         return FALSE;
     }
     $meta = $this->_mediator->meta;
     $fields = array();
     $allFields = array();
     $props = $object->props();
     foreach ($meta->propList() as $prop) {
         $allFields[$meta->dbField($prop)] = $props[$prop];
         if ($insert or $props[$prop] !== $object->_propInitial($prop)) {
             $field = $meta->dbQuoted($prop);
             $fields[$insert ? $field : "{$field} = ?"] = $props[$prop];
         }
     }
     if (!$fields) {
         return FALSE;
     }
     if ($insert) {
         $binds = $fields;
         $query = "INSERT INTO {$this->_table}(" . join(',', array_keys($fields)) . ") VALUES(" . sqlBinds($fields) . ")";
     } else {
         list($where, $wbinds) = $this->_getDbWhere($object);
         $binds = array_merge($fields, $wbinds);
         $query = "UPDATE {$this->_table} SET " . join(',', array_keys($fields)) . " WHERE {$where}";
     }
     $this->_dbh->exec($query, array_values($binds));
     if (!isNull($this->_tableHistory)) {
         $obHistory = M('Store')->history();
         if ($obHistory->_closeStamp() || $object->isChildren()) {
             list($where, $wbinds) = $this->_getDbWhere($object);
             $query = "UPDATE {$this->_tableHistory} SET stamp_close = " . $obHistory->getStamp() . ", last_state = 0 WHERE " . $where . " AND last_state = 1";
             $this->_dbh->exec($query, $wbinds);
         }
         $binds = array_merge(array('stamp_open' => $obHistory->getStamp(), 'stamp_close' => $obHistory->getFarFuture(), 'last_state' => 1), $allFields);
         $query = "REPLACE INTO {$this->_tableHistory}( " . join(',', array_keys($binds)) . ") VALUES(" . sqlBinds($binds) . ")";
         $this->_dbh->exec($query, array_values($binds));
         $obHistory->register($object, $insert ? RM_Store_History::OBJECT_CREATE : RM_Store_History::OBJECT_EDIT);
     }
     if ($this->_autoId and !$object->{$this->_autoId}) {
         $object->{$this->_autoId} = $this->_dbh->lastInsertID();
         $allFields[$meta->dbField($this->_autoId)] = $object->{$this->_autoId};
     }
     if ($this->_cacheNs) {
         $this->cacheUpdate($object, $allFields);
     }
     return TRUE;
 }
Exemplo n.º 12
0
    public function searchCheat()
    {
        $data = array();
        M('Db')->exec('truncate ' . $this->_tables['propability']);
        M('Db')->exec('truncate ' . $this->_tables['details']);
        $sth = M('Db')->query('select csid, count(distinct user_id) as quser_id,
			count(distinct ip) as qip, count(distinct adate) as qadate,
			sum(actions) as total_actions
			from ' . $this->_tables['log'] . ' group by csid 
			having quser_id>1 and total_actions>0
			order by quser_id desc');
        foreach ($sth as $row) {
            foreach ($this->_getAdmins($row['csid']) as $adminId) {
                $cheaters[$adminId] = 1;
            }
        }
        foreach ($cheaters as $adminId => $v) {
            $row = $this->_getCheatData($adminId);
            if ($row) {
                $data[] = $row;
                $csidList = array();
                foreach (M('Db')->query('select distinct csid from ' . $this->_tables['log'] . ' where user_id=?', $adminId) as $csid) {
                    $csidList[] = $csid['csid'];
                }
                M('Db')->exec('insert into ' . $this->_tables['details'] . '
						(admin_id, user_id, adate, actions)
						select ?, l.user_id, l.adate, sum(l.actions) as total_actions
						from ' . $this->_tables['log'] . ' l
						where l.csid in (' . sqlBinds($csidList) . ') and l.user_id!=? 
						group by l.user_id, l.adate
						having total_actions>0', $adminId, $csidList, $adminId);
            }
        }
        $q = M('Db')->createQuery($this->_tables['propability'], 'insert');
        foreach ($data as $row) {
            $q->set()->reset();
            foreach ($row as $k => $v) {
                $q->set($k, $v);
            }
            $q->execute();
        }
    }
Exemplo n.º 13
0
 public function getAvailableGroupsForAdmin()
 {
     $list = array();
     if (me()->id()) {
         $list = M('User')->getGroups()->filter('weight > 0');
         if (!me()->isUserInGroup(array('super-admin'), FALSE)) {
             $can_edit_groups = array();
             if (me()->isUserInGroup(array('support-control'), FALSE)) {
                 $can_edit_groups = array_merge($can_edit_groups, array('user', 'admin', 'region-admin', 'operator', 'mounter', 'invoicer'));
             }
             if (me()->isUserInGroup(array('admin-coder'), FALSE)) {
                 //$list->filter('(alias = ? OR alias LIKE ?)', 'ean-data', '%coder');
                 $can_edit_groups = array_merge($can_edit_groups, array('user', 'coder', 'super-coder', 'brand-coder', 'moderator-coder', 'catalog-coder', 'iowa-coder', 'ean-data', 'under-control-coder'));
             }
             if (me()->isUserInGroup(array('admin', 'region-admin'), FALSE)) {
                 $can_edit_groups = array_merge($can_edit_groups, array('user'));
             }
             if ($can_edit_groups) {
                 $list->filter('alias IN(' . sqlBinds($can_edit_groups) . ')', $can_edit_groups);
             }
         }
     }
     return $list;
 }
Exemplo n.º 14
0
    public function getQueriesForMovement($source, RM_Barcode_Object $obDestination, $restriction = array())
    {
        $purchaseQuery = M('Db')->createQuery($this->_mapper->table('purchase'), 'update')->set('barcode_value = ?', $obDestination->value)->where('barcode_value = ?', $source);
        $priceQuery = M('Db')->createQuery('rm_price_distribution', 'update')->set('barcode_value=?', $obDestination->value)->where('barcode_value=?', $source);
        $copyFields = qw2('
			product_name>attribute_1 
			generaltype_id>generaltype_id generaltype_name>getGeneraltypeName()
			brand_owner_id>owner_id brand_owner_name>getOwnerName()
			brand_id>brand_id			  brand_name>getBrandName()
			barcode_qty>qty() measure>measure() barcode_weight>getBarcodeWeight()');
        foreach ($copyFields as $k => $method) {
            $priceQuery->set($k, M('Tools')->misc()->value($obDestination, $method));
        }
        $priceQuery->set('total_weight = quantity * ?', $obDestination->getBarcodeWeight());
        $priceQuery->set('weight_price = if(quantity * ? > 0, price / ( quantity * ? ), 0)', $obDestination->getBarcodeWeight(), $obDestination->getBarcodeWeight());
        $priceQuery->set('item_price = if(ifnull(quantity,0) > 0,  price/quantity, 0)');
        if ($restriction) {
            $purchaseQuery->where('id IN (' . sqlBinds($restriction) . ')', $restriction);
            $priceQuery->where('purchase_id  IN (' . sqlBinds($restriction) . ')', $restriction);
        }
        return array($purchaseQuery, $priceQuery);
    }
Exemplo n.º 15
0
 protected function _addDependenceOfBricksToQuery(RM_Db_Query $q, array $brickList)
 {
     $nameList = array();
     foreach ($brickList as $brick) {
         if (!isNull($brick)) {
             $nameList[] = $brick->getBrickSystemName();
         }
     }
     if ($nameList) {
         $q->join('v', 'LEFT JOIN ' . $this->table('dependency') . ' dep on dep.value_id=v.id and dep.brick_code in (' . sqlBinds($nameList) . ')', $nameList);
         $q->what('dep.brick_code');
         $q->where('dep.value_id is null');
     }
 }
Exemplo n.º 16
0
 protected function _isNotUnique(RM_Points_Account $obAccount, $bdate)
 {
     $checkEvents = array('new-barcode', 'no-new-barcode');
     return count($obAccount->getPaymentList()->filter('event in (' . sqlBinds($checkEvents) . ')', $checkEvents)->filter('amount_date=?', M('Date')->dbDate($bdate))) > 0;
 }
Exemplo n.º 17
0
 /**
  * Counts actual data for account
  *
  * @param RM_Points_Account $obAccount
  * @return stdClass|RM_Base_Null
  */
 public function countAccountData(RM_Points_Account $obAccount)
 {
     $ignoreEvents = qw2('write-off present-request present-cancelled');
     $query = M('Db')->createQuery($this->table('payment'))->what("SUM(amount) amount, SUM(IF(ifnull(event,'') not in (" . sqlBinds($ignoreEvents) . "), amount,0)) collected", $ignoreEvents)->where('account_id = ?', $obAccount->id());
     return iterFirst(M('Store')->requestQuery(M('Store')->factoryObject(), $query));
 }