'', 'tag' => '', ]; protected $_tagTypeArray = array( 'geo' => array(self::NODE_TYPE_LOCALITY, self::NODE_TYPE_NEIGHBORHOOD, self::NODE_TYPE_STREET) ); public static function tableName() { return 'nodeRecommendLinkV'; } public function getGroups($id) { $query = static::createQuery() ->from([self::tableName() . ' nrl']) ->select(['t.internalTypeId', 't.typeCode', 't.typeName']) ->innerJoin('tagV t', '`nrl`.`srcNodeId` = `t`.`id`') ->where(['nrl.dstNodeId' => $id]) ->andWhere('t.geoRoot = 1') ->groupBy('t.typeCode') ->orderBy('t.typeName') ; return $query->createCommand()->queryAll(); } public function getBaseQuery($id, $internalTypeId) { $query = static::createQuery() ->from([self::tableName() . ' nrl']) ->select(['t.id', 't.name', 't.typeCode', 't.typeName']) ->innerJoin('tagV t', '`nrl`.`srcNodeId` = `t`.`id`') ->where(['nrl.dstNodeId' => $id, 't.geoRoot' => 1, 't.internalTypeId' => $internalTypeId]) ->orderBy('`nrl`.`dstMetric` ASC, `nrl`.`srcMetric` ASC') ; return $query; } /** * Returns list of typeName`s for recommended geo tags * @param int $id objectId * * @return array */ public function getRootGetTagTypeNames($id) { $query = $this->getBaseQuery($id, 'tag'); $query->select(['t.typeName']); $query->groupBy('t.typeName'); return $query->createCommand()->queryAll(PDO::FETCH_COLUMN); } /** * * Returns recommendations for root get tags * * @param int $id objectId * * @return array */ public function getRootGeoTags($id) { return $this->getBaseQuery($id, 'tag'); } /** * Returns recommendations for root get attributes * * @param int $id objectId * * @return array */ public function getRootGeoAttributes($id) { $query = $this->getBaseQuery($id, 'attribute'); $query->select[] = 't.attributeDataType dataType'; $query->select[] = 't.required'; $query->select[] = 't.uofmPre'; $query->select[] = 't.uofmPost'; $query->select[] = 'a.decimalMin'; $query->select[] = 'a.decimalMax'; $query->select[] = 'a.decimalRound'; $query->select[] = 'a.textIsLong'; $query->select[] = 'adf.name AS datetimeName'; $query->select[] = 'adf.outputFormatJs AS datetimeOutputFormatJs'; $query->leftJoin('attributeV AS a', 'a.id = t.id AND t.internalTypeId = "attribute"'); $query->leftJoin('attributeDatetimeFormatV AS adf', 'a.datetimeStorageId IS NOT NULL AND adf.id = a.datetimeStorageId'); return $query->createCommand()->queryAll(); } public function getRecommendedLinks($id, $prefix, $type = null, $essential = null) { $query = static::createQuery() ->from(array(self::tableName() . ' nrl')) ->select(array('sTagV.id', 'sTagV.typeCode', 'sTagV.name')) ->join('INNER JOIN', 'tagV sTagV', '`nrl`.`srcNodeId` = `sTagV`.`id`') ->where(array('nrl.dstNodeId' => $id)) ->andWhere('`sTagV`.`name` LIKE "%' . $prefix. '%"') // fixme: sql injection ; if ($type === 'geo') { $query->andWhere('sTagV.geoRoot = 1'); } //$query->orderBy('`nrl`.`dstMetric` ASC, `nrl`.`srcMetric` ASC'); $query->orderBy('sTagV.name'); return $query->createCommand()->queryAll(); } public function getRecommendAmenitySubmissionTag($id) { $list = $this->getRecommendAmenitySubmissionTagList($id); return Ticket::groupTagsByType($list); } public function getRecommendAmenitySubmissionTagList($id) { $query = static::createQuery() ->from(array('nodeRecommendLinkV nrl')) ->select(array('t.id', 't.typeCode', 't.typeName', 't.name')) ->join('INNER JOIN', 'tagV t', '`nrl`.`srcNodeId` = `t`.`id`') ->join('INNER JOIN', 'nodeRootLinkV nr', '`nr`.`dstNodeId` = `t`.`id`') ->where(array('nrl.dstNodeId' => $id)) ->andWhere('nr.typeCode IN ("rootamenity", "rootsubmission")') ->orderBy('`t`.`typeSorter`, `t`.`sorter`') ->groupBy('t.id') ; return $query->createCommand()->queryAll(); } }