예제 #1
0
 public static function checkNodeIsParentOfNode($primary, $childPrimary, $behaviour = array('ACCEPT_CODE' => false, 'CHECK_DIRECT' => false))
 {
     if (!$behaviour['ACCEPT_CODE']) {
         return static::checkNodeIsParentOfNodeById($primary, $childPrimary, $behaviour);
     }
     $primary = Assert::expectStringNotNull($primary, '$primary');
     $childPrimary = Assert::expectStringNotNull($childPrimary, '$childPrimary');
     return static::checkNodeIsParentOfNodeByFilters(array('=CODE' => $primary), array('=CODE' => $childPrimary), $behaviour);
 }
예제 #2
0
 private static function checkSiteId($siteId)
 {
     $siteId = Assert::expectStringNotNull($siteId, '$siteId');
     $res = Main\SiteTable::getList(array('filter' => array('LID' => $siteId)))->fetch();
     if (!$res) {
         throw new Main\ArgumentOutOfRangeException(Loc::getMessage('SALE_LOCATION_DEFAULTSITE_ENTITY_SITE_ID_UNKNOWN_EXCEPTION'));
     }
     return $siteId;
 }
예제 #3
0
 /**
  * 
  * $parameters is an ORM`s getList compatible array of parameters
  * 
  * 
  */
 public static function find($parameters, $behaviour = array('FALLBACK_TO_NOINDEX_ON_NOTFOUND' => true, 'USE_INDEX' => true, 'USE_ORM' => true))
 {
     /////////////////////////////////
     // parameter check and process
     Assert::expectArray($parameters, '$parameters');
     if (!is_array($behaviour)) {
         $behaviour = array();
     }
     if (!isset($behaviour['FALLBACK_TO_NOINDEX_ON_NOTFOUND'])) {
         $behaviour['FALLBACK_TO_NOINDEX_ON_NOTFOUND'] = true;
     }
     if (!isset($behaviour['USE_INDEX'])) {
         $behaviour['USE_INDEX'] = true;
     }
     if (!isset($behaviour['USE_ORM'])) {
         $behaviour['USE_ORM'] = true;
     }
     if (!isset($parameters['select'])) {
         $parameters['select'] = array('ID');
     }
     Assert::expectArray($parameters['select'], '$parameters[select]');
     if (isset($parameters['filter'])) {
         Assert::expectArray($parameters['filter'], '$parameters[filter]');
         // spikes, refactor later
         if (isset($parameters['filter']['PHRASE']) || isset($parameters['filter']['=PHRASE'])) {
             $key = isset($parameters['filter']['PHRASE']) ? 'PHRASE' : '=PHRASE';
             $parameters['filter'][$key] = Assert::expectStringNotNull($parameters['filter'][$key], '$parameters[filter][' . $key . ']');
             $parameters['filter'][$key] = str_replace('%', '', $parameters['filter'][$key]);
             // cannot pass '%' to like
         }
         if (isset($parameters['filter']['SITE_ID']) || isset($parameters['filter']['=SITE_ID'])) {
             $key = isset($parameters['filter']['SITE_ID']) ? 'SITE_ID' : '=SITE_ID';
             $parameters['filter'][$key] = Assert::expectStringNotNull($parameters['filter'][$key], '$parameters[filter][' . $key . ']');
             // stronger here
             if (!Location\SiteLocationTable::checkLinkUsageAny($parameters['filter'][$key])) {
                 unset($parameters['filter'][$key]);
             }
         }
     }
     if (isset($parameters['limit'])) {
         $parameters['limit'] = Assert::expectIntegerNonNegative($parameters['limit'], '$parameters[limit]');
     }
     if (isset($parameters['offset'])) {
         $parameters['offset'] = Assert::expectIntegerNonNegative($parameters['offset'], '$parameters[offset]');
     }
     /////////////////////////////////
     if (isset($parameters['filter']['PHRASE']) || isset($parameters['filter']['SITE_ID']) || isset($parameters['filter']['=PHRASE']) || isset($parameters['filter']['=SITE_ID']) || $behaviour['USE_ORM'] === false) {
         if (static::checkIndexValid() && $behaviour['USE_INDEX']) {
             $result = static::findUsingIndex($parameters);
             if (!$behaviour['FALLBACK_TO_NOINDEX_ON_NOTFOUND']) {
                 return $result;
             } else {
                 $temporalBuffer = array();
                 while ($item = $result->fetch()) {
                     $temporalBuffer[] = $item;
                 }
                 if (empty($temporalBuffer)) {
                     return static::findNoIndex($parameters);
                 } else {
                     return new DB\ArrayResult($temporalBuffer);
                 }
             }
         } else {
             return static::findNoIndex($parameters);
         }
     } else {
         return Location\LocationTable::getList($parameters);
     }
 }
