Advertisement
Guest User

Untitled

a guest
Apr 18th, 2014
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.71 KB | None | 0 0
  1. <?php
  2.  
  3. class CommentController extends Controller
  4. {
  5.  
  6. // Added this code.
  7. /**
  8. * @var private property containing the associated Project model instance.
  9. */
  10. private $_add = null;
  11. /**
  12. * @var string the default layout for the views. Defaults to '//layouts/column2', meaning
  13. * using two-column layout. See 'protected/views/layouts/column2.php'.
  14. */
  15. public $layout='//layouts/column2';
  16. /**
  17. * Protected method to load the associated add model class
  18. * @add_id the primary identifier of the associated add
  19. * @return object the Add data model based on the primary key
  20. */
  21. protected function loadAdd($add_id)
  22. {
  23. //if the add property is null, create it based on input id
  24. if($this->_add===null)
  25. {
  26. $this->_add=Add::model()->findbyPk($add_id);
  27. if($this->_add===null)
  28. {
  29. throw new CHttpException(404,'The requested ADD does not exist.');
  30. }
  31. }
  32. return $this->_add;
  33. }
  34.  
  35. /**
  36. * In-class defined filter method, configured for use in the above filters() method
  37. * It is called before the actionCreate() action method is run in order to ensure a proper project context
  38. */
  39. /**
  40. * added Filter class to project to filter the add so user can select * valid projects and process its issues
  41. */
  42. public function filteraddContext($filterChain)
  43. {
  44. //set the project identifier based on either the GET or POST input
  45. //request variables, since we allow both types for our actions
  46. $addId = null;
  47. if(isset($_GET['pid']))
  48. $addId = $_GET['pid'];
  49. else
  50. if(isset($_POST['pid']))
  51. $addId = $_POST['pid'];
  52. $this->loadAdd($addId);
  53. //complete the running of other filters and execute the requested action
  54. $filterChain->run();
  55. }
  56.  
  57.  
  58.  
  59. /**
  60. * @return array action filters
  61. */
  62. public function filters()
  63. {
  64. return array(
  65. 'accessControl', // perform access control for CRUD operations
  66. 'postOnly + delete', // we only allow deletion via POST request
  67. //I Faisal Added following filter
  68. 'addContext + create index admin', //check to ensure valid project context
  69. );
  70. }
  71.  
  72.  
  73. /**
  74. * Specifies the access control rules.
  75. * This method is used by the 'accessControl' filter.
  76. * @return array access control rules
  77. */
  78. public function accessRules()
  79. {
  80. return array(
  81. array('allow', // allow all users to perform 'index' and 'view' actions
  82. 'actions'=>array('index','view'),
  83. 'users'=>array('*'),
  84. ),
  85. array('allow', // allow authenticated user to perform 'create' and 'update' actions
  86. 'actions'=>array('create','update'),
  87. 'users'=>array('@'),
  88. ),
  89. array('allow', // allow admin user to perform 'admin' and 'delete' actions
  90. 'actions'=>array('admin','delete'),
  91. 'users'=>array('admin'),
  92. ),
  93. array('deny', // deny all users
  94. 'users'=>array('*'),
  95. ),
  96. );
  97. }
  98.  
  99. /**
  100. * Displays a particular model.
  101. * @param integer $id the ID of the model to be displayed
  102. */
  103. public function actionView($id)
  104. {
  105. $this->render('view',array(
  106. 'model'=>$this->loadModel($id),
  107. ));
  108. }
  109.  
  110. /**
  111. * Creates a new model.
  112. * If creation is successful, the browser will be redirected to the 'view' page.
  113. */
  114. public function actionCreate()
  115. {
  116. $model=new Comment;
  117. //I Faisal Added the project model property for the above instance of issue to assign for the perticular project
  118. $model->add_id = $this->_add->addid;
  119.  
  120. // Uncomment the following line if AJAX validation is needed
  121. // $this->performAjaxValidation($model);
  122.  
  123. if(isset($_POST['Comment']))
  124. {
  125. $model->attributes=$_POST['Comment'];
  126. $model->user_name=Yii::app()->user->name;
  127. $model->create_time=date("d m y G:i:s ");
  128. if($model->save())
  129. $this->redirect(array('view','id'=>$model->cid));
  130. }
  131.  
  132. $this->render('create',array(
  133. 'model'=>$model,
  134. ));
  135. }
  136.  
  137. /**
  138. * Updates a particular model.
  139. * If update is successful, the browser will be redirected to the 'view' page.
  140. * @param integer $id the ID of the model to be updated
  141. */
  142. public function actionUpdate($id)
  143. {
  144. $model=$this->loadModel($id);
  145.  
  146. // Uncomment the following line if AJAX validation is needed
  147. // $this->performAjaxValidation($model);
  148.  
  149. if(isset($_POST['Comment']))
  150. {
  151. $model->attributes=$_POST['Comment'];
  152. if($model->save())
  153. $this->redirect(array('view','id'=>$model->cid));
  154. }
  155.  
  156. $this->render('update',array(
  157. 'model'=>$model,
  158. ));
  159. }
  160.  
  161. /**
  162. * Deletes a particular model.
  163. * If deletion is successful, the browser will be redirected to the 'admin' page.
  164. * @param integer $id the ID of the model to be deleted
  165. */
  166. public function actionDelete($id)
  167. {
  168. $this->loadModel($id)->delete();
  169.  
  170. // if AJAX request (triggered by deletion via admin grid view), we should not redirect the browser
  171. if(!isset($_GET['ajax']))
  172. $this->redirect(isset($_POST['returnUrl']) ? $_POST['returnUrl'] : array('admin'));
  173. }
  174.  
  175. /**
  176. * Lists all models.
  177. */
  178. public function actionIndex()
  179. {
  180. /* added to only get comment for a particular add only*/
  181. $dataProvider=new CActiveDataProvider('Comment', array(
  182. 'criteria'=>array(
  183. 'condition'=>'add_id=:addId',
  184. 'params'=>array(':addId'=>$this->_add->addid),
  185. ),
  186. ));
  187. $this->render('index',array(
  188. 'dataProvider'=>$dataProvider,
  189. ));
  190. }
  191.  
  192. /**
  193. * Manages all models.
  194. */
  195. public function actionAdmin()
  196. {
  197. $model=new Comment('search');
  198. $model->unsetAttributes(); // clear any default values
  199. if(isset($_GET['Comment']))
  200. $model->attributes=$_GET['Comment'];
  201.  
  202. $this->render('admin',array(
  203. 'model'=>$model,
  204. ));
  205. }
  206.  
  207. /**
  208. * Returns the data model based on the primary key given in the GET variable.
  209. * If the data model is not found, an HTTP exception will be raised.
  210. * @param integer the ID of the model to be loaded
  211. */
  212. public function loadModel($id)
  213. {
  214. $model=Comment::model()->findByPk($id);
  215. if($model===null)
  216. throw new CHttpException(404,'The requested page does not exist.');
  217. return $model;
  218. }
  219.  
  220. /**
  221. * Performs the AJAX validation.
  222. * @param CModel the model to be validated
  223. */
  224. protected function performAjaxValidation($model)
  225. {
  226. if(isset($_POST['ajax']) && $_POST['ajax']==='comment-form')
  227. {
  228. echo CActiveForm::validate($model);
  229. Yii::app()->end();
  230. }
  231. }
  232.  
  233.  
  234. }
  235.  
  236. <?php
  237. /* @var $this AddController */
  238. /* @var $model Add */
  239. $Comment = new Comment("create");
  240. $this->breadcrumbs=array(
  241. 'Adds'=>array('index'),
  242. $model->addname,
  243. );
  244.  
  245. $this->menu=array(
  246. array('label'=>'List Add', 'url'=>array('index')),
  247. array('label'=>'Create Add', 'url'=>array('create')),
  248. array('label'=>'Update Add', 'url'=>array('update', 'id'=>$model->addid)),
  249. array('label'=>'Delete Add', 'url'=>'#', 'linkOptions'=>array('submit'=>array('delete','id'=>$model->addid),'confirm'=>'Are you sure you want to delete this item?')),
  250. array('label'=>'Manage Add', 'url'=>array('admin')),
  251. array('label'=>'Create Comment', 'url'=>array('comment/create', 'pid'=>$model->addid)),
  252. );
  253. ?>
  254.  
  255.  
  256.  
  257.  
  258.  
  259. <?php $this->widget('bootstrap.widgets.TbDetailView', array(
  260. 'data'=>$model,
  261. 'type'=>'condensed',
  262. 'attributes'=>array(
  263. 'username',
  264. 'addname',
  265. 'category',
  266. 'description',
  267. 'city',
  268. 'address',
  269. 'mobile',
  270. 'email',
  271. 'image',
  272. 'price',
  273. array(
  274. 'label'=>'imzzzage',
  275. 'type'=>'raw',
  276. 'value'=>CHtml::tag('img',
  277. array("title"=>"CollegeLogo",
  278. "src"=>Yii::app()->baseUrl."/images/".$model->image,
  279. "style"=>"height:200px")
  280. )
  281. ),
  282.  
  283. ),
  284. ));
  285.  
  286. echo CHtml::link("contact this add publisher ",array('add/contactpublisher','id'=> $model->addname));
  287.  
  288. ?>
  289. <br />
  290. <h2>Comments</h2>
  291. <?php $this->widget('zii.widgets.CListView', array(
  292. 'dataProvider'=>$commentDataProvider,
  293. 'itemView'=>'/comment/_view',
  294. )); ?>
  295.  
  296. <?php $this->renderPartial('/comment/create',array('model'=>$Comment,)); ?>
  297.  
  298. <?php
  299.  
  300. /**
  301. * This is the model class for table "tbl_comment".
  302. *
  303. * The followings are the available columns in table 'tbl_comment':
  304. * @property integer $cid
  305. * @property integer $add_id
  306. * @property integer $user_id
  307. * @property string $user_name
  308. * @property string $description
  309. * @property string $create_time
  310. *
  311. * The followings are the available model relations:
  312. * @property Users $user
  313. * @property Add $add
  314. */
  315. class Comment extends CActiveRecord
  316. {
  317. /**
  318. * Returns the static model of the specified AR class.
  319. * @param string $className active record class name.
  320. * @return Comment the static model class
  321. */
  322. public static function model($className=__CLASS__)
  323. {
  324. return parent::model($className);
  325. }
  326.  
  327. /**
  328. * @return string the associated database table name
  329. */
  330. public function tableName()
  331. {
  332. return 'tbl_comment';
  333. }
  334.  
  335. /**
  336. * @return array validation rules for model attributes.
  337. */
  338. public function rules()
  339. {
  340. // NOTE: you should only define rules for those attributes that
  341. // will receive user inputs.
  342. return array(
  343. array('description', 'required'),
  344. array('add_id, user_id', 'numerical', 'integerOnly'=>true),
  345. array('user_name', 'length', 'max'=>1000),
  346. array('description', 'length', 'max'=>2000),
  347. array('create_time', 'safe'),
  348. // The following rule is used by search().
  349. // Please remove those attributes that should not be searched.
  350. array('cid, add_id, user_id, user_name, description, create_time', 'safe', 'on'=>'search'),
  351. );
  352. }
  353.  
  354. /**
  355. * @return array relational rules.
  356. */
  357. public function relations()
  358. {
  359. // NOTE: you may need to adjust the relation name and the related
  360. // class name for the relations automatically generated below.
  361. return array(
  362. 'user' => array(self::BELONGS_TO, 'Users', 'user_id'),
  363. 'add' => array(self::BELONGS_TO, 'Add', 'add_id'),
  364. );
  365. }
  366.  
  367. /**
  368. * @return array customized attribute labels (name=>label)
  369. */
  370. public function attributeLabels()
  371. {
  372. return array(
  373. 'cid' => 'Cid',
  374. 'add_id' => 'Add',
  375. 'user_id' => 'User',
  376. 'user_name' => 'User Name',
  377. 'description' => 'Description',
  378. 'create_time' => 'Create Time',
  379. );
  380. }
  381.  
  382. /**
  383. * Retrieves a list of models based on the current search/filter conditions.
  384. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  385. */
  386. public function search()
  387. {
  388. // Warning: Please modify the following code to remove attributes that
  389. // should not be searched.
  390.  
  391. $criteria=new CDbCriteria;
  392.  
  393. $criteria->compare('cid',$this->cid);
  394. $criteria->compare('add_id',$this->add_id);
  395. $criteria->compare('user_id',$this->user_id);
  396. $criteria->compare('user_name',$this->user_name,true);
  397. $criteria->compare('description',$this->description,true);
  398. $criteria->compare('create_time',$this->create_time,true);
  399.  
  400. return new CActiveDataProvider($this, array(
  401. 'criteria'=>$criteria,
  402. ));
  403. }
  404. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement