public static function getObject($ind) { if (!$ind) { return false; } if (is_numeric($ind)) { $key = 'id'; $notUrl = ' and url=""'; // дополнительная проверка на пустой урл для этого обьекта, что-бы небыло повторов страниц } else { $key = 'url'; $ind = trim($ind, '/'); if (!$ind) { return false; } } // $objectModel = new Admin_Model_Object; // $object = $objectModel->mfr(select()->where(array($key => $ind))); // select *,(select name from obj_types where id=obj_objects.type limit 1) as typename, (select anchID from obj_objects where id=".$_REQUEST['look']." limit 1) as filial_info, (select symbol from obj_branches where id=obj_objects.branchID) as letter from obj_objects where id=".$_REQUEST['look']." limit 1" // $db->setQuery('select id,title,text from obj_plans where objID='.$this->data['id'].''); // phone, address, email $q = new K_Query(); $row = $q->q("SELECT o.*, b.symbol letter, t.name typename, o.branchID filial_info, b.symbol letter, b.phone, b.address, b.email FROM `obj_objects` o \n LEFT JOIN obj_rooms r ON r.id = o.id\n LEFT JOIN obj_types t ON t.id = o.type\n LEFT JOIN obj_branches b ON b.id = o.branchID \n WHERE o." . $key . "=" . K_Db_Quote::quote($ind) . ' ' . $notUrl, true); if ($row) { return $row[0]; } else { return false; } }
/** Функция возврящяет сформированный массив where * * * */ public static function where($fields, $pts) { foreach ($fields as $k => $v) { if (isset($pts[$k]) && !empty($pts[$k])) { if ($_POST[$k] == "нет") { $where[] = $v . ' IS NULL '; } else { $where[] = $v . ' LIKE ' . K_Db_Quote::quote($_POST[$k] . '%'); } } } return $where; }
public function loadCompletedFormsAction() { $page = intval($_POST['page']); $onPage = intval($_POST['onPage']); if ($page) { if (!$onPage) { $onPage = 10; } $start = $page * $onPage - $onPage; } else { $start = 0; $page = 1; $onPage = 10; } $formData = Gcontroller::loadclientFormStructure(trim($_POST['tree_link'])); /* $clientFormData = $typeClientForm->fetchRow( K_Db_Select::create()->where( "type_clientform_id=$clientFormKey" ) ); $this->view->formStructure=unserialize( $clientFormData['type_clientform_content'] );*/ $formStructure = json_decode($formData['form_structure']); $formStructure = K_Tree_Types::objectToArray($formStructure); $fieldCount = 0; foreach ($formStructure as $v) { if (isset($v['values']['name']) && isset($v['values']['label'])) { $colsKeys[] = $v['values']['name']; $fieldCount++; } if ($fieldCount > 3) { break; } } $query = new K_Db_Query(); $sql = "SELECT * FROM clientform_data WHERE clientform_data_type=" . K_Db_Quote::quote(trim($_POST['tree_link'])) . " ORDER by clientform_data_date DESC LIMIT {$start}, {$onPage}"; $formsRes = $query->q($sql); $sql = "SELECT count(*) as countItems from clientform_data WHERE clientform_data_type=" . K_Db_Quote::quote(trim($_POST['tree_link'])); $countItems = $query->q($sql); $countItems = $countItems[0]['countItems']; $forms = array(); foreach ($formsRes as $v) { $formData = array(); $id = $v['clientform_data_id']; $formData[] = $v['clientform_data_date']; $data = unserialize($v['clientform_data_content']); $data = K_Tree_Types::objectToArray($data); foreach ($colsKeys as $n) { $formData[] = isset($data[$n]) ? $data[$n] : 'off'; } $formData['id'] = $id; $forms[] = $formData; } $returnJson = array('error' => false, 'items' => $forms, 'countItems' => $countItems); $this->putJSON($returnJson); }
public static function balanceRemove($count) { self::init(); //снимаем деньги со счёта $organizationModel = new Admin_Model_Organization(); $organizationModel->update(array('organization_pay_balance' => K_Db_Quote::quote(K_Auth::getUserInfo('org_balance') - $count)), 'organization_id=' . K_Auth::getUserInfo('organization')); $journalData['p_org'] = K_Auth::getUserInfo('organization'); $journalData['p_client'] = K_Auth::getUserInfo('id'); $journalData['p_balance'] = K_Auth::getUserInfo('org_balance'); $journalData['p_count'] = $count; $journalData['p_admins'] = 0; $journalData['p_users'] = 1; $journalData['p_acost'] = self::$_adminCost; $journal = new Admin_Model_PayJournal(); $journal->save($journalData); K_Auth::setUserKey('org_balance', K_Auth::getUserInfo('org_balance') - $count); }
public function loadtypesAction() { $query = new Query(); $this->view->title = 'Добавление нового типа'; $this->view->header = 'Добавление нового типа'; $page = intval($_POST['page']); $onPage = intval($_POST['onPage']); if ($page) { if (!$onPage) { $onPage = 10; } $start = $page * $onPage - $onPage; } else { $start = 0; $page = 1; $onPage = 10; } if (isset($_POST['name'])) { $where[] = 'type_name Like ' . K_Db_Quote::quote('%' . $_POST['name'] . '%'); } if (isset($_POST['desc'])) { $where[] = 'type_desc Like ' . K_Db_Quote::quote('%' . $_POST['desc'] . '%'); } if ($where && count($where)) { $where = ' WHERE ' . implode(' AND ', $where); } $query = new Query(); $sql = "SELECT SQL_CALC_FOUND_ROWS * FROM types {$where} order by type_name LIMIT {$start}, {$onPage}"; $itemsRes = $query->q($sql); $sql = "SELECT FOUND_ROWS() as countItems;"; $countItems = $query->q($sql); $countItems = $countItems[0]['countItems']; $items = array(); foreach ($itemsRes as $v) { $itemRow['type_id'] = $v['type_id']; $itemRow['name'] = htmlspecialchars($v['type_name']); $itemRow['desc'] = htmlspecialchars($v['type_desc']); $items[] = $itemRow; } $returnJson = array('error' => false, 'items' => $items, 'countItems' => $countItems); $this->putJSON($returnJson); }
public function loadAction() { $userModel = new Admin_Model_User(); $page = intval($_POST['page']); $onPage = intval($_POST['onPage']); $filter = $_POST['filter']; if ($page) { if (!$onPage) { $onPage = 10; } $start = $page * $onPage - $onPage; } else { $start = 0; $page = 1; $onPage = 10; } $where = 'WHERE 1=1'; if ($filter) { $where = "WHERE user_name like " . K_Db_Quote::quote($filter . '%'); } $query = new K_Db_Query(); $sql = "SELECT SQL_CALC_FOUND_ROWS u.*, (SELECT GROUP_CONCAT(role_name SEPARATOR ', ') as user_roles FROM users_roles ur left join role on ur.usrol_role_id=role_id WHERE ur.usrol_user_id = u.user_id) as user_roles FROM users u \n {$where} order by user_name LIMIT {$start}, {$onPage}"; $usersRes = $query->q($sql); $sql = "SELECT FOUND_ROWS() as countItems;"; $countItems = $query->q($sql); $countItems = $countItems[0]['countItems']; $users = array(); foreach ($usersRes as $v) { $id = $v['user_id']; $userRow['name'] = $v['user_name']; $userRow['login'] = $v['user_login']; $userRow['email'] = $v['user_email']; $userRow['roles'] = $v['user_roles'] == null ? '' : $v['user_roles']; $users[$id] = $userRow; } $returnJson = array('error' => false, 'items' => $users, 'countItems' => $countItems); $this->putJSON($returnJson); }
public function loadAction() { $page = intval($_POST['page']); $onPage = intval($_POST['onPage']); $searche = $_POST['filter']; $blogId = intval($_POST['blogid']); if ($dateStart = K_Date::dateParse($_POST['date-start'])) { $dateStart = mktime(0, 0, 0, $dateStart['m'], $dateStart['d'], $dateStart['y']); } if ($dateStop = K_Date::dateParse($_POST['date-stop'])) { $dateStop = mktime(23, 59, 59, $dateStop['m'], $dateStop['d'], $dateStop['y']); } if (is_numeric($_POST['price-start'])) { $priceStart = $_POST['price-start']; } if (is_numeric($_POST['price-stop'])) { $priceStop = $_POST['price-stop']; } if ($page) { if (!$onPage) { $onPage = 10; } $start = $page * $onPage - $onPage; } else { $start = 0; $page = 1; $onPage = 10; } $where = ''; // перечень полей из пост запроса для проверки $fields = array('id' => 'o.id', 'idc1' => 'o.idc1', 'type' => 'o.type', 'filial' => 'o.filial', 'adres' => 'o.adres', 'comnati' => 'o.comnati'); $where = K_Afunc::where($fields, $_POST); // var_dump($where); // цена объекта if ($priceStart && $priceStop) { if ($priceStart > $priceStop) { $where[] = "UNIX_TIMESTAMP(o.price) >= " . K_Db_Quote::quote($priceStart); } else { $where[] = "(UNIX_TIMESTAMP(o.price) BETWEEN " . K_Db_Quote::quote($priceStart) . " AND " . K_Db_Quote::quote($priceStop) . ")"; } } else { if ($priceStart) { $where[] = "UNIX_TIMESTAMP(o.price) >= " . K_Db_Quote::quote($priceStart); } else { if ($priceStop) { $where[] = "UNIX_TIMESTAMP(o.price) <= " . K_Db_Quote::quote($priceStop); } } } // дата публикации объекта if ($dateStart && $dateStop) { if ($dateStart > $dateStop) { $where[] = "UNIX_TIMESTAMP(o.date_publication) >= " . K_Db_Quote::quote($dateStart); } else { $where[] = "(UNIX_TIMESTAMP(o.date_publication) BETWEEN " . K_Db_Quote::quote($dateStart) . " AND " . K_Db_Quote::quote($dateStop) . ")"; } } else { if ($dateStart) { $where[] = "UNIX_TIMESTAMP(o.date_publication) >= " . K_Db_Quote::quote($dateStart); } else { if ($dateStop) { $where[] = "UNIX_TIMESTAMP(o.date_publication) <= " . K_Db_Quote::quote($dateStop); } } } if ($where && count($where)) { $where = ' WHERE ' . implode(' AND ', $where); } $query = new K_Db_Query(); $sql = "SELECT SQL_CALC_FOUND_ROWS o.*, b.symbol letter, t.name typename, t.color color, o.branchID filial_info, b.symbol letter, b.phone, b.address, b.email, b.title filial FROM `obj_objects` o\n \n LEFT JOIN obj_rooms r ON r.id = o.id \n LEFT JOIN obj_types t ON t.id = o.type \n LEFT JOIN obj_branches b ON b.id = o.branchID \n \n {$where} ORDER BY date_publication DESC LIMIT {$start}, {$onPage}"; $itemsRes = $query->q($sql); $sql = "SELECT FOUND_ROWS() as countItems;"; $countItems = $query->q($sql); $countItems = $countItems[0]['countItems']; $items = array(); // сделать вывод планировок. // var_dump($itemRow); $this->view->objectRow = $itemRow; foreach ($itemsRes as $v) { $itemRow['id'] = $v['id']; $itemRow['id1c'] = $v['id1c']; $itemRow['type'] = $v['typename']; $itemRow['filial'] = strip_tags(htmlspecialchars($v['filial'])); $itemRow['adress'] = strip_tags($v['city'] . ' ' . $v['city'] . ' ' . $v['street']); $itemRow['rooms'] = strip_tags(htmlentities($v['rooms'])); $itemRow['price'] = $v['price']; $itemRow['color'] = strtoupper($v['color']); $items[] = $itemRow; } $returnJson = array('error' => false, 'items' => $items, 'countItems' => $countItems); $this->putJSON($returnJson); }
public function loadAction() { $page = intval($_POST['page']); $onPage = intval($_POST['onPage']); $searche = $_POST['filter']; $newId = intval($_POST['newid']); if ($dateStart = K_Date::dateParse($_POST['date-start'])) { $dateStart = mktime(0, 0, 0, $dateStart['m'], $dateStart['d'], $dateStart['y']); } if ($dateStop = K_Date::dateParse($_POST['date-stop'])) { $dateStop = mktime(23, 59, 59, $dateStop['m'], $dateStop['d'], $dateStop['y']); } if ($page) { if (!$onPage) { $onPage = 10; } $start = $page * $onPage - $onPage; } else { $start = 0; $page = 1; $onPage = 10; } if ($dateStart && $dateStop) { if ($dateStart > $dateStop) { $where[] = "UNIX_TIMESTAMP(comment_date) >= " . K_Db_Quote::quote($dateStart); } else { $where[] = "(UNIX_TIMESTAMP(comment_date) BETWEEN " . K_Db_Quote::quote($dateStart) . " AND " . K_Db_Quote::quote($dateStop) . ")"; } } else { if ($dateStart) { $where[] = "UNIX_TIMESTAMP(comment_date) >= " . K_Db_Quote::quote($dateStart); } else { if ($dateStop) { $where[] = "UNIX_TIMESTAMP(comment_date) <= " . K_Db_Quote::quote($dateStop); } } } if ($newId) { $where[] = " comment_new = " . K_Db_Quote::quote($newId); } if ($searche) { $where[] = " (comment_name like " . K_Db_Quote::quote($searche . '%') . " OR comment_email like " . K_Db_Quote::quote($searche . '%') . ")"; } if ($_POST['comments-status']) { $where[] = " comment_status = " . K_Db_Quote::quote($_POST['comments-status']); } if ($where && count($where)) { $where = ' WHERE ' . implode(' AND ', $where); } $query = new K_Db_Query(); $sql = "SELECT SQL_CALC_FOUND_ROWS * from comments {$where} order by comment_date DESC LIMIT {$start}, {$onPage}"; $itemsRes = $query->q($sql); $sql = "SELECT FOUND_ROWS() as countItems;"; $countItems = $query->q($sql); $countItems = $countItems[0]['countItems']; $items = array(); foreach ($itemsRes as $v) { $itemRow['id'] = $v['comment_id']; $itemRow['date'] = $v['comment_date']; $itemRow['name'] = strip_tags(htmlspecialchars($v['comment_name'])); $itemRow['content'] = strip_tags(htmlspecialchars($v['comment_content'])); $itemRow['status'] = $v['comment_status']; $itemRow['ip'] = long2ip($v['comment_ip']); $items[] = $itemRow; } $returnJson = array('error' => false, 'items' => $items, 'countItems' => $countItems); $this->putJSON($returnJson); }
/** * Перемещает элемент в новое место дерева. Позиция определяется относительно опорного элемента * * @throws Exception * @param integer $key Ключ (ID или URL) перемещаемого элемента * @param integer $base_key Ключ (ID или URL) опорного элемента * @param string $position Положение относительно опорного элемента. Возможные значения: bottom, top, before, after * @return bool Произошло ли перемещение */ public static function move($key, $base_key, $position = 'top') { $treeTable = new K_Tree_Model(); // Получаем информацию о перемещаемом элементе $node = self::getNode($key); if ($node === FALSE) { throw new Exception('Перемещаемого элемента (' . $key . ') не существует'); } if ($node['tree_level'] == 0) { throw new Exception('Невозможно переместить элемент нулевого уровня'); } $node_diff = $node['tree_rkey'] - $node['tree_lkey'] + 1; // Получаем опорный элемент $base = self::getNode($base_key); if ($base === FALSE) { throw new Exception('Заданного опорного элемента (' . $base_key . ') не существует'); } // Получаем родительский элемент $parent = self::_getPositionParent($base, $position); // Не пытаемся ли мы переместить элемент в один из вложенных? if ($node['tree_lkey'] < $parent['tree_lkey'] and $node['right_key'] > $parent['right_key']) { throw new Exception('Невозможно переместить элемент в один из вложенных'); } // Новые значения элемента $move = array('tree_lkey' => self::_getPositionLeftKey($base, $parent, $position), 'tree_level' => $parent['tree_level'] + 1, 'tree_name' => $node['tree_name'], 'tree_pid' => $parent['tree_id']); if ($node['tree_pid'] == $parent['tree_id']) { // Смена порядка внутри одного родителя. Упрощенный алгоритм для ускорения операций if ($node['tree_lkey'] == $move['tree_lkey']) { // Элемент уже находится в нужной позиции return TRUE; } if ($move['tree_lkey'] > $node['tree_lkey']) { // Перемещаем элемент вперед. Все промежуточные сдвигаем назад $shift = $move['tree_lkey'] - 1 - $node['tree_rkey']; $treeTable->update(array('tree_rkey' => new K_Db_Expr('IF(`tree_lkey` < ' . (int) $node['tree_rkey'] . ', `tree_rkey` + ' . $shift . ', `tree_rkey` - ' . (int) $node_diff . ')'), 'tree_lkey' => new K_Db_Expr('IF(`tree_lkey` < ' . (int) $node['tree_rkey'] . ', `tree_lkey` + ' . $shift . ', `tree_lkey` - ' . (int) $node_diff . ')')), '`tree_lkey` BETWEEN ' . (int) $node['tree_lkey'] . ' AND ' . ((int) $move['tree_lkey'] - 1)); } else { // Перемещаем элемент назад. Все промежуточные сдвигаем вперед $shift = $node['tree_lkey'] - $move['tree_lkey']; $treeTable->update(array('tree_rkey' => new K_Db_Expr('IF(`tree_lkey` < ' . (int) $node['tree_lkey'] . ', `tree_rkey` + ' . (int) $node_diff . ', `tree_rkey` - ' . $shift . ')'), 'tree_lkey' => new K_Db_Expr('IF(`tree_lkey` < ' . (int) $node['tree_lkey'] . ', `tree_lkey` + ' . (int) $node_diff . ', `tree_lkey` - ' . $shift . ')')), '`tree_lkey` BETWEEN ' . (int) $move['tree_lkey'] . ' AND ' . (int) $node['tree_rkey']); } } else { // Перемещение в другой родительский элемент. $move - место элемента, как если бы он вставлялся // Проверяем, чтобы URL не повторялся $name_occupied = $treeTable->select()->where('`tree_pid` = ' . (int) $parent['tree_id'] . ' AND `tree_name` = ' . K_Db_Quote::quoteKey($move['tree_name']))->fetchArray(); // Если предлагаемое имя сегмента занято, используем свободное имя //var_dump($name_occupied); if (count($name_occupied)) { // $move['tree_name'] = self::get_available_name($parent['tree_id'], $move['tree_name']); $move['tree_name'] = "_" . base_convert(time() + rand(1, 999), 10, 36); $move['tree_title'] = "_K"; } if ($move['tree_lkey'] > $node['tree_lkey']) { // Перемещаем вперед. Ориентируемся на правый ключ. Область перемещения: $node['tree_lkey'], $move['tree_rkey'] $move['tree_lkey'] -= $node_diff; $move['tree_rkey'] = $move['tree_lkey'] + $node_diff - 1; $shift = $move['tree_rkey'] - $node['tree_rkey']; $treeTable->update(array('tree_lkey' => new K_Db_Expr('IF(`tree_lkey` < ' . (int) $node['tree_rkey'] . ', IF(`tree_lkey` < ' . (int) $node['tree_lkey'] . ', `tree_lkey`, `tree_lkey` + ' . $shift . '), `tree_lkey` - ' . (int) $node_diff . ')'), 'tree_rkey' => new K_Db_Expr('IF(`tree_rkey` <= ' . (int) $node['tree_rkey'] . ', `tree_rkey` + ' . $shift . ', IF(`tree_rkey` <= ' . (int) $move['tree_rkey'] . ', `tree_rkey` - ' . (int) $node_diff . ', `tree_rkey`))')), '`tree_lkey` BETWEEN ' . (int) $node['tree_lkey'] . ' AND ' . (int) $move['tree_rkey'] . ' OR `tree_rkey` BETWEEN ' . (int) $node['tree_lkey'] . ' AND ' . (int) $move['tree_rkey']); } else { // Перемещаем назад. Ориентируемся на левый ключ. $move['tree_rkey'] = $move['tree_lkey'] + $node_diff - 1; $shift = $node['tree_lkey'] - $move['tree_lkey']; $treeTable->update(array('tree_lkey' => new K_Db_Expr('IF(`tree_lkey` < ' . (int) $node['tree_lkey'] . ', IF(`tree_lkey` < ' . (int) $move['tree_lkey'] . ', `tree_lkey`, `tree_lkey` + ' . (int) $node_diff . '), `tree_lkey` - ' . $shift . ')'), 'tree_rkey' => new K_Db_Expr('IF(`tree_rkey` <= ' . (int) $node['tree_lkey'] . ', `tree_rkey` + ' . (int) $node_diff . ', IF(`tree_rkey` <= ' . (int) $node['tree_rkey'] . ', `tree_rkey` - ' . $shift . ', `tree_rkey`))')), '`tree_lkey` BETWEEN ' . (int) $move['tree_lkey'] . ' AND ' . (int) $node['tree_rkey'] . ' OR `tree_rkey` BETWEEN ' . (int) $move['tree_lkey'] . ' AND ' . (int) $node['tree_rkey']); } if ($move['tree_level'] != $node['tree_level']) { $level_shift = $node['tree_level'] - $move['tree_level']; $treeTable->update(array('tree_level' => new K_Db_Expr('`tree_level` - (' . $level_shift . ')')), '`tree_lkey` BETWEEN ' . (int) $move['tree_lkey'] . ' AND ' . (int) $move['tree_rkey']); } $treeTable->update($move, '`tree_id`=' . $node['tree_id']); $move = array_merge($node, $move); self::_fixUrls($move, $parent['tree_link']); } return true; }
public function loadAction() { $page = intval($_POST['page']); $onPage = intval($_POST['onPage']); $searche = $_POST['filter']; $newId = intval($_POST['newid']); if ($dateStart = K_Date::dateParse($_POST['date-start'])) { $dateStart = mktime(0, 0, 0, $dateStart['m'], $dateStart['d'], $dateStart['y']); } if ($dateStop = K_Date::dateParse($_POST['date-stop'])) { $dateStop = mktime(23, 59, 59, $dateStop['m'], $dateStop['d'], $dateStop['y']); } if ($page) { if (!$onPage) { $onPage = 10; } $start = $page * $onPage - $onPage; } else { $start = 0; $page = 1; $onPage = 10; } if ($dateStart && $dateStop) { if ($dateStart > $dateStop) { $where[] = "UNIX_TIMESTAMP(type_news_date) >= " . K_Db_Quote::quote($dateStart); } else { $where[] = "(UNIX_TIMESTAMP(type_news_date) BETWEEN " . K_Db_Quote::quote($dateStart) . " AND " . K_Db_Quote::quote($dateStop) . ")"; } } else { if ($dateStart) { $where[] = "UNIX_TIMESTAMP(type_news_date) >= " . K_Db_Quote::quote($dateStart); } else { if ($dateStop) { $where[] = "UNIX_TIMESTAMP(type_news_date) <= " . K_Db_Quote::quote($dateStop); } } } if ($_POST['news-lang']) { $where[] = " type_news_lang = " . K_Db_Quote::quote($_POST['news-lang']); } if ($section = intval($_POST['section'])) { $where[] = " tree_pid = " . K_Db_Quote::quote($section); } if ($searche && mb_strlen($searche) > 2) { if ($searche) { $where[] = "(type_news_title LIKE " . K_Db_Quote::quote('%' . $searche . '%') . ' OR type_news_author LIKE ' . K_Db_Quote::quote($searche . '%') . ")"; } } if ($where && count($where)) { $where = ' WHERE ' . implode(' AND ', $where); } $query = new K_Db_Query(); $sql = "SELECT SQL_CALC_FOUND_ROWS type_news.*,type_section_ua_name from type_news\n LEFT JOIN tree ON tree_id = type_news_id \n LEFT JOIN type_section ON type_section_id = tree_pid \n {$where} order by type_news_date DESC LIMIT {$start}, {$onPage}"; $itemsRes = $query->q($sql); $sql = "SELECT FOUND_ROWS() as countItems;"; $countItems = $query->q($sql); $countItems = $countItems[0]['countItems']; $items = array(); foreach ($itemsRes as $v) { $itemRow['id'] = $v['type_news_id']; $itemRow['date'] = $v['type_news_date']; $itemRow['title'] = strip_tags(htmlspecialchars($v['type_news_title'])); $itemRow['lang'] = strip_tags($v['type_news_lang']); $itemRow['section'] = strip_tags($v['type_section_ua_name']); $itemRow['author'] = strip_tags(htmlentities($v['type_news_author'])); $items[] = $itemRow; } $returnJson = array('error' => false, 'items' => $items, 'countItems' => $countItems); $this->putJSON($returnJson); }
public function loadAction() { $userModel = new Admin_Model_User(); $page = intval($_POST['page']); $onPage = intval($_POST['onPage']); $filter = $_POST['filter']; if ($page) { if (!$onPage) { $onPage = 10; } $start = $page * $onPage - $onPage; } else { $start = 0; $page = 1; $onPage = 10; } $where = 'WHERE 1=1'; if ($filter) { $where = "WHERE r.role_name like " . K_Db_Quote::quote($filter . '%'); } $query = new K_Db_Query(); $sql = "SELECT SQL_CALC_FOUND_ROWS r.*, p.role_name AS parent, (SELECT count(*) as rule_count FROM rule WHERE rule_role_id=r.role_id) as rule_count FROM role AS r LEFT JOIN role AS p ON r.role_status = 1 AND p.role_status = 1 AND r.role_parent_id = p.role_id {$where} ORDER BY r.role_level LIMIT {$start}, {$onPage}"; //$sql = "SELECT SQL_CALC_FOUND_ROWS u.*, (SELECT GROUP_CONCAT(role_name SEPARATOR ', ') as user_roles FROM users_roles ur left join role on ur.usrol_role_id=role_id WHERE ur.usrol_user_id = u.user_id) as user_roles FROM users u // $where order by user_name LIMIT $start, $onPage"; $rolseRes = $query->q($sql); $sql = "SELECT FOUND_ROWS() as countItems;"; $countItems = $query->q($sql); $countItems = $countItems[0]['countItems']; $roles = array(); foreach ($rolseRes as $v) { $id = $v['role_id']; $roleRow['name'] = $v['role_name']; $roleRow['role_acl_key'] = $v['role_acl_key']; $roleRow['parentid'] = $v['role_parent_id'] == null ? '' : $v['role_parent_id']; $roleRow['parentname'] = $v['parent'] == null ? 'Нет предка' : $v['parent']; $roleRow['rule_count'] = $v['rule_count']; $roles[$id] = $roleRow; } $returnJson = array('error' => false, 'items' => $roles, 'countItems' => $countItems); $this->putJSON($returnJson); }
/** * @function update - îáíàâëåíèå çàïèñè â òàáëèöå * * @param $data - ìàññèâ äàííûõ * * @param $where - óñëîâèÿ ïî êîòîðûì îáíîâëÿòü çàïèñè * */ public function update($data, $where = null, $setModTime = true) { $set = array(); if (count($data)) { foreach ($data as $key => $value) { // ïðîâåðêà íà íóë, òåïåðü ìîæíî óñòàíàâëèâàòü çíà÷åíèå null â áàçó $v = is_null($value) ? 'null' : K_Db_Quote::quote($value); $set[] = K_Db_Quote::quoteKey($key) . ' = ' . $v; } } $whereString = '1=1'; if (!empty($where)) { if ($where instanceof K_Db_Select) { $whereString = $where->where; } elseif (is_array($where)) { $select = K_Db_Select::create(); $whereString = $select->_where(array($where)); } elseif (is_string($where)) { $whereString = $where; } } $sql = 'UPDATE ' . $this->name . ' SET ' . implode(',', $set) . ' WHERE ' . $whereString; $this->db->query($sql); if ($setModTime) { $this->db->_setLastDataChange($this->name); } }
/** * Generate SQL select query */ public function sql() { $sql = 'SELECT '; if (!empty($this->fields)) { $sql .= $this->fields; } else { $sql .= '*'; } if (empty($this->table)) { throw 'K_Db_Select: table name is empty'; } if (count($this->table)) { $joinsSql = ''; $currentTables = $this->table; $this->buildMultiJoins(); if (count($this->joins)) { $this->buildJoins(); $currentTables = array_merge($this->table, $this->joinTables); } foreach ($currentTables as &$tableInfo) { if ($tableInfo['type'] == 'table') { $joinsSql .= (!empty($joinsSql) ? ',' : '') . $tableInfo['sql']; } elseif ($tableInfo['type'] == 'join') { $joinsSql = '(' . $joinsSql . ')' . $tableInfo['sql']; } elseif ($tableInfo['type'] == 'select') { $joinsSql .= (!empty($joinsSql) ? ',' : '') . '(' . $tableInfo['sql'] . ')' . (!empty($tableInfo['name']) ? ' as ' . K_Db_Quote::quoteKey($tableInfo['name']) : ''); } } $sql .= ' FROM ' . $joinsSql; } if (!empty($this->where)) { $sql .= ' WHERE ' . $this->where; } if (!empty($this->group)) { $sql .= ' GROUP BY ' . $this->group; } if (!empty($this->having)) { $sql .= ' HAVING ' . $this->having; } if (!empty($this->order)) { $sql .= ' ORDER BY ' . $this->order; } if (!empty($this->limit)) { $sql .= ' LIMIT ' . $this->limit; } if (!empty($this->offset)) { $sql .= ' OFFSET ' . $this->offset; } return $sql . ''; }