Esempio n. 1
0
 /**
  * Método para crear/modificar un objeto de base de datos
  *
  * @param string $medthod: create, update
  * @param array $data: Data para autocargar el modelo
  * @param array $optData: Data adicional para autocargar
  *
  * return object ActiveRecord
  */
 public static function setEvento($method, $data, $usuario = null)
 {
     $obj = new Evento($data);
     //Se carga los datos con los de las tablas
     $obj->usuario_id = $usuario;
     if (!empty($obj->id)) {
         $old = new Evento();
         if ($old->find_first($obj->id)) {
             if ($method == 'create') {
                 $obj->id = $old->id;
                 $method = 'update';
             }
         }
     }
     return $obj->{$method}() ? $obj : FALSE;
 }
Esempio n. 2
0
 public function fileEventSave()
 {
     View::select(null, null);
     $data = null;
     if (Input::hasPost('fechaSelect')) {
         $upload = new DwUpload('archivo', 'img/upload/eventos/');
         //$upload->setAllowedTypes('png|jpg|gif|jpeg|png');
         $upload->setEncryptName(TRUE);
         $this->data = $upload->save();
         if (!$this->data) {
             //retorna un array('path'=>'ruta', 'name'=>'nombre.ext');
             $data = array('error' => TRUE, 'message' => $upload->getError());
         } else {
             $fecha = Input::post('fechaSelect');
             $hora = Input::post('hora');
             $id = Input::post('id');
             $evento = new Evento();
             if (is_numeric($id) && $evento->find_first($id)) {
                 $evento->urlFile = "img/upload/eventos/{$this->data['name']}";
                 $evento->update();
                 $data = array('success' => true);
                 $data = $evento;
                 $data->networks = json_decode($data->networks);
             } else {
                 $return = array("start" => $fecha, "urlFile" => "img/upload/eventos/{$this->data['name']}", "constraint" => "", "author" => "", "hour" => $hora, "networks" => array("facebook" => "false", "twitter" => "false", "instagram" => "false", "linkedin" => "false", "pinterest" => "false", "youtube" => "false", "plus" => "false"));
                 $data = Evento::setEvento('create', $return, Session::get('id'));
                 $data->networks = json_decode($data->networks);
             }
         }
     }
     $this->data = $data;
     View::json();
 }