예제 #1
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);
     }
 }
예제 #2
0
 /**
  * Functions for massive check for link type
  * 
  * 
  */
 public static function getLinkStatusForMultipleNodes($nodeInfo = array(), $entityPrimary, $connectors = false)
 {
     $nodeInfo = Assert::expectArray($nodeInfo, '$nodeInfo');
     $entityPrimary = Assert::expectStringNotNull($entityPrimary, '$entityPrimary');
     $result = array();
     if (!static::checkLinkUsageAny($entityPrimary)) {
         foreach ($nodeInfo as $node) {
             $result[$node['ID']] = self::LSTAT_BELOW_CONNECTOR;
         }
         return $result;
     }
     if (!is_array($connectors)) {
         $connectors = static::getConnectedLocationsInfo($entityPrimary);
     }
     foreach ($nodeInfo as $node) {
         $node = Assert::expectNotEmptyArray($node, '$nodeInfo[]');
         $node['ID'] = Assert::expectIntegerPositive($node['ID'], '$nodeInfo[][ID]');
         $node['LEFT_MARGIN'] = Assert::expectIntegerNonNegative($node['LEFT_MARGIN'], '$nodeInfo[][LEFT_MARGIN]');
         $node['RIGHT_MARGIN'] = Assert::expectIntegerPositive($node['RIGHT_MARGIN'], '$nodeInfo[][RIGHT_MARGIN]');
         $result[$node['ID']] = false;
         foreach ($connectors as $connector) {
             if ($connector['ID'] == $node['ID']) {
                 $result[$node['ID']] = self::LSTAT_IS_CONNECTOR;
                 break;
             } elseif ($node['LEFT_MARGIN'] >= $connector['LEFT_MARGIN'] && $node['RIGHT_MARGIN'] <= $connector['RIGHT_MARGIN']) {
                 $result[$node['ID']] = self::LSTAT_BELOW_CONNECTOR;
                 break;
             } elseif ($node['LEFT_MARGIN'] <= $connector['LEFT_MARGIN'] && $node['RIGHT_MARGIN'] >= $connector['RIGHT_MARGIN']) {
                 $result[$node['ID']] = self::LSTAT_ABOVE_CONNECTOR;
                 break;
             }
         }
         if (!$result[$node['ID']]) {
             $result[$node['ID']] = self::LSTAT_IN_NOT_CONNECTED_BRANCH;
         }
     }
     return $result;
 }