예제 #1
0
 /**
  * Function returns the Query for the relationhips
  * @param <Vtiger_Record_Model> $recordModel
  * @param type $actions
  * @return <String>
  */
 public function getQuery($recordModel, $actions = false)
 {
     $parentModuleModel = $this->getParentModuleModel();
     $relatedModuleModel = $this->getRelationModuleModel();
     $relatedModuleName = $relatedModuleModel->get('name');
     $parentModuleName = $parentModuleModel->get('name');
     $functionName = $this->get('name');
     $focus = CRMEntity::getInstance($parentModuleName);
     $focus->id = $recordModel->getId();
     if (method_exists($parentModuleModel, $functionName)) {
         $query = $parentModuleModel->{$functionName}($recordModel, $relatedModuleModel);
     } else {
         $result = $focus->{$functionName}($recordModel->getId(), $parentModuleModel->getId(), $relatedModuleModel->getId(), $actions);
         $query = $result['query'];
     }
     //modify query if any module has summary fields, those fields we are displayed in related list of that module
     $relatedListFields = $relatedModuleModel->getConfigureRelatedListFields();
     if (count($relatedListFields) > 0) {
         $currentUser = Users_Record_Model::getCurrentUserModel();
         $queryGenerator = new QueryGenerator($relatedModuleName, $currentUser);
         $queryGenerator->setFields($relatedListFields);
         $selectColumnSql = $queryGenerator->getSelectClauseColumnSQL();
         $newQuery = spliti('FROM', $query);
         $selectColumnSql = 'SELECT DISTINCT vtiger_crmentity.crmid,' . $selectColumnSql;
     }
     if ($functionName == ('get_pricebook_products' || 'get_pricebook_services')) {
         $selectColumnSql = $selectColumnSql . ', vtiger_pricebookproductrel.listprice';
     }
     $query = $selectColumnSql . ' FROM ' . $newQuery[1];
     return $query;
 }
예제 #2
0
    /**
     * Function returns query for PriceBooks-Services Relationship
     * @param <Vtiger_Record_Model> $recordModel
     * @param <Vtiger_Record_Model> $relatedModuleModel
     * @return <String>
     */
    function get_pricebook_services($recordModel, $relatedModuleModel)
    {
        $query = 'SELECT vtiger_service.serviceid, vtiger_service.servicename, vtiger_service.commissionrate,
					vtiger_service.qty_per_unit, vtiger_service.unit_price, vtiger_crmentity.crmid, vtiger_crmentity.smownerid,
					vtiger_pricebookproductrel.listprice
			FROM vtiger_service
			INNER JOIN vtiger_pricebookproductrel on vtiger_service.serviceid = vtiger_pricebookproductrel.productid
			INNER JOIN vtiger_crmentity on vtiger_crmentity.crmid = vtiger_service.serviceid
			INNER JOIN vtiger_pricebook on vtiger_pricebook.pricebookid = vtiger_pricebookproductrel.pricebookid
			LEFT JOIN vtiger_users ON vtiger_users.id=vtiger_crmentity.smownerid
			LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid ' . Users_Privileges_Model::getNonAdminAccessControlQuery($relatedModuleModel->getName()) . '
			WHERE vtiger_pricebook.pricebookid = ' . $recordModel->getId() . ' and vtiger_crmentity.deleted = 0';
        return $query;
    }
예제 #3
0
 /**
  * Function returns the Query for the relationhips
  * @param <Vtiger_Record_Model> $recordModel
  * @param type $actions
  * @return <String>
  */
 public function getQuery($recordModel, $actions = false)
 {
     $parentModuleModel = $this->getParentModuleModel();
     $relatedModuleModel = $this->getRelationModuleModel();
     $parentModuleName = $parentModuleModel->get('name');
     $functionName = $this->get('name');
     $focus = CRMEntity::getInstance($parentModuleName);
     $focus->id = $recordModel->getId();
     if (method_exists($parentModuleModel, $functionName)) {
         $query = $parentModuleModel->{$functionName}($recordModel, $relatedModuleModel);
         return $query;
     } else {
         $result = $focus->{$functionName}($recordModel->getId(), $parentModuleModel->getId(), $relatedModuleModel->getId(), $actions);
     }
     return $result['query'];
 }
예제 #4
0
 /**
  * Function returns the Query for the relationhips
  * @param <Vtiger_Record_Model> $recordModel
  * @param type $actions
  * @return <String>
  */
 public function getQuery($recordModel, $actions = false, $relationListView_Model = false)
 {
     $parentModuleModel = $this->getParentModuleModel();
     $relatedModuleModel = $this->getRelationModuleModel();
     $relatedModuleName = $relatedModuleModel->get('name');
     $parentModuleName = $parentModuleModel->get('name');
     $functionName = $this->get('name');
     $focus = CRMEntity::getInstance($parentModuleName);
     $focus->id = $recordModel->getId();
     if (method_exists($parentModuleModel, $functionName)) {
         $query = $parentModuleModel->{$functionName}($recordModel, $relatedModuleModel);
     } else {
         $result = $focus->{$functionName}($recordModel->getId(), $parentModuleModel->getId(), $relatedModuleModel->getId(), $actions);
         $query = $result['query'];
     }
     //modify query if any module has summary fields, those fields we are displayed in related list of that module
     $relatedListFields = $this->getRelationFields(true, true);
     if (count($relatedListFields) == 0) {
         $relatedListFields = $relatedModuleModel->getConfigureRelatedListFields();
     }
     if (count($relatedListFields) > 0) {
         $currentUser = Users_Record_Model::getCurrentUserModel();
         $queryGenerator = new QueryGenerator($relatedModuleName, $currentUser);
         $queryGenerator->setFields($relatedListFields);
         $selectColumnSql = $queryGenerator->getSelectClauseColumnSQL();
         $newQuery = explode('FROM', $query);
         $selectColumnSql = 'SELECT DISTINCT vtiger_crmentity.crmid, ' . $selectColumnSql;
     }
     if ($functionName == 'get_product_pricebooks') {
         $selectColumnSql = $selectColumnSql . ' ,vtiger_pricebookproductrel.listprice, vtiger_pricebook.currency_id, vtiger_products.unit_price';
     }
     if ($functionName == 'get_service_pricebooks') {
         $selectColumnSql = $selectColumnSql . ' ,vtiger_pricebookproductrel.listprice, vtiger_pricebook.currency_id, vtiger_service.unit_price';
     }
     if ($selectColumnSql && $newQuery[1]) {
         $query = $selectColumnSql . ' FROM ' . $newQuery[1];
     }
     if ($relationListView_Model) {
         $searchParams = $relationListView_Model->get('search_params');
         $this->addSearchConditions($query, $searchParams, $relatedModuleName);
     }
     return $query;
 }
예제 #5
0
    /**
     * Function returns query for Product-PriceBooks relation
     * @param <Vtiger_Record_Model> $recordModel
     * @param <Vtiger_Record_Model> $relatedModuleModel
     * @return <String>
     */
    function get_product_pricebooks($recordModel, $relatedModuleModel)
    {
        $query = 'SELECT vtiger_pricebook.pricebookid, vtiger_pricebook.bookname, vtiger_pricebook.active, vtiger_crmentity.crmid, 
						vtiger_crmentity.smownerid, vtiger_pricebookproductrel.listprice, vtiger_products.unit_price
					FROM vtiger_pricebook
					INNER JOIN vtiger_pricebookproductrel ON vtiger_pricebook.pricebookid = vtiger_pricebookproductrel.pricebookid
					INNER JOIN vtiger_crmentity on vtiger_crmentity.crmid = vtiger_pricebook.pricebookid
					INNER JOIN vtiger_products on vtiger_products.productid = vtiger_pricebookproductrel.productid
					INNER JOIN vtiger_pricebookcf on vtiger_pricebookcf.pricebookid = vtiger_pricebook.pricebookid
					LEFT JOIN vtiger_users ON vtiger_users.id=vtiger_crmentity.smownerid
					LEFT JOIN vtiger_groups ON vtiger_groups.groupid = vtiger_crmentity.smownerid ' . Users_Privileges_Model::getNonAdminAccessControlQuery($relatedModuleModel->getName()) . '
					WHERE vtiger_products.productid = ' . $recordModel->getId() . ' and vtiger_crmentity.deleted = 0';
        return $query;
    }
예제 #6
0
 /**
  * Function to retieve the instance from record model
  * @param <Vtiger_Record_Model> $recordModel - record instance
  * @return Vtiger_RecordStructure_Model
  */
 public static function getInstanceFromRecordModel($recordModel, $mode = self::RECORD_STRUCTURE_MODE_DEFAULT)
 {
     $moduleModel = $recordModel->getModule();
     $className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->getName(true));
     $instance = new $className();
     $instance->setModule($moduleModel)->setRecord($recordModel);
     return $instance;
 }
예제 #7
0
 /**
  * Function to retieve the instance from record model
  * @param <Vtiger_Record_Model> $recordModel - record instance
  * @return Vtiger_RecordStructure_Model
  */
 public static function getInstanceFromRecordModel($recordModel, $mode = self::RECORD_STRUCTURE_MODE_DEFAULT)
 {
     global $log;
     $log->debug("Entering ./models/RecordStructure.php::staticgetInstanceFromRecordModel");
     $moduleModel = $recordModel->getModule();
     $className = Vtiger_Loader::getComponentClassName('Model', $mode . 'RecordStructure', $moduleModel->getName(true));
     $instance = new $className();
     $instance->setModule($moduleModel)->setRecord($recordModel);
     return $instance;
 }