Author: sandip Language: php
Description: Not specified Timestamp: 2013-05-19 19:04:34 +0000
View raw paste Child paste by: qwerty Reply
  1. <?php
  2.  
  3. class SiteController extends Controller
  4. {
  5. /**
  6.  * Declares class-based actions.
  7.  */
  8. public function actions()
  9. {
  10.   return array(
  11.     // captcha action renders the CAPTCHA image displayed on the contact page
  12.     'captcha'=>array(
  13.       'class'=>'CCaptchaAction',
  14.       'backColor'=>0xFFFFFF,
  15.       ),
  16.     // page action renders "static" pages stored under 'protected/views/site/pages'
  17.     // They can be accessed via: index.php?r=site/page&view=FileName
  18.     'page'=>array(
  19.       'class'=>'CViewAction',
  20.       ),
  21.     );
  22. }
  23.  
  24. /**
  25.  * This is the default 'index' action that is invoked
  26.  * when an action is not explicitly requested by users.
  27.  */
  28. public function actionIndex()
  29.  
  30. {
  31.   $mongo = new Mongo('localhost');
  32.   $collection = $mongo->selectDB('listing')->selectCollection('doctors')->find();
  33.   echo "<pre>"; print_r($collection); exit("\n exited here \n");
  34.   $collection->ensureIndex(array('name'=>true));
  35.   $sp_cursor = $collection->group(
  36.     array('SPECIALITY'=>true),
  37.     array('count'=>0),
  38.     new MongoCode('function(doc,prev) {prev.count +1}'));
  39.   $city_cursor = $collection->group(
  40.     array('CCITY'=>true),
  41.     array('count'=>0),
  42.     new MongoCode('function(doc,prev) {prev.count +1}'));
  43.  
  44.  echo "<pre>";
  45.   print_r($sp_cursor);
  46. exit();
  47.  
  48.  
  49.  
  50.  
  51.  
  52.   $count_specialty = count($sp_cursor['retval']);
  53.   for ($i=0; $i <$count_specialty ; $i++) {
  54.     $sp[$i] = $sp_cursor['retval'][$i]['SPECIALITY'];
  55.   }
  56.   $count_city = count($city_cursor['retval']);
  57.   for ($i=0; $i <$count_city ; $i++) {
  58.     $city[$i] = $city_cursor['retval'][$i]['CCITY'];
  59.   }
  60.  
  61.   $this->render('index',array('speciality' => $sp , 'city' => $city ));
  62. }
  63.  
  64.  
  65.  
  66. public function actionIndexRef() {
  67.  
  68.   $term = $_POST['term'];
  69.  
  70.   $_GET['search'] = $term;
  71.   $_GET['searchField'] = "NAME";
  72.   if (isset($_GET['search']) && $_GET['searchField']) {
  73.     if (strpos($_GET['search'], '*') === false) {
  74.       if (!is_numeric($_GET['search'])) {
  75.         $find[$_GET['searchField']] = $_GET['search'];
  76.               } else { //$_GET is always a string-type
  77.                 $in = array((string) $_GET['search'], (int) $_GET['search'], (float) $_GET['search']);
  78.                 $find[$_GET['searchField']] = array('$in' => $in);
  79.               }
  80.           } else { //text with wildcards
  81.             $regex = '/' . str_replace('\*', '.*', preg_quote($_GET['search'])) . '/i';
  82.             $find['NAME'] = new mongoRegex($regex);
  83.           }
  84.         }
  85.  
  86.       // $cursor = $collection->find($find);
  87.  
  88.         $cursor = Yii::app()->mongodb->doctor->find($find);
  89.         $result = array();
  90.         if (!empty($cursor))
  91.           foreach ($cursor as $id => $value)
  92.             $result[] = $value;
  93.           echo json_encode($result);
  94.         }
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103. /**
  104.  * This is the action to handle external exceptions.
  105.  */
  106. public function actionError()
  107. {
  108.   if($error=Yii::app()->errorHandler->error)
  109.   {
  110.     if(Yii::app()->request->isAjaxRequest)
  111.       echo $error['message'];
  112.     else
  113.       $this->render('error', $error);
  114.   }
  115. }
  116.  
  117. /**
  118.  * Displays the contact page
  119.  */
  120. public function actionContact()
  121. {
  122.   $model=new ContactForm;
  123.   if(isset($_POST['ContactForm']))
  124.   {
  125.     $model->attributes=$_POST['ContactForm'];
  126.     if($model->validate())
  127.     {
  128.       $name='=?UTF-8?B?'.base64_encode($model->name).'?=';
  129.       $subject='=?UTF-8?B?'.base64_encode($model->subject).'?=';
  130.       $headers="From: $name <{$model->email}>\r\n".
  131.       "Reply-To: {$model->email}\r\n".
  132.       "MIME-Version: 1.0\r\n".
  133.       "Content-type: text/plain; charset=UTF-8";
  134.  
  135.       mail(Yii::app()->params['adminEmail'],$subject,$model->body,$headers);
  136.       Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
  137.       $this->refresh();
  138.     }
  139.   }
  140.   $this->render('contact',array('model'=>$model));
  141. }
  142.  
  143. /**
  144.  * Displays the login page
  145.  */
  146. public function actionLogin()
  147. {
  148.   $model=new LoginForm;
  149.  
  150.   // if it is ajax validation request
  151.   if(isset($_POST['ajax']) && $_POST['ajax']==='login-form')
  152.   {
  153.     echo CActiveForm::validate($model);
  154.     Yii::app()->end();
  155.   }
  156.  
  157.   // collect user input data
  158.   if(isset($_POST['LoginForm']))
  159.   {
  160.     $model->attributes=$_POST['LoginForm'];
  161.     // validate user input and redirect to the previous page if valid
  162.     if($model->validate() && $model->login())
  163.       $this->redirect(Yii::app()->user->returnUrl);
  164.   }
  165.   // display the login form
  166.   $this->render('login',array('model'=>$model));
  167. }
  168.  
  169. /**
  170.  * Logs out the current user and redirect to homepage.
  171.  */
  172. public function actionLogout()
  173. {
  174.   Yii::app()->user->logout();
  175.   $this->redirect(Yii::app()->homeUrl);
  176. }
  177. }
  178.  
View raw paste Child paste by: qwerty Reply