Пример #1
0
 /**
  * Import from Bug. 
  * 
  * @param  int    $projectID 
  * @param  string $orderBy 
  * @param  int    $recTotal 
  * @param  int    $recPerPage 
  * @param  int    $pageID 
  * @access public
  * @return void
  */
 public function importBug($projectID = 0, $browseType = 'all', $param = 0, $recTotal = 0, $recPerPage = 30, $pageID = 1)
 {
     if (!empty($_POST)) {
         $mails = $this->project->importBug($projectID);
         if (dao::isError()) {
             die(js::error(dao::getError()));
         }
         foreach ($mails as $mail) {
             $this->sendmail($mail->taskID, $mail->actionID);
         }
         /* Locate the browser. */
         die(js::locate($this->createLink('project', 'importBug', "projectID={$projectID}"), 'parent'));
     }
     /* Set browseType, productID, moduleID and queryID. */
     $browseType = strtolower($browseType);
     $queryID = $browseType == 'bysearch' ? (int) $param : 0;
     /* Save to session. */
     $uri = $this->app->getURI(true);
     $this->app->session->set('bugList', $uri);
     $this->app->session->set('storyList', $uri);
     $this->app->session->set('projectList', $uri);
     $this->loadModel('bug');
     $projects = $this->project->getPairs('nocode');
     $this->project->setMenu($projects, $projectID);
     /* Load pager. */
     $this->app->loadClass('pager', $static = true);
     $pager = new pager($recTotal, $recPerPage, $pageID);
     $title = $projects[$projectID] . $this->lang->colon . $this->lang->project->importBug;
     $position[] = html::a($this->createLink('project', 'task', "projectID={$projectID}"), $projects[$projectID]);
     $position[] = $this->lang->project->importBug;
     /* Get users, products and projects.*/
     $users = $this->project->getTeamMemberPairs($projectID, 'nodeleted');
     $products = $this->dao->select('t1.product, t2.name')->from(TABLE_PROJECTPRODUCT)->alias('t1')->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product = t2.id')->where('t1.project')->eq($projectID)->fetchPairs('product');
     if (!empty($products)) {
         unset($projects);
         $projects = $this->dao->select('t1.project, t2.name')->from(TABLE_PROJECTPRODUCT)->alias('t1')->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')->where('t1.product')->in(array_keys($products))->fetchPairs('project');
     } else {
         $projectName = $projects[$projectID];
         unset($projects);
         $projects[$projectID] = $projectName;
     }
     /* Get bugs.*/
     $bugs = array();
     if ($browseType != "bysearch") {
         $bugs = $this->bug->getActiveAndPostponedBugs(array_keys($products), $projectID, $pager);
     } else {
         if ($queryID) {
             $query = $this->loadModel('search')->getQuery($queryID);
             if ($query) {
                 $this->session->set('importBugQuery', $query->sql);
                 $this->session->set('importBugForm', $query->form);
             } else {
                 $this->session->set('importBugQuery', ' 1 = 1');
             }
         } else {
             if ($this->session->importBugQuery == false) {
                 $this->session->set('importBugQuery', ' 1 = 1');
             }
         }
         $bugQuery = str_replace("`product` = 'all'", "`product`" . helper::dbIN(array_keys($products)), $this->session->importBugQuery);
         // Search all project.
         $bugs = $this->project->getSearchBugs($products, $projectID, $bugQuery, $pager, 'id_desc');
     }
     /* Build the search form. */
     $this->config->bug->search['actionURL'] = $this->createLink('project', 'importBug', "projectID={$projectID}&browseType=bySearch&param=myQueryID");
     $this->config->bug->search['queryID'] = $queryID;
     if (!empty($products)) {
         $this->config->bug->search['params']['product']['values'] = array('' => '') + $products + array('all' => $this->lang->project->aboveAllProduct);
     } else {
         $this->config->bug->search['params']['product']['values'] = array('' => '');
     }
     $this->config->bug->search['params']['project']['values'] = array('' => '') + $projects + array('all' => $this->lang->project->aboveAllProject);
     $this->config->bug->search['params']['plan']['values'] = $this->loadModel('productplan')->getPairs(array_keys($products));
     $this->config->bug->search['module'] = 'importBug';
     $this->config->bug->search['params']['confirmed']['values'] = array('' => '') + $this->lang->bug->confirmedList;
     $this->config->bug->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($projectID, $viewType = 'bug', $startModuleID = 0);
     unset($this->config->bug->search['fields']['resolvedBy']);
     unset($this->config->bug->search['fields']['closedBy']);
     unset($this->config->bug->search['fields']['status']);
     unset($this->config->bug->search['fields']['toTask']);
     unset($this->config->bug->search['fields']['toStory']);
     unset($this->config->bug->search['fields']['severity']);
     unset($this->config->bug->search['fields']['resolution']);
     unset($this->config->bug->search['fields']['resolvedBuild']);
     unset($this->config->bug->search['fields']['resolvedDate']);
     unset($this->config->bug->search['fields']['closedDate']);
     unset($this->config->bug->search['params']['resolvedBy']);
     unset($this->config->bug->search['params']['closedBy']);
     unset($this->config->bug->search['params']['status']);
     unset($this->config->bug->search['params']['toTask']);
     unset($this->config->bug->search['params']['toStory']);
     unset($this->config->bug->search['params']['severity']);
     unset($this->config->bug->search['params']['resolution']);
     unset($this->config->bug->search['params']['resolvedBuild']);
     unset($this->config->bug->search['params']['resolvedDate']);
     unset($this->config->bug->search['params']['closedDate']);
     $this->loadModel('search')->setSearchParams($this->config->bug->search);
     /* Assign. */
     $this->view->title = $title;
     $this->view->position = $position;
     $this->view->pager = $pager;
     $this->view->bugs = $bugs;
     $this->view->recTotal = $pager->recTotal;
     $this->view->recPerPage = $pager->recPerPage;
     $this->view->browseType = $browseType;
     $this->view->param = $param;
     $this->view->users = $users;
     $this->view->projectID = $projectID;
     $this->display();
 }
Пример #2
0
 /**
  * Get dynamic by search. 
  * 
  * @param  array  $products 
  * @param  array  $projects 
  * @param  int    $queryID 
  * @param  string $orderBy 
  * @param  object $pager 
  * @access public
  * @return array 
  */
 public function getDynamicBySearch($products, $projects, $queryID, $orderBy = 'date_desc', $pager)
 {
     $query = $queryID ? $this->loadModel('search')->getQuery($queryID) : '';
     /* Get the sql and form status from the query. */
     if ($query) {
         $this->session->set('actionQuery', $query->sql);
         $this->session->set('actionForm', $query->form);
     }
     if ($this->session->actionQuery == false) {
         $this->session->set('actionQuery', ' 1 = 1');
     }
     $allProduct = "`product` = 'all'";
     $allProject = "`project` = 'all'";
     $actionQuery = $this->session->actionQuery;
     $productID = 0;
     if (preg_match("/`product` = '(\\d*)'/", $actionQuery, $out)) {
         $productID = $out[1];
     }
     /* If the sql not include 'product', add check purview for product. */
     if (strpos($actionQuery, $allProduct) === false) {
         if (!in_array($productID, array_keys($products))) {
             return array();
         }
     } else {
         $actionQuery = str_replace($allProduct, '1', $actionQuery);
     }
     /* If the sql not include 'project', add check purview for project. */
     if (strpos($actionQuery, $allProject) === false) {
         $actionQuery = $actionQuery . ' AND `project`' . helper::dbIN(array_keys($projects));
     } else {
         $actionQuery = str_replace($allProject, '1', $actionQuery);
     }
     $actionQuery = str_replace("`product` = '{$productID}'", "`product` LIKE '%,{$productID},%'", $actionQuery);
     $actions = $this->getBySQL($actionQuery, $orderBy, $pager);
     if (!$actions) {
         return array();
     }
     return $this->transformActions($actions);
 }
 /**
  * Get bugs by search. 
  * 
  * @param  int    $productID 
  * @param  array  $projects 
  * @param  int    $queryID 
  * @param  string $orderBy 
  * @param  object $pager 
  * @access public
  * @return array
  */
 public function getBySearch($productID, $projects, $queryID, $orderBy, $pager)
 {
     if ($queryID) {
         $query = $this->loadModel('search')->getQuery($queryID);
         if ($query) {
             $this->session->set('bugQuery', $query->sql);
             $this->session->set('bugForm', $query->form);
         } else {
             $this->session->set('bugQuery', ' 1 = 1');
         }
     } else {
         if ($this->session->bugQuery == false) {
             $this->session->set('bugQuery', ' 1 = 1');
         }
     }
     /* check the purview of projects.*/
     if (strpos($this->session->bugQuery, '`project`') === false) {
         $var = $this->session->bugQuery . 'AND `project`' . helper::dbIN(array_keys($projects));
         $this->session->set('bugQuery', "{$var}");
     }
     $bugQuery = str_replace("`product` = 'all'", '1', $this->session->bugQuery);
     // Search all product.
     $bugs = $this->dao->select('*')->from(TABLE_BUG)->where($bugQuery)->andWhere('deleted')->eq(0)->orderBy($orderBy)->page($pager)->fetchAll();
     return $bugs;
 }
