PageRenderTime 40ms CodeModel.GetById 13ms RepoModel.GetById 1ms app.codeStats 0ms

/protected/modules/carrera/models/ActividadIngreso.php

https://code.google.com/
PHP | 146 lines | 90 code | 16 blank | 40 comment | 8 complexity | 63c53f65ebb83ab940c4d669607a96fc MD5 | raw file
Possible License(s): BSD-3-Clause
  1. <?php
  2. /**
  3. * This is the model class for table "tbl_actividadingreso".
  4. *
  5. * The followings are the available columns in table 'tbl_actividadingreso':
  6. * @property integer $actividadingreso_id
  7. * @property string $actividadingreso_nombre
  8. * @property string $actividadingreso_creado
  9. * @property string $actividadingreso_creado_usuario_id
  10. * @property string $actividadingreso_modificado
  11. * @property string $actividadingreso_modificado_usuario_id
  12. * @property integer $actividadingreso_estado_id
  13. */
  14. class ActividadIngreso extends CActiveRecord
  15. {
  16. /**
  17. * Returns the static model of the specified AR class.
  18. * @return ActividadIngreso the static model class
  19. */
  20. public static function model($className=__CLASS__)
  21. {
  22. return parent::model($className);
  23. }
  24. /**
  25. * @return string the associated database table name
  26. */
  27. public function tableName()
  28. {
  29. return 'tbl_actividadingreso';
  30. }
  31. /**
  32. * @return array validation rules for model attributes.
  33. */
  34. public function rules()
  35. {
  36. // NOTE: you should only define rules for those attributes that
  37. // will receive user inputs.
  38. return array(
  39. array('actividadingreso_nombre, actividadingreso_estado_id', 'required'),
  40. array('actividadingreso_estado_id', 'numerical', 'integerOnly'=>true),
  41. array('actividadingreso_nombre', 'length', 'max'=>100),
  42. array('actividadingreso_creado_usuario_id, actividadingreso_modificado_usuario_id', 'length', 'max'=>20),
  43. array('actividadingreso_nombre', 'unique'),
  44. // The following rule is used by search().
  45. // Please remove those attributes that should not be searched.
  46. array('actividadingreso_id, actividadingreso_nombre, actividadingreso_creado, actividadingreso_creado_usuario_id, actividadingreso_modificado, actividadingreso_modificado_usuario_id, actividadingreso_estado_id', 'safe', 'on'=>'search'),
  47. );
  48. }
  49. /**
  50. * @return array relational rules.
  51. */
  52. public function relations()
  53. {
  54. // NOTE: you may need to adjust the relation name and the related
  55. // class name for the relations automatically generated below.
  56. return array(
  57. );
  58. }
  59. /**
  60. * @return array customized attribute labels (name=>label)
  61. */
  62. public function attributeLabels()
  63. {
  64. return array(
  65. 'actividadingreso_id' => t('ID','nucleo_etiqueta'),
  66. 'actividadingreso_nombre' => t('Nombre','nucleo_etiqueta'),
  67. 'actividadingreso_creado' => 'Actividadingreso Creado',
  68. 'actividadingreso_creado_usuario_id' => 'Actividadingreso Creado Usuario',
  69. 'actividadingreso_modificado' => 'Actividadingreso Modificado',
  70. 'actividadingreso_modificado_usuario_id' => 'Actividadingreso Modificado Usuario',
  71. 'actividadingreso_estado_id' => 'Actividadingreso Estado',
  72. );
  73. }
  74. /**
  75. * Retrieves a list of models based on the current search/filter conditions.
  76. * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  77. */
  78. public function search()
  79. {
  80. // Warning: Please modify the following code to remove attributes that
  81. // should not be searched.
  82. $criteria=new CDbCriteria;
  83. $criteria->compare('actividadingreso_id',$this->actividadingreso_id);
  84. $criteria->compare('actividadingreso_nombre',trim($this->actividadingreso_nombre),true);
  85. $criteria->compare('actividadingreso_creado',$this->actividadingreso_creado,true);
  86. $criteria->compare('actividadingreso_creado_usuario_id',$this->actividadingreso_creado_usuario_id,true);
  87. $criteria->compare('actividadingreso_modificado',$this->actividadingreso_modificado,true);
  88. $criteria->compare('actividadingreso_modificado_usuario_id',$this->actividadingreso_modificado_usuario_id,true);
  89. if(!user()->isSuperuser)
  90. {
  91. $criteria->addCondition('actividadingreso_estado_id <> ' .AplicacionVariables::ESTADO_ELIMINADO_ID);
  92. }
  93. return new CActiveDataProvider($this, array(
  94. 'criteria'=>$criteria,
  95. ));
  96. }
  97. protected function afterFind()
  98. {
  99. $this->actividadingreso_creado = ($this->actividadingreso_creado != '0000-00-00 00:00:00' && !is_null($this->actividadingreso_creado))?date('d/m/Y H:i:s', strtotime(str_replace('-','/',$this->actividadingreso_creado))):'';
  100. $this->actividadingreso_modificado = ($this->actividadingreso_modificado != '0000-00-00 00:00:00' && !is_null($this->actividadingreso_modificado))?date('d/m/Y H:i:s', strtotime(str_replace('-','/',$this->actividadingreso_modificado))):'';
  101. return TRUE;
  102. }
  103. protected function beforeSave()
  104. {
  105. if(!$this->isNewRecord)
  106. {
  107. if($this->actividadingreso_creado == '')
  108. {
  109. $this->actividadingreso_creado = new CDbExpression('NOW()');
  110. }
  111. else
  112. {
  113. $this->actividadingreso_creado = date('Y-m-d H:i:s', strtotime(str_replace('/','-',$this->actividadingreso_creado)));
  114. }
  115. $this->actividadingreso_creado_usuario_id = user()->getId();
  116. }
  117. else
  118. {
  119. $this->actividadingreso_modificado = new CDbExpression('NOW()');
  120. $this->actividadingreso_modificado_usuario_id = user()->getId();
  121. }
  122. return TRUE;
  123. }
  124. public function getActividadesIngresosIdNombreActivo()
  125. {
  126. $criteria = new CDbCriteria();
  127. $criteria->select = "actividadingreso_id, actividadingreso_nombre";
  128. return $this->findAll($criteria);
  129. }
  130. }