예제 #4
0
 public static function mergeRelationsFromTemporalTable($temporalTabName, $additinalFlds = array(), $fldMap = array())
 {
     $dbConnection = Main\HttpApplication::getConnection();
     $dbHelper = $dbConnection->getSqlHelper();
     $temporalTabName = Assert::expectStringNotNull($temporalTabName, false, 'Name of temporal table must be a non-zero length string');
     $temporalTabName = $dbHelper->forSql($temporalTabName);
     $entityTableName = static::getTableName();
     if (!is_array($additinalFlds)) {
         $additinalFlds = array();
     }
     $additinalFlds = array_merge(array('LEFT_MARGIN', 'RIGHT_MARGIN', 'DEPTH_LEVEL'), $additinalFlds);
     $fldReplace = array();
     foreach ($additinalFlds as &$fld) {
         $fld = $dbHelper->forSql($fld);
         $fldReplace[$fld] = is_array($fldMap) && isset($fldMap[$fld]) ? $dbHelper->forSql($fldMap[$fld]) : $fld;
     }
     $idReplace = is_array($fldMap) && isset($fldMap['ID']) ? $dbHelper->forSql($fldMap['ID']) : 'ID';
     if ($dbConnection->getType() == 'mysql') {
         $sql = 'update ' . $entityTableName . ', ' . $temporalTabName . ' set ';
         $additFldCnt = count($additinalFlds);
         for ($i = 0; $i < $additFldCnt; $i++) {
             $sql .= $entityTableName . '.' . $additinalFlds[$i] . ' = ' . $temporalTabName . '.' . $fldReplace[$additinalFlds[$i]] . ($i == count($additinalFlds) - 1 ? '' : ', ');
         }
         $sql .= ' where ' . $entityTableName . '.ID = ' . $temporalTabName . '.' . $idReplace;
     } elseif ($dbConnection->getType() == 'mssql') {
         $sql = 'update ' . $entityTableName . ' set ';
         $additFldCnt = count($additinalFlds);
         for ($i = 0; $i < $additFldCnt; $i++) {
             $sql .= $additinalFlds[$i] . ' = ' . $temporalTabName . '.' . $fldReplace[$additinalFlds[$i]] . ($i == count($additinalFlds) - 1 ? '' : ', ');
         }
         $sql .= ' from ' . $entityTableName . ' join ' . $temporalTabName . ' on ' . $entityTableName . '.ID = ' . $temporalTabName . '.' . $idReplace;
     } elseif ($dbConnection->getType() == 'oracle') {
         // update tab1 set (aa,bb) = (select aa,bb from tab2 where tab2.id = tab1.id)
         $sql = 'update ' . $entityTableName . ' set (' . implode(', ', $additinalFlds) . ') = (select ' . implode(', ', $fldReplace) . ' from ' . $temporalTabName . ' where ' . $entityTableName . '.ID = ' . $temporalTabName . '.' . $idReplace . ')';
     }
     $dbConnection->query($sql);
 }
예제 #5
0
 /**
  * Check if there is a link between entity and locations, optionally of a certain type (default: locations)
  *
  * @param mixed $entityPrimary primary key for an entity
  * @param string $linkType link type (G or L (default))
  *
  * @throws ArgumentNullException
  *
  * @return boolean
  */
 public static function checkLinkUsage($entityPrimary, $linkType = self::DB_LOCATION_FLAG)
 {
     $entityPrimary = Assert::expectStringNotNull($entityPrimary, '$entityPrimary');
     $linkType = Assert::expectEnumerationMember($linkType, array(self::DB_LOCATION_FLAG, self::DB_GROUP_FLAG), '$linkType');
     if (!static::getUseLinkTracking()) {
         return true;
     }
     // force to true if link tracking is off
     $useGroups = static::getUseGroups();
     if (!$useGroups && $linkType == self::DB_GROUP_FLAG) {
         return false;
     }
     // we know we dont use groups
     $usageFlags = static::getLinkUsageOptionValue();
     if (isset($usageFlags[$entityPrimary][$linkType])) {
         return $usageFlags[$entityPrimary][$linkType];
     }
     $strictFilter = array(static::getLinkField() => $entityPrimary);
     if ($useGroups) {
         $strictFilter['LOCATION_TYPE'] = self::DB_LOCATION_FLAG;
     }
     $usageFlags[$entityPrimary][self::DB_LOCATION_FLAG] = !!static::getList(array('limit' => 1, 'filter' => $strictFilter))->fetch();
     if ($useGroups) {
         $usageFlags[$entityPrimary][self::DB_GROUP_FLAG] = !!static::getList(array('limit' => 1, 'filter' => array(static::getLinkField() => $entityPrimary, 'LOCATION_TYPE' => self::DB_GROUP_FLAG)))->fetch();
     }
     static::setLinkUsageOptionValue($usageFlags);
     return $usageFlags[$entityPrimary];
 }