Пример #1
0
 /**
  * @param string $plugin
  * @return CM_Janus_ServerList
  */
 public function filterByPlugin($plugin)
 {
     $plugin = (string) $plugin;
     $serverList = array_values(Functional\filter($this->_servers, function (CM_Janus_Server $server) use($plugin) {
         return in_array($plugin, $server->getPluginList());
     }));
     return new self($serverList);
 }
Пример #2
0
 /**
  * @param string|null $filterIndexName
  * @throws CM_Exception_Invalid
  * @return CM_Elasticsearch_Type_Abstract[]
  */
 protected function _getTypes($filterIndexName = null)
 {
     $types = CM_Service_Manager::getInstance()->getElasticsearch()->getTypes();
     if (null !== $filterIndexName) {
         $types = \Functional\filter($types, function (CM_Elasticsearch_Type_Abstract $type) use($filterIndexName) {
             return $type->getIndex()->getName() === $filterIndexName;
         });
         if (count($types) === 0) {
             throw new CM_Exception_Invalid('No type with such index name: ' . $filterIndexName);
         }
     }
     return $types;
 }
Пример #3
0
function smarty_function_location(array $params, Smarty_Internal_Template $template)
{
    /** @var CM_Model_Location $location */
    $location = $params['location'];
    /** @var CM_Model_Location|null $distanceFrom */
    $distanceFrom = isset($params['distanceFrom']) ? $location->getDistance($params['distanceFrom']) : null;
    /** @var Closure|null $partLabeler */
    $partLabeler = isset($params['partLabeler']) ? $params['partLabeler'] : null;
    /** @var Closure|null $flagLabeler */
    $flagLabeler = isset($params['flagLabeler']) ? $params['flagLabeler'] : null;
    /** @var CM_Frontend_Render $render */
    $render = $template->smarty->getTemplateVars('render');
    $levelList = [CM_Model_Location::LEVEL_CITY, CM_Model_Location::LEVEL_STATE, CM_Model_Location::LEVEL_COUNTRY];
    $partNameList = [];
    foreach ($levelList as $level) {
        if (null !== $location->getId($level)) {
            if (null !== $partLabeler) {
                $partNameList[] = $partLabeler($location->get($level), $location);
            } else {
                $partNameList[] = $location->getName($level);
            }
        }
    }
    $partNameList = Functional\filter($partNameList, function ($partName) {
        return !empty($partName);
    });
    $html = implode(', ', $partNameList);
    $flag = '';
    if (null !== $location->getId(CM_Model_Location::LEVEL_COUNTRY)) {
        if (null !== $flagLabeler) {
            $flag = $flagLabeler($location->get(CM_Model_Location::LEVEL_COUNTRY), $location);
        } else {
            $flag = smarty_function_locationFlag(array('location' => $location), $template);
        }
        if ('' !== $flag) {
            $html .= $flag;
        }
    }
    if (null !== $distanceFrom && $distanceFrom < 100 * 1000) {
        $distance = smarty_function_distance(array('distance' => $distanceFrom), $template);
        $distanceTitle = $render->getTranslation('Distance from your location:') . ' ' . $distance;
        $html .= '<small class="distance" title="' . $distanceTitle . '">' . $distance . '</small>';
    }
    return '<span class="function-location' . ('' !== $flag ? ' contains-flag' : '') . '">' . $html . '</span>';
}
Пример #4
0
 /**
  * @return array
  */
 private function _getEmoticonAdditionalCodesMapping()
 {
     $paging = new CM_Paging_Emoticon_All();
     $emoticonList = $paging->getItems();
     $filteredEmoticonList = \Functional\filter($emoticonList, function (CM_Emoticon $emoticon) {
         return count($emoticon->getCodes()) > 1;
     });
     $mapping = [];
     /** @var CM_Emoticon $emoticon */
     foreach ($filteredEmoticonList as $emoticon) {
         $codeList = $emoticon->getCodes();
         $defaultCode = $emoticon->getDefaultCode();
         foreach ($codeList as $code) {
             if ($code !== $defaultCode) {
                 $mapping[$code] = $defaultCode;
             }
         }
     }
     return $mapping;
 }