PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/protected/modules/carrera/models/IngresoCurso.php

https://code.google.com/
PHP | 151 lines | 88 code | 18 blank | 45 comment | 2 complexity | 6851b88cbf6c2d498b7d1d1fdba75c47 MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * This is the model class for table "tbl_ingresocurso".
  4. *
  5. * The followings are the available columns in table 'tbl_ingresocurso':
  6. * @property string $ingresocurso_id
  7. * @property string $ingresocurso_periodoingreso_id
  8. * @property integer $ingresocurso_programaacademico_id
  9. * @property string $ingresocurso_inicio
  10. * @property string $ingresocurso_fin
  11. * @property string $ingresocurso_descripcion
  12. * @property integer $ingresocurso_porcentajeaprobacion
  13. * @property string $ingresocurso_creado
  14. * @property string $ingresocurso_creado_usuario_id
  15. * @property string $ingresocurso_modificado
  16. * @property string $ingresocurso_modificado_usuario_id
  17. * @property integer $ingresocurso_estado_id
  18. */
  19. class IngresoCurso extends CActiveRecord
  20. {
  21. public $ingresocurso_cantidadcurso;
  22. /**
  23. * Returns the static model of the specified AR class.
  24. * @return IngresoCurso the static model class
  25. */
  26. public static function model($className=__CLASS__)
  27. {
  28. return parent::model($className);
  29. }
  30. /**
  31. * @return string the associated database table name
  32. */
  33. public function tableName()
  34. {
  35. return 'tbl_ingresocurso';
  36. }
  37. /**
  38. * @return array validation rules for model attributes.
  39. */
  40. public function rules()
  41. {
  42. // NOTE: you should only define rules for those attributes that
  43. // will receive user inputs.
  44. return array(
  45. array('ingresocurso_inicio, ingresocurso_fin, ingresocurso_descripcion, ingresocurso_porcentajeaprobacion, ingresocurso_estado_id', 'required'),
  46. array('ingresocurso_periodoingreso_id, ingresocurso_programaacademico_id, ingresocurso_inicio, ingresocurso_fin, ingresocurso_descripcion, ingresocurso_porcentajeaprobacion, ingresocurso_estado_id', 'required','on'=>'Guardar'),
  47. array('ingresocurso_programaacademico_id, ingresocurso_porcentajeaprobacion, ingresocurso_estado_id', 'numerical', 'integerOnly'=>true),
  48. array('ingresocurso_periodoingreso_id, ingresocurso_creado_usuario_id, ingresocurso_modificado_usuario_id', 'length', 'max'=>20),
  49. array('ingresocurso_descripcion', 'length', 'max'=>255),
  50. // The following rule is used by search().
  51. // Please remove those attributes that should not be searched.
  52. array('ingresocurso_id, ingresocurso_periodoingreso_id, ingresocurso_programaacademico_id, ingresocurso_inicio, ingresocurso_fin, ingresocurso_descripcion, ingresocurso_porcentajeaprobacion, ingresocurso_creado, ingresocurso_creado_usuario_id, ingresocurso_modificado, ingresocurso_modificado_usuario_id, ingresocurso_estado_id,ingresocurso_cantidadcurso', 'safe', 'on'=>'search'),
  53. );
  54. }
  55. /**
  56. * @return array relational rules.
  57. */
  58. public function relations()
  59. {
  60. // NOTE: you may need to adjust the relation name and the related
  61. // class name for the relations automatically generated below.
  62. return array(
  63. 'programaAcademico' => array(self::BELONGS_TO, 'ProgramaAcademico', 'ingresocurso_programaacademico_id'),
  64. 'periodoIngreso' => array(self::BELONGS_TO, 'PeriodoIngreso', 'ingresocurso_periodoingreso_id'),
  65. 'usuarioCreador' => array(self::BELONGS_TO, 'Usuario', 'ingresocurso_creado_usuario_id'),
  66. 'usuarioModificador' => array(self::BELONGS_TO, 'Usuario', 'ingresocurso_modificado_usuario_id'),
  67. );
  68. }
  69. /**
  70. * @return array customized attribute labels (name=>label)
  71. */
  72. public function attributeLabels()
  73. {
  74. return array(
  75. 'ingresocurso_id' => t('ID','nucleo_etiqueta'),
  76. 'ingresocurso_periodoingreso_id' => t('Periodo Ingreso','nucleo_etiqueta'),
  77. 'ingresocurso_programaacademico_id' => t('Programa Academico','carrera_etiqueta'),
  78. 'ingresocurso_inicio' => t('Inicio','carrera_etiqueta'),
  79. 'ingresocurso_fin' => t('Fin','carrera_etiqueta'),
  80. 'ingresocurso_descripcion' => t('Descripcion','carrera_etiqueta'),
  81. 'ingresocurso_porcentajeaprobacion' => t('Procentaje de Aprobacion','carrera_etiqueta'),
  82. 'ingresocurso_creado' => 'Ingresocurso Creado',
  83. 'ingresocurso_creado_usuario_id' => 'Ingresocurso Creado Usuario',
  84. 'ingresocurso_modificado' => 'Ingresocurso Modificado',
  85. 'ingresocurso_modificado_usuario_id' => 'Ingresocurso Modificado Usuario',
  86. 'ingresocurso_estado_id' => 'Ingresocurso Estado',
  87. 'ingresocurso_cantidadcurso' => t('Cant. Cursos','carrera_etiqueta'),
  88. );
  89. }
  90. /**
  91. * Retrieves a list of models based on the current search/filter conditions.
  92. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  93. */
  94. public function search()
  95. {
  96. // Warning: Please modify the following code to remove attributes that
  97. // should not be searched.
  98. $criteria=new CDbCriteria;
  99. $criteria->compare('ingresocurso_id',$this->ingresocurso_id,true);
  100. $criteria->compare('ingresocurso_periodoingreso_id',$this->ingresocurso_periodoingreso_id,true);
  101. $criteria->compare('ingresocurso_programaacademico_id',$this->ingresocurso_programaacademico_id);
  102. $criteria->compare('ingresocurso_inicio',$this->ingresocurso_inicio,true);
  103. $criteria->compare('ingresocurso_fin',$this->ingresocurso_fin,true);
  104. $criteria->compare('ingresocurso_descripcion',$this->ingresocurso_descripcion,true);
  105. $criteria->compare('ingresocurso_porcentajeaprobacion',$this->ingresocurso_porcentajeaprobacion);
  106. $criteria->compare('ingresocurso_creado',$this->ingresocurso_creado,true);
  107. $criteria->compare('ingresocurso_creado_usuario_id',$this->ingresocurso_creado_usuario_id,true);
  108. $criteria->compare('ingresocurso_modificado',$this->ingresocurso_modificado,true);
  109. $criteria->compare('ingresocurso_modificado_usuario_id',$this->ingresocurso_modificado_usuario_id,true);
  110. $criteria->compare('ingresocurso_estado_id',$this->ingresocurso_estado_id);
  111. if(intval($this->ingresocurso_cantidadcurso) != 0)
  112. {
  113. $criteria->having = 'COUNT(ingresocurso_id) = ' .$this->ingresocurso_cantidadcurso;
  114. }
  115. $criteria->group = 'ingresocurso_periodoingreso_id,ingresocurso_programaacademico_id';
  116. $criteria->select = 'ingresocurso_periodoingreso_id,ingresocurso_programaacademico_id,COUNT(ingresocurso_id) as ingresocurso_cantidadcurso';
  117. return new CActiveDataProvider($this, array(
  118. 'criteria'=>$criteria,
  119. ));
  120. }
  121. protected function beforeSave()
  122. {
  123. $this->ingresocurso_inicio = date('Y-m-d', strtotime(str_replace('/','-',$this->ingresocurso_inicio)));
  124. $this->ingresocurso_fin = date('Y-m-d', strtotime(str_replace('/','-',$this->ingresocurso_fin)));
  125. return TRUE;
  126. }
  127. protected function afterFind()
  128. {
  129. $this->ingresocurso_inicio = date('d/m/Y', strtotime($this->ingresocurso_inicio));
  130. $this->ingresocurso_fin = date('d/m/Y', strtotime($this->ingresocurso_fin));
  131. return TRUE;
  132. }
  133. }