Пример #4
0
 /**
  * Create not in part.
  * 
  * @param  string|array $ids   list string by ',' or an array
  * @access public
  * @return object the sql object.
  */
 public function notin($ids)
 {
     if ($this->inCondition and !$this->conditionIsTrue) {
         return $this;
     }
     $this->sql .= ' NOT ' . helper::dbIN($ids);
     return $this;
 }
Пример #5
0
 /**
  * Get bugs by search. 
  * 
  * @param  int    $productID 
  * @param  int    $queryID 
  * @param  string $orderBy 
  * @param  object $pager 
  * @access public
  * @return array
  */
 public function getBySearch($productID, $queryID, $orderBy, $pager = null, $branch = 0)
 {
     if ($queryID) {
         $query = $this->loadModel('search')->getQuery($queryID);
         if ($query) {
             $this->session->set('bugQuery', $query->sql);
             $this->session->set('bugForm', $query->form);
         } else {
             $this->session->set('bugQuery', ' 1 = 1');
         }
     } else {
         if ($this->session->bugQuery == false) {
             $this->session->set('bugQuery', ' 1 = 1');
         }
     }
     if (strpos($this->session->bugQuery, '`product`') === false) {
         $var = $this->session->bugQuery . ' AND `product` = ' . $productID;
         $this->session->set('bugQuery', "{$var}");
     }
     $allProduct = "`product` = 'all'";
     $bugQuery = $this->session->bugQuery;
     if (strpos($this->session->bugQuery, $allProduct) !== false) {
         $products = array_keys($this->loadModel('product')->getPrivProducts());
         $bugQuery = str_replace($allProduct, '1', $this->session->bugQuery);
         $bugQuery = $bugQuery . ' AND `product`' . helper::dbIN($products);
     }
     if ($branch) {
         $bugQuery .= " AND `branch` in('0','{$branch}')";
     }
     $bugs = $this->dao->select('*')->from(TABLE_BUG)->where($bugQuery)->andWhere('deleted')->eq(0)->orderBy($orderBy)->page($pager)->fetchAll();
     return $bugs;
 }
Пример #6
0
 /**
  * Get stories through search.
  * 
  * @access public
  * @param  int    $productID 
  * @param  int    $queryID 
  * @param  string $orderBy 
  * @param  object $pager 
  * @access public
  * @return array
  */
 public function getBySearch($productID, $queryID, $orderBy, $pager, $projectID = '')
 {
     if ($projectID != '') {
         $products = $this->loadModel('project')->getProducts($projectID);
     } else {
         $products = $this->loadModel('product')->getPairs();
     }
     $query = $queryID ? $this->loadModel('search')->getQuery($queryID) : '';
     /* Get the sql and form status from the query. */
     if ($query) {
         $this->session->set('storyQuery', $query->sql);
         $this->session->set('storyForm', $query->form);
     }
     if ($this->session->storyQuery == false) {
         $this->session->set('storyQuery', ' 1 = 1');
     }
     $allProduct = "`product` = 'all'";
     $storyQuery = $this->session->storyQuery;
     $queryProductID = $productID;
     if (strpos($this->session->storyQuery, $allProduct) !== false) {
         $storyQuery = str_replace($allProduct, '1', $this->session->storyQuery);
         $queryProductID = 'all';
     }
     $storyQuery = $storyQuery . ' AND `product`' . helper::dbIN(array_keys($products));
     $storyQuery = $this->loadModel('search')->replaceDynamic($storyQuery);
     return $this->getBySQL($queryProductID, $storyQuery, $orderBy, $pager);
 }
