Advertisement
yacel100

archivo model

Jun 18th, 2013
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.22 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * This is the model class for table "archivo".
  5.  *
  6.  * The followings are the available columns in table 'archivo':
  7.  * @property integer $id_pro
  8.  * @property integer $id_arc
  9.  * @property integer $id_tip_arc
  10.  * @property string $nombre_arc
  11.  * @property string $url_arcventas
  12.  * @property double $tamano_arc
  13.  * @property double $version_arc
  14.  * @property string $fecha_cre_arc
  15.  *
  16.  * The followings are the available model relations:
  17.  * @property TipoArchivo $idTipArc
  18.  * @property Proyecto $idPro
  19.  * @property Video[] $videos
  20.  * @property Video[] $videos1
  21.  */
  22. class Archivo extends CActiveRecord
  23. {
  24.     /**
  25.      * Returns the static model of the specified AR class.
  26.      * @param string $className active record class name.
  27.      * @return Archivo the static model class
  28.      */
  29.     public static function model($className=__CLASS__)
  30.     {
  31.         return parent::model($className);
  32.     }
  33.  
  34.     /**
  35.      * @return string the associated database table name
  36.      */
  37.     public function tableName()
  38.     {
  39.         return 'archivo';
  40.     }
  41.  
  42.     /**
  43.      * @return array validation rules for model attributes.
  44.      */
  45.     public function rules()
  46.     {
  47.         // NOTE: you should only define rules for those attributes that
  48.         // will receive user inputs.
  49.         return array(
  50.             array('id_pro, id_tip_arc, nombre_arc, url_arc, fecha_cre_arc', 'required'),
  51.             array('id_pro, id_tip_arc', 'numerical', 'integerOnly'=>true),
  52.             array('tamano_arc, version_arc', 'numerical'),
  53.             array('nombre_arc', 'length', 'max'=>100),
  54.             // The following rule is used by search().
  55.             // Please remove those attributes that should not be searched.
  56.             array('id_pro, id_arc, id_tip_arc, nombre_arc, url_arc, tamano_arc, version_arc, fecha_cre_arc', 'safe', 'on'=>'search'),
  57.         );
  58.     }
  59.  
  60.     /**
  61.      * @return array relational rules.
  62.      */
  63.     public function relations()
  64.     {
  65.         // NOTE: you may need to adjust the relation name and the related
  66.         // class name for the relations automatically generated below.
  67.         return array(
  68.             'idTipArc' => array(self::BELONGS_TO, 'TipoArchivo', 'id_tip_arc'),
  69.             'idPro' => array(self::BELONGS_TO, 'Proyecto', 'id_pro'),
  70.             'videos' => array(self::HAS_MANY, 'Video', 'id_pro'),
  71.             'videos1' => array(self::HAS_MANY, 'Video', 'id_arc'),
  72.         );
  73.     }
  74.  
  75.     /**
  76.      * @return array customized attribute labels (name=>label)
  77.      */
  78.     public function attributeLabels()
  79.     {
  80.         return array(
  81.             'id_pro' => 'Id Pro',
  82.             'id_arc' => 'Id Arc',
  83.             'id_tip_arc' => 'Id Tip Arc',
  84.             'nombre_arc' => 'Nombre Arc',
  85.             'url_arc' => 'Url Arc',
  86.             'tamano_arc' => 'Tamano Arc',
  87.             'version_arc' => 'Version Arc',
  88.             'fecha_cre_arc' => 'Fecha Cre Arc',
  89.         );
  90.     }
  91.  
  92.     /**
  93.      * Retrieves a list of models based on the current search/filter conditions.
  94.      * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
  95.      */
  96.     public function search()
  97.     {
  98.         // Warning: Please modify the following code to remove attributes that
  99.         // should not be searched.
  100.  
  101.         $criteria=new CDbCriteria;
  102.  
  103.         $criteria->compare('id_pro',$this->id_pro);
  104.         $criteria->compare('id_arc',$this->id_arc);
  105.         $criteria->compare('id_tip_arc',$this->id_tip_arc);
  106.         $criteria->compare('nombre_arc',$this->nombre_arc,true);
  107.         $criteria->compare('url_arc',$this->url_arc,true);
  108.         $criteria->compare('tamano_arc',$this->tamano_arc);
  109.         $criteria->compare('version_arc',$this->version_arc);
  110.         $criteria->compare('fecha_cre_arc',$this->fecha_cre_arc,true);
  111.  
  112.         return new CActiveDataProvider($this, array(
  113.             'criteria'=>$criteria,
  114.         ));
  115.     }
  116.  
  117.     public function onFileUploaded($fullFileName,$userdata) {
  118.         // userdata is the same passed via widget config.
  119.         // fullFileName es la ruta del archivo
  120.         // listo para leer.
  121.  
  122.         $userid = $userdata;
  123.         //siendo este ultimo algun ID pasado al widget
  124.         //en la vista en donde lo pusiste. supon que es
  125.         //el ID del usuario activo que tu tienes.
  126.  
  127.         //bueno, simple:
  128.         //$nuevaRuta = crea_nueva_ruta($userid);
  129.         //mover_archivo($fullFileName, $nuevaRuta);
  130.  
  131.         $archivo = Archivo::model()->findByPk($userid);
  132.  
  133.         // podrias usar esa foto como perfil:
  134.         $archivo->url_arc =$fullFileName;
  135.  
  136.         // o podrias almacenar esa foto o archivo
  137.         // en su lista de archivos...
  138.         //$almacen = $archivo->getAlmacen();
  139.         //$almacen->agregar($nuevaRuta);
  140.     }
  141.    
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement