/** * Set flag `is_food` for all barcodes in query * * @param RM_Db_Query * @param is_food * @return int **/ public function setFood(RM_Db_Query $query, $is_food) { $query->command('update')->set('bc.is_food = ?', $is_food); return $query->execute(); /* print_r($query->render()); exit;*/ }
/** * Returns data for iterator * * @return PDOStatement */ protected function _data() { if (!$this->_data) { $this->_data = $this->_query->execute(); } return $this->_data; }
public function moveLog(RM_Db_Query $query, $barcodes) { if (count($barcodes) == 0) { return; } $diff = $this->_prepareDiff($query->set()->data(), $query->set()->binds()); return $this->changeLog($barcodes, $diff); }
protected function _applyGrouping(RM_Db_Query $query) { $query->order()->reset(); foreach ($this->_columnGroup as $groupField) { $query->group($groupField); $query->order($groupField); } return $query; }
/** * Description... * * @return void **/ public function setBlankQuery(RM_Db_Query $query, $aliases = NULL, $reset = FALSE) { $this->_blankQuery = clone $query; if ($reset) { $this->_blankQuery->what()->reset(); } $this->_aliases = is_null($aliases) ? NULL : $aliases; }
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'); } }
/** * Adds sort conditions into query * * @param RM_Db_Query query * @return void **/ protected function _addSortToQuery(RM_Db_Query $query) { $query->order(implode(', ', array_reverse($this->_getSort()))); }
/** * Apply sort to report data query * * @param RM_Db_Query * @return RM_Db_Query **/ protected function _applySort(RM_Db_Query &$query) { $sortField = 'IF(' . $this->detail()->getFieldNameWithId() . ' = 0, ' . (strtoupper($this->order()) == 'ASC' ? '' : '-') . '1000000000000, ifnull(' . $this->sort() . ',0))'; return $query->order($sortField . ' ' . $this->order()); }
/** * Добавим в запрос данные о кодировщике, последним изменившем запись, и дату последнего изменения * * @param RM_Db_Query query * @return void */ private function _addLastChangeInfo(RM_Db_Query $query) { $query->set('last_change_user_id', me()->id()); $query->set('last_change_date', M('Tools')->date()->dbDateTime()); }
/** * Description... * * @return void **/ public function _appendSort(RM_Db_Query $query) { if (isNull($this->_sort)) { foreach ($this->values() as $item) { $this->_sort['param'] = $item; break; } } $sortField = 'if(' . $this->detailLevel()->getFieldNameWithId() . '=0, ' . ($this->order() == 'asc' ? '' : '-') . '1000000000000, ' . $this->sort()->getVarname() . ')'; return $query->order($sortField . ' ' . $this->order()); }
/** * Adds permission check to query. Parameters can be following: * PARAM TYPE DEFAULT DESC * join-table string Table to join to * permissions string|hash<id:perm> Permissions to check. Can be passed in format: * 'permissions' => 'GRANT' * or * 'permissions' => array('read' => 'READ', 'grnt' => 'GRANT') * or * 'permissions' => array('read' => array( $userId, 'READ') ) * For every key, alias {SELF-PREFIX}{KEY} will be added. * When permissions is a string, KEY='result' * self-alias string access Permission table alias. * self-prefix string access_ Prefix for self aliases * access-id-field string access_id field with access ID in "join-table" * owner-id-field string owner_id field with owner ID in "join-table" * * Short example: * addPermissionToQuery($query, $aliases, array( * 'join-table' => 'mytable', * 'self-prefix' => 'file_access_', * 'permissions' => array('read' => 'READ-INFO'), * )); * $request = $storage->request($query, $aliases); * * // required PERM_ALLOW * $request->filter('file_access_read = ?', PERM_ALLOW); * // required PERM_ALLOW or PERM_UNDEF * $request->filter('(file_access_read & ?)', PERM_ALLOW|PERM_UNDEF); * * @param query RM_Db_Query Query object * @param aliases hashref Hash to store aliases * @param conf hash<name:value> Configuration params * @return void */ public function addPermissionToQuery(RM_Db_Query $query, array &$aliases = array(), array $origConf = array()) { $conf = array(); foreach (qw2('join-table> permissions> self-alias>access self-prefix>access_ access-id-field>access_id owner-id-field>owner_id ps-id>') as $id => $v) { if (array_key_exists($id, $origConf)) { $conf[$id] = $origConf[$id]; unset($origConf[$id]); } else { $conf[$id] = $v; } } if (count($origConf)) { throw new RM_Base_Exception_BadUsage("Unknown params: " . join(',', array_keys($origConf))); } if (!$conf['join-table']) { throw new RM_Base_Exception_BadUsage("'join-table' parameter is required"); } $query->join($conf['join-table'], sprintf("LEFT JOIN %s AS %s ON %s = %s", $this->_pdTable, $conf['self-alias'], M('Db')->field($conf['self-alias'], 'pd_access_id'), M('Db')->field($conf['join-table'], $conf['access-id-field']))); $perms = is_array($conf['permissions']) ? $conf['permissions'] : array('result' => $conf['permissions']); if (!count($perms)) { throw new RM_Base_Exception_BadUsage("You must specify at least one permission if you call this method..."); } $binds = array(); foreach ($perms as $key => $value) { list($uid, $value) = is_array($value) ? $value : array(NULL, $value); $ids = $this->permToIds($value); if (count($ids) != 1) { throw new RM_Base_Exception_BadUsage("'permission' must be specified and must be the single permission (multiple permissions not implemented yet, contact Permission lib developer if you really need it)"); } list($aliases[$conf['self-prefix'] . $key], $binds[$key]) = $this->_fmtCheckAccessCall($ids[0], $uid, $conf['ps-id'], M('Db')->field($conf['join-table'], $conf['owner-id-field']), M('Db')->field($conf['self-alias'], 'pd_data'), M('Db')->field($conf['self-alias'], 'pd_access_id')); } return $binds; }
/** * Description... * * @return void **/ public function initPlotByQuery($type, RM_Db_Query $q, $field, $index = NULL, array $args = array()) { $data = array(); $xLabels = NULL; foreach ($q->execute() as $row) { $data[] = $row[$field]; if (isset($args['xLabels']) || isset($args['xLabelsFunction'])) { $xLabels[] = $this->_getLabel($row, $args); } } /* if(isset($xLabels)) $this->graph(isset($args['graphIndex']) ? $args['graphIndex'] : 0)->addLabels($xLabels);*/ return $this->_createPlot($type, $index, array('data' => $data, 'xLabels' => $xLabels)); }
/** * Adds tree table to query. Conf: * PARAM TYPE DEFAULT DESC * self-alias string tree Tree table alias. * self-prefix string tree_ Prefix for self aliases * self-field string descendent_id Field to link agains: descendent_id, ancestor_id * join-table string '' Table to join to * join-field string id Field in "join-table" * * Adds aliases: * ancestor_id * descendent_id * level * (with prefix "self-prefix") * * @param query RM_Db_Query Source query * @param aliases arrayref Array for aliases * @param conf hash Configuration. See above * @return void */ public function addTreeToQuery(RM_Db_Query $query, array &$aliases = array(), array $conf = array()) { $conf = array_merge(qw2('self-alias>tree self-prefix>tree_ self-field>descendent_id join-table> join-field>id'), $conf); $query->join($conf['join-table'], sprintf("LEFT JOIN %s AS %s ON %s = %s", $this->_table, $conf['self-alias'], M('Db')->field($conf['self-alias'], $conf['self-field']), M('Db')->field($conf['join-table'], $conf['join-field']))); foreach (qw2('ancestor_id descendent_id level') as $f) { $aliases[$conf['self-prefix'] . $f] = M('Db')->field($conf['self-alias'], $f); } }
function count() { return $this->_query->executeCount(); }