Пример #7
0
 /**
  * Browse cases.
  * 
  * @param  int    $productID 
  * @param  string $browseType 
  * @param  int    $param 
  * @param  string $orderBy 
  * @param  int    $recTotal 
  * @param  int    $recPerPage 
  * @param  int    $pageID 
  * @access public
  * @return void
  */
 public function browse($productID = 0, $browseType = 'all', $param = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
 {
     /* Set browseType, productID, moduleID and queryID. */
     $browseType = strtolower($browseType);
     $productID = $this->product->saveState($productID, $this->products);
     $moduleID = $browseType == 'bymodule' ? (int) $param : 0;
     $queryID = $browseType == 'bysearch' ? (int) $param : 0;
     /* Set menu, save session. */
     $this->testcase->setMenu($this->products, $productID);
     $this->session->set('caseList', $this->app->getURI(true));
     $this->session->set('productID', $productID);
     $this->session->set('moduleID', $moduleID);
     $this->session->set('browseType', $browseType);
     $this->session->set('orderBy', $orderBy);
     /* Load lang. */
     $this->app->loadLang('testtask');
     /* Load pager. */
     $this->app->loadClass('pager', $static = true);
     $pager = pager::init($recTotal, $recPerPage, $pageID);
     $sort = $this->loadModel('common')->appendOrder($orderBy);
     /* By module or all cases. */
     if ($browseType == 'bymodule' or $browseType == 'all') {
         $childModuleIds = $this->tree->getAllChildId($moduleID);
         $this->view->cases = $this->testcase->getModuleCases($productID, $childModuleIds, $sort, $pager);
     } elseif ($browseType == 'needconfirm') {
         $this->view->cases = $this->dao->select('t1.*, t2.title AS storyTitle')->from(TABLE_CASE)->alias('t1')->leftJoin(TABLE_STORY)->alias('t2')->on('t1.story = t2.id')->where("t2.status = 'active'")->andWhere('t1.deleted')->eq(0)->andWhere('t2.version > t1.storyVersion')->orderBy($sort)->page($pager)->fetchAll();
     } elseif ($browseType == 'bysearch') {
         if ($queryID) {
             $query = $this->loadModel('search')->getQuery($queryID);
             if ($query) {
                 $this->session->set('testcaseQuery', $query->sql);
                 $this->session->set('testcaseForm', $query->form);
             } else {
                 $this->session->set('testcaseQuery', ' 1 = 1');
             }
         } else {
             if ($this->session->testcaseQuery == false) {
                 $this->session->set('testcaseQuery', ' 1 = 1');
             }
         }
         $queryProductID = $productID;
         $allProduct = "`product` = 'all'";
         $caseQuery = '(' . $this->session->testcaseQuery;
         if (strpos($this->session->testcaseQuery, $allProduct) !== false) {
             $products = array_keys($this->loadModel('product')->getPrivProducts());
             $caseQuery = str_replace($allProduct, '1', $caseQuery);
             $caseQuery = $caseQuery . ' AND `product`' . helper::dbIN($products);
             $queryProductID = 'all';
         }
         $caseQuery .= ')';
         $this->view->cases = $this->dao->select('*')->from(TABLE_CASE)->where($caseQuery)->beginIF($queryProductID != 'all')->andWhere('product')->eq($productID)->fi()->andWhere('deleted')->eq(0)->orderBy($sort)->page($pager)->fetchAll();
     }
     /* save session .*/
     $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'testcase', $browseType != 'bysearch' ? false : true);
     /* Build the search form. */
     $this->config->testcase->search['params']['product']['values'] = array($productID => $this->products[$productID], 'all' => $this->lang->testcase->allProduct);
     $this->config->testcase->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($productID, $viewType = 'case');
     $this->config->testcase->search['actionURL'] = $this->createLink('testcase', 'browse', "productID={$productID}&browseType=bySearch&queryID=myQueryID");
     $this->config->testcase->search['queryID'] = $queryID;
     $this->loadModel('search')->setSearchParams($this->config->testcase->search);
     /* Assign. */
     $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->testcase->common;
     $this->view->position[] = html::a($this->createLink('testcase', 'browse', "productID={$productID}"), $this->products[$productID]);
     $this->view->position[] = $this->lang->testcase->common;
     $this->view->productID = $productID;
     $this->view->productName = $this->products[$productID];
     $this->view->moduleTree = $this->tree->getTreeMenu($productID, $viewType = 'case', $startModuleID = 0, array('treeModel', 'createCaseLink'));
     $this->view->moduleID = $moduleID;
     $this->view->pager = $pager;
     $this->view->users = $this->user->getPairs('noletter');
     $this->view->orderBy = $orderBy;
     $this->view->browseType = $browseType;
     $this->view->param = $param;
     $this->display();
 }
