예제 #1
0
 /**
  * Add related object selection
  */
 public function addSubAction()
 {
     $this->_checkCanEdit();
     $this->_checkLoaded();
     $baseField = Request::post('basefield', 'string', false);
     $subObject = Request::post('subobject', 'string', false);
     $subField = Request::post('subfield', 'string', false);
     $join = Request::post('join', 'integer', 1);
     if (!$baseField || !$subObject || !$subField || !$join) {
         Response::jsonError($this->_lang->WRONG_REQUEST);
     }
     $query = $this->_session->get('query');
     $basePart = $query->getRootPart();
     $childPart = $query->findChild($basePart->getId(), $baseField);
     if ($childPart !== false) {
         $query->removePart($childPart->getId());
     }
     $newPart = new Db_Query_Part();
     $newPart->setObject($subObject);
     $newPart->setParentField($baseField);
     $newPart->setChildField($subField);
     $newPart->setJoinType($join);
     if (!$query->addPart($newPart, $basePart->getId())) {
         Response::jsonArray(array('success' => false, 'msg' => $this->_lang->CANT_EXEC));
     }
     $basePart->setFieldCfg($baseField, 'selectSub', true);
     $basePart->setFieldCfg($baseField, 'isLink', true);
     $this->_session->set('query', $query);
     Response::jsonSuccess();
 }
예제 #2
0
파일: Query.php 프로젝트: vgrish/dvelum
 protected function _addSqlPart(Db_Query_Part $part, $sql, Db_Query_Part $parenPart, $countOnly = false)
 {
     if ($countOnly) {
         $fields = array();
     } else {
         $fields = $this->_extractFields($part);
         if (empty($fields)) {
             return;
         }
     }
     $parentTable = Db_Object_Config::getInstance($parenPart->getObject())->getTable();
     $curTable = Db_Object_Config::getInstance($part->getObject())->getTable();
     $condition = '`' . $parentTable . '`.`' . $part->parentField . '` = `' . $curTable . '`.`' . $part->childField . '`';
     switch ($part->joinType) {
         case Db_Query_Part::JOIN_INNER:
             $sql->joinInner($curTable, $condition, $fields);
             break;
         case Db_Query_Part::JOIN_LEFT:
             $sql->joinLeft($curTable, $condition, $fields);
             break;
         case Db_Query_Part::JOIN_RIGHT:
             $sql->joinRight($curTable, $condition, $fields);
             break;
     }
 }