Wednesday, September 16, 2015

Yii EGMap color change

Add 'style' => '['.EGMap::MAPTYPECONTROL_STYLE_HORIZONTAL_BAR.', "map_style"]', in view page
$gMap = new EGMap();
$gMap->setWidth('auto');
$gMap->setHeight(500);
$gMap->zoom = 11;

$mapTypeControlOptions = array(
  'position' => EGMapControlPosition::RIGHT_TOP,
  'style' => '['.EGMap::MAPTYPECONTROL_STYLE_HORIZONTAL_BAR.', "map_style"]',
);

Replace this code in EGMap.php
public function registerMapScript($afterInit=array(), $language = null, $region = 'bd', $position = CClientScript::POS_LOAD)
 {
  // TODO: include support in the future
  $params = 'sensor=false';
                $params .= '&libraries=places';
  if ($language !== null)
   $params .= '&language=' . $language;
  if ($region !== null)
   $params .= '& region=' . $region;

  CGoogleApi::init();
  CGoogleApi::register('maps', '3', array('other_params' => $params));

  $this->registerPlugins();

  $js = '';

  $init_events = array();
  if (null !== $this->_appendTo)
  {
   $init_events[] = "$('{$this->getContainer()}').appendTo('{$this->_appendTo}');" . PHP_EOL;
  }
// this for color change
                $style_array_here="[
    { featureType: 'landscape', 
        elementType: 'all',
        stylers: [ { hue: '#fad99d' }, { saturation: 87 }, { lightness: -10 }, { visibility: 'on' } ] },{ featureType: 'water', elementType: 'all', stylers: [ { hue: '#fad99d' }, { saturation: 82 }, { lightness: 16 }, { visibility: 'on' } ] } ];
var styledMap = new google.maps.StyledMapType(styles,
    {name: 'Styled Map'})        
";
                $init_events[] = 'var styles = '.$this->encode($style_array_here).';' . PHP_EOL;
  $init_events[] = 'var mapOptions = ' . $this->encode($this->options) . ';' . PHP_EOL;
  $init_events[] = 'var '.$this->getJsName() . ' = new google.maps.Map(document.getElementById("' . $this->getContainerId() . '"), mapOptions); '.$this->getJsName().'.mapTypes.set("map_style", styledMap); '.$this->getJsName().'.setMapTypeId("map_style");' . PHP_EOL;


  // add some more events
  $init_events[] = $this->getEventsJs();
  $init_events[] = $this->getMarkersJs();
  $init_events[] = $this->getDirectionsJs();
  $init_events[] = $this->getPluginsJs();
  $init_events[] = $this->getPolygonsJs();
  $init_events[] = $this->getCirclesJs();
  $init_events[] = $this->getRectanglesJs();
              
              

  if (is_array($afterInit))
  {
   foreach ($afterInit as $ainit)
    $init_events[] = $ainit;
  }
  if ($this->getGlobalVariable($this->getJsName() . '_info_window'))
   $init_events[] = $this->getJsName() . '_info_window=new google.maps.InfoWindow();';
  if ($this->getGlobalVariable($this->getJsName() . '_info_box') && $this->resources->itemAt('infobox_config'))
   $init_events[] = $this->getJsName (). '_info_box=new InfoBox('.
    $this->resources->itemAt('infobox_config').');';
  
  // declare the Google Map Javascript object as global
  $this->addGlobalVariable($this->getJsName(), 'null');

  $js = $this->getGlobalVariables();

  Yii::app()->getClientScript()->registerScript('EGMap_' . $this->getJsName(), $js, CClientScript::POS_HEAD);

  $js = 'function ' . $this->_containerId . '_init(){' . PHP_EOL;
  foreach ($init_events as $init_event)
  {
   if ($init_event)
   {
    $js .= $init_event . PHP_EOL;
   }
  }
  $js .= '
     } google.maps.event.addDomListener(window, "load",' . PHP_EOL . $this->_containerId . '_init);' . PHP_EOL;

  Yii::app()->getClientScript()->registerScript($this->_containerId . time(), $js, CClientScript::POS_END);
 }

Tuesday, September 15, 2015

yii Select2 replacement for select boxes

       Yii::import('ext.select2.Select2');
            $data = CHtml::listData(Judge::model()->findAll(),'name', 'name');
            echo Select2::multiSelect('judge', $model->judge, $data, array(
                'required' => 'required',
                'style' => 'width: 237px;',
                'placeholder' => 'Judge Name',
                'select2Options' => array('maximumSelectionSize' => 1,),
            ));

Wednesday, September 9, 2015

Add width, height and others attribute for image and link


echo CHtml::link(CHtml::image(Yii::app()->baseUrl."/uploads/promotion/".$promotion->image,$promotion->description,array('class'=>'promotion', 'title'=>$promotion->description)), "$promotion->url", array('target'=>'_self','class'=>'promotion'));


echo CHtml::image(Yii::app()->request->baseUrl.'/img/image.png', 'this is alt tag of image', array('width'=>'100px','height'=>'100px','title'=>'image title here'));

Sunday, September 6, 2015

Limit Content Length in Yii


public function getPagesummary($id=null){

        $model= Model::model()->findByPk($id);

        $wordlimit= strip_tags($model->details);
        if (str_word_count($wordlimit, 0) > 40) {
            $words = str_word_count($wordlimit, 2);
            $pos = array_keys($words);
            $textt = substr($wordlimit, 0, $pos[40]) . '...';

            return $textt;
        }
       else

    return $wordlimit;

    }

public function limitWords($id, $limit=50) {
 $model= Model::model()->findByPk($id);
$text= strip_tags($model->details);

    $word_arr = explode(" ", $text);

    if (count($word_arr) > $limit) {
        $words = implode(" ", array_slice($word_arr , 0, $limit) ) . ' ...';
        return $words;
    }

    return $text;
}


$model->getPagesummary($model->id)

$model->limitWords($model->id)

yii Get The First Image From a Post

    public function catch_that_image($str){

        $output = preg_match_all('/]+src=[\'"]([^\'"]+)[\'"][^>]*>/i', $str, $matches);
        return $matches[1][0];

    }

$recentnew->catch_that_image($recentnew->details);