Пример #8
0
 /**
  * Browse cases of a test task.
  * 
  * @param  string $taskID 
  * @param  string $browseType  bymodule|all|assignedtome
  * @param  int    $param 
  * @param  int    $recTotal 
  * @param  int    $recPerPage 
  * @param  int    $pageID 
  * @access public
  * @return void
  */
 public function cases($taskID, $browseType = 'all', $param = 0, $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
 {
     /* Save the session. */
     $this->app->loadLang('testcase');
     $this->session->set('caseList', $this->app->getURI(true));
     /* Load pager. */
     $this->app->loadClass('pager', $static = true);
     $pager = pager::init($recTotal, $recPerPage, $pageID);
     /* Set the browseType and moduleID. */
     $browseType = strtolower($browseType);
     $moduleID = $browseType == 'bymodule' ? (int) $param : 0;
     $queryID = $browseType == 'bysearch' ? (int) $param : 0;
     /* Append id for secend sort. */
     $sort = $this->loadModel('common')->appendOrder($orderBy);
     /* Get task and product info, set menu. */
     $task = $this->testtask->getById($taskID);
     if (!$task) {
         die(js::error($this->lang->notFound) . js::locate('back'));
     }
     $productID = $task->product;
     $this->testtask->setMenu($this->products, $productID);
     if ($browseType == 'bymodule' or $browseType == 'all') {
         $modules = '';
         if ($moduleID) {
             $modules = $this->loadModel('tree')->getAllChildID($moduleID);
         }
         $this->view->runs = $this->testtask->getRuns($taskID, $modules, $sort, $pager);
     } elseif ($browseType == 'assignedtome') {
         $this->view->runs = $this->testtask->getUserRuns($taskID, $this->session->user->account, $sort, $pager);
     } elseif ($browseType == 'bysearch') {
         if ($queryID) {
             $query = $this->loadModel('search')->getQuery($queryID);
             if ($query) {
                 $this->session->set('testcaseQuery', $query->sql);
                 $this->session->set('testcaseForm', $query->form);
             } else {
                 $this->session->set('testcaseQuery', ' 1 = 1');
             }
         } else {
             if ($this->session->testcaseQuery == false) {
                 $this->session->set('testcaseQuery', ' 1 = 1');
             }
         }
         $queryProductID = $productID;
         $allProduct = "`product` = 'all'";
         $caseQuery = $this->session->testcaseQuery;
         if (strpos($this->session->testcaseQuery, $allProduct) !== false) {
             $products = array_keys($this->loadModel('product')->getPrivProducts());
             $caseQuery = str_replace($allProduct, '1', $this->session->testcaseQuery);
             $caseQuery = $caseQuery . ' AND `product`' . helper::dbIN(array_keys($products));
             $queryProductID = 'all';
         }
         $caseQuery = $this->loadModel('search')->replaceDynamic($caseQuery);
         $caseQuery = preg_replace('/`(\\w+)`/', 't2.`$1`', $caseQuery);
         $this->view->runs = $this->dao->select('t2.*,t1.*, t2.version as caseVersion')->from(TABLE_TESTRUN)->alias('t1')->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id')->where($caseQuery)->andWhere('t1.task')->eq($taskID)->orderBy(strpos($sort, 'assignedTo') !== false ? 't1.' . $sort : 't2.' . $sort)->page($pager)->fetchAll();
     }
     $this->loadModel('common')->saveQueryCondition($this->dao->get(), 'testcase', false);
     /* Save testcaseIDs session for get the pre and next testcase. */
     $testcaseIDs = '';
     foreach ($this->view->runs as $run) {
         $testcaseIDs .= ',' . $run->case;
     }
     $this->session->set('testcaseIDs', $testcaseIDs . ',');
     /* Build the search form. */
     $this->loadModel('testcase');
     $this->config->testcase->search['params']['product']['values'] = array($productID => $this->products[$productID], 'all' => $this->lang->testcase->allProduct);
     $this->config->testcase->search['params']['module']['values'] = $this->loadModel('tree')->getOptionMenu($productID, $viewType = 'case');
     $this->config->testcase->search['actionURL'] = inlink('cases', "taskID={$taskID}&browseType=bySearch&queryID=myQueryID");
     $this->loadModel('search')->setSearchParams($this->config->testcase->search);
     $this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->testtask->cases;
     $this->view->position[] = html::a($this->createLink('testtask', 'browse', "productID={$productID}"), $this->products[$productID]);
     $this->view->position[] = $this->lang->testtask->common;
     $this->view->position[] = $this->lang->testtask->cases;
     $this->view->productID = $productID;
     $this->view->productName = $this->products[$productID];
     $this->view->task = $task;
     $this->view->users = $this->loadModel('user')->getPairs('noclosed,nodeleted,qafirst');
     $this->view->moduleTree = $this->loadModel('tree')->getTreeMenu($productID, $viewType = 'case', $startModuleID = 0, array('treeModel', 'createTestTaskLink'), $extra = $taskID);
     $this->view->browseType = $browseType;
     $this->view->param = $param;
     $this->view->orderBy = $orderBy;
     $this->view->taskID = $taskID;
     $this->view->moduleID = $moduleID;
     $this->view->treeClass = $browseType == 'bymodule' ? '' : 'hidden';
     $this->view->pager = $pager;
     $this->display();
 }
Пример #9
0
 /**
  * Build the query to execute.
  * 
  * @access public
  * @return void
  */
 public function buildQuery()
 {
     /* Init vars. */
     $where = '';
     $groupItems = $this->config->search->groupItems;
     $groupAndOr = strtoupper($this->post->groupAndOr);
     if ($groupAndOr != 'AND' and $groupAndOr != 'OR') {
         $groupAndOr = 'AND';
     }
     for ($i = 1; $i <= $groupItems * 2; $i++) {
         /* The and or between two groups. */
         if ($i == 1) {
             $where .= '( 1  ';
         }
         if ($i == $groupItems + 1) {
             $where .= " ) {$groupAndOr} ( 1 ";
         }
         /* Set var names. */
         $fieldName = "field{$i}";
         $andOrName = "andOr{$i}";
         $operatorName = "operator{$i}";
         $valueName = "value{$i}";
         /* Skip empty values. */
         if ($this->post->{$valueName} == false) {
             continue;
         }
         if ($this->post->{$valueName} == 'null') {
             $this->post->{$valueName} = '';
         }
         // Null is special, stands to empty.
         /* Set and or. */
         $andOr = strtoupper($this->post->{$andOrName});
         if ($andOr != 'AND' and $andOr != 'OR') {
             $andOr = 'AND';
         }
         $where .= " {$andOr} ";
         /* Set filed name. */
         $where .= '`' . $this->post->{$fieldName} . '` ';
         /* Set operator. */
         $value = $this->post->{$valueName};
         $operator = $this->post->{$operatorName};
         if (!isset($this->lang->search->operators[$operator])) {
             $operator = '=';
         }
         if ($operator == "include") {
             $where .= ' LIKE ' . $this->dbh->quote("%{$value}%");
         } elseif ($operator == "notinclude") {
             $where .= ' NOT LIKE ' . $this->dbh->quote("%{$value}%");
         } elseif ($operator == 'belong') {
             if ($this->post->{$fieldName} == 'module') {
                 $allModules = $this->loadModel('tree')->getAllChildId($value);
                 $where .= helper::dbIN($allModules);
             } else {
                 $where .= ' = ' . $this->dbh->quote($value) . ' ';
             }
         } else {
             $where .= $operator . ' ' . $this->dbh->quote($value) . ' ';
         }
     }
     $where .= " )";
     /* Save to session. */
     $querySessionName = $this->post->module . 'Query';
     $formSessionName = $this->post->module . 'Form';
     $this->session->set($querySessionName, $where);
     $this->session->set($formSessionName, $_POST);
 }
Пример #10
0
 /**
  * Get stories through search.
  * 
  * @access public
  * @param  int    $productID 
  * @param  int    $queryID 
  * @param  string $orderBy 
  * @param  object $pager 
  * @param  string $projectID 
  * @access public
  * @return array
  */
 public function getBySearch($productID, $queryID, $orderBy, $pager = null, $projectID = '', $branch = 0)
 {
     if ($projectID != '') {
         $products = $this->loadModel('project')->getProducts($projectID);
     } else {
         $products = $this->loadModel('product')->getPairs();
     }
     $query = $queryID ? $this->loadModel('search')->getQuery($queryID) : '';
     /* Get the sql and form status from the query. */
     if ($query) {
         $this->session->set('storyQuery', $query->sql);
         $this->session->set('storyForm', $query->form);
     }
     if ($this->session->storyQuery == false) {
         $this->session->set('storyQuery', ' 1 = 1');
     }
     $allProduct = "`product` = 'all'";
     $storyQuery = $this->session->storyQuery;
     $queryProductID = $productID;
     if (strpos($this->session->storyQuery, $allProduct) !== false) {
         $storyQuery = str_replace($allProduct, '1', $this->session->storyQuery);
         $queryProductID = 'all';
     }
     $storyQuery = $storyQuery . ' AND `product`' . helper::dbIN(array_keys($products));
     if ($projectID != '') {
         foreach ($products as $product) {
             $branches[$product->branch] = $product->branch;
         }
         unset($branches[0]);
         $branches = join(',', $branches);
         if ($branches) {
             $storyQuery .= " AND `branch`" . helper::dbIN("0,{$branches}");
         }
         $storyQuery .= " AND `status` NOT IN ('draft', 'closed')";
     } elseif ($branch) {
         $storyQuery .= " AND `branch`" . helper::dbIN("0,{$branch}");
     }
     $storyQuery = preg_replace("/`plan` +LIKE +'%([0-9]+)%'/i", "CONCAT(',', `plan`, ',') LIKE '%,\$1,%'", $storyQuery);
     return $this->getBySQL($queryProductID, $storyQuery, $orderBy, $pager);
 }
Пример #11
0
 /**
  * Get stories through search.
  * 
  * @access public
  * @param  int    $productID 
  * @param  int    $queryID 
  * @param  string $orderBy 
  * @param  object $pager 
  * @param  string $projectID 
  * @access public
  * @return array
  */
 public function getBySearch($productID, $queryID, $orderBy, $pager = null, $projectID = '')
 {
     if ($projectID != '') {
         $products = $this->loadModel('project')->getProducts($projectID);
     } else {
         $products = $this->loadModel('product')->getPairs();
     }
     $query = $queryID ? $this->loadModel('search')->getQuery($queryID) : '';
     /* Get the sql and form status from the query. */
     if ($query) {
         $this->session->set('storyQuery', $query->sql);
         $this->session->set('storyForm', $query->form);
     }
     if ($this->session->storyQuery == false) {
         $this->session->set('storyQuery', ' 1 = 1');
     }
     $allProduct = "`product` = 'all'";
     $storyQuery = $this->session->storyQuery;
     $queryProductID = $productID;
     if (strpos($this->session->storyQuery, $allProduct) !== false) {
         $storyQuery = str_replace($allProduct, '1', $this->session->storyQuery);
         $queryProductID = 'all';
     }
     $storyQuery = $storyQuery . ' AND `product`' . helper::dbIN(array_keys($products));
     if ($projectID != '') {
         $branches = array(0 => 0);
         foreach ($products as $product) {
             $branches += $product->branches;
         }
         $storyQuery .= " AND `branch`" . helper::dbIN($branches);
         $storyQuery .= " AND `status` != 'draft'";
     }
     return $this->getBySQL($queryProductID, $storyQuery, $orderBy, $pager);
 }